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