Home | History | Annotate | Line # | Download | only in kern
vfs_xattr.c revision 1.2
      1  1.2  thorpej /*	$NetBSD: vfs_xattr.c,v 1.2 2005/07/10 22:04:20 thorpej Exp $	*/
      2  1.2  thorpej 
      3  1.2  thorpej /*-
      4  1.2  thorpej  * Copyright (c) 2005 The NetBSD Foundation, Inc.
      5  1.2  thorpej  * All rights reserved.
      6  1.2  thorpej  *
      7  1.2  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  thorpej  * by Jason R. Thorpe.
      9  1.2  thorpej  *
     10  1.2  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.2  thorpej  * modification, are permitted provided that the following conditions
     12  1.2  thorpej  * are met:
     13  1.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.2  thorpej  *    must display the following acknowledgement:
     20  1.2  thorpej  *	This product includes software developed by the NetBSD
     21  1.2  thorpej  *	Foundation, Inc. and its contributors.
     22  1.2  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.2  thorpej  *    from this software without specific prior written permission.
     25  1.2  thorpej  *
     26  1.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2  thorpej  */
     38  1.1  thorpej 
     39  1.1  thorpej /*
     40  1.1  thorpej  * Copyright (c) 1989, 1993
     41  1.1  thorpej  *	The Regents of the University of California.  All rights reserved.
     42  1.1  thorpej  * (c) UNIX System Laboratories, Inc.
     43  1.1  thorpej  * All or some portions of this file are derived from material licensed
     44  1.1  thorpej  * to the University of California by American Telephone and Telegraph
     45  1.1  thorpej  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     46  1.1  thorpej  * the permission of UNIX System Laboratories, Inc.
     47  1.1  thorpej  *
     48  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     49  1.1  thorpej  * modification, are permitted provided that the following conditions
     50  1.1  thorpej  * are met:
     51  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     52  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     53  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     54  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     55  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     56  1.1  thorpej  * 3. Neither the name of the University nor the names of its contributors
     57  1.1  thorpej  *    may be used to endorse or promote products derived from this software
     58  1.1  thorpej  *    without specific prior written permission.
     59  1.1  thorpej  *
     60  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62  1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63  1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64  1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65  1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66  1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67  1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68  1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69  1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70  1.1  thorpej  * SUCH DAMAGE.
     71  1.1  thorpej  */
     72  1.1  thorpej 
     73  1.1  thorpej /*
     74  1.1  thorpej  * VFS extended attribute support.
     75  1.1  thorpej  */
     76  1.1  thorpej 
     77  1.1  thorpej #include <sys/cdefs.h>
     78  1.2  thorpej __KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.2 2005/07/10 22:04:20 thorpej Exp $");
     79  1.1  thorpej 
     80  1.1  thorpej #include <sys/param.h>
     81  1.1  thorpej #include <sys/systm.h>
     82  1.1  thorpej #include <sys/namei.h>
     83  1.1  thorpej #include <sys/filedesc.h>
     84  1.1  thorpej #include <sys/kernel.h>
     85  1.1  thorpej #include <sys/file.h>
     86  1.1  thorpej #include <sys/vnode.h>
     87  1.1  thorpej #include <sys/mount.h>
     88  1.1  thorpej #include <sys/proc.h>
     89  1.1  thorpej #include <sys/uio.h>
     90  1.1  thorpej #include <sys/extattr.h>
     91  1.2  thorpej #include <sys/xattr.h>
     92  1.1  thorpej #include <sys/sysctl.h>
     93  1.1  thorpej #include <sys/sa.h>
     94  1.1  thorpej #include <sys/syscallargs.h>
     95  1.1  thorpej 
     96  1.1  thorpej /*
     97  1.2  thorpej  * Push extended attribute configuration information into the file
     98  1.2  thorpej  * system.
     99  1.1  thorpej  *
    100  1.1  thorpej  * NOTE: Not all file systems that support extended attributes will
    101  1.1  thorpej  * require the use of this system call.
    102  1.1  thorpej  */
    103  1.1  thorpej int
    104  1.1  thorpej sys_extattrctl(struct lwp *l, void *v, register_t *retval)
    105  1.1  thorpej {
    106  1.1  thorpej 	struct sys_extattrctl_args /* {
    107  1.1  thorpej 		syscallarg(const char *) path;
    108  1.1  thorpej 		syscallarg(int) cmd;
    109  1.1  thorpej 		syscallarg(const char *) filename;
    110  1.1  thorpej 		syscallarg(int) attrnamespace;
    111  1.1  thorpej 		syscallarg(const char *) attrname;
    112  1.1  thorpej 	} */ *uap = v;
    113  1.1  thorpej 	struct proc *p = l->l_proc;
    114  1.1  thorpej 	struct vnode *vp;
    115  1.1  thorpej 	struct nameidata nd;
    116  1.1  thorpej 	struct mount *mp;
    117  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    118  1.1  thorpej 	int error;
    119  1.1  thorpej 
    120  1.1  thorpej 	if (SCARG(uap, attrname) != NULL) {
    121  1.1  thorpej 		error = copyinstr(SCARG(uap, attrname), attrname,
    122  1.1  thorpej 		    sizeof(attrname), NULL);
    123  1.1  thorpej 		if (error)
    124  1.1  thorpej 			return (error);
    125  1.1  thorpej 	}
    126  1.1  thorpej 
    127  1.1  thorpej 	vp = NULL;
    128  1.1  thorpej 	if (SCARG(uap, filename) != NULL) {
    129  1.1  thorpej 		NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
    130  1.1  thorpej 		    SCARG(uap, filename), p);
    131  1.1  thorpej 		error = namei(&nd);
    132  1.1  thorpej 		if (error)
    133  1.1  thorpej 			return (error);
    134  1.1  thorpej 		vp = nd.ni_vp;
    135  1.1  thorpej 	}
    136  1.1  thorpej 
    137  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    138  1.1  thorpej 	error = namei(&nd);
    139  1.1  thorpej 	if (error) {
    140  1.1  thorpej 		if (vp != NULL)
    141  1.1  thorpej 			vput(vp);
    142  1.1  thorpej 		return (error);
    143  1.1  thorpej 	}
    144  1.1  thorpej 
    145  1.1  thorpej 	error = vn_start_write(nd.ni_vp, &mp, V_WAIT | V_PCATCH);
    146  1.1  thorpej 	if (error) {
    147  1.1  thorpej 		if (vp != NULL)
    148  1.1  thorpej 			vput(vp);
    149  1.1  thorpej 		return (error);
    150  1.1  thorpej 	}
    151  1.1  thorpej 
    152  1.1  thorpej 	error = VFS_EXTATTRCTL(mp, SCARG(uap, cmd), vp,
    153  1.1  thorpej 	    SCARG(uap, attrnamespace),
    154  1.1  thorpej 	    SCARG(uap, attrname) != NULL ? attrname : NULL, p);
    155  1.1  thorpej 
    156  1.1  thorpej 	vn_finished_write(mp, 0);
    157  1.1  thorpej 
    158  1.1  thorpej 	if (vp != NULL)
    159  1.1  thorpej 		vrele(vp);
    160  1.1  thorpej 
    161  1.1  thorpej 	return (error);
    162  1.1  thorpej }
    163  1.1  thorpej 
    164  1.1  thorpej /*****************************************************************************
    165  1.1  thorpej  * Internal routines to manipulate file system extended attributes:
    166  1.1  thorpej  *	- set
    167  1.1  thorpej  *	- get
    168  1.1  thorpej  *	- delete
    169  1.1  thorpej  *	- list
    170  1.1  thorpej  *****************************************************************************/
    171  1.1  thorpej 
    172  1.1  thorpej /*
    173  1.1  thorpej  * extattr_set_vp:
    174  1.1  thorpej  *
    175  1.1  thorpej  *	Set a named extended attribute on a file or directory.
    176  1.1  thorpej  */
    177  1.1  thorpej static int
    178  1.1  thorpej extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    179  1.1  thorpej     const void *data, size_t nbytes, struct proc *p, register_t *retval)
    180  1.1  thorpej {
    181  1.1  thorpej 	struct mount *mp;
    182  1.1  thorpej 	struct uio auio;
    183  1.1  thorpej 	struct iovec aiov;
    184  1.1  thorpej 	ssize_t cnt;
    185  1.1  thorpej 	int error;
    186  1.1  thorpej 
    187  1.1  thorpej 	error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
    188  1.1  thorpej 	if (error)
    189  1.1  thorpej 		return (error);
    190  1.1  thorpej 	VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
    191  1.1  thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    192  1.1  thorpej 
    193  1.1  thorpej 	aiov.iov_base = __UNCONST(data);	/* XXXUNCONST kills const */
    194  1.1  thorpej 	aiov.iov_len = nbytes;
    195  1.1  thorpej 	auio.uio_iov = &aiov;
    196  1.1  thorpej 	auio.uio_iovcnt = 1;
    197  1.1  thorpej 	auio.uio_offset = 0;
    198  1.1  thorpej 	if (nbytes > INT_MAX) {
    199  1.1  thorpej 		error = EINVAL;
    200  1.1  thorpej 		goto done;
    201  1.1  thorpej 	}
    202  1.1  thorpej 	auio.uio_resid = nbytes;
    203  1.1  thorpej 	auio.uio_rw = UIO_WRITE;
    204  1.1  thorpej 	auio.uio_segflg = UIO_USERSPACE;
    205  1.1  thorpej 	auio.uio_procp = p;
    206  1.1  thorpej 	cnt = nbytes;
    207  1.1  thorpej 
    208  1.1  thorpej 	error = VOP_SETEXTATTR(vp, attrnamespace, attrname, &auio,
    209  1.1  thorpej 	    p->p_ucred, p);
    210  1.1  thorpej 	cnt -= auio.uio_resid;
    211  1.1  thorpej 	retval[0] = cnt;
    212  1.1  thorpej 
    213  1.1  thorpej  done:
    214  1.1  thorpej 	VOP_UNLOCK(vp, 0);
    215  1.1  thorpej 	vn_finished_write(mp, 0);
    216  1.1  thorpej 	return (error);
    217  1.1  thorpej }
    218  1.1  thorpej 
    219  1.1  thorpej /*
    220  1.1  thorpej  * extattr_get_vp:
    221  1.1  thorpej  *
    222  1.1  thorpej  *	Get a named extended attribute on a file or directory.
    223  1.1  thorpej  */
    224  1.1  thorpej static int
    225  1.1  thorpej extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    226  1.1  thorpej     void *data, size_t nbytes, struct proc *p, register_t *retval)
    227  1.1  thorpej {
    228  1.1  thorpej 	struct uio auio, *auiop;
    229  1.1  thorpej 	struct iovec aiov;
    230  1.1  thorpej 	ssize_t cnt;
    231  1.1  thorpej 	size_t size, *sizep;
    232  1.1  thorpej 	int error;
    233  1.1  thorpej 
    234  1.1  thorpej 	VOP_LEASE(vp, p, p->p_ucred, LEASE_READ);
    235  1.1  thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    236  1.1  thorpej 
    237  1.1  thorpej 	/*
    238  1.1  thorpej 	 * Slightly unusual semantics: if the user provides a NULL data
    239  1.1  thorpej 	 * pointer, they don't want to receive the data, just the maximum
    240  1.1  thorpej 	 * read length.
    241  1.1  thorpej 	 */
    242  1.1  thorpej 	auiop = NULL;
    243  1.1  thorpej 	sizep = NULL;
    244  1.1  thorpej 	cnt = 0;
    245  1.1  thorpej 	if (data != NULL) {
    246  1.1  thorpej 		aiov.iov_base = data;
    247  1.1  thorpej 		aiov.iov_len = nbytes;
    248  1.1  thorpej 		auio.uio_iov = &aiov;
    249  1.1  thorpej 		auio.uio_offset = 0;
    250  1.1  thorpej 		if (nbytes > INT_MAX) {
    251  1.1  thorpej 			error = EINVAL;
    252  1.1  thorpej 			goto done;
    253  1.1  thorpej 		}
    254  1.1  thorpej 		auio.uio_resid = nbytes;
    255  1.1  thorpej 		auio.uio_rw = UIO_READ;
    256  1.1  thorpej 		auio.uio_segflg = UIO_USERSPACE;
    257  1.1  thorpej 		auio.uio_procp = p;
    258  1.1  thorpej 		auiop = &auio;
    259  1.1  thorpej 		cnt = nbytes;
    260  1.1  thorpej 	} else
    261  1.1  thorpej 		sizep = &size;
    262  1.1  thorpej 
    263  1.1  thorpej 	error = VOP_GETEXTATTR(vp, attrnamespace, attrname, auiop, sizep,
    264  1.1  thorpej 	    p->p_ucred, p);
    265  1.1  thorpej 
    266  1.1  thorpej 	if (auiop != NULL) {
    267  1.1  thorpej 		cnt -= auio.uio_resid;
    268  1.1  thorpej 		retval[0] = cnt;
    269  1.1  thorpej 	} else
    270  1.1  thorpej 		retval[0] = size;
    271  1.1  thorpej 
    272  1.1  thorpej  done:
    273  1.1  thorpej 	VOP_UNLOCK(vp, 0);
    274  1.1  thorpej 	return (error);
    275  1.1  thorpej }
    276  1.1  thorpej 
    277  1.1  thorpej /*
    278  1.1  thorpej  * extattr_delete_vp:
    279  1.1  thorpej  *
    280  1.1  thorpej  *	Delete a named extended attribute on a file or directory.
    281  1.1  thorpej  */
    282  1.1  thorpej static int
    283  1.1  thorpej extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    284  1.1  thorpej     struct proc *p)
    285  1.1  thorpej {
    286  1.1  thorpej 	struct mount *mp;
    287  1.1  thorpej 	int error;
    288  1.1  thorpej 
    289  1.1  thorpej 	error = vn_start_write(vp, &mp, V_WAIT | V_PCATCH);
    290  1.1  thorpej 	if (error)
    291  1.1  thorpej 		return (error);
    292  1.1  thorpej 	VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
    293  1.1  thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    294  1.1  thorpej 
    295  1.1  thorpej 	error = VOP_DELETEEXTATTR(vp, attrnamespace, attrname, p->p_ucred, p);
    296  1.1  thorpej 	if (error == EOPNOTSUPP)
    297  1.1  thorpej 		error = VOP_SETEXTATTR(vp, attrnamespace, attrname, NULL,
    298  1.1  thorpej 		    p->p_ucred, p);
    299  1.1  thorpej 
    300  1.1  thorpej 	VOP_UNLOCK(vp, 0);
    301  1.1  thorpej 	vn_finished_write(mp, 0);
    302  1.1  thorpej 	return (error);
    303  1.1  thorpej }
    304  1.1  thorpej 
    305  1.1  thorpej /*
    306  1.1  thorpej  * extattr_list_vp:
    307  1.1  thorpej  *
    308  1.1  thorpej  *	Retrieve a list of extended attributes on a file or directory.
    309  1.1  thorpej  */
    310  1.1  thorpej static int
    311  1.1  thorpej extattr_list_vp(struct vnode *vp, int attrnamespace, void *data, size_t nbytes,
    312  1.1  thorpej     struct proc *p, register_t *retval)
    313  1.1  thorpej {
    314  1.1  thorpej 	struct uio auio, *auiop;
    315  1.1  thorpej 	size_t size, *sizep;
    316  1.1  thorpej 	struct iovec aiov;
    317  1.1  thorpej 	ssize_t cnt;
    318  1.1  thorpej 	int error;
    319  1.1  thorpej 
    320  1.1  thorpej 	VOP_LEASE(vp, p, p->p_ucred, LEASE_READ);
    321  1.1  thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    322  1.1  thorpej 
    323  1.1  thorpej 	auiop = NULL;
    324  1.1  thorpej 	sizep = NULL;
    325  1.1  thorpej 	cnt = 0;
    326  1.1  thorpej 	if (data != NULL) {
    327  1.1  thorpej 		aiov.iov_base = data;
    328  1.1  thorpej 		aiov.iov_len = nbytes;
    329  1.1  thorpej 		auio.uio_iov = &aiov;
    330  1.1  thorpej 		auio.uio_offset = 0;
    331  1.1  thorpej 		if (nbytes > INT_MAX) {
    332  1.1  thorpej 			error = EINVAL;
    333  1.1  thorpej 			goto done;
    334  1.1  thorpej 		}
    335  1.1  thorpej 		auio.uio_resid = nbytes;
    336  1.1  thorpej 		auio.uio_rw = UIO_READ;
    337  1.1  thorpej 		auio.uio_segflg = UIO_USERSPACE;
    338  1.1  thorpej 		auio.uio_procp = p;
    339  1.1  thorpej 		auiop = &auio;
    340  1.1  thorpej 		cnt = nbytes;
    341  1.1  thorpej 	} else
    342  1.1  thorpej 		sizep = &size;
    343  1.1  thorpej 
    344  1.1  thorpej 	error = VOP_LISTEXTATTR(vp, attrnamespace, auiop, sizep,
    345  1.1  thorpej 	    p->p_ucred, p);
    346  1.1  thorpej 
    347  1.1  thorpej 	if (auiop != NULL) {
    348  1.1  thorpej 		cnt -= auio.uio_resid;
    349  1.1  thorpej 		retval[0] = cnt;
    350  1.1  thorpej 	} else
    351  1.1  thorpej 		retval[0] = size;
    352  1.1  thorpej 
    353  1.1  thorpej  done:
    354  1.1  thorpej 	VOP_UNLOCK(vp, 0);
    355  1.1  thorpej 	return (error);
    356  1.1  thorpej }
    357  1.1  thorpej 
    358  1.1  thorpej /*****************************************************************************
    359  1.1  thorpej  * BSD <sys/extattr.h> API for file system extended attributes
    360  1.1  thorpej  *****************************************************************************/
    361  1.1  thorpej 
    362  1.1  thorpej int
    363  1.1  thorpej sys_extattr_set_fd(struct lwp *l, void *v, register_t *retval)
    364  1.1  thorpej {
    365  1.1  thorpej 	struct sys_extattr_set_fd_args /* {
    366  1.1  thorpej 		syscallarg(int) fd;
    367  1.1  thorpej 		syscallarg(int) attrnamespace;
    368  1.1  thorpej 		syscallarg(const char *) attrname;
    369  1.1  thorpej 		syscallarg(const void *) data;
    370  1.1  thorpej 		syscallarg(size_t) nbytes;
    371  1.1  thorpej 	} */ *uap = v;
    372  1.1  thorpej 	struct proc *p = l->l_proc;
    373  1.1  thorpej 	struct file *fp;
    374  1.1  thorpej 	struct vnode *vp;
    375  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    376  1.1  thorpej 	int error;
    377  1.1  thorpej 
    378  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    379  1.1  thorpej 	    NULL);
    380  1.1  thorpej 	if (error)
    381  1.1  thorpej 		return (error);
    382  1.1  thorpej 
    383  1.1  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    384  1.1  thorpej 	if (error)
    385  1.1  thorpej 		return (error);
    386  1.1  thorpej 	vp = (struct vnode *) fp->f_data;
    387  1.1  thorpej 
    388  1.1  thorpej 	error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
    389  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    390  1.1  thorpej 
    391  1.1  thorpej 	FILE_UNUSE(fp, p);
    392  1.1  thorpej 	return (error);
    393  1.1  thorpej }
    394  1.1  thorpej 
    395  1.1  thorpej int
    396  1.1  thorpej sys_extattr_set_file(struct lwp *l, void *v, register_t *retval)
    397  1.1  thorpej {
    398  1.1  thorpej 	struct sys_extattr_set_file_args /* {
    399  1.1  thorpej 		syscallarg(const char *) path;
    400  1.1  thorpej 		syscallarg(int) attrnamespace;
    401  1.1  thorpej 		syscallarg(const char *) attrname;
    402  1.1  thorpej 		syscallarg(const void *) data;
    403  1.1  thorpej 		syscallarg(size_t) nbytes;
    404  1.1  thorpej 	} */ *uap = v;
    405  1.1  thorpej 	struct proc *p = l->l_proc;
    406  1.1  thorpej 	struct nameidata nd;
    407  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    408  1.1  thorpej 	int error;
    409  1.1  thorpej 
    410  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    411  1.1  thorpej 	    NULL);
    412  1.1  thorpej 	if (error)
    413  1.1  thorpej 		return (error);
    414  1.1  thorpej 
    415  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    416  1.1  thorpej 	error = namei(&nd);
    417  1.1  thorpej 	if (error)
    418  1.1  thorpej 		return (error);
    419  1.1  thorpej 
    420  1.1  thorpej 	error = extattr_set_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    421  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    422  1.1  thorpej 
    423  1.1  thorpej 	vrele(nd.ni_vp);
    424  1.1  thorpej 	return (error);
    425  1.1  thorpej }
    426  1.1  thorpej 
    427  1.1  thorpej int
    428  1.1  thorpej sys_extattr_set_link(struct lwp *l, void *v, register_t *retval)
    429  1.1  thorpej {
    430  1.1  thorpej 	struct sys_extattr_set_link_args /* {
    431  1.1  thorpej 		syscallarg(const char *) path;
    432  1.1  thorpej 		syscallarg(int) attrnamespace;
    433  1.1  thorpej 		syscallarg(const char *) attrname;
    434  1.1  thorpej 		syscallarg(const void *) data;
    435  1.1  thorpej 		syscallarg(size_t) nbytes;
    436  1.1  thorpej 	} */ *uap = v;
    437  1.1  thorpej 	struct proc *p = l->l_proc;
    438  1.1  thorpej 	struct nameidata nd;
    439  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    440  1.1  thorpej 	int error;
    441  1.1  thorpej 
    442  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    443  1.1  thorpej 	    NULL);
    444  1.1  thorpej 	if (error)
    445  1.1  thorpej 		return (error);
    446  1.1  thorpej 
    447  1.1  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    448  1.1  thorpej 	error = namei(&nd);
    449  1.1  thorpej 	if (error)
    450  1.1  thorpej 		return (error);
    451  1.1  thorpej 
    452  1.1  thorpej 	error = extattr_set_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    453  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    454  1.1  thorpej 
    455  1.1  thorpej 	vrele(nd.ni_vp);
    456  1.1  thorpej 	return (error);
    457  1.1  thorpej }
    458  1.1  thorpej 
    459  1.1  thorpej int
    460  1.1  thorpej sys_extattr_get_fd(struct lwp *l, void *v, register_t *retval)
    461  1.1  thorpej {
    462  1.1  thorpej 	struct sys_extattr_get_fd_args /* {
    463  1.1  thorpej 		syscallarg(int) fd;
    464  1.1  thorpej 		syscallarg(int) attrnamespace;
    465  1.1  thorpej 		syscallarg(const char *) attrname;
    466  1.1  thorpej 		syscallarg(void *) data;
    467  1.1  thorpej 		syscallarg(size_t) nbytes;
    468  1.1  thorpej 	} */ *uap = v;
    469  1.1  thorpej 	struct proc *p = l->l_proc;
    470  1.1  thorpej 	struct file *fp;
    471  1.1  thorpej 	struct vnode *vp;
    472  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    473  1.1  thorpej 	int error;
    474  1.1  thorpej 
    475  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    476  1.1  thorpej 	    NULL);
    477  1.1  thorpej 	if (error)
    478  1.1  thorpej 		return (error);
    479  1.1  thorpej 
    480  1.1  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    481  1.1  thorpej 	if (error)
    482  1.1  thorpej 		return (error);
    483  1.1  thorpej 	vp = (struct vnode *) fp->f_data;
    484  1.1  thorpej 
    485  1.1  thorpej 	error = extattr_get_vp(vp, SCARG(uap, attrnamespace), attrname,
    486  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    487  1.1  thorpej 
    488  1.1  thorpej 	FILE_UNUSE(fp, p);
    489  1.1  thorpej 	return (error);
    490  1.1  thorpej }
    491  1.1  thorpej 
    492  1.1  thorpej int
    493  1.1  thorpej sys_extattr_get_file(struct lwp *l, void *v, register_t *retval)
    494  1.1  thorpej {
    495  1.1  thorpej 	struct sys_extattr_get_file_args /* {
    496  1.1  thorpej 		syscallarg(const char *) path;
    497  1.1  thorpej 		syscallarg(int) attrnamespace;
    498  1.1  thorpej 		syscallarg(const char *) attrname;
    499  1.1  thorpej 		syscallarg(void *) data;
    500  1.1  thorpej 		syscallarg(size_t) nbytes;
    501  1.1  thorpej 	} */ *uap = v;
    502  1.1  thorpej 	struct proc *p = l->l_proc;
    503  1.1  thorpej 	struct nameidata nd;
    504  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    505  1.1  thorpej 	int error;
    506  1.1  thorpej 
    507  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    508  1.1  thorpej 	    NULL);
    509  1.1  thorpej 	if (error)
    510  1.1  thorpej 		return (error);
    511  1.1  thorpej 
    512  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    513  1.1  thorpej 	error = namei(&nd);
    514  1.1  thorpej 	if (error)
    515  1.1  thorpej 		return (error);
    516  1.1  thorpej 
    517  1.1  thorpej 	error = extattr_get_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    518  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    519  1.1  thorpej 
    520  1.1  thorpej 	vrele(nd.ni_vp);
    521  1.1  thorpej 	return (error);
    522  1.1  thorpej }
    523  1.1  thorpej 
    524  1.1  thorpej int
    525  1.1  thorpej sys_extattr_get_link(struct lwp *l, void *v, register_t *retval)
    526  1.1  thorpej {
    527  1.1  thorpej 	struct sys_extattr_get_link_args /* {
    528  1.1  thorpej 		syscallarg(const char *) path;
    529  1.1  thorpej 		syscallarg(int) attrnamespace;
    530  1.1  thorpej 		syscallarg(const char *) attrname;
    531  1.1  thorpej 		syscallarg(void *) data;
    532  1.1  thorpej 		syscallarg(size_t) nbytes;
    533  1.1  thorpej 	} */ *uap = v;
    534  1.1  thorpej 	struct proc *p = l->l_proc;
    535  1.1  thorpej 	struct nameidata nd;
    536  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    537  1.1  thorpej 	int error;
    538  1.1  thorpej 
    539  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    540  1.1  thorpej 	    NULL);
    541  1.1  thorpej 	if (error)
    542  1.1  thorpej 		return (error);
    543  1.1  thorpej 
    544  1.1  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    545  1.1  thorpej 	error = namei(&nd);
    546  1.1  thorpej 	if (error)
    547  1.1  thorpej 		return (error);
    548  1.1  thorpej 
    549  1.1  thorpej 	error = extattr_get_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    550  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    551  1.1  thorpej 
    552  1.1  thorpej 	vrele(nd.ni_vp);
    553  1.1  thorpej 	return (error);
    554  1.1  thorpej }
    555  1.1  thorpej 
    556  1.1  thorpej int
    557  1.1  thorpej sys_extattr_delete_fd(struct lwp *l, void *v, register_t *retval)
    558  1.1  thorpej {
    559  1.1  thorpej 	struct sys_extattr_delete_fd_args /* {
    560  1.1  thorpej 		syscallarg(int) fd;
    561  1.1  thorpej 		syscallarg(int) attrnamespace;
    562  1.1  thorpej 		syscallarg(const char *) attrname;
    563  1.1  thorpej 	} */ *uap = v;
    564  1.1  thorpej 	struct proc *p = l->l_proc;
    565  1.1  thorpej 	struct file *fp;
    566  1.1  thorpej 	struct vnode *vp;
    567  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    568  1.1  thorpej 	int error;
    569  1.1  thorpej 
    570  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    571  1.1  thorpej 	    NULL);
    572  1.1  thorpej 	if (error)
    573  1.1  thorpej 		return (error);
    574  1.1  thorpej 
    575  1.1  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    576  1.1  thorpej 	if (error)
    577  1.1  thorpej 		return (error);
    578  1.1  thorpej 	vp = (struct vnode *) fp->f_data;
    579  1.1  thorpej 
    580  1.1  thorpej 	error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, p);
    581  1.1  thorpej 
    582  1.1  thorpej 	FILE_UNUSE(fp, p);
    583  1.1  thorpej 	return (error);
    584  1.1  thorpej }
    585  1.1  thorpej 
    586  1.1  thorpej int
    587  1.1  thorpej sys_extattr_delete_file(struct lwp *l, void *v, register_t *retval)
    588  1.1  thorpej {
    589  1.1  thorpej 	struct sys_extattr_delete_file_args /* {
    590  1.1  thorpej 		syscallarg(const char *) path;
    591  1.1  thorpej 		syscallarg(int) attrnamespace;
    592  1.1  thorpej 		syscallarg(const char *) attrname;
    593  1.1  thorpej 	} */ *uap = v;
    594  1.1  thorpej 	struct proc *p = l->l_proc;
    595  1.1  thorpej 	struct nameidata nd;
    596  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    597  1.1  thorpej 	int error;
    598  1.1  thorpej 
    599  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    600  1.1  thorpej 	    NULL);
    601  1.1  thorpej 	if (error)
    602  1.1  thorpej 		return (error);
    603  1.1  thorpej 
    604  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    605  1.1  thorpej 	error = namei(&nd);
    606  1.1  thorpej 	if (error)
    607  1.1  thorpej 		return (error);
    608  1.1  thorpej 
    609  1.1  thorpej 	error = extattr_delete_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    610  1.1  thorpej 	    p);
    611  1.1  thorpej 
    612  1.1  thorpej 	vrele(nd.ni_vp);
    613  1.1  thorpej 	return (error);
    614  1.1  thorpej }
    615  1.1  thorpej 
    616  1.1  thorpej int
    617  1.1  thorpej sys_extattr_delete_link(struct lwp *l, void *v, register_t *retval)
    618  1.1  thorpej {
    619  1.1  thorpej 	struct sys_extattr_delete_link_args /* {
    620  1.1  thorpej 		syscallarg(const char *) path;
    621  1.1  thorpej 		syscallarg(int) attrnamespace;
    622  1.1  thorpej 		syscallarg(const char *) attrname;
    623  1.1  thorpej 	} */ *uap = v;
    624  1.1  thorpej 	struct proc *p = l->l_proc;
    625  1.1  thorpej 	struct nameidata nd;
    626  1.1  thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    627  1.1  thorpej 	int error;
    628  1.1  thorpej 
    629  1.1  thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    630  1.1  thorpej 	    NULL);
    631  1.1  thorpej 	if (error)
    632  1.1  thorpej 		return (error);
    633  1.1  thorpej 
    634  1.1  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    635  1.1  thorpej 	error = namei(&nd);
    636  1.1  thorpej 	if (error)
    637  1.1  thorpej 		return (error);
    638  1.1  thorpej 
    639  1.1  thorpej 	error = extattr_delete_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    640  1.1  thorpej 	    p);
    641  1.1  thorpej 
    642  1.1  thorpej 	vrele(nd.ni_vp);
    643  1.1  thorpej 	return (error);
    644  1.1  thorpej }
    645  1.1  thorpej 
    646  1.1  thorpej int
    647  1.1  thorpej sys_extattr_list_fd(struct lwp *l, void *v, register_t *retval)
    648  1.1  thorpej {
    649  1.1  thorpej 	struct sys_extattr_list_fd_args /* {
    650  1.1  thorpej 		syscallarg(int) fd;
    651  1.1  thorpej 		syscallarg(int) attrnamespace;
    652  1.1  thorpej 		syscallarg(void *) data;
    653  1.1  thorpej 		syscallarg(size_t) nbytes;
    654  1.1  thorpej 	} */ *uap = v;
    655  1.1  thorpej 	struct proc *p = l->l_proc;
    656  1.1  thorpej 	struct file *fp;
    657  1.1  thorpej 	struct vnode *vp;
    658  1.1  thorpej 	int error;
    659  1.1  thorpej 
    660  1.1  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    661  1.1  thorpej 	if (error)
    662  1.1  thorpej 		return (error);
    663  1.1  thorpej 	vp = (struct vnode *) fp->f_data;
    664  1.1  thorpej 
    665  1.1  thorpej 	error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
    666  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    667  1.1  thorpej 
    668  1.1  thorpej 	FILE_UNUSE(fp, p);
    669  1.1  thorpej 	return (error);
    670  1.1  thorpej }
    671  1.1  thorpej 
    672  1.1  thorpej int
    673  1.1  thorpej sys_extattr_list_file(struct lwp *l, void *v, register_t *retval)
    674  1.1  thorpej {
    675  1.1  thorpej 	struct sys_extattr_list_file_args /* {
    676  1.1  thorpej 		syscallarg(const char *) path;
    677  1.1  thorpej 		syscallarg(int) attrnamespace;
    678  1.1  thorpej 		syscallarg(void *) data;
    679  1.1  thorpej 		syscallarg(size_t) nbytes;
    680  1.1  thorpej 	} */ *uap = v;
    681  1.1  thorpej 	struct proc *p = l->l_proc;
    682  1.1  thorpej 	struct nameidata nd;
    683  1.1  thorpej 	int error;
    684  1.1  thorpej 
    685  1.1  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    686  1.1  thorpej 	error = namei(&nd);
    687  1.1  thorpej 	if (error)
    688  1.1  thorpej 		return (error);
    689  1.1  thorpej 
    690  1.1  thorpej 	error = extattr_list_vp(nd.ni_vp, SCARG(uap, attrnamespace),
    691  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    692  1.1  thorpej 
    693  1.1  thorpej 	vrele(nd.ni_vp);
    694  1.1  thorpej 	return (error);
    695  1.1  thorpej }
    696  1.1  thorpej 
    697  1.1  thorpej int
    698  1.1  thorpej sys_extattr_list_link(struct lwp *l, void *v, register_t *retval)
    699  1.1  thorpej {
    700  1.1  thorpej 	struct sys_extattr_list_link_args /* {
    701  1.1  thorpej 		syscallarg(const char *) path;
    702  1.1  thorpej 		syscallarg(int) attrnamespace;
    703  1.1  thorpej 		syscallarg(void *) data;
    704  1.1  thorpej 		syscallarg(size_t) nbytes;
    705  1.1  thorpej 	} */ *uap = v;
    706  1.1  thorpej 	struct proc *p = l->l_proc;
    707  1.1  thorpej 	struct nameidata nd;
    708  1.1  thorpej 	int error;
    709  1.1  thorpej 
    710  1.1  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    711  1.1  thorpej 	error = namei(&nd);
    712  1.1  thorpej 	if (error)
    713  1.1  thorpej 		return (error);
    714  1.1  thorpej 
    715  1.1  thorpej 	error = extattr_list_vp(nd.ni_vp, SCARG(uap, attrnamespace),
    716  1.1  thorpej 	    SCARG(uap, data), SCARG(uap, nbytes), p, retval);
    717  1.1  thorpej 
    718  1.1  thorpej 	vrele(nd.ni_vp);
    719  1.1  thorpej 	return (error);
    720  1.1  thorpej }
    721  1.2  thorpej 
    722  1.2  thorpej /*****************************************************************************
    723  1.2  thorpej  * Linux-compatible <sys/xattr.h> API for file system extended attributes
    724  1.2  thorpej  *****************************************************************************/
    725  1.2  thorpej 
    726  1.2  thorpej int
    727  1.2  thorpej sys_setxattr(struct lwp *l, void *v, register_t *retval)
    728  1.2  thorpej {
    729  1.2  thorpej 	struct sys_setxattr_args /* {
    730  1.2  thorpej 		syscallarg(const char *) path;
    731  1.2  thorpej 		syscallarg(const char *) name;
    732  1.2  thorpej 		syscallarg(void *) value;
    733  1.2  thorpej 		syscallarg(size_t) size;
    734  1.2  thorpej 		syscallarg(int) flags;
    735  1.2  thorpej 	} */ *uap = v;
    736  1.2  thorpej 	struct proc *p = l->l_proc;
    737  1.2  thorpej 	struct nameidata nd;
    738  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
    739  1.2  thorpej 	int error;
    740  1.2  thorpej 
    741  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    742  1.2  thorpej 	    NULL);
    743  1.2  thorpej 	if (error)
    744  1.2  thorpej 		return (error);
    745  1.2  thorpej 
    746  1.2  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    747  1.2  thorpej 	error = namei(&nd);
    748  1.2  thorpej 	if (error)
    749  1.2  thorpej 		return (error);
    750  1.2  thorpej 
    751  1.2  thorpej 	/* XXX flags */
    752  1.2  thorpej 
    753  1.2  thorpej 	error = extattr_set_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    754  1.2  thorpej 	    attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
    755  1.2  thorpej 
    756  1.2  thorpej 	vrele(nd.ni_vp);
    757  1.2  thorpej 	return (error);
    758  1.2  thorpej }
    759  1.2  thorpej 
    760  1.2  thorpej int
    761  1.2  thorpej sys_lsetxattr(struct lwp *l, void *v, register_t *retval)
    762  1.2  thorpej {
    763  1.2  thorpej 	struct sys_lsetxattr_args /* {
    764  1.2  thorpej 		syscallarg(const char *) path;
    765  1.2  thorpej 		syscallarg(const char *) name;
    766  1.2  thorpej 		syscallarg(void *) value;
    767  1.2  thorpej 		syscallarg(size_t) size;
    768  1.2  thorpej 		syscallarg(int) flags;
    769  1.2  thorpej 	} */ *uap = v;
    770  1.2  thorpej 	struct proc *p = l->l_proc;
    771  1.2  thorpej 	struct nameidata nd;
    772  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
    773  1.2  thorpej 	int error;
    774  1.2  thorpej 
    775  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    776  1.2  thorpej 	    NULL);
    777  1.2  thorpej 	if (error)
    778  1.2  thorpej 		return (error);
    779  1.2  thorpej 
    780  1.2  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    781  1.2  thorpej 	error = namei(&nd);
    782  1.2  thorpej 	if (error)
    783  1.2  thorpej 		return (error);
    784  1.2  thorpej 
    785  1.2  thorpej 	/* XXX flags */
    786  1.2  thorpej 
    787  1.2  thorpej 	error = extattr_set_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    788  1.2  thorpej 	    attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
    789  1.2  thorpej 
    790  1.2  thorpej 	vrele(nd.ni_vp);
    791  1.2  thorpej 	return (error);
    792  1.2  thorpej }
    793  1.2  thorpej 
    794  1.2  thorpej int
    795  1.2  thorpej sys_fsetxattr(struct lwp *l, void *v, register_t *retval)
    796  1.2  thorpej {
    797  1.2  thorpej 	struct sys_fsetxattr_args /* {
    798  1.2  thorpej 		syscallarg(int) fd;
    799  1.2  thorpej 		syscallarg(const char *) name;
    800  1.2  thorpej 		syscallarg(void *) value;
    801  1.2  thorpej 		syscallarg(size_t) size;
    802  1.2  thorpej 		syscallarg(int) flags;
    803  1.2  thorpej 	} */ *uap = v;
    804  1.2  thorpej 	struct proc *p = l->l_proc;
    805  1.2  thorpej 	struct file *fp;
    806  1.2  thorpej 	struct vnode *vp;
    807  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
    808  1.2  thorpej 	int error;
    809  1.2  thorpej 
    810  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    811  1.2  thorpej 	    NULL);
    812  1.2  thorpej 	if (error)
    813  1.2  thorpej 		return (error);
    814  1.2  thorpej 
    815  1.2  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    816  1.2  thorpej 	if (error)
    817  1.2  thorpej 		return (error);
    818  1.2  thorpej 	vp = (struct vnode *) fp->f_data;
    819  1.2  thorpej 
    820  1.2  thorpej 	/* XXX flags */
    821  1.2  thorpej 
    822  1.2  thorpej 	error = extattr_set_vp(vp, EXTATTR_NAMESPACE_USER,
    823  1.2  thorpej 	    attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
    824  1.2  thorpej 
    825  1.2  thorpej 	FILE_UNUSE(fp, p);
    826  1.2  thorpej 	return (error);
    827  1.2  thorpej }
    828  1.2  thorpej 
    829  1.2  thorpej int
    830  1.2  thorpej sys_getxattr(struct lwp *l, void *v, register_t *retval)
    831  1.2  thorpej {
    832  1.2  thorpej 	struct sys_getxattr_args /* {
    833  1.2  thorpej 		syscallarg(const char *) path;
    834  1.2  thorpej 		syscallarg(const char *) name;
    835  1.2  thorpej 		syscallarg(void *) value;
    836  1.2  thorpej 		syscallarg(size_t) size;
    837  1.2  thorpej 	} */ *uap = v;
    838  1.2  thorpej 	struct proc *p = l->l_proc;
    839  1.2  thorpej 	struct nameidata nd;
    840  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
    841  1.2  thorpej 	int error;
    842  1.2  thorpej 
    843  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    844  1.2  thorpej 	    NULL);
    845  1.2  thorpej 	if (error)
    846  1.2  thorpej 		return (error);
    847  1.2  thorpej 
    848  1.2  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    849  1.2  thorpej 	error = namei(&nd);
    850  1.2  thorpej 	if (error)
    851  1.2  thorpej 		return (error);
    852  1.2  thorpej 
    853  1.2  thorpej 	error = extattr_get_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    854  1.2  thorpej 	    attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
    855  1.2  thorpej 
    856  1.2  thorpej 	vrele(nd.ni_vp);
    857  1.2  thorpej 	return (error);
    858  1.2  thorpej }
    859  1.2  thorpej 
    860  1.2  thorpej int
    861  1.2  thorpej sys_lgetxattr(struct lwp *l, void *v, register_t *retval)
    862  1.2  thorpej {
    863  1.2  thorpej 	struct sys_lgetxattr_args /* {
    864  1.2  thorpej 		syscallarg(const char *) path;
    865  1.2  thorpej 		syscallarg(const char *) name;
    866  1.2  thorpej 		syscallarg(void *) value;
    867  1.2  thorpej 		syscallarg(size_t) size;
    868  1.2  thorpej 	} */ *uap = v;
    869  1.2  thorpej 	struct proc *p = l->l_proc;
    870  1.2  thorpej 	struct nameidata nd;
    871  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
    872  1.2  thorpej 	int error;
    873  1.2  thorpej 
    874  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    875  1.2  thorpej 	    NULL);
    876  1.2  thorpej 	if (error)
    877  1.2  thorpej 		return (error);
    878  1.2  thorpej 
    879  1.2  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    880  1.2  thorpej 	error = namei(&nd);
    881  1.2  thorpej 	if (error)
    882  1.2  thorpej 		return (error);
    883  1.2  thorpej 
    884  1.2  thorpej 	error = extattr_get_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    885  1.2  thorpej 	    attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
    886  1.2  thorpej 
    887  1.2  thorpej 	vrele(nd.ni_vp);
    888  1.2  thorpej 	return (error);
    889  1.2  thorpej }
    890  1.2  thorpej 
    891  1.2  thorpej int
    892  1.2  thorpej sys_fgetxattr(struct lwp *l, void *v, register_t *retval)
    893  1.2  thorpej {
    894  1.2  thorpej 	struct sys_fgetxattr_args /* {
    895  1.2  thorpej 		syscallarg(int) fd;
    896  1.2  thorpej 		syscallarg(const char *) name;
    897  1.2  thorpej 		syscallarg(void *) value;
    898  1.2  thorpej 		syscallarg(size_t) size;
    899  1.2  thorpej 	} */ *uap = v;
    900  1.2  thorpej 	struct proc *p = l->l_proc;
    901  1.2  thorpej 	struct file *fp;
    902  1.2  thorpej 	struct vnode *vp;
    903  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
    904  1.2  thorpej 	int error;
    905  1.2  thorpej 
    906  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    907  1.2  thorpej 	    NULL);
    908  1.2  thorpej 	if (error)
    909  1.2  thorpej 		return (error);
    910  1.2  thorpej 
    911  1.2  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    912  1.2  thorpej 	if (error)
    913  1.2  thorpej 		return (error);
    914  1.2  thorpej 	vp = (struct vnode *) fp->f_data;
    915  1.2  thorpej 
    916  1.2  thorpej 	error = extattr_get_vp(vp, EXTATTR_NAMESPACE_USER,
    917  1.2  thorpej 	    attrname, SCARG(uap, value), SCARG(uap, size), p, retval);
    918  1.2  thorpej 
    919  1.2  thorpej 	FILE_UNUSE(fp, p);
    920  1.2  thorpej 	return (error);
    921  1.2  thorpej }
    922  1.2  thorpej 
    923  1.2  thorpej int
    924  1.2  thorpej sys_listxattr(struct lwp *l, void *v, register_t *retval)
    925  1.2  thorpej {
    926  1.2  thorpej 	struct sys_listxattr_args /* {
    927  1.2  thorpej 		syscallarg(const char *) path;
    928  1.2  thorpej 		syscallarg(char *) list;
    929  1.2  thorpej 		syscallarg(size_t) size;
    930  1.2  thorpej 	} */ *uap = v;
    931  1.2  thorpej 	struct proc *p = l->l_proc;
    932  1.2  thorpej 	struct nameidata nd;
    933  1.2  thorpej 	int error;
    934  1.2  thorpej 
    935  1.2  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    936  1.2  thorpej 	error = namei(&nd);
    937  1.2  thorpej 	if (error)
    938  1.2  thorpej 		return (error);
    939  1.2  thorpej 
    940  1.2  thorpej 	error = extattr_list_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    941  1.2  thorpej 	    SCARG(uap, list), SCARG(uap, size), p, retval);
    942  1.2  thorpej 
    943  1.2  thorpej 	vrele(nd.ni_vp);
    944  1.2  thorpej 	return (error);
    945  1.2  thorpej }
    946  1.2  thorpej 
    947  1.2  thorpej int
    948  1.2  thorpej sys_llistxattr(struct lwp *l, void *v, register_t *retval)
    949  1.2  thorpej {
    950  1.2  thorpej 	struct sys_llistxattr_args /* {
    951  1.2  thorpej 		syscallarg(const char *) path;
    952  1.2  thorpej 		syscallarg(char *) list;
    953  1.2  thorpej 		syscallarg(size_t) size;
    954  1.2  thorpej 	} */ *uap = v;
    955  1.2  thorpej 	struct proc *p = l->l_proc;
    956  1.2  thorpej 	struct nameidata nd;
    957  1.2  thorpej 	int error;
    958  1.2  thorpej 
    959  1.2  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
    960  1.2  thorpej 	error = namei(&nd);
    961  1.2  thorpej 	if (error)
    962  1.2  thorpej 		return (error);
    963  1.2  thorpej 
    964  1.2  thorpej 	error = extattr_list_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    965  1.2  thorpej 	    SCARG(uap, list), SCARG(uap, size), p, retval);
    966  1.2  thorpej 
    967  1.2  thorpej 	vrele(nd.ni_vp);
    968  1.2  thorpej 	return (error);
    969  1.2  thorpej }
    970  1.2  thorpej 
    971  1.2  thorpej int
    972  1.2  thorpej sys_flistxattr(struct lwp *l, void *v, register_t *retval)
    973  1.2  thorpej {
    974  1.2  thorpej 	struct sys_flistxattr_args /* {
    975  1.2  thorpej 		syscallarg(int) fd;
    976  1.2  thorpej 		syscallarg(char *) list;
    977  1.2  thorpej 		syscallarg(size_t) size;
    978  1.2  thorpej 	} */ *uap = v;
    979  1.2  thorpej 	struct proc *p = l->l_proc;
    980  1.2  thorpej 	struct file *fp;
    981  1.2  thorpej 	struct vnode *vp;
    982  1.2  thorpej 	int error;
    983  1.2  thorpej 
    984  1.2  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
    985  1.2  thorpej 	if (error)
    986  1.2  thorpej 		return (error);
    987  1.2  thorpej 	vp = (struct vnode *) fp->f_data;
    988  1.2  thorpej 
    989  1.2  thorpej 	error = extattr_list_vp(vp, EXTATTR_NAMESPACE_USER,
    990  1.2  thorpej 	    SCARG(uap, list), SCARG(uap, size), p, retval);
    991  1.2  thorpej 
    992  1.2  thorpej 	FILE_UNUSE(fp, p);
    993  1.2  thorpej 	return (error);
    994  1.2  thorpej }
    995  1.2  thorpej 
    996  1.2  thorpej int
    997  1.2  thorpej sys_removexattr(struct lwp *l, void *v, register_t *retval)
    998  1.2  thorpej {
    999  1.2  thorpej 	struct sys_removexattr_args /* {
   1000  1.2  thorpej 		syscallarg(const char *) path;
   1001  1.2  thorpej 		syscallarg(const char *) name;
   1002  1.2  thorpej 	} */ *uap = v;
   1003  1.2  thorpej 	struct proc *p = l->l_proc;
   1004  1.2  thorpej 	struct nameidata nd;
   1005  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
   1006  1.2  thorpej 	int error;
   1007  1.2  thorpej 
   1008  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
   1009  1.2  thorpej 	    NULL);
   1010  1.2  thorpej 	if (error)
   1011  1.2  thorpej 		return (error);
   1012  1.2  thorpej 
   1013  1.2  thorpej 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
   1014  1.2  thorpej 	error = namei(&nd);
   1015  1.2  thorpej 	if (error)
   1016  1.2  thorpej 		return (error);
   1017  1.2  thorpej 
   1018  1.2  thorpej 	error = extattr_delete_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
   1019  1.2  thorpej 	    attrname, p);
   1020  1.2  thorpej 
   1021  1.2  thorpej 	vrele(nd.ni_vp);
   1022  1.2  thorpej 	return (error);
   1023  1.2  thorpej }
   1024  1.2  thorpej 
   1025  1.2  thorpej int
   1026  1.2  thorpej sys_lremovexattr(struct lwp *l, void *v, register_t *retval)
   1027  1.2  thorpej {
   1028  1.2  thorpej 	struct sys_lremovexattr_args /* {
   1029  1.2  thorpej 		syscallarg(const char *) path;
   1030  1.2  thorpej 		syscallarg(const char *) name;
   1031  1.2  thorpej 	} */ *uap = v;
   1032  1.2  thorpej 	struct proc *p = l->l_proc;
   1033  1.2  thorpej 	struct nameidata nd;
   1034  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
   1035  1.2  thorpej 	int error;
   1036  1.2  thorpej 
   1037  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
   1038  1.2  thorpej 	    NULL);
   1039  1.2  thorpej 	if (error)
   1040  1.2  thorpej 		return (error);
   1041  1.2  thorpej 
   1042  1.2  thorpej 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
   1043  1.2  thorpej 	error = namei(&nd);
   1044  1.2  thorpej 	if (error)
   1045  1.2  thorpej 		return (error);
   1046  1.2  thorpej 
   1047  1.2  thorpej 	error = extattr_delete_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
   1048  1.2  thorpej 	    attrname, p);
   1049  1.2  thorpej 
   1050  1.2  thorpej 	vrele(nd.ni_vp);
   1051  1.2  thorpej 	return (error);
   1052  1.2  thorpej }
   1053  1.2  thorpej 
   1054  1.2  thorpej int
   1055  1.2  thorpej sys_fremovexattr(struct lwp *l, void *v, register_t *retval)
   1056  1.2  thorpej {
   1057  1.2  thorpej 	struct sys_fremovexattr_args /* {
   1058  1.2  thorpej 		syscallarg(int) fd;
   1059  1.2  thorpej 		syscallarg(const char *) name;
   1060  1.2  thorpej 	} */ *uap = v;
   1061  1.2  thorpej 	struct proc *p = l->l_proc;
   1062  1.2  thorpej 	struct file *fp;
   1063  1.2  thorpej 	struct vnode *vp;
   1064  1.2  thorpej 	char attrname[XATTR_NAME_MAX];
   1065  1.2  thorpej 	int error;
   1066  1.2  thorpej 
   1067  1.2  thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
   1068  1.2  thorpej 	    NULL);
   1069  1.2  thorpej 	if (error)
   1070  1.2  thorpej 		return (error);
   1071  1.2  thorpej 
   1072  1.2  thorpej 	error = getvnode(p->p_fd, SCARG(uap, fd), &fp);
   1073  1.2  thorpej 	if (error)
   1074  1.2  thorpej 		return (error);
   1075  1.2  thorpej 	vp = (struct vnode *) fp->f_data;
   1076  1.2  thorpej 
   1077  1.2  thorpej 	error = extattr_delete_vp(vp, EXTATTR_NAMESPACE_USER,
   1078  1.2  thorpej 	    attrname, p);
   1079  1.2  thorpej 
   1080  1.2  thorpej 	FILE_UNUSE(fp, p);
   1081  1.2  thorpej 	return (error);
   1082  1.2  thorpej }
   1083