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/mutex.h>
75 #include <sys/mount.h>
76 #include <sys/vnode.h>
77 #include <sys/namei.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>
90 #include "fuse_file.h"
91 #include "fuse_internal.h"
93 #include "fuse_node.h"
94 #include "fuse_file.h"
96 SDT_PROVIDER_DECLARE(fusefs);
99 * arg0: verbosity. Higher numbers give more verbose messages
100 * arg1: Textual message
102 SDT_PROBE_DEFINE2(fusefs, , internal, trace, "int", "char*");
104 #ifdef ZERO_PAD_INCOMPLETE_BUFS
105 static int isbzero(void *buf, size_t len);
109 /* Synchronously send a FUSE_ACCESS operation */
111 fuse_internal_access(struct vnode *vp,
117 uint32_t mask = F_OK;
121 struct fuse_dispatcher fdi;
122 struct fuse_access_in *fai;
123 struct fuse_data *data;
125 mp = vnode_mount(vp);
126 vtype = vnode_vtype(vp);
128 data = fuse_get_mpdata(mp);
129 dataflags = data->dataflags;
134 if (mode & VMODIFY_PERMS && vfs_isrdonly(mp)) {
135 switch (vp->v_type) {
147 /* Unless explicitly permitted, deny everyone except the fs owner. */
148 if (!(dataflags & FSESS_DAEMON_CAN_SPY)) {
149 if (fuse_match_cred(data->daemoncred, cred))
153 if (dataflags & FSESS_DEFAULT_PERMISSIONS) {
156 fuse_internal_getattr(vp, &va, cred, td);
157 return vaccess(vp->v_type, va.va_mode, va.va_uid,
158 va.va_gid, mode, cred, NULL);
161 if (!fsess_isimpl(mp, FUSE_ACCESS))
164 if ((mode & (VWRITE | VAPPEND | VADMIN)) != 0)
166 if ((mode & VREAD) != 0)
168 if ((mode & VEXEC) != 0)
171 fdisp_init(&fdi, sizeof(*fai));
172 fdisp_make_vp(&fdi, FUSE_ACCESS, vp, td, cred);
177 err = fdisp_wait_answ(&fdi);
181 fsess_set_notimpl(mp, FUSE_ACCESS);
188 * Cache FUSE attributes from attr, in attribute cache associated with vnode
189 * 'vp'. Optionally, if argument 'vap' is not NULL, store a copy of the
190 * converted attributes there as well.
192 * If the nominal attribute cache TTL is zero, do not cache on the 'vp' (but do
193 * return the result to the caller).
196 fuse_internal_cache_attrs(struct vnode *vp, struct ucred *cred,
197 struct fuse_attr *attr, uint64_t attr_valid, uint32_t attr_valid_nsec,
201 struct fuse_vnode_data *fvdat;
202 struct fuse_data *data;
203 struct vattr *vp_cache_at;
205 mp = vnode_mount(vp);
207 data = fuse_get_mpdata(mp);
209 cred = curthread->td_ucred;
211 ASSERT_VOP_ELOCKED(vp, "fuse_internal_cache_attrs");
213 fuse_validity_2_bintime(attr_valid, attr_valid_nsec,
214 &fvdat->attr_cache_timeout);
216 /* Fix our buffers if the filesize changed without us knowing */
217 if (vnode_isreg(vp) && attr->size != fvdat->cached_attrs.va_size) {
218 (void)fuse_vnode_setsize(vp, cred, attr->size);
219 fvdat->cached_attrs.va_size = attr->size;
222 if (attr_valid > 0 || attr_valid_nsec > 0)
223 vp_cache_at = &(fvdat->cached_attrs);
224 else if (vap != NULL)
229 vattr_null(vp_cache_at);
230 vp_cache_at->va_fsid = mp->mnt_stat.f_fsid.val[0];
231 vp_cache_at->va_fileid = attr->ino;
232 vp_cache_at->va_mode = attr->mode & ~S_IFMT;
233 vp_cache_at->va_nlink = attr->nlink;
234 vp_cache_at->va_uid = attr->uid;
235 vp_cache_at->va_gid = attr->gid;
236 vp_cache_at->va_rdev = attr->rdev;
237 vp_cache_at->va_size = attr->size;
238 /* XXX on i386, seconds are truncated to 32 bits */
239 vp_cache_at->va_atime.tv_sec = attr->atime;
240 vp_cache_at->va_atime.tv_nsec = attr->atimensec;
241 vp_cache_at->va_mtime.tv_sec = attr->mtime;
242 vp_cache_at->va_mtime.tv_nsec = attr->mtimensec;
243 vp_cache_at->va_ctime.tv_sec = attr->ctime;
244 vp_cache_at->va_ctime.tv_nsec = attr->ctimensec;
245 if (fuse_libabi_geq(data, 7, 9) && attr->blksize > 0)
246 vp_cache_at->va_blocksize = attr->blksize;
248 vp_cache_at->va_blocksize = PAGE_SIZE;
249 vp_cache_at->va_type = IFTOVT(attr->mode);
250 vp_cache_at->va_bytes = attr->blocks * S_BLKSIZE;
251 vp_cache_at->va_flags = 0;
253 if (vap != vp_cache_at && vap != NULL)
254 memcpy(vap, vp_cache_at, sizeof(*vap));
261 fuse_internal_fsync_callback(struct fuse_ticket *tick, struct uio *uio)
263 if (tick->tk_aw_ohead.error == ENOSYS) {
264 fsess_set_notimpl(tick->tk_data->mp, fticket_opcode(tick));
270 fuse_internal_fsync(struct vnode *vp,
275 struct fuse_fsync_in *ffsi = NULL;
276 struct fuse_dispatcher fdi;
277 struct fuse_filehandle *fufh;
278 struct fuse_vnode_data *fvdat = VTOFUD(vp);
279 struct mount *mp = vnode_mount(vp);
283 if (!fsess_isimpl(vnode_mount(vp),
284 (vnode_vtype(vp) == VDIR ? FUSE_FSYNCDIR : FUSE_FSYNC))) {
290 if (!fsess_isimpl(mp, op))
293 fdisp_init(&fdi, sizeof(*ffsi));
295 * fsync every open file handle for this file, because we can't be sure
296 * which file handle the caller is really referring to.
298 LIST_FOREACH(fufh, &fvdat->handles, next) {
300 fdisp_make_vp(&fdi, op, vp, td, NULL);
302 fdisp_refresh_vp(&fdi, op, vp, td, NULL);
304 ffsi->fh = fufh->fh_id;
305 ffsi->fsync_flags = 0;
308 ffsi->fsync_flags = 1;
310 if (waitfor == MNT_WAIT) {
311 err = fdisp_wait_answ(&fdi);
313 fuse_insert_callback(fdi.tick,
314 fuse_internal_fsync_callback);
315 fuse_insert_message(fdi.tick, false);
318 /* ENOSYS means "success, and don't call again" */
319 fsess_set_notimpl(mp, op);
331 fuse_internal_mknod(struct vnode *dvp, struct vnode **vpp,
332 struct componentname *cnp, struct vattr *vap)
334 struct fuse_data *data;
335 struct fuse_mknod_in fmni;
338 data = fuse_get_mpdata(dvp->v_mount);
340 fmni.mode = MAKEIMODE(vap->va_type, vap->va_mode);
341 fmni.rdev = vap->va_rdev;
342 if (fuse_libabi_geq(data, 7, 12)) {
343 insize = sizeof(fmni);
344 fmni.umask = curthread->td_proc->p_fd->fd_cmask;
346 insize = FUSE_COMPAT_MKNOD_IN_SIZE;
348 return (fuse_internal_newentry(dvp, vpp, cnp, FUSE_MKNOD, &fmni,
349 insize, vap->va_type));
355 fuse_internal_readdir(struct vnode *vp,
358 struct fuse_filehandle *fufh,
359 struct fuse_iov *cookediov,
364 struct fuse_dispatcher fdi;
365 struct fuse_read_in *fri = NULL;
368 if (uio_resid(uio) == 0)
373 * Note that we DO NOT have a UIO_SYSSPACE here (so no need for p2p
378 * fnd_start is set non-zero once the offset in the directory gets
379 * to the startoff. This is done because directories must be read
380 * from the beginning (offset == 0) when fuse_vnop_readdir() needs
381 * to do an open of the directory.
382 * If it is not set non-zero here, it will be set non-zero in
383 * fuse_internal_readdir_processdata() when uio_offset == startoff.
386 if (uio->uio_offset == startoff)
388 while (uio_resid(uio) > 0) {
389 fdi.iosize = sizeof(*fri);
391 fdisp_make_vp(&fdi, FUSE_READDIR, vp, NULL, NULL);
393 fdisp_refresh_vp(&fdi, FUSE_READDIR, vp, NULL, NULL);
396 fri->fh = fufh->fh_id;
397 fri->offset = uio_offset(uio);
398 fri->size = MIN(uio->uio_resid,
399 fuse_get_mpdata(vp->v_mount)->max_read);
401 if ((err = fdisp_wait_answ(&fdi)))
403 if ((err = fuse_internal_readdir_processdata(uio, startoff,
404 &fnd_start, fri->size, fdi.answ, fdi.iosize, cookediov,
405 ncookies, &cookies)))
410 return ((err == -1) ? 0 : err);
414 * Return -1 to indicate that this readdir is finished, 0 if it copied
415 * all the directory data read in and it may be possible to read more
416 * and greater than 0 for a failure.
419 fuse_internal_readdir_processdata(struct uio *uio,
425 struct fuse_iov *cookediov,
434 struct fuse_dirent *fudge;
438 if (bufsize < FUSE_NAME_OFFSET)
441 if (bufsize < FUSE_NAME_OFFSET) {
445 fudge = (struct fuse_dirent *)buf;
446 freclen = FUSE_DIRENT_SIZE(fudge);
448 if (bufsize < freclen) {
450 * This indicates a partial directory entry at the
451 * end of the directory data.
456 #ifdef ZERO_PAD_INCOMPLETE_BUFS
457 if (isbzero(buf, FUSE_NAME_OFFSET)) {
463 if (!fudge->namelen || fudge->namelen > MAXNAMLEN) {
467 bytesavail = GENERIC_DIRSIZ((struct pseudo_dirent *)
470 if (bytesavail > uio_resid(uio)) {
471 /* Out of space for the dir so we are done. */
476 * Don't start to copy the directory entries out until
477 * the requested offset in the directory is found.
479 if (*fnd_start != 0) {
480 fiov_adjust(cookediov, bytesavail);
481 bzero(cookediov->base, bytesavail);
483 de = (struct dirent *)cookediov->base;
484 de->d_fileno = fudge->ino;
485 de->d_reclen = bytesavail;
486 de->d_type = fudge->type;
487 de->d_namlen = fudge->namelen;
488 memcpy((char *)cookediov->base + sizeof(struct dirent) -
490 (char *)buf + FUSE_NAME_OFFSET, fudge->namelen);
491 dirent_terminate(de);
493 err = uiomove(cookediov->base, cookediov->len, uio);
496 if (cookies != NULL) {
497 if (*ncookies == 0) {
501 *cookies = fudge->off;
505 } else if (startoff == fudge->off)
507 buf = (char *)buf + freclen;
509 uio_setoffset(uio, fudge->off);
519 fuse_internal_remove(struct vnode *dvp,
521 struct componentname *cnp,
524 struct fuse_dispatcher fdi;
527 fdisp_init(&fdi, cnp->cn_namelen + 1);
528 fdisp_make_vp(&fdi, op, dvp, cnp->cn_thread, cnp->cn_cred);
530 memcpy(fdi.indata, cnp->cn_nameptr, cnp->cn_namelen);
531 ((char *)fdi.indata)[cnp->cn_namelen] = '\0';
533 err = fdisp_wait_answ(&fdi);
541 fuse_internal_rename(struct vnode *fdvp,
542 struct componentname *fcnp,
544 struct componentname *tcnp)
546 struct fuse_dispatcher fdi;
547 struct fuse_rename_in *fri;
550 fdisp_init(&fdi, sizeof(*fri) + fcnp->cn_namelen + tcnp->cn_namelen + 2);
551 fdisp_make_vp(&fdi, FUSE_RENAME, fdvp, tcnp->cn_thread, tcnp->cn_cred);
554 fri->newdir = VTOI(tdvp);
555 memcpy((char *)fdi.indata + sizeof(*fri), fcnp->cn_nameptr,
557 ((char *)fdi.indata)[sizeof(*fri) + fcnp->cn_namelen] = '\0';
558 memcpy((char *)fdi.indata + sizeof(*fri) + fcnp->cn_namelen + 1,
559 tcnp->cn_nameptr, tcnp->cn_namelen);
560 ((char *)fdi.indata)[sizeof(*fri) + fcnp->cn_namelen +
561 tcnp->cn_namelen + 1] = '\0';
563 err = fdisp_wait_answ(&fdi);
570 /* entity creation */
573 fuse_internal_newentry_makerequest(struct mount *mp,
575 struct componentname *cnp,
579 struct fuse_dispatcher *fdip)
581 fdip->iosize = bufsize + cnp->cn_namelen + 1;
583 fdisp_make(fdip, op, mp, dnid, cnp->cn_thread, cnp->cn_cred);
584 memcpy(fdip->indata, buf, bufsize);
585 memcpy((char *)fdip->indata + bufsize, cnp->cn_nameptr, cnp->cn_namelen);
586 ((char *)fdip->indata)[bufsize + cnp->cn_namelen] = '\0';
590 fuse_internal_newentry_core(struct vnode *dvp,
592 struct componentname *cnp,
594 struct fuse_dispatcher *fdip)
597 struct fuse_entry_out *feo;
598 struct mount *mp = vnode_mount(dvp);
600 if ((err = fdisp_wait_answ(fdip))) {
605 if ((err = fuse_internal_checkentry(feo, vtyp))) {
608 err = fuse_vnode_get(mp, feo, feo->nodeid, dvp, vpp, cnp, vtyp);
610 fuse_internal_forget_send(mp, cnp->cn_thread, cnp->cn_cred,
616 * Purge the parent's attribute cache because the daemon should've
617 * updated its mtime and ctime
619 fuse_vnode_clear_attr_cache(dvp);
621 fuse_internal_cache_attrs(*vpp, NULL, &feo->attr, feo->attr_valid,
622 feo->attr_valid_nsec, NULL);
628 fuse_internal_newentry(struct vnode *dvp,
630 struct componentname *cnp,
637 struct fuse_dispatcher fdi;
638 struct mount *mp = vnode_mount(dvp);
641 fuse_internal_newentry_makerequest(mp, VTOI(dvp), cnp, op, buf,
643 err = fuse_internal_newentry_core(dvp, vpp, cnp, vtype, &fdi);
649 /* entity destruction */
652 fuse_internal_forget_callback(struct fuse_ticket *ftick, struct uio *uio)
654 fuse_internal_forget_send(ftick->tk_data->mp, curthread, NULL,
655 ((struct fuse_in_header *)ftick->tk_ms_fiov.base)->nodeid, 1);
661 fuse_internal_forget_send(struct mount *mp,
668 struct fuse_dispatcher fdi;
669 struct fuse_forget_in *ffi;
672 * KASSERT(nlookup > 0, ("zero-times forget for vp #%llu",
673 * (long long unsigned) nodeid));
676 fdisp_init(&fdi, sizeof(*ffi));
677 fdisp_make(&fdi, FUSE_FORGET, mp, nodeid, td, cred);
680 ffi->nlookup = nlookup;
682 fuse_insert_message(fdi.tick, false);
686 /* Fetch the vnode's attributes from the daemon*/
688 fuse_internal_do_getattr(struct vnode *vp, struct vattr *vap,
689 struct ucred *cred, struct thread *td)
691 struct fuse_dispatcher fdi;
692 struct fuse_vnode_data *fvdat = VTOFUD(vp);
693 struct fuse_getattr_in *fgai;
694 struct fuse_attr_out *fao;
695 off_t old_filesize = fvdat->cached_attrs.va_size;
700 fdisp_make_vp(&fdi, FUSE_GETATTR, vp, td, cred);
703 * We could look up a file handle and set it in fgai->fh, but that
704 * involves extra runtime work and I'm unaware of any file systems that
707 fgai->getattr_flags = 0;
708 if ((err = fdisp_simple_putget_vp(&fdi, FUSE_GETATTR, vp, td, cred))) {
710 fuse_internal_vnode_disappear(vp);
714 fao = (struct fuse_attr_out *)fdi.answ;
715 vtyp = IFTOVT(fao->attr.mode);
716 if (fvdat->flag & FN_SIZECHANGE)
717 fao->attr.size = old_filesize;
718 fuse_internal_cache_attrs(vp, NULL, &fao->attr, fao->attr_valid,
719 fao->attr_valid_nsec, vap);
720 if (vtyp != vnode_vtype(vp)) {
721 fuse_internal_vnode_disappear(vp);
730 /* Read a vnode's attributes from cache or fetch them from the fuse daemon */
732 fuse_internal_getattr(struct vnode *vp, struct vattr *vap, struct ucred *cred,
737 if ((attrs = VTOVA(vp)) != NULL) {
738 *vap = *attrs; /* struct copy */
742 return fuse_internal_do_getattr(vp, vap, cred, td);
746 fuse_internal_vnode_disappear(struct vnode *vp)
748 struct fuse_vnode_data *fvdat = VTOFUD(vp);
750 ASSERT_VOP_ELOCKED(vp, "fuse_internal_vnode_disappear");
751 fvdat->flag |= FN_REVOKED;
752 bintime_clear(&fvdat->attr_cache_timeout);
753 bintime_clear(&fvdat->entry_cache_timeout);
757 /* fuse start/stop */
760 fuse_internal_init_callback(struct fuse_ticket *tick, struct uio *uio)
763 struct fuse_data *data = tick->tk_data;
764 struct fuse_init_out *fiio;
766 if ((err = tick->tk_aw_ohead.error)) {
769 if ((err = fticket_pull(tick, uio))) {
772 fiio = fticket_resp(tick)->base;
774 /* XXX: Do we want to check anything further besides this? */
775 if (fiio->major < 7) {
776 SDT_PROBE2(fusefs, , internal, trace, 1,
777 "userpace version too low");
778 err = EPROTONOSUPPORT;
781 data->fuse_libabi_major = fiio->major;
782 data->fuse_libabi_minor = fiio->minor;
784 if (fuse_libabi_geq(data, 7, 5)) {
785 if (fticket_resp(tick)->len == sizeof(struct fuse_init_out)) {
786 data->max_write = fiio->max_write;
787 if (fiio->flags & FUSE_ASYNC_READ)
788 data->dataflags |= FSESS_ASYNC_READ;
789 if (fiio->flags & FUSE_POSIX_LOCKS)
790 data->dataflags |= FSESS_POSIX_LOCKS;
791 if (fiio->flags & FUSE_EXPORT_SUPPORT)
792 data->dataflags |= FSESS_EXPORT_SUPPORT;
794 * Don't bother to check FUSE_BIG_WRITES, because it's
795 * redundant with max_write
802 data->max_write = 4096;
807 fdata_set_dead(data);
810 data->dataflags |= FSESS_INITED;
811 wakeup(&data->ticketer);
818 fuse_internal_send_init(struct fuse_data *data, struct thread *td)
820 struct fuse_init_in *fiii;
821 struct fuse_dispatcher fdi;
823 fdisp_init(&fdi, sizeof(*fiii));
824 fdisp_make(&fdi, FUSE_INIT, data->mp, 0, td, NULL);
826 fiii->major = FUSE_KERNEL_VERSION;
827 fiii->minor = FUSE_KERNEL_MINOR_VERSION;
829 * fusefs currently doesn't do any readahead other than fetching whole
830 * buffer cache block sized regions at once. So the max readahead is
831 * the size of a buffer cache block.
833 fiii->max_readahead = maxbcachebuf;
835 * Unsupported features:
836 * FUSE_FILE_OPS: No known FUSE server or client supports it
837 * FUSE_ATOMIC_O_TRUNC: our VFS cannot support it
838 * FUSE_DONT_MASK: unlike Linux, FreeBSD always applies the umask, even
839 * when default ACLs are in use.
841 fiii->flags = FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_EXPORT_SUPPORT
844 fuse_insert_callback(fdi.tick, fuse_internal_init_callback);
845 fuse_insert_message(fdi.tick, false);
850 * Send a FUSE_SETATTR operation with no permissions checks. If cred is NULL,
851 * send the request with root credentials
853 int fuse_internal_setattr(struct vnode *vp, struct vattr *vap,
854 struct thread *td, struct ucred *cred)
856 struct fuse_dispatcher fdi;
857 struct fuse_setattr_in *fsai;
859 pid_t pid = td->td_proc->p_pid;
860 struct fuse_data *data;
864 int sizechanged = -1;
865 uint64_t newsize = 0;
867 mp = vnode_mount(vp);
868 data = fuse_get_mpdata(mp);
869 dataflags = data->dataflags;
871 fdisp_init(&fdi, sizeof(*fsai));
872 fdisp_make_vp(&fdi, FUSE_SETATTR, vp, td, cred);
880 if (vap->va_uid != (uid_t)VNOVAL) {
881 fsai->uid = vap->va_uid;
882 fsai->valid |= FATTR_UID;
884 if (vap->va_gid != (gid_t)VNOVAL) {
885 fsai->gid = vap->va_gid;
886 fsai->valid |= FATTR_GID;
888 if (vap->va_size != VNOVAL) {
889 struct fuse_filehandle *fufh = NULL;
891 /*Truncate to a new value. */
892 fsai->size = vap->va_size;
894 newsize = vap->va_size;
895 fsai->valid |= FATTR_SIZE;
897 fuse_filehandle_getrw(vp, FWRITE, &fufh, cred, pid);
899 fsai->fh = fufh->fh_id;
900 fsai->valid |= FATTR_FH;
902 VTOFUD(vp)->flag &= ~FN_SIZECHANGE;
904 if (vap->va_atime.tv_sec != VNOVAL) {
905 fsai->atime = vap->va_atime.tv_sec;
906 fsai->atimensec = vap->va_atime.tv_nsec;
907 fsai->valid |= FATTR_ATIME;
908 if (vap->va_vaflags & VA_UTIMES_NULL)
909 fsai->valid |= FATTR_ATIME_NOW;
911 if (vap->va_mtime.tv_sec != VNOVAL) {
912 fsai->mtime = vap->va_mtime.tv_sec;
913 fsai->mtimensec = vap->va_mtime.tv_nsec;
914 fsai->valid |= FATTR_MTIME;
915 if (vap->va_vaflags & VA_UTIMES_NULL)
916 fsai->valid |= FATTR_MTIME_NOW;
918 if (vap->va_mode != (mode_t)VNOVAL) {
919 fsai->mode = vap->va_mode & ALLPERMS;
920 fsai->valid |= FATTR_MODE;
926 if ((err = fdisp_wait_answ(&fdi)))
928 vtyp = IFTOVT(((struct fuse_attr_out *)fdi.answ)->attr.mode);
930 if (vnode_vtype(vp) != vtyp) {
931 if (vnode_vtype(vp) == VNON && vtyp != VNON) {
932 SDT_PROBE2(fusefs, , internal, trace, 1, "FUSE: Dang! "
933 "vnode_vtype is VNON and vtype isn't.");
938 * The vnode has changed its type "behind our back".
939 * There's nothing really we can do, so let us just
940 * force an internal revocation and tell the caller to
941 * try again, if interested.
943 fuse_internal_vnode_disappear(vp);
948 struct fuse_attr_out *fao = (struct fuse_attr_out*)fdi.answ;
949 fuse_internal_cache_attrs(vp, cred, &fao->attr, fao->attr_valid,
950 fao->attr_valid_nsec, NULL);
958 #ifdef ZERO_PAD_INCOMPLETE_BUFS
960 isbzero(void *buf, size_t len)
964 for (i = 0; i < len; i++) {
965 if (((char *)buf)[i])