Home | History | Annotate | Line # | Download | only in kern
vfs_xattr.c revision 1.16.6.1
      1  1.16.6.1       mjf /*	$NetBSD: vfs_xattr.c,v 1.16.6.1 2008/04/03 12:43:05 mjf Exp $	*/
      2       1.2   thorpej 
      3       1.2   thorpej /*-
      4  1.16.6.1       mjf  * Copyright (c) 2005, 2008 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.16.6.1       mjf __KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.16.6.1 2008/04/03 12:43:05 mjf 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/syscallargs.h>
     94       1.6      elad #include <sys/kauth.h>
     95       1.1   thorpej 
     96       1.1   thorpej /*
     97       1.3   thorpej  * Credential check based on process requesting service, and per-attribute
     98       1.3   thorpej  * permissions.
     99       1.3   thorpej  *
    100       1.3   thorpej  * NOTE: Vnode must be locked.
    101       1.3   thorpej  */
    102       1.3   thorpej int
    103       1.3   thorpej extattr_check_cred(struct vnode *vp, int attrnamespace,
    104       1.6      elad     kauth_cred_t cred, struct lwp *l, int access)
    105       1.3   thorpej {
    106       1.3   thorpej 
    107       1.3   thorpej 	if (cred == NOCRED)
    108       1.3   thorpej 		return (0);
    109       1.3   thorpej 
    110       1.3   thorpej 	switch (attrnamespace) {
    111       1.3   thorpej 	case EXTATTR_NAMESPACE_SYSTEM:
    112       1.3   thorpej 		/*
    113       1.3   thorpej 		 * Do we really want to allow this, or just require that
    114       1.3   thorpej 		 * these requests come from kernel code (NOCRED case above)?
    115       1.3   thorpej 		 */
    116       1.6      elad 		return (kauth_authorize_generic(cred, KAUTH_GENERIC_ISSUSER,
    117      1.10      elad 		    NULL));
    118       1.3   thorpej 
    119       1.3   thorpej 	case EXTATTR_NAMESPACE_USER:
    120      1.13     pooka 		return (VOP_ACCESS(vp, access, cred));
    121       1.3   thorpej 
    122       1.3   thorpej 	default:
    123       1.3   thorpej 		return (EPERM);
    124       1.3   thorpej 	}
    125       1.3   thorpej }
    126       1.3   thorpej 
    127       1.3   thorpej /*
    128       1.3   thorpej  * Default vfs_extattrctl routine for file systems that do not support
    129       1.3   thorpej  * it.
    130       1.3   thorpej  */
    131       1.3   thorpej /*ARGSUSED*/
    132       1.3   thorpej int
    133       1.9      yamt vfs_stdextattrctl(struct mount *mp, int cmt, struct vnode *vp,
    134      1.13     pooka     int attrnamespace, const char *attrname)
    135       1.3   thorpej {
    136       1.3   thorpej 
    137       1.3   thorpej 	if (vp != NULL)
    138       1.3   thorpej 		VOP_UNLOCK(vp, 0);
    139       1.3   thorpej 	return (EOPNOTSUPP);
    140       1.3   thorpej }
    141       1.3   thorpej 
    142       1.3   thorpej /*
    143       1.2   thorpej  * Push extended attribute configuration information into the file
    144       1.2   thorpej  * system.
    145       1.1   thorpej  *
    146       1.1   thorpej  * NOTE: Not all file systems that support extended attributes will
    147       1.1   thorpej  * require the use of this system call.
    148       1.1   thorpej  */
    149       1.1   thorpej int
    150      1.15       dsl sys_extattrctl(struct lwp *l, const struct sys_extattrctl_args *uap, register_t *retval)
    151       1.1   thorpej {
    152      1.15       dsl 	/* {
    153       1.1   thorpej 		syscallarg(const char *) path;
    154       1.1   thorpej 		syscallarg(int) cmd;
    155       1.1   thorpej 		syscallarg(const char *) filename;
    156       1.1   thorpej 		syscallarg(int) attrnamespace;
    157       1.1   thorpej 		syscallarg(const char *) attrname;
    158      1.15       dsl 	} */
    159       1.1   thorpej 	struct vnode *vp;
    160       1.1   thorpej 	struct nameidata nd;
    161       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    162       1.1   thorpej 	int error;
    163       1.1   thorpej 
    164       1.1   thorpej 	if (SCARG(uap, attrname) != NULL) {
    165       1.1   thorpej 		error = copyinstr(SCARG(uap, attrname), attrname,
    166       1.1   thorpej 		    sizeof(attrname), NULL);
    167       1.1   thorpej 		if (error)
    168       1.1   thorpej 			return (error);
    169       1.1   thorpej 	}
    170       1.1   thorpej 
    171       1.1   thorpej 	vp = NULL;
    172       1.1   thorpej 	if (SCARG(uap, filename) != NULL) {
    173       1.1   thorpej 		NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
    174      1.14     pooka 		    SCARG(uap, filename));
    175       1.1   thorpej 		error = namei(&nd);
    176       1.1   thorpej 		if (error)
    177       1.1   thorpej 			return (error);
    178       1.1   thorpej 		vp = nd.ni_vp;
    179       1.1   thorpej 	}
    180       1.1   thorpej 
    181      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
    182       1.1   thorpej 	error = namei(&nd);
    183       1.1   thorpej 	if (error) {
    184       1.1   thorpej 		if (vp != NULL)
    185       1.1   thorpej 			vput(vp);
    186       1.1   thorpej 		return (error);
    187       1.1   thorpej 	}
    188       1.1   thorpej 
    189      1.12   hannken 	error = VFS_EXTATTRCTL(nd.ni_vp->v_mount, SCARG(uap, cmd), vp,
    190       1.1   thorpej 	    SCARG(uap, attrnamespace),
    191      1.13     pooka 	    SCARG(uap, attrname) != NULL ? attrname : NULL);
    192       1.1   thorpej 
    193       1.1   thorpej 	if (vp != NULL)
    194       1.1   thorpej 		vrele(vp);
    195       1.1   thorpej 
    196       1.1   thorpej 	return (error);
    197       1.1   thorpej }
    198       1.1   thorpej 
    199       1.1   thorpej /*****************************************************************************
    200       1.1   thorpej  * Internal routines to manipulate file system extended attributes:
    201       1.1   thorpej  *	- set
    202       1.1   thorpej  *	- get
    203       1.1   thorpej  *	- delete
    204       1.1   thorpej  *	- list
    205       1.1   thorpej  *****************************************************************************/
    206       1.1   thorpej 
    207       1.1   thorpej /*
    208       1.1   thorpej  * extattr_set_vp:
    209       1.1   thorpej  *
    210       1.1   thorpej  *	Set a named extended attribute on a file or directory.
    211       1.1   thorpej  */
    212       1.1   thorpej static int
    213       1.1   thorpej extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    214       1.4  christos     const void *data, size_t nbytes, struct lwp *l, register_t *retval)
    215       1.1   thorpej {
    216       1.1   thorpej 	struct uio auio;
    217       1.1   thorpej 	struct iovec aiov;
    218       1.1   thorpej 	ssize_t cnt;
    219       1.1   thorpej 	int error;
    220       1.1   thorpej 
    221       1.1   thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    222       1.1   thorpej 
    223       1.1   thorpej 	aiov.iov_base = __UNCONST(data);	/* XXXUNCONST kills const */
    224       1.1   thorpej 	aiov.iov_len = nbytes;
    225       1.1   thorpej 	auio.uio_iov = &aiov;
    226       1.1   thorpej 	auio.uio_iovcnt = 1;
    227       1.1   thorpej 	auio.uio_offset = 0;
    228       1.1   thorpej 	if (nbytes > INT_MAX) {
    229       1.1   thorpej 		error = EINVAL;
    230       1.1   thorpej 		goto done;
    231       1.1   thorpej 	}
    232       1.1   thorpej 	auio.uio_resid = nbytes;
    233       1.1   thorpej 	auio.uio_rw = UIO_WRITE;
    234       1.5      yamt 	KASSERT(l == curlwp);
    235       1.5      yamt 	auio.uio_vmspace = l->l_proc->p_vmspace;
    236       1.1   thorpej 	cnt = nbytes;
    237       1.1   thorpej 
    238      1.13     pooka 	error = VOP_SETEXTATTR(vp, attrnamespace, attrname, &auio, l->l_cred);
    239       1.1   thorpej 	cnt -= auio.uio_resid;
    240       1.1   thorpej 	retval[0] = cnt;
    241       1.1   thorpej 
    242       1.1   thorpej  done:
    243       1.1   thorpej 	VOP_UNLOCK(vp, 0);
    244       1.1   thorpej 	return (error);
    245       1.1   thorpej }
    246       1.1   thorpej 
    247       1.1   thorpej /*
    248       1.1   thorpej  * extattr_get_vp:
    249       1.1   thorpej  *
    250       1.1   thorpej  *	Get a named extended attribute on a file or directory.
    251       1.1   thorpej  */
    252       1.1   thorpej static int
    253       1.1   thorpej extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    254       1.4  christos     void *data, size_t nbytes, struct lwp *l, register_t *retval)
    255       1.1   thorpej {
    256       1.1   thorpej 	struct uio auio, *auiop;
    257       1.1   thorpej 	struct iovec aiov;
    258       1.1   thorpej 	ssize_t cnt;
    259       1.1   thorpej 	size_t size, *sizep;
    260       1.1   thorpej 	int error;
    261       1.1   thorpej 
    262       1.1   thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    263       1.1   thorpej 
    264       1.1   thorpej 	/*
    265       1.1   thorpej 	 * Slightly unusual semantics: if the user provides a NULL data
    266       1.1   thorpej 	 * pointer, they don't want to receive the data, just the maximum
    267       1.1   thorpej 	 * read length.
    268       1.1   thorpej 	 */
    269       1.1   thorpej 	auiop = NULL;
    270       1.1   thorpej 	sizep = NULL;
    271       1.1   thorpej 	cnt = 0;
    272       1.1   thorpej 	if (data != NULL) {
    273       1.1   thorpej 		aiov.iov_base = data;
    274       1.1   thorpej 		aiov.iov_len = nbytes;
    275       1.1   thorpej 		auio.uio_iov = &aiov;
    276       1.1   thorpej 		auio.uio_offset = 0;
    277       1.1   thorpej 		if (nbytes > INT_MAX) {
    278       1.1   thorpej 			error = EINVAL;
    279       1.1   thorpej 			goto done;
    280       1.1   thorpej 		}
    281       1.1   thorpej 		auio.uio_resid = nbytes;
    282       1.1   thorpej 		auio.uio_rw = UIO_READ;
    283       1.5      yamt 		KASSERT(l == curlwp);
    284       1.5      yamt 		auio.uio_vmspace = l->l_proc->p_vmspace;
    285       1.1   thorpej 		auiop = &auio;
    286       1.1   thorpej 		cnt = nbytes;
    287       1.1   thorpej 	} else
    288       1.1   thorpej 		sizep = &size;
    289       1.1   thorpej 
    290       1.1   thorpej 	error = VOP_GETEXTATTR(vp, attrnamespace, attrname, auiop, sizep,
    291      1.13     pooka 	    l->l_cred);
    292       1.1   thorpej 
    293       1.1   thorpej 	if (auiop != NULL) {
    294       1.1   thorpej 		cnt -= auio.uio_resid;
    295       1.1   thorpej 		retval[0] = cnt;
    296       1.1   thorpej 	} else
    297       1.1   thorpej 		retval[0] = size;
    298       1.1   thorpej 
    299       1.1   thorpej  done:
    300       1.1   thorpej 	VOP_UNLOCK(vp, 0);
    301       1.1   thorpej 	return (error);
    302       1.1   thorpej }
    303       1.1   thorpej 
    304       1.1   thorpej /*
    305       1.1   thorpej  * extattr_delete_vp:
    306       1.1   thorpej  *
    307       1.1   thorpej  *	Delete a named extended attribute on a file or directory.
    308       1.1   thorpej  */
    309       1.1   thorpej static int
    310       1.1   thorpej extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname,
    311       1.4  christos     struct lwp *l)
    312       1.1   thorpej {
    313       1.1   thorpej 	int error;
    314       1.1   thorpej 
    315       1.1   thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    316       1.1   thorpej 
    317      1.13     pooka 	error = VOP_DELETEEXTATTR(vp, attrnamespace, attrname, l->l_cred);
    318       1.1   thorpej 	if (error == EOPNOTSUPP)
    319       1.1   thorpej 		error = VOP_SETEXTATTR(vp, attrnamespace, attrname, NULL,
    320      1.13     pooka 		    l->l_cred);
    321       1.1   thorpej 
    322       1.1   thorpej 	VOP_UNLOCK(vp, 0);
    323       1.1   thorpej 	return (error);
    324       1.1   thorpej }
    325       1.1   thorpej 
    326       1.1   thorpej /*
    327       1.1   thorpej  * extattr_list_vp:
    328       1.1   thorpej  *
    329       1.1   thorpej  *	Retrieve a list of extended attributes on a file or directory.
    330       1.1   thorpej  */
    331       1.1   thorpej static int
    332       1.1   thorpej extattr_list_vp(struct vnode *vp, int attrnamespace, void *data, size_t nbytes,
    333       1.4  christos     struct lwp *l, register_t *retval)
    334       1.1   thorpej {
    335       1.1   thorpej 	struct uio auio, *auiop;
    336       1.1   thorpej 	size_t size, *sizep;
    337       1.1   thorpej 	struct iovec aiov;
    338       1.1   thorpej 	ssize_t cnt;
    339       1.1   thorpej 	int error;
    340       1.1   thorpej 
    341       1.1   thorpej 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    342       1.1   thorpej 
    343       1.1   thorpej 	auiop = NULL;
    344       1.1   thorpej 	sizep = NULL;
    345       1.1   thorpej 	cnt = 0;
    346       1.1   thorpej 	if (data != NULL) {
    347       1.1   thorpej 		aiov.iov_base = data;
    348       1.1   thorpej 		aiov.iov_len = nbytes;
    349       1.1   thorpej 		auio.uio_iov = &aiov;
    350       1.1   thorpej 		auio.uio_offset = 0;
    351       1.1   thorpej 		if (nbytes > INT_MAX) {
    352       1.1   thorpej 			error = EINVAL;
    353       1.1   thorpej 			goto done;
    354       1.1   thorpej 		}
    355       1.1   thorpej 		auio.uio_resid = nbytes;
    356       1.1   thorpej 		auio.uio_rw = UIO_READ;
    357       1.5      yamt 		KASSERT(l == curlwp);
    358       1.5      yamt 		auio.uio_vmspace = l->l_proc->p_vmspace;
    359       1.1   thorpej 		auiop = &auio;
    360       1.1   thorpej 		cnt = nbytes;
    361       1.1   thorpej 	} else
    362       1.1   thorpej 		sizep = &size;
    363       1.1   thorpej 
    364      1.13     pooka 	error = VOP_LISTEXTATTR(vp, attrnamespace, auiop, sizep, l->l_cred);
    365       1.1   thorpej 
    366       1.1   thorpej 	if (auiop != NULL) {
    367       1.1   thorpej 		cnt -= auio.uio_resid;
    368       1.1   thorpej 		retval[0] = cnt;
    369       1.1   thorpej 	} else
    370       1.1   thorpej 		retval[0] = size;
    371       1.1   thorpej 
    372       1.1   thorpej  done:
    373       1.1   thorpej 	VOP_UNLOCK(vp, 0);
    374       1.1   thorpej 	return (error);
    375       1.1   thorpej }
    376       1.1   thorpej 
    377       1.1   thorpej /*****************************************************************************
    378       1.1   thorpej  * BSD <sys/extattr.h> API for file system extended attributes
    379       1.1   thorpej  *****************************************************************************/
    380       1.1   thorpej 
    381       1.1   thorpej int
    382      1.15       dsl sys_extattr_set_fd(struct lwp *l, const struct sys_extattr_set_fd_args *uap, register_t *retval)
    383       1.1   thorpej {
    384      1.15       dsl 	/* {
    385       1.1   thorpej 		syscallarg(int) fd;
    386       1.1   thorpej 		syscallarg(int) attrnamespace;
    387       1.1   thorpej 		syscallarg(const char *) attrname;
    388       1.1   thorpej 		syscallarg(const void *) data;
    389       1.1   thorpej 		syscallarg(size_t) nbytes;
    390      1.15       dsl 	} */
    391       1.1   thorpej 	struct file *fp;
    392       1.1   thorpej 	struct vnode *vp;
    393       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    394       1.1   thorpej 	int error;
    395       1.1   thorpej 
    396       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    397       1.1   thorpej 	    NULL);
    398       1.1   thorpej 	if (error)
    399       1.1   thorpej 		return (error);
    400       1.1   thorpej 
    401  1.16.6.1       mjf 	error = getvnode(SCARG(uap, fd), &fp);
    402       1.1   thorpej 	if (error)
    403       1.1   thorpej 		return (error);
    404       1.1   thorpej 	vp = (struct vnode *) fp->f_data;
    405       1.1   thorpej 
    406       1.1   thorpej 	error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
    407       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    408       1.1   thorpej 
    409  1.16.6.1       mjf 	fd_putfile(SCARG(uap, fd));
    410       1.1   thorpej 	return (error);
    411       1.1   thorpej }
    412       1.1   thorpej 
    413       1.1   thorpej int
    414      1.15       dsl sys_extattr_set_file(struct lwp *l, const struct sys_extattr_set_file_args *uap, register_t *retval)
    415       1.1   thorpej {
    416      1.15       dsl 	/* {
    417       1.1   thorpej 		syscallarg(const char *) path;
    418       1.1   thorpej 		syscallarg(int) attrnamespace;
    419       1.1   thorpej 		syscallarg(const char *) attrname;
    420       1.1   thorpej 		syscallarg(const void *) data;
    421       1.1   thorpej 		syscallarg(size_t) nbytes;
    422      1.15       dsl 	} */
    423       1.1   thorpej 	struct nameidata nd;
    424       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    425       1.1   thorpej 	int error;
    426       1.1   thorpej 
    427       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    428       1.1   thorpej 	    NULL);
    429       1.1   thorpej 	if (error)
    430       1.1   thorpej 		return (error);
    431       1.1   thorpej 
    432      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
    433       1.1   thorpej 	error = namei(&nd);
    434       1.1   thorpej 	if (error)
    435       1.1   thorpej 		return (error);
    436       1.1   thorpej 
    437       1.1   thorpej 	error = extattr_set_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    438       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    439       1.1   thorpej 
    440       1.1   thorpej 	vrele(nd.ni_vp);
    441       1.1   thorpej 	return (error);
    442       1.1   thorpej }
    443       1.1   thorpej 
    444       1.1   thorpej int
    445      1.15       dsl sys_extattr_set_link(struct lwp *l, const struct sys_extattr_set_link_args *uap, register_t *retval)
    446       1.1   thorpej {
    447      1.15       dsl 	/* {
    448       1.1   thorpej 		syscallarg(const char *) path;
    449       1.1   thorpej 		syscallarg(int) attrnamespace;
    450       1.1   thorpej 		syscallarg(const char *) attrname;
    451       1.1   thorpej 		syscallarg(const void *) data;
    452       1.1   thorpej 		syscallarg(size_t) nbytes;
    453      1.15       dsl 	} */
    454       1.1   thorpej 	struct nameidata nd;
    455       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    456       1.1   thorpej 	int error;
    457       1.1   thorpej 
    458       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    459       1.1   thorpej 	    NULL);
    460       1.1   thorpej 	if (error)
    461       1.1   thorpej 		return (error);
    462       1.1   thorpej 
    463      1.14     pooka 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path));
    464       1.1   thorpej 	error = namei(&nd);
    465       1.1   thorpej 	if (error)
    466       1.1   thorpej 		return (error);
    467       1.1   thorpej 
    468       1.1   thorpej 	error = extattr_set_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    469       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    470       1.1   thorpej 
    471       1.1   thorpej 	vrele(nd.ni_vp);
    472       1.1   thorpej 	return (error);
    473       1.1   thorpej }
    474       1.1   thorpej 
    475       1.1   thorpej int
    476      1.15       dsl sys_extattr_get_fd(struct lwp *l, const struct sys_extattr_get_fd_args *uap, register_t *retval)
    477       1.1   thorpej {
    478      1.15       dsl 	/* {
    479       1.1   thorpej 		syscallarg(int) fd;
    480       1.1   thorpej 		syscallarg(int) attrnamespace;
    481       1.1   thorpej 		syscallarg(const char *) attrname;
    482       1.1   thorpej 		syscallarg(void *) data;
    483       1.1   thorpej 		syscallarg(size_t) nbytes;
    484      1.15       dsl 	} */
    485       1.1   thorpej 	struct file *fp;
    486       1.1   thorpej 	struct vnode *vp;
    487       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    488       1.1   thorpej 	int error;
    489       1.1   thorpej 
    490       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    491       1.1   thorpej 	    NULL);
    492       1.1   thorpej 	if (error)
    493       1.1   thorpej 		return (error);
    494       1.1   thorpej 
    495  1.16.6.1       mjf 	error = getvnode(SCARG(uap, fd), &fp);
    496       1.1   thorpej 	if (error)
    497       1.1   thorpej 		return (error);
    498       1.1   thorpej 	vp = (struct vnode *) fp->f_data;
    499       1.1   thorpej 
    500       1.1   thorpej 	error = extattr_get_vp(vp, SCARG(uap, attrnamespace), attrname,
    501       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    502       1.1   thorpej 
    503  1.16.6.1       mjf 	fd_putfile(SCARG(uap, fd));
    504       1.1   thorpej 	return (error);
    505       1.1   thorpej }
    506       1.1   thorpej 
    507       1.1   thorpej int
    508      1.15       dsl sys_extattr_get_file(struct lwp *l, const struct sys_extattr_get_file_args *uap, register_t *retval)
    509       1.1   thorpej {
    510      1.15       dsl 	/* {
    511       1.1   thorpej 		syscallarg(const char *) path;
    512       1.1   thorpej 		syscallarg(int) attrnamespace;
    513       1.1   thorpej 		syscallarg(const char *) attrname;
    514       1.1   thorpej 		syscallarg(void *) data;
    515       1.1   thorpej 		syscallarg(size_t) nbytes;
    516      1.15       dsl 	} */
    517       1.1   thorpej 	struct nameidata nd;
    518       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    519       1.1   thorpej 	int error;
    520       1.1   thorpej 
    521       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    522       1.1   thorpej 	    NULL);
    523       1.1   thorpej 	if (error)
    524       1.1   thorpej 		return (error);
    525       1.1   thorpej 
    526      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
    527       1.1   thorpej 	error = namei(&nd);
    528       1.1   thorpej 	if (error)
    529       1.1   thorpej 		return (error);
    530       1.1   thorpej 
    531       1.1   thorpej 	error = extattr_get_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    532       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    533       1.1   thorpej 
    534       1.1   thorpej 	vrele(nd.ni_vp);
    535       1.1   thorpej 	return (error);
    536       1.1   thorpej }
    537       1.1   thorpej 
    538       1.1   thorpej int
    539      1.15       dsl sys_extattr_get_link(struct lwp *l, const struct sys_extattr_get_link_args *uap, register_t *retval)
    540       1.1   thorpej {
    541      1.15       dsl 	/* {
    542       1.1   thorpej 		syscallarg(const char *) path;
    543       1.1   thorpej 		syscallarg(int) attrnamespace;
    544       1.1   thorpej 		syscallarg(const char *) attrname;
    545       1.1   thorpej 		syscallarg(void *) data;
    546       1.1   thorpej 		syscallarg(size_t) nbytes;
    547      1.15       dsl 	} */
    548       1.1   thorpej 	struct nameidata nd;
    549       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    550       1.1   thorpej 	int error;
    551       1.1   thorpej 
    552       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    553       1.1   thorpej 	    NULL);
    554       1.1   thorpej 	if (error)
    555       1.1   thorpej 		return (error);
    556       1.1   thorpej 
    557      1.14     pooka 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path));
    558       1.1   thorpej 	error = namei(&nd);
    559       1.1   thorpej 	if (error)
    560       1.1   thorpej 		return (error);
    561       1.1   thorpej 
    562       1.1   thorpej 	error = extattr_get_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    563       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    564       1.1   thorpej 
    565       1.1   thorpej 	vrele(nd.ni_vp);
    566       1.1   thorpej 	return (error);
    567       1.1   thorpej }
    568       1.1   thorpej 
    569       1.1   thorpej int
    570      1.15       dsl sys_extattr_delete_fd(struct lwp *l, const struct sys_extattr_delete_fd_args *uap, register_t *retval)
    571       1.1   thorpej {
    572      1.15       dsl 	/* {
    573       1.1   thorpej 		syscallarg(int) fd;
    574       1.1   thorpej 		syscallarg(int) attrnamespace;
    575       1.1   thorpej 		syscallarg(const char *) attrname;
    576      1.15       dsl 	} */
    577       1.1   thorpej 	struct file *fp;
    578       1.1   thorpej 	struct vnode *vp;
    579       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    580       1.1   thorpej 	int error;
    581       1.1   thorpej 
    582       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    583       1.1   thorpej 	    NULL);
    584       1.1   thorpej 	if (error)
    585       1.1   thorpej 		return (error);
    586       1.1   thorpej 
    587  1.16.6.1       mjf 	error = getvnode(SCARG(uap, fd), &fp);
    588       1.1   thorpej 	if (error)
    589       1.1   thorpej 		return (error);
    590       1.1   thorpej 	vp = (struct vnode *) fp->f_data;
    591       1.1   thorpej 
    592       1.4  christos 	error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, l);
    593       1.1   thorpej 
    594  1.16.6.1       mjf 	fd_putfile(SCARG(uap, fd));
    595       1.1   thorpej 	return (error);
    596       1.1   thorpej }
    597       1.1   thorpej 
    598       1.1   thorpej int
    599      1.15       dsl sys_extattr_delete_file(struct lwp *l, const struct sys_extattr_delete_file_args *uap, register_t *retval)
    600       1.1   thorpej {
    601      1.15       dsl 	/* {
    602       1.1   thorpej 		syscallarg(const char *) path;
    603       1.1   thorpej 		syscallarg(int) attrnamespace;
    604       1.1   thorpej 		syscallarg(const char *) attrname;
    605      1.15       dsl 	} */
    606       1.1   thorpej 	struct nameidata nd;
    607       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    608       1.1   thorpej 	int error;
    609       1.1   thorpej 
    610       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    611       1.1   thorpej 	    NULL);
    612       1.1   thorpej 	if (error)
    613       1.1   thorpej 		return (error);
    614       1.1   thorpej 
    615      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
    616       1.1   thorpej 	error = namei(&nd);
    617       1.1   thorpej 	if (error)
    618       1.1   thorpej 		return (error);
    619       1.1   thorpej 
    620       1.1   thorpej 	error = extattr_delete_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    621       1.4  christos 	    l);
    622       1.1   thorpej 
    623       1.1   thorpej 	vrele(nd.ni_vp);
    624       1.1   thorpej 	return (error);
    625       1.1   thorpej }
    626       1.1   thorpej 
    627       1.1   thorpej int
    628      1.15       dsl sys_extattr_delete_link(struct lwp *l, const struct sys_extattr_delete_link_args *uap, register_t *retval)
    629       1.1   thorpej {
    630      1.15       dsl 	/* {
    631       1.1   thorpej 		syscallarg(const char *) path;
    632       1.1   thorpej 		syscallarg(int) attrnamespace;
    633       1.1   thorpej 		syscallarg(const char *) attrname;
    634      1.15       dsl 	} */
    635       1.1   thorpej 	struct nameidata nd;
    636       1.1   thorpej 	char attrname[EXTATTR_MAXNAMELEN];
    637       1.1   thorpej 	int error;
    638       1.1   thorpej 
    639       1.1   thorpej 	error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
    640       1.1   thorpej 	    NULL);
    641       1.1   thorpej 	if (error)
    642       1.1   thorpej 		return (error);
    643       1.1   thorpej 
    644      1.14     pooka 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path));
    645       1.1   thorpej 	error = namei(&nd);
    646       1.1   thorpej 	if (error)
    647       1.1   thorpej 		return (error);
    648       1.1   thorpej 
    649       1.1   thorpej 	error = extattr_delete_vp(nd.ni_vp, SCARG(uap, attrnamespace), attrname,
    650       1.4  christos 	    l);
    651       1.1   thorpej 
    652       1.1   thorpej 	vrele(nd.ni_vp);
    653       1.1   thorpej 	return (error);
    654       1.1   thorpej }
    655       1.1   thorpej 
    656       1.1   thorpej int
    657      1.15       dsl sys_extattr_list_fd(struct lwp *l, const struct sys_extattr_list_fd_args *uap, register_t *retval)
    658       1.1   thorpej {
    659      1.15       dsl 	/* {
    660       1.1   thorpej 		syscallarg(int) fd;
    661       1.1   thorpej 		syscallarg(int) attrnamespace;
    662       1.1   thorpej 		syscallarg(void *) data;
    663       1.1   thorpej 		syscallarg(size_t) nbytes;
    664      1.15       dsl 	} */
    665       1.1   thorpej 	struct file *fp;
    666       1.1   thorpej 	struct vnode *vp;
    667       1.1   thorpej 	int error;
    668       1.1   thorpej 
    669  1.16.6.1       mjf 	error = getvnode(SCARG(uap, fd), &fp);
    670       1.1   thorpej 	if (error)
    671       1.1   thorpej 		return (error);
    672       1.1   thorpej 	vp = (struct vnode *) fp->f_data;
    673       1.1   thorpej 
    674       1.1   thorpej 	error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
    675       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    676       1.1   thorpej 
    677  1.16.6.1       mjf 	fd_putfile(SCARG(uap, fd));
    678       1.1   thorpej 	return (error);
    679       1.1   thorpej }
    680       1.1   thorpej 
    681       1.1   thorpej int
    682      1.15       dsl sys_extattr_list_file(struct lwp *l, const struct sys_extattr_list_file_args *uap, register_t *retval)
    683       1.1   thorpej {
    684      1.15       dsl 	/* {
    685       1.1   thorpej 		syscallarg(const char *) path;
    686       1.1   thorpej 		syscallarg(int) attrnamespace;
    687       1.1   thorpej 		syscallarg(void *) data;
    688       1.1   thorpej 		syscallarg(size_t) nbytes;
    689      1.15       dsl 	} */
    690       1.1   thorpej 	struct nameidata nd;
    691       1.1   thorpej 	int error;
    692       1.1   thorpej 
    693      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
    694       1.1   thorpej 	error = namei(&nd);
    695       1.1   thorpej 	if (error)
    696       1.1   thorpej 		return (error);
    697       1.1   thorpej 
    698       1.1   thorpej 	error = extattr_list_vp(nd.ni_vp, SCARG(uap, attrnamespace),
    699       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    700       1.1   thorpej 
    701       1.1   thorpej 	vrele(nd.ni_vp);
    702       1.1   thorpej 	return (error);
    703       1.1   thorpej }
    704       1.1   thorpej 
    705       1.1   thorpej int
    706      1.15       dsl sys_extattr_list_link(struct lwp *l, const struct sys_extattr_list_link_args *uap, register_t *retval)
    707       1.1   thorpej {
    708      1.15       dsl 	/* {
    709       1.1   thorpej 		syscallarg(const char *) path;
    710       1.1   thorpej 		syscallarg(int) attrnamespace;
    711       1.1   thorpej 		syscallarg(void *) data;
    712       1.1   thorpej 		syscallarg(size_t) nbytes;
    713      1.15       dsl 	} */
    714       1.1   thorpej 	struct nameidata nd;
    715       1.1   thorpej 	int error;
    716       1.1   thorpej 
    717      1.14     pooka 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path));
    718       1.1   thorpej 	error = namei(&nd);
    719       1.1   thorpej 	if (error)
    720       1.1   thorpej 		return (error);
    721       1.1   thorpej 
    722       1.1   thorpej 	error = extattr_list_vp(nd.ni_vp, SCARG(uap, attrnamespace),
    723       1.4  christos 	    SCARG(uap, data), SCARG(uap, nbytes), l, retval);
    724       1.1   thorpej 
    725       1.1   thorpej 	vrele(nd.ni_vp);
    726       1.1   thorpej 	return (error);
    727       1.1   thorpej }
    728       1.2   thorpej 
    729       1.2   thorpej /*****************************************************************************
    730       1.2   thorpej  * Linux-compatible <sys/xattr.h> API for file system extended attributes
    731       1.2   thorpej  *****************************************************************************/
    732       1.2   thorpej 
    733       1.2   thorpej int
    734      1.15       dsl sys_setxattr(struct lwp *l, const struct sys_setxattr_args *uap, register_t *retval)
    735       1.2   thorpej {
    736      1.15       dsl 	/* {
    737       1.2   thorpej 		syscallarg(const char *) path;
    738       1.2   thorpej 		syscallarg(const char *) name;
    739       1.2   thorpej 		syscallarg(void *) value;
    740       1.2   thorpej 		syscallarg(size_t) size;
    741       1.2   thorpej 		syscallarg(int) flags;
    742      1.15       dsl 	} */
    743       1.2   thorpej 	struct nameidata nd;
    744       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
    745       1.2   thorpej 	int error;
    746       1.2   thorpej 
    747       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    748       1.2   thorpej 	    NULL);
    749       1.2   thorpej 	if (error)
    750       1.2   thorpej 		return (error);
    751       1.2   thorpej 
    752      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
    753       1.2   thorpej 	error = namei(&nd);
    754       1.2   thorpej 	if (error)
    755       1.2   thorpej 		return (error);
    756       1.2   thorpej 
    757       1.2   thorpej 	/* XXX flags */
    758       1.2   thorpej 
    759       1.2   thorpej 	error = extattr_set_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    760       1.4  christos 	    attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
    761       1.2   thorpej 
    762       1.2   thorpej 	vrele(nd.ni_vp);
    763       1.2   thorpej 	return (error);
    764       1.2   thorpej }
    765       1.2   thorpej 
    766       1.2   thorpej int
    767      1.15       dsl sys_lsetxattr(struct lwp *l, const struct sys_lsetxattr_args *uap, register_t *retval)
    768       1.2   thorpej {
    769      1.15       dsl 	/* {
    770       1.2   thorpej 		syscallarg(const char *) path;
    771       1.2   thorpej 		syscallarg(const char *) name;
    772       1.2   thorpej 		syscallarg(void *) value;
    773       1.2   thorpej 		syscallarg(size_t) size;
    774       1.2   thorpej 		syscallarg(int) flags;
    775      1.15       dsl 	} */
    776       1.2   thorpej 	struct nameidata nd;
    777       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
    778       1.2   thorpej 	int error;
    779       1.2   thorpej 
    780       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    781       1.2   thorpej 	    NULL);
    782       1.2   thorpej 	if (error)
    783       1.2   thorpej 		return (error);
    784       1.2   thorpej 
    785      1.14     pooka 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path));
    786       1.2   thorpej 	error = namei(&nd);
    787       1.2   thorpej 	if (error)
    788       1.2   thorpej 		return (error);
    789       1.2   thorpej 
    790       1.2   thorpej 	/* XXX flags */
    791       1.2   thorpej 
    792       1.2   thorpej 	error = extattr_set_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    793       1.4  christos 	    attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
    794       1.2   thorpej 
    795       1.2   thorpej 	vrele(nd.ni_vp);
    796       1.2   thorpej 	return (error);
    797       1.2   thorpej }
    798       1.2   thorpej 
    799       1.2   thorpej int
    800      1.15       dsl sys_fsetxattr(struct lwp *l, const struct sys_fsetxattr_args *uap, register_t *retval)
    801       1.2   thorpej {
    802      1.15       dsl 	/* {
    803       1.2   thorpej 		syscallarg(int) fd;
    804       1.2   thorpej 		syscallarg(const char *) name;
    805       1.2   thorpej 		syscallarg(void *) value;
    806       1.2   thorpej 		syscallarg(size_t) size;
    807       1.2   thorpej 		syscallarg(int) flags;
    808      1.15       dsl 	} */
    809       1.2   thorpej 	struct file *fp;
    810       1.2   thorpej 	struct vnode *vp;
    811       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
    812       1.2   thorpej 	int error;
    813       1.2   thorpej 
    814       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    815       1.2   thorpej 	    NULL);
    816       1.2   thorpej 	if (error)
    817       1.2   thorpej 		return (error);
    818       1.2   thorpej 
    819  1.16.6.1       mjf 	error = getvnode(SCARG(uap, fd), &fp);
    820       1.2   thorpej 	if (error)
    821       1.2   thorpej 		return (error);
    822       1.2   thorpej 	vp = (struct vnode *) fp->f_data;
    823       1.2   thorpej 
    824       1.2   thorpej 	/* XXX flags */
    825       1.2   thorpej 
    826       1.2   thorpej 	error = extattr_set_vp(vp, EXTATTR_NAMESPACE_USER,
    827       1.4  christos 	    attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
    828       1.2   thorpej 
    829  1.16.6.1       mjf 	fd_putfile(SCARG(uap, fd));
    830       1.2   thorpej 	return (error);
    831       1.2   thorpej }
    832       1.2   thorpej 
    833       1.2   thorpej int
    834      1.15       dsl sys_getxattr(struct lwp *l, const struct sys_getxattr_args *uap, register_t *retval)
    835       1.2   thorpej {
    836      1.15       dsl 	/* {
    837       1.2   thorpej 		syscallarg(const char *) path;
    838       1.2   thorpej 		syscallarg(const char *) name;
    839       1.2   thorpej 		syscallarg(void *) value;
    840       1.2   thorpej 		syscallarg(size_t) size;
    841      1.15       dsl 	} */
    842       1.2   thorpej 	struct nameidata nd;
    843       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
    844       1.2   thorpej 	int error;
    845       1.2   thorpej 
    846       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    847       1.2   thorpej 	    NULL);
    848       1.2   thorpej 	if (error)
    849       1.2   thorpej 		return (error);
    850       1.2   thorpej 
    851      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
    852       1.2   thorpej 	error = namei(&nd);
    853       1.2   thorpej 	if (error)
    854       1.2   thorpej 		return (error);
    855       1.2   thorpej 
    856       1.2   thorpej 	error = extattr_get_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    857       1.4  christos 	    attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
    858       1.2   thorpej 
    859       1.2   thorpej 	vrele(nd.ni_vp);
    860       1.2   thorpej 	return (error);
    861       1.2   thorpej }
    862       1.2   thorpej 
    863       1.2   thorpej int
    864      1.15       dsl sys_lgetxattr(struct lwp *l, const struct sys_lgetxattr_args *uap, register_t *retval)
    865       1.2   thorpej {
    866      1.15       dsl 	/* {
    867       1.2   thorpej 		syscallarg(const char *) path;
    868       1.2   thorpej 		syscallarg(const char *) name;
    869       1.2   thorpej 		syscallarg(void *) value;
    870       1.2   thorpej 		syscallarg(size_t) size;
    871      1.15       dsl 	} */
    872       1.2   thorpej 	struct nameidata nd;
    873       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
    874       1.2   thorpej 	int error;
    875       1.2   thorpej 
    876       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    877       1.2   thorpej 	    NULL);
    878       1.2   thorpej 	if (error)
    879       1.2   thorpej 		return (error);
    880       1.2   thorpej 
    881      1.14     pooka 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path));
    882       1.2   thorpej 	error = namei(&nd);
    883       1.2   thorpej 	if (error)
    884       1.2   thorpej 		return (error);
    885       1.2   thorpej 
    886       1.2   thorpej 	error = extattr_get_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    887       1.4  christos 	    attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
    888       1.2   thorpej 
    889       1.2   thorpej 	vrele(nd.ni_vp);
    890       1.2   thorpej 	return (error);
    891       1.2   thorpej }
    892       1.2   thorpej 
    893       1.2   thorpej int
    894      1.15       dsl sys_fgetxattr(struct lwp *l, const struct sys_fgetxattr_args *uap, register_t *retval)
    895       1.2   thorpej {
    896      1.15       dsl 	/* {
    897       1.2   thorpej 		syscallarg(int) fd;
    898       1.2   thorpej 		syscallarg(const char *) name;
    899       1.2   thorpej 		syscallarg(void *) value;
    900       1.2   thorpej 		syscallarg(size_t) size;
    901      1.15       dsl 	} */
    902       1.2   thorpej 	struct file *fp;
    903       1.2   thorpej 	struct vnode *vp;
    904       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
    905       1.2   thorpej 	int error;
    906       1.2   thorpej 
    907       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
    908       1.2   thorpej 	    NULL);
    909       1.2   thorpej 	if (error)
    910       1.2   thorpej 		return (error);
    911       1.2   thorpej 
    912  1.16.6.1       mjf 	error = getvnode(SCARG(uap, fd), &fp);
    913       1.2   thorpej 	if (error)
    914       1.2   thorpej 		return (error);
    915       1.2   thorpej 	vp = (struct vnode *) fp->f_data;
    916       1.2   thorpej 
    917       1.2   thorpej 	error = extattr_get_vp(vp, EXTATTR_NAMESPACE_USER,
    918       1.4  christos 	    attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
    919       1.2   thorpej 
    920  1.16.6.1       mjf 	fd_putfile(SCARG(uap, fd));
    921       1.2   thorpej 	return (error);
    922       1.2   thorpej }
    923       1.2   thorpej 
    924       1.2   thorpej int
    925      1.15       dsl sys_listxattr(struct lwp *l, const struct sys_listxattr_args *uap, register_t *retval)
    926       1.2   thorpej {
    927      1.15       dsl 	/* {
    928       1.2   thorpej 		syscallarg(const char *) path;
    929       1.2   thorpej 		syscallarg(char *) list;
    930       1.2   thorpej 		syscallarg(size_t) size;
    931      1.15       dsl 	} */
    932       1.2   thorpej 	struct nameidata nd;
    933       1.2   thorpej 	int error;
    934       1.2   thorpej 
    935      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
    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.4  christos 	    SCARG(uap, list), SCARG(uap, size), l, 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.15       dsl sys_llistxattr(struct lwp *l, const struct sys_llistxattr_args *uap, register_t *retval)
    949       1.2   thorpej {
    950      1.15       dsl 	/* {
    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.15       dsl 	} */
    955       1.2   thorpej 	struct nameidata nd;
    956       1.2   thorpej 	int error;
    957       1.2   thorpej 
    958      1.14     pooka 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path));
    959       1.2   thorpej 	error = namei(&nd);
    960       1.2   thorpej 	if (error)
    961       1.2   thorpej 		return (error);
    962       1.2   thorpej 
    963       1.2   thorpej 	error = extattr_list_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
    964       1.4  christos 	    SCARG(uap, list), SCARG(uap, size), l, retval);
    965       1.2   thorpej 
    966       1.2   thorpej 	vrele(nd.ni_vp);
    967       1.2   thorpej 	return (error);
    968       1.2   thorpej }
    969       1.2   thorpej 
    970       1.2   thorpej int
    971      1.15       dsl sys_flistxattr(struct lwp *l, const struct sys_flistxattr_args *uap, register_t *retval)
    972       1.2   thorpej {
    973      1.15       dsl 	/* {
    974       1.2   thorpej 		syscallarg(int) fd;
    975       1.2   thorpej 		syscallarg(char *) list;
    976       1.2   thorpej 		syscallarg(size_t) size;
    977      1.15       dsl 	} */
    978       1.2   thorpej 	struct file *fp;
    979       1.2   thorpej 	struct vnode *vp;
    980       1.2   thorpej 	int error;
    981       1.2   thorpej 
    982  1.16.6.1       mjf 	error = getvnode(SCARG(uap, fd), &fp);
    983       1.2   thorpej 	if (error)
    984       1.2   thorpej 		return (error);
    985       1.2   thorpej 	vp = (struct vnode *) fp->f_data;
    986       1.2   thorpej 
    987       1.2   thorpej 	error = extattr_list_vp(vp, EXTATTR_NAMESPACE_USER,
    988       1.4  christos 	    SCARG(uap, list), SCARG(uap, size), l, retval);
    989       1.2   thorpej 
    990  1.16.6.1       mjf 	fd_putfile(SCARG(uap, fd));
    991       1.2   thorpej 	return (error);
    992       1.2   thorpej }
    993       1.2   thorpej 
    994       1.2   thorpej int
    995      1.15       dsl sys_removexattr(struct lwp *l, const struct sys_removexattr_args *uap, register_t *retval)
    996       1.2   thorpej {
    997      1.15       dsl 	/* {
    998       1.2   thorpej 		syscallarg(const char *) path;
    999       1.2   thorpej 		syscallarg(const char *) name;
   1000      1.15       dsl 	} */
   1001       1.2   thorpej 	struct nameidata nd;
   1002       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
   1003       1.2   thorpej 	int error;
   1004       1.2   thorpej 
   1005       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
   1006       1.2   thorpej 	    NULL);
   1007       1.2   thorpej 	if (error)
   1008       1.2   thorpej 		return (error);
   1009       1.2   thorpej 
   1010      1.14     pooka 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path));
   1011       1.2   thorpej 	error = namei(&nd);
   1012       1.2   thorpej 	if (error)
   1013       1.2   thorpej 		return (error);
   1014       1.2   thorpej 
   1015       1.2   thorpej 	error = extattr_delete_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
   1016       1.4  christos 	    attrname, l);
   1017       1.2   thorpej 
   1018       1.2   thorpej 	vrele(nd.ni_vp);
   1019       1.2   thorpej 	return (error);
   1020       1.2   thorpej }
   1021       1.2   thorpej 
   1022       1.2   thorpej int
   1023      1.15       dsl sys_lremovexattr(struct lwp *l, const struct sys_lremovexattr_args *uap, register_t *retval)
   1024       1.2   thorpej {
   1025      1.15       dsl 	/* {
   1026       1.2   thorpej 		syscallarg(const char *) path;
   1027       1.2   thorpej 		syscallarg(const char *) name;
   1028      1.15       dsl 	} */
   1029       1.2   thorpej 	struct nameidata nd;
   1030       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
   1031       1.2   thorpej 	int error;
   1032       1.2   thorpej 
   1033       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
   1034       1.2   thorpej 	    NULL);
   1035       1.2   thorpej 	if (error)
   1036       1.2   thorpej 		return (error);
   1037       1.2   thorpej 
   1038      1.14     pooka 	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path));
   1039       1.2   thorpej 	error = namei(&nd);
   1040       1.2   thorpej 	if (error)
   1041       1.2   thorpej 		return (error);
   1042       1.2   thorpej 
   1043       1.2   thorpej 	error = extattr_delete_vp(nd.ni_vp, EXTATTR_NAMESPACE_USER,
   1044       1.4  christos 	    attrname, l);
   1045       1.2   thorpej 
   1046       1.2   thorpej 	vrele(nd.ni_vp);
   1047       1.2   thorpej 	return (error);
   1048       1.2   thorpej }
   1049       1.2   thorpej 
   1050       1.2   thorpej int
   1051      1.15       dsl sys_fremovexattr(struct lwp *l, const struct sys_fremovexattr_args *uap, register_t *retval)
   1052       1.2   thorpej {
   1053      1.15       dsl 	/* {
   1054       1.2   thorpej 		syscallarg(int) fd;
   1055       1.2   thorpej 		syscallarg(const char *) name;
   1056      1.15       dsl 	} */
   1057       1.2   thorpej 	struct file *fp;
   1058       1.2   thorpej 	struct vnode *vp;
   1059       1.2   thorpej 	char attrname[XATTR_NAME_MAX];
   1060       1.2   thorpej 	int error;
   1061       1.2   thorpej 
   1062       1.2   thorpej 	error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
   1063       1.2   thorpej 	    NULL);
   1064       1.2   thorpej 	if (error)
   1065       1.2   thorpej 		return (error);
   1066       1.2   thorpej 
   1067  1.16.6.1       mjf 	error = getvnode(SCARG(uap, fd), &fp);
   1068       1.2   thorpej 	if (error)
   1069       1.2   thorpej 		return (error);
   1070       1.2   thorpej 	vp = (struct vnode *) fp->f_data;
   1071       1.2   thorpej 
   1072       1.2   thorpej 	error = extattr_delete_vp(vp, EXTATTR_NAMESPACE_USER,
   1073       1.4  christos 	    attrname, l);
   1074       1.2   thorpej 
   1075  1.16.6.1       mjf 	fd_putfile(SCARG(uap, fd));
   1076       1.2   thorpej 	return (error);
   1077       1.2   thorpej }
   1078