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