3 .\" Copyright (c) 1996 Doug Rabson
5 .\" All rights reserved.
7 .\" This program is free software.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 .\" $FreeBSD: src/share/man/man9/VOP_READDIR.9,v 1.6.2.1 2001/12/17 11:30:18 ru Exp $
36 .Nd read contents of a directory
42 .Fn VOP_READDIR "struct vnode *vp" "struct uio *uio" "struct ucred *cred" "int *eofflag" "int *ncookies" "u_long **cookies"
44 Read directory entries.
45 .Bl -tag -width ncookies
47 the vnode of the directory
49 where to read the directory contents
51 the caller's credentials
53 return end of file status (NULL if not wanted)
55 number of directory cookies generated for NFS (NULL if not wanted)
57 directory seek cookies generated for NFS (NULL if not wanted)
59 The directory contents are read into
61 structures. If the on-disc data structures differ from this then they
64 The directory should be locked on entry and will still be locked on exit.
66 Zero is returned on success, otherwise an error code is returned.
68 If this is called from the NFS server, the extra arguments
76 should be set to TRUE if the end of the directory is reached while
78 The directory seek cookies are returned to the NFS client and may be used
79 later to restart a directory read part way through the directory.
80 There should be one cookie returned per directory entry. The value of
81 the cookie should be the offset within the directory where the on-disc
82 version of the appropriate directory entry starts.
83 Memory for the cookies should be allocated using:
87 *ncookies = number of entries read;
89 malloc(*ncookies * sizeof(u_int), M_TEMP, M_WAITOK);
94 vop_readdir(struct vnode *vp, struct uio *uio, struct ucred *cred,
95 int *eofflag, int *ncookies, u_int **cookies)
101 * Remember the original offset to use later in generating cookies.
103 off = uio->uio_offset;
106 * Read directory contents starting at uio->uio_offset into buffer
111 if (!error && ncookies != NULL) {
112 struct dirent *dpStart;
113 struct dirent *dpEnd;
119 if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
120 panic("vop_readdir: unexpected uio from NFS server");
123 * Parse the stuff just read into the uio.
125 dpStart = (struct dirent *)
126 (uio->uio_iov->iov_base - (uio->uio_offset - off));
127 dpEnd = (struct dirent *) uio->uio_iov->iov_base;
130 * Count number of entries.
132 for (dp = dpStart, count = 0;
134 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen))
137 cookiebuf = (u_int *) malloc(count * sizeof(u_int), M_TEMP, M_WAITOK);
138 for (dp = dpStart; cookiep = cookiebuf;
140 dp = (struct dirent *)((caddr_t) dp + dp->d_reclen)) {
142 *cookiep++ = (u_int) off;
145 *cookies = cookiebuf;
148 if (eofflag && uio->uio_offset is past the end of the directory) {
158 attempt to read from an illegal offset in the directory
160 a read error occurred while reading the directory
165 This man page was written by