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 * Copyright (c) 2019 The FreeBSD Foundation
38 * Portions of this software were developed by BFF Storage Systems, LLC under
39 * sponsorship from the FreeBSD Foundation.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
50 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 #include <sys/cdefs.h>
64 __FBSDID("$FreeBSD$");
66 #include <sys/param.h>
67 #include <sys/module.h>
68 #include <sys/systm.h>
69 #include <sys/errno.h>
70 #include <sys/kernel.h>
72 #include <sys/filio.h>
74 #include <sys/malloc.h>
75 #include <sys/queue.h>
76 #include <sys/limits.h>
78 #include <sys/rwlock.h>
81 #include <sys/mount.h>
82 #include <sys/vnode.h>
83 #include <sys/namei.h>
84 #include <sys/extattr.h>
86 #include <sys/unistd.h>
87 #include <sys/filedesc.h>
89 #include <sys/fcntl.h>
90 #include <sys/dirent.h>
93 #include <sys/sysctl.h>
94 #include <sys/vmmeter.h>
97 #include <vm/vm_extern.h>
99 #include <vm/vm_map.h>
100 #include <vm/vm_page.h>
101 #include <vm/vm_param.h>
102 #include <vm/vm_object.h>
103 #include <vm/vm_pager.h>
104 #include <vm/vnode_pager.h>
105 #include <vm/vm_object.h>
108 #include "fuse_file.h"
109 #include "fuse_internal.h"
110 #include "fuse_ipc.h"
111 #include "fuse_node.h"
114 #include <sys/priv.h>
116 /* Maximum number of hardlinks to a single FUSE file */
117 #define FUSE_LINK_MAX UINT32_MAX
119 SDT_PROVIDER_DECLARE(fusefs);
122 * arg0: verbosity. Higher numbers give more verbose messages
123 * arg1: Textual message
125 SDT_PROBE_DEFINE2(fusefs, , vnops, trace, "int", "char*");
128 static vop_access_t fuse_vnop_access;
129 static vop_advlock_t fuse_vnop_advlock;
130 static vop_bmap_t fuse_vnop_bmap;
131 static vop_close_t fuse_fifo_close;
132 static vop_close_t fuse_vnop_close;
133 static vop_copy_file_range_t fuse_vnop_copy_file_range;
134 static vop_create_t fuse_vnop_create;
135 static vop_deleteextattr_t fuse_vnop_deleteextattr;
136 static vop_fdatasync_t fuse_vnop_fdatasync;
137 static vop_fsync_t fuse_vnop_fsync;
138 static vop_getattr_t fuse_vnop_getattr;
139 static vop_getextattr_t fuse_vnop_getextattr;
140 static vop_inactive_t fuse_vnop_inactive;
141 static vop_ioctl_t fuse_vnop_ioctl;
142 static vop_link_t fuse_vnop_link;
143 static vop_listextattr_t fuse_vnop_listextattr;
144 static vop_lookup_t fuse_vnop_lookup;
145 static vop_mkdir_t fuse_vnop_mkdir;
146 static vop_mknod_t fuse_vnop_mknod;
147 static vop_open_t fuse_vnop_open;
148 static vop_pathconf_t fuse_vnop_pathconf;
149 static vop_read_t fuse_vnop_read;
150 static vop_readdir_t fuse_vnop_readdir;
151 static vop_readlink_t fuse_vnop_readlink;
152 static vop_reclaim_t fuse_vnop_reclaim;
153 static vop_remove_t fuse_vnop_remove;
154 static vop_rename_t fuse_vnop_rename;
155 static vop_rmdir_t fuse_vnop_rmdir;
156 static vop_setattr_t fuse_vnop_setattr;
157 static vop_setextattr_t fuse_vnop_setextattr;
158 static vop_strategy_t fuse_vnop_strategy;
159 static vop_symlink_t fuse_vnop_symlink;
160 static vop_write_t fuse_vnop_write;
161 static vop_getpages_t fuse_vnop_getpages;
162 static vop_print_t fuse_vnop_print;
163 static vop_vptofh_t fuse_vnop_vptofh;
165 struct vop_vector fuse_fifoops = {
166 .vop_default = &fifo_specops,
167 .vop_access = fuse_vnop_access,
168 .vop_close = fuse_fifo_close,
169 .vop_fsync = fuse_vnop_fsync,
170 .vop_getattr = fuse_vnop_getattr,
171 .vop_inactive = fuse_vnop_inactive,
172 .vop_pathconf = fuse_vnop_pathconf,
173 .vop_print = fuse_vnop_print,
174 .vop_read = VOP_PANIC,
175 .vop_reclaim = fuse_vnop_reclaim,
176 .vop_setattr = fuse_vnop_setattr,
177 .vop_write = VOP_PANIC,
178 .vop_vptofh = fuse_vnop_vptofh,
180 VFS_VOP_VECTOR_REGISTER(fuse_fifoops);
182 struct vop_vector fuse_vnops = {
183 .vop_allocate = VOP_EINVAL,
184 .vop_default = &default_vnodeops,
185 .vop_access = fuse_vnop_access,
186 .vop_advlock = fuse_vnop_advlock,
187 .vop_bmap = fuse_vnop_bmap,
188 .vop_close = fuse_vnop_close,
189 .vop_copy_file_range = fuse_vnop_copy_file_range,
190 .vop_create = fuse_vnop_create,
191 .vop_deleteextattr = fuse_vnop_deleteextattr,
192 .vop_fsync = fuse_vnop_fsync,
193 .vop_fdatasync = fuse_vnop_fdatasync,
194 .vop_getattr = fuse_vnop_getattr,
195 .vop_getextattr = fuse_vnop_getextattr,
196 .vop_inactive = fuse_vnop_inactive,
197 .vop_ioctl = fuse_vnop_ioctl,
198 .vop_link = fuse_vnop_link,
199 .vop_listextattr = fuse_vnop_listextattr,
200 .vop_lookup = fuse_vnop_lookup,
201 .vop_mkdir = fuse_vnop_mkdir,
202 .vop_mknod = fuse_vnop_mknod,
203 .vop_open = fuse_vnop_open,
204 .vop_pathconf = fuse_vnop_pathconf,
206 * TODO: implement vop_poll after upgrading to protocol 7.21.
207 * FUSE_POLL was added in protocol 7.11, but it's kind of broken until
208 * 7.21, which adds the ability for the client to choose which poll
209 * events it wants, and for a client to deregister a file handle
211 .vop_read = fuse_vnop_read,
212 .vop_readdir = fuse_vnop_readdir,
213 .vop_readlink = fuse_vnop_readlink,
214 .vop_reclaim = fuse_vnop_reclaim,
215 .vop_remove = fuse_vnop_remove,
216 .vop_rename = fuse_vnop_rename,
217 .vop_rmdir = fuse_vnop_rmdir,
218 .vop_setattr = fuse_vnop_setattr,
219 .vop_setextattr = fuse_vnop_setextattr,
220 .vop_strategy = fuse_vnop_strategy,
221 .vop_symlink = fuse_vnop_symlink,
222 .vop_write = fuse_vnop_write,
223 .vop_getpages = fuse_vnop_getpages,
224 .vop_print = fuse_vnop_print,
225 .vop_vptofh = fuse_vnop_vptofh,
227 VFS_VOP_VECTOR_REGISTER(fuse_vnops);
229 uma_zone_t fuse_pbuf_zone;
231 /* Check permission for extattr operations, much like extattr_check_cred */
233 fuse_extattr_check_cred(struct vnode *vp, int ns, struct ucred *cred,
234 struct thread *td, accmode_t accmode)
236 struct mount *mp = vnode_mount(vp);
237 struct fuse_data *data = fuse_get_mpdata(mp);
238 int default_permissions = data->dataflags & FSESS_DEFAULT_PERMISSIONS;
241 * Kernel-invoked always succeeds.
247 * Do not allow privileged processes in jail to directly manipulate
251 case EXTATTR_NAMESPACE_SYSTEM:
252 if (default_permissions) {
253 return (priv_check_cred(cred, PRIV_VFS_EXTATTR_SYSTEM));
256 case EXTATTR_NAMESPACE_USER:
257 if (default_permissions) {
258 return (fuse_internal_access(vp, accmode, td, cred));
266 /* Get a filehandle for a directory */
268 fuse_filehandle_get_dir(struct vnode *vp, struct fuse_filehandle **fufhp,
269 struct ucred *cred, pid_t pid)
271 if (fuse_filehandle_get(vp, FREAD, fufhp, cred, pid) == 0)
273 return fuse_filehandle_get(vp, FEXEC, fufhp, cred, pid);
276 /* Send FUSE_FLUSH for this vnode */
278 fuse_flush(struct vnode *vp, struct ucred *cred, pid_t pid, int fflag)
280 struct fuse_flush_in *ffi;
281 struct fuse_filehandle *fufh;
282 struct fuse_dispatcher fdi;
283 struct thread *td = curthread;
284 struct mount *mp = vnode_mount(vp);
287 if (fsess_not_impl(vnode_mount(vp), FUSE_FLUSH))
290 err = fuse_filehandle_getrw(vp, fflag, &fufh, cred, pid);
294 fdisp_init(&fdi, sizeof(*ffi));
295 fdisp_make_vp(&fdi, FUSE_FLUSH, vp, td, cred);
297 ffi->fh = fufh->fh_id;
299 * If the file has a POSIX lock then we're supposed to set lock_owner.
300 * If not, then lock_owner is undefined. So we may as well always set
303 ffi->lock_owner = td->td_proc->p_pid;
305 err = fdisp_wait_answ(&fdi);
307 fsess_set_notimpl(mp, FUSE_FLUSH);
314 /* Close wrapper for fifos. */
316 fuse_fifo_close(struct vop_close_args *ap)
318 return (fifo_specops.vop_close(ap));
321 /* Send FUSE_LSEEK for this node */
323 fuse_vnop_do_lseek(struct vnode *vp, struct thread *td, struct ucred *cred,
324 pid_t pid, off_t *offp, int whence)
326 struct fuse_dispatcher fdi;
327 struct fuse_filehandle *fufh;
328 struct fuse_lseek_in *flsi;
329 struct fuse_lseek_out *flso;
330 struct mount *mp = vnode_mount(vp);
333 ASSERT_VOP_LOCKED(vp, __func__);
335 err = fuse_filehandle_getrw(vp, FREAD, &fufh, cred, pid);
338 fdisp_init(&fdi, sizeof(*flsi));
339 fdisp_make_vp(&fdi, FUSE_LSEEK, vp, td, cred);
341 flsi->fh = fufh->fh_id;
342 flsi->offset = *offp;
343 flsi->whence = whence;
344 err = fdisp_wait_answ(&fdi);
346 fsess_set_notimpl(mp, FUSE_LSEEK);
347 } else if (err == 0) {
348 fsess_set_impl(mp, FUSE_LSEEK);
350 *offp = flso->offset;
358 struct vnop_access_args {
360 #if VOP_ACCESS_TAKES_ACCMODE_T
365 struct ucred *a_cred;
370 fuse_vnop_access(struct vop_access_args *ap)
372 struct vnode *vp = ap->a_vp;
373 int accmode = ap->a_accmode;
374 struct ucred *cred = ap->a_cred;
376 struct fuse_data *data = fuse_get_mpdata(vnode_mount(vp));
380 if (fuse_isdeadfs(vp)) {
381 if (vnode_isvroot(vp)) {
386 if (!(data->dataflags & FSESS_INITED)) {
387 if (vnode_isvroot(vp)) {
388 if (priv_check_cred(cred, PRIV_VFS_ADMIN) ||
389 (fuse_match_cred(data->daemoncred, cred) == 0)) {
395 if (vnode_islnk(vp)) {
399 err = fuse_internal_access(vp, accmode, ap->a_td, ap->a_cred);
404 * struct vop_advlock_args {
405 * struct vop_generic_args a_gen;
406 * struct vnode *a_vp;
409 * struct flock *a_fl;
414 fuse_vnop_advlock(struct vop_advlock_args *ap)
416 struct vnode *vp = ap->a_vp;
417 struct flock *fl = ap->a_fl;
418 struct thread *td = curthread;
419 struct ucred *cred = td->td_ucred;
420 pid_t pid = td->td_proc->p_pid;
421 struct fuse_filehandle *fufh;
422 struct fuse_dispatcher fdi;
423 struct fuse_lk_in *fli;
424 struct fuse_lk_out *flo;
427 int flags = ap->a_flags;
429 dataflags = fuse_get_mpdata(vnode_mount(vp))->dataflags;
431 if (fuse_isdeadfs(vp)) {
452 if (!(dataflags & FSESS_POSIX_LOCKS))
453 return vop_stdadvlock(ap);
454 /* FUSE doesn't properly support flock until protocol 7.17 */
456 return vop_stdadvlock(ap);
458 vn_lock(vp, LK_SHARED | LK_RETRY);
460 err = fuse_filehandle_get_anyflags(vp, &fufh, cred, pid);
464 fdisp_init(&fdi, sizeof(*fli));
466 fdisp_make_vp(&fdi, op, vp, td, cred);
468 fli->fh = fufh->fh_id;
469 fli->owner = td->td_proc->p_pid;
470 fli->lk.start = fl->l_start;
472 fli->lk.end = fl->l_start + fl->l_len - 1;
474 fli->lk.end = INT64_MAX;
475 fli->lk.type = fl->l_type;
476 fli->lk.pid = td->td_proc->p_pid;
478 err = fdisp_wait_answ(&fdi);
481 if (err == 0 && op == FUSE_GETLK) {
483 fl->l_type = flo->lk.type;
484 fl->l_pid = flo->lk.pid;
485 if (flo->lk.type != F_UNLCK) {
486 fl->l_start = flo->lk.start;
487 if (flo->lk.end == INT64_MAX)
490 fl->l_len = flo->lk.end - flo->lk.start + 1;
491 fl->l_start = flo->lk.start;
503 struct bufobj **a_bop;
509 fuse_vnop_bmap(struct vop_bmap_args *ap)
511 struct vnode *vp = ap->a_vp;
512 struct bufobj **bo = ap->a_bop;
513 struct thread *td = curthread;
515 struct fuse_dispatcher fdi;
516 struct fuse_bmap_in *fbi;
517 struct fuse_bmap_out *fbo;
518 struct fuse_data *data;
521 daddr_t lbn = ap->a_bn;
522 daddr_t *pbn = ap->a_bnp;
523 int *runp = ap->a_runp;
524 int *runb = ap->a_runb;
528 if (fuse_isdeadfs(vp)) {
532 mp = vnode_mount(vp);
533 data = fuse_get_mpdata(mp);
534 biosize = fuse_iosize(vp);
535 maxrun = MIN(vp->v_mount->mnt_iosize_max / biosize - 1,
536 data->max_readahead_blocks);
542 * The FUSE_BMAP operation does not include the runp and runb
543 * variables, so we must guess. Report nonzero contiguous runs so
544 * cluster_read will combine adjacent reads. It's worthwhile to reduce
545 * upcalls even if we don't know the true physical layout of the file.
547 * FUSE file systems may opt out of read clustering in two ways:
548 * * mounting with -onoclusterr
549 * * Setting max_readahead <= maxbcachebuf during FUSE_INIT
552 *runb = MIN(lbn, maxrun);
554 error = fuse_vnode_size(vp, &filesize, td->td_ucred, td);
556 *runp = MIN(MAX(0, filesize / (off_t)biosize - lbn - 1),
562 if (fsess_maybe_impl(mp, FUSE_BMAP)) {
563 fdisp_init(&fdi, sizeof(*fbi));
564 fdisp_make_vp(&fdi, FUSE_BMAP, vp, td, td->td_ucred);
567 fbi->blocksize = biosize;
568 error = fdisp_wait_answ(&fdi);
569 if (error == ENOSYS) {
571 fsess_set_notimpl(mp, FUSE_BMAP);
575 if (error == 0 && pbn != NULL)
582 /* If the daemon doesn't support BMAP, make up a sensible default */
584 *pbn = lbn * btodb(biosize);
589 struct vop_close_args {
592 struct ucred *a_cred;
597 fuse_vnop_close(struct vop_close_args *ap)
599 struct vnode *vp = ap->a_vp;
600 struct ucred *cred = ap->a_cred;
601 int fflag = ap->a_fflag;
602 struct thread *td = ap->a_td;
603 pid_t pid = td->td_proc->p_pid;
606 if (fuse_isdeadfs(vp))
610 if (fflag & IO_NDELAY)
613 err = fuse_flush(vp, cred, pid, fflag);
614 /* TODO: close the file handle, if we're sure it's no longer used */
615 if ((VTOFUD(vp)->flag & FN_SIZECHANGE) != 0) {
616 fuse_vnode_savesize(vp, cred, td->td_proc->p_pid);
622 struct vop_copy_file_range_args {
623 struct vop_generic_args a_gen;
624 struct vnode *a_invp;
626 struct vnode *a_outvp;
629 unsigned int a_flags;
630 struct ucred *a_incred;
631 struct ucred *a_outcred;
632 struct thread *a_fsizetd;
636 fuse_vnop_copy_file_range(struct vop_copy_file_range_args *ap)
638 struct vnode *invp = ap->a_invp;
639 struct vnode *outvp = ap->a_outvp;
640 struct mount *mp = vnode_mount(invp);
641 struct fuse_dispatcher fdi;
642 struct fuse_filehandle *infufh, *outfufh;
643 struct fuse_copy_file_range_in *fcfri;
644 struct ucred *incred = ap->a_incred;
645 struct ucred *outcred = ap->a_outcred;
646 struct fuse_write_out *fwo;
652 if (mp != vnode_mount(outvp))
655 if (incred->cr_uid != outcred->cr_uid)
658 if (incred->cr_groups[0] != outcred->cr_groups[0])
661 if (fsess_not_impl(mp, FUSE_COPY_FILE_RANGE))
664 if (ap->a_fsizetd == NULL)
668 pid = td->td_proc->p_pid;
670 /* Lock both vnodes, avoiding risk of deadlock. */
672 err = vn_lock(outvp, LK_EXCLUSIVE);
676 err = vn_lock(invp, LK_SHARED | LK_NOWAIT);
680 err = vn_lock(invp, LK_SHARED);
688 err = fuse_filehandle_getrw(invp, FREAD, &infufh, incred, pid);
692 err = fuse_filehandle_getrw(outvp, FWRITE, &outfufh, outcred, pid);
697 io.uio_offset = *ap->a_outoffp;
698 io.uio_resid = *ap->a_lenp;
699 err = vn_rlimit_fsize(outvp, &io, ap->a_fsizetd);
704 fdisp_init(&fdi, sizeof(*fcfri));
705 fdisp_make_vp(&fdi, FUSE_COPY_FILE_RANGE, invp, td, incred);
707 fcfri->fh_in = infufh->fh_id;
708 fcfri->off_in = *ap->a_inoffp;
709 fcfri->nodeid_out = VTOI(outvp);
710 fcfri->fh_out = outfufh->fh_id;
711 fcfri->off_out = *ap->a_outoffp;
712 fcfri->len = *ap->a_lenp;
715 err = fdisp_wait_answ(&fdi);
718 *ap->a_lenp = fwo->size;
719 *ap->a_inoffp += fwo->size;
720 *ap->a_outoffp += fwo->size;
721 fuse_internal_clear_suid_on_write(outvp, outcred, td);
731 fsess_set_notimpl(mp, FUSE_COPY_FILE_RANGE);
733 err = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp,
734 ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags,
735 ap->a_incred, ap->a_outcred, ap->a_fsizetd);
742 fdisp_make_mknod_for_fallback(
743 struct fuse_dispatcher *fdip,
744 struct componentname *cnp,
750 enum fuse_opcode *op)
752 struct fuse_mknod_in *fmni;
754 fdisp_init(fdip, sizeof(*fmni) + cnp->cn_namelen + 1);
756 fdisp_make(fdip, *op, vnode_mount(dvp), parentnid, td, cred);
760 memcpy((char *)fdip->indata + sizeof(*fmni), cnp->cn_nameptr,
762 ((char *)fdip->indata)[sizeof(*fmni) + cnp->cn_namelen] = '\0';
765 struct vnop_create_args {
767 struct vnode **a_vpp;
768 struct componentname *a_cnp;
773 fuse_vnop_create(struct vop_create_args *ap)
775 struct vnode *dvp = ap->a_dvp;
776 struct vnode **vpp = ap->a_vpp;
777 struct componentname *cnp = ap->a_cnp;
778 struct vattr *vap = ap->a_vap;
779 struct thread *td = cnp->cn_thread;
780 struct ucred *cred = cnp->cn_cred;
782 struct fuse_data *data;
783 struct fuse_create_in *fci;
784 struct fuse_entry_out *feo;
785 struct fuse_open_out *foo;
786 struct fuse_dispatcher fdi, fdi2;
787 struct fuse_dispatcher *fdip = &fdi;
788 struct fuse_dispatcher *fdip2 = NULL;
792 struct mount *mp = vnode_mount(dvp);
793 data = fuse_get_mpdata(mp);
794 uint64_t parentnid = VTOFUD(dvp)->nid;
795 mode_t mode = MAKEIMODE(vap->va_type, vap->va_mode);
799 if (fuse_isdeadfs(dvp))
802 /* FUSE expects sockets to be created with FUSE_MKNOD */
803 if (vap->va_type == VSOCK)
804 return fuse_internal_mknod(dvp, vpp, cnp, vap);
807 * VOP_CREATE doesn't tell us the open(2) flags, so we guess. Only a
808 * writable mode makes sense, and we might as well include readability
813 bzero(&fdi, sizeof(fdi));
815 if (vap->va_type != VREG)
818 if (fsess_not_impl(mp, FUSE_CREATE) || vap->va_type == VSOCK) {
819 /* Fallback to FUSE_MKNOD/FUSE_OPEN */
820 fdisp_make_mknod_for_fallback(fdip, cnp, dvp, parentnid, td,
823 /* Use FUSE_CREATE */
827 fdisp_init(fdip, sizeof(*fci) + cnp->cn_namelen + 1);
828 fdisp_make(fdip, op, vnode_mount(dvp), parentnid, td, cred);
831 fci->flags = O_CREAT | flags;
832 if (fuse_libabi_geq(data, 7, 12)) {
833 insize = sizeof(*fci);
834 fci->umask = td->td_proc->p_pd->pd_cmask;
836 insize = sizeof(struct fuse_open_in);
839 memcpy((char *)fdip->indata + insize, cnp->cn_nameptr,
841 ((char *)fdip->indata)[insize + cnp->cn_namelen] = '\0';
844 err = fdisp_wait_answ(fdip);
847 if (err == ENOSYS && op == FUSE_CREATE) {
848 fsess_set_notimpl(mp, FUSE_CREATE);
850 fdisp_make_mknod_for_fallback(fdip, cnp, dvp,
851 parentnid, td, cred, mode, &op);
852 err = fdisp_wait_answ(fdip);
860 if ((err = fuse_internal_checkentry(feo, vap->va_type))) {
864 if (op == FUSE_CREATE) {
865 foo = (struct fuse_open_out*)(feo + 1);
867 /* Issue a separate FUSE_OPEN */
868 struct fuse_open_in *foi;
871 fdisp_init(fdip2, sizeof(*foi));
872 fdisp_make(fdip2, FUSE_OPEN, vnode_mount(dvp), feo->nodeid, td,
876 err = fdisp_wait_answ(fdip2);
881 err = fuse_vnode_get(mp, feo, feo->nodeid, dvp, vpp, cnp, vap->va_type);
883 struct fuse_release_in *fri;
884 uint64_t nodeid = feo->nodeid;
885 uint64_t fh_id = foo->fh;
887 fdisp_init(fdip, sizeof(*fri));
888 fdisp_make(fdip, FUSE_RELEASE, mp, nodeid, td, cred);
892 fuse_insert_callback(fdip->tick, fuse_internal_forget_callback);
893 fuse_insert_message(fdip->tick, false);
896 ASSERT_VOP_ELOCKED(*vpp, "fuse_vnop_create");
897 fuse_internal_cache_attrs(*vpp, &feo->attr, feo->attr_valid,
898 feo->attr_valid_nsec, NULL, true);
900 fuse_filehandle_init(*vpp, FUFH_RDWR, NULL, td, cred, foo);
901 fuse_vnode_open(*vpp, foo->open_flags, td);
903 * Purge the parent's attribute cache because the daemon should've
904 * updated its mtime and ctime
906 fuse_vnode_clear_attr_cache(dvp);
907 cache_purge_negative(dvp);
911 fdisp_destroy(fdip2);
917 struct vnop_fdatasync_args {
918 struct vop_generic_args a_gen;
920 struct thread * a_td;
924 fuse_vnop_fdatasync(struct vop_fdatasync_args *ap)
926 struct vnode *vp = ap->a_vp;
927 struct thread *td = ap->a_td;
928 int waitfor = MNT_WAIT;
932 if (fuse_isdeadfs(vp)) {
935 if ((err = vop_stdfdatasync_buf(ap)))
938 return fuse_internal_fsync(vp, td, waitfor, true);
942 struct vnop_fsync_args {
943 struct vop_generic_args a_gen;
946 struct thread * a_td;
950 fuse_vnop_fsync(struct vop_fsync_args *ap)
952 struct vnode *vp = ap->a_vp;
953 struct thread *td = ap->a_td;
954 int waitfor = ap->a_waitfor;
957 if (fuse_isdeadfs(vp)) {
960 if ((err = vop_stdfsync(ap)))
963 return fuse_internal_fsync(vp, td, waitfor, false);
967 struct vnop_getattr_args {
970 struct ucred *a_cred;
975 fuse_vnop_getattr(struct vop_getattr_args *ap)
977 struct vnode *vp = ap->a_vp;
978 struct vattr *vap = ap->a_vap;
979 struct ucred *cred = ap->a_cred;
980 struct thread *td = curthread;
985 dataflags = fuse_get_mpdata(vnode_mount(vp))->dataflags;
987 /* Note that we are not bailing out on a dead file system just yet. */
989 if (!(dataflags & FSESS_INITED)) {
990 if (!vnode_isvroot(vp)) {
991 fdata_set_dead(fuse_get_mpdata(vnode_mount(vp)));
998 err = fuse_internal_getattr(vp, vap, cred, td);
999 if (err == ENOTCONN && vnode_isvroot(vp)) {
1000 /* see comment in fuse_vfsop_statfs() */
1007 bzero(vap, sizeof(*vap));
1008 vap->va_type = vnode_vtype(vp);
1014 struct vnop_inactive_args {
1019 fuse_vnop_inactive(struct vop_inactive_args *ap)
1021 struct vnode *vp = ap->a_vp;
1022 struct thread *td = curthread;
1024 struct fuse_vnode_data *fvdat = VTOFUD(vp);
1025 struct fuse_filehandle *fufh, *fufh_tmp;
1029 LIST_FOREACH_SAFE(fufh, &fvdat->handles, next, fufh_tmp) {
1030 if (need_flush && vp->v_type == VREG) {
1031 if ((VTOFUD(vp)->flag & FN_SIZECHANGE) != 0) {
1032 fuse_vnode_savesize(vp, NULL, 0);
1034 if ((fvdat->flag & FN_REVOKED) != 0)
1035 fuse_io_invalbuf(vp, td);
1037 fuse_io_flushbuf(vp, MNT_WAIT, td);
1040 fuse_filehandle_close(vp, fufh, td, NULL);
1043 if ((fvdat->flag & FN_REVOKED) != 0)
1050 struct vnop_ioctl_args {
1055 struct ucred *a_cred;
1056 struct thread *a_td;
1060 fuse_vnop_ioctl(struct vop_ioctl_args *ap)
1062 struct vnode *vp = ap->a_vp;
1063 struct mount *mp = vnode_mount(vp);
1064 struct ucred *cred = ap->a_cred;
1066 pid_t pid = ap->a_td->td_proc->p_pid;
1069 switch (ap->a_command) {
1072 /* Call FUSE_LSEEK, if we can, or fall back to vop_stdioctl */
1073 if (fsess_maybe_impl(mp, FUSE_LSEEK)) {
1077 if (ap->a_command == FIOSEEKDATA)
1082 vn_lock(vp, LK_SHARED | LK_RETRY);
1083 err = fuse_vnop_do_lseek(vp, ap->a_td, cred, pid, offp,
1087 if (fsess_not_impl(mp, FUSE_LSEEK))
1088 err = vop_stdioctl(ap);
1091 /* TODO: implement FUSE_IOCTL */
1100 struct vnop_link_args {
1101 struct vnode *a_tdvp;
1103 struct componentname *a_cnp;
1107 fuse_vnop_link(struct vop_link_args *ap)
1109 struct vnode *vp = ap->a_vp;
1110 struct vnode *tdvp = ap->a_tdvp;
1111 struct componentname *cnp = ap->a_cnp;
1113 struct vattr *vap = VTOVA(vp);
1115 struct fuse_dispatcher fdi;
1116 struct fuse_entry_out *feo;
1117 struct fuse_link_in fli;
1121 if (fuse_isdeadfs(vp)) {
1124 if (vnode_mount(tdvp) != vnode_mount(vp)) {
1129 * This is a seatbelt check to protect naive userspace filesystems from
1130 * themselves and the limitations of the FUSE IPC protocol. If a
1131 * filesystem does not allow attribute caching, assume it is capable of
1132 * validating that nlink does not overflow.
1134 if (vap != NULL && vap->va_nlink >= FUSE_LINK_MAX)
1136 fli.oldnodeid = VTOI(vp);
1138 fdisp_init(&fdi, 0);
1139 fuse_internal_newentry_makerequest(vnode_mount(tdvp), VTOI(tdvp), cnp,
1140 FUSE_LINK, &fli, sizeof(fli), &fdi);
1141 if ((err = fdisp_wait_answ(&fdi))) {
1146 err = fuse_internal_checkentry(feo, vnode_vtype(vp));
1149 * Purge the parent's attribute cache because the daemon
1150 * should've updated its mtime and ctime
1152 fuse_vnode_clear_attr_cache(tdvp);
1153 fuse_internal_cache_attrs(vp, &feo->attr, feo->attr_valid,
1154 feo->attr_valid_nsec, NULL, true);
1157 fdisp_destroy(&fdi);
1161 struct fuse_lookup_alloc_arg {
1162 struct fuse_entry_out *feo;
1163 struct componentname *cnp;
1168 /* Callback for vn_get_ino */
1170 fuse_lookup_alloc(struct mount *mp, void *arg, int lkflags, struct vnode **vpp)
1172 struct fuse_lookup_alloc_arg *flaa = arg;
1174 return fuse_vnode_get(mp, flaa->feo, flaa->nid, NULL, vpp, flaa->cnp,
1178 SDT_PROBE_DEFINE3(fusefs, , vnops, cache_lookup,
1179 "int", "struct timespec*", "struct timespec*");
1181 struct vnop_lookup_args {
1182 struct vnodeop_desc *a_desc;
1183 struct vnode *a_dvp;
1184 struct vnode **a_vpp;
1185 struct componentname *a_cnp;
1189 fuse_vnop_lookup(struct vop_lookup_args *ap)
1191 struct vnode *dvp = ap->a_dvp;
1192 struct vnode **vpp = ap->a_vpp;
1193 struct componentname *cnp = ap->a_cnp;
1194 struct thread *td = cnp->cn_thread;
1195 struct ucred *cred = cnp->cn_cred;
1197 int nameiop = cnp->cn_nameiop;
1198 int flags = cnp->cn_flags;
1199 int wantparent = flags & (LOCKPARENT | WANTPARENT);
1200 int islastcn = flags & ISLASTCN;
1201 struct mount *mp = vnode_mount(dvp);
1202 struct fuse_data *data = fuse_get_mpdata(mp);
1203 int default_permissions = data->dataflags & FSESS_DEFAULT_PERMISSIONS;
1207 struct vnode *vp = NULL;
1209 struct fuse_dispatcher fdi;
1210 bool did_lookup = false;
1211 struct fuse_entry_out *feo = NULL;
1212 enum vtype vtyp; /* vnode type of target */
1213 off_t filesize; /* filesize of target */
1217 if (fuse_isdeadfs(dvp)) {
1221 if (!vnode_isdir(dvp))
1224 if (islastcn && vfs_isrdonly(mp) && (nameiop != LOOKUP))
1227 if ((cnp->cn_flags & NOEXECCHECK) != 0)
1228 cnp->cn_flags &= ~NOEXECCHECK;
1229 else if ((err = fuse_internal_access(dvp, VEXEC, td, cred)))
1232 if (flags & ISDOTDOT) {
1233 KASSERT(VTOFUD(dvp)->flag & FN_PARENT_NID,
1234 ("Looking up .. is TODO"));
1235 nid = VTOFUD(dvp)->parent_nid;
1238 /* .. is obviously a directory */
1241 } else if (cnp->cn_namelen == 1 && *(cnp->cn_nameptr) == '.') {
1243 /* . is obviously a directory */
1247 struct timespec now, timeout;
1248 int ncpticks; /* here to accomodate for API contract */
1250 err = cache_lookup(dvp, vpp, cnp, &timeout, &ncpticks);
1251 getnanouptime(&now);
1252 SDT_PROBE3(fusefs, , vnops, cache_lookup, err, &timeout, &now);
1254 case -1: /* positive match */
1255 if (timespeccmp(&timeout, &now, >)) {
1256 counter_u64_add(fuse_lookup_cache_hits, 1);
1259 counter_u64_add(fuse_lookup_cache_misses, 1);
1261 &VTOFUD(*vpp)->entry_cache_timeout);
1272 case 0: /* no match in cache */
1273 counter_u64_add(fuse_lookup_cache_misses, 1);
1276 case ENOENT: /* negative match */
1277 getnanouptime(&now);
1278 if (timespeccmp(&timeout, &now, <=)) {
1280 cache_purge_negative(dvp);
1289 fdisp_init(&fdi, cnp->cn_namelen + 1);
1290 fdisp_make(&fdi, FUSE_LOOKUP, mp, nid, td, cred);
1292 memcpy(fdi.indata, cnp->cn_nameptr, cnp->cn_namelen);
1293 ((char *)fdi.indata)[cnp->cn_namelen] = '\0';
1294 lookup_err = fdisp_wait_answ(&fdi);
1298 /* lookup call succeeded */
1299 feo = (struct fuse_entry_out *)fdi.answ;
1302 /* zero nodeid means ENOENT and cache it */
1303 struct timespec timeout;
1305 fdi.answ_stat = ENOENT;
1306 lookup_err = ENOENT;
1307 if (cnp->cn_flags & MAKEENTRY) {
1308 fuse_validity_2_timespec(feo, &timeout);
1309 cache_enter_time(dvp, *vpp, cnp,
1312 } else if (nid == FUSE_ROOT_ID) {
1313 lookup_err = EINVAL;
1315 vtyp = IFTOVT(feo->attr.mode);
1316 filesize = feo->attr.size;
1318 if (lookup_err && (!fdi.answ_stat || lookup_err != ENOENT)) {
1319 fdisp_destroy(&fdi);
1323 /* lookup_err, if non-zero, must be ENOENT at this point */
1326 /* Entry not found */
1327 if ((nameiop == CREATE || nameiop == RENAME) && islastcn) {
1328 if (default_permissions)
1329 err = fuse_internal_access(dvp, VWRITE, td,
1335 * Set the SAVENAME flag to hold onto the
1336 * pathname for use later in VOP_CREATE or
1339 cnp->cn_flags |= SAVENAME;
1347 /* Entry was found */
1348 if (flags & ISDOTDOT) {
1349 struct fuse_lookup_alloc_arg flaa;
1355 err = vn_vget_ino_gen(dvp, fuse_lookup_alloc, &flaa, 0,
1358 } else if (nid == VTOI(dvp)) {
1362 struct fuse_vnode_data *fvdat;
1364 err = fuse_vnode_get(vnode_mount(dvp), feo, nid, dvp,
1372 fuse_internal_cache_attrs(*vpp, &feo->attr,
1373 feo->attr_valid, feo->attr_valid_nsec, NULL, true);
1374 fuse_validity_2_bintime(feo->entry_valid,
1375 feo->entry_valid_nsec,
1376 &fvdat->entry_cache_timeout);
1378 if ((nameiop == DELETE || nameiop == RENAME) &&
1379 islastcn && default_permissions)
1381 struct vattr dvattr;
1383 err = fuse_internal_access(dvp, VWRITE, td,
1388 * if the parent's sticky bit is set, check
1389 * whether we're allowed to remove the file.
1390 * Need to figure out the vnode locking to make
1393 fuse_internal_getattr(dvp, &dvattr, cred, td);
1394 if ((dvattr.va_mode & S_ISTXT) &&
1395 fuse_internal_access(dvp, VADMIN, td,
1397 fuse_internal_access(*vpp, VADMIN, td,
1405 (nameiop == DELETE) ||
1406 (nameiop == RENAME && wantparent))) {
1407 cnp->cn_flags |= SAVENAME;
1413 if (vp != NULL && dvp != vp)
1415 else if (vp != NULL)
1420 fdisp_destroy(&fdi);
1426 struct vnop_mkdir_args {
1427 struct vnode *a_dvp;
1428 struct vnode **a_vpp;
1429 struct componentname *a_cnp;
1430 struct vattr *a_vap;
1434 fuse_vnop_mkdir(struct vop_mkdir_args *ap)
1436 struct vnode *dvp = ap->a_dvp;
1437 struct vnode **vpp = ap->a_vpp;
1438 struct componentname *cnp = ap->a_cnp;
1439 struct vattr *vap = ap->a_vap;
1441 struct fuse_mkdir_in fmdi;
1443 if (fuse_isdeadfs(dvp)) {
1446 fmdi.mode = MAKEIMODE(vap->va_type, vap->va_mode);
1447 fmdi.umask = curthread->td_proc->p_pd->pd_cmask;
1449 return (fuse_internal_newentry(dvp, vpp, cnp, FUSE_MKDIR, &fmdi,
1450 sizeof(fmdi), VDIR));
1454 struct vnop_mknod_args {
1455 struct vnode *a_dvp;
1456 struct vnode **a_vpp;
1457 struct componentname *a_cnp;
1458 struct vattr *a_vap;
1462 fuse_vnop_mknod(struct vop_mknod_args *ap)
1465 struct vnode *dvp = ap->a_dvp;
1466 struct vnode **vpp = ap->a_vpp;
1467 struct componentname *cnp = ap->a_cnp;
1468 struct vattr *vap = ap->a_vap;
1470 if (fuse_isdeadfs(dvp))
1473 return fuse_internal_mknod(dvp, vpp, cnp, vap);
1477 struct vop_open_args {
1480 struct ucred *a_cred;
1481 struct thread *a_td;
1482 int a_fdidx; / struct file *a_fp;
1486 fuse_vnop_open(struct vop_open_args *ap)
1488 struct vnode *vp = ap->a_vp;
1489 int a_mode = ap->a_mode;
1490 struct thread *td = ap->a_td;
1491 struct ucred *cred = ap->a_cred;
1492 pid_t pid = td->td_proc->p_pid;
1493 struct fuse_vnode_data *fvdat;
1495 if (fuse_isdeadfs(vp))
1497 if (vp->v_type == VCHR || vp->v_type == VBLK || vp->v_type == VFIFO)
1498 return (EOPNOTSUPP);
1499 if ((a_mode & (FREAD | FWRITE | FEXEC)) == 0)
1504 if (fuse_filehandle_validrw(vp, a_mode, cred, pid)) {
1505 fuse_vnode_open(vp, 0, td);
1509 return fuse_filehandle_open(vp, a_mode, NULL, td, cred);
1513 fuse_vnop_pathconf(struct vop_pathconf_args *ap)
1515 struct vnode *vp = ap->a_vp;
1518 switch (ap->a_name) {
1519 case _PC_FILESIZEBITS:
1523 *ap->a_retval = NAME_MAX;
1526 *ap->a_retval = MIN(LONG_MAX, FUSE_LINK_MAX);
1528 case _PC_SYMLINK_MAX:
1529 *ap->a_retval = MAXPATHLEN;
1534 case _PC_MIN_HOLE_SIZE:
1536 * The FUSE protocol provides no mechanism for a server to
1537 * report _PC_MIN_HOLE_SIZE. It's a protocol bug. Instead,
1538 * return EINVAL if the server does not support FUSE_LSEEK, or
1541 mp = vnode_mount(vp);
1542 if (!fsess_is_impl(mp, FUSE_LSEEK) &&
1543 !fsess_not_impl(mp, FUSE_LSEEK)) {
1546 /* Issue a FUSE_LSEEK to find out if it's implemented */
1547 fuse_vnop_do_lseek(vp, curthread, curthread->td_ucred,
1548 curthread->td_proc->p_pid, &offset, SEEK_DATA);
1551 if (fsess_is_impl(mp, FUSE_LSEEK)) {
1556 * Probably FUSE_LSEEK is not implemented. It might
1557 * be, if the FUSE_LSEEK above returned an error like
1558 * EACCES, but in that case we can't tell, so it's
1559 * safest to report EINVAL anyway.
1564 return (vop_stdpathconf(ap));
1569 struct vnop_read_args {
1573 struct ucred *a_cred;
1577 fuse_vnop_read(struct vop_read_args *ap)
1579 struct vnode *vp = ap->a_vp;
1580 struct uio *uio = ap->a_uio;
1581 int ioflag = ap->a_ioflag;
1582 struct ucred *cred = ap->a_cred;
1583 pid_t pid = curthread->td_proc->p_pid;
1585 if (fuse_isdeadfs(vp)) {
1589 if (VTOFUD(vp)->flag & FN_DIRECTIO) {
1590 ioflag |= IO_DIRECT;
1593 return fuse_io_dispatch(vp, uio, ioflag, cred, pid);
1597 struct vnop_readdir_args {
1600 struct ucred *a_cred;
1607 fuse_vnop_readdir(struct vop_readdir_args *ap)
1609 struct vnode *vp = ap->a_vp;
1610 struct uio *uio = ap->a_uio;
1611 struct ucred *cred = ap->a_cred;
1612 struct fuse_filehandle *fufh = NULL;
1613 struct fuse_iov cookediov;
1619 bool closefufh = false;
1620 pid_t pid = curthread->td_proc->p_pid;
1624 if (fuse_isdeadfs(vp)) {
1627 if ( /* XXXIP ((uio_iovcnt(uio) > 1)) || */
1628 (uio_resid(uio) < sizeof(struct dirent))) {
1632 tresid = uio->uio_resid;
1633 startoff = uio->uio_offset;
1634 err = fuse_filehandle_get_dir(vp, &fufh, cred, pid);
1635 if (err == EBADF && vnode_mount(vp)->mnt_flag & MNT_EXPORTED) {
1637 * nfsd will do VOP_READDIR without first doing VOP_OPEN. We
1638 * must implicitly open the directory here
1640 err = fuse_filehandle_open(vp, FREAD, &fufh, curthread, cred);
1643 * When a directory is opened, it must be read from
1644 * the beginning. Hopefully, the "startoff" still
1645 * exists as an offset cookie for the directory.
1646 * If not, it will read the entire directory without
1647 * returning any entries and just return eof.
1649 uio->uio_offset = 0;
1655 if (ap->a_ncookies != NULL) {
1656 ncookies = uio->uio_resid /
1657 (offsetof(struct dirent, d_name) + 4) + 1;
1658 cookies = malloc(ncookies * sizeof(*cookies), M_TEMP, M_WAITOK);
1659 *ap->a_ncookies = ncookies;
1660 *ap->a_cookies = cookies;
1665 #define DIRCOOKEDSIZE FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + MAXNAMLEN + 1)
1666 fiov_init(&cookediov, DIRCOOKEDSIZE);
1668 err = fuse_internal_readdir(vp, uio, startoff, fufh, &cookediov,
1669 &ncookies, cookies);
1671 fiov_teardown(&cookediov);
1673 fuse_filehandle_close(vp, fufh, curthread, cred);
1675 if (ap->a_ncookies != NULL) {
1677 *ap->a_ncookies -= ncookies;
1679 free(*ap->a_cookies, M_TEMP);
1680 *ap->a_ncookies = 0;
1681 *ap->a_cookies = NULL;
1684 if (err == 0 && tresid == uio->uio_resid)
1691 struct vnop_readlink_args {
1694 struct ucred *a_cred;
1698 fuse_vnop_readlink(struct vop_readlink_args *ap)
1700 struct vnode *vp = ap->a_vp;
1701 struct uio *uio = ap->a_uio;
1702 struct ucred *cred = ap->a_cred;
1704 struct fuse_dispatcher fdi;
1707 if (fuse_isdeadfs(vp)) {
1710 if (!vnode_islnk(vp)) {
1713 fdisp_init(&fdi, 0);
1714 err = fdisp_simple_putget_vp(&fdi, FUSE_READLINK, vp, curthread, cred);
1718 if (((char *)fdi.answ)[0] == '/' &&
1719 fuse_get_mpdata(vnode_mount(vp))->dataflags & FSESS_PUSH_SYMLINKS_IN) {
1720 char *mpth = vnode_mount(vp)->mnt_stat.f_mntonname;
1722 err = uiomove(mpth, strlen(mpth), uio);
1725 err = uiomove(fdi.answ, fdi.iosize, uio);
1728 fdisp_destroy(&fdi);
1733 struct vnop_reclaim_args {
1738 fuse_vnop_reclaim(struct vop_reclaim_args *ap)
1740 struct vnode *vp = ap->a_vp;
1741 struct thread *td = curthread;
1742 struct fuse_vnode_data *fvdat = VTOFUD(vp);
1743 struct fuse_filehandle *fufh, *fufh_tmp;
1746 panic("FUSE: no vnode data during recycling");
1748 LIST_FOREACH_SAFE(fufh, &fvdat->handles, next, fufh_tmp) {
1749 printf("FUSE: vnode being reclaimed with open fufh "
1750 "(type=%#x)", fufh->fufh_type);
1751 fuse_filehandle_close(vp, fufh, td, NULL);
1754 if (!fuse_isdeadfs(vp) && fvdat->nlookup > 0) {
1755 fuse_internal_forget_send(vnode_mount(vp), td, NULL, VTOI(vp),
1759 vfs_hash_remove(vp);
1760 fuse_vnode_destroy(vp);
1766 struct vnop_remove_args {
1767 struct vnode *a_dvp;
1769 struct componentname *a_cnp;
1773 fuse_vnop_remove(struct vop_remove_args *ap)
1775 struct vnode *dvp = ap->a_dvp;
1776 struct vnode *vp = ap->a_vp;
1777 struct componentname *cnp = ap->a_cnp;
1781 if (fuse_isdeadfs(vp)) {
1784 if (vnode_isdir(vp)) {
1788 err = fuse_internal_remove(dvp, vp, cnp, FUSE_UNLINK);
1794 struct vnop_rename_args {
1795 struct vnode *a_fdvp;
1796 struct vnode *a_fvp;
1797 struct componentname *a_fcnp;
1798 struct vnode *a_tdvp;
1799 struct vnode *a_tvp;
1800 struct componentname *a_tcnp;
1804 fuse_vnop_rename(struct vop_rename_args *ap)
1806 struct vnode *fdvp = ap->a_fdvp;
1807 struct vnode *fvp = ap->a_fvp;
1808 struct componentname *fcnp = ap->a_fcnp;
1809 struct vnode *tdvp = ap->a_tdvp;
1810 struct vnode *tvp = ap->a_tvp;
1811 struct componentname *tcnp = ap->a_tcnp;
1812 struct fuse_data *data;
1813 bool newparent = fdvp != tdvp;
1814 bool isdir = fvp->v_type == VDIR;
1817 if (fuse_isdeadfs(fdvp)) {
1820 if (fvp->v_mount != tdvp->v_mount ||
1821 (tvp && fvp->v_mount != tvp->v_mount)) {
1822 SDT_PROBE2(fusefs, , vnops, trace, 1, "cross-device rename");
1829 * FUSE library is expected to check if target directory is not
1830 * under the source directory in the file system tree.
1831 * Linux performs this check at VFS level.
1834 * If source is a directory, and it will get a new parent, user must
1835 * have write permission to it, so ".." can be modified.
1837 data = fuse_get_mpdata(vnode_mount(tdvp));
1838 if (data->dataflags & FSESS_DEFAULT_PERMISSIONS && isdir && newparent) {
1839 err = fuse_internal_access(fvp, VWRITE,
1840 tcnp->cn_thread, tcnp->cn_cred);
1844 sx_xlock(&data->rename_lock);
1845 err = fuse_internal_rename(fdvp, fcnp, tdvp, tcnp);
1848 fuse_vnode_setparent(fvp, tdvp);
1850 fuse_vnode_setparent(tvp, NULL);
1852 sx_unlock(&data->rename_lock);
1854 if (tvp != NULL && tvp != fvp) {
1857 if (vnode_isdir(fvp)) {
1858 if ((tvp != NULL) && vnode_isdir(tvp)) {
1879 struct vnop_rmdir_args {
1880 struct vnode *a_dvp;
1882 struct componentname *a_cnp;
1886 fuse_vnop_rmdir(struct vop_rmdir_args *ap)
1888 struct vnode *dvp = ap->a_dvp;
1889 struct vnode *vp = ap->a_vp;
1893 if (fuse_isdeadfs(vp)) {
1896 if (VTOFUD(vp) == VTOFUD(dvp)) {
1899 err = fuse_internal_remove(dvp, vp, ap->a_cnp, FUSE_RMDIR);
1905 struct vnop_setattr_args {
1907 struct vattr *a_vap;
1908 struct ucred *a_cred;
1909 struct thread *a_td;
1913 fuse_vnop_setattr(struct vop_setattr_args *ap)
1915 struct vnode *vp = ap->a_vp;
1916 struct vattr *vap = ap->a_vap;
1917 struct ucred *cred = ap->a_cred;
1918 struct thread *td = curthread;
1920 struct fuse_data *data;
1921 struct vattr old_va;
1924 accmode_t accmode = 0;
1926 bool drop_suid = false;
1929 mp = vnode_mount(vp);
1930 data = fuse_get_mpdata(mp);
1931 dataflags = data->dataflags;
1932 checkperm = dataflags & FSESS_DEFAULT_PERMISSIONS;
1933 if (cred->cr_ngroups > 0)
1934 cr_gid = cred->cr_groups[0];
1938 if (fuse_isdeadfs(vp)) {
1942 if (vap->va_uid != (uid_t)VNOVAL) {
1944 /* Only root may change a file's owner */
1945 err = priv_check_cred(cred, PRIV_VFS_CHOWN);
1947 /* As a special case, allow the null chown */
1948 err2 = fuse_internal_getattr(vp, &old_va, cred,
1952 if (vap->va_uid != old_va.va_uid)
1962 if (vap->va_gid != (gid_t)VNOVAL) {
1963 if (checkperm && priv_check_cred(cred, PRIV_VFS_CHOWN))
1965 if (checkperm && !groupmember(vap->va_gid, cred))
1968 * Non-root users may only chgrp to one of their own
1971 err = priv_check_cred(cred, PRIV_VFS_CHOWN);
1973 /* As a special case, allow the null chgrp */
1974 err2 = fuse_internal_getattr(vp, &old_va, cred,
1978 if (vap->va_gid != old_va.va_gid)
1986 if (vap->va_size != VNOVAL) {
1987 switch (vp->v_type) {
1992 if (vfs_isrdonly(mp))
1997 * According to POSIX, the result is unspecified
1998 * for file types other than regular files,
1999 * directories and shared memory objects. We
2000 * don't support shared memory objects in the file
2001 * system, and have dubious support for truncating
2002 * symlinks. Just ignore the request in other cases.
2006 /* Don't set accmode. Permission to trunc is checked upstack */
2008 if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
2009 if (vap->va_vaflags & VA_UTIMES_NULL)
2015 if (vap->va_mode != (mode_t)VNOVAL)
2016 vap->va_mode &= ~(S_ISUID | S_ISGID);
2018 err = fuse_internal_getattr(vp, &old_va, cred, td);
2021 vap->va_mode = old_va.va_mode & ~(S_ISUID | S_ISGID);
2024 if (vap->va_mode != (mode_t)VNOVAL) {
2025 /* Only root may set the sticky bit on non-directories */
2026 if (checkperm && vp->v_type != VDIR && (vap->va_mode & S_ISTXT)
2027 && priv_check_cred(cred, PRIV_VFS_STICKYFILE))
2029 if (checkperm && (vap->va_mode & S_ISGID)) {
2030 err = fuse_internal_getattr(vp, &old_va, cred, td);
2033 if (!groupmember(old_va.va_gid, cred)) {
2034 err = priv_check_cred(cred, PRIV_VFS_SETGID);
2042 if (vfs_isrdonly(mp))
2046 err = fuse_internal_access(vp, accmode, td, cred);
2053 return fuse_internal_setattr(vp, vap, td, cred);
2057 struct vnop_strategy_args {
2063 fuse_vnop_strategy(struct vop_strategy_args *ap)
2065 struct vnode *vp = ap->a_vp;
2066 struct buf *bp = ap->a_bp;
2068 if (!vp || fuse_isdeadfs(vp)) {
2069 bp->b_ioflags |= BIO_ERROR;
2070 bp->b_error = ENXIO;
2076 * VOP_STRATEGY always returns zero and signals error via bp->b_ioflags.
2077 * fuse_io_strategy sets bp's error fields
2079 (void)fuse_io_strategy(vp, bp);
2085 struct vnop_symlink_args {
2086 struct vnode *a_dvp;
2087 struct vnode **a_vpp;
2088 struct componentname *a_cnp;
2089 struct vattr *a_vap;
2094 fuse_vnop_symlink(struct vop_symlink_args *ap)
2096 struct vnode *dvp = ap->a_dvp;
2097 struct vnode **vpp = ap->a_vpp;
2098 struct componentname *cnp = ap->a_cnp;
2099 const char *target = ap->a_target;
2101 struct fuse_dispatcher fdi;
2106 if (fuse_isdeadfs(dvp)) {
2110 * Unlike the other creator type calls, here we have to create a message
2111 * where the name of the new entry comes first, and the data describing
2112 * the entry comes second.
2113 * Hence we can't rely on our handy fuse_internal_newentry() routine,
2114 * but put together the message manually and just call the core part.
2117 len = strlen(target) + 1;
2118 fdisp_init(&fdi, len + cnp->cn_namelen + 1);
2119 fdisp_make_vp(&fdi, FUSE_SYMLINK, dvp, curthread, NULL);
2121 memcpy(fdi.indata, cnp->cn_nameptr, cnp->cn_namelen);
2122 ((char *)fdi.indata)[cnp->cn_namelen] = '\0';
2123 memcpy((char *)fdi.indata + cnp->cn_namelen + 1, target, len);
2125 err = fuse_internal_newentry_core(dvp, vpp, cnp, VLNK, &fdi);
2126 fdisp_destroy(&fdi);
2131 struct vnop_write_args {
2135 struct ucred *a_cred;
2139 fuse_vnop_write(struct vop_write_args *ap)
2141 struct vnode *vp = ap->a_vp;
2142 struct uio *uio = ap->a_uio;
2143 int ioflag = ap->a_ioflag;
2144 struct ucred *cred = ap->a_cred;
2145 pid_t pid = curthread->td_proc->p_pid;
2147 if (fuse_isdeadfs(vp)) {
2151 if (VTOFUD(vp)->flag & FN_DIRECTIO) {
2152 ioflag |= IO_DIRECT;
2155 return fuse_io_dispatch(vp, uio, ioflag, cred, pid);
2159 fuse_gbp_getblkno(struct vnode *vp, vm_ooffset_t off)
2161 const int biosize = fuse_iosize(vp);
2163 return (off / biosize);
2167 fuse_gbp_getblksz(struct vnode *vp, daddr_t lbn, long *blksz)
2171 const int biosize = fuse_iosize(vp);
2173 err = fuse_vnode_size(vp, &filesize, NULL, NULL);
2175 /* This will turn into a SIGBUS */
2177 } else if ((off_t)lbn * biosize >= filesize) {
2179 } else if ((off_t)(lbn + 1) * biosize > filesize) {
2180 *blksz = filesize - (off_t)lbn *biosize;
2188 struct vnop_getpages_args {
2196 fuse_vnop_getpages(struct vop_getpages_args *ap)
2198 struct vnode *vp = ap->a_vp;
2200 if (!fsess_opt_mmap(vnode_mount(vp))) {
2201 SDT_PROBE2(fusefs, , vnops, trace, 1,
2202 "called on non-cacheable vnode??\n");
2203 return (VM_PAGER_ERROR);
2206 return (vfs_bio_getpages(vp, ap->a_m, ap->a_count, ap->a_rbehind,
2207 ap->a_rahead, fuse_gbp_getblkno, fuse_gbp_getblksz));
2210 static const char extattr_namespace_separator = '.';
2213 struct vop_getextattr_args {
2214 struct vop_generic_args a_gen;
2216 int a_attrnamespace;
2220 struct ucred *a_cred;
2221 struct thread *a_td;
2225 fuse_vnop_getextattr(struct vop_getextattr_args *ap)
2227 struct vnode *vp = ap->a_vp;
2228 struct uio *uio = ap->a_uio;
2229 struct fuse_dispatcher fdi;
2230 struct fuse_getxattr_in *get_xattr_in;
2231 struct fuse_getxattr_out *get_xattr_out;
2232 struct mount *mp = vnode_mount(vp);
2233 struct thread *td = ap->a_td;
2234 struct ucred *cred = ap->a_cred;
2240 if (fuse_isdeadfs(vp))
2243 if (fsess_not_impl(mp, FUSE_GETXATTR))
2246 err = fuse_extattr_check_cred(vp, ap->a_attrnamespace, cred, td, VREAD);
2250 /* Default to looking for user attributes. */
2251 if (ap->a_attrnamespace == EXTATTR_NAMESPACE_SYSTEM)
2252 prefix = EXTATTR_NAMESPACE_SYSTEM_STRING;
2254 prefix = EXTATTR_NAMESPACE_USER_STRING;
2256 len = strlen(prefix) + sizeof(extattr_namespace_separator) +
2257 strlen(ap->a_name) + 1;
2259 fdisp_init(&fdi, len + sizeof(*get_xattr_in));
2260 fdisp_make_vp(&fdi, FUSE_GETXATTR, vp, td, cred);
2262 get_xattr_in = fdi.indata;
2264 * Check to see whether we're querying the available size or
2265 * issuing the actual request. If we pass in 0, we get back struct
2266 * fuse_getxattr_out. If we pass in a non-zero size, we get back
2267 * that much data, without the struct fuse_getxattr_out header.
2270 get_xattr_in->size = 0;
2272 get_xattr_in->size = uio->uio_resid;
2274 attr_str = (char *)fdi.indata + sizeof(*get_xattr_in);
2275 snprintf(attr_str, len, "%s%c%s", prefix, extattr_namespace_separator,
2278 err = fdisp_wait_answ(&fdi);
2280 if (err == ENOSYS) {
2281 fsess_set_notimpl(mp, FUSE_GETXATTR);
2287 get_xattr_out = fdi.answ;
2289 if (ap->a_size != NULL)
2290 *ap->a_size = get_xattr_out->size;
2293 err = uiomove(fdi.answ, fdi.iosize, uio);
2296 fdisp_destroy(&fdi);
2301 struct vop_setextattr_args {
2302 struct vop_generic_args a_gen;
2304 int a_attrnamespace;
2307 struct ucred *a_cred;
2308 struct thread *a_td;
2312 fuse_vnop_setextattr(struct vop_setextattr_args *ap)
2314 struct vnode *vp = ap->a_vp;
2315 struct uio *uio = ap->a_uio;
2316 struct fuse_dispatcher fdi;
2317 struct fuse_setxattr_in *set_xattr_in;
2318 struct mount *mp = vnode_mount(vp);
2319 struct thread *td = ap->a_td;
2320 struct ucred *cred = ap->a_cred;
2326 if (fuse_isdeadfs(vp))
2329 if (fsess_not_impl(mp, FUSE_SETXATTR))
2332 if (vfs_isrdonly(mp))
2335 /* Deleting xattrs must use VOP_DELETEEXTATTR instead */
2336 if (ap->a_uio == NULL) {
2338 * If we got here as fallback from VOP_DELETEEXTATTR, then
2339 * return EOPNOTSUPP.
2341 if (fsess_not_impl(mp, FUSE_REMOVEXATTR))
2342 return (EOPNOTSUPP);
2347 err = fuse_extattr_check_cred(vp, ap->a_attrnamespace, cred, td,
2352 /* Default to looking for user attributes. */
2353 if (ap->a_attrnamespace == EXTATTR_NAMESPACE_SYSTEM)
2354 prefix = EXTATTR_NAMESPACE_SYSTEM_STRING;
2356 prefix = EXTATTR_NAMESPACE_USER_STRING;
2358 len = strlen(prefix) + sizeof(extattr_namespace_separator) +
2359 strlen(ap->a_name) + 1;
2361 fdisp_init(&fdi, len + sizeof(*set_xattr_in) + uio->uio_resid);
2362 fdisp_make_vp(&fdi, FUSE_SETXATTR, vp, td, cred);
2364 set_xattr_in = fdi.indata;
2365 set_xattr_in->size = uio->uio_resid;
2367 attr_str = (char *)fdi.indata + sizeof(*set_xattr_in);
2368 snprintf(attr_str, len, "%s%c%s", prefix, extattr_namespace_separator,
2371 err = uiomove((char *)fdi.indata + sizeof(*set_xattr_in) + len,
2372 uio->uio_resid, uio);
2377 err = fdisp_wait_answ(&fdi);
2379 if (err == ENOSYS) {
2380 fsess_set_notimpl(mp, FUSE_SETXATTR);
2383 if (err == ERESTART) {
2384 /* Can't restart after calling uiomove */
2389 fdisp_destroy(&fdi);
2394 * The Linux / FUSE extended attribute list is simply a collection of
2395 * NUL-terminated strings. The FreeBSD extended attribute list is a single
2396 * byte length followed by a non-NUL terminated string. So, this allows
2397 * conversion of the Linux / FUSE format to the FreeBSD format in place.
2398 * Linux attribute names are reported with the namespace as a prefix (e.g.
2399 * "user.attribute_name"), but in FreeBSD they are reported without the
2400 * namespace prefix (e.g. "attribute_name"). So, we're going from:
2402 * user.attr_name1\0user.attr_name2\0
2406 * <num>attr_name1<num>attr_name2
2408 * Where "<num>" is a single byte number of characters in the attribute name.
2411 * prefix - exattr namespace prefix string
2412 * list, list_len - input list with namespace prefixes
2413 * bsd_list, bsd_list_len - output list compatible with bsd vfs
2416 fuse_xattrlist_convert(char *prefix, const char *list, int list_len,
2417 char *bsd_list, int *bsd_list_len)
2419 int len, pos, dist_to_next, prefix_len;
2423 prefix_len = strlen(prefix);
2425 while (pos < list_len && list[pos] != '\0') {
2426 dist_to_next = strlen(&list[pos]) + 1;
2427 if (bcmp(&list[pos], prefix, prefix_len) == 0 &&
2428 list[pos + prefix_len] == extattr_namespace_separator) {
2429 len = dist_to_next -
2430 (prefix_len + sizeof(extattr_namespace_separator)) - 1;
2431 if (len >= EXTATTR_MAXNAMELEN)
2432 return (ENAMETOOLONG);
2434 bsd_list[*bsd_list_len] = len;
2435 memcpy(&bsd_list[*bsd_list_len + 1],
2436 &list[pos + prefix_len +
2437 sizeof(extattr_namespace_separator)], len);
2439 *bsd_list_len += len + 1;
2442 pos += dist_to_next;
2449 * List extended attributes
2451 * The FUSE_LISTXATTR operation is based on Linux's listxattr(2) syscall, which
2452 * has a number of differences compared to its FreeBSD equivalent,
2453 * extattr_list_file:
2455 * - FUSE_LISTXATTR returns all extended attributes across all namespaces,
2456 * whereas listxattr(2) only returns attributes for a single namespace
2457 * - FUSE_LISTXATTR prepends each attribute name with "namespace."
2458 * - If the provided buffer is not large enough to hold the result,
2459 * FUSE_LISTXATTR should return ERANGE, whereas listxattr is expected to
2460 * return as many results as will fit.
2463 struct vop_listextattr_args {
2464 struct vop_generic_args a_gen;
2466 int a_attrnamespace;
2469 struct ucred *a_cred;
2470 struct thread *a_td;
2474 fuse_vnop_listextattr(struct vop_listextattr_args *ap)
2476 struct vnode *vp = ap->a_vp;
2477 struct uio *uio = ap->a_uio;
2478 struct fuse_dispatcher fdi;
2479 struct fuse_listxattr_in *list_xattr_in;
2480 struct fuse_listxattr_out *list_xattr_out;
2481 struct mount *mp = vnode_mount(vp);
2482 struct thread *td = ap->a_td;
2483 struct ucred *cred = ap->a_cred;
2485 char *bsd_list = NULL;
2491 if (fuse_isdeadfs(vp))
2494 if (fsess_not_impl(mp, FUSE_LISTXATTR))
2497 err = fuse_extattr_check_cred(vp, ap->a_attrnamespace, cred, td, VREAD);
2502 * Add space for a NUL and the period separator if enabled.
2503 * Default to looking for user attributes.
2505 if (ap->a_attrnamespace == EXTATTR_NAMESPACE_SYSTEM)
2506 prefix = EXTATTR_NAMESPACE_SYSTEM_STRING;
2508 prefix = EXTATTR_NAMESPACE_USER_STRING;
2510 fdisp_init(&fdi, sizeof(*list_xattr_in));
2511 fdisp_make_vp(&fdi, FUSE_LISTXATTR, vp, td, cred);
2514 * Retrieve Linux / FUSE compatible list size.
2516 list_xattr_in = fdi.indata;
2517 list_xattr_in->size = 0;
2519 err = fdisp_wait_answ(&fdi);
2521 if (err == ENOSYS) {
2522 fsess_set_notimpl(mp, FUSE_LISTXATTR);
2528 list_xattr_out = fdi.answ;
2529 linux_list_len = list_xattr_out->size;
2530 if (linux_list_len == 0) {
2531 if (ap->a_size != NULL)
2532 *ap->a_size = linux_list_len;
2537 * Retrieve Linux / FUSE compatible list values.
2539 fdisp_refresh_vp(&fdi, FUSE_LISTXATTR, vp, td, cred);
2540 list_xattr_in = fdi.indata;
2541 list_xattr_in->size = linux_list_len;
2543 err = fdisp_wait_answ(&fdi);
2544 if (err == ERANGE) {
2546 * Race detected. The attribute list must've grown since the
2547 * first FUSE_LISTXATTR call. Start over. Go all the way back
2548 * to userland so we can process signals, if necessary, before
2553 } else if (err != 0)
2556 linux_list = fdi.answ;
2557 /* FUSE doesn't allow the server to return more data than requested */
2558 if (fdi.iosize > linux_list_len) {
2559 struct fuse_data *data = fuse_get_mpdata(mp);
2561 fuse_warn(data, FSESS_WARN_LSEXTATTR_LONG,
2563 "more extended attribute data than requested; "
2564 "should've returned ERANGE instead.");
2566 /* But returning less data is fine */
2567 linux_list_len = fdi.iosize;
2571 * Retrieve the BSD compatible list values.
2572 * The Linux / FUSE attribute list format isn't the same
2573 * as FreeBSD's format. So we need to transform it into
2574 * FreeBSD's format before giving it to the user.
2576 bsd_list = malloc(linux_list_len, M_TEMP, M_WAITOK);
2577 err = fuse_xattrlist_convert(prefix, linux_list, linux_list_len,
2578 bsd_list, &bsd_list_len);
2582 if (ap->a_size != NULL)
2583 *ap->a_size = bsd_list_len;
2586 err = uiomove(bsd_list, bsd_list_len, uio);
2589 free(bsd_list, M_TEMP);
2590 fdisp_destroy(&fdi);
2595 struct vop_deleteextattr_args {
2596 struct vop_generic_args a_gen;
2598 int a_attrnamespace;
2600 struct ucred *a_cred;
2601 struct thread *a_td;
2605 fuse_vnop_deleteextattr(struct vop_deleteextattr_args *ap)
2607 struct vnode *vp = ap->a_vp;
2608 struct fuse_dispatcher fdi;
2609 struct mount *mp = vnode_mount(vp);
2610 struct thread *td = ap->a_td;
2611 struct ucred *cred = ap->a_cred;
2617 if (fuse_isdeadfs(vp))
2620 if (fsess_not_impl(mp, FUSE_REMOVEXATTR))
2623 if (vfs_isrdonly(mp))
2626 err = fuse_extattr_check_cred(vp, ap->a_attrnamespace, cred, td,
2631 /* Default to looking for user attributes. */
2632 if (ap->a_attrnamespace == EXTATTR_NAMESPACE_SYSTEM)
2633 prefix = EXTATTR_NAMESPACE_SYSTEM_STRING;
2635 prefix = EXTATTR_NAMESPACE_USER_STRING;
2637 len = strlen(prefix) + sizeof(extattr_namespace_separator) +
2638 strlen(ap->a_name) + 1;
2640 fdisp_init(&fdi, len);
2641 fdisp_make_vp(&fdi, FUSE_REMOVEXATTR, vp, td, cred);
2643 attr_str = fdi.indata;
2644 snprintf(attr_str, len, "%s%c%s", prefix, extattr_namespace_separator,
2647 err = fdisp_wait_answ(&fdi);
2648 if (err == ENOSYS) {
2649 fsess_set_notimpl(mp, FUSE_REMOVEXATTR);
2653 fdisp_destroy(&fdi);
2658 struct vnop_print_args {
2663 fuse_vnop_print(struct vop_print_args *ap)
2665 struct fuse_vnode_data *fvdat = VTOFUD(ap->a_vp);
2667 printf("nodeid: %ju, parent nodeid: %ju, nlookup: %ju, flag: %#x\n",
2668 (uintmax_t)VTOILLU(ap->a_vp), (uintmax_t)fvdat->parent_nid,
2669 (uintmax_t)fvdat->nlookup,
2676 * Get an NFS filehandle for a FUSE file.
2678 * This will only work for FUSE file systems that guarantee the uniqueness of
2679 * nodeid:generation, which most don't.
2683 IN struct vnode *a_vp;
2684 IN struct fid *a_fhp;
2688 fuse_vnop_vptofh(struct vop_vptofh_args *ap)
2690 struct vnode *vp = ap->a_vp;
2691 struct fuse_vnode_data *fvdat = VTOFUD(vp);
2692 struct fuse_fid *fhp = (struct fuse_fid *)(ap->a_fhp);
2693 _Static_assert(sizeof(struct fuse_fid) <= sizeof(struct fid),
2694 "FUSE fid type is too big");
2695 struct mount *mp = vnode_mount(vp);
2696 struct fuse_data *data = fuse_get_mpdata(mp);
2700 if (!(data->dataflags & FSESS_EXPORT_SUPPORT))
2703 err = fuse_internal_getattr(vp, &va, curthread->td_ucred, curthread);
2707 /*ip = VTOI(ap->a_vp);*/
2708 /*ufhp = (struct ufid *)ap->a_fhp;*/
2709 fhp->len = sizeof(struct fuse_fid);
2710 fhp->nid = fvdat->nid;
2711 if (fvdat->generation <= UINT32_MAX)
2712 fhp->gen = fvdat->generation;