FreeBSD/sys/cddl/contrib/opensolaris/uts/common/fs/gfs.c
/*
 * gfs_readdir_emit_int: internal routine to emit directory entry
 *
 *   st		- the current readdir state, which must have d_ino/ed_ino
 *		  and d_name/ed_name set
 *   uiop	- caller-supplied uio pointer
 *   next	- the offset of the next entry
 */
internal routine to emit directory entry
st         - the current readdir state, which must have d_ino/ed_ino
and d_name/ed_name set
uiop       - caller-supplied uio pointer
next       - the offset of the next entry
internal routine to emit directory entry st - the current readdir state which must have d_ino / ed_ino and d_name / ed_name set uiop - caller - supplied uio pointer next - the offset of the next entry
static int
gfs_readdir_emit_int(gfs_readdir_state_t *st, uio_t *uiop, offset_t next,
    int *ncookies, u_long **cookies)
{
	int reclen, namlen;
	dirent64_t *dp;
	edirent_t *edp;
	if (st->grd_flags & V_RDDIR_ENTFLAGS) {
		edp = st->grd_dirent;
		namlen = strlen(edp->ed_name);
		reclen = EDIRENT_RECLEN(namlen);
	} else {
		dp = st->grd_dirent;
		namlen = strlen(dp->d_name);
		reclen = DIRENT64_RECLEN(namlen);
	}
	if (reclen > uiop->uio_resid) {
		if (uiop->uio_resid == st->grd_oresid)
			return (EINVAL);
		return (-1);
	}
	if (st->grd_flags & V_RDDIR_ENTFLAGS) {
		edp->ed_off = next;
		edp->ed_reclen = (ushort_t)reclen;
	} else {
		dp->d_reclen = (ushort_t)reclen;
		dp->d_type = DT_DIR;
		dp->d_namlen = namlen;
	}
	if (uiomove((caddr_t)st->grd_dirent, reclen, UIO_READ, uiop))
		return (EFAULT);
	uiop->uio_loffset = next;
	if (*cookies != NULL) {
		**cookies = next;
		(*cookies)++;
		(*ncookies)--;
		KASSERT(*ncookies >= 0, ("ncookies=%d", *ncookies));
	}
	return (0);
}
static int gfs_readdir_emit_int ( gfs_readdir_state_t * st , uio_t * uiop , offset_t next , int * ncookies , u_long * * cookies ) { int reclen , namlen ; dirent64_t * dp ; edirent_t * edp ; if ( st -> grd_flags & V_RDDIR_ENTFLAGS ) { edp = st -> grd_dirent ; namlen = strlen ( edp -> ed_name ) ; reclen = EDIRENT_RECLEN ( namlen ) ; } else { dp = st -> grd_dirent ; namlen = strlen ( dp -> d_name ) ; reclen = DIRENT64_RECLEN ( namlen ) ; } if ( reclen > uiop -> uio_resid ) { if ( uiop -> uio_resid == st -> grd_oresid ) return ( EINVAL ) ; return ( -1 ) ; } if ( st -> grd_flags & V_RDDIR_ENTFLAGS ) { edp -> ed_off = next ; edp -> ed_reclen = ( ushort_t ) reclen ; } else { dp -> d_reclen = ( ushort_t ) reclen ; dp -> d_type = DT_DIR ; dp -> d_namlen = namlen ; } if ( uiomove ( ( caddr_t ) st -> grd_dirent , reclen , UIO_READ , uiop ) ) return ( EFAULT ) ; uiop -> uio_loffset = next ; if ( * cookies != NULL ) { * * cookies = next ; ( * cookies ) ++ ; ( * ncookies ) -- ; KASSERT ( * ncookies >= 0 , ( " " , * ncookies ) ) ; } return ( 0 ) ; }
gfs_readdir_emit_int: internal routine to emit directory entry
   st         - the current readdir state, which must have d_ino/ed_ino
                and d_name/ed_name set
   uiop       - caller-supplied uio pointer
   next       - the offset of the next entry
gfs_readdir_emit_int : internal routine to emit directory entry st - the current readdir state which must have d_ino / ed_ino and d_name / ed_name set uiop - caller - supplied uio pointer next - the offset of the next entry
/*
		 * Error if no entries were returned yet
		 */ /* XXX: This can change in the future. */