2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2007-2009 Google Inc. and Amit Singh
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following disclaimer
15 * in the documentation and/or other materials provided with the
17 * * Neither the name of Google Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (C) 2005 Csaba Henk.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 #include <sys/cdefs.h>
59 __FBSDID("$FreeBSD$");
61 #include <sys/param.h>
62 #include <sys/module.h>
63 #include <sys/systm.h>
64 #include <sys/errno.h>
65 #include <sys/kernel.h>
68 #include <sys/malloc.h>
69 #include <sys/queue.h>
71 #include <sys/rwlock.h>
74 #include <sys/mount.h>
75 #include <sys/vnode.h>
76 #include <sys/namei.h>
77 #include <sys/extattr.h>
79 #include <sys/unistd.h>
80 #include <sys/filedesc.h>
82 #include <sys/fcntl.h>
83 #include <sys/dirent.h>
86 #include <sys/sysctl.h>
87 #include <sys/vmmeter.h>
90 #include <vm/vm_extern.h>
92 #include <vm/vm_map.h>
93 #include <vm/vm_page.h>
94 #include <vm/vm_param.h>
95 #include <vm/vm_object.h>
96 #include <vm/vm_pager.h>
97 #include <vm/vnode_pager.h>
98 #include <vm/vm_object.h>
101 #include "fuse_file.h"
102 #include "fuse_internal.h"
103 #include "fuse_ipc.h"
104 #include "fuse_node.h"
107 #include <sys/priv.h>
109 /* Maximum number of hardlinks to a single FUSE file */
110 #define FUSE_LINK_MAX UINT32_MAX
112 SDT_PROVIDER_DECLARE(fusefs);
115 * arg0: verbosity. Higher numbers give more verbose messages
116 * arg1: Textual message
118 SDT_PROBE_DEFINE2(fusefs, , vnops, trace, "int", "char*");
121 static vop_access_t fuse_vnop_access;
122 static vop_advlock_t fuse_vnop_advlock;
123 static vop_bmap_t fuse_vnop_bmap;
124 static vop_close_t fuse_fifo_close;
125 static vop_close_t fuse_vnop_close;
126 static vop_create_t fuse_vnop_create;
127 static vop_deleteextattr_t fuse_vnop_deleteextattr;
128 static vop_fdatasync_t fuse_vnop_fdatasync;
129 static vop_fsync_t fuse_vnop_fsync;
130 static vop_getattr_t fuse_vnop_getattr;
131 static vop_getextattr_t fuse_vnop_getextattr;
132 static vop_inactive_t fuse_vnop_inactive;
133 static vop_link_t fuse_vnop_link;
134 static vop_listextattr_t fuse_vnop_listextattr;
135 static vop_lookup_t fuse_vnop_lookup;
136 static vop_mkdir_t fuse_vnop_mkdir;
137 static vop_mknod_t fuse_vnop_mknod;
138 static vop_open_t fuse_vnop_open;
139 static vop_pathconf_t fuse_vnop_pathconf;
140 static vop_read_t fuse_vnop_read;
141 static vop_readdir_t fuse_vnop_readdir;
142 static vop_readlink_t fuse_vnop_readlink;
143 static vop_reclaim_t fuse_vnop_reclaim;
144 static vop_remove_t fuse_vnop_remove;
145 static vop_rename_t fuse_vnop_rename;
146 static vop_rmdir_t fuse_vnop_rmdir;
147 static vop_setattr_t fuse_vnop_setattr;
148 static vop_setextattr_t fuse_vnop_setextattr;
149 static vop_strategy_t fuse_vnop_strategy;
150 static vop_symlink_t fuse_vnop_symlink;
151 static vop_write_t fuse_vnop_write;
152 static vop_getpages_t fuse_vnop_getpages;
153 static vop_putpages_t fuse_vnop_putpages;
154 static vop_print_t fuse_vnop_print;
155 static vop_vptofh_t fuse_vnop_vptofh;
157 struct vop_vector fuse_fifoops = {
158 .vop_default = &fifo_specops,
159 .vop_access = fuse_vnop_access,
160 .vop_close = fuse_fifo_close,
161 .vop_fsync = fuse_vnop_fsync,
162 .vop_getattr = fuse_vnop_getattr,
163 .vop_inactive = fuse_vnop_inactive,
164 .vop_pathconf = fuse_vnop_pathconf,
165 .vop_print = fuse_vnop_print,
166 .vop_read = VOP_PANIC,
167 .vop_reclaim = fuse_vnop_reclaim,
168 .vop_setattr = fuse_vnop_setattr,
169 .vop_write = VOP_PANIC,
170 .vop_vptofh = fuse_vnop_vptofh,
173 struct vop_vector fuse_vnops = {
174 .vop_allocate = VOP_EINVAL,
175 .vop_default = &default_vnodeops,
176 .vop_access = fuse_vnop_access,
177 .vop_advlock = fuse_vnop_advlock,
178 .vop_bmap = fuse_vnop_bmap,
179 .vop_close = fuse_vnop_close,
180 .vop_create = fuse_vnop_create,
181 .vop_deleteextattr = fuse_vnop_deleteextattr,
182 .vop_fsync = fuse_vnop_fsync,
183 .vop_fdatasync = fuse_vnop_fdatasync,
184 .vop_getattr = fuse_vnop_getattr,
185 .vop_getextattr = fuse_vnop_getextattr,
186 .vop_inactive = fuse_vnop_inactive,
188 * TODO: implement vop_ioctl after upgrading to protocol 7.16.
189 * FUSE_IOCTL was added in 7.11, but 32-bit compat is broken until
192 .vop_link = fuse_vnop_link,
193 .vop_listextattr = fuse_vnop_listextattr,
194 .vop_lookup = fuse_vnop_lookup,
195 .vop_mkdir = fuse_vnop_mkdir,
196 .vop_mknod = fuse_vnop_mknod,
197 .vop_open = fuse_vnop_open,
198 .vop_pathconf = fuse_vnop_pathconf,
200 * TODO: implement vop_poll after upgrading to protocol 7.21.
201 * FUSE_POLL was added in protocol 7.11, but it's kind of broken until
202 * 7.21, which adds the ability for the client to choose which poll
203 * events it wants, and for a client to deregister a file handle
205 .vop_read = fuse_vnop_read,
206 .vop_readdir = fuse_vnop_readdir,
207 .vop_readlink = fuse_vnop_readlink,
208 .vop_reclaim = fuse_vnop_reclaim,
209 .vop_remove = fuse_vnop_remove,
210 .vop_rename = fuse_vnop_rename,
211 .vop_rmdir = fuse_vnop_rmdir,
212 .vop_setattr = fuse_vnop_setattr,
213 .vop_setextattr = fuse_vnop_setextattr,
214 .vop_strategy = fuse_vnop_strategy,
215 .vop_symlink = fuse_vnop_symlink,
216 .vop_write = fuse_vnop_write,
217 .vop_getpages = fuse_vnop_getpages,
218 .vop_putpages = fuse_vnop_putpages,
219 .vop_print = fuse_vnop_print,
220 .vop_vptofh = fuse_vnop_vptofh,
223 u_long fuse_lookup_cache_hits = 0;
225 SYSCTL_ULONG(_vfs_fusefs, OID_AUTO, lookup_cache_hits, CTLFLAG_RD,
226 &fuse_lookup_cache_hits, 0, "number of positive cache hits in lookup");
228 u_long fuse_lookup_cache_misses = 0;
230 SYSCTL_ULONG(_vfs_fusefs, OID_AUTO, lookup_cache_misses, CTLFLAG_RD,
231 &fuse_lookup_cache_misses, 0, "number of cache misses in lookup");
234 * XXX: This feature is highly experimental and can bring to instabilities,
235 * needs revisiting before to be enabled by default.
237 static int fuse_reclaim_revoked = 0;
239 SYSCTL_INT(_vfs_fusefs, OID_AUTO, reclaim_revoked, CTLFLAG_RW,
240 &fuse_reclaim_revoked, 0, "");
242 uma_zone_t fuse_pbuf_zone;
244 #define fuse_vm_page_lock(m) vm_page_lock((m));
245 #define fuse_vm_page_unlock(m) vm_page_unlock((m));
246 #define fuse_vm_page_lock_queues() ((void)0)
247 #define fuse_vm_page_unlock_queues() ((void)0)
249 /* Check permission for extattr operations, much like extattr_check_cred */
251 fuse_extattr_check_cred(struct vnode *vp, int ns, struct ucred *cred,
252 struct thread *td, accmode_t accmode)
254 struct mount *mp = vnode_mount(vp);
255 struct fuse_data *data = fuse_get_mpdata(mp);
258 * Kernel-invoked always succeeds.
264 * Do not allow privileged processes in jail to directly manipulate
268 case EXTATTR_NAMESPACE_SYSTEM:
269 if (data->dataflags & FSESS_DEFAULT_PERMISSIONS) {
270 return (priv_check_cred(cred, PRIV_VFS_EXTATTR_SYSTEM));
273 case EXTATTR_NAMESPACE_USER:
274 return (fuse_internal_access(vp, accmode, td, cred));
280 /* Get a filehandle for a directory */
282 fuse_filehandle_get_dir(struct vnode *vp, struct fuse_filehandle **fufhp,
283 struct ucred *cred, pid_t pid)
285 if (fuse_filehandle_get(vp, FREAD, fufhp, cred, pid) == 0)
287 return fuse_filehandle_get(vp, FEXEC, fufhp, cred, pid);
290 /* Send FUSE_FLUSH for this vnode */
292 fuse_flush(struct vnode *vp, struct ucred *cred, pid_t pid, int fflag)
294 struct fuse_flush_in *ffi;
295 struct fuse_filehandle *fufh;
296 struct fuse_dispatcher fdi;
297 struct thread *td = curthread;
298 struct mount *mp = vnode_mount(vp);
301 if (!fsess_isimpl(vnode_mount(vp), FUSE_FLUSH))
304 err = fuse_filehandle_getrw(vp, fflag, &fufh, cred, pid);
308 fdisp_init(&fdi, sizeof(*ffi));
309 fdisp_make_vp(&fdi, FUSE_FLUSH, vp, td, cred);
311 ffi->fh = fufh->fh_id;
313 * If the file has a POSIX lock then we're supposed to set lock_owner.
314 * If not, then lock_owner is undefined. So we may as well always set
317 ffi->lock_owner = td->td_proc->p_pid;
319 err = fdisp_wait_answ(&fdi);
321 fsess_set_notimpl(mp, FUSE_FLUSH);
328 /* Close wrapper for fifos. */
330 fuse_fifo_close(struct vop_close_args *ap)
332 return (fifo_specops.vop_close(ap));
336 struct vnop_access_args {
338 #if VOP_ACCESS_TAKES_ACCMODE_T
343 struct ucred *a_cred;
348 fuse_vnop_access(struct vop_access_args *ap)
350 struct vnode *vp = ap->a_vp;
351 int accmode = ap->a_accmode;
352 struct ucred *cred = ap->a_cred;
354 struct fuse_data *data = fuse_get_mpdata(vnode_mount(vp));
358 if (fuse_isdeadfs(vp)) {
359 if (vnode_isvroot(vp)) {
364 if (!(data->dataflags & FSESS_INITED)) {
365 if (vnode_isvroot(vp)) {
366 if (priv_check_cred(cred, PRIV_VFS_ADMIN) ||
367 (fuse_match_cred(data->daemoncred, cred) == 0)) {
373 if (vnode_islnk(vp)) {
377 err = fuse_internal_access(vp, accmode, ap->a_td, ap->a_cred);
382 * struct vop_advlock_args {
383 * struct vop_generic_args a_gen;
384 * struct vnode *a_vp;
387 * struct flock *a_fl;
392 fuse_vnop_advlock(struct vop_advlock_args *ap)
394 struct vnode *vp = ap->a_vp;
395 struct flock *fl = ap->a_fl;
396 struct thread *td = curthread;
397 struct ucred *cred = td->td_ucred;
398 pid_t pid = td->td_proc->p_pid;
399 struct fuse_filehandle *fufh;
400 struct fuse_dispatcher fdi;
401 struct fuse_lk_in *fli;
402 struct fuse_lk_out *flo;
405 int flags = ap->a_flags;
407 dataflags = fuse_get_mpdata(vnode_mount(vp))->dataflags;
409 if (fuse_isdeadfs(vp)) {
413 if (!(dataflags & FSESS_POSIX_LOCKS))
414 return vop_stdadvlock(ap);
415 /* FUSE doesn't properly support flock until protocol 7.17 */
417 return vop_stdadvlock(ap);
419 err = fuse_filehandle_get_anyflags(vp, &fufh, cred, pid);
423 fdisp_init(&fdi, sizeof(*fli));
439 fdisp_make_vp(&fdi, op, vp, td, cred);
441 fli->fh = fufh->fh_id;
442 fli->owner = fl->l_pid;
443 fli->lk.start = fl->l_start;
445 fli->lk.end = fl->l_start + fl->l_len - 1;
447 fli->lk.end = INT64_MAX;
448 fli->lk.type = fl->l_type;
449 fli->lk.pid = fl->l_pid;
451 err = fdisp_wait_answ(&fdi);
454 if (err == 0 && op == FUSE_GETLK) {
456 fl->l_type = flo->lk.type;
457 fl->l_pid = flo->lk.pid;
458 if (flo->lk.type != F_UNLCK) {
459 fl->l_start = flo->lk.start;
460 if (flo->lk.end == INT64_MAX)
463 fl->l_len = flo->lk.end - flo->lk.start + 1;
464 fl->l_start = flo->lk.start;
474 struct bufobj **a_bop;
480 fuse_vnop_bmap(struct vop_bmap_args *ap)
482 struct vnode *vp = ap->a_vp;
483 struct bufobj **bo = ap->a_bop;
484 struct thread *td = curthread;
486 struct fuse_dispatcher fdi;
487 struct fuse_bmap_in *fbi;
488 struct fuse_bmap_out *fbo;
489 struct fuse_data *data;
492 daddr_t lbn = ap->a_bn;
493 daddr_t *pbn = ap->a_bnp;
494 int *runp = ap->a_runp;
495 int *runb = ap->a_runb;
499 if (fuse_isdeadfs(vp)) {
503 mp = vnode_mount(vp);
504 data = fuse_get_mpdata(mp);
505 biosize = fuse_iosize(vp);
506 maxrun = MIN(vp->v_mount->mnt_iosize_max / biosize - 1,
507 data->max_readahead_blocks);
513 * The FUSE_BMAP operation does not include the runp and runb
514 * variables, so we must guess. Report nonzero contiguous runs so
515 * cluster_read will combine adjacent reads. It's worthwhile to reduce
516 * upcalls even if we don't know the true physical layout of the file.
518 * FUSE file systems may opt out of read clustering in two ways:
519 * * mounting with -onoclusterr
520 * * Setting max_readahead <= maxbcachebuf during FUSE_INIT
523 *runb = MIN(lbn, maxrun);
525 error = fuse_vnode_size(vp, &filesize, td->td_ucred, td);
527 *runp = MIN(MAX(0, filesize / biosize - lbn - 1),
533 if (fsess_isimpl(mp, FUSE_BMAP)) {
534 fdisp_init(&fdi, sizeof(*fbi));
535 fdisp_make_vp(&fdi, FUSE_BMAP, vp, td, td->td_ucred);
538 fbi->blocksize = biosize;
539 error = fdisp_wait_answ(&fdi);
540 if (error == ENOSYS) {
541 fsess_set_notimpl(mp, FUSE_BMAP);
545 if (error == 0 && pbn != NULL)
551 /* If the daemon doesn't support BMAP, make up a sensible default */
553 *pbn = lbn * btodb(biosize);
558 struct vop_close_args {
561 struct ucred *a_cred;
566 fuse_vnop_close(struct vop_close_args *ap)
568 struct vnode *vp = ap->a_vp;
569 struct ucred *cred = ap->a_cred;
570 int fflag = ap->a_fflag;
571 struct thread *td = ap->a_td;
572 pid_t pid = td->td_proc->p_pid;
575 if (fuse_isdeadfs(vp))
579 if (fflag & IO_NDELAY)
582 err = fuse_flush(vp, cred, pid, fflag);
583 /* TODO: close the file handle, if we're sure it's no longer used */
584 if ((VTOFUD(vp)->flag & FN_SIZECHANGE) != 0) {
585 fuse_vnode_savesize(vp, cred, td->td_proc->p_pid);
591 fdisp_make_mknod_for_fallback(
592 struct fuse_dispatcher *fdip,
593 struct componentname *cnp,
599 enum fuse_opcode *op)
601 struct fuse_mknod_in *fmni;
603 fdisp_init(fdip, sizeof(*fmni) + cnp->cn_namelen + 1);
605 fdisp_make(fdip, *op, vnode_mount(dvp), parentnid, td, cred);
609 memcpy((char *)fdip->indata + sizeof(*fmni), cnp->cn_nameptr,
611 ((char *)fdip->indata)[sizeof(*fmni) + cnp->cn_namelen] = '\0';
614 struct vnop_create_args {
616 struct vnode **a_vpp;
617 struct componentname *a_cnp;
622 fuse_vnop_create(struct vop_create_args *ap)
624 struct vnode *dvp = ap->a_dvp;
625 struct vnode **vpp = ap->a_vpp;
626 struct componentname *cnp = ap->a_cnp;
627 struct vattr *vap = ap->a_vap;
628 struct thread *td = cnp->cn_thread;
629 struct ucred *cred = cnp->cn_cred;
631 struct fuse_data *data;
632 struct fuse_create_in *fci;
633 struct fuse_entry_out *feo;
634 struct fuse_open_out *foo;
635 struct fuse_dispatcher fdi, fdi2;
636 struct fuse_dispatcher *fdip = &fdi;
637 struct fuse_dispatcher *fdip2 = NULL;
641 struct mount *mp = vnode_mount(dvp);
642 data = fuse_get_mpdata(mp);
643 uint64_t parentnid = VTOFUD(dvp)->nid;
644 mode_t mode = MAKEIMODE(vap->va_type, vap->va_mode);
648 if (fuse_isdeadfs(dvp))
651 /* FUSE expects sockets to be created with FUSE_MKNOD */
652 if (vap->va_type == VSOCK)
653 return fuse_internal_mknod(dvp, vpp, cnp, vap);
656 * VOP_CREATE doesn't tell us the open(2) flags, so we guess. Only a
657 * writable mode makes sense, and we might as well include readability
662 bzero(&fdi, sizeof(fdi));
664 if (vap->va_type != VREG)
667 if (!fsess_isimpl(mp, FUSE_CREATE) || vap->va_type == VSOCK) {
668 /* Fallback to FUSE_MKNOD/FUSE_OPEN */
669 fdisp_make_mknod_for_fallback(fdip, cnp, dvp, parentnid, td,
672 /* Use FUSE_CREATE */
676 fdisp_init(fdip, sizeof(*fci) + cnp->cn_namelen + 1);
677 fdisp_make(fdip, op, vnode_mount(dvp), parentnid, td, cred);
680 fci->flags = O_CREAT | flags;
681 if (fuse_libabi_geq(data, 7, 12)) {
682 insize = sizeof(*fci);
683 fci->umask = td->td_proc->p_fd->fd_cmask;
685 insize = sizeof(struct fuse_open_in);
688 memcpy((char *)fdip->indata + insize, cnp->cn_nameptr,
690 ((char *)fdip->indata)[insize + cnp->cn_namelen] = '\0';
693 err = fdisp_wait_answ(fdip);
696 if (err == ENOSYS && op == FUSE_CREATE) {
697 fsess_set_notimpl(mp, FUSE_CREATE);
698 fdisp_make_mknod_for_fallback(fdip, cnp, dvp,
699 parentnid, td, cred, mode, &op);
700 err = fdisp_wait_answ(fdip);
708 if ((err = fuse_internal_checkentry(feo, vap->va_type))) {
712 if (op == FUSE_CREATE) {
713 foo = (struct fuse_open_out*)(feo + 1);
715 /* Issue a separate FUSE_OPEN */
716 struct fuse_open_in *foi;
719 fdisp_init(fdip2, sizeof(*foi));
720 fdisp_make(fdip2, FUSE_OPEN, vnode_mount(dvp), feo->nodeid, td,
724 err = fdisp_wait_answ(fdip2);
729 err = fuse_vnode_get(mp, feo, feo->nodeid, dvp, vpp, cnp, vap->va_type);
731 struct fuse_release_in *fri;
732 uint64_t nodeid = feo->nodeid;
733 uint64_t fh_id = foo->fh;
735 fdisp_init(fdip, sizeof(*fri));
736 fdisp_make(fdip, FUSE_RELEASE, mp, nodeid, td, cred);
740 fuse_insert_callback(fdip->tick, fuse_internal_forget_callback);
741 fuse_insert_message(fdip->tick, false);
744 ASSERT_VOP_ELOCKED(*vpp, "fuse_vnop_create");
745 fuse_internal_cache_attrs(*vpp, &feo->attr, feo->attr_valid,
746 feo->attr_valid_nsec, NULL);
748 fuse_filehandle_init(*vpp, FUFH_RDWR, NULL, td, cred, foo);
749 fuse_vnode_open(*vpp, foo->open_flags, td);
751 * Purge the parent's attribute cache because the daemon should've
752 * updated its mtime and ctime
754 fuse_vnode_clear_attr_cache(dvp);
755 cache_purge_negative(dvp);
759 fdisp_destroy(fdip2);
765 struct vnop_fdatasync_args {
766 struct vop_generic_args a_gen;
768 struct thread * a_td;
772 fuse_vnop_fdatasync(struct vop_fdatasync_args *ap)
774 struct vnode *vp = ap->a_vp;
775 struct thread *td = ap->a_td;
776 int waitfor = MNT_WAIT;
780 if (fuse_isdeadfs(vp)) {
783 if ((err = vop_stdfdatasync_buf(ap)))
786 return fuse_internal_fsync(vp, td, waitfor, true);
790 struct vnop_fsync_args {
791 struct vop_generic_args a_gen;
794 struct thread * a_td;
798 fuse_vnop_fsync(struct vop_fsync_args *ap)
800 struct vnode *vp = ap->a_vp;
801 struct thread *td = ap->a_td;
802 int waitfor = ap->a_waitfor;
805 if (fuse_isdeadfs(vp)) {
808 if ((err = vop_stdfsync(ap)))
811 return fuse_internal_fsync(vp, td, waitfor, false);
815 struct vnop_getattr_args {
818 struct ucred *a_cred;
823 fuse_vnop_getattr(struct vop_getattr_args *ap)
825 struct vnode *vp = ap->a_vp;
826 struct vattr *vap = ap->a_vap;
827 struct ucred *cred = ap->a_cred;
828 struct thread *td = curthread;
833 dataflags = fuse_get_mpdata(vnode_mount(vp))->dataflags;
835 /* Note that we are not bailing out on a dead file system just yet. */
837 if (!(dataflags & FSESS_INITED)) {
838 if (!vnode_isvroot(vp)) {
839 fdata_set_dead(fuse_get_mpdata(vnode_mount(vp)));
846 err = fuse_internal_getattr(vp, vap, cred, td);
847 if (err == ENOTCONN && vnode_isvroot(vp)) {
848 /* see comment in fuse_vfsop_statfs() */
855 bzero(vap, sizeof(*vap));
856 vap->va_type = vnode_vtype(vp);
862 struct vnop_inactive_args {
868 fuse_vnop_inactive(struct vop_inactive_args *ap)
870 struct vnode *vp = ap->a_vp;
871 struct thread *td = ap->a_td;
873 struct fuse_vnode_data *fvdat = VTOFUD(vp);
874 struct fuse_filehandle *fufh, *fufh_tmp;
878 LIST_FOREACH_SAFE(fufh, &fvdat->handles, next, fufh_tmp) {
879 if (need_flush && vp->v_type == VREG) {
880 if ((VTOFUD(vp)->flag & FN_SIZECHANGE) != 0) {
881 fuse_vnode_savesize(vp, NULL, 0);
883 if ((fvdat->flag & FN_REVOKED) != 0)
884 fuse_io_invalbuf(vp, td);
886 fuse_io_flushbuf(vp, MNT_WAIT, td);
889 fuse_filehandle_close(vp, fufh, td, NULL);
892 if ((fvdat->flag & FN_REVOKED) != 0 && fuse_reclaim_revoked) {
899 struct vnop_link_args {
900 struct vnode *a_tdvp;
902 struct componentname *a_cnp;
906 fuse_vnop_link(struct vop_link_args *ap)
908 struct vnode *vp = ap->a_vp;
909 struct vnode *tdvp = ap->a_tdvp;
910 struct componentname *cnp = ap->a_cnp;
912 struct vattr *vap = VTOVA(vp);
914 struct fuse_dispatcher fdi;
915 struct fuse_entry_out *feo;
916 struct fuse_link_in fli;
920 if (fuse_isdeadfs(vp)) {
923 if (vnode_mount(tdvp) != vnode_mount(vp)) {
928 * This is a seatbelt check to protect naive userspace filesystems from
929 * themselves and the limitations of the FUSE IPC protocol. If a
930 * filesystem does not allow attribute caching, assume it is capable of
931 * validating that nlink does not overflow.
933 if (vap != NULL && vap->va_nlink >= FUSE_LINK_MAX)
935 fli.oldnodeid = VTOI(vp);
938 fuse_internal_newentry_makerequest(vnode_mount(tdvp), VTOI(tdvp), cnp,
939 FUSE_LINK, &fli, sizeof(fli), &fdi);
940 if ((err = fdisp_wait_answ(&fdi))) {
945 err = fuse_internal_checkentry(feo, vnode_vtype(vp));
948 * Purge the parent's attribute cache because the daemon
949 * should've updated its mtime and ctime
951 fuse_vnode_clear_attr_cache(tdvp);
952 fuse_internal_cache_attrs(vp, &feo->attr, feo->attr_valid,
953 feo->attr_valid_nsec, NULL);
960 struct fuse_lookup_alloc_arg {
961 struct fuse_entry_out *feo;
962 struct componentname *cnp;
967 /* Callback for vn_get_ino */
969 fuse_lookup_alloc(struct mount *mp, void *arg, int lkflags, struct vnode **vpp)
971 struct fuse_lookup_alloc_arg *flaa = arg;
973 return fuse_vnode_get(mp, flaa->feo, flaa->nid, NULL, vpp, flaa->cnp,
977 SDT_PROBE_DEFINE3(fusefs, , vnops, cache_lookup,
978 "int", "struct timespec*", "struct timespec*");
980 struct vnop_lookup_args {
981 struct vnodeop_desc *a_desc;
983 struct vnode **a_vpp;
984 struct componentname *a_cnp;
988 fuse_vnop_lookup(struct vop_lookup_args *ap)
990 struct vnode *dvp = ap->a_dvp;
991 struct vnode **vpp = ap->a_vpp;
992 struct componentname *cnp = ap->a_cnp;
993 struct thread *td = cnp->cn_thread;
994 struct ucred *cred = cnp->cn_cred;
996 int nameiop = cnp->cn_nameiop;
997 int flags = cnp->cn_flags;
998 int wantparent = flags & (LOCKPARENT | WANTPARENT);
999 int islastcn = flags & ISLASTCN;
1000 struct mount *mp = vnode_mount(dvp);
1004 struct vnode *vp = NULL;
1006 struct fuse_dispatcher fdi;
1007 bool did_lookup = false;
1008 struct fuse_entry_out *feo = NULL;
1009 enum vtype vtyp; /* vnode type of target */
1010 off_t filesize; /* filesize of target */
1014 if (fuse_isdeadfs(dvp)) {
1018 if (!vnode_isdir(dvp))
1021 if (islastcn && vfs_isrdonly(mp) && (nameiop != LOOKUP))
1024 if ((err = fuse_internal_access(dvp, VEXEC, td, cred)))
1027 if (flags & ISDOTDOT) {
1028 KASSERT(VTOFUD(dvp)->flag & FN_PARENT_NID,
1029 ("Looking up .. is TODO"));
1030 nid = VTOFUD(dvp)->parent_nid;
1033 /* .. is obviously a directory */
1036 } else if (cnp->cn_namelen == 1 && *(cnp->cn_nameptr) == '.') {
1038 /* . is obviously a directory */
1042 struct timespec now, timeout;
1044 err = cache_lookup(dvp, vpp, cnp, &timeout, NULL);
1045 getnanouptime(&now);
1046 SDT_PROBE3(fusefs, , vnops, cache_lookup, err, &timeout, &now);
1048 case -1: /* positive match */
1049 if (timespeccmp(&timeout, &now, >)) {
1050 atomic_add_acq_long(&fuse_lookup_cache_hits, 1);
1053 atomic_add_acq_long(&fuse_lookup_cache_misses,
1056 &VTOFUD(*vpp)->entry_cache_timeout);
1067 case 0: /* no match in cache */
1068 atomic_add_acq_long(&fuse_lookup_cache_misses, 1);
1071 case ENOENT: /* negative match */
1072 getnanouptime(&now);
1073 if (timespeccmp(&timeout, &now, <=)) {
1075 cache_purge_negative(dvp);
1084 fdisp_init(&fdi, cnp->cn_namelen + 1);
1085 fdisp_make(&fdi, FUSE_LOOKUP, mp, nid, td, cred);
1087 memcpy(fdi.indata, cnp->cn_nameptr, cnp->cn_namelen);
1088 ((char *)fdi.indata)[cnp->cn_namelen] = '\0';
1089 lookup_err = fdisp_wait_answ(&fdi);
1093 /* lookup call succeeded */
1094 feo = (struct fuse_entry_out *)fdi.answ;
1097 /* zero nodeid means ENOENT and cache it */
1098 struct timespec timeout;
1100 fdi.answ_stat = ENOENT;
1101 lookup_err = ENOENT;
1102 if (cnp->cn_flags & MAKEENTRY) {
1103 fuse_validity_2_timespec(feo, &timeout);
1104 cache_enter_time(dvp, *vpp, cnp,
1107 } else if (nid == FUSE_ROOT_ID) {
1108 lookup_err = EINVAL;
1110 vtyp = IFTOVT(feo->attr.mode);
1111 filesize = feo->attr.size;
1113 if (lookup_err && (!fdi.answ_stat || lookup_err != ENOENT)) {
1114 fdisp_destroy(&fdi);
1118 /* lookup_err, if non-zero, must be ENOENT at this point */
1121 /* Entry not found */
1122 if ((nameiop == CREATE || nameiop == RENAME) && islastcn) {
1123 err = fuse_internal_access(dvp, VWRITE, td, cred);
1126 * Set the SAVENAME flag to hold onto the
1127 * pathname for use later in VOP_CREATE or
1130 cnp->cn_flags |= SAVENAME;
1138 /* Entry was found */
1139 if (flags & ISDOTDOT) {
1140 struct fuse_lookup_alloc_arg flaa;
1146 err = vn_vget_ino_gen(dvp, fuse_lookup_alloc, &flaa, 0,
1149 } else if (nid == VTOI(dvp)) {
1153 struct fuse_vnode_data *fvdat;
1155 err = fuse_vnode_get(vnode_mount(dvp), feo, nid, dvp,
1162 * In the case where we are looking up a FUSE node
1163 * represented by an existing cached vnode, and the
1164 * true size reported by FUSE_LOOKUP doesn't match
1165 * the vnode's cached size, then any cached writes
1166 * beyond the file's current size are lost.
1169 * * following attribute cache expiration, or
1170 * * due a bug in the daemon, or
1173 if (vnode_isreg(vp) &&
1174 filesize != fvdat->cached_attrs.va_size &&
1175 fvdat->flag & FN_SIZECHANGE) {
1177 * The FN_SIZECHANGE flag reflects a dirty
1178 * append. If userspace lets us know our cache
1179 * is invalid, that write was lost. (Dirty
1180 * writes that do not cause append are also
1181 * lost, but we don't detect them here.)
1183 * XXX: Maybe disable WB caching on this mount.
1185 printf("%s: WB cache incoherent on %s!\n",
1187 vnode_mount(vp)->mnt_stat.f_mntonname);
1189 fvdat->flag &= ~FN_SIZECHANGE;
1193 fuse_internal_cache_attrs(*vpp, &feo->attr,
1194 feo->attr_valid, feo->attr_valid_nsec, NULL);
1195 fuse_validity_2_bintime(feo->entry_valid,
1196 feo->entry_valid_nsec,
1197 &fvdat->entry_cache_timeout);
1199 if ((nameiop == DELETE || nameiop == RENAME) &&
1202 struct vattr dvattr;
1204 err = fuse_internal_access(dvp, VWRITE, td,
1209 * if the parent's sticky bit is set, check
1210 * whether we're allowed to remove the file.
1211 * Need to figure out the vnode locking to make
1214 fuse_internal_getattr(dvp, &dvattr, cred, td);
1215 if ((dvattr.va_mode & S_ISTXT) &&
1216 fuse_internal_access(dvp, VADMIN, td,
1218 fuse_internal_access(*vpp, VADMIN, td,
1226 (nameiop == DELETE) ||
1227 (nameiop == RENAME && wantparent))) {
1228 cnp->cn_flags |= SAVENAME;
1235 if (vp != NULL && dvp != vp)
1237 else if (vp != NULL)
1242 fdisp_destroy(&fdi);
1248 struct vnop_mkdir_args {
1249 struct vnode *a_dvp;
1250 struct vnode **a_vpp;
1251 struct componentname *a_cnp;
1252 struct vattr *a_vap;
1256 fuse_vnop_mkdir(struct vop_mkdir_args *ap)
1258 struct vnode *dvp = ap->a_dvp;
1259 struct vnode **vpp = ap->a_vpp;
1260 struct componentname *cnp = ap->a_cnp;
1261 struct vattr *vap = ap->a_vap;
1263 struct fuse_mkdir_in fmdi;
1265 if (fuse_isdeadfs(dvp)) {
1268 fmdi.mode = MAKEIMODE(vap->va_type, vap->va_mode);
1269 fmdi.umask = curthread->td_proc->p_fd->fd_cmask;
1271 return (fuse_internal_newentry(dvp, vpp, cnp, FUSE_MKDIR, &fmdi,
1272 sizeof(fmdi), VDIR));
1276 struct vnop_mknod_args {
1277 struct vnode *a_dvp;
1278 struct vnode **a_vpp;
1279 struct componentname *a_cnp;
1280 struct vattr *a_vap;
1284 fuse_vnop_mknod(struct vop_mknod_args *ap)
1287 struct vnode *dvp = ap->a_dvp;
1288 struct vnode **vpp = ap->a_vpp;
1289 struct componentname *cnp = ap->a_cnp;
1290 struct vattr *vap = ap->a_vap;
1292 if (fuse_isdeadfs(dvp))
1295 return fuse_internal_mknod(dvp, vpp, cnp, vap);
1299 struct vop_open_args {
1302 struct ucred *a_cred;
1303 struct thread *a_td;
1304 int a_fdidx; / struct file *a_fp;
1308 fuse_vnop_open(struct vop_open_args *ap)
1310 struct vnode *vp = ap->a_vp;
1311 int a_mode = ap->a_mode;
1312 struct thread *td = ap->a_td;
1313 struct ucred *cred = ap->a_cred;
1314 pid_t pid = td->td_proc->p_pid;
1315 struct fuse_vnode_data *fvdat;
1317 if (fuse_isdeadfs(vp))
1319 if (vp->v_type == VCHR || vp->v_type == VBLK || vp->v_type == VFIFO)
1320 return (EOPNOTSUPP);
1321 if ((a_mode & (FREAD | FWRITE | FEXEC)) == 0)
1326 if (fuse_filehandle_validrw(vp, a_mode, cred, pid)) {
1327 fuse_vnode_open(vp, 0, td);
1331 return fuse_filehandle_open(vp, a_mode, NULL, td, cred);
1335 fuse_vnop_pathconf(struct vop_pathconf_args *ap)
1338 switch (ap->a_name) {
1339 case _PC_FILESIZEBITS:
1343 *ap->a_retval = NAME_MAX;
1346 *ap->a_retval = MIN(LONG_MAX, FUSE_LINK_MAX);
1348 case _PC_SYMLINK_MAX:
1349 *ap->a_retval = MAXPATHLEN;
1355 return (vop_stdpathconf(ap));
1360 struct vnop_read_args {
1364 struct ucred *a_cred;
1368 fuse_vnop_read(struct vop_read_args *ap)
1370 struct vnode *vp = ap->a_vp;
1371 struct uio *uio = ap->a_uio;
1372 int ioflag = ap->a_ioflag;
1373 struct ucred *cred = ap->a_cred;
1374 pid_t pid = curthread->td_proc->p_pid;
1376 if (fuse_isdeadfs(vp)) {
1380 if (VTOFUD(vp)->flag & FN_DIRECTIO) {
1381 ioflag |= IO_DIRECT;
1384 return fuse_io_dispatch(vp, uio, ioflag, false, cred, pid);
1388 struct vnop_readdir_args {
1391 struct ucred *a_cred;
1398 fuse_vnop_readdir(struct vop_readdir_args *ap)
1400 struct vnode *vp = ap->a_vp;
1401 struct uio *uio = ap->a_uio;
1402 struct ucred *cred = ap->a_cred;
1403 struct fuse_filehandle *fufh = NULL;
1404 struct fuse_iov cookediov;
1410 bool closefufh = false;
1411 pid_t pid = curthread->td_proc->p_pid;
1415 if (fuse_isdeadfs(vp)) {
1418 if ( /* XXXIP ((uio_iovcnt(uio) > 1)) || */
1419 (uio_resid(uio) < sizeof(struct dirent))) {
1423 tresid = uio->uio_resid;
1424 startoff = uio->uio_offset;
1425 err = fuse_filehandle_get_dir(vp, &fufh, cred, pid);
1426 if (err == EBADF && vnode_mount(vp)->mnt_flag & MNT_EXPORTED) {
1428 * nfsd will do VOP_READDIR without first doing VOP_OPEN. We
1429 * must implicitly open the directory here
1431 err = fuse_filehandle_open(vp, FREAD, &fufh, curthread, cred);
1434 * When a directory is opened, it must be read from
1435 * the beginning. Hopefully, the "startoff" still
1436 * exists as an offset cookie for the directory.
1437 * If not, it will read the entire directory without
1438 * returning any entries and just return eof.
1440 uio->uio_offset = 0;
1446 if (ap->a_ncookies != NULL) {
1447 ncookies = uio->uio_resid /
1448 (offsetof(struct dirent, d_name) + 4) + 1;
1449 cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
1450 *ap->a_ncookies = ncookies;
1451 *ap->a_cookies = cookies;
1456 #define DIRCOOKEDSIZE FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + MAXNAMLEN + 1)
1457 fiov_init(&cookediov, DIRCOOKEDSIZE);
1459 err = fuse_internal_readdir(vp, uio, startoff, fufh, &cookediov,
1460 &ncookies, cookies);
1462 fiov_teardown(&cookediov);
1464 fuse_filehandle_close(vp, fufh, curthread, cred);
1466 if (ap->a_ncookies != NULL) {
1468 *ap->a_ncookies -= ncookies;
1470 free(*ap->a_cookies, M_TEMP);
1471 *ap->a_ncookies = 0;
1472 *ap->a_cookies = NULL;
1475 if (err == 0 && tresid == uio->uio_resid)
1482 struct vnop_readlink_args {
1485 struct ucred *a_cred;
1489 fuse_vnop_readlink(struct vop_readlink_args *ap)
1491 struct vnode *vp = ap->a_vp;
1492 struct uio *uio = ap->a_uio;
1493 struct ucred *cred = ap->a_cred;
1495 struct fuse_dispatcher fdi;
1498 if (fuse_isdeadfs(vp)) {
1501 if (!vnode_islnk(vp)) {
1504 fdisp_init(&fdi, 0);
1505 err = fdisp_simple_putget_vp(&fdi, FUSE_READLINK, vp, curthread, cred);
1509 if (((char *)fdi.answ)[0] == '/' &&
1510 fuse_get_mpdata(vnode_mount(vp))->dataflags & FSESS_PUSH_SYMLINKS_IN) {
1511 char *mpth = vnode_mount(vp)->mnt_stat.f_mntonname;
1513 err = uiomove(mpth, strlen(mpth), uio);
1516 err = uiomove(fdi.answ, fdi.iosize, uio);
1519 fdisp_destroy(&fdi);
1524 struct vnop_reclaim_args {
1526 struct thread *a_td;
1530 fuse_vnop_reclaim(struct vop_reclaim_args *ap)
1532 struct vnode *vp = ap->a_vp;
1533 struct thread *td = ap->a_td;
1534 struct fuse_vnode_data *fvdat = VTOFUD(vp);
1535 struct fuse_filehandle *fufh, *fufh_tmp;
1538 panic("FUSE: no vnode data during recycling");
1540 LIST_FOREACH_SAFE(fufh, &fvdat->handles, next, fufh_tmp) {
1541 printf("FUSE: vnode being reclaimed with open fufh "
1542 "(type=%#x)", fufh->fufh_type);
1543 fuse_filehandle_close(vp, fufh, td, NULL);
1546 if ((!fuse_isdeadfs(vp)) && (fvdat->nlookup)) {
1547 fuse_internal_forget_send(vnode_mount(vp), td, NULL, VTOI(vp),
1550 fuse_vnode_setparent(vp, NULL);
1552 vfs_hash_remove(vp);
1553 vnode_destroy_vobject(vp);
1554 fuse_vnode_destroy(vp);
1560 struct vnop_remove_args {
1561 struct vnode *a_dvp;
1563 struct componentname *a_cnp;
1567 fuse_vnop_remove(struct vop_remove_args *ap)
1569 struct vnode *dvp = ap->a_dvp;
1570 struct vnode *vp = ap->a_vp;
1571 struct componentname *cnp = ap->a_cnp;
1575 if (fuse_isdeadfs(vp)) {
1578 if (vnode_isdir(vp)) {
1583 err = fuse_internal_remove(dvp, vp, cnp, FUSE_UNLINK);
1586 fuse_internal_vnode_disappear(vp);
1588 * Purge the parent's attribute cache because the daemon
1589 * should've updated its mtime and ctime
1591 fuse_vnode_clear_attr_cache(dvp);
1597 struct vnop_rename_args {
1598 struct vnode *a_fdvp;
1599 struct vnode *a_fvp;
1600 struct componentname *a_fcnp;
1601 struct vnode *a_tdvp;
1602 struct vnode *a_tvp;
1603 struct componentname *a_tcnp;
1607 fuse_vnop_rename(struct vop_rename_args *ap)
1609 struct vnode *fdvp = ap->a_fdvp;
1610 struct vnode *fvp = ap->a_fvp;
1611 struct componentname *fcnp = ap->a_fcnp;
1612 struct vnode *tdvp = ap->a_tdvp;
1613 struct vnode *tvp = ap->a_tvp;
1614 struct componentname *tcnp = ap->a_tcnp;
1615 struct fuse_data *data;
1616 bool newparent = fdvp != tdvp;
1617 bool isdir = fvp->v_type == VDIR;
1620 if (fuse_isdeadfs(fdvp)) {
1623 if (fvp->v_mount != tdvp->v_mount ||
1624 (tvp && fvp->v_mount != tvp->v_mount)) {
1625 SDT_PROBE2(fusefs, , vnops, trace, 1, "cross-device rename");
1632 * FUSE library is expected to check if target directory is not
1633 * under the source directory in the file system tree.
1634 * Linux performs this check at VFS level.
1637 * If source is a directory, and it will get a new parent, user must
1638 * have write permission to it, so ".." can be modified.
1640 data = fuse_get_mpdata(vnode_mount(tdvp));
1641 if (data->dataflags & FSESS_DEFAULT_PERMISSIONS && isdir && newparent) {
1642 err = fuse_internal_access(fvp, VWRITE,
1643 tcnp->cn_thread, tcnp->cn_cred);
1647 sx_xlock(&data->rename_lock);
1648 err = fuse_internal_rename(fdvp, fcnp, tdvp, tcnp);
1651 fuse_vnode_setparent(fvp, tdvp);
1653 fuse_vnode_setparent(tvp, NULL);
1655 sx_unlock(&data->rename_lock);
1657 if (tvp != NULL && tvp != fvp) {
1660 if (vnode_isdir(fvp)) {
1661 if ((tvp != NULL) && vnode_isdir(tvp)) {
1682 struct vnop_rmdir_args {
1683 struct vnode *a_dvp;
1685 struct componentname *a_cnp;
1689 fuse_vnop_rmdir(struct vop_rmdir_args *ap)
1691 struct vnode *dvp = ap->a_dvp;
1692 struct vnode *vp = ap->a_vp;
1696 if (fuse_isdeadfs(vp)) {
1699 if (VTOFUD(vp) == VTOFUD(dvp)) {
1702 err = fuse_internal_remove(dvp, vp, ap->a_cnp, FUSE_RMDIR);
1705 fuse_internal_vnode_disappear(vp);
1707 * Purge the parent's attribute cache because the daemon
1708 * should've updated its mtime and ctime
1710 fuse_vnode_clear_attr_cache(dvp);
1716 struct vnop_setattr_args {
1718 struct vattr *a_vap;
1719 struct ucred *a_cred;
1720 struct thread *a_td;
1724 fuse_vnop_setattr(struct vop_setattr_args *ap)
1726 struct vnode *vp = ap->a_vp;
1727 struct vattr *vap = ap->a_vap;
1728 struct ucred *cred = ap->a_cred;
1729 struct thread *td = curthread;
1731 struct fuse_data *data;
1732 struct vattr old_va;
1735 accmode_t accmode = 0;
1737 bool drop_suid = false;
1740 mp = vnode_mount(vp);
1741 data = fuse_get_mpdata(mp);
1742 dataflags = data->dataflags;
1743 checkperm = dataflags & FSESS_DEFAULT_PERMISSIONS;
1744 if (cred->cr_ngroups > 0)
1745 cr_gid = cred->cr_groups[0];
1749 if (fuse_isdeadfs(vp)) {
1753 if (vap->va_uid != (uid_t)VNOVAL) {
1755 /* Only root may change a file's owner */
1756 err = priv_check_cred(cred, PRIV_VFS_CHOWN);
1758 /* As a special case, allow the null chown */
1759 err2 = fuse_internal_getattr(vp, &old_va, cred,
1763 if (vap->va_uid != old_va.va_uid)
1773 if (vap->va_gid != (gid_t)VNOVAL) {
1774 if (checkperm && priv_check_cred(cred, PRIV_VFS_CHOWN))
1776 if (checkperm && !groupmember(vap->va_gid, cred))
1779 * Non-root users may only chgrp to one of their own
1782 err = priv_check_cred(cred, PRIV_VFS_CHOWN);
1784 /* As a special case, allow the null chgrp */
1785 err2 = fuse_internal_getattr(vp, &old_va, cred,
1789 if (vap->va_gid != old_va.va_gid)
1797 if (vap->va_size != VNOVAL) {
1798 switch (vp->v_type) {
1803 if (vfs_isrdonly(mp))
1808 * According to POSIX, the result is unspecified
1809 * for file types other than regular files,
1810 * directories and shared memory objects. We
1811 * don't support shared memory objects in the file
1812 * system, and have dubious support for truncating
1813 * symlinks. Just ignore the request in other cases.
1817 /* Don't set accmode. Permission to trunc is checked upstack */
1819 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
1820 if (vap->va_vaflags & VA_UTIMES_NULL)
1826 if (vap->va_mode != (mode_t)VNOVAL)
1827 vap->va_mode &= ~(S_ISUID | S_ISGID);
1829 err = fuse_internal_getattr(vp, &old_va, cred, td);
1832 vap->va_mode = old_va.va_mode & ~(S_ISUID | S_ISGID);
1835 if (vap->va_mode != (mode_t)VNOVAL) {
1836 /* Only root may set the sticky bit on non-directories */
1837 if (checkperm && vp->v_type != VDIR && (vap->va_mode & S_ISTXT)
1838 && priv_check_cred(cred, PRIV_VFS_STICKYFILE))
1840 if (checkperm && (vap->va_mode & S_ISGID)) {
1841 err = fuse_internal_getattr(vp, &old_va, cred, td);
1844 if (!groupmember(old_va.va_gid, cred)) {
1845 err = priv_check_cred(cred, PRIV_VFS_SETGID);
1853 if (vfs_isrdonly(mp))
1856 err = fuse_internal_access(vp, accmode, td, cred);
1860 return fuse_internal_setattr(vp, vap, td, cred);
1864 struct vnop_strategy_args {
1870 fuse_vnop_strategy(struct vop_strategy_args *ap)
1872 struct vnode *vp = ap->a_vp;
1873 struct buf *bp = ap->a_bp;
1875 if (!vp || fuse_isdeadfs(vp)) {
1876 bp->b_ioflags |= BIO_ERROR;
1877 bp->b_error = ENXIO;
1883 * VOP_STRATEGY always returns zero and signals error via bp->b_ioflags.
1884 * fuse_io_strategy sets bp's error fields
1886 (void)fuse_io_strategy(vp, bp);
1893 struct vnop_symlink_args {
1894 struct vnode *a_dvp;
1895 struct vnode **a_vpp;
1896 struct componentname *a_cnp;
1897 struct vattr *a_vap;
1902 fuse_vnop_symlink(struct vop_symlink_args *ap)
1904 struct vnode *dvp = ap->a_dvp;
1905 struct vnode **vpp = ap->a_vpp;
1906 struct componentname *cnp = ap->a_cnp;
1907 const char *target = ap->a_target;
1909 struct fuse_dispatcher fdi;
1914 if (fuse_isdeadfs(dvp)) {
1918 * Unlike the other creator type calls, here we have to create a message
1919 * where the name of the new entry comes first, and the data describing
1920 * the entry comes second.
1921 * Hence we can't rely on our handy fuse_internal_newentry() routine,
1922 * but put together the message manually and just call the core part.
1925 len = strlen(target) + 1;
1926 fdisp_init(&fdi, len + cnp->cn_namelen + 1);
1927 fdisp_make_vp(&fdi, FUSE_SYMLINK, dvp, curthread, NULL);
1929 memcpy(fdi.indata, cnp->cn_nameptr, cnp->cn_namelen);
1930 ((char *)fdi.indata)[cnp->cn_namelen] = '\0';
1931 memcpy((char *)fdi.indata + cnp->cn_namelen + 1, target, len);
1933 err = fuse_internal_newentry_core(dvp, vpp, cnp, VLNK, &fdi);
1934 fdisp_destroy(&fdi);
1939 struct vnop_write_args {
1943 struct ucred *a_cred;
1947 fuse_vnop_write(struct vop_write_args *ap)
1949 struct vnode *vp = ap->a_vp;
1950 struct uio *uio = ap->a_uio;
1951 int ioflag = ap->a_ioflag;
1952 struct ucred *cred = ap->a_cred;
1953 pid_t pid = curthread->td_proc->p_pid;
1955 if (fuse_isdeadfs(vp)) {
1959 if (VTOFUD(vp)->flag & FN_DIRECTIO) {
1960 ioflag |= IO_DIRECT;
1963 return fuse_io_dispatch(vp, uio, ioflag, false, cred, pid);
1966 SDT_PROBE_DEFINE1(fusefs, , vnops, vnop_getpages_error, "int");
1968 struct vnop_getpages_args {
1976 fuse_vnop_getpages(struct vop_getpages_args *ap)
1978 int i, error, nextoff, size, toff, count, npages;
1987 pid_t pid = curthread->td_proc->p_pid;
1990 KASSERT(vp->v_object, ("objectless vp passed to getpages"));
1991 td = curthread; /* XXX */
1992 cred = curthread->td_ucred; /* XXX */
1994 npages = ap->a_count;
1996 if (!fsess_opt_mmap(vnode_mount(vp))) {
1997 SDT_PROBE2(fusefs, , vnops, trace, 1,
1998 "called on non-cacheable vnode??\n");
1999 return (VM_PAGER_ERROR);
2003 * If the last page is partially valid, just return it and allow
2004 * the pager to zero-out the blanks. Partially valid pages can
2005 * only occur at the file EOF.
2007 * XXXGL: is that true for FUSE, which is a local filesystem,
2008 * but still somewhat disconnected from the kernel?
2010 VM_OBJECT_WLOCK(vp->v_object);
2011 if (pages[npages - 1]->valid != 0 && --npages == 0)
2013 VM_OBJECT_WUNLOCK(vp->v_object);
2016 * We use only the kva address for the buffer, but this is extremely
2017 * convenient and fast.
2019 bp = uma_zalloc(fuse_pbuf_zone, M_WAITOK);
2021 kva = (vm_offset_t)bp->b_data;
2022 pmap_qenter(kva, pages, npages);
2023 VM_CNT_INC(v_vnodein);
2024 VM_CNT_ADD(v_vnodepgsin, npages);
2026 count = npages << PAGE_SHIFT;
2027 iov.iov_base = (caddr_t)kva;
2028 iov.iov_len = count;
2031 uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
2032 uio.uio_resid = count;
2033 uio.uio_segflg = UIO_SYSSPACE;
2034 uio.uio_rw = UIO_READ;
2037 error = fuse_io_dispatch(vp, &uio, IO_DIRECT, true, cred, pid);
2038 pmap_qremove(kva, npages);
2040 uma_zfree(fuse_pbuf_zone, bp);
2042 if (error && (uio.uio_resid == count)) {
2043 SDT_PROBE1(fusefs, , vnops, vnop_getpages_error, error);
2044 return VM_PAGER_ERROR;
2047 * Calculate the number of bytes read and validate only that number
2048 * of bytes. Note that due to pending writes, size may be 0. This
2049 * does not mean that the remaining data is invalid!
2052 size = count - uio.uio_resid;
2053 VM_OBJECT_WLOCK(vp->v_object);
2054 fuse_vm_page_lock_queues();
2055 for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
2058 nextoff = toff + PAGE_SIZE;
2061 if (nextoff <= size) {
2063 * Read operation filled an entire page
2065 m->valid = VM_PAGE_BITS_ALL;
2066 KASSERT(m->dirty == 0,
2067 ("fuse_getpages: page %p is dirty", m));
2068 } else if (size > toff) {
2070 * Read operation filled a partial page.
2073 vm_page_set_valid_range(m, 0, size - toff);
2074 KASSERT(m->dirty == 0,
2075 ("fuse_getpages: page %p is dirty", m));
2078 * Read operation was short. If no error occurred
2079 * we may have hit a zero-fill section. We simply
2080 * leave valid set to 0.
2085 fuse_vm_page_unlock_queues();
2087 VM_OBJECT_WUNLOCK(vp->v_object);
2092 return (VM_PAGER_OK);
2096 struct vnop_putpages_args {
2102 vm_ooffset_t a_offset;
2106 fuse_vnop_putpages(struct vop_putpages_args *ap)
2112 int i, error, npages, count;
2120 pid_t pid = curthread->td_proc->p_pid;
2123 KASSERT(vp->v_object, ("objectless vp passed to putpages"));
2124 fsize = vp->v_object->un_pager.vnp.vnp_size;
2125 td = curthread; /* XXX */
2126 cred = curthread->td_ucred; /* XXX */
2128 count = ap->a_count;
2129 rtvals = ap->a_rtvals;
2130 npages = btoc(count);
2131 offset = IDX_TO_OFF(pages[0]->pindex);
2133 if (!fsess_opt_mmap(vnode_mount(vp))) {
2134 SDT_PROBE2(fusefs, , vnops, trace, 1,
2135 "called on non-cacheable vnode??\n");
2137 for (i = 0; i < npages; i++)
2138 rtvals[i] = VM_PAGER_AGAIN;
2141 * When putting pages, do not extend file past EOF.
2144 if (offset + count > fsize) {
2145 count = fsize - offset;
2150 * We use only the kva address for the buffer, but this is extremely
2151 * convenient and fast.
2153 bp = uma_zalloc(fuse_pbuf_zone, M_WAITOK);
2155 kva = (vm_offset_t)bp->b_data;
2156 pmap_qenter(kva, pages, npages);
2157 VM_CNT_INC(v_vnodeout);
2158 VM_CNT_ADD(v_vnodepgsout, count);
2160 iov.iov_base = (caddr_t)kva;
2161 iov.iov_len = count;
2164 uio.uio_offset = offset;
2165 uio.uio_resid = count;
2166 uio.uio_segflg = UIO_SYSSPACE;
2167 uio.uio_rw = UIO_WRITE;
2170 error = fuse_io_dispatch(vp, &uio, IO_DIRECT, true, cred, pid);
2172 pmap_qremove(kva, npages);
2173 uma_zfree(fuse_pbuf_zone, bp);
2176 int nwritten = round_page(count - uio.uio_resid) / PAGE_SIZE;
2178 for (i = 0; i < nwritten; i++) {
2179 rtvals[i] = VM_PAGER_OK;
2180 VM_OBJECT_WLOCK(pages[i]->object);
2181 vm_page_undirty(pages[i]);
2182 VM_OBJECT_WUNLOCK(pages[i]->object);
2188 static const char extattr_namespace_separator = '.';
2191 struct vop_getextattr_args {
2192 struct vop_generic_args a_gen;
2194 int a_attrnamespace;
2198 struct ucred *a_cred;
2199 struct thread *a_td;
2203 fuse_vnop_getextattr(struct vop_getextattr_args *ap)
2205 struct vnode *vp = ap->a_vp;
2206 struct uio *uio = ap->a_uio;
2207 struct fuse_dispatcher fdi;
2208 struct fuse_getxattr_in *get_xattr_in;
2209 struct fuse_getxattr_out *get_xattr_out;
2210 struct mount *mp = vnode_mount(vp);
2211 struct thread *td = ap->a_td;
2212 struct ucred *cred = ap->a_cred;
2218 if (fuse_isdeadfs(vp))
2221 if (!fsess_isimpl(mp, FUSE_GETXATTR))
2224 err = fuse_extattr_check_cred(vp, ap->a_attrnamespace, cred, td, VREAD);
2228 /* Default to looking for user attributes. */
2229 if (ap->a_attrnamespace == EXTATTR_NAMESPACE_SYSTEM)
2230 prefix = EXTATTR_NAMESPACE_SYSTEM_STRING;
2232 prefix = EXTATTR_NAMESPACE_USER_STRING;
2234 len = strlen(prefix) + sizeof(extattr_namespace_separator) +
2235 strlen(ap->a_name) + 1;
2237 fdisp_init(&fdi, len + sizeof(*get_xattr_in));
2238 fdisp_make_vp(&fdi, FUSE_GETXATTR, vp, td, cred);
2240 get_xattr_in = fdi.indata;
2242 * Check to see whether we're querying the available size or
2243 * issuing the actual request. If we pass in 0, we get back struct
2244 * fuse_getxattr_out. If we pass in a non-zero size, we get back
2245 * that much data, without the struct fuse_getxattr_out header.
2248 get_xattr_in->size = 0;
2250 get_xattr_in->size = uio->uio_resid;
2252 attr_str = (char *)fdi.indata + sizeof(*get_xattr_in);
2253 snprintf(attr_str, len, "%s%c%s", prefix, extattr_namespace_separator,
2256 err = fdisp_wait_answ(&fdi);
2258 if (err == ENOSYS) {
2259 fsess_set_notimpl(mp, FUSE_GETXATTR);
2265 get_xattr_out = fdi.answ;
2267 if (ap->a_size != NULL)
2268 *ap->a_size = get_xattr_out->size;
2271 err = uiomove(fdi.answ, fdi.iosize, uio);
2274 fdisp_destroy(&fdi);
2279 struct vop_setextattr_args {
2280 struct vop_generic_args a_gen;
2282 int a_attrnamespace;
2285 struct ucred *a_cred;
2286 struct thread *a_td;
2290 fuse_vnop_setextattr(struct vop_setextattr_args *ap)
2292 struct vnode *vp = ap->a_vp;
2293 struct uio *uio = ap->a_uio;
2294 struct fuse_dispatcher fdi;
2295 struct fuse_setxattr_in *set_xattr_in;
2296 struct mount *mp = vnode_mount(vp);
2297 struct thread *td = ap->a_td;
2298 struct ucred *cred = ap->a_cred;
2304 if (fuse_isdeadfs(vp))
2307 if (!fsess_isimpl(mp, FUSE_SETXATTR))
2310 if (vfs_isrdonly(mp))
2313 /* Deleting xattrs must use VOP_DELETEEXTATTR instead */
2314 if (ap->a_uio == NULL) {
2316 * If we got here as fallback from VOP_DELETEEXTATTR, then
2317 * return EOPNOTSUPP.
2319 if (!fsess_isimpl(mp, FUSE_REMOVEXATTR))
2320 return (EOPNOTSUPP);
2325 err = fuse_extattr_check_cred(vp, ap->a_attrnamespace, cred, td,
2330 /* Default to looking for user attributes. */
2331 if (ap->a_attrnamespace == EXTATTR_NAMESPACE_SYSTEM)
2332 prefix = EXTATTR_NAMESPACE_SYSTEM_STRING;
2334 prefix = EXTATTR_NAMESPACE_USER_STRING;
2336 len = strlen(prefix) + sizeof(extattr_namespace_separator) +
2337 strlen(ap->a_name) + 1;
2339 fdisp_init(&fdi, len + sizeof(*set_xattr_in) + uio->uio_resid);
2340 fdisp_make_vp(&fdi, FUSE_SETXATTR, vp, td, cred);
2342 set_xattr_in = fdi.indata;
2343 set_xattr_in->size = uio->uio_resid;
2345 attr_str = (char *)fdi.indata + sizeof(*set_xattr_in);
2346 snprintf(attr_str, len, "%s%c%s", prefix, extattr_namespace_separator,
2349 err = uiomove((char *)fdi.indata + sizeof(*set_xattr_in) + len,
2350 uio->uio_resid, uio);
2355 err = fdisp_wait_answ(&fdi);
2357 if (err == ENOSYS) {
2358 fsess_set_notimpl(mp, FUSE_SETXATTR);
2361 if (err == ERESTART) {
2362 /* Can't restart after calling uiomove */
2367 fdisp_destroy(&fdi);
2372 * The Linux / FUSE extended attribute list is simply a collection of
2373 * NUL-terminated strings. The FreeBSD extended attribute list is a single
2374 * byte length followed by a non-NUL terminated string. So, this allows
2375 * conversion of the Linux / FUSE format to the FreeBSD format in place.
2376 * Linux attribute names are reported with the namespace as a prefix (e.g.
2377 * "user.attribute_name"), but in FreeBSD they are reported without the
2378 * namespace prefix (e.g. "attribute_name"). So, we're going from:
2380 * user.attr_name1\0user.attr_name2\0
2384 * <num>attr_name1<num>attr_name2
2386 * Where "<num>" is a single byte number of characters in the attribute name.
2389 * prefix - exattr namespace prefix string
2390 * list, list_len - input list with namespace prefixes
2391 * bsd_list, bsd_list_len - output list compatible with bsd vfs
2394 fuse_xattrlist_convert(char *prefix, const char *list, int list_len,
2395 char *bsd_list, int *bsd_list_len)
2397 int len, pos, dist_to_next, prefix_len;
2401 prefix_len = strlen(prefix);
2403 while (pos < list_len && list[pos] != '\0') {
2404 dist_to_next = strlen(&list[pos]) + 1;
2405 if (bcmp(&list[pos], prefix, prefix_len) == 0 &&
2406 list[pos + prefix_len] == extattr_namespace_separator) {
2407 len = dist_to_next -
2408 (prefix_len + sizeof(extattr_namespace_separator)) - 1;
2409 if (len >= EXTATTR_MAXNAMELEN)
2410 return (ENAMETOOLONG);
2412 bsd_list[*bsd_list_len] = len;
2413 memcpy(&bsd_list[*bsd_list_len + 1],
2414 &list[pos + prefix_len +
2415 sizeof(extattr_namespace_separator)], len);
2417 *bsd_list_len += len + 1;
2420 pos += dist_to_next;
2427 struct vop_listextattr_args {
2428 struct vop_generic_args a_gen;
2430 int a_attrnamespace;
2433 struct ucred *a_cred;
2434 struct thread *a_td;
2438 fuse_vnop_listextattr(struct vop_listextattr_args *ap)
2440 struct vnode *vp = ap->a_vp;
2441 struct uio *uio = ap->a_uio;
2442 struct fuse_dispatcher fdi;
2443 struct fuse_listxattr_in *list_xattr_in;
2444 struct fuse_listxattr_out *list_xattr_out;
2445 struct mount *mp = vnode_mount(vp);
2446 struct thread *td = ap->a_td;
2447 struct ucred *cred = ap->a_cred;
2451 char *bsd_list = NULL;
2457 if (fuse_isdeadfs(vp))
2460 if (!fsess_isimpl(mp, FUSE_LISTXATTR))
2463 err = fuse_extattr_check_cred(vp, ap->a_attrnamespace, cred, td, VREAD);
2468 * Add space for a NUL and the period separator if enabled.
2469 * Default to looking for user attributes.
2471 if (ap->a_attrnamespace == EXTATTR_NAMESPACE_SYSTEM)
2472 prefix = EXTATTR_NAMESPACE_SYSTEM_STRING;
2474 prefix = EXTATTR_NAMESPACE_USER_STRING;
2476 len = strlen(prefix) + sizeof(extattr_namespace_separator) + 1;
2478 fdisp_init(&fdi, sizeof(*list_xattr_in) + len);
2479 fdisp_make_vp(&fdi, FUSE_LISTXATTR, vp, td, cred);
2482 * Retrieve Linux / FUSE compatible list size.
2484 list_xattr_in = fdi.indata;
2485 list_xattr_in->size = 0;
2486 attr_str = (char *)fdi.indata + sizeof(*list_xattr_in);
2487 snprintf(attr_str, len, "%s%c", prefix, extattr_namespace_separator);
2489 err = fdisp_wait_answ(&fdi);
2491 if (err == ENOSYS) {
2492 fsess_set_notimpl(mp, FUSE_LISTXATTR);
2498 list_xattr_out = fdi.answ;
2499 linux_list_len = list_xattr_out->size;
2500 if (linux_list_len == 0) {
2501 if (ap->a_size != NULL)
2502 *ap->a_size = linux_list_len;
2507 * Retrieve Linux / FUSE compatible list values.
2509 fdisp_refresh_vp(&fdi, FUSE_LISTXATTR, vp, td, cred);
2510 list_xattr_in = fdi.indata;
2511 list_xattr_in->size = linux_list_len + sizeof(*list_xattr_out);
2512 attr_str = (char *)fdi.indata + sizeof(*list_xattr_in);
2513 snprintf(attr_str, len, "%s%c", prefix, extattr_namespace_separator);
2515 err = fdisp_wait_answ(&fdi);
2519 linux_list = fdi.answ;
2520 linux_list_len = fdi.iosize;
2523 * Retrieve the BSD compatible list values.
2524 * The Linux / FUSE attribute list format isn't the same
2525 * as FreeBSD's format. So we need to transform it into
2526 * FreeBSD's format before giving it to the user.
2528 bsd_list = malloc(linux_list_len, M_TEMP, M_WAITOK);
2529 err = fuse_xattrlist_convert(prefix, linux_list, linux_list_len,
2530 bsd_list, &bsd_list_len);
2534 if (ap->a_size != NULL)
2535 *ap->a_size = bsd_list_len;
2538 err = uiomove(bsd_list, bsd_list_len, uio);
2541 free(bsd_list, M_TEMP);
2542 fdisp_destroy(&fdi);
2547 struct vop_deleteextattr_args {
2548 struct vop_generic_args a_gen;
2550 int a_attrnamespace;
2552 struct ucred *a_cred;
2553 struct thread *a_td;
2557 fuse_vnop_deleteextattr(struct vop_deleteextattr_args *ap)
2559 struct vnode *vp = ap->a_vp;
2560 struct fuse_dispatcher fdi;
2561 struct mount *mp = vnode_mount(vp);
2562 struct thread *td = ap->a_td;
2563 struct ucred *cred = ap->a_cred;
2569 if (fuse_isdeadfs(vp))
2572 if (!fsess_isimpl(mp, FUSE_REMOVEXATTR))
2575 if (vfs_isrdonly(mp))
2578 err = fuse_extattr_check_cred(vp, ap->a_attrnamespace, cred, td,
2583 /* Default to looking for user attributes. */
2584 if (ap->a_attrnamespace == EXTATTR_NAMESPACE_SYSTEM)
2585 prefix = EXTATTR_NAMESPACE_SYSTEM_STRING;
2587 prefix = EXTATTR_NAMESPACE_USER_STRING;
2589 len = strlen(prefix) + sizeof(extattr_namespace_separator) +
2590 strlen(ap->a_name) + 1;
2592 fdisp_init(&fdi, len);
2593 fdisp_make_vp(&fdi, FUSE_REMOVEXATTR, vp, td, cred);
2595 attr_str = fdi.indata;
2596 snprintf(attr_str, len, "%s%c%s", prefix, extattr_namespace_separator,
2599 err = fdisp_wait_answ(&fdi);
2600 if (err == ENOSYS) {
2601 fsess_set_notimpl(mp, FUSE_REMOVEXATTR);
2605 fdisp_destroy(&fdi);
2610 struct vnop_print_args {
2615 fuse_vnop_print(struct vop_print_args *ap)
2617 struct fuse_vnode_data *fvdat = VTOFUD(ap->a_vp);
2619 printf("nodeid: %ju, parent nodeid: %ju, nlookup: %ju, flag: %#x\n",
2620 (uintmax_t)VTOILLU(ap->a_vp), (uintmax_t)fvdat->parent_nid,
2621 (uintmax_t)fvdat->nlookup,
2628 * Get an NFS filehandle for a FUSE file.
2630 * This will only work for FUSE file systems that guarantee the uniqueness of
2631 * nodeid:generation, which most don't.
2635 IN struct vnode *a_vp;
2636 IN struct fid *a_fhp;
2640 fuse_vnop_vptofh(struct vop_vptofh_args *ap)
2642 struct vnode *vp = ap->a_vp;
2643 struct fuse_vnode_data *fvdat = VTOFUD(vp);
2644 struct fuse_fid *fhp = (struct fuse_fid *)(ap->a_fhp);
2645 _Static_assert(sizeof(struct fuse_fid) <= sizeof(struct fid),
2646 "FUSE fid type is too big");
2647 struct mount *mp = vnode_mount(vp);
2648 struct fuse_data *data = fuse_get_mpdata(mp);
2652 if (!(data->dataflags & FSESS_EXPORT_SUPPORT))
2655 err = fuse_internal_getattr(vp, &va, curthread->td_ucred, curthread);
2659 /*ip = VTOI(ap->a_vp);*/
2660 /*ufhp = (struct ufid *)ap->a_fhp;*/
2661 fhp->len = sizeof(struct fuse_fid);
2662 fhp->nid = fvdat->nid;
2663 if (fvdat->generation <= UINT32_MAX)
2664 fhp->gen = fvdat->generation;