FreeBSD/sys/ufs/ufs/ufs_extattr.c
/*
 * Given a locked directory vnode, iterate over the names in the directory
 * and use ufs_extattr_lookup() to retrieve locked vnodes of potential
 * attribute files.  Then invoke ufs_extattr_enable_with_open() on each
 * to attempt to start the attribute.  Leaves the directory locked on
 * exit.
 */
Given a locked directory vnode, iterate over the names in the directory
and use ufs_extattr_lookup() to retrieve locked vnodes of potential
attribute files.  Then invoke ufs_extattr_enable_with_open() on each
to attempt to start the attribute.  Leaves the directory locked on
exit.
Given a locked directory vnode iterate over the names in the directory and use ufs_extattr_lookup () to retrieve locked vnodes of potential attribute files . Then invoke ufs_extattr_enable_with_open () on each to attempt to start the attribute . Leaves the directory locked on exit .
static int
ufs_extattr_iterate_directory(struct ufsmount *ump, struct vnode *dvp,
    int attrnamespace, struct thread *td)
{
	struct vop_readdir_args vargs;
	struct dirent *dp, *edp;
	struct vnode *attr_vp;
	struct uio auio;
	struct iovec aiov;
	char *dirbuf;
	int error, eofflag = 0;
	if (dvp->v_type != VDIR)
		return (ENOTDIR);
	dirbuf = malloc(DIRBLKSIZ, M_TEMP, M_WAITOK);
	auio.uio_iov = &aiov;
	auio.uio_iovcnt = 1;
	auio.uio_rw = UIO_READ;
	auio.uio_segflg = UIO_SYSSPACE;
	auio.uio_td = td;
	auio.uio_offset = 0;
	vargs.a_gen.a_desc = NULL;
	vargs.a_vp = dvp;
	vargs.a_uio = &auio;
	vargs.a_cred = td->td_ucred;
	vargs.a_eofflag = &eofflag;
	vargs.a_ncookies = NULL;
	vargs.a_cookies = NULL;
	while (!eofflag) {
		auio.uio_resid = DIRBLKSIZ;
		aiov.iov_base = dirbuf;
		aiov.iov_len = DIRBLKSIZ;
		error = ufs_readdir(&vargs);
		if (error) {
			printf("ufs_extattr_iterate_directory: ufs_readdir "
			    "%d\n", error);
			return (error);
		}
		edp = (struct dirent *)&dirbuf[DIRBLKSIZ - auio.uio_resid];
		for (dp = (struct dirent *)dirbuf; dp < edp; ) {
			if (dp->d_reclen == 0)
				break;
			error = ufs_extattr_lookup(dvp, UE_GETDIR_LOCKPARENT,
			    dp->d_name, &attr_vp, td);
			if (error) {
				printf("ufs_extattr_iterate_directory: lookup "
				    "%s %d\n", dp->d_name, error);
			} else if (attr_vp == dvp) {
				vrele(attr_vp);
			} else if (attr_vp->v_type != VREG) {
				vput(attr_vp);
			} else {
				error = ufs_extattr_enable_with_open(ump,
				    attr_vp, attrnamespace, dp->d_name, td);
				vrele(attr_vp);
				if (error) {
					printf("ufs_extattr_iterate_directory: "
					    "enable %s %d\n", dp->d_name,
					    error);
				} else if (bootverbose) {
					printf("UFS autostarted EA %s\n",
					    dp->d_name);
				}
			}
			dp = (struct dirent *) ((char *)dp + dp->d_reclen);
			if (dp >= edp)
				break;
		}
	}
	free(dirbuf, M_TEMP);
	return (0);
}
static int ufs_extattr_iterate_directory ( struct ufsmount * ump , struct vnode * dvp , int attrnamespace , struct thread * td ) { struct vop_readdir_args vargs ; struct dirent * dp , * edp ; struct vnode * attr_vp ; struct uio auio ; struct iovec aiov ; char * dirbuf ; int error , eofflag = 0 ; if ( dvp -> v_type != VDIR ) return ( ENOTDIR ) ; dirbuf = malloc ( DIRBLKSIZ , M_TEMP , M_WAITOK ) ; auio . uio_iov = & aiov ; auio . uio_iovcnt = 1 ; auio . uio_rw = UIO_READ ; auio . uio_segflg = UIO_SYSSPACE ; auio . uio_td = td ; auio . uio_offset = 0 ; vargs . a_gen . a_desc = NULL ; vargs . a_vp = dvp ; vargs . a_uio = & auio ; vargs . a_cred = td -> td_ucred ; vargs . a_eofflag = & eofflag ; vargs . a_ncookies = NULL ; vargs . a_cookies = NULL ; while ( ! eofflag ) { auio . uio_resid = DIRBLKSIZ ; aiov . iov_base = dirbuf ; aiov . iov_len = DIRBLKSIZ ; error = ufs_readdir ( & vargs ) ; if ( error ) { printf ( " " " \n " , error ) ; return ( error ) ; } edp = ( struct dirent * ) & dirbuf [ DIRBLKSIZ - auio . uio_resid ] ; for ( dp = ( struct dirent * ) dirbuf ; dp < edp ; ) { if ( dp -> d_reclen == 0 ) break ; error = ufs_extattr_lookup ( dvp , UE_GETDIR_LOCKPARENT , dp -> d_name , & attr_vp , td ) ; if ( error ) { printf ( " " " \n " , dp -> d_name , error ) ; } else if ( attr_vp == dvp ) { vrele ( attr_vp ) ; } else if ( attr_vp -> v_type != VREG ) { vput ( attr_vp ) ; } else { error = ufs_extattr_enable_with_open ( ump , attr_vp , attrnamespace , dp -> d_name , td ) ; vrele ( attr_vp ) ; if ( error ) { printf ( " " " \n " , dp -> d_name , error ) ; } else if ( bootverbose ) { printf ( " \n " , dp -> d_name ) ; } } dp = ( struct dirent * ) ( ( char * ) dp + dp -> d_reclen ) ; if ( dp >= edp ) break ; } } free ( dirbuf , M_TEMP ) ; return ( 0 ) ; }
Given a locked directory vnode, iterate over the names in the directory
 and use ufs_extattr_lookup() to retrieve locked vnodes of potential
 attribute files.
Given a locked directory vnode iterate over the names in the directory and use ufs_extattr_lookup () to retrieve locked vnodes of potential attribute files .