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