vfs_xattr.c revision 1.37 1 1.37 riastrad /* $NetBSD: vfs_xattr.c,v 1.37 2022/10/25 23:22:17 riastradh 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.37 riastrad __KERNEL_RCSID(0, "$NetBSD: vfs_xattr.c,v 1.37 2022/10/25 23:22:17 riastradh 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.28 manu #include <sys/ktrace.h>
89 1.1 thorpej
90 1.30 elad #include <miscfs/genfs/genfs.h>
91 1.30 elad
92 1.36 christos static void
93 1.36 christos ktr_xattr_name(const char *str)
94 1.36 christos {
95 1.36 christos ktrkuser("xattr-name", (void *)__UNCONST(str), strlen(str));
96 1.36 christos }
97 1.36 christos
98 1.36 christos static void
99 1.36 christos ktr_xattr_val(const void *data, size_t cnt)
100 1.36 christos {
101 1.36 christos ktruser("xattr-val", __UNCONST(data), cnt, 0);
102 1.36 christos }
103 1.36 christos
104 1.1 thorpej /*
105 1.3 thorpej * Credential check based on process requesting service, and per-attribute
106 1.3 thorpej * permissions.
107 1.3 thorpej *
108 1.3 thorpej * NOTE: Vnode must be locked.
109 1.3 thorpej */
110 1.3 thorpej int
111 1.35 christos extattr_check_cred(struct vnode *vp, int attrspace, kauth_cred_t cred,
112 1.30 elad int access)
113 1.3 thorpej {
114 1.3 thorpej
115 1.3 thorpej if (cred == NOCRED)
116 1.3 thorpej return (0);
117 1.3 thorpej
118 1.30 elad return kauth_authorize_vnode(cred, kauth_extattr_action(access), vp,
119 1.35 christos NULL, genfs_can_extattr(vp, cred, access, attrspace));
120 1.3 thorpej }
121 1.3 thorpej
122 1.3 thorpej /*
123 1.3 thorpej * Default vfs_extattrctl routine for file systems that do not support
124 1.3 thorpej * it.
125 1.3 thorpej */
126 1.3 thorpej /*ARGSUSED*/
127 1.3 thorpej int
128 1.9 yamt vfs_stdextattrctl(struct mount *mp, int cmt, struct vnode *vp,
129 1.13 pooka int attrnamespace, const char *attrname)
130 1.3 thorpej {
131 1.3 thorpej
132 1.3 thorpej if (vp != NULL)
133 1.22 hannken VOP_UNLOCK(vp);
134 1.3 thorpej return (EOPNOTSUPP);
135 1.3 thorpej }
136 1.3 thorpej
137 1.3 thorpej /*
138 1.2 thorpej * Push extended attribute configuration information into the file
139 1.2 thorpej * system.
140 1.1 thorpej *
141 1.1 thorpej * NOTE: Not all file systems that support extended attributes will
142 1.1 thorpej * require the use of this system call.
143 1.1 thorpej */
144 1.1 thorpej int
145 1.15 dsl sys_extattrctl(struct lwp *l, const struct sys_extattrctl_args *uap, register_t *retval)
146 1.1 thorpej {
147 1.15 dsl /* {
148 1.1 thorpej syscallarg(const char *) path;
149 1.1 thorpej syscallarg(int) cmd;
150 1.1 thorpej syscallarg(const char *) filename;
151 1.1 thorpej syscallarg(int) attrnamespace;
152 1.1 thorpej syscallarg(const char *) attrname;
153 1.15 dsl } */
154 1.20 dholland struct vnode *path_vp, *file_vp;
155 1.23 dholland struct pathbuf *file_pb;
156 1.20 dholland struct nameidata file_nd;
157 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
158 1.1 thorpej int error;
159 1.1 thorpej
160 1.1 thorpej if (SCARG(uap, attrname) != NULL) {
161 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname,
162 1.1 thorpej sizeof(attrname), NULL);
163 1.1 thorpej if (error)
164 1.1 thorpej return (error);
165 1.1 thorpej }
166 1.1 thorpej
167 1.21 pooka error = namei_simple_user(SCARG(uap, path),
168 1.21 pooka NSM_FOLLOW_NOEMULROOT, &path_vp);
169 1.21 pooka if (error) {
170 1.21 pooka return (error);
171 1.21 pooka }
172 1.21 pooka
173 1.20 dholland file_vp = NULL;
174 1.1 thorpej if (SCARG(uap, filename) != NULL) {
175 1.23 dholland error = pathbuf_copyin(SCARG(uap, filename), &file_pb);
176 1.23 dholland if (error) {
177 1.23 dholland vrele(path_vp);
178 1.23 dholland return (error);
179 1.23 dholland }
180 1.23 dholland NDINIT(&file_nd, LOOKUP, FOLLOW | LOCKLEAF, file_pb);
181 1.20 dholland error = namei(&file_nd);
182 1.21 pooka if (error) {
183 1.23 dholland pathbuf_destroy(file_pb);
184 1.21 pooka vrele(path_vp);
185 1.1 thorpej return (error);
186 1.21 pooka }
187 1.20 dholland file_vp = file_nd.ni_vp;
188 1.23 dholland pathbuf_destroy(file_pb);
189 1.1 thorpej }
190 1.1 thorpej
191 1.20 dholland error = VFS_EXTATTRCTL(path_vp->v_mount, SCARG(uap, cmd), file_vp,
192 1.1 thorpej SCARG(uap, attrnamespace),
193 1.13 pooka SCARG(uap, attrname) != NULL ? attrname : NULL);
194 1.1 thorpej
195 1.20 dholland if (file_vp != NULL)
196 1.20 dholland vrele(file_vp);
197 1.20 dholland vrele(path_vp);
198 1.1 thorpej
199 1.1 thorpej return (error);
200 1.1 thorpej }
201 1.1 thorpej
202 1.1 thorpej /*****************************************************************************
203 1.1 thorpej * Internal routines to manipulate file system extended attributes:
204 1.1 thorpej * - set
205 1.1 thorpej * - get
206 1.1 thorpej * - delete
207 1.1 thorpej * - list
208 1.1 thorpej *****************************************************************************/
209 1.1 thorpej
210 1.1 thorpej /*
211 1.1 thorpej * extattr_set_vp:
212 1.1 thorpej *
213 1.1 thorpej * Set a named extended attribute on a file or directory.
214 1.1 thorpej */
215 1.1 thorpej static int
216 1.1 thorpej extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname,
217 1.24 manu const void *data, size_t nbytes, struct lwp *l, register_t *retval,
218 1.24 manu int flag)
219 1.1 thorpej {
220 1.1 thorpej struct uio auio;
221 1.1 thorpej struct iovec aiov;
222 1.1 thorpej ssize_t cnt;
223 1.1 thorpej int error;
224 1.1 thorpej
225 1.1 thorpej vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
226 1.1 thorpej
227 1.24 manu if (flag) {
228 1.24 manu size_t attrlen;
229 1.24 manu
230 1.24 manu error = VOP_GETEXTATTR(vp, attrnamespace, attrname, NULL,
231 1.24 manu &attrlen, l->l_cred);
232 1.24 manu
233 1.24 manu switch (error) {
234 1.31 manu case ENODATA:
235 1.24 manu if (flag & XATTR_REPLACE)
236 1.24 manu goto done;
237 1.24 manu break;
238 1.24 manu case 0:
239 1.24 manu if (flag & XATTR_CREATE) {
240 1.24 manu error = EEXIST;
241 1.24 manu goto done;
242 1.24 manu }
243 1.24 manu break;
244 1.24 manu default:
245 1.24 manu goto done;
246 1.24 manu break;
247 1.24 manu }
248 1.24 manu }
249 1.24 manu
250 1.1 thorpej aiov.iov_base = __UNCONST(data); /* XXXUNCONST kills const */
251 1.1 thorpej aiov.iov_len = nbytes;
252 1.1 thorpej auio.uio_iov = &aiov;
253 1.1 thorpej auio.uio_iovcnt = 1;
254 1.1 thorpej auio.uio_offset = 0;
255 1.1 thorpej if (nbytes > INT_MAX) {
256 1.1 thorpej error = EINVAL;
257 1.1 thorpej goto done;
258 1.1 thorpej }
259 1.1 thorpej auio.uio_resid = nbytes;
260 1.1 thorpej auio.uio_rw = UIO_WRITE;
261 1.5 yamt KASSERT(l == curlwp);
262 1.5 yamt auio.uio_vmspace = l->l_proc->p_vmspace;
263 1.1 thorpej cnt = nbytes;
264 1.1 thorpej
265 1.36 christos ktr_xattr_name(attrname);
266 1.36 christos ktr_xattr_val(data, nbytes);
267 1.28 manu
268 1.13 pooka error = VOP_SETEXTATTR(vp, attrnamespace, attrname, &auio, l->l_cred);
269 1.1 thorpej cnt -= auio.uio_resid;
270 1.1 thorpej retval[0] = cnt;
271 1.1 thorpej
272 1.1 thorpej done:
273 1.22 hannken VOP_UNLOCK(vp);
274 1.1 thorpej return (error);
275 1.1 thorpej }
276 1.1 thorpej
277 1.1 thorpej /*
278 1.1 thorpej * extattr_get_vp:
279 1.1 thorpej *
280 1.1 thorpej * Get a named extended attribute on a file or directory.
281 1.1 thorpej */
282 1.1 thorpej static int
283 1.1 thorpej extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname,
284 1.4 christos void *data, size_t nbytes, struct lwp *l, register_t *retval)
285 1.1 thorpej {
286 1.1 thorpej struct uio auio, *auiop;
287 1.1 thorpej struct iovec aiov;
288 1.1 thorpej ssize_t cnt;
289 1.1 thorpej size_t size, *sizep;
290 1.1 thorpej int error;
291 1.1 thorpej
292 1.1 thorpej vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
293 1.1 thorpej
294 1.1 thorpej /*
295 1.1 thorpej * Slightly unusual semantics: if the user provides a NULL data
296 1.1 thorpej * pointer, they don't want to receive the data, just the maximum
297 1.1 thorpej * read length.
298 1.1 thorpej */
299 1.1 thorpej auiop = NULL;
300 1.1 thorpej sizep = NULL;
301 1.1 thorpej cnt = 0;
302 1.1 thorpej if (data != NULL) {
303 1.1 thorpej aiov.iov_base = data;
304 1.1 thorpej aiov.iov_len = nbytes;
305 1.1 thorpej auio.uio_iov = &aiov;
306 1.37 riastrad auio.uio_iovcnt = 1;
307 1.1 thorpej auio.uio_offset = 0;
308 1.1 thorpej if (nbytes > INT_MAX) {
309 1.1 thorpej error = EINVAL;
310 1.1 thorpej goto done;
311 1.1 thorpej }
312 1.1 thorpej auio.uio_resid = nbytes;
313 1.1 thorpej auio.uio_rw = UIO_READ;
314 1.5 yamt KASSERT(l == curlwp);
315 1.5 yamt auio.uio_vmspace = l->l_proc->p_vmspace;
316 1.1 thorpej auiop = &auio;
317 1.1 thorpej cnt = nbytes;
318 1.1 thorpej } else
319 1.1 thorpej sizep = &size;
320 1.1 thorpej
321 1.36 christos ktr_xattr_name(attrname);
322 1.28 manu
323 1.1 thorpej error = VOP_GETEXTATTR(vp, attrnamespace, attrname, auiop, sizep,
324 1.13 pooka l->l_cred);
325 1.1 thorpej
326 1.1 thorpej if (auiop != NULL) {
327 1.1 thorpej cnt -= auio.uio_resid;
328 1.1 thorpej retval[0] = cnt;
329 1.28 manu
330 1.36 christos ktr_xattr_val(data, cnt);
331 1.1 thorpej } else
332 1.1 thorpej retval[0] = size;
333 1.1 thorpej
334 1.1 thorpej done:
335 1.22 hannken VOP_UNLOCK(vp);
336 1.1 thorpej return (error);
337 1.1 thorpej }
338 1.1 thorpej
339 1.1 thorpej /*
340 1.1 thorpej * extattr_delete_vp:
341 1.1 thorpej *
342 1.1 thorpej * Delete a named extended attribute on a file or directory.
343 1.1 thorpej */
344 1.1 thorpej static int
345 1.1 thorpej extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname,
346 1.4 christos struct lwp *l)
347 1.1 thorpej {
348 1.1 thorpej int error;
349 1.1 thorpej
350 1.1 thorpej vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
351 1.1 thorpej
352 1.36 christos ktr_xattr_name(attrname);
353 1.28 manu
354 1.13 pooka error = VOP_DELETEEXTATTR(vp, attrnamespace, attrname, l->l_cred);
355 1.1 thorpej if (error == EOPNOTSUPP)
356 1.1 thorpej error = VOP_SETEXTATTR(vp, attrnamespace, attrname, NULL,
357 1.13 pooka l->l_cred);
358 1.1 thorpej
359 1.22 hannken VOP_UNLOCK(vp);
360 1.1 thorpej return (error);
361 1.1 thorpej }
362 1.1 thorpej
363 1.1 thorpej /*
364 1.1 thorpej * extattr_list_vp:
365 1.1 thorpej *
366 1.1 thorpej * Retrieve a list of extended attributes on a file or directory.
367 1.1 thorpej */
368 1.1 thorpej static int
369 1.1 thorpej extattr_list_vp(struct vnode *vp, int attrnamespace, void *data, size_t nbytes,
370 1.27 manu int flag, struct lwp *l, register_t *retval)
371 1.1 thorpej {
372 1.1 thorpej struct uio auio, *auiop;
373 1.1 thorpej size_t size, *sizep;
374 1.1 thorpej struct iovec aiov;
375 1.1 thorpej ssize_t cnt;
376 1.1 thorpej int error;
377 1.1 thorpej
378 1.1 thorpej vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
379 1.1 thorpej
380 1.1 thorpej auiop = NULL;
381 1.1 thorpej sizep = NULL;
382 1.1 thorpej cnt = 0;
383 1.1 thorpej if (data != NULL) {
384 1.1 thorpej aiov.iov_base = data;
385 1.1 thorpej aiov.iov_len = nbytes;
386 1.1 thorpej auio.uio_iov = &aiov;
387 1.37 riastrad auio.uio_iovcnt = 1;
388 1.1 thorpej auio.uio_offset = 0;
389 1.1 thorpej if (nbytes > INT_MAX) {
390 1.1 thorpej error = EINVAL;
391 1.1 thorpej goto done;
392 1.1 thorpej }
393 1.1 thorpej auio.uio_resid = nbytes;
394 1.1 thorpej auio.uio_rw = UIO_READ;
395 1.5 yamt KASSERT(l == curlwp);
396 1.5 yamt auio.uio_vmspace = l->l_proc->p_vmspace;
397 1.1 thorpej auiop = &auio;
398 1.1 thorpej cnt = nbytes;
399 1.1 thorpej } else
400 1.1 thorpej sizep = &size;
401 1.1 thorpej
402 1.27 manu error = VOP_LISTEXTATTR(vp, attrnamespace, auiop, sizep,
403 1.27 manu flag, l->l_cred);
404 1.1 thorpej
405 1.1 thorpej if (auiop != NULL) {
406 1.1 thorpej cnt -= auio.uio_resid;
407 1.1 thorpej retval[0] = cnt;
408 1.28 manu
409 1.34 christos ktruser("xattr-list", data, cnt, 0);
410 1.1 thorpej } else
411 1.1 thorpej retval[0] = size;
412 1.1 thorpej
413 1.1 thorpej done:
414 1.22 hannken VOP_UNLOCK(vp);
415 1.1 thorpej return (error);
416 1.1 thorpej }
417 1.1 thorpej
418 1.1 thorpej /*****************************************************************************
419 1.1 thorpej * BSD <sys/extattr.h> API for file system extended attributes
420 1.1 thorpej *****************************************************************************/
421 1.1 thorpej
422 1.1 thorpej int
423 1.15 dsl sys_extattr_set_fd(struct lwp *l, const struct sys_extattr_set_fd_args *uap, register_t *retval)
424 1.1 thorpej {
425 1.15 dsl /* {
426 1.1 thorpej syscallarg(int) fd;
427 1.1 thorpej syscallarg(int) attrnamespace;
428 1.1 thorpej syscallarg(const char *) attrname;
429 1.1 thorpej syscallarg(const void *) data;
430 1.1 thorpej syscallarg(size_t) nbytes;
431 1.15 dsl } */
432 1.1 thorpej struct file *fp;
433 1.1 thorpej struct vnode *vp;
434 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
435 1.1 thorpej int error;
436 1.1 thorpej
437 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
438 1.1 thorpej NULL);
439 1.1 thorpej if (error)
440 1.1 thorpej return (error);
441 1.1 thorpej
442 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
443 1.1 thorpej if (error)
444 1.1 thorpej return (error);
445 1.33 matt vp = fp->f_vnode;
446 1.1 thorpej
447 1.1 thorpej error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
448 1.24 manu SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
449 1.1 thorpej
450 1.17 ad fd_putfile(SCARG(uap, fd));
451 1.1 thorpej return (error);
452 1.1 thorpej }
453 1.1 thorpej
454 1.1 thorpej int
455 1.15 dsl sys_extattr_set_file(struct lwp *l, const struct sys_extattr_set_file_args *uap, register_t *retval)
456 1.1 thorpej {
457 1.15 dsl /* {
458 1.1 thorpej syscallarg(const char *) path;
459 1.1 thorpej syscallarg(int) attrnamespace;
460 1.1 thorpej syscallarg(const char *) attrname;
461 1.1 thorpej syscallarg(const void *) data;
462 1.1 thorpej syscallarg(size_t) nbytes;
463 1.15 dsl } */
464 1.20 dholland struct vnode *vp;
465 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
466 1.1 thorpej int error;
467 1.1 thorpej
468 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
469 1.1 thorpej NULL);
470 1.1 thorpej if (error)
471 1.1 thorpej return (error);
472 1.1 thorpej
473 1.20 dholland error = namei_simple_user(SCARG(uap, path),
474 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
475 1.1 thorpej if (error)
476 1.1 thorpej return (error);
477 1.1 thorpej
478 1.20 dholland error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
479 1.24 manu SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
480 1.1 thorpej
481 1.20 dholland vrele(vp);
482 1.1 thorpej return (error);
483 1.1 thorpej }
484 1.1 thorpej
485 1.1 thorpej int
486 1.15 dsl sys_extattr_set_link(struct lwp *l, const struct sys_extattr_set_link_args *uap, register_t *retval)
487 1.1 thorpej {
488 1.15 dsl /* {
489 1.1 thorpej syscallarg(const char *) path;
490 1.1 thorpej syscallarg(int) attrnamespace;
491 1.1 thorpej syscallarg(const char *) attrname;
492 1.1 thorpej syscallarg(const void *) data;
493 1.1 thorpej syscallarg(size_t) nbytes;
494 1.15 dsl } */
495 1.20 dholland struct vnode *vp;
496 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
497 1.1 thorpej int error;
498 1.1 thorpej
499 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
500 1.1 thorpej NULL);
501 1.1 thorpej if (error)
502 1.1 thorpej return (error);
503 1.1 thorpej
504 1.20 dholland error = namei_simple_user(SCARG(uap, path),
505 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
506 1.1 thorpej if (error)
507 1.1 thorpej return (error);
508 1.1 thorpej
509 1.20 dholland error = extattr_set_vp(vp, SCARG(uap, attrnamespace), attrname,
510 1.24 manu SCARG(uap, data), SCARG(uap, nbytes), l, retval, 0);
511 1.1 thorpej
512 1.20 dholland vrele(vp);
513 1.1 thorpej return (error);
514 1.1 thorpej }
515 1.1 thorpej
516 1.1 thorpej int
517 1.15 dsl sys_extattr_get_fd(struct lwp *l, const struct sys_extattr_get_fd_args *uap, register_t *retval)
518 1.1 thorpej {
519 1.15 dsl /* {
520 1.1 thorpej syscallarg(int) fd;
521 1.1 thorpej syscallarg(int) attrnamespace;
522 1.1 thorpej syscallarg(const char *) attrname;
523 1.1 thorpej syscallarg(void *) data;
524 1.1 thorpej syscallarg(size_t) nbytes;
525 1.15 dsl } */
526 1.1 thorpej struct file *fp;
527 1.1 thorpej struct vnode *vp;
528 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
529 1.1 thorpej int error;
530 1.1 thorpej
531 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
532 1.1 thorpej NULL);
533 1.1 thorpej if (error)
534 1.1 thorpej return (error);
535 1.1 thorpej
536 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
537 1.1 thorpej if (error)
538 1.1 thorpej return (error);
539 1.33 matt vp = fp->f_vnode;
540 1.1 thorpej
541 1.1 thorpej error = extattr_get_vp(vp, SCARG(uap, attrnamespace), attrname,
542 1.4 christos SCARG(uap, data), SCARG(uap, nbytes), l, retval);
543 1.1 thorpej
544 1.17 ad fd_putfile(SCARG(uap, fd));
545 1.1 thorpej return (error);
546 1.1 thorpej }
547 1.1 thorpej
548 1.1 thorpej int
549 1.15 dsl sys_extattr_get_file(struct lwp *l, const struct sys_extattr_get_file_args *uap, register_t *retval)
550 1.1 thorpej {
551 1.15 dsl /* {
552 1.1 thorpej syscallarg(const char *) path;
553 1.1 thorpej syscallarg(int) attrnamespace;
554 1.1 thorpej syscallarg(const char *) attrname;
555 1.1 thorpej syscallarg(void *) data;
556 1.1 thorpej syscallarg(size_t) nbytes;
557 1.15 dsl } */
558 1.20 dholland struct vnode *vp;
559 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
560 1.1 thorpej int error;
561 1.1 thorpej
562 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
563 1.1 thorpej NULL);
564 1.1 thorpej if (error)
565 1.1 thorpej return (error);
566 1.1 thorpej
567 1.20 dholland error = namei_simple_user(SCARG(uap, path),
568 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
569 1.1 thorpej if (error)
570 1.1 thorpej return (error);
571 1.1 thorpej
572 1.20 dholland error = extattr_get_vp(vp, SCARG(uap, attrnamespace), attrname,
573 1.4 christos SCARG(uap, data), SCARG(uap, nbytes), l, retval);
574 1.1 thorpej
575 1.20 dholland vrele(vp);
576 1.1 thorpej return (error);
577 1.1 thorpej }
578 1.1 thorpej
579 1.1 thorpej int
580 1.15 dsl sys_extattr_get_link(struct lwp *l, const struct sys_extattr_get_link_args *uap, register_t *retval)
581 1.1 thorpej {
582 1.15 dsl /* {
583 1.1 thorpej syscallarg(const char *) path;
584 1.1 thorpej syscallarg(int) attrnamespace;
585 1.1 thorpej syscallarg(const char *) attrname;
586 1.1 thorpej syscallarg(void *) data;
587 1.1 thorpej syscallarg(size_t) nbytes;
588 1.15 dsl } */
589 1.20 dholland struct vnode *vp;
590 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
591 1.1 thorpej int error;
592 1.1 thorpej
593 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
594 1.1 thorpej NULL);
595 1.1 thorpej if (error)
596 1.1 thorpej return (error);
597 1.1 thorpej
598 1.20 dholland error = namei_simple_user(SCARG(uap, path),
599 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
600 1.1 thorpej if (error)
601 1.1 thorpej return (error);
602 1.1 thorpej
603 1.20 dholland error = extattr_get_vp(vp, SCARG(uap, attrnamespace), attrname,
604 1.4 christos SCARG(uap, data), SCARG(uap, nbytes), l, retval);
605 1.1 thorpej
606 1.20 dholland vrele(vp);
607 1.1 thorpej return (error);
608 1.1 thorpej }
609 1.1 thorpej
610 1.1 thorpej int
611 1.15 dsl sys_extattr_delete_fd(struct lwp *l, const struct sys_extattr_delete_fd_args *uap, register_t *retval)
612 1.1 thorpej {
613 1.15 dsl /* {
614 1.1 thorpej syscallarg(int) fd;
615 1.1 thorpej syscallarg(int) attrnamespace;
616 1.1 thorpej syscallarg(const char *) attrname;
617 1.15 dsl } */
618 1.1 thorpej struct file *fp;
619 1.1 thorpej struct vnode *vp;
620 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
621 1.1 thorpej int error;
622 1.1 thorpej
623 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
624 1.1 thorpej NULL);
625 1.1 thorpej if (error)
626 1.1 thorpej return (error);
627 1.1 thorpej
628 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
629 1.1 thorpej if (error)
630 1.1 thorpej return (error);
631 1.33 matt vp = fp->f_vnode;
632 1.1 thorpej
633 1.4 christos error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, l);
634 1.1 thorpej
635 1.17 ad fd_putfile(SCARG(uap, fd));
636 1.1 thorpej return (error);
637 1.1 thorpej }
638 1.1 thorpej
639 1.1 thorpej int
640 1.15 dsl sys_extattr_delete_file(struct lwp *l, const struct sys_extattr_delete_file_args *uap, register_t *retval)
641 1.1 thorpej {
642 1.15 dsl /* {
643 1.1 thorpej syscallarg(const char *) path;
644 1.1 thorpej syscallarg(int) attrnamespace;
645 1.1 thorpej syscallarg(const char *) attrname;
646 1.15 dsl } */
647 1.20 dholland struct vnode *vp;
648 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
649 1.1 thorpej int error;
650 1.1 thorpej
651 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
652 1.1 thorpej NULL);
653 1.1 thorpej if (error)
654 1.1 thorpej return (error);
655 1.1 thorpej
656 1.20 dholland error = namei_simple_user(SCARG(uap, path),
657 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
658 1.1 thorpej if (error)
659 1.1 thorpej return (error);
660 1.1 thorpej
661 1.20 dholland error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, l);
662 1.1 thorpej
663 1.20 dholland vrele(vp);
664 1.1 thorpej return (error);
665 1.1 thorpej }
666 1.1 thorpej
667 1.1 thorpej int
668 1.15 dsl sys_extattr_delete_link(struct lwp *l, const struct sys_extattr_delete_link_args *uap, register_t *retval)
669 1.1 thorpej {
670 1.15 dsl /* {
671 1.1 thorpej syscallarg(const char *) path;
672 1.1 thorpej syscallarg(int) attrnamespace;
673 1.1 thorpej syscallarg(const char *) attrname;
674 1.15 dsl } */
675 1.20 dholland struct vnode *vp;
676 1.1 thorpej char attrname[EXTATTR_MAXNAMELEN];
677 1.1 thorpej int error;
678 1.1 thorpej
679 1.1 thorpej error = copyinstr(SCARG(uap, attrname), attrname, sizeof(attrname),
680 1.1 thorpej NULL);
681 1.1 thorpej if (error)
682 1.1 thorpej return (error);
683 1.1 thorpej
684 1.20 dholland error = namei_simple_user(SCARG(uap, path),
685 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
686 1.1 thorpej if (error)
687 1.1 thorpej return (error);
688 1.1 thorpej
689 1.20 dholland error = extattr_delete_vp(vp, SCARG(uap, attrnamespace), attrname, l);
690 1.1 thorpej
691 1.20 dholland vrele(vp);
692 1.1 thorpej return (error);
693 1.1 thorpej }
694 1.1 thorpej
695 1.1 thorpej int
696 1.15 dsl sys_extattr_list_fd(struct lwp *l, const struct sys_extattr_list_fd_args *uap, register_t *retval)
697 1.1 thorpej {
698 1.15 dsl /* {
699 1.1 thorpej syscallarg(int) fd;
700 1.1 thorpej syscallarg(int) attrnamespace;
701 1.1 thorpej syscallarg(void *) data;
702 1.1 thorpej syscallarg(size_t) nbytes;
703 1.15 dsl } */
704 1.1 thorpej struct file *fp;
705 1.1 thorpej struct vnode *vp;
706 1.1 thorpej int error;
707 1.1 thorpej
708 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
709 1.1 thorpej if (error)
710 1.1 thorpej return (error);
711 1.33 matt vp = fp->f_vnode;
712 1.1 thorpej
713 1.1 thorpej error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
714 1.27 manu SCARG(uap, data), SCARG(uap, nbytes),
715 1.27 manu EXTATTR_LIST_LENPREFIX, l, retval);
716 1.1 thorpej
717 1.17 ad fd_putfile(SCARG(uap, fd));
718 1.1 thorpej return (error);
719 1.1 thorpej }
720 1.1 thorpej
721 1.1 thorpej int
722 1.15 dsl sys_extattr_list_file(struct lwp *l, const struct sys_extattr_list_file_args *uap, register_t *retval)
723 1.1 thorpej {
724 1.15 dsl /* {
725 1.1 thorpej syscallarg(const char *) path;
726 1.1 thorpej syscallarg(int) attrnamespace;
727 1.1 thorpej syscallarg(void *) data;
728 1.1 thorpej syscallarg(size_t) nbytes;
729 1.15 dsl } */
730 1.20 dholland struct vnode *vp;
731 1.1 thorpej int error;
732 1.1 thorpej
733 1.20 dholland error = namei_simple_user(SCARG(uap, path),
734 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
735 1.1 thorpej if (error)
736 1.1 thorpej return (error);
737 1.1 thorpej
738 1.20 dholland error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
739 1.27 manu SCARG(uap, data), SCARG(uap, nbytes),
740 1.27 manu EXTATTR_LIST_LENPREFIX, l, retval);
741 1.1 thorpej
742 1.20 dholland vrele(vp);
743 1.1 thorpej return (error);
744 1.1 thorpej }
745 1.1 thorpej
746 1.1 thorpej int
747 1.15 dsl sys_extattr_list_link(struct lwp *l, const struct sys_extattr_list_link_args *uap, register_t *retval)
748 1.1 thorpej {
749 1.15 dsl /* {
750 1.1 thorpej syscallarg(const char *) path;
751 1.1 thorpej syscallarg(int) attrnamespace;
752 1.1 thorpej syscallarg(void *) data;
753 1.1 thorpej syscallarg(size_t) nbytes;
754 1.15 dsl } */
755 1.20 dholland struct vnode *vp;
756 1.1 thorpej int error;
757 1.1 thorpej
758 1.20 dholland error = namei_simple_user(SCARG(uap, path),
759 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
760 1.1 thorpej if (error)
761 1.1 thorpej return (error);
762 1.1 thorpej
763 1.20 dholland error = extattr_list_vp(vp, SCARG(uap, attrnamespace),
764 1.27 manu SCARG(uap, data), SCARG(uap, nbytes),
765 1.27 manu EXTATTR_LIST_LENPREFIX, l, retval);
766 1.1 thorpej
767 1.20 dholland vrele(vp);
768 1.1 thorpej return (error);
769 1.1 thorpej }
770 1.2 thorpej
771 1.2 thorpej /*****************************************************************************
772 1.2 thorpej * Linux-compatible <sys/xattr.h> API for file system extended attributes
773 1.2 thorpej *****************************************************************************/
774 1.2 thorpej
775 1.24 manu #define MATCH_NS(ns, key) (strncmp(ns, key, sizeof(ns) - 1) == 0)
776 1.24 manu static int
777 1.24 manu xattr_native(const char *key) {
778 1.24 manu if (MATCH_NS("system.", key))
779 1.24 manu return EXTATTR_NAMESPACE_SYSTEM;
780 1.24 manu else if (MATCH_NS("user.", key))
781 1.24 manu return EXTATTR_NAMESPACE_USER;
782 1.24 manu else if (MATCH_NS("security.", key))
783 1.24 manu return EXTATTR_NAMESPACE_SYSTEM;
784 1.24 manu else if (MATCH_NS("trusted.", key))
785 1.24 manu return EXTATTR_NAMESPACE_SYSTEM;
786 1.24 manu else
787 1.24 manu return EXTATTR_NAMESPACE_USER;
788 1.24 manu
789 1.24 manu }
790 1.24 manu #undef MATCH_NS
791 1.24 manu
792 1.29 drochner #define XATTR_ERRNO(e) ((e) == EOPNOTSUPP ? ENOTSUP : (e))
793 1.29 drochner
794 1.2 thorpej int
795 1.15 dsl sys_setxattr(struct lwp *l, const struct sys_setxattr_args *uap, register_t *retval)
796 1.2 thorpej {
797 1.15 dsl /* {
798 1.2 thorpej syscallarg(const char *) path;
799 1.2 thorpej syscallarg(const char *) name;
800 1.2 thorpej syscallarg(void *) value;
801 1.2 thorpej syscallarg(size_t) size;
802 1.2 thorpej syscallarg(int) flags;
803 1.15 dsl } */
804 1.20 dholland struct vnode *vp;
805 1.2 thorpej char attrname[XATTR_NAME_MAX];
806 1.32 matt int attrnamespace;
807 1.24 manu register_t attrlen;
808 1.2 thorpej int error;
809 1.2 thorpej
810 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
811 1.2 thorpej NULL);
812 1.2 thorpej if (error)
813 1.24 manu goto out;
814 1.2 thorpej
815 1.20 dholland error = namei_simple_user(SCARG(uap, path),
816 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
817 1.2 thorpej if (error)
818 1.26 manu goto out;
819 1.2 thorpej
820 1.32 matt attrnamespace = xattr_native(attrname);
821 1.2 thorpej
822 1.32 matt error = extattr_set_vp(vp, attrnamespace,
823 1.24 manu attrname, SCARG(uap, value), SCARG(uap, size), l,
824 1.24 manu &attrlen, SCARG(uap, flags));
825 1.2 thorpej
826 1.20 dholland vrele(vp);
827 1.24 manu out:
828 1.24 manu *retval = (error == 0) ? 0 : -1;
829 1.29 drochner return (XATTR_ERRNO(error));
830 1.2 thorpej }
831 1.2 thorpej
832 1.2 thorpej int
833 1.15 dsl sys_lsetxattr(struct lwp *l, const struct sys_lsetxattr_args *uap, register_t *retval)
834 1.2 thorpej {
835 1.15 dsl /* {
836 1.2 thorpej syscallarg(const char *) path;
837 1.2 thorpej syscallarg(const char *) name;
838 1.2 thorpej syscallarg(void *) value;
839 1.2 thorpej syscallarg(size_t) size;
840 1.2 thorpej syscallarg(int) flags;
841 1.15 dsl } */
842 1.20 dholland struct vnode *vp;
843 1.2 thorpej char attrname[XATTR_NAME_MAX];
844 1.32 matt int attrnamespace;
845 1.24 manu register_t attrlen;
846 1.2 thorpej int error;
847 1.2 thorpej
848 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
849 1.2 thorpej NULL);
850 1.2 thorpej if (error)
851 1.24 manu goto out;
852 1.2 thorpej
853 1.20 dholland error = namei_simple_user(SCARG(uap, path),
854 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
855 1.2 thorpej if (error)
856 1.26 manu goto out;
857 1.2 thorpej
858 1.32 matt attrnamespace = xattr_native(attrname);
859 1.2 thorpej
860 1.32 matt error = extattr_set_vp(vp, attrnamespace,
861 1.24 manu attrname, SCARG(uap, value), SCARG(uap, size), l,
862 1.24 manu &attrlen, SCARG(uap, flags));
863 1.2 thorpej
864 1.20 dholland vrele(vp);
865 1.24 manu out:
866 1.24 manu *retval = (error == 0) ? 0 : -1;
867 1.29 drochner return (XATTR_ERRNO(error));
868 1.2 thorpej }
869 1.2 thorpej
870 1.2 thorpej int
871 1.15 dsl sys_fsetxattr(struct lwp *l, const struct sys_fsetxattr_args *uap, register_t *retval)
872 1.2 thorpej {
873 1.15 dsl /* {
874 1.2 thorpej syscallarg(int) fd;
875 1.2 thorpej syscallarg(const char *) name;
876 1.2 thorpej syscallarg(void *) value;
877 1.2 thorpej syscallarg(size_t) size;
878 1.2 thorpej syscallarg(int) flags;
879 1.15 dsl } */
880 1.2 thorpej struct file *fp;
881 1.2 thorpej struct vnode *vp;
882 1.2 thorpej char attrname[XATTR_NAME_MAX];
883 1.32 matt int attrnamespace;
884 1.24 manu register_t attrlen;
885 1.2 thorpej int error;
886 1.2 thorpej
887 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
888 1.2 thorpej NULL);
889 1.2 thorpej if (error)
890 1.24 manu goto out;
891 1.2 thorpej
892 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
893 1.2 thorpej if (error)
894 1.24 manu goto out;
895 1.33 matt vp = fp->f_vnode;
896 1.2 thorpej
897 1.32 matt attrnamespace = xattr_native(attrname);
898 1.2 thorpej
899 1.32 matt error = extattr_set_vp(vp, attrnamespace,
900 1.24 manu attrname, SCARG(uap, value), SCARG(uap, size), l,
901 1.24 manu &attrlen, SCARG(uap, flags));
902 1.2 thorpej
903 1.17 ad fd_putfile(SCARG(uap, fd));
904 1.24 manu out:
905 1.24 manu *retval = (error == 0) ? 0 : -1;
906 1.29 drochner return (XATTR_ERRNO(error));
907 1.2 thorpej }
908 1.2 thorpej
909 1.2 thorpej int
910 1.15 dsl sys_getxattr(struct lwp *l, const struct sys_getxattr_args *uap, register_t *retval)
911 1.2 thorpej {
912 1.15 dsl /* {
913 1.2 thorpej syscallarg(const char *) path;
914 1.2 thorpej syscallarg(const char *) name;
915 1.2 thorpej syscallarg(void *) value;
916 1.2 thorpej syscallarg(size_t) size;
917 1.15 dsl } */
918 1.20 dholland struct vnode *vp;
919 1.2 thorpej char attrname[XATTR_NAME_MAX];
920 1.32 matt int attrnamespace;
921 1.2 thorpej int error;
922 1.2 thorpej
923 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
924 1.2 thorpej NULL);
925 1.2 thorpej if (error)
926 1.2 thorpej return (error);
927 1.2 thorpej
928 1.20 dholland error = namei_simple_user(SCARG(uap, path),
929 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
930 1.2 thorpej if (error)
931 1.2 thorpej return (error);
932 1.2 thorpej
933 1.32 matt attrnamespace = xattr_native(attrname);
934 1.24 manu
935 1.32 matt error = extattr_get_vp(vp, attrnamespace,
936 1.4 christos attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
937 1.2 thorpej
938 1.20 dholland vrele(vp);
939 1.29 drochner return (XATTR_ERRNO(error));
940 1.2 thorpej }
941 1.2 thorpej
942 1.2 thorpej int
943 1.15 dsl sys_lgetxattr(struct lwp *l, const struct sys_lgetxattr_args *uap, register_t *retval)
944 1.2 thorpej {
945 1.15 dsl /* {
946 1.2 thorpej syscallarg(const char *) path;
947 1.2 thorpej syscallarg(const char *) name;
948 1.2 thorpej syscallarg(void *) value;
949 1.2 thorpej syscallarg(size_t) size;
950 1.15 dsl } */
951 1.20 dholland struct vnode *vp;
952 1.2 thorpej char attrname[XATTR_NAME_MAX];
953 1.32 matt int attrnamespace;
954 1.2 thorpej int error;
955 1.2 thorpej
956 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
957 1.2 thorpej NULL);
958 1.2 thorpej if (error)
959 1.2 thorpej return (error);
960 1.2 thorpej
961 1.20 dholland error = namei_simple_user(SCARG(uap, path),
962 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
963 1.2 thorpej if (error)
964 1.2 thorpej return (error);
965 1.2 thorpej
966 1.32 matt attrnamespace = xattr_native(attrname);
967 1.24 manu
968 1.32 matt error = extattr_get_vp(vp, attrnamespace,
969 1.4 christos attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
970 1.2 thorpej
971 1.20 dholland vrele(vp);
972 1.29 drochner return (XATTR_ERRNO(error));
973 1.2 thorpej }
974 1.2 thorpej
975 1.2 thorpej int
976 1.15 dsl sys_fgetxattr(struct lwp *l, const struct sys_fgetxattr_args *uap, register_t *retval)
977 1.2 thorpej {
978 1.15 dsl /* {
979 1.2 thorpej syscallarg(int) fd;
980 1.2 thorpej syscallarg(const char *) name;
981 1.2 thorpej syscallarg(void *) value;
982 1.2 thorpej syscallarg(size_t) size;
983 1.15 dsl } */
984 1.2 thorpej struct file *fp;
985 1.2 thorpej struct vnode *vp;
986 1.2 thorpej char attrname[XATTR_NAME_MAX];
987 1.32 matt int attrnamespace;
988 1.2 thorpej int error;
989 1.2 thorpej
990 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
991 1.2 thorpej NULL);
992 1.2 thorpej if (error)
993 1.2 thorpej return (error);
994 1.2 thorpej
995 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
996 1.2 thorpej if (error)
997 1.2 thorpej return (error);
998 1.33 matt vp = fp->f_vnode;
999 1.2 thorpej
1000 1.32 matt attrnamespace = xattr_native(attrname);
1001 1.24 manu
1002 1.32 matt error = extattr_get_vp(vp, attrnamespace,
1003 1.4 christos attrname, SCARG(uap, value), SCARG(uap, size), l, retval);
1004 1.2 thorpej
1005 1.17 ad fd_putfile(SCARG(uap, fd));
1006 1.29 drochner return (XATTR_ERRNO(error));
1007 1.2 thorpej }
1008 1.2 thorpej
1009 1.2 thorpej int
1010 1.15 dsl sys_listxattr(struct lwp *l, const struct sys_listxattr_args *uap, register_t *retval)
1011 1.2 thorpej {
1012 1.15 dsl /* {
1013 1.2 thorpej syscallarg(const char *) path;
1014 1.2 thorpej syscallarg(char *) list;
1015 1.2 thorpej syscallarg(size_t) size;
1016 1.15 dsl } */
1017 1.20 dholland struct vnode *vp;
1018 1.24 manu char *list;
1019 1.24 manu size_t size;
1020 1.24 manu register_t listsize_usr, listsize_sys;
1021 1.2 thorpej int error;
1022 1.2 thorpej
1023 1.20 dholland error = namei_simple_user(SCARG(uap, path),
1024 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
1025 1.2 thorpej if (error)
1026 1.2 thorpej return (error);
1027 1.2 thorpej
1028 1.24 manu list = SCARG(uap, list);
1029 1.24 manu size = SCARG(uap, size);
1030 1.24 manu
1031 1.20 dholland error = extattr_list_vp(vp, EXTATTR_NAMESPACE_USER,
1032 1.27 manu list, size, 0, l, &listsize_usr);
1033 1.24 manu if (error)
1034 1.24 manu goto out;
1035 1.24 manu
1036 1.24 manu if (list)
1037 1.24 manu list += listsize_usr;
1038 1.24 manu if (size)
1039 1.24 manu size -= listsize_usr;
1040 1.2 thorpej
1041 1.24 manu error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
1042 1.27 manu list, size, 0, l, &listsize_sys);
1043 1.25 manu switch (error) {
1044 1.25 manu case EPERM:
1045 1.25 manu error = 0; /* Ignore and just skip system EA */
1046 1.25 manu listsize_sys = 0;
1047 1.25 manu break;
1048 1.25 manu case 0:
1049 1.25 manu break;
1050 1.25 manu default:
1051 1.24 manu goto out;
1052 1.25 manu break;
1053 1.25 manu }
1054 1.24 manu
1055 1.24 manu *retval = listsize_usr + listsize_sys;
1056 1.24 manu
1057 1.24 manu out:
1058 1.20 dholland vrele(vp);
1059 1.29 drochner return (XATTR_ERRNO(error));
1060 1.2 thorpej }
1061 1.2 thorpej
1062 1.2 thorpej int
1063 1.15 dsl sys_llistxattr(struct lwp *l, const struct sys_llistxattr_args *uap, register_t *retval)
1064 1.2 thorpej {
1065 1.15 dsl /* {
1066 1.2 thorpej syscallarg(const char *) path;
1067 1.2 thorpej syscallarg(char *) list;
1068 1.2 thorpej syscallarg(size_t) size;
1069 1.15 dsl } */
1070 1.20 dholland struct vnode *vp;
1071 1.24 manu char *list;
1072 1.24 manu size_t size;
1073 1.24 manu register_t listsize_usr, listsize_sys;
1074 1.2 thorpej int error;
1075 1.2 thorpej
1076 1.20 dholland error = namei_simple_user(SCARG(uap, path),
1077 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
1078 1.2 thorpej if (error)
1079 1.2 thorpej return (error);
1080 1.2 thorpej
1081 1.24 manu list = SCARG(uap, list);
1082 1.24 manu size = SCARG(uap, size);
1083 1.24 manu
1084 1.20 dholland error = extattr_list_vp(vp, EXTATTR_NAMESPACE_USER,
1085 1.27 manu list, size, 0, l, &listsize_usr);
1086 1.24 manu if (error)
1087 1.24 manu goto out;
1088 1.24 manu if (list)
1089 1.24 manu list += listsize_usr;
1090 1.24 manu if (size)
1091 1.24 manu size -= listsize_usr;
1092 1.2 thorpej
1093 1.24 manu error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
1094 1.27 manu list, size, 0, l, &listsize_sys);
1095 1.25 manu switch (error) {
1096 1.25 manu case EPERM:
1097 1.25 manu error = 0; /* Ignore and just skip system EA */
1098 1.25 manu listsize_sys = 0;
1099 1.25 manu break;
1100 1.25 manu case 0:
1101 1.25 manu break;
1102 1.25 manu default:
1103 1.24 manu goto out;
1104 1.25 manu break;
1105 1.25 manu }
1106 1.24 manu
1107 1.24 manu *retval = listsize_usr + listsize_sys;
1108 1.24 manu out:
1109 1.20 dholland vrele(vp);
1110 1.29 drochner return (XATTR_ERRNO(error));
1111 1.2 thorpej }
1112 1.2 thorpej
1113 1.2 thorpej int
1114 1.15 dsl sys_flistxattr(struct lwp *l, const struct sys_flistxattr_args *uap, register_t *retval)
1115 1.2 thorpej {
1116 1.15 dsl /* {
1117 1.2 thorpej syscallarg(int) fd;
1118 1.2 thorpej syscallarg(char *) list;
1119 1.2 thorpej syscallarg(size_t) size;
1120 1.15 dsl } */
1121 1.2 thorpej struct file *fp;
1122 1.2 thorpej struct vnode *vp;
1123 1.24 manu char *list;
1124 1.24 manu size_t size;
1125 1.24 manu register_t listsize_usr, listsize_sys;
1126 1.2 thorpej int error;
1127 1.2 thorpej
1128 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
1129 1.2 thorpej if (error)
1130 1.2 thorpej return (error);
1131 1.33 matt vp = fp->f_vnode;
1132 1.2 thorpej
1133 1.24 manu list = SCARG(uap, list);
1134 1.24 manu size = SCARG(uap, size);
1135 1.24 manu
1136 1.2 thorpej error = extattr_list_vp(vp, EXTATTR_NAMESPACE_USER,
1137 1.27 manu list, size, 0, l, &listsize_usr);
1138 1.24 manu if (error)
1139 1.24 manu goto out;
1140 1.24 manu
1141 1.24 manu if (list)
1142 1.24 manu list += listsize_usr;
1143 1.24 manu if (size)
1144 1.24 manu size -= listsize_usr;
1145 1.24 manu
1146 1.24 manu error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
1147 1.27 manu list, size, 0, l, &listsize_sys);
1148 1.25 manu switch (error) {
1149 1.25 manu case EPERM:
1150 1.25 manu error = 0; /* Ignore and just skip system EA */
1151 1.25 manu listsize_sys = 0;
1152 1.25 manu break;
1153 1.25 manu case 0:
1154 1.25 manu break;
1155 1.25 manu default:
1156 1.24 manu goto out;
1157 1.25 manu break;
1158 1.25 manu }
1159 1.24 manu
1160 1.24 manu *retval = listsize_usr + listsize_sys;
1161 1.24 manu out:
1162 1.2 thorpej
1163 1.17 ad fd_putfile(SCARG(uap, fd));
1164 1.29 drochner return (XATTR_ERRNO(error));
1165 1.2 thorpej }
1166 1.2 thorpej
1167 1.2 thorpej int
1168 1.15 dsl sys_removexattr(struct lwp *l, const struct sys_removexattr_args *uap, register_t *retval)
1169 1.2 thorpej {
1170 1.15 dsl /* {
1171 1.2 thorpej syscallarg(const char *) path;
1172 1.2 thorpej syscallarg(const char *) name;
1173 1.15 dsl } */
1174 1.20 dholland struct vnode *vp;
1175 1.2 thorpej char attrname[XATTR_NAME_MAX];
1176 1.32 matt int attrnamespace;
1177 1.2 thorpej int error;
1178 1.2 thorpej
1179 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
1180 1.2 thorpej NULL);
1181 1.2 thorpej if (error)
1182 1.2 thorpej return (error);
1183 1.2 thorpej
1184 1.20 dholland error = namei_simple_user(SCARG(uap, path),
1185 1.20 dholland NSM_FOLLOW_NOEMULROOT, &vp);
1186 1.2 thorpej if (error)
1187 1.2 thorpej return (error);
1188 1.2 thorpej
1189 1.32 matt attrnamespace = xattr_native(attrname);
1190 1.24 manu
1191 1.32 matt error = extattr_delete_vp(vp, attrnamespace, attrname, l);
1192 1.2 thorpej
1193 1.20 dholland vrele(vp);
1194 1.29 drochner return (XATTR_ERRNO(error));
1195 1.2 thorpej }
1196 1.2 thorpej
1197 1.2 thorpej int
1198 1.15 dsl sys_lremovexattr(struct lwp *l, const struct sys_lremovexattr_args *uap, register_t *retval)
1199 1.2 thorpej {
1200 1.15 dsl /* {
1201 1.2 thorpej syscallarg(const char *) path;
1202 1.2 thorpej syscallarg(const char *) name;
1203 1.15 dsl } */
1204 1.20 dholland struct vnode *vp;
1205 1.2 thorpej char attrname[XATTR_NAME_MAX];
1206 1.32 matt int attrnamespace;
1207 1.2 thorpej int error;
1208 1.2 thorpej
1209 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
1210 1.2 thorpej NULL);
1211 1.2 thorpej if (error)
1212 1.2 thorpej return (error);
1213 1.2 thorpej
1214 1.20 dholland error = namei_simple_user(SCARG(uap, path),
1215 1.20 dholland NSM_NOFOLLOW_NOEMULROOT, &vp);
1216 1.2 thorpej if (error)
1217 1.2 thorpej return (error);
1218 1.2 thorpej
1219 1.32 matt attrnamespace = xattr_native(attrname);
1220 1.24 manu
1221 1.32 matt error = extattr_delete_vp(vp, attrnamespace, attrname, l);
1222 1.2 thorpej
1223 1.20 dholland vrele(vp);
1224 1.29 drochner return (XATTR_ERRNO(error));
1225 1.2 thorpej }
1226 1.2 thorpej
1227 1.2 thorpej int
1228 1.15 dsl sys_fremovexattr(struct lwp *l, const struct sys_fremovexattr_args *uap, register_t *retval)
1229 1.2 thorpej {
1230 1.15 dsl /* {
1231 1.2 thorpej syscallarg(int) fd;
1232 1.2 thorpej syscallarg(const char *) name;
1233 1.15 dsl } */
1234 1.2 thorpej struct file *fp;
1235 1.2 thorpej struct vnode *vp;
1236 1.2 thorpej char attrname[XATTR_NAME_MAX];
1237 1.32 matt int attrnamespace;
1238 1.2 thorpej int error;
1239 1.2 thorpej
1240 1.2 thorpej error = copyinstr(SCARG(uap, name), attrname, sizeof(attrname),
1241 1.2 thorpej NULL);
1242 1.2 thorpej if (error)
1243 1.2 thorpej return (error);
1244 1.2 thorpej
1245 1.19 ad error = fd_getvnode(SCARG(uap, fd), &fp);
1246 1.2 thorpej if (error)
1247 1.2 thorpej return (error);
1248 1.33 matt vp = fp->f_vnode;
1249 1.2 thorpej
1250 1.32 matt attrnamespace = xattr_native(attrname);
1251 1.24 manu
1252 1.32 matt error = extattr_delete_vp(vp, attrnamespace, attrname, l);
1253 1.2 thorpej
1254 1.17 ad fd_putfile(SCARG(uap, fd));
1255 1.29 drochner return (XATTR_ERRNO(error));
1256 1.2 thorpej }
1257