2 FUSE: Filesystem in Userspace
5 This program can be distributed under the terms of the GNU GPL.
11 #include <linux/pagemap.h>
12 #include <linux/file.h>
13 #include <linux/fs_context.h>
14 #include <linux/sched.h>
15 #include <linux/namei.h>
16 #include <linux/slab.h>
17 #include <linux/xattr.h>
18 #include <linux/iversion.h>
19 #include <linux/posix_acl.h>
21 static void fuse_advise_use_readdirplus(struct inode *dir)
23 struct fuse_inode *fi = get_fuse_inode(dir);
25 set_bit(FUSE_I_ADVISE_RDPLUS, &fi->state);
28 #if BITS_PER_LONG >= 64
29 static inline void __fuse_dentry_settime(struct dentry *entry, u64 time)
31 entry->d_fsdata = (void *) time;
34 static inline u64 fuse_dentry_time(const struct dentry *entry)
36 return (u64)entry->d_fsdata;
45 static inline void __fuse_dentry_settime(struct dentry *dentry, u64 time)
47 ((union fuse_dentry *) dentry->d_fsdata)->time = time;
50 static inline u64 fuse_dentry_time(const struct dentry *entry)
52 return ((union fuse_dentry *) entry->d_fsdata)->time;
56 static void fuse_dentry_settime(struct dentry *dentry, u64 time)
58 struct fuse_conn *fc = get_fuse_conn_super(dentry->d_sb);
59 bool delete = !time && fc->delete_stale;
61 * Mess with DCACHE_OP_DELETE because dput() will be faster without it.
62 * Don't care about races, either way it's just an optimization
64 if ((!delete && (dentry->d_flags & DCACHE_OP_DELETE)) ||
65 (delete && !(dentry->d_flags & DCACHE_OP_DELETE))) {
66 spin_lock(&dentry->d_lock);
68 dentry->d_flags &= ~DCACHE_OP_DELETE;
70 dentry->d_flags |= DCACHE_OP_DELETE;
71 spin_unlock(&dentry->d_lock);
74 __fuse_dentry_settime(dentry, time);
78 * FUSE caches dentries and attributes with separate timeout. The
79 * time in jiffies until the dentry/attributes are valid is stored in
80 * dentry->d_fsdata and fuse_inode->i_time respectively.
84 * Calculate the time in jiffies until a dentry/attributes are valid
86 static u64 time_to_jiffies(u64 sec, u32 nsec)
89 struct timespec64 ts = {
91 min_t(u32, nsec, NSEC_PER_SEC - 1)
94 return get_jiffies_64() + timespec64_to_jiffies(&ts);
100 * Set dentry and possibly attribute timeouts from the lookup/mk*
103 void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o)
105 fuse_dentry_settime(entry,
106 time_to_jiffies(o->entry_valid, o->entry_valid_nsec));
109 static u64 attr_timeout(struct fuse_attr_out *o)
111 return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
114 u64 entry_attr_timeout(struct fuse_entry_out *o)
116 return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
119 static void fuse_invalidate_attr_mask(struct inode *inode, u32 mask)
121 set_mask_bits(&get_fuse_inode(inode)->inval_mask, 0, mask);
125 * Mark the attributes as stale, so that at the next call to
126 * ->getattr() they will be fetched from userspace
128 void fuse_invalidate_attr(struct inode *inode)
130 fuse_invalidate_attr_mask(inode, STATX_BASIC_STATS);
133 static void fuse_dir_changed(struct inode *dir)
135 fuse_invalidate_attr(dir);
136 inode_maybe_inc_iversion(dir, false);
140 * Mark the attributes as stale due to an atime change. Avoid the invalidate if
143 void fuse_invalidate_atime(struct inode *inode)
145 if (!IS_RDONLY(inode))
146 fuse_invalidate_attr_mask(inode, STATX_ATIME);
150 * Just mark the entry as stale, so that a next attempt to look it up
151 * will result in a new lookup call to userspace
153 * This is called when a dentry is about to become negative and the
154 * timeout is unknown (unlink, rmdir, rename and in some cases
157 void fuse_invalidate_entry_cache(struct dentry *entry)
159 fuse_dentry_settime(entry, 0);
163 * Same as fuse_invalidate_entry_cache(), but also try to remove the
164 * dentry from the hash
166 static void fuse_invalidate_entry(struct dentry *entry)
169 fuse_invalidate_entry_cache(entry);
172 static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args,
173 u64 nodeid, const struct qstr *name,
174 struct fuse_entry_out *outarg)
176 memset(outarg, 0, sizeof(struct fuse_entry_out));
177 args->opcode = FUSE_LOOKUP;
178 args->nodeid = nodeid;
179 args->in_numargs = 1;
180 args->in_args[0].size = name->len + 1;
181 args->in_args[0].value = name->name;
182 args->out_numargs = 1;
183 args->out_args[0].size = sizeof(struct fuse_entry_out);
184 args->out_args[0].value = outarg;
188 * Check whether the dentry is still valid
190 * If the entry validity timeout has expired and the dentry is
191 * positive, try to redo the lookup. If the lookup results in a
192 * different inode, then let the VFS invalidate the dentry and redo
193 * the lookup once more. If the lookup results in the same inode,
194 * then refresh the attributes, timeouts and mark the dentry valid.
196 static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
199 struct dentry *parent;
200 struct fuse_mount *fm;
201 struct fuse_inode *fi;
204 inode = d_inode_rcu(entry);
205 if (inode && is_bad_inode(inode))
207 else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) ||
208 (flags & LOOKUP_REVAL)) {
209 struct fuse_entry_out outarg;
211 struct fuse_forget_link *forget;
214 /* For negative dentries, always do a fresh lookup */
219 if (flags & LOOKUP_RCU)
222 fm = get_fuse_mount(inode);
224 forget = fuse_alloc_forget();
229 attr_version = fuse_get_attr_version(fm->fc);
231 parent = dget_parent(entry);
232 fuse_lookup_init(fm->fc, &args, get_node_id(d_inode(parent)),
233 &entry->d_name, &outarg);
234 ret = fuse_simple_request(fm, &args);
236 /* Zero nodeid is same as -ENOENT */
237 if (!ret && !outarg.nodeid)
240 fi = get_fuse_inode(inode);
241 if (outarg.nodeid != get_node_id(inode) ||
242 (bool) IS_AUTOMOUNT(inode) != (bool) (outarg.attr.flags & FUSE_ATTR_SUBMOUNT)) {
243 fuse_queue_forget(fm->fc, forget,
247 spin_lock(&fi->lock);
249 spin_unlock(&fi->lock);
254 if (ret || fuse_invalid_attr(&outarg.attr) ||
255 (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
258 forget_all_cached_acls(inode);
259 fuse_change_attributes(inode, &outarg.attr,
260 entry_attr_timeout(&outarg),
262 fuse_change_entry_timeout(entry, &outarg);
264 fi = get_fuse_inode(inode);
265 if (flags & LOOKUP_RCU) {
266 if (test_bit(FUSE_I_INIT_RDPLUS, &fi->state))
268 } else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) {
269 parent = dget_parent(entry);
270 fuse_advise_use_readdirplus(d_inode(parent));
283 #if BITS_PER_LONG < 64
284 static int fuse_dentry_init(struct dentry *dentry)
286 dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry),
287 GFP_KERNEL_ACCOUNT | __GFP_RECLAIMABLE);
289 return dentry->d_fsdata ? 0 : -ENOMEM;
291 static void fuse_dentry_release(struct dentry *dentry)
293 union fuse_dentry *fd = dentry->d_fsdata;
299 static int fuse_dentry_delete(const struct dentry *dentry)
301 return time_before64(fuse_dentry_time(dentry), get_jiffies_64());
305 * Create a fuse_mount object with a new superblock (with path->dentry
306 * as the root), and return that mount so it can be auto-mounted on
309 static struct vfsmount *fuse_dentry_automount(struct path *path)
311 struct fs_context *fsc;
312 struct fuse_mount *parent_fm = get_fuse_mount_super(path->mnt->mnt_sb);
313 struct fuse_conn *fc = parent_fm->fc;
314 struct fuse_mount *fm;
315 struct vfsmount *mnt;
316 struct fuse_inode *mp_fi = get_fuse_inode(d_inode(path->dentry));
317 struct super_block *sb;
320 fsc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry);
327 fm = kzalloc(sizeof(struct fuse_mount), GFP_KERNEL);
331 refcount_set(&fm->count, 1);
333 sb = sget_fc(fsc, NULL, set_anon_super_fc);
339 fm->fc = fuse_conn_get(fc);
341 /* Initialize superblock, making @mp_fi its root */
342 err = fuse_fill_super_submount(sb, mp_fi);
346 sb->s_flags |= SB_ACTIVE;
347 fsc->root = dget(sb->s_root);
348 /* We are done configuring the superblock, so unlock it */
349 up_write(&sb->s_umount);
351 down_write(&fc->killsb);
352 list_add_tail(&fm->fc_entry, &fc->mounts);
353 up_write(&fc->killsb);
355 /* Create the submount */
356 mnt = vfs_create_mount(fsc);
367 * Only jump here when fsc->root is NULL and sb is still locked
368 * (otherwise put_fs_context() will put the superblock)
370 deactivate_locked_super(sb);
377 const struct dentry_operations fuse_dentry_operations = {
378 .d_revalidate = fuse_dentry_revalidate,
379 .d_delete = fuse_dentry_delete,
380 #if BITS_PER_LONG < 64
381 .d_init = fuse_dentry_init,
382 .d_release = fuse_dentry_release,
384 .d_automount = fuse_dentry_automount,
387 const struct dentry_operations fuse_root_dentry_operations = {
388 #if BITS_PER_LONG < 64
389 .d_init = fuse_dentry_init,
390 .d_release = fuse_dentry_release,
394 int fuse_valid_type(int m)
396 return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
397 S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
400 bool fuse_invalid_attr(struct fuse_attr *attr)
402 return !fuse_valid_type(attr->mode) ||
403 attr->size > LLONG_MAX;
406 int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
407 struct fuse_entry_out *outarg, struct inode **inode)
409 struct fuse_mount *fm = get_fuse_mount_super(sb);
411 struct fuse_forget_link *forget;
417 if (name->len > FUSE_NAME_MAX)
421 forget = fuse_alloc_forget();
426 attr_version = fuse_get_attr_version(fm->fc);
428 fuse_lookup_init(fm->fc, &args, nodeid, name, outarg);
429 err = fuse_simple_request(fm, &args);
430 /* Zero nodeid is same as -ENOENT, but with valid timeout */
431 if (err || !outarg->nodeid)
437 if (fuse_invalid_attr(&outarg->attr))
440 *inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
441 &outarg->attr, entry_attr_timeout(outarg),
445 fuse_queue_forget(fm->fc, forget, outarg->nodeid, 1);
456 static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
460 struct fuse_entry_out outarg;
462 struct dentry *newent;
463 bool outarg_valid = true;
466 locked = fuse_lock_inode(dir);
467 err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
469 fuse_unlock_inode(dir, locked);
470 if (err == -ENOENT) {
471 outarg_valid = false;
478 if (inode && get_node_id(inode) == FUSE_ROOT_ID)
481 newent = d_splice_alias(inode, entry);
482 err = PTR_ERR(newent);
486 entry = newent ? newent : entry;
488 fuse_change_entry_timeout(entry, &outarg);
490 fuse_invalidate_entry_cache(entry);
493 fuse_advise_use_readdirplus(dir);
503 * Atomic create+open operation
505 * If the filesystem doesn't support this, then fall back to separate
506 * 'mknod' + 'open' requests.
508 static int fuse_create_open(struct inode *dir, struct dentry *entry,
509 struct file *file, unsigned flags,
514 struct fuse_mount *fm = get_fuse_mount(dir);
516 struct fuse_forget_link *forget;
517 struct fuse_create_in inarg;
518 struct fuse_open_out outopen;
519 struct fuse_entry_out outentry;
520 struct fuse_inode *fi;
521 struct fuse_file *ff;
523 /* Userspace expects S_IFREG in create mode */
524 BUG_ON((mode & S_IFMT) != S_IFREG);
526 forget = fuse_alloc_forget();
532 ff = fuse_file_alloc(fm);
534 goto out_put_forget_req;
536 if (!fm->fc->dont_mask)
537 mode &= ~current_umask();
540 memset(&inarg, 0, sizeof(inarg));
541 memset(&outentry, 0, sizeof(outentry));
544 inarg.umask = current_umask();
545 args.opcode = FUSE_CREATE;
546 args.nodeid = get_node_id(dir);
548 args.in_args[0].size = sizeof(inarg);
549 args.in_args[0].value = &inarg;
550 args.in_args[1].size = entry->d_name.len + 1;
551 args.in_args[1].value = entry->d_name.name;
552 args.out_numargs = 2;
553 args.out_args[0].size = sizeof(outentry);
554 args.out_args[0].value = &outentry;
555 args.out_args[1].size = sizeof(outopen);
556 args.out_args[1].value = &outopen;
557 err = fuse_simple_request(fm, &args);
562 if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid) ||
563 fuse_invalid_attr(&outentry.attr))
567 ff->nodeid = outentry.nodeid;
568 ff->open_flags = outopen.open_flags;
569 inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
570 &outentry.attr, entry_attr_timeout(&outentry), 0);
572 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
573 fuse_sync_release(NULL, ff, flags);
574 fuse_queue_forget(fm->fc, forget, outentry.nodeid, 1);
579 d_instantiate(entry, inode);
580 fuse_change_entry_timeout(entry, &outentry);
581 fuse_dir_changed(dir);
582 err = finish_open(file, entry, generic_file_open);
584 fi = get_fuse_inode(inode);
585 fuse_sync_release(fi, ff, flags);
587 file->private_data = ff;
588 fuse_finish_open(inode, file);
600 static int fuse_mknod(struct inode *, struct dentry *, umode_t, dev_t);
601 static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
602 struct file *file, unsigned flags,
606 struct fuse_conn *fc = get_fuse_conn(dir);
607 struct dentry *res = NULL;
609 if (d_in_lookup(entry)) {
610 res = fuse_lookup(dir, entry, 0);
618 if (!(flags & O_CREAT) || d_really_is_positive(entry))
622 file->f_mode |= FMODE_CREATED;
627 err = fuse_create_open(dir, entry, file, flags, mode);
628 if (err == -ENOSYS) {
637 err = fuse_mknod(dir, entry, mode, 0);
641 return finish_no_open(file, res);
645 * Code shared between mknod, mkdir, symlink and link
647 static int create_new_entry(struct fuse_mount *fm, struct fuse_args *args,
648 struct inode *dir, struct dentry *entry,
651 struct fuse_entry_out outarg;
655 struct fuse_forget_link *forget;
657 forget = fuse_alloc_forget();
661 memset(&outarg, 0, sizeof(outarg));
662 args->nodeid = get_node_id(dir);
663 args->out_numargs = 1;
664 args->out_args[0].size = sizeof(outarg);
665 args->out_args[0].value = &outarg;
666 err = fuse_simple_request(fm, args);
668 goto out_put_forget_req;
671 if (invalid_nodeid(outarg.nodeid) || fuse_invalid_attr(&outarg.attr))
672 goto out_put_forget_req;
674 if ((outarg.attr.mode ^ mode) & S_IFMT)
675 goto out_put_forget_req;
677 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
678 &outarg.attr, entry_attr_timeout(&outarg), 0);
680 fuse_queue_forget(fm->fc, forget, outarg.nodeid, 1);
686 d = d_splice_alias(inode, entry);
691 fuse_change_entry_timeout(d, &outarg);
694 fuse_change_entry_timeout(entry, &outarg);
696 fuse_dir_changed(dir);
704 static int fuse_mknod(struct inode *dir, struct dentry *entry, umode_t mode,
707 struct fuse_mknod_in inarg;
708 struct fuse_mount *fm = get_fuse_mount(dir);
711 if (!fm->fc->dont_mask)
712 mode &= ~current_umask();
714 memset(&inarg, 0, sizeof(inarg));
716 inarg.rdev = new_encode_dev(rdev);
717 inarg.umask = current_umask();
718 args.opcode = FUSE_MKNOD;
720 args.in_args[0].size = sizeof(inarg);
721 args.in_args[0].value = &inarg;
722 args.in_args[1].size = entry->d_name.len + 1;
723 args.in_args[1].value = entry->d_name.name;
724 return create_new_entry(fm, &args, dir, entry, mode);
727 static int fuse_create(struct inode *dir, struct dentry *entry, umode_t mode,
730 return fuse_mknod(dir, entry, mode, 0);
733 static int fuse_mkdir(struct inode *dir, struct dentry *entry, umode_t mode)
735 struct fuse_mkdir_in inarg;
736 struct fuse_mount *fm = get_fuse_mount(dir);
739 if (!fm->fc->dont_mask)
740 mode &= ~current_umask();
742 memset(&inarg, 0, sizeof(inarg));
744 inarg.umask = current_umask();
745 args.opcode = FUSE_MKDIR;
747 args.in_args[0].size = sizeof(inarg);
748 args.in_args[0].value = &inarg;
749 args.in_args[1].size = entry->d_name.len + 1;
750 args.in_args[1].value = entry->d_name.name;
751 return create_new_entry(fm, &args, dir, entry, S_IFDIR);
754 static int fuse_symlink(struct inode *dir, struct dentry *entry,
757 struct fuse_mount *fm = get_fuse_mount(dir);
758 unsigned len = strlen(link) + 1;
761 args.opcode = FUSE_SYMLINK;
763 args.in_args[0].size = entry->d_name.len + 1;
764 args.in_args[0].value = entry->d_name.name;
765 args.in_args[1].size = len;
766 args.in_args[1].value = link;
767 return create_new_entry(fm, &args, dir, entry, S_IFLNK);
770 void fuse_update_ctime(struct inode *inode)
772 if (!IS_NOCMTIME(inode)) {
773 inode->i_ctime = current_time(inode);
774 mark_inode_dirty_sync(inode);
778 static int fuse_unlink(struct inode *dir, struct dentry *entry)
781 struct fuse_mount *fm = get_fuse_mount(dir);
784 args.opcode = FUSE_UNLINK;
785 args.nodeid = get_node_id(dir);
787 args.in_args[0].size = entry->d_name.len + 1;
788 args.in_args[0].value = entry->d_name.name;
789 err = fuse_simple_request(fm, &args);
791 struct inode *inode = d_inode(entry);
792 struct fuse_inode *fi = get_fuse_inode(inode);
794 spin_lock(&fi->lock);
795 fi->attr_version = atomic64_inc_return(&fm->fc->attr_version);
797 * If i_nlink == 0 then unlink doesn't make sense, yet this can
798 * happen if userspace filesystem is careless. It would be
799 * difficult to enforce correct nlink usage so just ignore this
802 if (inode->i_nlink > 0)
804 spin_unlock(&fi->lock);
805 fuse_invalidate_attr(inode);
806 fuse_dir_changed(dir);
807 fuse_invalidate_entry_cache(entry);
808 fuse_update_ctime(inode);
809 } else if (err == -EINTR)
810 fuse_invalidate_entry(entry);
814 static int fuse_rmdir(struct inode *dir, struct dentry *entry)
817 struct fuse_mount *fm = get_fuse_mount(dir);
820 args.opcode = FUSE_RMDIR;
821 args.nodeid = get_node_id(dir);
823 args.in_args[0].size = entry->d_name.len + 1;
824 args.in_args[0].value = entry->d_name.name;
825 err = fuse_simple_request(fm, &args);
827 clear_nlink(d_inode(entry));
828 fuse_dir_changed(dir);
829 fuse_invalidate_entry_cache(entry);
830 } else if (err == -EINTR)
831 fuse_invalidate_entry(entry);
835 static int fuse_rename_common(struct inode *olddir, struct dentry *oldent,
836 struct inode *newdir, struct dentry *newent,
837 unsigned int flags, int opcode, size_t argsize)
840 struct fuse_rename2_in inarg;
841 struct fuse_mount *fm = get_fuse_mount(olddir);
844 memset(&inarg, 0, argsize);
845 inarg.newdir = get_node_id(newdir);
847 args.opcode = opcode;
848 args.nodeid = get_node_id(olddir);
850 args.in_args[0].size = argsize;
851 args.in_args[0].value = &inarg;
852 args.in_args[1].size = oldent->d_name.len + 1;
853 args.in_args[1].value = oldent->d_name.name;
854 args.in_args[2].size = newent->d_name.len + 1;
855 args.in_args[2].value = newent->d_name.name;
856 err = fuse_simple_request(fm, &args);
859 fuse_invalidate_attr(d_inode(oldent));
860 fuse_update_ctime(d_inode(oldent));
862 if (flags & RENAME_EXCHANGE) {
863 fuse_invalidate_attr(d_inode(newent));
864 fuse_update_ctime(d_inode(newent));
867 fuse_dir_changed(olddir);
868 if (olddir != newdir)
869 fuse_dir_changed(newdir);
871 /* newent will end up negative */
872 if (!(flags & RENAME_EXCHANGE) && d_really_is_positive(newent)) {
873 fuse_invalidate_attr(d_inode(newent));
874 fuse_invalidate_entry_cache(newent);
875 fuse_update_ctime(d_inode(newent));
877 } else if (err == -EINTR) {
878 /* If request was interrupted, DEITY only knows if the
879 rename actually took place. If the invalidation
880 fails (e.g. some process has CWD under the renamed
881 directory), then there can be inconsistency between
882 the dcache and the real filesystem. Tough luck. */
883 fuse_invalidate_entry(oldent);
884 if (d_really_is_positive(newent))
885 fuse_invalidate_entry(newent);
891 static int fuse_rename2(struct inode *olddir, struct dentry *oldent,
892 struct inode *newdir, struct dentry *newent,
895 struct fuse_conn *fc = get_fuse_conn(olddir);
898 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE | RENAME_WHITEOUT))
902 if (fc->no_rename2 || fc->minor < 23)
905 err = fuse_rename_common(olddir, oldent, newdir, newent, flags,
907 sizeof(struct fuse_rename2_in));
908 if (err == -ENOSYS) {
913 err = fuse_rename_common(olddir, oldent, newdir, newent, 0,
915 sizeof(struct fuse_rename_in));
921 static int fuse_link(struct dentry *entry, struct inode *newdir,
922 struct dentry *newent)
925 struct fuse_link_in inarg;
926 struct inode *inode = d_inode(entry);
927 struct fuse_mount *fm = get_fuse_mount(inode);
930 memset(&inarg, 0, sizeof(inarg));
931 inarg.oldnodeid = get_node_id(inode);
932 args.opcode = FUSE_LINK;
934 args.in_args[0].size = sizeof(inarg);
935 args.in_args[0].value = &inarg;
936 args.in_args[1].size = newent->d_name.len + 1;
937 args.in_args[1].value = newent->d_name.name;
938 err = create_new_entry(fm, &args, newdir, newent, inode->i_mode);
939 /* Contrary to "normal" filesystems it can happen that link
940 makes two "logical" inodes point to the same "physical"
941 inode. We invalidate the attributes of the old one, so it
942 will reflect changes in the backing inode (link count,
946 struct fuse_inode *fi = get_fuse_inode(inode);
948 spin_lock(&fi->lock);
949 fi->attr_version = atomic64_inc_return(&fm->fc->attr_version);
950 if (likely(inode->i_nlink < UINT_MAX))
952 spin_unlock(&fi->lock);
953 fuse_invalidate_attr(inode);
954 fuse_update_ctime(inode);
955 } else if (err == -EINTR) {
956 fuse_invalidate_attr(inode);
961 static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr,
964 unsigned int blkbits;
965 struct fuse_conn *fc = get_fuse_conn(inode);
967 /* see the comment in fuse_change_attributes() */
968 if (fc->writeback_cache && S_ISREG(inode->i_mode)) {
969 attr->size = i_size_read(inode);
970 attr->mtime = inode->i_mtime.tv_sec;
971 attr->mtimensec = inode->i_mtime.tv_nsec;
972 attr->ctime = inode->i_ctime.tv_sec;
973 attr->ctimensec = inode->i_ctime.tv_nsec;
976 stat->dev = inode->i_sb->s_dev;
977 stat->ino = attr->ino;
978 stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
979 stat->nlink = attr->nlink;
980 stat->uid = make_kuid(fc->user_ns, attr->uid);
981 stat->gid = make_kgid(fc->user_ns, attr->gid);
982 stat->rdev = inode->i_rdev;
983 stat->atime.tv_sec = attr->atime;
984 stat->atime.tv_nsec = attr->atimensec;
985 stat->mtime.tv_sec = attr->mtime;
986 stat->mtime.tv_nsec = attr->mtimensec;
987 stat->ctime.tv_sec = attr->ctime;
988 stat->ctime.tv_nsec = attr->ctimensec;
989 stat->size = attr->size;
990 stat->blocks = attr->blocks;
992 if (attr->blksize != 0)
993 blkbits = ilog2(attr->blksize);
995 blkbits = inode->i_sb->s_blocksize_bits;
997 stat->blksize = 1 << blkbits;
1000 static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
1004 struct fuse_getattr_in inarg;
1005 struct fuse_attr_out outarg;
1006 struct fuse_mount *fm = get_fuse_mount(inode);
1010 attr_version = fuse_get_attr_version(fm->fc);
1012 memset(&inarg, 0, sizeof(inarg));
1013 memset(&outarg, 0, sizeof(outarg));
1014 /* Directories have separate file-handle space */
1015 if (file && S_ISREG(inode->i_mode)) {
1016 struct fuse_file *ff = file->private_data;
1018 inarg.getattr_flags |= FUSE_GETATTR_FH;
1021 args.opcode = FUSE_GETATTR;
1022 args.nodeid = get_node_id(inode);
1023 args.in_numargs = 1;
1024 args.in_args[0].size = sizeof(inarg);
1025 args.in_args[0].value = &inarg;
1026 args.out_numargs = 1;
1027 args.out_args[0].size = sizeof(outarg);
1028 args.out_args[0].value = &outarg;
1029 err = fuse_simple_request(fm, &args);
1031 if (fuse_invalid_attr(&outarg.attr) ||
1032 (inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1033 make_bad_inode(inode);
1036 fuse_change_attributes(inode, &outarg.attr,
1037 attr_timeout(&outarg),
1040 fuse_fillattr(inode, &outarg.attr, stat);
1046 static int fuse_update_get_attr(struct inode *inode, struct file *file,
1047 struct kstat *stat, u32 request_mask,
1050 struct fuse_inode *fi = get_fuse_inode(inode);
1054 if (flags & AT_STATX_FORCE_SYNC)
1056 else if (flags & AT_STATX_DONT_SYNC)
1058 else if (request_mask & READ_ONCE(fi->inval_mask))
1061 sync = time_before64(fi->i_time, get_jiffies_64());
1064 forget_all_cached_acls(inode);
1065 err = fuse_do_getattr(inode, stat, file);
1067 generic_fillattr(inode, stat);
1068 stat->mode = fi->orig_i_mode;
1069 stat->ino = fi->orig_ino;
1075 int fuse_update_attributes(struct inode *inode, struct file *file)
1077 /* Do *not* need to get atime for internal purposes */
1078 return fuse_update_get_attr(inode, file, NULL,
1079 STATX_BASIC_STATS & ~STATX_ATIME, 0);
1082 int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
1083 u64 child_nodeid, struct qstr *name)
1086 struct inode *parent;
1088 struct dentry *entry;
1090 parent = fuse_ilookup(fc, parent_nodeid, NULL);
1095 if (!S_ISDIR(parent->i_mode))
1099 dir = d_find_alias(parent);
1103 name->hash = full_name_hash(dir, name->name, name->len);
1104 entry = d_lookup(dir, name);
1109 fuse_dir_changed(parent);
1110 fuse_invalidate_entry(entry);
1112 if (child_nodeid != 0 && d_really_is_positive(entry)) {
1113 inode_lock(d_inode(entry));
1114 if (get_node_id(d_inode(entry)) != child_nodeid) {
1118 if (d_mountpoint(entry)) {
1122 if (d_is_dir(entry)) {
1123 shrink_dcache_parent(entry);
1124 if (!simple_empty(entry)) {
1128 d_inode(entry)->i_flags |= S_DEAD;
1131 clear_nlink(d_inode(entry));
1134 inode_unlock(d_inode(entry));
1143 inode_unlock(parent);
1149 * Calling into a user-controlled filesystem gives the filesystem
1150 * daemon ptrace-like capabilities over the current process. This
1151 * means, that the filesystem daemon is able to record the exact
1152 * filesystem operations performed, and can also control the behavior
1153 * of the requester process in otherwise impossible ways. For example
1154 * it can delay the operation for arbitrary length of time allowing
1155 * DoS against the requester.
1157 * For this reason only those processes can call into the filesystem,
1158 * for which the owner of the mount has ptrace privilege. This
1159 * excludes processes started by other users, suid or sgid processes.
1161 int fuse_allow_current_process(struct fuse_conn *fc)
1163 const struct cred *cred;
1165 if (fc->allow_other)
1166 return current_in_userns(fc->user_ns);
1168 cred = current_cred();
1169 if (uid_eq(cred->euid, fc->user_id) &&
1170 uid_eq(cred->suid, fc->user_id) &&
1171 uid_eq(cred->uid, fc->user_id) &&
1172 gid_eq(cred->egid, fc->group_id) &&
1173 gid_eq(cred->sgid, fc->group_id) &&
1174 gid_eq(cred->gid, fc->group_id))
1180 static int fuse_access(struct inode *inode, int mask)
1182 struct fuse_mount *fm = get_fuse_mount(inode);
1184 struct fuse_access_in inarg;
1187 BUG_ON(mask & MAY_NOT_BLOCK);
1189 if (fm->fc->no_access)
1192 memset(&inarg, 0, sizeof(inarg));
1193 inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC);
1194 args.opcode = FUSE_ACCESS;
1195 args.nodeid = get_node_id(inode);
1196 args.in_numargs = 1;
1197 args.in_args[0].size = sizeof(inarg);
1198 args.in_args[0].value = &inarg;
1199 err = fuse_simple_request(fm, &args);
1200 if (err == -ENOSYS) {
1201 fm->fc->no_access = 1;
1207 static int fuse_perm_getattr(struct inode *inode, int mask)
1209 if (mask & MAY_NOT_BLOCK)
1212 forget_all_cached_acls(inode);
1213 return fuse_do_getattr(inode, NULL, NULL);
1217 * Check permission. The two basic access models of FUSE are:
1219 * 1) Local access checking ('default_permissions' mount option) based
1220 * on file mode. This is the plain old disk filesystem permission
1223 * 2) "Remote" access checking, where server is responsible for
1224 * checking permission in each inode operation. An exception to this
1225 * is if ->permission() was invoked from sys_access() in which case an
1226 * access request is sent. Execute permission is still checked
1227 * locally based on file mode.
1229 static int fuse_permission(struct inode *inode, int mask)
1231 struct fuse_conn *fc = get_fuse_conn(inode);
1232 bool refreshed = false;
1235 if (!fuse_allow_current_process(fc))
1239 * If attributes are needed, refresh them before proceeding
1241 if (fc->default_permissions ||
1242 ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
1243 struct fuse_inode *fi = get_fuse_inode(inode);
1244 u32 perm_mask = STATX_MODE | STATX_UID | STATX_GID;
1246 if (perm_mask & READ_ONCE(fi->inval_mask) ||
1247 time_before64(fi->i_time, get_jiffies_64())) {
1250 err = fuse_perm_getattr(inode, mask);
1256 if (fc->default_permissions) {
1257 err = generic_permission(inode, mask);
1259 /* If permission is denied, try to refresh file
1260 attributes. This is also needed, because the root
1261 node will at first have no permissions */
1262 if (err == -EACCES && !refreshed) {
1263 err = fuse_perm_getattr(inode, mask);
1265 err = generic_permission(inode, mask);
1268 /* Note: the opposite of the above test does not
1269 exist. So if permissions are revoked this won't be
1270 noticed immediately, only after the attribute
1271 timeout has expired */
1272 } else if (mask & (MAY_ACCESS | MAY_CHDIR)) {
1273 err = fuse_access(inode, mask);
1274 } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
1275 if (!(inode->i_mode & S_IXUGO)) {
1279 err = fuse_perm_getattr(inode, mask);
1280 if (!err && !(inode->i_mode & S_IXUGO))
1287 static int fuse_readlink_page(struct inode *inode, struct page *page)
1289 struct fuse_mount *fm = get_fuse_mount(inode);
1290 struct fuse_page_desc desc = { .length = PAGE_SIZE - 1 };
1291 struct fuse_args_pages ap = {
1299 ap.args.opcode = FUSE_READLINK;
1300 ap.args.nodeid = get_node_id(inode);
1301 ap.args.out_pages = true;
1302 ap.args.out_argvar = true;
1303 ap.args.page_zeroing = true;
1304 ap.args.out_numargs = 1;
1305 ap.args.out_args[0].size = desc.length;
1306 res = fuse_simple_request(fm, &ap.args);
1308 fuse_invalidate_atime(inode);
1313 if (WARN_ON(res >= PAGE_SIZE))
1316 link = page_address(page);
1322 static const char *fuse_get_link(struct dentry *dentry, struct inode *inode,
1323 struct delayed_call *callback)
1325 struct fuse_conn *fc = get_fuse_conn(inode);
1330 if (is_bad_inode(inode))
1333 if (fc->cache_symlinks)
1334 return page_get_link(dentry, inode, callback);
1340 page = alloc_page(GFP_KERNEL);
1345 err = fuse_readlink_page(inode, page);
1351 set_delayed_call(callback, page_put_link, page);
1353 return page_address(page);
1356 return ERR_PTR(err);
1359 static int fuse_dir_open(struct inode *inode, struct file *file)
1361 return fuse_open_common(inode, file, true);
1364 static int fuse_dir_release(struct inode *inode, struct file *file)
1366 fuse_release_common(file, true);
1371 static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
1374 struct inode *inode = file->f_mapping->host;
1375 struct fuse_conn *fc = get_fuse_conn(inode);
1378 if (is_bad_inode(inode))
1381 if (fc->no_fsyncdir)
1385 err = fuse_fsync_common(file, start, end, datasync, FUSE_FSYNCDIR);
1386 if (err == -ENOSYS) {
1387 fc->no_fsyncdir = 1;
1390 inode_unlock(inode);
1395 static long fuse_dir_ioctl(struct file *file, unsigned int cmd,
1398 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1400 /* FUSE_IOCTL_DIR only supported for API version >= 7.18 */
1404 return fuse_ioctl_common(file, cmd, arg, FUSE_IOCTL_DIR);
1407 static long fuse_dir_compat_ioctl(struct file *file, unsigned int cmd,
1410 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1415 return fuse_ioctl_common(file, cmd, arg,
1416 FUSE_IOCTL_COMPAT | FUSE_IOCTL_DIR);
1419 static bool update_mtime(unsigned ivalid, bool trust_local_mtime)
1421 /* Always update if mtime is explicitly set */
1422 if (ivalid & ATTR_MTIME_SET)
1425 /* Or if kernel i_mtime is the official one */
1426 if (trust_local_mtime)
1429 /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
1430 if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
1433 /* In all other cases update */
1437 static void iattr_to_fattr(struct fuse_conn *fc, struct iattr *iattr,
1438 struct fuse_setattr_in *arg, bool trust_local_cmtime)
1440 unsigned ivalid = iattr->ia_valid;
1442 if (ivalid & ATTR_MODE)
1443 arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode;
1444 if (ivalid & ATTR_UID)
1445 arg->valid |= FATTR_UID, arg->uid = from_kuid(fc->user_ns, iattr->ia_uid);
1446 if (ivalid & ATTR_GID)
1447 arg->valid |= FATTR_GID, arg->gid = from_kgid(fc->user_ns, iattr->ia_gid);
1448 if (ivalid & ATTR_SIZE)
1449 arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size;
1450 if (ivalid & ATTR_ATIME) {
1451 arg->valid |= FATTR_ATIME;
1452 arg->atime = iattr->ia_atime.tv_sec;
1453 arg->atimensec = iattr->ia_atime.tv_nsec;
1454 if (!(ivalid & ATTR_ATIME_SET))
1455 arg->valid |= FATTR_ATIME_NOW;
1457 if ((ivalid & ATTR_MTIME) && update_mtime(ivalid, trust_local_cmtime)) {
1458 arg->valid |= FATTR_MTIME;
1459 arg->mtime = iattr->ia_mtime.tv_sec;
1460 arg->mtimensec = iattr->ia_mtime.tv_nsec;
1461 if (!(ivalid & ATTR_MTIME_SET) && !trust_local_cmtime)
1462 arg->valid |= FATTR_MTIME_NOW;
1464 if ((ivalid & ATTR_CTIME) && trust_local_cmtime) {
1465 arg->valid |= FATTR_CTIME;
1466 arg->ctime = iattr->ia_ctime.tv_sec;
1467 arg->ctimensec = iattr->ia_ctime.tv_nsec;
1472 * Prevent concurrent writepages on inode
1474 * This is done by adding a negative bias to the inode write counter
1475 * and waiting for all pending writes to finish.
1477 void fuse_set_nowrite(struct inode *inode)
1479 struct fuse_inode *fi = get_fuse_inode(inode);
1481 BUG_ON(!inode_is_locked(inode));
1483 spin_lock(&fi->lock);
1484 BUG_ON(fi->writectr < 0);
1485 fi->writectr += FUSE_NOWRITE;
1486 spin_unlock(&fi->lock);
1487 wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
1491 * Allow writepages on inode
1493 * Remove the bias from the writecounter and send any queued
1496 static void __fuse_release_nowrite(struct inode *inode)
1498 struct fuse_inode *fi = get_fuse_inode(inode);
1500 BUG_ON(fi->writectr != FUSE_NOWRITE);
1502 fuse_flush_writepages(inode);
1505 void fuse_release_nowrite(struct inode *inode)
1507 struct fuse_inode *fi = get_fuse_inode(inode);
1509 spin_lock(&fi->lock);
1510 __fuse_release_nowrite(inode);
1511 spin_unlock(&fi->lock);
1514 static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args,
1515 struct inode *inode,
1516 struct fuse_setattr_in *inarg_p,
1517 struct fuse_attr_out *outarg_p)
1519 args->opcode = FUSE_SETATTR;
1520 args->nodeid = get_node_id(inode);
1521 args->in_numargs = 1;
1522 args->in_args[0].size = sizeof(*inarg_p);
1523 args->in_args[0].value = inarg_p;
1524 args->out_numargs = 1;
1525 args->out_args[0].size = sizeof(*outarg_p);
1526 args->out_args[0].value = outarg_p;
1530 * Flush inode->i_mtime to the server
1532 int fuse_flush_times(struct inode *inode, struct fuse_file *ff)
1534 struct fuse_mount *fm = get_fuse_mount(inode);
1536 struct fuse_setattr_in inarg;
1537 struct fuse_attr_out outarg;
1539 memset(&inarg, 0, sizeof(inarg));
1540 memset(&outarg, 0, sizeof(outarg));
1542 inarg.valid = FATTR_MTIME;
1543 inarg.mtime = inode->i_mtime.tv_sec;
1544 inarg.mtimensec = inode->i_mtime.tv_nsec;
1545 if (fm->fc->minor >= 23) {
1546 inarg.valid |= FATTR_CTIME;
1547 inarg.ctime = inode->i_ctime.tv_sec;
1548 inarg.ctimensec = inode->i_ctime.tv_nsec;
1551 inarg.valid |= FATTR_FH;
1554 fuse_setattr_fill(fm->fc, &args, inode, &inarg, &outarg);
1556 return fuse_simple_request(fm, &args);
1560 * Set attributes, and at the same time refresh them.
1562 * Truncation is slightly complicated, because the 'truncate' request
1563 * may fail, in which case we don't want to touch the mapping.
1564 * vmtruncate() doesn't allow for this case, so do the rlimit checking
1565 * and the actual truncation by hand.
1567 int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1570 struct inode *inode = d_inode(dentry);
1571 struct fuse_mount *fm = get_fuse_mount(inode);
1572 struct fuse_conn *fc = fm->fc;
1573 struct fuse_inode *fi = get_fuse_inode(inode);
1575 struct fuse_setattr_in inarg;
1576 struct fuse_attr_out outarg;
1577 bool is_truncate = false;
1578 bool is_wb = fc->writeback_cache;
1581 bool trust_local_cmtime = is_wb && S_ISREG(inode->i_mode);
1582 bool fault_blocked = false;
1584 if (!fc->default_permissions)
1585 attr->ia_valid |= ATTR_FORCE;
1587 err = setattr_prepare(dentry, attr);
1591 if (attr->ia_valid & ATTR_SIZE) {
1592 if (WARN_ON(!S_ISREG(inode->i_mode)))
1597 if (FUSE_IS_DAX(inode) && is_truncate) {
1598 down_write(&fi->i_mmap_sem);
1599 fault_blocked = true;
1600 err = fuse_dax_break_layouts(inode, 0, 0);
1602 up_write(&fi->i_mmap_sem);
1607 if (attr->ia_valid & ATTR_OPEN) {
1608 /* This is coming from open(..., ... | O_TRUNC); */
1609 WARN_ON(!(attr->ia_valid & ATTR_SIZE));
1610 WARN_ON(attr->ia_size != 0);
1611 if (fc->atomic_o_trunc) {
1613 * No need to send request to userspace, since actual
1614 * truncation has already been done by OPEN. But still
1615 * need to truncate page cache.
1617 i_size_write(inode, 0);
1618 truncate_pagecache(inode, 0);
1624 /* Flush dirty data/metadata before non-truncate SETATTR */
1625 if (is_wb && S_ISREG(inode->i_mode) &&
1627 (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_MTIME_SET |
1629 err = write_inode_now(inode, true);
1633 fuse_set_nowrite(inode);
1634 fuse_release_nowrite(inode);
1638 fuse_set_nowrite(inode);
1639 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1640 if (trust_local_cmtime && attr->ia_size != inode->i_size)
1641 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1644 memset(&inarg, 0, sizeof(inarg));
1645 memset(&outarg, 0, sizeof(outarg));
1646 iattr_to_fattr(fc, attr, &inarg, trust_local_cmtime);
1648 struct fuse_file *ff = file->private_data;
1649 inarg.valid |= FATTR_FH;
1652 if (attr->ia_valid & ATTR_SIZE) {
1653 /* For mandatory locking in truncate */
1654 inarg.valid |= FATTR_LOCKOWNER;
1655 inarg.lock_owner = fuse_lock_owner_id(fc, current->files);
1657 fuse_setattr_fill(fc, &args, inode, &inarg, &outarg);
1658 err = fuse_simple_request(fm, &args);
1661 fuse_invalidate_attr(inode);
1665 if (fuse_invalid_attr(&outarg.attr) ||
1666 (inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1667 make_bad_inode(inode);
1672 spin_lock(&fi->lock);
1673 /* the kernel maintains i_mtime locally */
1674 if (trust_local_cmtime) {
1675 if (attr->ia_valid & ATTR_MTIME)
1676 inode->i_mtime = attr->ia_mtime;
1677 if (attr->ia_valid & ATTR_CTIME)
1678 inode->i_ctime = attr->ia_ctime;
1679 /* FIXME: clear I_DIRTY_SYNC? */
1682 fuse_change_attributes_common(inode, &outarg.attr,
1683 attr_timeout(&outarg));
1684 oldsize = inode->i_size;
1685 /* see the comment in fuse_change_attributes() */
1686 if (!is_wb || is_truncate || !S_ISREG(inode->i_mode))
1687 i_size_write(inode, outarg.attr.size);
1690 /* NOTE: this may release/reacquire fi->lock */
1691 __fuse_release_nowrite(inode);
1693 spin_unlock(&fi->lock);
1696 * Only call invalidate_inode_pages2() after removing
1697 * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
1699 if ((is_truncate || !is_wb) &&
1700 S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
1701 truncate_pagecache(inode, outarg.attr.size);
1702 invalidate_inode_pages2(inode->i_mapping);
1705 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1708 up_write(&fi->i_mmap_sem);
1714 fuse_release_nowrite(inode);
1716 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1719 up_write(&fi->i_mmap_sem);
1723 static int fuse_setattr(struct dentry *entry, struct iattr *attr)
1725 struct inode *inode = d_inode(entry);
1726 struct fuse_conn *fc = get_fuse_conn(inode);
1727 struct file *file = (attr->ia_valid & ATTR_FILE) ? attr->ia_file : NULL;
1730 if (!fuse_allow_current_process(get_fuse_conn(inode)))
1733 if (attr->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) {
1734 attr->ia_valid &= ~(ATTR_KILL_SUID | ATTR_KILL_SGID |
1738 * The only sane way to reliably kill suid/sgid is to do it in
1739 * the userspace filesystem
1741 * This should be done on write(), truncate() and chown().
1743 if (!fc->handle_killpriv) {
1745 * ia_mode calculation may have used stale i_mode.
1746 * Refresh and recalculate.
1748 ret = fuse_do_getattr(inode, NULL, file);
1752 attr->ia_mode = inode->i_mode;
1753 if (inode->i_mode & S_ISUID) {
1754 attr->ia_valid |= ATTR_MODE;
1755 attr->ia_mode &= ~S_ISUID;
1757 if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
1758 attr->ia_valid |= ATTR_MODE;
1759 attr->ia_mode &= ~S_ISGID;
1763 if (!attr->ia_valid)
1766 ret = fuse_do_setattr(entry, attr, file);
1769 * If filesystem supports acls it may have updated acl xattrs in
1770 * the filesystem, so forget cached acls for the inode.
1773 forget_all_cached_acls(inode);
1775 /* Directory mode changed, may need to revalidate access */
1776 if (d_is_dir(entry) && (attr->ia_valid & ATTR_MODE))
1777 fuse_invalidate_entry_cache(entry);
1782 static int fuse_getattr(const struct path *path, struct kstat *stat,
1783 u32 request_mask, unsigned int flags)
1785 struct inode *inode = d_inode(path->dentry);
1786 struct fuse_conn *fc = get_fuse_conn(inode);
1788 if (!fuse_allow_current_process(fc)) {
1789 if (!request_mask) {
1791 * If user explicitly requested *nothing* then don't
1792 * error out, but return st_dev only.
1794 stat->result_mask = 0;
1795 stat->dev = inode->i_sb->s_dev;
1801 return fuse_update_get_attr(inode, NULL, stat, request_mask, flags);
1804 static const struct inode_operations fuse_dir_inode_operations = {
1805 .lookup = fuse_lookup,
1806 .mkdir = fuse_mkdir,
1807 .symlink = fuse_symlink,
1808 .unlink = fuse_unlink,
1809 .rmdir = fuse_rmdir,
1810 .rename = fuse_rename2,
1812 .setattr = fuse_setattr,
1813 .create = fuse_create,
1814 .atomic_open = fuse_atomic_open,
1815 .mknod = fuse_mknod,
1816 .permission = fuse_permission,
1817 .getattr = fuse_getattr,
1818 .listxattr = fuse_listxattr,
1819 .get_acl = fuse_get_acl,
1820 .set_acl = fuse_set_acl,
1823 static const struct file_operations fuse_dir_operations = {
1824 .llseek = generic_file_llseek,
1825 .read = generic_read_dir,
1826 .iterate_shared = fuse_readdir,
1827 .open = fuse_dir_open,
1828 .release = fuse_dir_release,
1829 .fsync = fuse_dir_fsync,
1830 .unlocked_ioctl = fuse_dir_ioctl,
1831 .compat_ioctl = fuse_dir_compat_ioctl,
1834 static const struct inode_operations fuse_common_inode_operations = {
1835 .setattr = fuse_setattr,
1836 .permission = fuse_permission,
1837 .getattr = fuse_getattr,
1838 .listxattr = fuse_listxattr,
1839 .get_acl = fuse_get_acl,
1840 .set_acl = fuse_set_acl,
1843 static const struct inode_operations fuse_symlink_inode_operations = {
1844 .setattr = fuse_setattr,
1845 .get_link = fuse_get_link,
1846 .getattr = fuse_getattr,
1847 .listxattr = fuse_listxattr,
1850 void fuse_init_common(struct inode *inode)
1852 inode->i_op = &fuse_common_inode_operations;
1855 void fuse_init_dir(struct inode *inode)
1857 struct fuse_inode *fi = get_fuse_inode(inode);
1859 inode->i_op = &fuse_dir_inode_operations;
1860 inode->i_fop = &fuse_dir_operations;
1862 spin_lock_init(&fi->rdc.lock);
1863 fi->rdc.cached = false;
1866 fi->rdc.version = 0;
1869 static int fuse_symlink_readpage(struct file *null, struct page *page)
1871 int err = fuse_readlink_page(page->mapping->host, page);
1874 SetPageUptodate(page);
1881 static const struct address_space_operations fuse_symlink_aops = {
1882 .readpage = fuse_symlink_readpage,
1885 void fuse_init_symlink(struct inode *inode)
1887 inode->i_op = &fuse_symlink_inode_operations;
1888 inode->i_data.a_ops = &fuse_symlink_aops;
1889 inode_nohighmem(inode);