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