FreeBSD/sys/kern/vfs_extattr.c
/*-
 * Retrieve a list of extended attributes on a file or directory.
 *
 * Arguments: unlocked vnode "vp", attribute namespace 'attrnamespace",
 *            userspace buffer pointer "data", buffer length "nbytes",
 *            thread "td".
 * Returns: 0 on success, an error number otherwise
 * Locks: none
 * References: vp must be a valid reference for the duration of the call
 */
Retrieve a list of extended attributes on a file or directory.
Retrieve a list of extended attributes on a file or directory .
static int
extattr_list_vp(struct vnode *vp, int attrnamespace, void *data,
    size_t nbytes, struct thread *td)
{
	struct uio auio, *auiop;
	size_t size, *sizep;
	struct iovec aiov;
	ssize_t cnt;
	int error;
	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
	auiop = NULL;
	sizep = NULL;
	cnt = 0;
	if (data != NULL) {
		aiov.iov_base = data;
		aiov.iov_len = nbytes;
		auio.uio_iov = &aiov;
		auio.uio_iovcnt = 1;
		auio.uio_offset = 0;
		if (nbytes > IOSIZE_MAX) {
			error = EINVAL;
			goto done;
		}
		auio.uio_resid = nbytes;
		auio.uio_rw = UIO_READ;
		auio.uio_segflg = UIO_USERSPACE;
		auio.uio_td = td;
		auiop = &auio;
		cnt = nbytes;
	} else
		sizep = &size;
#ifdef MAC
	error = mac_vnode_check_listextattr(td->td_ucred, vp, attrnamespace);
	if (error)
		goto done;
#endif
	error = VOP_LISTEXTATTR(vp, attrnamespace, auiop, sizep,
	    td->td_ucred, td);
	if (auiop != NULL) {
		cnt -= auio.uio_resid;
		td->td_retval[0] = cnt;
	} else
		td->td_retval[0] = size;
done:
	VOP_UNLOCK(vp, 0);
	return (error);
}
static int extattr_list_vp ( struct vnode * vp , int attrnamespace , void * data , size_t nbytes , struct thread * td ) { struct uio auio , * auiop ; size_t size , * sizep ; struct iovec aiov ; ssize_t cnt ; int error ; vn_lock ( vp , LK_EXCLUSIVE | LK_RETRY ) ; auiop = NULL ; sizep = NULL ; cnt = 0 ; if ( data != NULL ) { aiov . iov_base = data ; aiov . iov_len = nbytes ; auio . uio_iov = & aiov ; auio . uio_iovcnt = 1 ; auio . uio_offset = 0 ; if ( nbytes > IOSIZE_MAX ) { error = EINVAL ; goto done ; } auio . uio_resid = nbytes ; auio . uio_rw = UIO_READ ; auio . uio_segflg = UIO_USERSPACE ; auio . uio_td = td ; auiop = & auio ; cnt = nbytes ; } else sizep = & size ; #ifdef MAC error = mac_vnode_check_listextattr ( td -> td_ucred , vp , attrnamespace ) ; if ( error ) goto done ; #endif error = VOP_LISTEXTATTR ( vp , attrnamespace , auiop , sizep , td -> td_ucred , td ) ; if ( auiop != NULL ) { cnt -= auio . uio_resid ; td -> td_retval [ 0 ] = cnt ; } else td -> td_retval [ 0 ] = size ; done : VOP_UNLOCK ( vp , 0 ) ; return ( error ) ; }
Retrieve a list of extended attributes on a file or directory.
Retrieve a list of extended attributes on a file or directory .