xref: /dflybsd-src/share/man/man9/VOP_READDIR.9 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino.\" Copyright (c) 1996 Doug Rabson
286d7f5d3SJohn Marino.\"
386d7f5d3SJohn Marino.\" All rights reserved.
486d7f5d3SJohn Marino.\"
586d7f5d3SJohn Marino.\" This program is free software.
686d7f5d3SJohn Marino.\"
786d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without
886d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions
986d7f5d3SJohn Marino.\" are met:
1086d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright
1186d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer.
1286d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright
1386d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer in the
1486d7f5d3SJohn Marino.\"    documentation and/or other materials provided with the distribution.
1586d7f5d3SJohn Marino.\"
1686d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
1786d7f5d3SJohn Marino.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1886d7f5d3SJohn Marino.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1986d7f5d3SJohn Marino.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
2086d7f5d3SJohn Marino.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2186d7f5d3SJohn Marino.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2286d7f5d3SJohn Marino.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2386d7f5d3SJohn Marino.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2486d7f5d3SJohn Marino.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2586d7f5d3SJohn Marino.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2686d7f5d3SJohn Marino.\"
2786d7f5d3SJohn Marino.\" $FreeBSD: src/share/man/man9/VOP_READDIR.9,v 1.6.2.1 2001/12/17 11:30:18 ru Exp $
2886d7f5d3SJohn Marino.\"
2986d7f5d3SJohn Marino.Dd July 24, 1996
3086d7f5d3SJohn Marino.Dt VOP_READDIR 9
3186d7f5d3SJohn Marino.Os
3286d7f5d3SJohn Marino.Sh NAME
3386d7f5d3SJohn Marino.Nm VOP_READDIR
3486d7f5d3SJohn Marino.Nd read contents of a directory
3586d7f5d3SJohn Marino.Sh SYNOPSIS
3686d7f5d3SJohn Marino.In sys/param.h
3786d7f5d3SJohn Marino.In sys/dirent.h
3886d7f5d3SJohn Marino.In sys/vnode.h
3986d7f5d3SJohn Marino.Ft int
4086d7f5d3SJohn Marino.Fn VOP_READDIR "struct vnode *vp" "struct uio *uio" "struct ucred *cred" "int *eofflag" "int *ncookies" "u_long **cookies"
4186d7f5d3SJohn Marino.Sh DESCRIPTION
4286d7f5d3SJohn MarinoRead directory entries.
4386d7f5d3SJohn Marino.Bl -tag -width ncookies
4486d7f5d3SJohn Marino.It Fa vp
4586d7f5d3SJohn Marinothe vnode of the directory
4686d7f5d3SJohn Marino.It Fa uio
4786d7f5d3SJohn Marinowhere to read the directory contents
4886d7f5d3SJohn Marino.It Fa cred
4986d7f5d3SJohn Marinothe caller's credentials
5086d7f5d3SJohn Marino.It Fa eofflag
5186d7f5d3SJohn Marinoreturn end of file status (NULL if not wanted)
5286d7f5d3SJohn Marino.It Fa ncookies
5386d7f5d3SJohn Marinonumber of directory cookies generated for NFS (NULL if not wanted)
5486d7f5d3SJohn Marino.It Fa cookies
5586d7f5d3SJohn Marinodirectory seek cookies generated for NFS (NULL if not wanted)
5686d7f5d3SJohn Marino.El
5786d7f5d3SJohn MarinoThe directory contents are read into
5886d7f5d3SJohn Marino.Vt struct dirent
5986d7f5d3SJohn Marinostructures.  If the on-disc data structures differ from this then they
6086d7f5d3SJohn Marinoshould be translated.
6186d7f5d3SJohn Marino.Sh LOCKS
6286d7f5d3SJohn MarinoThe directory should be locked on entry and will still be locked on exit.
6386d7f5d3SJohn Marino.Sh RETURN VALUES
6486d7f5d3SJohn MarinoZero is returned on success, otherwise an error code is returned.
6586d7f5d3SJohn Marino.Pp
6686d7f5d3SJohn MarinoIf this is called from the NFS server, the extra arguments
6786d7f5d3SJohn Marino.Fa eofflag ,
6886d7f5d3SJohn Marino.Fa ncookies
6986d7f5d3SJohn Marinoand
7086d7f5d3SJohn Marino.Fa cookies
7186d7f5d3SJohn Marinoare given.
7286d7f5d3SJohn MarinoThe value of
7386d7f5d3SJohn Marino.Fa *eofflag
7486d7f5d3SJohn Marinoshould be set to TRUE if the end of the directory is reached while
7586d7f5d3SJohn Marinoreading.
7686d7f5d3SJohn MarinoThe directory seek cookies are returned to the NFS client and may be used
7786d7f5d3SJohn Marinolater to restart a directory read part way through the directory.
7886d7f5d3SJohn MarinoThere should be one cookie returned per directory entry.  The value of
7986d7f5d3SJohn Marinothe cookie should be the offset within the directory where the on-disc
8086d7f5d3SJohn Marinoversion of the appropriate directory entry starts.
8186d7f5d3SJohn MarinoMemory for the cookies should be allocated using:
8286d7f5d3SJohn Marino.Bd -literal
8386d7f5d3SJohn Marino	...;
8486d7f5d3SJohn Marino	*ncookies = number of entries read;
8586d7f5d3SJohn Marino	*cookies = (u_int*)#
8686d7f5d3SJohn Marino		kmalloc(*ncookies * sizeof(u_int), M_TEMP, M_WAITOK);
8786d7f5d3SJohn Marino.Ed
8886d7f5d3SJohn Marino.Sh PSEUDOCODE
8986d7f5d3SJohn Marino.Bd -literal
9086d7f5d3SJohn Marinoint
9186d7f5d3SJohn Marinovop_readdir(struct vnode *vp, struct uio *uio, struct ucred *cred,
9286d7f5d3SJohn Marino	    int *eofflag, int *ncookies, u_int **cookies)
9386d7f5d3SJohn Marino{
9486d7f5d3SJohn Marino    off_t off;
9586d7f5d3SJohn Marino    int error = 0;
9686d7f5d3SJohn Marino
9786d7f5d3SJohn Marino    /*
9886d7f5d3SJohn Marino     * Remember the original offset to use later in generating cookies.
9986d7f5d3SJohn Marino     */
10086d7f5d3SJohn Marino    off = uio->uio_offset;
10186d7f5d3SJohn Marino
10286d7f5d3SJohn Marino    /*
10386d7f5d3SJohn Marino     * Read directory contents starting at uio->uio_offset into buffer
10486d7f5d3SJohn Marino     * pointed to by uio.
10586d7f5d3SJohn Marino     */
10686d7f5d3SJohn Marino    ...;
10786d7f5d3SJohn Marino
10886d7f5d3SJohn Marino    if (!error && ncookies != NULL) {
10986d7f5d3SJohn Marino	struct dirent *dpStart;
11086d7f5d3SJohn Marino	struct dirent *dpEnd;
11186d7f5d3SJohn Marino	struct dirent *dp;
11286d7f5d3SJohn Marino	int count;
11386d7f5d3SJohn Marino	u_int *cookiebuf;
11486d7f5d3SJohn Marino	u_int *cookiep;
11586d7f5d3SJohn Marino
11686d7f5d3SJohn Marino	if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
11786d7f5d3SJohn Marino	    panic("vop_readdir: unexpected uio from NFS server");
11886d7f5d3SJohn Marino
11986d7f5d3SJohn Marino	/*
12086d7f5d3SJohn Marino	 * Parse the stuff just read into the uio.
12186d7f5d3SJohn Marino	 */
12286d7f5d3SJohn Marino	dpStart = (struct dirent *)
12386d7f5d3SJohn Marino	    (uio->uio_iov->iov_base - (uio->uio_offset - off));
12486d7f5d3SJohn Marino	dpEnd = (struct dirent *) uio->uio_iov->iov_base;
12586d7f5d3SJohn Marino
12686d7f5d3SJohn Marino	/*
12786d7f5d3SJohn Marino	 * Count number of entries.
12886d7f5d3SJohn Marino	 */
12986d7f5d3SJohn Marino	for (dp = dpStart, count = 0;
13086d7f5d3SJohn Marino	     dp < dpEnd;
13186d7f5d3SJohn Marino	     dp = (struct dirent *)((caddr_t) dp + dp->d_reclen))
13286d7f5d3SJohn Marino	    count++;
13386d7f5d3SJohn Marino
13486d7f5d3SJohn Marino	cookiebuf = (u_int *) kmalloc(count * sizeof(u_int), M_TEMP, M_WAITOK);
13586d7f5d3SJohn Marino	for (dp = dpStart; cookiep = cookiebuf;
13686d7f5d3SJohn Marino	     dp < dpEnd;
13786d7f5d3SJohn Marino	     dp = (struct dirent *)((caddr_t) dp + dp->d_reclen)) {
13886d7f5d3SJohn Marino	    off += dp->d_reclen;
13986d7f5d3SJohn Marino	    *cookiep++ = (u_int) off;
14086d7f5d3SJohn Marino	}
14186d7f5d3SJohn Marino	*ncookies = count;
14286d7f5d3SJohn Marino	*cookies = cookiebuf;
14386d7f5d3SJohn Marino    }
14486d7f5d3SJohn Marino
14586d7f5d3SJohn Marino    if (eofflag && uio->uio_offset is past the end of the directory) {
14686d7f5d3SJohn Marino	*eofflag = TRUE;
14786d7f5d3SJohn Marino    }
14886d7f5d3SJohn Marino
14986d7f5d3SJohn Marino    return error;
15086d7f5d3SJohn Marino}
15186d7f5d3SJohn Marino.Ed
15286d7f5d3SJohn Marino.Sh ERRORS
15386d7f5d3SJohn Marino.Bl -tag -width Er
15486d7f5d3SJohn Marino.It Bq Er EINVAL
15586d7f5d3SJohn Marinoattempt to read from an illegal offset in the directory
15686d7f5d3SJohn Marino.It Bq Er EIO
15786d7f5d3SJohn Marinoa read error occurred while reading the directory
15886d7f5d3SJohn Marino.El
15986d7f5d3SJohn Marino.Sh SEE ALSO
16086d7f5d3SJohn Marino.Xr vnode 9
16186d7f5d3SJohn Marino.Sh AUTHORS
16286d7f5d3SJohn MarinoThis man page was written by
16386d7f5d3SJohn Marino.An Doug Rabson .
164