vnop_readdir Entry Point

Purpose

Reads directory entries in standard format.

Syntax

int vnop_readdir ( vp,  uiop,  crp)
struct vnode *vp;
struct uio *uiop;
struct ucred *crp;

Parameters

Item Description
vp Points to the virtual node (v-node) of the directory.
uiop Points to the uio structure that describes the data area into which to put the block of dirent structures. The starting directory offset is found in the uiop->uio_offset field and the size of the buffer area is found in the uiop->uio_resid field.
crp Points to the cred structure. This structure contains data that the file system can use to validate access permission.

Description

The vnop_readdir entry point is used to access directory entries in a standard way. These directories should be returned as an array of dirent structures. The /usr/include/sys/dir.h file contains the definition of a dirent structure.

The vnop_readdir entry point does the following:

The End-of-file character should be indicated by not reading any bytes (not by a partial read). This provides directories with the ability to have some hidden information in each block.

The virtual file system-specific implementation is also responsible for setting the uio_offset field to the offset of the next whole block to be read.

Notes:
  • If the call is meant for a JFS2 filesystem, extra processing is needed to avoid duplicate entries being returned in the user data area. The caller can check the VFS type from the directory vnode.
  • The caller must allocate a two-element array of type struct iovec to pass with the uio structure. The first element is initialized to point to the user data area to receive the dirent structures. If the file pointer of the directory has a non-NULL f_vinfo field, the second iovec element is initialized to point to the f_vinfo field and the length is set to 0; the number of elements in the uio structure is set to 2. If the f_vinfo field is NULL, then the number of elements in the uio structure is set to 1 and the second iovec element remains uninitialized.
  • If the caller does not have access to the directory file pointer, a dirent structure can be allocated in place of the f_vinfo field. The caller must not change this allocated structure between calls to the vnop_readdir entry point.

Execution Environment

The vnop_readdir entry point can be called from the process environment only.

Return Values

Item Description
0 Indicates success.

Nonzero return values are returned from the /usr/include/sys/errno.h file to indicate failure.