*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->FreeBSD man pages -> VOP_READDIR (9)              
Title
Content
Arch
Section
 

VOP_READDIR(9)

Contents


NAME    [Toc]    [Back]

     VOP_READDIR -- read contents of a directory

SYNOPSIS    [Toc]    [Back]

     #include <sys/param.h>
     #include <sys/dirent.h>
     #include <sys/vnode.h>

     int
     VOP_READDIR(struct vnode *vp, struct uio *uio, struct ucred *cred,
	 int *eofflag, int *ncookies, u_long **cookies);

DESCRIPTION    [Toc]    [Back]

     Read directory entries.

     vp        the vnode of the directory

     uio       where to read the directory contents

     cred      the caller's credentials

     eofflag   return end of file status (NULL if not wanted)

     ncookies  number of directory cookies generated for NFS (NULL if not
	       wanted)

     cookies   directory seek cookies generated for NFS (NULL if not wanted)
     The directory contents are read into struct dirent structures.  If the
     on-disc data structures differ from this then they should be translated.

LOCKS    [Toc]    [Back]

     The directory should be locked on entry and will still be locked on exit.

RETURN VALUES    [Toc]    [Back]

     Zero is returned on success, otherwise an error code is returned.

     If this is called from the NFS server, the extra arguments eofflag,
     ncookies and cookies are given.  The value of *eofflag should be set to
     TRUE if the end of the directory is reached while reading.  The directory
     seek cookies are returned to the NFS client and may be used later to
     restart a directory read part way through the directory.  There should be
     one cookie returned per directory entry.  The value of the cookie should
     be the offset within the directory where the on-disc version of the
     appropriate directory entry starts.  Memory for the cookies should be
     allocated using:

	     ...;
	     *ncookies = number of entries read;
	     *cookies = (u_int*)#
		     malloc(*ncookies * sizeof(u_int), M_TEMP, M_WAITOK);

PSEUDOCODE    [Toc]    [Back]

     int
     vop_readdir(struct vnode *vp, struct uio *uio, struct ucred *cred,
		 int *eofflag, int *ncookies, u_int **cookies)
     {
	 off_t off;
	 int error = 0;

	 /*
	  * Remember the original offset to use later in generating cookies.
	  */
	 off = uio->uio_offset;

	 /*
	  * Read directory contents starting at uio->uio_offset into buffer
	  * pointed to by uio.
	  */
	 ...;

	 if (!error && ncookies != NULL) {
	     struct dirent *dpStart;
	     struct dirent *dpEnd;
	     struct dirent *dp;
	     int count;
	     u_int *cookiebuf;
	     u_int *cookiep;

	     if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
		 panic("vop_readdir: unexpected uio from NFS server");

	     /*
	      * Parse the stuff just read into the uio.
	      */
	     dpStart = (struct dirent *)
		 ((char *)uio->uio_iov->iov_base - (uio->uio_offset - off));
	     dpEnd = (struct dirent *) uio->uio_iov->iov_base;

	     /*
	      * Count number of entries.
	      */
	     for (dp = dpStart, count = 0;
		  dp < dpEnd;
		  dp = (struct dirent *)((caddr_t) dp + dp->d_reclen))
		 count++;

	     cookiebuf = (u_int *) malloc(count * sizeof(u_int), M_TEMP, M_WAITOK);
	     for (dp = dpStart; cookiep = cookiebuf;
		  dp < dpEnd;
		  dp = (struct dirent *)((caddr_t) dp + dp->d_reclen)) {
		 off += dp->d_reclen;
		 *cookiep++ = (u_int) off;
	     }
	     *ncookies = count;
	     *cookies = cookiebuf;
	 }

	 if (eofflag && uio->uio_offset is past the end of the directory) {
	     *eofflag = TRUE;
	 }

	 return error;
     }

ERRORS    [Toc]    [Back]

     [EINVAL]		An attempt was made to read from an illegal offset in
			the directory.

     [EIO]		A read error occurred while reading the directory.

SEE ALSO    [Toc]    [Back]

      
      
     vnode(9)

AUTHORS    [Toc]    [Back]

     This man page was written by Doug Rabson.


FreeBSD 5.2.1			 July 24, 1996			 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
readlink HP-UX read the contents of a symbolic link
vdir Linux list directory contents
ls FreeBSD list directory contents
lifls HP-UX list contents of a LIF directory
ls IRIX list contents of directory
nisls HP-UX list the contents of an NIS+ directory
ls OpenBSD list directory contents
dir Linux list directory contents
ls Linux list directory contents
alphasort Tru64 Scan or sorts directory contents
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service