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