Home | History | Annotate | Line # | Download | only in kern
vfs_xattr.c revision 1.1
      1  1.1  thorpej /*	$NetBSD: vfs_xattr.c,v 1.1 2005/07/09 01:05:24 thorpej Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*
      4  1.1  thorpej  * Copyright (c) 1989, 1993
      5  1.1  thorpej  *	The Regents of the University of California.  All rights reserved.
      6  1.1  thorpej  * (c) UNIX System Laboratories, Inc.
      7  1.1  thorpej  * All or some portions of this file are derived from material licensed
      8  1.1  thorpej  * to the University of California by American Telephone and Telegraph
      9  1.1  thorpej  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     10  1.1  thorpej  * the permission of UNIX System Laboratories, Inc.
     11  1.1  thorpej  *
     12  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     13  1.1  thorpej  * modification, are permitted provided that the following conditions
     14  1.1  thorpej  * are met:
     15  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     16  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     17  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     19  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     20  1.1  thorpej  * 3. Neither the name of the University nor the names of its contributors
     21  1.1  thorpej  *    may be used to endorse or promote products derived from this software
     22  1.1  thorpej  *    without specific prior written permission.
     23  1.1  thorpej  *
     24  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1  thorpej  * SUCH DAMAGE.
     35  1.1  thorpej  */
     36  1.1  thorpej 
     37  1.1  thorpej /*
     38  1.1  thorpej  * VFS extended attribute support.
     39  1.1  thorpej  */
     40  1.1  thorpej 
     41  1.1  thorpej #include <sys/cdefs.h>
     42  1.1  thorpej __KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.1 2005/07/09 01:05:24 thorpej Exp $");
     43  1.1  thorpej 
     44  1.1  thorpej #include <sys/param.h>
     45  1.1  thorpej #include <sys/systm.h>
     46  1.1  thorpej #include <sys/namei.h>
     47  1.1  thorpej #include <sys/filedesc.h>
     48  1.1  thorpej #include <sys/kernel.h>
     49  1.1  thorpej #include <sys/file.h>
     50  1.1  thorpej #include <sys/vnode.h>
     51  1.1  thorpej #include <sys/mount.h>
     52  1.1  thorpej #include <sys/proc.h>
     53  1.1  thorpej #include <sys/uio.h>
     54  1.1  thorpej #include <sys/extattr.h>
     55  1.1  thorpej #include <sys/sysctl.h>
     56  1.1  thorpej #include <sys/sa.h>
     57  1.1  thorpej #include <sys/syscallargs.h>
     58  1.1  thorpej 
     59  1.1  thorpej /*
     60  1.1  thorpej  * Push extended attribute configuration information into the VFS.
     61  1.1  thorpej  *
     62  1.1  thorpej  * NOTE: Not all file systems that support extended attributes will
     63  1.1  thorpej  * require the use of this system call.
     64  1.1  thorpej  */
     65  1.1  thorpej int
     66  1.1  thorpej sys_extattrctl(struct lwp *l, void *v, register_t *retval)
     67  1.1  thorpej {
     68  1.1  thorpej 	struct sys_extattrctl_args /* {
     69  1.1  thorpej 		syscallarg(const char *) path;
     70  1.1  thorpej 		syscallarg(int) cmd;
     71  1.1  thorpej 		syscallarg(const char *) filename;
     72  1.1  thorpej 		syscallarg(int) attrnamespace;
     73  1.1  thorpej 		syscallarg(const char *) attrname;
     74  1.1  thorpej 	} */ *uap = v;
     75  1.1  thorpej 	struct proc *p = l->l_proc;
     76  1.1  thorpej 	struct vnode *vp;
     77  1.1  thorpej 	struct nameidata nd;
     78  1.1  thorpej 	struct mount *mp;
     79  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
     80  1.1  thorpej 	int error;
     81  1.1  thorpej 
     82  1.1  thorpej 	if (SCARG(uap, attrname) != NULL) {
     83  1.1  thorpej 		error = copyinstr(SCARG(uap, attrname), attrname,
     84  1.1  thorpej 		    sizeof(attrname), NULL);
     85  1.1  thorpej 		if (error)
     86  1.1  thorpej 			return (error);
     87  1.1  thorpej 	}
     88  1.1  thorpej 
     89  1.1  thorpej 	vp = NULL;
     90  1.1  thorpej 	if (SCARG(uap, filename) != NULL) {
     91  1.1  thorpej 		NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
     92  1.1  thorpej 		    SCARG(uap, filename), p);
     93  1.1  thorpej 		error = namei(&nd);
     94  1.1  thorpej 		if (error)
     95  1.1  thorpej 			return (error);
     96  1.1  thorpej 		vp = nd.ni_vp;
     97  1.1  thorpej 	}
     98  1.1  thorpej 
     99  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    100  1.1  thorpej 	error = namei(&nd);
    101  1.1  thorpej 	if (error) {
    102  1.1  thorpej 		if (vp != NULL)
    103  1.1  thorpej 			vput(vp);
    104  1.1  thorpej 		return (error);
    105  1.1  thorpej 	}
    106  1.1  thorpej 
    107  1.1  thorpej 	error = vn_start_write(nd.ni_vp, &mp, V_WAIT | V_PCATCH);
    108  1.1  thorpej 	if (error) {
    109  1.1  thorpej 		if (vp != NULL)
    110  1.1  thorpej 			vput(vp);
    111  1.1  thorpej 		return (error);
    112  1.1  thorpej 	}
    113  1.1  thorpej 
    114  1.1  thorpej 	error = VFS_EXTATTRCTL(mp, SCARG(uap, cmd), vp,
    115  1.1  thorpej 	    SCARG(uap, attrnamespace),
    116  1.1  thorpej 	    SCARG(uap, attrname) != NULL ? attrname : NULL, p);
    117  1.1  thorpej 
    118  1.1  thorpej 	vn_finished_write(mp, 0);
    119  1.1  thorpej 
    120  1.1  thorpej 	if (vp != NULL)
    121  1.1  thorpej 		vrele(vp);
    122  1.1  thorpej 
    123  1.1  thorpej 	return (error);
    124  1.1  thorpej }
    125  1.1  thorpej 
    126  1.1  thorpej /*****************************************************************************
    127  1.1  thorpej  * Internal routines to manipulate file system extended attributes:
    128  1.1  thorpej  *	- set
    129  1.1  thorpej  *	- get
    130  1.1  thorpej  *	- delete
    131  1.1  thorpej  *	- list
    132  1.1  thorpej  *****************************************************************************/
    133  1.1  thorpej 
    134  1.1  thorpej /*
    135  1.1  thorpej  * extattr_set_vp:
    136  1.1  thorpej  *
    137  1.1  thorpej  *	Set a named extended attribute on a file or directory.
    138  1.1  thorpej  */
    139  1.1  thorpej static int
    140  1.1  thorpej extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    141  1.1  thorpej     const void *data, size_t nbytes, struct proc *p, register_t *retval)
    142  1.1  thorpej {
    143  1.1  thorpej 	struct mount *mp;
    144  1.1  thorpej 	struct uio auio;
    145  1.1  thorpej 	struct iovec aiov;
    146  1.1  thorpej 	ssize_t cnt;
    147  1.1  thorpej 	int error;
    148  1.1  thorpej 
    149  1.1  thorpej 	error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
    150  1.1  thorpej 	if (error)
    151  1.1  thorpej 		return (error);
    152  1.1  thorpej 	VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
    153  1.1  thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    154  1.1  thorpej 
    155  1.1  thorpej 	aiov.iov_base = __UNCONST(data);	/* XXXUNCONST kills const */
    156  1.1  thorpej 	aiov.iov_len = nbytes;
    157  1.1  thorpej 	auio.uio_iov = &aiov;
    158  1.1  thorpej 	auio.uio_iovcnt = 1;
    159  1.1  thorpej 	auio.uio_offset = 0;
    160  1.1  thorpej 	if (nbytes > INT_MAX) {
    161  1.1  thorpej 		error = EINVAL;
    162  1.1  thorpej 		goto done;
    163  1.1  thorpej 	}
    164  1.1  thorpej 	auio.uio_resid = nbytes;
    165  1.1  thorpej 	auio.uio_rw = UIO_WRITE;
    166  1.1  thorpej 	auio.uio_segflg = UIO_USERSPACE;
    167  1.1  thorpej 	auio.uio_procp = p;
    168  1.1  thorpej 	cnt = nbytes;
    169  1.1  thorpej 
    170  1.1  thorpej 	error = VOP_SETEXTATTR(vp, attrnamespace, attrname, &auio,
    171  1.1  thorpej 	    p->p_ucred, p);
    172  1.1  thorpej 	cnt -= auio.uio_resid;
    173  1.1  thorpej 	retval[0] = cnt;
    174  1.1  thorpej 
    175  1.1  thorpej  done:
    176  1.1  thorpej 	VOP_UNLOCK(vp, 0);
    177  1.1  thorpej 	vn_finished_write(mp, 0);
    178  1.1  thorpej 	return (error);
    179  1.1  thorpej }
    180  1.1  thorpej 
    181  1.1  thorpej /*
    182  1.1  thorpej  * extattr_get_vp:
    183  1.1  thorpej  *
    184  1.1  thorpej  *	Get a named extended attribute on a file or directory.
    185  1.1  thorpej  */
    186  1.1  thorpej static int
    187  1.1  thorpej extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    188  1.1  thorpej     void *data, size_t nbytes, struct proc *p, register_t *retval)
    189  1.1  thorpej {
    190  1.1  thorpej 	struct uio auio, *auiop;
    191  1.1  thorpej 	struct iovec aiov;
    192  1.1  thorpej 	ssize_t cnt;
    193  1.1  thorpej 	size_t size, *sizep;
    194  1.1  thorpej 	int error;
    195  1.1  thorpej 
    196  1.1  thorpej 	VOP_LEASE(vp, p, p->p_ucred, LEASE_READ);
    197  1.1  thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    198  1.1  thorpej 
    199  1.1  thorpej 	/*
    200  1.1  thorpej 	 * Slightly unusual semantics: if the user provides a NULL data
    201  1.1  thorpej 	 * pointer, they don't want to receive the data, just the maximum
    202  1.1  thorpej 	 * read length.
    203  1.1  thorpej 	 */
    204  1.1  thorpej 	auiop = NULL;
    205  1.1  thorpej 	sizep = NULL;
    206  1.1  thorpej 	cnt = 0;
    207  1.1  thorpej 	if (data != NULL) {
    208  1.1  thorpej 		aiov.iov_base = data;
    209  1.1  thorpej 		aiov.iov_len = nbytes;
    210  1.1  thorpej 		auio.uio_iov = &aiov;
    211  1.1  thorpej 		auio.uio_offset = 0;
    212  1.1  thorpej 		if (nbytes > INT_MAX) {
    213  1.1  thorpej 			error = EINVAL;
    214  1.1  thorpej 			goto done;
    215  1.1  thorpej 		}
    216  1.1  thorpej 		auio.uio_resid = nbytes;
    217  1.1  thorpej 		auio.uio_rw = UIO_READ;
    218  1.1  thorpej 		auio.uio_segflg = UIO_USERSPACE;
    219  1.1  thorpej 		auio.uio_procp = p;
    220  1.1  thorpej 		auiop = &auio;
    221  1.1  thorpej 		cnt = nbytes;
    222  1.1  thorpej 	} else
    223  1.1  thorpej 		sizep = &size;
    224  1.1  thorpej 
    225  1.1  thorpej 	error = VOP_GETEXTATTR(vp, attrnamespace, attrname, auiop, sizep,
    226  1.1  thorpej 	    p->p_ucred, p);
    227  1.1  thorpej 
    228  1.1  thorpej 	if (auiop != NULL) {
    229  1.1  thorpej 		cnt -= auio.uio_resid;
    230  1.1  thorpej 		retval[0] = cnt;
    231  1.1  thorpej 	} else
    232  1.1  thorpej 		retval[0] = size;
    233  1.1  thorpej 
    234  1.1  thorpej  done:
    235  1.1  thorpej 	VOP_UNLOCK(vp, 0);
    236  1.1  thorpej 	return (error);
    237  1.1  thorpej }
    238  1.1  thorpej 
    239  1.1  thorpej /*
    240  1.1  thorpej  * extattr_delete_vp:
    241  1.1  thorpej  *
    242  1.1  thorpej  *	Delete a named extended attribute on a file or directory.
    243  1.1  thorpej  */
    244  1.1  thorpej static int
    245  1.1  thorpej extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    246  1.1  thorpej     struct proc *p)
    247  1.1  thorpej {
    248  1.1  thorpej 	struct mount *mp;
    249  1.1  thorpej 	int error;
    250  1.1  thorpej 
    251  1.1  thorpej 	error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
    252  1.1  thorpej 	if (error)
    253  1.1  thorpej 		return (error);
    254  1.1  thorpej 	VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
    255  1.1  thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    256  1.1  thorpej 
    257  1.1  thorpej 	error = VOP_DELETEEXTATTR(vp, attrnamespace, attrname, p->p_ucred, p);
    258  1.1  thorpej 	if (error == EOPNOTSUPP)
    259  1.1  thorpej 		error = VOP_SETEXTATTR(vp, attrnamespace, attrname, NULL,
    260  1.1  thorpej 		    p->p_ucred, p);
    261  1.1  thorpej 
    262  1.1  thorpej 	VOP_UNLOCK(vp, 0);
    263  1.1  thorpej 	vn_finished_write(mp, 0);
    264  1.1  thorpej 	return (error);
    265  1.1  thorpej }
    266  1.1  thorpej 
    267  1.1  thorpej /*
    268  1.1  thorpej  * extattr_list_vp:
    269  1.1  thorpej  *
    270  1.1  thorpej  *	Retrieve a list of extended attributes on a file or directory.
    271  1.1  thorpej  */
    272  1.1  thorpej static int
    273  1.1  thorpej extattr_list_vp(struct vnode *vp, int attrnamespace, void *data, size_t nbytes,
    274  1.1  thorpej     struct proc *p, register_t *retval)
    275  1.1  thorpej {
    276  1.1  thorpej 	struct uio auio, *auiop;
    277  1.1  thorpej 	size_t size, *sizep;
    278  1.1  thorpej 	struct iovec aiov;
    279  1.1  thorpej 	ssize_t cnt;
    280  1.1  thorpej 	int error;
    281  1.1  thorpej 
    282  1.1  thorpej 	VOP_LEASE(vp, p, p->p_ucred, LEASE_READ);
    283  1.1  thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    284  1.1  thorpej 
    285  1.1  thorpej 	auiop = NULL;
    286  1.1  thorpej 	sizep = NULL;
    287  1.1  thorpej 	cnt = 0;
    288  1.1  thorpej 	if (data != NULL) {
    289  1.1  thorpej 		aiov.iov_base = data;
    290  1.1  thorpej 		aiov.iov_len = nbytes;
    291  1.1  thorpej 		auio.uio_iov = &aiov;
    292  1.1  thorpej 		auio.uio_offset = 0;
    293  1.1  thorpej 		if (nbytes > INT_MAX) {
    294  1.1  thorpej 			error = EINVAL;
    295  1.1  thorpej 			goto done;
    296  1.1  thorpej 		}
    297  1.1  thorpej 		auio.uio_resid = nbytes;
    298  1.1  thorpej 		auio.uio_rw = UIO_READ;
    299  1.1  thorpej 		auio.uio_segflg = UIO_USERSPACE;
    300  1.1  thorpej 		auio.uio_procp = p;
    301  1.1  thorpej 		auiop = &auio;
    302  1.1  thorpej 		cnt = nbytes;
    303  1.1  thorpej 	} else
    304  1.1  thorpej 		sizep = &size;
    305  1.1  thorpej 
    306  1.1  thorpej 	error = VOP_LISTEXTATTR(vp, attrnamespace, auiop, sizep,
    307  1.1  thorpej 	    p->p_ucred, p);
    308  1.1  thorpej 
    309  1.1  thorpej 	if (auiop != NULL) {
    310  1.1  thorpej 		cnt -= auio.uio_resid;
    311  1.1  thorpej 		retval[0] = cnt;
    312  1.1  thorpej 	} else
    313  1.1  thorpej 		retval[0] = size;
    314  1.1  thorpej 
    315  1.1  thorpej  done:
    316  1.1  thorpej 	VOP_UNLOCK(vp, 0);
    317  1.1  thorpej 	return (error);
    318  1.1  thorpej }
    319  1.1  thorpej 
    320  1.1  thorpej /*****************************************************************************
    321  1.1  thorpej  * BSD <sys/extattr.h> API for file system extended attributes
    322  1.1  thorpej  *****************************************************************************/
    323  1.1  thorpej 
    324  1.1  thorpej int
    325  1.1  thorpej sys_extattr_set_fd(struct lwp *l, void *v, register_t *retval)
    326  1.1  thorpej {
    327  1.1  thorpej 	struct sys_extattr_set_fd_args /* {
    328  1.1  thorpej 		syscallarg(int) fd;
    329  1.1  thorpej 		syscallarg(int) attrnamespace;
    330  1.1  thorpej 		syscallarg(const char *) attrname;
    331  1.1  thorpej 		syscallarg(const void *) data;
    332  1.1  thorpej 		syscallarg(size_t) nbytes;
    333  1.1  thorpej 	} */ *uap = v;
    334  1.1  thorpej 	struct proc *p = l->l_proc;
    335  1.1  thorpej 	struct file *fp;
    336  1.1  thorpej 	struct vnode *vp;
    337  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    338  1.1  thorpej 	int error;
    339  1.1  thorpej 
    340  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    341  1.1  thorpej 	    NULL);
    342  1.1  thorpej 	if (error)
    343  1.1  thorpej 		return (error);
    344  1.1  thorpej 
    345  1.1  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    346  1.1  thorpej 	if (error)
    347  1.1  thorpej 		return (error);
    348  1.1  thorpej 	vp = (struct vnode *) fp->f_data;
    349  1.1  thorpej 
    350  1.1  thorpej 	error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
    351  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    352  1.1  thorpej 
    353  1.1  thorpej 	FILE_UNUSE(fp, p);
    354  1.1  thorpej 	return (error);
    355  1.1  thorpej }
    356  1.1  thorpej 
    357  1.1  thorpej int
    358  1.1  thorpej sys_extattr_set_file(struct lwp *l, void *v, register_t *retval)
    359  1.1  thorpej {
    360  1.1  thorpej 	struct sys_extattr_set_file_args /* {
    361  1.1  thorpej 		syscallarg(const char *) path;
    362  1.1  thorpej 		syscallarg(int) attrnamespace;
    363  1.1  thorpej 		syscallarg(const char *) attrname;
    364  1.1  thorpej 		syscallarg(const void *) data;
    365  1.1  thorpej 		syscallarg(size_t) nbytes;
    366  1.1  thorpej 	} */ *uap = v;
    367  1.1  thorpej 	struct proc *p = l->l_proc;
    368  1.1  thorpej 	struct nameidata nd;
    369  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    370  1.1  thorpej 	int error;
    371  1.1  thorpej 
    372  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    373  1.1  thorpej 	    NULL);
    374  1.1  thorpej 	if (error)
    375  1.1  thorpej 		return (error);
    376  1.1  thorpej 
    377  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    378  1.1  thorpej 	error = namei(&nd);
    379  1.1  thorpej 	if (error)
    380  1.1  thorpej 		return (error);
    381  1.1  thorpej 
    382  1.1  thorpej 	error = extattr_set_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    383  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    384  1.1  thorpej 
    385  1.1  thorpej 	vrele(nd.ni_vp);
    386  1.1  thorpej 	return (error);
    387  1.1  thorpej }
    388  1.1  thorpej 
    389  1.1  thorpej int
    390  1.1  thorpej sys_extattr_set_link(struct lwp *l, void *v, register_t *retval)
    391  1.1  thorpej {
    392  1.1  thorpej 	struct sys_extattr_set_link_args /* {
    393  1.1  thorpej 		syscallarg(const char *) path;
    394  1.1  thorpej 		syscallarg(int) attrnamespace;
    395  1.1  thorpej 		syscallarg(const char *) attrname;
    396  1.1  thorpej 		syscallarg(const void *) data;
    397  1.1  thorpej 		syscallarg(size_t) nbytes;
    398  1.1  thorpej 	} */ *uap = v;
    399  1.1  thorpej 	struct proc *p = l->l_proc;
    400  1.1  thorpej 	struct nameidata nd;
    401  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    402  1.1  thorpej 	int error;
    403  1.1  thorpej 
    404  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    405  1.1  thorpej 	    NULL);
    406  1.1  thorpej 	if (error)
    407  1.1  thorpej 		return (error);
    408  1.1  thorpej 
    409  1.1  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    410  1.1  thorpej 	error = namei(&nd);
    411  1.1  thorpej 	if (error)
    412  1.1  thorpej 		return (error);
    413  1.1  thorpej 
    414  1.1  thorpej 	error = extattr_set_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    415  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    416  1.1  thorpej 
    417  1.1  thorpej 	vrele(nd.ni_vp);
    418  1.1  thorpej 	return (error);
    419  1.1  thorpej }
    420  1.1  thorpej 
    421  1.1  thorpej int
    422  1.1  thorpej sys_extattr_get_fd(struct lwp *l, void *v, register_t *retval)
    423  1.1  thorpej {
    424  1.1  thorpej 	struct sys_extattr_get_fd_args /* {
    425  1.1  thorpej 		syscallarg(int) fd;
    426  1.1  thorpej 		syscallarg(int) attrnamespace;
    427  1.1  thorpej 		syscallarg(const char *) attrname;
    428  1.1  thorpej 		syscallarg(void *) data;
    429  1.1  thorpej 		syscallarg(size_t) nbytes;
    430  1.1  thorpej 	} */ *uap = v;
    431  1.1  thorpej 	struct proc *p = l->l_proc;
    432  1.1  thorpej 	struct file *fp;
    433  1.1  thorpej 	struct vnode *vp;
    434  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    435  1.1  thorpej 	int error;
    436  1.1  thorpej 
    437  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    438  1.1  thorpej 	    NULL);
    439  1.1  thorpej 	if (error)
    440  1.1  thorpej 		return (error);
    441  1.1  thorpej 
    442  1.1  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    443  1.1  thorpej 	if (error)
    444  1.1  thorpej 		return (error);
    445  1.1  thorpej 	vp = (struct vnode *) fp->f_data;
    446  1.1  thorpej 
    447  1.1  thorpej 	error = extattr_get_vp(vp, SCARG(uap, attrnamespace), attrname,
    448  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    449  1.1  thorpej 
    450  1.1  thorpej 	FILE_UNUSE(fp, p);
    451  1.1  thorpej 	return (error);
    452  1.1  thorpej }
    453  1.1  thorpej 
    454  1.1  thorpej int
    455  1.1  thorpej sys_extattr_get_file(struct lwp *l, void *v, register_t *retval)
    456  1.1  thorpej {
    457  1.1  thorpej 	struct sys_extattr_get_file_args /* {
    458  1.1  thorpej 		syscallarg(const char *) path;
    459  1.1  thorpej 		syscallarg(int) attrnamespace;
    460  1.1  thorpej 		syscallarg(const char *) attrname;
    461  1.1  thorpej 		syscallarg(void *) data;
    462  1.1  thorpej 		syscallarg(size_t) nbytes;
    463  1.1  thorpej 	} */ *uap = v;
    464  1.1  thorpej 	struct proc *p = l->l_proc;
    465  1.1  thorpej 	struct nameidata nd;
    466  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    467  1.1  thorpej 	int error;
    468  1.1  thorpej 
    469  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    470  1.1  thorpej 	    NULL);
    471  1.1  thorpej 	if (error)
    472  1.1  thorpej 		return (error);
    473  1.1  thorpej 
    474  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    475  1.1  thorpej 	error = namei(&nd);
    476  1.1  thorpej 	if (error)
    477  1.1  thorpej 		return (error);
    478  1.1  thorpej 
    479  1.1  thorpej 	error = extattr_get_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    480  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    481  1.1  thorpej 
    482  1.1  thorpej 	vrele(nd.ni_vp);
    483  1.1  thorpej 	return (error);
    484  1.1  thorpej }
    485  1.1  thorpej 
    486  1.1  thorpej int
    487  1.1  thorpej sys_extattr_get_link(struct lwp *l, void *v, register_t *retval)
    488  1.1  thorpej {
    489  1.1  thorpej 	struct sys_extattr_get_link_args /* {
    490  1.1  thorpej 		syscallarg(const char *) path;
    491  1.1  thorpej 		syscallarg(int) attrnamespace;
    492  1.1  thorpej 		syscallarg(const char *) attrname;
    493  1.1  thorpej 		syscallarg(void *) data;
    494  1.1  thorpej 		syscallarg(size_t) nbytes;
    495  1.1  thorpej 	} */ *uap = v;
    496  1.1  thorpej 	struct proc *p = l->l_proc;
    497  1.1  thorpej 	struct nameidata nd;
    498  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    499  1.1  thorpej 	int error;
    500  1.1  thorpej 
    501  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    502  1.1  thorpej 	    NULL);
    503  1.1  thorpej 	if (error)
    504  1.1  thorpej 		return (error);
    505  1.1  thorpej 
    506  1.1  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    507  1.1  thorpej 	error = namei(&nd);
    508  1.1  thorpej 	if (error)
    509  1.1  thorpej 		return (error);
    510  1.1  thorpej 
    511  1.1  thorpej 	error = extattr_get_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    512  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    513  1.1  thorpej 
    514  1.1  thorpej 	vrele(nd.ni_vp);
    515  1.1  thorpej 	return (error);
    516  1.1  thorpej }
    517  1.1  thorpej 
    518  1.1  thorpej int
    519  1.1  thorpej sys_extattr_delete_fd(struct lwp *l, void *v, register_t *retval)
    520  1.1  thorpej {
    521  1.1  thorpej 	struct sys_extattr_delete_fd_args /* {
    522  1.1  thorpej 		syscallarg(int) fd;
    523  1.1  thorpej 		syscallarg(int) attrnamespace;
    524  1.1  thorpej 		syscallarg(const char *) attrname;
    525  1.1  thorpej 	} */ *uap = v;
    526  1.1  thorpej 	struct proc *p = l->l_proc;
    527  1.1  thorpej 	struct file *fp;
    528  1.1  thorpej 	struct vnode *vp;
    529  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    530  1.1  thorpej 	int error;
    531  1.1  thorpej 
    532  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    533  1.1  thorpej 	    NULL);
    534  1.1  thorpej 	if (error)
    535  1.1  thorpej 		return (error);
    536  1.1  thorpej 
    537  1.1  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    538  1.1  thorpej 	if (error)
    539  1.1  thorpej 		return (error);
    540  1.1  thorpej 	vp = (struct vnode *) fp->f_data;
    541  1.1  thorpej 
    542  1.1  thorpej 	error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, p);
    543  1.1  thorpej 
    544  1.1  thorpej 	FILE_UNUSE(fp, p);
    545  1.1  thorpej 	return (error);
    546  1.1  thorpej }
    547  1.1  thorpej 
    548  1.1  thorpej int
    549  1.1  thorpej sys_extattr_delete_file(struct lwp *l, void *v, register_t *retval)
    550  1.1  thorpej {
    551  1.1  thorpej 	struct sys_extattr_delete_file_args /* {
    552  1.1  thorpej 		syscallarg(const char *) path;
    553  1.1  thorpej 		syscallarg(int) attrnamespace;
    554  1.1  thorpej 		syscallarg(const char *) attrname;
    555  1.1  thorpej 	} */ *uap = v;
    556  1.1  thorpej 	struct proc *p = l->l_proc;
    557  1.1  thorpej 	struct nameidata nd;
    558  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    559  1.1  thorpej 	int error;
    560  1.1  thorpej 
    561  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    562  1.1  thorpej 	    NULL);
    563  1.1  thorpej 	if (error)
    564  1.1  thorpej 		return (error);
    565  1.1  thorpej 
    566  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    567  1.1  thorpej 	error = namei(&nd);
    568  1.1  thorpej 	if (error)
    569  1.1  thorpej 		return (error);
    570  1.1  thorpej 
    571  1.1  thorpej 	error = extattr_delete_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    572  1.1  thorpej 	    p);
    573  1.1  thorpej 
    574  1.1  thorpej 	vrele(nd.ni_vp);
    575  1.1  thorpej 	return (error);
    576  1.1  thorpej }
    577  1.1  thorpej 
    578  1.1  thorpej int
    579  1.1  thorpej sys_extattr_delete_link(struct lwp *l, void *v, register_t *retval)
    580  1.1  thorpej {
    581  1.1  thorpej 	struct sys_extattr_delete_link_args /* {
    582  1.1  thorpej 		syscallarg(const char *) path;
    583  1.1  thorpej 		syscallarg(int) attrnamespace;
    584  1.1  thorpej 		syscallarg(const char *) attrname;
    585  1.1  thorpej 	} */ *uap = v;
    586  1.1  thorpej 	struct proc *p = l->l_proc;
    587  1.1  thorpej 	struct nameidata nd;
    588  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    589  1.1  thorpej 	int error;
    590  1.1  thorpej 
    591  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    592  1.1  thorpej 	    NULL);
    593  1.1  thorpej 	if (error)
    594  1.1  thorpej 		return (error);
    595  1.1  thorpej 
    596  1.1  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    597  1.1  thorpej 	error = namei(&nd);
    598  1.1  thorpej 	if (error)
    599  1.1  thorpej 		return (error);
    600  1.1  thorpej 
    601  1.1  thorpej 	error = extattr_delete_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    602  1.1  thorpej 	    p);
    603  1.1  thorpej 
    604  1.1  thorpej 	vrele(nd.ni_vp);
    605  1.1  thorpej 	return (error);
    606  1.1  thorpej }
    607  1.1  thorpej 
    608  1.1  thorpej int
    609  1.1  thorpej sys_extattr_list_fd(struct lwp *l, void *v, register_t *retval)
    610  1.1  thorpej {
    611  1.1  thorpej 	struct sys_extattr_list_fd_args /* {
    612  1.1  thorpej 		syscallarg(int) fd;
    613  1.1  thorpej 		syscallarg(int) attrnamespace;
    614  1.1  thorpej 		syscallarg(void *) data;
    615  1.1  thorpej 		syscallarg(size_t) nbytes;
    616  1.1  thorpej 	} */ *uap = v;
    617  1.1  thorpej 	struct proc *p = l->l_proc;
    618  1.1  thorpej 	struct file *fp;
    619  1.1  thorpej 	struct vnode *vp;
    620  1.1  thorpej 	int error;
    621  1.1  thorpej 
    622  1.1  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    623  1.1  thorpej 	if (error)
    624  1.1  thorpej 		return (error);
    625  1.1  thorpej 	vp = (struct vnode *) fp->f_data;
    626  1.1  thorpej 
    627  1.1  thorpej 	error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
    628  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    629  1.1  thorpej 
    630  1.1  thorpej 	FILE_UNUSE(fp, p);
    631  1.1  thorpej 	return (error);
    632  1.1  thorpej }
    633  1.1  thorpej 
    634  1.1  thorpej int
    635  1.1  thorpej sys_extattr_list_file(struct lwp *l, void *v, register_t *retval)
    636  1.1  thorpej {
    637  1.1  thorpej 	struct sys_extattr_list_file_args /* {
    638  1.1  thorpej 		syscallarg(const char *) path;
    639  1.1  thorpej 		syscallarg(int) attrnamespace;
    640  1.1  thorpej 		syscallarg(void *) data;
    641  1.1  thorpej 		syscallarg(size_t) nbytes;
    642  1.1  thorpej 	} */ *uap = v;
    643  1.1  thorpej 	struct proc *p = l->l_proc;
    644  1.1  thorpej 	struct nameidata nd;
    645  1.1  thorpej 	int error;
    646  1.1  thorpej 
    647  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    648  1.1  thorpej 	error = namei(&nd);
    649  1.1  thorpej 	if (error)
    650  1.1  thorpej 		return (error);
    651  1.1  thorpej 
    652  1.1  thorpej 	error = extattr_list_vp(nd.ni_vp, SCARG(uap, attrnamespace),
    653  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    654  1.1  thorpej 
    655  1.1  thorpej 	vrele(nd.ni_vp);
    656  1.1  thorpej 	return (error);
    657  1.1  thorpej }
    658  1.1  thorpej 
    659  1.1  thorpej int
    660  1.1  thorpej sys_extattr_list_link(struct lwp *l, void *v, register_t *retval)
    661  1.1  thorpej {
    662  1.1  thorpej 	struct sys_extattr_list_link_args /* {
    663  1.1  thorpej 		syscallarg(const char *) path;
    664  1.1  thorpej 		syscallarg(int) attrnamespace;
    665  1.1  thorpej 		syscallarg(void *) data;
    666  1.1  thorpej 		syscallarg(size_t) nbytes;
    667  1.1  thorpej 	} */ *uap = v;
    668  1.1  thorpej 	struct proc *p = l->l_proc;
    669  1.1  thorpej 	struct nameidata nd;
    670  1.1  thorpej 	int error;
    671  1.1  thorpej 
    672  1.1  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    673  1.1  thorpej 	error = namei(&nd);
    674  1.1  thorpej 	if (error)
    675  1.1  thorpej 		return (error);
    676  1.1  thorpej 
    677  1.1  thorpej 	error = extattr_list_vp(nd.ni_vp, SCARG(uap, attrnamespace),
    678  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    679  1.1  thorpej 
    680  1.1  thorpej 	vrele(nd.ni_vp);
    681  1.1  thorpej 	return (error);
    682  1.1  thorpej }
    683