vfs_xattr.c revision 1.26 1 1.26 manu /* $NetBSD: vfs_xattr.c,v 1.26 2011/06/29 08:01:14 manu 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.26 manu __KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.26 2011/06/29 08:01:14 manu 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.22 hannken VOP_UNLOCK(vp);
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.23 dholland struct pathbuf *file_pb;
154 1.20 dholland struct nameidata file_nd;
155 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
156 1.1 thorpej int error;
157 1.1 thorpej
158 1.1 thorpej if (SCARG(uap, attrname) != NULL) {
159 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname,
160 1.1 thorpej sizeof(attrname), NULL);
161 1.1 thorpej if (error)
162 1.1 thorpej return (error);
163 1.1 thorpej }
164 1.1 thorpej
165 1.21 pooka error = namei_simple_user(SCARG(uap, path),
166 1.21 pooka NSM_FOLLOW_NOEMULROOT, &path_vp);
167 1.21 pooka if (error) {
168 1.21 pooka return (error);
169 1.21 pooka }
170 1.21 pooka
171 1.20 dholland file_vp = NULL;
172 1.1 thorpej if (SCARG(uap, filename) != NULL) {
173 1.23 dholland error = pathbuf_copyin(SCARG(uap, filename), &file_pb);
174 1.23 dholland if (error) {
175 1.23 dholland vrele(path_vp);
176 1.23 dholland return (error);
177 1.23 dholland }
178 1.23 dholland NDINIT(&file_nd, LOOKUP, FOLLOW | LOCKLEAF, file_pb);
179 1.20 dholland error = namei(&file_nd);
180 1.21 pooka if (error) {
181 1.23 dholland pathbuf_destroy(file_pb);
182 1.21 pooka vrele(path_vp);
183 1.1 thorpej return (error);
184 1.21 pooka }
185 1.20 dholland file_vp = file_nd.ni_vp;
186 1.23 dholland pathbuf_destroy(file_pb);
187 1.1 thorpej }
188 1.1 thorpej
189 1.20 dholland error = VFS_EXTATTRCTL(path_vp->v_mount, SCARG(uap, cmd), file_vp,
190 1.1 thorpej SCARG(uap, attrnamespace),
191 1.13 pooka SCARG(uap, attrname) != NULL ? attrname : NULL);
192 1.1 thorpej
193 1.20 dholland if (file_vp != NULL)
194 1.20 dholland vrele(file_vp);
195 1.20 dholland vrele(path_vp);
196 1.1 thorpej
197 1.1 thorpej return (error);
198 1.1 thorpej }
199 1.1 thorpej
200 1.1 thorpej /*****************************************************************************
201 1.1 thorpej * Internal routines to manipulate file system extended attributes:
202 1.1 thorpej * - set
203 1.1 thorpej * - get
204 1.1 thorpej * - delete
205 1.1 thorpej * - list
206 1.1 thorpej *****************************************************************************/
207 1.1 thorpej
208 1.1 thorpej /*
209 1.1 thorpej * extattr_set_vp:
210 1.1 thorpej *
211 1.1 thorpej * Set a named extended attribute on a file or directory.
212 1.1 thorpej */
213 1.1 thorpej static int
214 1.1 thorpej extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname,
215 1.24 manu const void *data, size_t nbytes, struct lwp *l, register_t *retval,
216 1.24 manu int flag)
217 1.1 thorpej {
218 1.1 thorpej struct uio auio;
219 1.1 thorpej struct iovec aiov;
220 1.1 thorpej ssize_t cnt;
221 1.1 thorpej int error;
222 1.1 thorpej
223 1.1 thorpej vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
224 1.1 thorpej
225 1.24 manu if (flag) {
226 1.24 manu size_t attrlen;
227 1.24 manu
228 1.24 manu error = VOP_GETEXTATTR(vp, attrnamespace, attrname, NULL,
229 1.24 manu &attrlen, l->l_cred);
230 1.24 manu
231 1.24 manu switch (error) {
232 1.24 manu case ENOATTR:
233 1.24 manu if (flag & XATTR_REPLACE)
234 1.24 manu goto done;
235 1.24 manu break;
236 1.24 manu case 0:
237 1.24 manu if (flag & XATTR_CREATE) {
238 1.24 manu error = EEXIST;
239 1.24 manu goto done;
240 1.24 manu }
241 1.24 manu break;
242 1.24 manu default:
243 1.24 manu goto done;
244 1.24 manu break;
245 1.24 manu }
246 1.24 manu }
247 1.24 manu
248 1.1 thorpej aiov.iov_base = __UNCONST(data); /* XXXUNCONST kills const */
249 1.1 thorpej aiov.iov_len = nbytes;
250 1.1 thorpej auio.uio_iov = &aiov;
251 1.1 thorpej auio.uio_iovcnt = 1;
252 1.1 thorpej auio.uio_offset = 0;
253 1.1 thorpej if (nbytes > INT_MAX) {
254 1.1 thorpej error = EINVAL;
255 1.1 thorpej goto done;
256 1.1 thorpej }
257 1.1 thorpej auio.uio_resid = nbytes;
258 1.1 thorpej auio.uio_rw = UIO_WRITE;
259 1.5 yamt KASSERT(l == curlwp);
260 1.5 yamt auio.uio_vmspace = l->l_proc->p_vmspace;
261 1.1 thorpej cnt = nbytes;
262 1.1 thorpej
263 1.13 pooka error = VOP_SETEXTATTR(vp, attrnamespace, attrname, &auio, l->l_cred);
264 1.1 thorpej cnt -= auio.uio_resid;
265 1.1 thorpej retval[0] = cnt;
266 1.1 thorpej
267 1.1 thorpej done:
268 1.22 hannken VOP_UNLOCK(vp);
269 1.1 thorpej return (error);
270 1.1 thorpej }
271 1.1 thorpej
272 1.1 thorpej /*
273 1.1 thorpej * extattr_get_vp:
274 1.1 thorpej *
275 1.1 thorpej * Get a named extended attribute on a file or directory.
276 1.1 thorpej */
277 1.1 thorpej static int
278 1.1 thorpej extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname,
279 1.4 christos void *data, size_t nbytes, struct lwp *l, register_t *retval)
280 1.1 thorpej {
281 1.1 thorpej struct uio auio, *auiop;
282 1.1 thorpej struct iovec aiov;
283 1.1 thorpej ssize_t cnt;
284 1.1 thorpej size_t size, *sizep;
285 1.1 thorpej int error;
286 1.1 thorpej
287 1.1 thorpej vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
288 1.1 thorpej
289 1.1 thorpej /*
290 1.1 thorpej * Slightly unusual semantics: if the user provides a NULL data
291 1.1 thorpej * pointer, they don't want to receive the data, just the maximum
292 1.1 thorpej * read length.
293 1.1 thorpej */
294 1.1 thorpej auiop = NULL;
295 1.1 thorpej sizep = NULL;
296 1.1 thorpej cnt = 0;
297 1.1 thorpej if (data != NULL) {
298 1.1 thorpej aiov.iov_base = data;
299 1.1 thorpej aiov.iov_len = nbytes;
300 1.1 thorpej auio.uio_iov = &aiov;
301 1.1 thorpej auio.uio_offset = 0;
302 1.1 thorpej if (nbytes > INT_MAX) {
303 1.1 thorpej error = EINVAL;
304 1.1 thorpej goto done;
305 1.1 thorpej }
306 1.1 thorpej auio.uio_resid = nbytes;
307 1.1 thorpej auio.uio_rw = UIO_READ;
308 1.5 yamt KASSERT(l == curlwp);
309 1.5 yamt auio.uio_vmspace = l->l_proc->p_vmspace;
310 1.1 thorpej auiop = &auio;
311 1.1 thorpej cnt = nbytes;
312 1.1 thorpej } else
313 1.1 thorpej sizep = &size;
314 1.1 thorpej
315 1.1 thorpej error = VOP_GETEXTATTR(vp, attrnamespace, attrname, auiop, sizep,
316 1.13 pooka l->l_cred);
317 1.1 thorpej
318 1.1 thorpej if (auiop != NULL) {
319 1.1 thorpej cnt -= auio.uio_resid;
320 1.1 thorpej retval[0] = cnt;
321 1.1 thorpej } else
322 1.1 thorpej retval[0] = size;
323 1.1 thorpej
324 1.1 thorpej done:
325 1.22 hannken VOP_UNLOCK(vp);
326 1.1 thorpej return (error);
327 1.1 thorpej }
328 1.1 thorpej
329 1.1 thorpej /*
330 1.1 thorpej * extattr_delete_vp:
331 1.1 thorpej *
332 1.1 thorpej * Delete a named extended attribute on a file or directory.
333 1.1 thorpej */
334 1.1 thorpej static int
335 1.1 thorpej extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname,
336 1.4 christos struct lwp *l)
337 1.1 thorpej {
338 1.1 thorpej int error;
339 1.1 thorpej
340 1.1 thorpej vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
341 1.1 thorpej
342 1.13 pooka error = VOP_DELETEEXTATTR(vp, attrnamespace, attrname, l->l_cred);
343 1.1 thorpej if (error == EOPNOTSUPP)
344 1.1 thorpej error = VOP_SETEXTATTR(vp, attrnamespace, attrname, NULL,
345 1.13 pooka l->l_cred);
346 1.1 thorpej
347 1.22 hannken VOP_UNLOCK(vp);
348 1.1 thorpej return (error);
349 1.1 thorpej }
350 1.1 thorpej
351 1.1 thorpej /*
352 1.1 thorpej * extattr_list_vp:
353 1.1 thorpej *
354 1.1 thorpej * Retrieve a list of extended attributes on a file or directory.
355 1.1 thorpej */
356 1.1 thorpej static int
357 1.1 thorpej extattr_list_vp(struct vnode *vp, int attrnamespace, void *data, size_t nbytes,
358 1.4 christos struct lwp *l, register_t *retval)
359 1.1 thorpej {
360 1.1 thorpej struct uio auio, *auiop;
361 1.1 thorpej size_t size, *sizep;
362 1.1 thorpej struct iovec aiov;
363 1.1 thorpej ssize_t cnt;
364 1.1 thorpej int error;
365 1.1 thorpej
366 1.1 thorpej vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
367 1.1 thorpej
368 1.1 thorpej auiop = NULL;
369 1.1 thorpej sizep = NULL;
370 1.1 thorpej cnt = 0;
371 1.1 thorpej if (data != NULL) {
372 1.1 thorpej aiov.iov_base = data;
373 1.1 thorpej aiov.iov_len = nbytes;
374 1.1 thorpej auio.uio_iov = &aiov;
375 1.1 thorpej auio.uio_offset = 0;
376 1.1 thorpej if (nbytes > INT_MAX) {
377 1.1 thorpej error = EINVAL;
378 1.1 thorpej goto done;
379 1.1 thorpej }
380 1.1 thorpej auio.uio_resid = nbytes;
381 1.1 thorpej auio.uio_rw = UIO_READ;
382 1.5 yamt KASSERT(l == curlwp);
383 1.5 yamt auio.uio_vmspace = l->l_proc->p_vmspace;
384 1.1 thorpej auiop = &auio;
385 1.1 thorpej cnt = nbytes;
386 1.1 thorpej } else
387 1.1 thorpej sizep = &size;
388 1.1 thorpej
389 1.13 pooka error = VOP_LISTEXTATTR(vp, attrnamespace, auiop, sizep, l->l_cred);
390 1.1 thorpej
391 1.1 thorpej if (auiop != NULL) {
392 1.1 thorpej cnt -= auio.uio_resid;
393 1.1 thorpej retval[0] = cnt;
394 1.1 thorpej } else
395 1.1 thorpej retval[0] = size;
396 1.1 thorpej
397 1.1 thorpej done:
398 1.22 hannken VOP_UNLOCK(vp);
399 1.1 thorpej return (error);
400 1.1 thorpej }
401 1.1 thorpej
402 1.1 thorpej /*****************************************************************************
403 1.1 thorpej * BSD <sys/extattr.h> API for file system extended attributes
404 1.1 thorpej *****************************************************************************/
405 1.1 thorpej
406 1.1 thorpej int
407 1.15 dsl sys_extattr_set_fd(struct lwp *l, const struct sys_extattr_set_fd_args *uap, register_t *retval)
408 1.1 thorpej {
409 1.15 dsl /* {
410 1.1 thorpej syscallarg(int) fd;
411 1.1 thorpej syscallarg(int) attrnamespace;
412 1.1 thorpej syscallarg(const char *) attrname;
413 1.1 thorpej syscallarg(const void *) data;
414 1.1 thorpej syscallarg(size_t) nbytes;
415 1.15 dsl } */
416 1.1 thorpej struct file *fp;
417 1.1 thorpej 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.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
427 1.1 thorpej if (error)
428 1.1 thorpej return (error);
429 1.1 thorpej vp = (struct vnode *) fp->f_data;
430 1.1 thorpej
431 1.1 thorpej error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
432 1.24 manu SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
433 1.1 thorpej
434 1.17 ad fd_putfile(SCARG(uap, fd));
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_file(struct lwp *l, const struct sys_extattr_set_file_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_FOLLOW_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.24 manu SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
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_set_link(struct lwp *l, const struct sys_extattr_set_link_args *uap, register_t *retval)
471 1.1 thorpej {
472 1.15 dsl /* {
473 1.1 thorpej syscallarg(const char *) path;
474 1.1 thorpej syscallarg(int) attrnamespace;
475 1.1 thorpej syscallarg(const char *) attrname;
476 1.1 thorpej syscallarg(const void *) data;
477 1.1 thorpej syscallarg(size_t) nbytes;
478 1.15 dsl } */
479 1.20 dholland struct vnode *vp;
480 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
481 1.1 thorpej int error;
482 1.1 thorpej
483 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
484 1.1 thorpej NULL);
485 1.1 thorpej if (error)
486 1.1 thorpej return (error);
487 1.1 thorpej
488 1.20 dholland error = namei_simple_user(SCARG(uap, path),
489 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
490 1.1 thorpej if (error)
491 1.1 thorpej return (error);
492 1.1 thorpej
493 1.20 dholland error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
494 1.24 manu SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
495 1.1 thorpej
496 1.20 dholland vrele(vp);
497 1.1 thorpej return (error);
498 1.1 thorpej }
499 1.1 thorpej
500 1.1 thorpej int
501 1.15 dsl sys_extattr_get_fd(struct lwp *l, const struct sys_extattr_get_fd_args *uap, register_t *retval)
502 1.1 thorpej {
503 1.15 dsl /* {
504 1.1 thorpej syscallarg(int) fd;
505 1.1 thorpej syscallarg(int) attrnamespace;
506 1.1 thorpej syscallarg(const char *) attrname;
507 1.1 thorpej syscallarg(void *) data;
508 1.1 thorpej syscallarg(size_t) nbytes;
509 1.15 dsl } */
510 1.1 thorpej struct file *fp;
511 1.1 thorpej 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.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
521 1.1 thorpej if (error)
522 1.1 thorpej return (error);
523 1.1 thorpej vp = (struct vnode *) fp->f_data;
524 1.1 thorpej
525 1.1 thorpej 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.17 ad fd_putfile(SCARG(uap, fd));
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_file(struct lwp *l, const struct sys_extattr_get_file_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_FOLLOW_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_get_link(struct lwp *l, const struct sys_extattr_get_link_args *uap, register_t *retval)
565 1.1 thorpej {
566 1.15 dsl /* {
567 1.1 thorpej syscallarg(const char *) path;
568 1.1 thorpej syscallarg(int) attrnamespace;
569 1.1 thorpej syscallarg(const char *) attrname;
570 1.1 thorpej syscallarg(void *) data;
571 1.1 thorpej syscallarg(size_t) nbytes;
572 1.15 dsl } */
573 1.20 dholland struct vnode *vp;
574 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
575 1.1 thorpej int error;
576 1.1 thorpej
577 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
578 1.1 thorpej NULL);
579 1.1 thorpej if (error)
580 1.1 thorpej return (error);
581 1.1 thorpej
582 1.20 dholland error = namei_simple_user(SCARG(uap, path),
583 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
584 1.1 thorpej if (error)
585 1.1 thorpej return (error);
586 1.1 thorpej
587 1.20 dholland error = extattr_get_vp(vp, SCARG(uap, attrnamespace), attrname,
588 1.4 christos SCARG(uap, data), SCARG(uap, nbytes), l, retval);
589 1.1 thorpej
590 1.20 dholland vrele(vp);
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_fd(struct lwp *l, const struct sys_extattr_delete_fd_args *uap, register_t *retval)
596 1.1 thorpej {
597 1.15 dsl /* {
598 1.1 thorpej syscallarg(int) fd;
599 1.1 thorpej syscallarg(int) attrnamespace;
600 1.1 thorpej syscallarg(const char *) attrname;
601 1.15 dsl } */
602 1.1 thorpej struct file *fp;
603 1.1 thorpej struct vnode *vp;
604 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
605 1.1 thorpej int error;
606 1.1 thorpej
607 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
608 1.1 thorpej NULL);
609 1.1 thorpej if (error)
610 1.1 thorpej return (error);
611 1.1 thorpej
612 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
613 1.1 thorpej if (error)
614 1.1 thorpej return (error);
615 1.1 thorpej vp = (struct vnode *) fp->f_data;
616 1.1 thorpej
617 1.4 christos error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, l);
618 1.1 thorpej
619 1.17 ad fd_putfile(SCARG(uap, fd));
620 1.1 thorpej return (error);
621 1.1 thorpej }
622 1.1 thorpej
623 1.1 thorpej int
624 1.15 dsl sys_extattr_delete_file(struct lwp *l, const struct sys_extattr_delete_file_args *uap, register_t *retval)
625 1.1 thorpej {
626 1.15 dsl /* {
627 1.1 thorpej syscallarg(const char *) path;
628 1.1 thorpej syscallarg(int) attrnamespace;
629 1.1 thorpej syscallarg(const char *) attrname;
630 1.15 dsl } */
631 1.20 dholland struct vnode *vp;
632 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
633 1.1 thorpej int error;
634 1.1 thorpej
635 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
636 1.1 thorpej NULL);
637 1.1 thorpej if (error)
638 1.1 thorpej return (error);
639 1.1 thorpej
640 1.20 dholland error = namei_simple_user(SCARG(uap, path),
641 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
642 1.1 thorpej if (error)
643 1.1 thorpej return (error);
644 1.1 thorpej
645 1.20 dholland error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, l);
646 1.1 thorpej
647 1.20 dholland vrele(vp);
648 1.1 thorpej return (error);
649 1.1 thorpej }
650 1.1 thorpej
651 1.1 thorpej int
652 1.15 dsl sys_extattr_delete_link(struct lwp *l, const struct sys_extattr_delete_link_args *uap, register_t *retval)
653 1.1 thorpej {
654 1.15 dsl /* {
655 1.1 thorpej syscallarg(const char *) path;
656 1.1 thorpej syscallarg(int) attrnamespace;
657 1.1 thorpej syscallarg(const char *) attrname;
658 1.15 dsl } */
659 1.20 dholland struct vnode *vp;
660 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
661 1.1 thorpej int error;
662 1.1 thorpej
663 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
664 1.1 thorpej NULL);
665 1.1 thorpej if (error)
666 1.1 thorpej return (error);
667 1.1 thorpej
668 1.20 dholland error = namei_simple_user(SCARG(uap, path),
669 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
670 1.1 thorpej if (error)
671 1.1 thorpej return (error);
672 1.1 thorpej
673 1.20 dholland error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, l);
674 1.1 thorpej
675 1.20 dholland vrele(vp);
676 1.1 thorpej return (error);
677 1.1 thorpej }
678 1.1 thorpej
679 1.1 thorpej int
680 1.15 dsl sys_extattr_list_fd(struct lwp *l, const struct sys_extattr_list_fd_args *uap, register_t *retval)
681 1.1 thorpej {
682 1.15 dsl /* {
683 1.1 thorpej syscallarg(int) fd;
684 1.1 thorpej syscallarg(int) attrnamespace;
685 1.1 thorpej syscallarg(void *) data;
686 1.1 thorpej syscallarg(size_t) nbytes;
687 1.15 dsl } */
688 1.1 thorpej struct file *fp;
689 1.1 thorpej struct vnode *vp;
690 1.1 thorpej int error;
691 1.1 thorpej
692 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
693 1.1 thorpej if (error)
694 1.1 thorpej return (error);
695 1.1 thorpej vp = (struct vnode *) fp->f_data;
696 1.1 thorpej
697 1.1 thorpej error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
698 1.4 christos SCARG(uap, data), SCARG(uap, nbytes), l, retval);
699 1.1 thorpej
700 1.17 ad fd_putfile(SCARG(uap, fd));
701 1.1 thorpej return (error);
702 1.1 thorpej }
703 1.1 thorpej
704 1.1 thorpej int
705 1.15 dsl sys_extattr_list_file(struct lwp *l, const struct sys_extattr_list_file_args *uap, register_t *retval)
706 1.1 thorpej {
707 1.15 dsl /* {
708 1.1 thorpej syscallarg(const char *) path;
709 1.1 thorpej syscallarg(int) attrnamespace;
710 1.1 thorpej syscallarg(void *) data;
711 1.1 thorpej syscallarg(size_t) nbytes;
712 1.15 dsl } */
713 1.20 dholland struct vnode *vp;
714 1.1 thorpej int error;
715 1.1 thorpej
716 1.20 dholland error = namei_simple_user(SCARG(uap, path),
717 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
718 1.1 thorpej if (error)
719 1.1 thorpej return (error);
720 1.1 thorpej
721 1.20 dholland error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
722 1.4 christos SCARG(uap, data), SCARG(uap, nbytes), l, retval);
723 1.1 thorpej
724 1.20 dholland vrele(vp);
725 1.1 thorpej return (error);
726 1.1 thorpej }
727 1.1 thorpej
728 1.1 thorpej int
729 1.15 dsl sys_extattr_list_link(struct lwp *l, const struct sys_extattr_list_link_args *uap, register_t *retval)
730 1.1 thorpej {
731 1.15 dsl /* {
732 1.1 thorpej syscallarg(const char *) path;
733 1.1 thorpej syscallarg(int) attrnamespace;
734 1.1 thorpej syscallarg(void *) data;
735 1.1 thorpej syscallarg(size_t) nbytes;
736 1.15 dsl } */
737 1.20 dholland struct vnode *vp;
738 1.1 thorpej int error;
739 1.1 thorpej
740 1.20 dholland error = namei_simple_user(SCARG(uap, path),
741 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
742 1.1 thorpej if (error)
743 1.1 thorpej return (error);
744 1.1 thorpej
745 1.20 dholland error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
746 1.4 christos SCARG(uap, data), SCARG(uap, nbytes), l, retval);
747 1.1 thorpej
748 1.20 dholland vrele(vp);
749 1.1 thorpej return (error);
750 1.1 thorpej }
751 1.2 thorpej
752 1.2 thorpej /*****************************************************************************
753 1.2 thorpej * Linux-compatible <sys/xattr.h> API for file system extended attributes
754 1.2 thorpej *****************************************************************************/
755 1.2 thorpej
756 1.24 manu #define MATCH_NS(ns, key) (strncmp(ns, key, sizeof(ns) - 1) == 0)
757 1.24 manu static int
758 1.24 manu xattr_native(const char *key) {
759 1.24 manu if (MATCH_NS("system.", key))
760 1.24 manu return EXTATTR_NAMESPACE_SYSTEM;
761 1.24 manu else if (MATCH_NS("user.", key))
762 1.24 manu return EXTATTR_NAMESPACE_USER;
763 1.24 manu else if (MATCH_NS("security.", key))
764 1.24 manu return EXTATTR_NAMESPACE_SYSTEM;
765 1.24 manu else if (MATCH_NS("trusted.", key))
766 1.24 manu return EXTATTR_NAMESPACE_SYSTEM;
767 1.24 manu else
768 1.24 manu return EXTATTR_NAMESPACE_USER;
769 1.24 manu
770 1.24 manu }
771 1.24 manu #undef MATCH_NS
772 1.24 manu
773 1.2 thorpej int
774 1.15 dsl sys_setxattr(struct lwp *l, const struct sys_setxattr_args *uap, register_t *retval)
775 1.2 thorpej {
776 1.15 dsl /* {
777 1.2 thorpej syscallarg(const char *) path;
778 1.2 thorpej syscallarg(const char *) name;
779 1.2 thorpej syscallarg(void *) value;
780 1.2 thorpej syscallarg(size_t) size;
781 1.2 thorpej syscallarg(int) flags;
782 1.15 dsl } */
783 1.20 dholland struct vnode *vp;
784 1.2 thorpej char attrname[XATTR_NAME_MAX];
785 1.24 manu int namespace;
786 1.24 manu register_t attrlen;
787 1.2 thorpej int error;
788 1.2 thorpej
789 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
790 1.2 thorpej NULL);
791 1.2 thorpej if (error)
792 1.24 manu goto out;
793 1.2 thorpej
794 1.20 dholland error = namei_simple_user(SCARG(uap, path),
795 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
796 1.2 thorpej if (error)
797 1.26 manu goto out;
798 1.2 thorpej
799 1.24 manu namespace = xattr_native(attrname);
800 1.2 thorpej
801 1.24 manu error = extattr_set_vp(vp, namespace,
802 1.24 manu attrname, SCARG(uap, value), SCARG(uap, size), l,
803 1.24 manu &attrlen, SCARG(uap, flags));
804 1.2 thorpej
805 1.20 dholland vrele(vp);
806 1.24 manu out:
807 1.24 manu *retval = (error == 0) ? 0 : -1;
808 1.2 thorpej return (error);
809 1.2 thorpej }
810 1.2 thorpej
811 1.2 thorpej int
812 1.15 dsl sys_lsetxattr(struct lwp *l, const struct sys_lsetxattr_args *uap, register_t *retval)
813 1.2 thorpej {
814 1.15 dsl /* {
815 1.2 thorpej syscallarg(const char *) path;
816 1.2 thorpej syscallarg(const char *) name;
817 1.2 thorpej syscallarg(void *) value;
818 1.2 thorpej syscallarg(size_t) size;
819 1.2 thorpej syscallarg(int) flags;
820 1.15 dsl } */
821 1.20 dholland struct vnode *vp;
822 1.2 thorpej char attrname[XATTR_NAME_MAX];
823 1.24 manu int namespace;
824 1.24 manu register_t attrlen;
825 1.2 thorpej int error;
826 1.2 thorpej
827 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
828 1.2 thorpej NULL);
829 1.2 thorpej if (error)
830 1.24 manu goto out;
831 1.2 thorpej
832 1.20 dholland error = namei_simple_user(SCARG(uap, path),
833 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
834 1.2 thorpej if (error)
835 1.26 manu goto out;
836 1.2 thorpej
837 1.24 manu namespace = xattr_native(attrname);
838 1.2 thorpej
839 1.24 manu error = extattr_set_vp(vp, namespace,
840 1.24 manu attrname, SCARG(uap, value), SCARG(uap, size), l,
841 1.24 manu &attrlen, SCARG(uap, flags));
842 1.2 thorpej
843 1.20 dholland vrele(vp);
844 1.24 manu out:
845 1.24 manu *retval = (error == 0) ? 0 : -1;
846 1.2 thorpej return (error);
847 1.2 thorpej }
848 1.2 thorpej
849 1.2 thorpej int
850 1.15 dsl sys_fsetxattr(struct lwp *l, const struct sys_fsetxattr_args *uap, register_t *retval)
851 1.2 thorpej {
852 1.15 dsl /* {
853 1.2 thorpej syscallarg(int) fd;
854 1.2 thorpej syscallarg(const char *) name;
855 1.2 thorpej syscallarg(void *) value;
856 1.2 thorpej syscallarg(size_t) size;
857 1.2 thorpej syscallarg(int) flags;
858 1.15 dsl } */
859 1.2 thorpej struct file *fp;
860 1.2 thorpej struct vnode *vp;
861 1.2 thorpej char attrname[XATTR_NAME_MAX];
862 1.24 manu int namespace;
863 1.24 manu register_t attrlen;
864 1.2 thorpej int error;
865 1.2 thorpej
866 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
867 1.2 thorpej NULL);
868 1.2 thorpej if (error)
869 1.24 manu goto out;
870 1.2 thorpej
871 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
872 1.2 thorpej if (error)
873 1.24 manu goto out;
874 1.2 thorpej vp = (struct vnode *) fp->f_data;
875 1.2 thorpej
876 1.24 manu namespace = xattr_native(attrname);
877 1.2 thorpej
878 1.24 manu error = extattr_set_vp(vp, namespace,
879 1.24 manu attrname, SCARG(uap, value), SCARG(uap, size), l,
880 1.24 manu &attrlen, SCARG(uap, flags));
881 1.2 thorpej
882 1.17 ad fd_putfile(SCARG(uap, fd));
883 1.24 manu out:
884 1.24 manu *retval = (error == 0) ? 0 : -1;
885 1.2 thorpej return (error);
886 1.2 thorpej }
887 1.2 thorpej
888 1.2 thorpej int
889 1.15 dsl sys_getxattr(struct lwp *l, const struct sys_getxattr_args *uap, register_t *retval)
890 1.2 thorpej {
891 1.15 dsl /* {
892 1.2 thorpej syscallarg(const char *) path;
893 1.2 thorpej syscallarg(const char *) name;
894 1.2 thorpej syscallarg(void *) value;
895 1.2 thorpej syscallarg(size_t) size;
896 1.15 dsl } */
897 1.20 dholland struct vnode *vp;
898 1.2 thorpej char attrname[XATTR_NAME_MAX];
899 1.24 manu int namespace;
900 1.2 thorpej int error;
901 1.2 thorpej
902 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
903 1.2 thorpej NULL);
904 1.2 thorpej if (error)
905 1.2 thorpej return (error);
906 1.2 thorpej
907 1.20 dholland error = namei_simple_user(SCARG(uap, path),
908 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
909 1.2 thorpej if (error)
910 1.2 thorpej return (error);
911 1.2 thorpej
912 1.24 manu namespace = xattr_native(attrname);
913 1.24 manu
914 1.24 manu error = extattr_get_vp(vp, namespace,
915 1.4 christos attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
916 1.2 thorpej
917 1.20 dholland vrele(vp);
918 1.2 thorpej return (error);
919 1.2 thorpej }
920 1.2 thorpej
921 1.2 thorpej int
922 1.15 dsl sys_lgetxattr(struct lwp *l, const struct sys_lgetxattr_args *uap, register_t *retval)
923 1.2 thorpej {
924 1.15 dsl /* {
925 1.2 thorpej syscallarg(const char *) path;
926 1.2 thorpej syscallarg(const char *) name;
927 1.2 thorpej syscallarg(void *) value;
928 1.2 thorpej syscallarg(size_t) size;
929 1.15 dsl } */
930 1.20 dholland struct vnode *vp;
931 1.2 thorpej char attrname[XATTR_NAME_MAX];
932 1.24 manu int namespace;
933 1.2 thorpej int error;
934 1.2 thorpej
935 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
936 1.2 thorpej NULL);
937 1.2 thorpej if (error)
938 1.2 thorpej return (error);
939 1.2 thorpej
940 1.20 dholland error = namei_simple_user(SCARG(uap, path),
941 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
942 1.2 thorpej if (error)
943 1.2 thorpej return (error);
944 1.2 thorpej
945 1.24 manu namespace = xattr_native(attrname);
946 1.24 manu
947 1.24 manu error = extattr_get_vp(vp, namespace,
948 1.4 christos attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
949 1.2 thorpej
950 1.20 dholland vrele(vp);
951 1.2 thorpej return (error);
952 1.2 thorpej }
953 1.2 thorpej
954 1.2 thorpej int
955 1.15 dsl sys_fgetxattr(struct lwp *l, const struct sys_fgetxattr_args *uap, register_t *retval)
956 1.2 thorpej {
957 1.15 dsl /* {
958 1.2 thorpej syscallarg(int) fd;
959 1.2 thorpej syscallarg(const char *) name;
960 1.2 thorpej syscallarg(void *) value;
961 1.2 thorpej syscallarg(size_t) size;
962 1.15 dsl } */
963 1.2 thorpej struct file *fp;
964 1.2 thorpej struct vnode *vp;
965 1.2 thorpej char attrname[XATTR_NAME_MAX];
966 1.24 manu int namespace;
967 1.2 thorpej int error;
968 1.2 thorpej
969 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
970 1.2 thorpej NULL);
971 1.2 thorpej if (error)
972 1.2 thorpej return (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.24 manu namespace = xattr_native(attrname);
980 1.24 manu
981 1.24 manu error = extattr_get_vp(vp, namespace,
982 1.4 christos attrname, SCARG(uap, value), 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_listxattr(struct lwp *l, const struct sys_listxattr_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(char *) list;
994 1.2 thorpej syscallarg(size_t) size;
995 1.15 dsl } */
996 1.20 dholland struct vnode *vp;
997 1.24 manu char *list;
998 1.24 manu size_t size;
999 1.24 manu register_t listsize_usr, listsize_sys;
1000 1.2 thorpej int 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.24 manu list = SCARG(uap, list);
1008 1.24 manu size = SCARG(uap, size);
1009 1.24 manu
1010 1.20 dholland error = extattr_list_vp(vp, EXTATTR_NAMESPACE_USER,
1011 1.24 manu list, size, l, &listsize_usr);
1012 1.24 manu if (error)
1013 1.24 manu goto out;
1014 1.24 manu
1015 1.24 manu if (list)
1016 1.24 manu list += listsize_usr;
1017 1.24 manu if (size)
1018 1.24 manu size -= listsize_usr;
1019 1.2 thorpej
1020 1.24 manu error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
1021 1.24 manu list, size, l, &listsize_sys);
1022 1.25 manu switch (error) {
1023 1.25 manu case EPERM:
1024 1.25 manu error = 0; /* Ignore and just skip system EA */
1025 1.25 manu listsize_sys = 0;
1026 1.25 manu break;
1027 1.25 manu case 0:
1028 1.25 manu break;
1029 1.25 manu default:
1030 1.24 manu goto out;
1031 1.25 manu break;
1032 1.25 manu }
1033 1.24 manu
1034 1.24 manu *retval = listsize_usr + listsize_sys;
1035 1.24 manu
1036 1.24 manu out:
1037 1.20 dholland vrele(vp);
1038 1.2 thorpej return (error);
1039 1.2 thorpej }
1040 1.2 thorpej
1041 1.2 thorpej int
1042 1.15 dsl sys_llistxattr(struct lwp *l, const struct sys_llistxattr_args *uap, register_t *retval)
1043 1.2 thorpej {
1044 1.15 dsl /* {
1045 1.2 thorpej syscallarg(const char *) path;
1046 1.2 thorpej syscallarg(char *) list;
1047 1.2 thorpej syscallarg(size_t) size;
1048 1.15 dsl } */
1049 1.20 dholland struct vnode *vp;
1050 1.24 manu char *list;
1051 1.24 manu size_t size;
1052 1.24 manu register_t listsize_usr, listsize_sys;
1053 1.2 thorpej int error;
1054 1.2 thorpej
1055 1.20 dholland error = namei_simple_user(SCARG(uap, path),
1056 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
1057 1.2 thorpej if (error)
1058 1.2 thorpej return (error);
1059 1.2 thorpej
1060 1.24 manu list = SCARG(uap, list);
1061 1.24 manu size = SCARG(uap, size);
1062 1.24 manu
1063 1.20 dholland error = extattr_list_vp(vp, EXTATTR_NAMESPACE_USER,
1064 1.24 manu list, size, l, &listsize_usr);
1065 1.24 manu if (error)
1066 1.24 manu goto out;
1067 1.24 manu
1068 1.24 manu if (list)
1069 1.24 manu list += listsize_usr;
1070 1.24 manu if (size)
1071 1.24 manu size -= listsize_usr;
1072 1.2 thorpej
1073 1.24 manu error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
1074 1.24 manu list, size, l, &listsize_sys);
1075 1.25 manu switch (error) {
1076 1.25 manu case EPERM:
1077 1.25 manu error = 0; /* Ignore and just skip system EA */
1078 1.25 manu listsize_sys = 0;
1079 1.25 manu break;
1080 1.25 manu case 0:
1081 1.25 manu break;
1082 1.25 manu default:
1083 1.24 manu goto out;
1084 1.25 manu break;
1085 1.25 manu }
1086 1.24 manu
1087 1.24 manu *retval = listsize_usr + listsize_sys;
1088 1.24 manu out:
1089 1.20 dholland vrele(vp);
1090 1.2 thorpej return (error);
1091 1.2 thorpej }
1092 1.2 thorpej
1093 1.2 thorpej int
1094 1.15 dsl sys_flistxattr(struct lwp *l, const struct sys_flistxattr_args *uap, register_t *retval)
1095 1.2 thorpej {
1096 1.15 dsl /* {
1097 1.2 thorpej syscallarg(int) fd;
1098 1.2 thorpej syscallarg(char *) list;
1099 1.2 thorpej syscallarg(size_t) size;
1100 1.15 dsl } */
1101 1.2 thorpej struct file *fp;
1102 1.2 thorpej struct vnode *vp;
1103 1.24 manu char *list;
1104 1.24 manu size_t size;
1105 1.24 manu register_t listsize_usr, listsize_sys;
1106 1.2 thorpej int error;
1107 1.2 thorpej
1108 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
1109 1.2 thorpej if (error)
1110 1.2 thorpej return (error);
1111 1.2 thorpej vp = (struct vnode *) fp->f_data;
1112 1.2 thorpej
1113 1.24 manu list = SCARG(uap, list);
1114 1.24 manu size = SCARG(uap, size);
1115 1.24 manu
1116 1.2 thorpej error = extattr_list_vp(vp, EXTATTR_NAMESPACE_USER,
1117 1.24 manu list, size, l, &listsize_usr);
1118 1.24 manu if (error)
1119 1.24 manu goto out;
1120 1.24 manu
1121 1.24 manu if (list)
1122 1.24 manu list += listsize_usr;
1123 1.24 manu if (size)
1124 1.24 manu size -= listsize_usr;
1125 1.24 manu
1126 1.24 manu error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
1127 1.24 manu list, size, l, &listsize_sys);
1128 1.25 manu switch (error) {
1129 1.25 manu case EPERM:
1130 1.25 manu error = 0; /* Ignore and just skip system EA */
1131 1.25 manu listsize_sys = 0;
1132 1.25 manu break;
1133 1.25 manu case 0:
1134 1.25 manu break;
1135 1.25 manu default:
1136 1.24 manu goto out;
1137 1.25 manu break;
1138 1.25 manu }
1139 1.24 manu
1140 1.24 manu *retval = listsize_usr + listsize_sys;
1141 1.24 manu out:
1142 1.2 thorpej
1143 1.17 ad fd_putfile(SCARG(uap, fd));
1144 1.2 thorpej return (error);
1145 1.2 thorpej }
1146 1.2 thorpej
1147 1.2 thorpej int
1148 1.15 dsl sys_removexattr(struct lwp *l, const struct sys_removexattr_args *uap, register_t *retval)
1149 1.2 thorpej {
1150 1.15 dsl /* {
1151 1.2 thorpej syscallarg(const char *) path;
1152 1.2 thorpej syscallarg(const char *) name;
1153 1.15 dsl } */
1154 1.20 dholland struct vnode *vp;
1155 1.2 thorpej char attrname[XATTR_NAME_MAX];
1156 1.24 manu int namespace;
1157 1.2 thorpej int error;
1158 1.2 thorpej
1159 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
1160 1.2 thorpej NULL);
1161 1.2 thorpej if (error)
1162 1.2 thorpej return (error);
1163 1.2 thorpej
1164 1.20 dholland error = namei_simple_user(SCARG(uap, path),
1165 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
1166 1.2 thorpej if (error)
1167 1.2 thorpej return (error);
1168 1.2 thorpej
1169 1.24 manu namespace = xattr_native(attrname);
1170 1.24 manu
1171 1.24 manu error = extattr_delete_vp(vp, namespace, attrname, l);
1172 1.2 thorpej
1173 1.20 dholland vrele(vp);
1174 1.2 thorpej return (error);
1175 1.2 thorpej }
1176 1.2 thorpej
1177 1.2 thorpej int
1178 1.15 dsl sys_lremovexattr(struct lwp *l, const struct sys_lremovexattr_args *uap, register_t *retval)
1179 1.2 thorpej {
1180 1.15 dsl /* {
1181 1.2 thorpej syscallarg(const char *) path;
1182 1.2 thorpej syscallarg(const char *) name;
1183 1.15 dsl } */
1184 1.20 dholland struct vnode *vp;
1185 1.2 thorpej char attrname[XATTR_NAME_MAX];
1186 1.24 manu int namespace;
1187 1.2 thorpej int error;
1188 1.2 thorpej
1189 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
1190 1.2 thorpej NULL);
1191 1.2 thorpej if (error)
1192 1.2 thorpej return (error);
1193 1.2 thorpej
1194 1.20 dholland error = namei_simple_user(SCARG(uap, path),
1195 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
1196 1.2 thorpej if (error)
1197 1.2 thorpej return (error);
1198 1.2 thorpej
1199 1.24 manu namespace = xattr_native(attrname);
1200 1.24 manu
1201 1.24 manu error = extattr_delete_vp(vp, namespace, attrname, l);
1202 1.2 thorpej
1203 1.20 dholland vrele(vp);
1204 1.2 thorpej return (error);
1205 1.2 thorpej }
1206 1.2 thorpej
1207 1.2 thorpej int
1208 1.15 dsl sys_fremovexattr(struct lwp *l, const struct sys_fremovexattr_args *uap, register_t *retval)
1209 1.2 thorpej {
1210 1.15 dsl /* {
1211 1.2 thorpej syscallarg(int) fd;
1212 1.2 thorpej syscallarg(const char *) name;
1213 1.15 dsl } */
1214 1.2 thorpej struct file *fp;
1215 1.2 thorpej struct vnode *vp;
1216 1.2 thorpej char attrname[XATTR_NAME_MAX];
1217 1.24 manu int namespace;
1218 1.2 thorpej int error;
1219 1.2 thorpej
1220 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
1221 1.2 thorpej NULL);
1222 1.2 thorpej if (error)
1223 1.2 thorpej return (error);
1224 1.2 thorpej
1225 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
1226 1.2 thorpej if (error)
1227 1.2 thorpej return (error);
1228 1.2 thorpej vp = (struct vnode *) fp->f_data;
1229 1.2 thorpej
1230 1.24 manu namespace = xattr_native(attrname);
1231 1.24 manu
1232 1.24 manu error = extattr_delete_vp(vp, namespace, attrname, l);
1233 1.2 thorpej
1234 1.17 ad fd_putfile(SCARG(uap, fd));
1235 1.2 thorpej return (error);
1236 1.2 thorpej }
1237