2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
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/sched.h>
14 #include <linux/namei.h>
15 #include <linux/slab.h>
17 static bool fuse_use_readdirplus(struct inode *dir, struct dir_context *ctx)
19 struct fuse_conn *fc = get_fuse_conn(dir);
20 struct fuse_inode *fi = get_fuse_inode(dir);
22 if (!fc->do_readdirplus)
24 if (!fc->readdirplus_auto)
26 if (test_and_clear_bit(FUSE_I_ADVISE_RDPLUS, &fi->state))
33 static void fuse_advise_use_readdirplus(struct inode *dir)
35 struct fuse_inode *fi = get_fuse_inode(dir);
37 set_bit(FUSE_I_ADVISE_RDPLUS, &fi->state);
40 #if BITS_PER_LONG >= 64
41 static inline void fuse_dentry_settime(struct dentry *entry, u64 time)
46 static inline u64 fuse_dentry_time(struct dentry *entry)
52 * On 32 bit archs store the high 32 bits of time in d_fsdata
54 static void fuse_dentry_settime(struct dentry *entry, u64 time)
57 entry->d_fsdata = (void *) (unsigned long) (time >> 32);
60 static u64 fuse_dentry_time(struct dentry *entry)
62 return (u64) entry->d_time +
63 ((u64) (unsigned long) entry->d_fsdata << 32);
68 * FUSE caches dentries and attributes with separate timeout. The
69 * time in jiffies until the dentry/attributes are valid is stored in
70 * dentry->d_time and fuse_inode->i_time respectively.
74 * Calculate the time in jiffies until a dentry/attributes are valid
76 static u64 time_to_jiffies(unsigned long sec, unsigned long nsec)
79 struct timespec ts = {sec, nsec};
80 return get_jiffies_64() + timespec_to_jiffies(&ts);
86 * Set dentry and possibly attribute timeouts from the lookup/mk*
89 static void fuse_change_entry_timeout(struct dentry *entry,
90 struct fuse_entry_out *o)
92 fuse_dentry_settime(entry,
93 time_to_jiffies(o->entry_valid, o->entry_valid_nsec));
96 static u64 attr_timeout(struct fuse_attr_out *o)
98 return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
101 static u64 entry_attr_timeout(struct fuse_entry_out *o)
103 return time_to_jiffies(o->attr_valid, o->attr_valid_nsec);
107 * Mark the attributes as stale, so that at the next call to
108 * ->getattr() they will be fetched from userspace
110 void fuse_invalidate_attr(struct inode *inode)
112 get_fuse_inode(inode)->i_time = 0;
116 * Just mark the entry as stale, so that a next attempt to look it up
117 * will result in a new lookup call to userspace
119 * This is called when a dentry is about to become negative and the
120 * timeout is unknown (unlink, rmdir, rename and in some cases
123 void fuse_invalidate_entry_cache(struct dentry *entry)
125 fuse_dentry_settime(entry, 0);
129 * Same as fuse_invalidate_entry_cache(), but also try to remove the
130 * dentry from the hash
132 static void fuse_invalidate_entry(struct dentry *entry)
135 fuse_invalidate_entry_cache(entry);
138 static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_req *req,
139 u64 nodeid, struct qstr *name,
140 struct fuse_entry_out *outarg)
142 memset(outarg, 0, sizeof(struct fuse_entry_out));
143 req->in.h.opcode = FUSE_LOOKUP;
144 req->in.h.nodeid = nodeid;
146 req->in.args[0].size = name->len + 1;
147 req->in.args[0].value = name->name;
148 req->out.numargs = 1;
150 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
152 req->out.args[0].size = sizeof(struct fuse_entry_out);
153 req->out.args[0].value = outarg;
156 u64 fuse_get_attr_version(struct fuse_conn *fc)
161 * The spin lock isn't actually needed on 64bit archs, but we
162 * don't yet care too much about such optimizations.
164 spin_lock(&fc->lock);
165 curr_version = fc->attr_version;
166 spin_unlock(&fc->lock);
172 * Check whether the dentry is still valid
174 * If the entry validity timeout has expired and the dentry is
175 * positive, try to redo the lookup. If the lookup results in a
176 * different inode, then let the VFS invalidate the dentry and redo
177 * the lookup once more. If the lookup results in the same inode,
178 * then refresh the attributes, timeouts and mark the dentry valid.
180 static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
183 struct dentry *parent;
184 struct fuse_conn *fc;
185 struct fuse_inode *fi;
188 inode = ACCESS_ONCE(entry->d_inode);
189 if (inode && is_bad_inode(inode))
191 else if (fuse_dentry_time(entry) < get_jiffies_64()) {
193 struct fuse_entry_out outarg;
194 struct fuse_req *req;
195 struct fuse_forget_link *forget;
198 /* For negative dentries, always do a fresh lookup */
203 if (flags & LOOKUP_RCU)
206 fc = get_fuse_conn(inode);
207 req = fuse_get_req_nopages(fc);
212 forget = fuse_alloc_forget();
214 fuse_put_request(fc, req);
219 attr_version = fuse_get_attr_version(fc);
221 parent = dget_parent(entry);
222 fuse_lookup_init(fc, req, get_node_id(parent->d_inode),
223 &entry->d_name, &outarg);
224 fuse_request_send(fc, req);
226 err = req->out.h.error;
227 fuse_put_request(fc, req);
228 /* Zero nodeid is same as -ENOENT */
229 if (!err && !outarg.nodeid)
232 fi = get_fuse_inode(inode);
233 if (outarg.nodeid != get_node_id(inode)) {
234 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
237 spin_lock(&fc->lock);
239 spin_unlock(&fc->lock);
242 if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
245 fuse_change_attributes(inode, &outarg.attr,
246 entry_attr_timeout(&outarg),
248 fuse_change_entry_timeout(entry, &outarg);
250 fi = get_fuse_inode(inode);
251 if (flags & LOOKUP_RCU) {
252 if (test_bit(FUSE_I_INIT_RDPLUS, &fi->state))
254 } else if (test_and_clear_bit(FUSE_I_INIT_RDPLUS, &fi->state)) {
255 parent = dget_parent(entry);
256 fuse_advise_use_readdirplus(parent->d_inode);
267 if (!(flags & LOOKUP_RCU) && check_submounts_and_drop(entry) != 0)
272 static int invalid_nodeid(u64 nodeid)
274 return !nodeid || nodeid == FUSE_ROOT_ID;
277 const struct dentry_operations fuse_dentry_operations = {
278 .d_revalidate = fuse_dentry_revalidate,
281 int fuse_valid_type(int m)
283 return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
284 S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
287 int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
288 struct fuse_entry_out *outarg, struct inode **inode)
290 struct fuse_conn *fc = get_fuse_conn_super(sb);
291 struct fuse_req *req;
292 struct fuse_forget_link *forget;
298 if (name->len > FUSE_NAME_MAX)
301 req = fuse_get_req_nopages(fc);
306 forget = fuse_alloc_forget();
309 fuse_put_request(fc, req);
313 attr_version = fuse_get_attr_version(fc);
315 fuse_lookup_init(fc, req, nodeid, name, outarg);
316 fuse_request_send(fc, req);
317 err = req->out.h.error;
318 fuse_put_request(fc, req);
319 /* Zero nodeid is same as -ENOENT, but with valid timeout */
320 if (err || !outarg->nodeid)
326 if (!fuse_valid_type(outarg->attr.mode))
329 *inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
330 &outarg->attr, entry_attr_timeout(outarg),
334 fuse_queue_forget(fc, forget, outarg->nodeid, 1);
345 static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
349 struct fuse_entry_out outarg;
351 struct dentry *newent;
352 bool outarg_valid = true;
354 err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
356 if (err == -ENOENT) {
357 outarg_valid = false;
364 if (inode && get_node_id(inode) == FUSE_ROOT_ID)
367 newent = d_materialise_unique(entry, inode);
368 err = PTR_ERR(newent);
372 entry = newent ? newent : entry;
374 fuse_change_entry_timeout(entry, &outarg);
376 fuse_invalidate_entry_cache(entry);
378 fuse_advise_use_readdirplus(dir);
388 * Atomic create+open operation
390 * If the filesystem doesn't support this, then fall back to separate
391 * 'mknod' + 'open' requests.
393 static int fuse_create_open(struct inode *dir, struct dentry *entry,
394 struct file *file, unsigned flags,
395 umode_t mode, int *opened)
399 struct fuse_conn *fc = get_fuse_conn(dir);
400 struct fuse_req *req;
401 struct fuse_forget_link *forget;
402 struct fuse_create_in inarg;
403 struct fuse_open_out outopen;
404 struct fuse_entry_out outentry;
405 struct fuse_file *ff;
407 /* Userspace expects S_IFREG in create mode */
408 BUG_ON((mode & S_IFMT) != S_IFREG);
410 forget = fuse_alloc_forget();
415 req = fuse_get_req_nopages(fc);
418 goto out_put_forget_req;
421 ff = fuse_file_alloc(fc);
423 goto out_put_request;
426 mode &= ~current_umask();
429 memset(&inarg, 0, sizeof(inarg));
430 memset(&outentry, 0, sizeof(outentry));
433 inarg.umask = current_umask();
434 req->in.h.opcode = FUSE_CREATE;
435 req->in.h.nodeid = get_node_id(dir);
437 req->in.args[0].size = fc->minor < 12 ? sizeof(struct fuse_open_in) :
439 req->in.args[0].value = &inarg;
440 req->in.args[1].size = entry->d_name.len + 1;
441 req->in.args[1].value = entry->d_name.name;
442 req->out.numargs = 2;
444 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
446 req->out.args[0].size = sizeof(outentry);
447 req->out.args[0].value = &outentry;
448 req->out.args[1].size = sizeof(outopen);
449 req->out.args[1].value = &outopen;
450 fuse_request_send(fc, req);
451 err = req->out.h.error;
456 if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid))
459 fuse_put_request(fc, req);
461 ff->nodeid = outentry.nodeid;
462 ff->open_flags = outopen.open_flags;
463 inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
464 &outentry.attr, entry_attr_timeout(&outentry), 0);
466 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
467 fuse_sync_release(ff, flags);
468 fuse_queue_forget(fc, forget, outentry.nodeid, 1);
473 d_instantiate(entry, inode);
474 fuse_change_entry_timeout(entry, &outentry);
475 fuse_invalidate_attr(dir);
476 err = finish_open(file, entry, generic_file_open, opened);
478 fuse_sync_release(ff, flags);
480 file->private_data = fuse_file_get(ff);
481 fuse_finish_open(inode, file);
488 fuse_put_request(fc, req);
495 static int fuse_mknod(struct inode *, struct dentry *, umode_t, dev_t);
496 static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
497 struct file *file, unsigned flags,
498 umode_t mode, int *opened)
501 struct fuse_conn *fc = get_fuse_conn(dir);
502 struct dentry *res = NULL;
504 if (d_unhashed(entry)) {
505 res = fuse_lookup(dir, entry, 0);
513 if (!(flags & O_CREAT) || entry->d_inode)
517 *opened |= FILE_CREATED;
522 err = fuse_create_open(dir, entry, file, flags, mode, opened);
523 if (err == -ENOSYS) {
532 err = fuse_mknod(dir, entry, mode, 0);
536 return finish_no_open(file, res);
540 * Code shared between mknod, mkdir, symlink and link
542 static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
543 struct inode *dir, struct dentry *entry,
546 struct fuse_entry_out outarg;
549 struct fuse_forget_link *forget;
551 forget = fuse_alloc_forget();
553 fuse_put_request(fc, req);
557 memset(&outarg, 0, sizeof(outarg));
558 req->in.h.nodeid = get_node_id(dir);
559 req->out.numargs = 1;
561 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
563 req->out.args[0].size = sizeof(outarg);
564 req->out.args[0].value = &outarg;
565 fuse_request_send(fc, req);
566 err = req->out.h.error;
567 fuse_put_request(fc, req);
569 goto out_put_forget_req;
572 if (invalid_nodeid(outarg.nodeid))
573 goto out_put_forget_req;
575 if ((outarg.attr.mode ^ mode) & S_IFMT)
576 goto out_put_forget_req;
578 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
579 &outarg.attr, entry_attr_timeout(&outarg), 0);
581 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
586 err = d_instantiate_no_diralias(entry, inode);
592 fuse_change_entry_timeout(entry, &outarg);
593 fuse_invalidate_attr(dir);
601 static int fuse_mknod(struct inode *dir, struct dentry *entry, umode_t mode,
604 struct fuse_mknod_in inarg;
605 struct fuse_conn *fc = get_fuse_conn(dir);
606 struct fuse_req *req = fuse_get_req_nopages(fc);
611 mode &= ~current_umask();
613 memset(&inarg, 0, sizeof(inarg));
615 inarg.rdev = new_encode_dev(rdev);
616 inarg.umask = current_umask();
617 req->in.h.opcode = FUSE_MKNOD;
619 req->in.args[0].size = fc->minor < 12 ? FUSE_COMPAT_MKNOD_IN_SIZE :
621 req->in.args[0].value = &inarg;
622 req->in.args[1].size = entry->d_name.len + 1;
623 req->in.args[1].value = entry->d_name.name;
624 return create_new_entry(fc, req, dir, entry, mode);
627 static int fuse_create(struct inode *dir, struct dentry *entry, umode_t mode,
630 return fuse_mknod(dir, entry, mode, 0);
633 static int fuse_mkdir(struct inode *dir, struct dentry *entry, umode_t mode)
635 struct fuse_mkdir_in inarg;
636 struct fuse_conn *fc = get_fuse_conn(dir);
637 struct fuse_req *req = fuse_get_req_nopages(fc);
642 mode &= ~current_umask();
644 memset(&inarg, 0, sizeof(inarg));
646 inarg.umask = current_umask();
647 req->in.h.opcode = FUSE_MKDIR;
649 req->in.args[0].size = sizeof(inarg);
650 req->in.args[0].value = &inarg;
651 req->in.args[1].size = entry->d_name.len + 1;
652 req->in.args[1].value = entry->d_name.name;
653 return create_new_entry(fc, req, dir, entry, S_IFDIR);
656 static int fuse_symlink(struct inode *dir, struct dentry *entry,
659 struct fuse_conn *fc = get_fuse_conn(dir);
660 unsigned len = strlen(link) + 1;
661 struct fuse_req *req = fuse_get_req_nopages(fc);
665 req->in.h.opcode = FUSE_SYMLINK;
667 req->in.args[0].size = entry->d_name.len + 1;
668 req->in.args[0].value = entry->d_name.name;
669 req->in.args[1].size = len;
670 req->in.args[1].value = link;
671 return create_new_entry(fc, req, dir, entry, S_IFLNK);
674 static int fuse_unlink(struct inode *dir, struct dentry *entry)
677 struct fuse_conn *fc = get_fuse_conn(dir);
678 struct fuse_req *req = fuse_get_req_nopages(fc);
682 req->in.h.opcode = FUSE_UNLINK;
683 req->in.h.nodeid = get_node_id(dir);
685 req->in.args[0].size = entry->d_name.len + 1;
686 req->in.args[0].value = entry->d_name.name;
687 fuse_request_send(fc, req);
688 err = req->out.h.error;
689 fuse_put_request(fc, req);
691 struct inode *inode = entry->d_inode;
692 struct fuse_inode *fi = get_fuse_inode(inode);
694 spin_lock(&fc->lock);
695 fi->attr_version = ++fc->attr_version;
697 * If i_nlink == 0 then unlink doesn't make sense, yet this can
698 * happen if userspace filesystem is careless. It would be
699 * difficult to enforce correct nlink usage so just ignore this
702 if (inode->i_nlink > 0)
704 spin_unlock(&fc->lock);
705 fuse_invalidate_attr(inode);
706 fuse_invalidate_attr(dir);
707 fuse_invalidate_entry_cache(entry);
708 } else if (err == -EINTR)
709 fuse_invalidate_entry(entry);
713 static int fuse_rmdir(struct inode *dir, struct dentry *entry)
716 struct fuse_conn *fc = get_fuse_conn(dir);
717 struct fuse_req *req = fuse_get_req_nopages(fc);
721 req->in.h.opcode = FUSE_RMDIR;
722 req->in.h.nodeid = get_node_id(dir);
724 req->in.args[0].size = entry->d_name.len + 1;
725 req->in.args[0].value = entry->d_name.name;
726 fuse_request_send(fc, req);
727 err = req->out.h.error;
728 fuse_put_request(fc, req);
730 clear_nlink(entry->d_inode);
731 fuse_invalidate_attr(dir);
732 fuse_invalidate_entry_cache(entry);
733 } else if (err == -EINTR)
734 fuse_invalidate_entry(entry);
738 static int fuse_rename(struct inode *olddir, struct dentry *oldent,
739 struct inode *newdir, struct dentry *newent)
742 struct fuse_rename_in inarg;
743 struct fuse_conn *fc = get_fuse_conn(olddir);
744 struct fuse_req *req = fuse_get_req_nopages(fc);
749 memset(&inarg, 0, sizeof(inarg));
750 inarg.newdir = get_node_id(newdir);
751 req->in.h.opcode = FUSE_RENAME;
752 req->in.h.nodeid = get_node_id(olddir);
754 req->in.args[0].size = sizeof(inarg);
755 req->in.args[0].value = &inarg;
756 req->in.args[1].size = oldent->d_name.len + 1;
757 req->in.args[1].value = oldent->d_name.name;
758 req->in.args[2].size = newent->d_name.len + 1;
759 req->in.args[2].value = newent->d_name.name;
760 fuse_request_send(fc, req);
761 err = req->out.h.error;
762 fuse_put_request(fc, req);
765 fuse_invalidate_attr(oldent->d_inode);
767 fuse_invalidate_attr(olddir);
768 if (olddir != newdir)
769 fuse_invalidate_attr(newdir);
771 /* newent will end up negative */
772 if (newent->d_inode) {
773 fuse_invalidate_attr(newent->d_inode);
774 fuse_invalidate_entry_cache(newent);
776 } else if (err == -EINTR) {
777 /* If request was interrupted, DEITY only knows if the
778 rename actually took place. If the invalidation
779 fails (e.g. some process has CWD under the renamed
780 directory), then there can be inconsistency between
781 the dcache and the real filesystem. Tough luck. */
782 fuse_invalidate_entry(oldent);
784 fuse_invalidate_entry(newent);
790 static int fuse_link(struct dentry *entry, struct inode *newdir,
791 struct dentry *newent)
794 struct fuse_link_in inarg;
795 struct inode *inode = entry->d_inode;
796 struct fuse_conn *fc = get_fuse_conn(inode);
797 struct fuse_req *req = fuse_get_req_nopages(fc);
801 memset(&inarg, 0, sizeof(inarg));
802 inarg.oldnodeid = get_node_id(inode);
803 req->in.h.opcode = FUSE_LINK;
805 req->in.args[0].size = sizeof(inarg);
806 req->in.args[0].value = &inarg;
807 req->in.args[1].size = newent->d_name.len + 1;
808 req->in.args[1].value = newent->d_name.name;
809 err = create_new_entry(fc, req, newdir, newent, inode->i_mode);
810 /* Contrary to "normal" filesystems it can happen that link
811 makes two "logical" inodes point to the same "physical"
812 inode. We invalidate the attributes of the old one, so it
813 will reflect changes in the backing inode (link count,
817 struct fuse_inode *fi = get_fuse_inode(inode);
819 spin_lock(&fc->lock);
820 fi->attr_version = ++fc->attr_version;
822 spin_unlock(&fc->lock);
823 fuse_invalidate_attr(inode);
824 } else if (err == -EINTR) {
825 fuse_invalidate_attr(inode);
830 static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr,
833 unsigned int blkbits;
835 stat->dev = inode->i_sb->s_dev;
836 stat->ino = attr->ino;
837 stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
838 stat->nlink = attr->nlink;
839 stat->uid = make_kuid(&init_user_ns, attr->uid);
840 stat->gid = make_kgid(&init_user_ns, attr->gid);
841 stat->rdev = inode->i_rdev;
842 stat->atime.tv_sec = attr->atime;
843 stat->atime.tv_nsec = attr->atimensec;
844 stat->mtime.tv_sec = attr->mtime;
845 stat->mtime.tv_nsec = attr->mtimensec;
846 stat->ctime.tv_sec = attr->ctime;
847 stat->ctime.tv_nsec = attr->ctimensec;
848 stat->size = attr->size;
849 stat->blocks = attr->blocks;
851 if (attr->blksize != 0)
852 blkbits = ilog2(attr->blksize);
854 blkbits = inode->i_sb->s_blocksize_bits;
856 stat->blksize = 1 << blkbits;
859 static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
863 struct fuse_getattr_in inarg;
864 struct fuse_attr_out outarg;
865 struct fuse_conn *fc = get_fuse_conn(inode);
866 struct fuse_req *req;
869 req = fuse_get_req_nopages(fc);
873 attr_version = fuse_get_attr_version(fc);
875 memset(&inarg, 0, sizeof(inarg));
876 memset(&outarg, 0, sizeof(outarg));
877 /* Directories have separate file-handle space */
878 if (file && S_ISREG(inode->i_mode)) {
879 struct fuse_file *ff = file->private_data;
881 inarg.getattr_flags |= FUSE_GETATTR_FH;
884 req->in.h.opcode = FUSE_GETATTR;
885 req->in.h.nodeid = get_node_id(inode);
887 req->in.args[0].size = sizeof(inarg);
888 req->in.args[0].value = &inarg;
889 req->out.numargs = 1;
891 req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
893 req->out.args[0].size = sizeof(outarg);
894 req->out.args[0].value = &outarg;
895 fuse_request_send(fc, req);
896 err = req->out.h.error;
897 fuse_put_request(fc, req);
899 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
900 make_bad_inode(inode);
903 fuse_change_attributes(inode, &outarg.attr,
904 attr_timeout(&outarg),
907 fuse_fillattr(inode, &outarg.attr, stat);
913 int fuse_update_attributes(struct inode *inode, struct kstat *stat,
914 struct file *file, bool *refreshed)
916 struct fuse_inode *fi = get_fuse_inode(inode);
920 if (fi->i_time < get_jiffies_64()) {
922 err = fuse_do_getattr(inode, stat, file);
927 generic_fillattr(inode, stat);
928 stat->mode = fi->orig_i_mode;
929 stat->ino = fi->orig_ino;
933 if (refreshed != NULL)
939 int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
940 u64 child_nodeid, struct qstr *name)
943 struct inode *parent;
945 struct dentry *entry;
947 parent = ilookup5(sb, parent_nodeid, fuse_inode_eq, &parent_nodeid);
951 mutex_lock(&parent->i_mutex);
952 if (!S_ISDIR(parent->i_mode))
956 dir = d_find_alias(parent);
960 entry = d_lookup(dir, name);
965 fuse_invalidate_attr(parent);
966 fuse_invalidate_entry(entry);
968 if (child_nodeid != 0 && entry->d_inode) {
969 mutex_lock(&entry->d_inode->i_mutex);
970 if (get_node_id(entry->d_inode) != child_nodeid) {
974 if (d_mountpoint(entry)) {
978 if (S_ISDIR(entry->d_inode->i_mode)) {
979 shrink_dcache_parent(entry);
980 if (!simple_empty(entry)) {
984 entry->d_inode->i_flags |= S_DEAD;
987 clear_nlink(entry->d_inode);
990 mutex_unlock(&entry->d_inode->i_mutex);
999 mutex_unlock(&parent->i_mutex);
1005 * Calling into a user-controlled filesystem gives the filesystem
1006 * daemon ptrace-like capabilities over the current process. This
1007 * means, that the filesystem daemon is able to record the exact
1008 * filesystem operations performed, and can also control the behavior
1009 * of the requester process in otherwise impossible ways. For example
1010 * it can delay the operation for arbitrary length of time allowing
1011 * DoS against the requester.
1013 * For this reason only those processes can call into the filesystem,
1014 * for which the owner of the mount has ptrace privilege. This
1015 * excludes processes started by other users, suid or sgid processes.
1017 int fuse_allow_current_process(struct fuse_conn *fc)
1019 const struct cred *cred;
1021 if (fc->flags & FUSE_ALLOW_OTHER)
1024 cred = current_cred();
1025 if (uid_eq(cred->euid, fc->user_id) &&
1026 uid_eq(cred->suid, fc->user_id) &&
1027 uid_eq(cred->uid, fc->user_id) &&
1028 gid_eq(cred->egid, fc->group_id) &&
1029 gid_eq(cred->sgid, fc->group_id) &&
1030 gid_eq(cred->gid, fc->group_id))
1036 static int fuse_access(struct inode *inode, int mask)
1038 struct fuse_conn *fc = get_fuse_conn(inode);
1039 struct fuse_req *req;
1040 struct fuse_access_in inarg;
1043 BUG_ON(mask & MAY_NOT_BLOCK);
1048 req = fuse_get_req_nopages(fc);
1050 return PTR_ERR(req);
1052 memset(&inarg, 0, sizeof(inarg));
1053 inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC);
1054 req->in.h.opcode = FUSE_ACCESS;
1055 req->in.h.nodeid = get_node_id(inode);
1056 req->in.numargs = 1;
1057 req->in.args[0].size = sizeof(inarg);
1058 req->in.args[0].value = &inarg;
1059 fuse_request_send(fc, req);
1060 err = req->out.h.error;
1061 fuse_put_request(fc, req);
1062 if (err == -ENOSYS) {
1069 static int fuse_perm_getattr(struct inode *inode, int mask)
1071 if (mask & MAY_NOT_BLOCK)
1074 return fuse_do_getattr(inode, NULL, NULL);
1078 * Check permission. The two basic access models of FUSE are:
1080 * 1) Local access checking ('default_permissions' mount option) based
1081 * on file mode. This is the plain old disk filesystem permission
1084 * 2) "Remote" access checking, where server is responsible for
1085 * checking permission in each inode operation. An exception to this
1086 * is if ->permission() was invoked from sys_access() in which case an
1087 * access request is sent. Execute permission is still checked
1088 * locally based on file mode.
1090 static int fuse_permission(struct inode *inode, int mask)
1092 struct fuse_conn *fc = get_fuse_conn(inode);
1093 bool refreshed = false;
1096 if (!fuse_allow_current_process(fc))
1100 * If attributes are needed, refresh them before proceeding
1102 if ((fc->flags & FUSE_DEFAULT_PERMISSIONS) ||
1103 ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
1104 struct fuse_inode *fi = get_fuse_inode(inode);
1106 if (fi->i_time < get_jiffies_64()) {
1109 err = fuse_perm_getattr(inode, mask);
1115 if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
1116 err = generic_permission(inode, mask);
1118 /* If permission is denied, try to refresh file
1119 attributes. This is also needed, because the root
1120 node will at first have no permissions */
1121 if (err == -EACCES && !refreshed) {
1122 err = fuse_perm_getattr(inode, mask);
1124 err = generic_permission(inode, mask);
1127 /* Note: the opposite of the above test does not
1128 exist. So if permissions are revoked this won't be
1129 noticed immediately, only after the attribute
1130 timeout has expired */
1131 } else if (mask & (MAY_ACCESS | MAY_CHDIR)) {
1132 err = fuse_access(inode, mask);
1133 } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
1134 if (!(inode->i_mode & S_IXUGO)) {
1138 err = fuse_perm_getattr(inode, mask);
1139 if (!err && !(inode->i_mode & S_IXUGO))
1146 static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
1147 struct dir_context *ctx)
1149 while (nbytes >= FUSE_NAME_OFFSET) {
1150 struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
1151 size_t reclen = FUSE_DIRENT_SIZE(dirent);
1152 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
1154 if (reclen > nbytes)
1156 if (memchr(dirent->name, '/', dirent->namelen) != NULL)
1159 if (!dir_emit(ctx, dirent->name, dirent->namelen,
1160 dirent->ino, dirent->type))
1165 ctx->pos = dirent->off;
1171 static int fuse_direntplus_link(struct file *file,
1172 struct fuse_direntplus *direntplus,
1176 struct fuse_entry_out *o = &direntplus->entry_out;
1177 struct fuse_dirent *dirent = &direntplus->dirent;
1178 struct dentry *parent = file->f_path.dentry;
1179 struct qstr name = QSTR_INIT(dirent->name, dirent->namelen);
1180 struct dentry *dentry;
1181 struct dentry *alias;
1182 struct inode *dir = parent->d_inode;
1183 struct fuse_conn *fc;
1184 struct inode *inode;
1188 * Unlike in the case of fuse_lookup, zero nodeid does not mean
1189 * ENOENT. Instead, it only means the userspace filesystem did
1190 * not want to return attributes/handle for this entry.
1197 if (name.name[0] == '.') {
1199 * We could potentially refresh the attributes of the directory
1204 if (name.name[1] == '.' && name.len == 2)
1208 if (invalid_nodeid(o->nodeid))
1210 if (!fuse_valid_type(o->attr.mode))
1213 fc = get_fuse_conn(dir);
1215 name.hash = full_name_hash(name.name, name.len);
1216 dentry = d_lookup(parent, &name);
1218 inode = dentry->d_inode;
1221 } else if (get_node_id(inode) != o->nodeid ||
1222 ((o->attr.mode ^ inode->i_mode) & S_IFMT)) {
1223 err = d_invalidate(dentry);
1226 } else if (is_bad_inode(inode)) {
1230 struct fuse_inode *fi;
1231 fi = get_fuse_inode(inode);
1232 spin_lock(&fc->lock);
1234 spin_unlock(&fc->lock);
1236 fuse_change_attributes(inode, &o->attr,
1237 entry_attr_timeout(o),
1241 * The other branch to 'found' comes via fuse_iget()
1242 * which bumps nlookup inside
1249 dentry = d_alloc(parent, &name);
1254 inode = fuse_iget(dir->i_sb, o->nodeid, o->generation,
1255 &o->attr, entry_attr_timeout(o), attr_version);
1259 alias = d_materialise_unique(dentry, inode);
1260 err = PTR_ERR(alias);
1270 if (fc->readdirplus_auto)
1271 set_bit(FUSE_I_INIT_RDPLUS, &get_fuse_inode(inode)->state);
1272 fuse_change_entry_timeout(dentry, o);
1280 static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
1281 struct dir_context *ctx, u64 attr_version)
1283 struct fuse_direntplus *direntplus;
1284 struct fuse_dirent *dirent;
1289 while (nbytes >= FUSE_NAME_OFFSET_DIRENTPLUS) {
1290 direntplus = (struct fuse_direntplus *) buf;
1291 dirent = &direntplus->dirent;
1292 reclen = FUSE_DIRENTPLUS_SIZE(direntplus);
1294 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
1296 if (reclen > nbytes)
1298 if (memchr(dirent->name, '/', dirent->namelen) != NULL)
1302 /* We fill entries into dstbuf only as much as
1303 it can hold. But we still continue iterating
1304 over remaining entries to link them. If not,
1305 we need to send a FORGET for each of those
1306 which we did not link.
1308 over = !dir_emit(ctx, dirent->name, dirent->namelen,
1309 dirent->ino, dirent->type);
1310 ctx->pos = dirent->off;
1316 ret = fuse_direntplus_link(file, direntplus, attr_version);
1318 fuse_force_forget(file, direntplus->entry_out.nodeid);
1324 static int fuse_readdir(struct file *file, struct dir_context *ctx)
1329 struct inode *inode = file_inode(file);
1330 struct fuse_conn *fc = get_fuse_conn(inode);
1331 struct fuse_req *req;
1332 u64 attr_version = 0;
1334 if (is_bad_inode(inode))
1337 req = fuse_get_req(fc, 1);
1339 return PTR_ERR(req);
1341 page = alloc_page(GFP_KERNEL);
1343 fuse_put_request(fc, req);
1347 plus = fuse_use_readdirplus(inode, ctx);
1348 req->out.argpages = 1;
1350 req->pages[0] = page;
1351 req->page_descs[0].length = PAGE_SIZE;
1353 attr_version = fuse_get_attr_version(fc);
1354 fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
1357 fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
1360 fuse_request_send(fc, req);
1361 nbytes = req->out.args[0].size;
1362 err = req->out.h.error;
1363 fuse_put_request(fc, req);
1366 err = parse_dirplusfile(page_address(page), nbytes,
1370 err = parse_dirfile(page_address(page), nbytes, file,
1376 fuse_invalidate_attr(inode); /* atime changed */
1380 static char *read_link(struct dentry *dentry)
1382 struct inode *inode = dentry->d_inode;
1383 struct fuse_conn *fc = get_fuse_conn(inode);
1384 struct fuse_req *req = fuse_get_req_nopages(fc);
1388 return ERR_CAST(req);
1390 link = (char *) __get_free_page(GFP_KERNEL);
1392 link = ERR_PTR(-ENOMEM);
1395 req->in.h.opcode = FUSE_READLINK;
1396 req->in.h.nodeid = get_node_id(inode);
1397 req->out.argvar = 1;
1398 req->out.numargs = 1;
1399 req->out.args[0].size = PAGE_SIZE - 1;
1400 req->out.args[0].value = link;
1401 fuse_request_send(fc, req);
1402 if (req->out.h.error) {
1403 free_page((unsigned long) link);
1404 link = ERR_PTR(req->out.h.error);
1406 link[req->out.args[0].size] = '\0';
1408 fuse_put_request(fc, req);
1409 fuse_invalidate_attr(inode); /* atime changed */
1413 static void free_link(char *link)
1416 free_page((unsigned long) link);
1419 static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd)
1421 nd_set_link(nd, read_link(dentry));
1425 static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
1427 free_link(nd_get_link(nd));
1430 static int fuse_dir_open(struct inode *inode, struct file *file)
1432 return fuse_open_common(inode, file, true);
1435 static int fuse_dir_release(struct inode *inode, struct file *file)
1437 fuse_release_common(file, FUSE_RELEASEDIR);
1442 static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
1445 return fuse_fsync_common(file, start, end, datasync, 1);
1448 static long fuse_dir_ioctl(struct file *file, unsigned int cmd,
1451 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1453 /* FUSE_IOCTL_DIR only supported for API version >= 7.18 */
1457 return fuse_ioctl_common(file, cmd, arg, FUSE_IOCTL_DIR);
1460 static long fuse_dir_compat_ioctl(struct file *file, unsigned int cmd,
1463 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1468 return fuse_ioctl_common(file, cmd, arg,
1469 FUSE_IOCTL_COMPAT | FUSE_IOCTL_DIR);
1472 static bool update_mtime(unsigned ivalid)
1474 /* Always update if mtime is explicitly set */
1475 if (ivalid & ATTR_MTIME_SET)
1478 /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
1479 if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
1482 /* In all other cases update */
1486 static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
1488 unsigned ivalid = iattr->ia_valid;
1490 if (ivalid & ATTR_MODE)
1491 arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode;
1492 if (ivalid & ATTR_UID)
1493 arg->valid |= FATTR_UID, arg->uid = from_kuid(&init_user_ns, iattr->ia_uid);
1494 if (ivalid & ATTR_GID)
1495 arg->valid |= FATTR_GID, arg->gid = from_kgid(&init_user_ns, iattr->ia_gid);
1496 if (ivalid & ATTR_SIZE)
1497 arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size;
1498 if (ivalid & ATTR_ATIME) {
1499 arg->valid |= FATTR_ATIME;
1500 arg->atime = iattr->ia_atime.tv_sec;
1501 arg->atimensec = iattr->ia_atime.tv_nsec;
1502 if (!(ivalid & ATTR_ATIME_SET))
1503 arg->valid |= FATTR_ATIME_NOW;
1505 if ((ivalid & ATTR_MTIME) && update_mtime(ivalid)) {
1506 arg->valid |= FATTR_MTIME;
1507 arg->mtime = iattr->ia_mtime.tv_sec;
1508 arg->mtimensec = iattr->ia_mtime.tv_nsec;
1509 if (!(ivalid & ATTR_MTIME_SET))
1510 arg->valid |= FATTR_MTIME_NOW;
1515 * Prevent concurrent writepages on inode
1517 * This is done by adding a negative bias to the inode write counter
1518 * and waiting for all pending writes to finish.
1520 void fuse_set_nowrite(struct inode *inode)
1522 struct fuse_conn *fc = get_fuse_conn(inode);
1523 struct fuse_inode *fi = get_fuse_inode(inode);
1525 BUG_ON(!mutex_is_locked(&inode->i_mutex));
1527 spin_lock(&fc->lock);
1528 BUG_ON(fi->writectr < 0);
1529 fi->writectr += FUSE_NOWRITE;
1530 spin_unlock(&fc->lock);
1531 wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
1535 * Allow writepages on inode
1537 * Remove the bias from the writecounter and send any queued
1540 static void __fuse_release_nowrite(struct inode *inode)
1542 struct fuse_inode *fi = get_fuse_inode(inode);
1544 BUG_ON(fi->writectr != FUSE_NOWRITE);
1546 fuse_flush_writepages(inode);
1549 void fuse_release_nowrite(struct inode *inode)
1551 struct fuse_conn *fc = get_fuse_conn(inode);
1553 spin_lock(&fc->lock);
1554 __fuse_release_nowrite(inode);
1555 spin_unlock(&fc->lock);
1559 * Set attributes, and at the same time refresh them.
1561 * Truncation is slightly complicated, because the 'truncate' request
1562 * may fail, in which case we don't want to touch the mapping.
1563 * vmtruncate() doesn't allow for this case, so do the rlimit checking
1564 * and the actual truncation by hand.
1566 int fuse_do_setattr(struct inode *inode, struct iattr *attr,
1569 struct fuse_conn *fc = get_fuse_conn(inode);
1570 struct fuse_inode *fi = get_fuse_inode(inode);
1571 struct fuse_req *req;
1572 struct fuse_setattr_in inarg;
1573 struct fuse_attr_out outarg;
1574 bool is_truncate = false;
1578 if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
1579 attr->ia_valid |= ATTR_FORCE;
1581 err = inode_change_ok(inode, attr);
1585 if (attr->ia_valid & ATTR_OPEN) {
1586 if (fc->atomic_o_trunc)
1591 if (attr->ia_valid & ATTR_SIZE)
1594 req = fuse_get_req_nopages(fc);
1596 return PTR_ERR(req);
1599 fuse_set_nowrite(inode);
1600 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1603 memset(&inarg, 0, sizeof(inarg));
1604 memset(&outarg, 0, sizeof(outarg));
1605 iattr_to_fattr(attr, &inarg);
1607 struct fuse_file *ff = file->private_data;
1608 inarg.valid |= FATTR_FH;
1611 if (attr->ia_valid & ATTR_SIZE) {
1612 /* For mandatory locking in truncate */
1613 inarg.valid |= FATTR_LOCKOWNER;
1614 inarg.lock_owner = fuse_lock_owner_id(fc, current->files);
1616 req->in.h.opcode = FUSE_SETATTR;
1617 req->in.h.nodeid = get_node_id(inode);
1618 req->in.numargs = 1;
1619 req->in.args[0].size = sizeof(inarg);
1620 req->in.args[0].value = &inarg;
1621 req->out.numargs = 1;
1623 req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
1625 req->out.args[0].size = sizeof(outarg);
1626 req->out.args[0].value = &outarg;
1627 fuse_request_send(fc, req);
1628 err = req->out.h.error;
1629 fuse_put_request(fc, req);
1632 fuse_invalidate_attr(inode);
1636 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1637 make_bad_inode(inode);
1642 spin_lock(&fc->lock);
1643 fuse_change_attributes_common(inode, &outarg.attr,
1644 attr_timeout(&outarg));
1645 oldsize = inode->i_size;
1646 i_size_write(inode, outarg.attr.size);
1649 /* NOTE: this may release/reacquire fc->lock */
1650 __fuse_release_nowrite(inode);
1652 spin_unlock(&fc->lock);
1655 * Only call invalidate_inode_pages2() after removing
1656 * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
1658 if (S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
1659 truncate_pagecache(inode, outarg.attr.size);
1660 invalidate_inode_pages2(inode->i_mapping);
1663 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1668 fuse_release_nowrite(inode);
1670 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1674 static int fuse_setattr(struct dentry *entry, struct iattr *attr)
1676 struct inode *inode = entry->d_inode;
1678 if (!fuse_allow_current_process(get_fuse_conn(inode)))
1681 if (attr->ia_valid & ATTR_FILE)
1682 return fuse_do_setattr(inode, attr, attr->ia_file);
1684 return fuse_do_setattr(inode, attr, NULL);
1687 static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
1690 struct inode *inode = entry->d_inode;
1691 struct fuse_conn *fc = get_fuse_conn(inode);
1693 if (!fuse_allow_current_process(fc))
1696 return fuse_update_attributes(inode, stat, NULL, NULL);
1699 static int fuse_setxattr(struct dentry *entry, const char *name,
1700 const void *value, size_t size, int flags)
1702 struct inode *inode = entry->d_inode;
1703 struct fuse_conn *fc = get_fuse_conn(inode);
1704 struct fuse_req *req;
1705 struct fuse_setxattr_in inarg;
1708 if (fc->no_setxattr)
1711 req = fuse_get_req_nopages(fc);
1713 return PTR_ERR(req);
1715 memset(&inarg, 0, sizeof(inarg));
1717 inarg.flags = flags;
1718 req->in.h.opcode = FUSE_SETXATTR;
1719 req->in.h.nodeid = get_node_id(inode);
1720 req->in.numargs = 3;
1721 req->in.args[0].size = sizeof(inarg);
1722 req->in.args[0].value = &inarg;
1723 req->in.args[1].size = strlen(name) + 1;
1724 req->in.args[1].value = name;
1725 req->in.args[2].size = size;
1726 req->in.args[2].value = value;
1727 fuse_request_send(fc, req);
1728 err = req->out.h.error;
1729 fuse_put_request(fc, req);
1730 if (err == -ENOSYS) {
1731 fc->no_setxattr = 1;
1735 fuse_invalidate_attr(inode);
1739 static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
1740 void *value, size_t size)
1742 struct inode *inode = entry->d_inode;
1743 struct fuse_conn *fc = get_fuse_conn(inode);
1744 struct fuse_req *req;
1745 struct fuse_getxattr_in inarg;
1746 struct fuse_getxattr_out outarg;
1749 if (fc->no_getxattr)
1752 req = fuse_get_req_nopages(fc);
1754 return PTR_ERR(req);
1756 memset(&inarg, 0, sizeof(inarg));
1758 req->in.h.opcode = FUSE_GETXATTR;
1759 req->in.h.nodeid = get_node_id(inode);
1760 req->in.numargs = 2;
1761 req->in.args[0].size = sizeof(inarg);
1762 req->in.args[0].value = &inarg;
1763 req->in.args[1].size = strlen(name) + 1;
1764 req->in.args[1].value = name;
1765 /* This is really two different operations rolled into one */
1766 req->out.numargs = 1;
1768 req->out.argvar = 1;
1769 req->out.args[0].size = size;
1770 req->out.args[0].value = value;
1772 req->out.args[0].size = sizeof(outarg);
1773 req->out.args[0].value = &outarg;
1775 fuse_request_send(fc, req);
1776 ret = req->out.h.error;
1778 ret = size ? req->out.args[0].size : outarg.size;
1780 if (ret == -ENOSYS) {
1781 fc->no_getxattr = 1;
1785 fuse_put_request(fc, req);
1789 static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
1791 struct inode *inode = entry->d_inode;
1792 struct fuse_conn *fc = get_fuse_conn(inode);
1793 struct fuse_req *req;
1794 struct fuse_getxattr_in inarg;
1795 struct fuse_getxattr_out outarg;
1798 if (!fuse_allow_current_process(fc))
1801 if (fc->no_listxattr)
1804 req = fuse_get_req_nopages(fc);
1806 return PTR_ERR(req);
1808 memset(&inarg, 0, sizeof(inarg));
1810 req->in.h.opcode = FUSE_LISTXATTR;
1811 req->in.h.nodeid = get_node_id(inode);
1812 req->in.numargs = 1;
1813 req->in.args[0].size = sizeof(inarg);
1814 req->in.args[0].value = &inarg;
1815 /* This is really two different operations rolled into one */
1816 req->out.numargs = 1;
1818 req->out.argvar = 1;
1819 req->out.args[0].size = size;
1820 req->out.args[0].value = list;
1822 req->out.args[0].size = sizeof(outarg);
1823 req->out.args[0].value = &outarg;
1825 fuse_request_send(fc, req);
1826 ret = req->out.h.error;
1828 ret = size ? req->out.args[0].size : outarg.size;
1830 if (ret == -ENOSYS) {
1831 fc->no_listxattr = 1;
1835 fuse_put_request(fc, req);
1839 static int fuse_removexattr(struct dentry *entry, const char *name)
1841 struct inode *inode = entry->d_inode;
1842 struct fuse_conn *fc = get_fuse_conn(inode);
1843 struct fuse_req *req;
1846 if (fc->no_removexattr)
1849 req = fuse_get_req_nopages(fc);
1851 return PTR_ERR(req);
1853 req->in.h.opcode = FUSE_REMOVEXATTR;
1854 req->in.h.nodeid = get_node_id(inode);
1855 req->in.numargs = 1;
1856 req->in.args[0].size = strlen(name) + 1;
1857 req->in.args[0].value = name;
1858 fuse_request_send(fc, req);
1859 err = req->out.h.error;
1860 fuse_put_request(fc, req);
1861 if (err == -ENOSYS) {
1862 fc->no_removexattr = 1;
1866 fuse_invalidate_attr(inode);
1870 static const struct inode_operations fuse_dir_inode_operations = {
1871 .lookup = fuse_lookup,
1872 .mkdir = fuse_mkdir,
1873 .symlink = fuse_symlink,
1874 .unlink = fuse_unlink,
1875 .rmdir = fuse_rmdir,
1876 .rename = fuse_rename,
1878 .setattr = fuse_setattr,
1879 .create = fuse_create,
1880 .atomic_open = fuse_atomic_open,
1881 .mknod = fuse_mknod,
1882 .permission = fuse_permission,
1883 .getattr = fuse_getattr,
1884 .setxattr = fuse_setxattr,
1885 .getxattr = fuse_getxattr,
1886 .listxattr = fuse_listxattr,
1887 .removexattr = fuse_removexattr,
1890 static const struct file_operations fuse_dir_operations = {
1891 .llseek = generic_file_llseek,
1892 .read = generic_read_dir,
1893 .iterate = fuse_readdir,
1894 .open = fuse_dir_open,
1895 .release = fuse_dir_release,
1896 .fsync = fuse_dir_fsync,
1897 .unlocked_ioctl = fuse_dir_ioctl,
1898 .compat_ioctl = fuse_dir_compat_ioctl,
1901 static const struct inode_operations fuse_common_inode_operations = {
1902 .setattr = fuse_setattr,
1903 .permission = fuse_permission,
1904 .getattr = fuse_getattr,
1905 .setxattr = fuse_setxattr,
1906 .getxattr = fuse_getxattr,
1907 .listxattr = fuse_listxattr,
1908 .removexattr = fuse_removexattr,
1911 static const struct inode_operations fuse_symlink_inode_operations = {
1912 .setattr = fuse_setattr,
1913 .follow_link = fuse_follow_link,
1914 .put_link = fuse_put_link,
1915 .readlink = generic_readlink,
1916 .getattr = fuse_getattr,
1917 .setxattr = fuse_setxattr,
1918 .getxattr = fuse_getxattr,
1919 .listxattr = fuse_listxattr,
1920 .removexattr = fuse_removexattr,
1923 void fuse_init_common(struct inode *inode)
1925 inode->i_op = &fuse_common_inode_operations;
1928 void fuse_init_dir(struct inode *inode)
1930 inode->i_op = &fuse_dir_inode_operations;
1931 inode->i_fop = &fuse_dir_operations;
1934 void fuse_init_symlink(struct inode *inode)
1936 inode->i_op = &fuse_symlink_inode_operations;