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;
187 inode = ACCESS_ONCE(entry->d_inode);
188 if (inode && is_bad_inode(inode))
190 else if (fuse_dentry_time(entry) < get_jiffies_64()) {
192 struct fuse_entry_out outarg;
193 struct fuse_req *req;
194 struct fuse_forget_link *forget;
197 /* For negative dentries, always do a fresh lookup */
202 if (flags & LOOKUP_RCU)
205 fc = get_fuse_conn(inode);
206 req = fuse_get_req_nopages(fc);
211 forget = fuse_alloc_forget();
213 fuse_put_request(fc, req);
218 attr_version = fuse_get_attr_version(fc);
220 parent = dget_parent(entry);
221 fuse_lookup_init(fc, req, get_node_id(parent->d_inode),
222 &entry->d_name, &outarg);
223 fuse_request_send(fc, req);
225 err = req->out.h.error;
226 fuse_put_request(fc, req);
227 /* Zero nodeid is same as -ENOENT */
228 if (!err && !outarg.nodeid)
231 struct fuse_inode *fi = get_fuse_inode(inode);
232 if (outarg.nodeid != get_node_id(inode)) {
233 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
236 spin_lock(&fc->lock);
238 spin_unlock(&fc->lock);
241 if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
244 fuse_change_attributes(inode, &outarg.attr,
245 entry_attr_timeout(&outarg),
247 fuse_change_entry_timeout(entry, &outarg);
249 fc = get_fuse_conn(inode);
250 if (fc->readdirplus_auto) {
251 parent = dget_parent(entry);
252 fuse_advise_use_readdirplus(parent->d_inode);
265 static int invalid_nodeid(u64 nodeid)
267 return !nodeid || nodeid == FUSE_ROOT_ID;
270 const struct dentry_operations fuse_dentry_operations = {
271 .d_revalidate = fuse_dentry_revalidate,
274 int fuse_valid_type(int m)
276 return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
277 S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
280 int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
281 struct fuse_entry_out *outarg, struct inode **inode)
283 struct fuse_conn *fc = get_fuse_conn_super(sb);
284 struct fuse_req *req;
285 struct fuse_forget_link *forget;
291 if (name->len > FUSE_NAME_MAX)
294 req = fuse_get_req_nopages(fc);
299 forget = fuse_alloc_forget();
302 fuse_put_request(fc, req);
306 attr_version = fuse_get_attr_version(fc);
308 fuse_lookup_init(fc, req, nodeid, name, outarg);
309 fuse_request_send(fc, req);
310 err = req->out.h.error;
311 fuse_put_request(fc, req);
312 /* Zero nodeid is same as -ENOENT, but with valid timeout */
313 if (err || !outarg->nodeid)
319 if (!fuse_valid_type(outarg->attr.mode))
322 *inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
323 &outarg->attr, entry_attr_timeout(outarg),
327 fuse_queue_forget(fc, forget, outarg->nodeid, 1);
338 static struct dentry *fuse_materialise_dentry(struct dentry *dentry,
341 struct dentry *newent;
343 if (inode && S_ISDIR(inode->i_mode)) {
344 struct fuse_conn *fc = get_fuse_conn(inode);
346 mutex_lock(&fc->inst_mutex);
347 newent = d_materialise_unique(dentry, inode);
348 mutex_unlock(&fc->inst_mutex);
350 newent = d_materialise_unique(dentry, inode);
356 static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
360 struct fuse_entry_out outarg;
362 struct dentry *newent;
363 bool outarg_valid = true;
365 err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
367 if (err == -ENOENT) {
368 outarg_valid = false;
375 if (inode && get_node_id(inode) == FUSE_ROOT_ID)
378 newent = fuse_materialise_dentry(entry, inode);
379 err = PTR_ERR(newent);
383 entry = newent ? newent : entry;
385 fuse_change_entry_timeout(entry, &outarg);
387 fuse_invalidate_entry_cache(entry);
389 fuse_advise_use_readdirplus(dir);
399 * Atomic create+open operation
401 * If the filesystem doesn't support this, then fall back to separate
402 * 'mknod' + 'open' requests.
404 static int fuse_create_open(struct inode *dir, struct dentry *entry,
405 struct file *file, unsigned flags,
406 umode_t mode, int *opened)
410 struct fuse_conn *fc = get_fuse_conn(dir);
411 struct fuse_req *req;
412 struct fuse_forget_link *forget;
413 struct fuse_create_in inarg;
414 struct fuse_open_out outopen;
415 struct fuse_entry_out outentry;
416 struct fuse_file *ff;
418 /* Userspace expects S_IFREG in create mode */
419 BUG_ON((mode & S_IFMT) != S_IFREG);
421 forget = fuse_alloc_forget();
426 req = fuse_get_req_nopages(fc);
429 goto out_put_forget_req;
432 ff = fuse_file_alloc(fc);
434 goto out_put_request;
437 mode &= ~current_umask();
440 memset(&inarg, 0, sizeof(inarg));
441 memset(&outentry, 0, sizeof(outentry));
444 inarg.umask = current_umask();
445 req->in.h.opcode = FUSE_CREATE;
446 req->in.h.nodeid = get_node_id(dir);
448 req->in.args[0].size = fc->minor < 12 ? sizeof(struct fuse_open_in) :
450 req->in.args[0].value = &inarg;
451 req->in.args[1].size = entry->d_name.len + 1;
452 req->in.args[1].value = entry->d_name.name;
453 req->out.numargs = 2;
455 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
457 req->out.args[0].size = sizeof(outentry);
458 req->out.args[0].value = &outentry;
459 req->out.args[1].size = sizeof(outopen);
460 req->out.args[1].value = &outopen;
461 fuse_request_send(fc, req);
462 err = req->out.h.error;
467 if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid))
470 fuse_put_request(fc, req);
472 ff->nodeid = outentry.nodeid;
473 ff->open_flags = outopen.open_flags;
474 inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
475 &outentry.attr, entry_attr_timeout(&outentry), 0);
477 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
478 fuse_sync_release(ff, flags);
479 fuse_queue_forget(fc, forget, outentry.nodeid, 1);
484 d_instantiate(entry, inode);
485 fuse_change_entry_timeout(entry, &outentry);
486 fuse_invalidate_attr(dir);
487 err = finish_open(file, entry, generic_file_open, opened);
489 fuse_sync_release(ff, flags);
491 file->private_data = fuse_file_get(ff);
492 fuse_finish_open(inode, file);
499 fuse_put_request(fc, req);
506 static int fuse_mknod(struct inode *, struct dentry *, umode_t, dev_t);
507 static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
508 struct file *file, unsigned flags,
509 umode_t mode, int *opened)
512 struct fuse_conn *fc = get_fuse_conn(dir);
513 struct dentry *res = NULL;
515 if (d_unhashed(entry)) {
516 res = fuse_lookup(dir, entry, 0);
524 if (!(flags & O_CREAT) || entry->d_inode)
528 *opened |= FILE_CREATED;
533 err = fuse_create_open(dir, entry, file, flags, mode, opened);
534 if (err == -ENOSYS) {
543 err = fuse_mknod(dir, entry, mode, 0);
547 return finish_no_open(file, res);
551 * Code shared between mknod, mkdir, symlink and link
553 static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
554 struct inode *dir, struct dentry *entry,
557 struct fuse_entry_out outarg;
560 struct fuse_forget_link *forget;
562 forget = fuse_alloc_forget();
564 fuse_put_request(fc, req);
568 memset(&outarg, 0, sizeof(outarg));
569 req->in.h.nodeid = get_node_id(dir);
570 req->out.numargs = 1;
572 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
574 req->out.args[0].size = sizeof(outarg);
575 req->out.args[0].value = &outarg;
576 fuse_request_send(fc, req);
577 err = req->out.h.error;
578 fuse_put_request(fc, req);
580 goto out_put_forget_req;
583 if (invalid_nodeid(outarg.nodeid))
584 goto out_put_forget_req;
586 if ((outarg.attr.mode ^ mode) & S_IFMT)
587 goto out_put_forget_req;
589 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
590 &outarg.attr, entry_attr_timeout(&outarg), 0);
592 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
597 if (S_ISDIR(inode->i_mode)) {
598 struct dentry *alias;
599 mutex_lock(&fc->inst_mutex);
600 alias = d_find_alias(inode);
602 /* New directory must have moved since mkdir */
603 mutex_unlock(&fc->inst_mutex);
608 d_instantiate(entry, inode);
609 mutex_unlock(&fc->inst_mutex);
611 d_instantiate(entry, inode);
613 fuse_change_entry_timeout(entry, &outarg);
614 fuse_invalidate_attr(dir);
622 static int fuse_mknod(struct inode *dir, struct dentry *entry, umode_t mode,
625 struct fuse_mknod_in inarg;
626 struct fuse_conn *fc = get_fuse_conn(dir);
627 struct fuse_req *req = fuse_get_req_nopages(fc);
632 mode &= ~current_umask();
634 memset(&inarg, 0, sizeof(inarg));
636 inarg.rdev = new_encode_dev(rdev);
637 inarg.umask = current_umask();
638 req->in.h.opcode = FUSE_MKNOD;
640 req->in.args[0].size = fc->minor < 12 ? FUSE_COMPAT_MKNOD_IN_SIZE :
642 req->in.args[0].value = &inarg;
643 req->in.args[1].size = entry->d_name.len + 1;
644 req->in.args[1].value = entry->d_name.name;
645 return create_new_entry(fc, req, dir, entry, mode);
648 static int fuse_create(struct inode *dir, struct dentry *entry, umode_t mode,
651 return fuse_mknod(dir, entry, mode, 0);
654 static int fuse_mkdir(struct inode *dir, struct dentry *entry, umode_t mode)
656 struct fuse_mkdir_in inarg;
657 struct fuse_conn *fc = get_fuse_conn(dir);
658 struct fuse_req *req = fuse_get_req_nopages(fc);
663 mode &= ~current_umask();
665 memset(&inarg, 0, sizeof(inarg));
667 inarg.umask = current_umask();
668 req->in.h.opcode = FUSE_MKDIR;
670 req->in.args[0].size = sizeof(inarg);
671 req->in.args[0].value = &inarg;
672 req->in.args[1].size = entry->d_name.len + 1;
673 req->in.args[1].value = entry->d_name.name;
674 return create_new_entry(fc, req, dir, entry, S_IFDIR);
677 static int fuse_symlink(struct inode *dir, struct dentry *entry,
680 struct fuse_conn *fc = get_fuse_conn(dir);
681 unsigned len = strlen(link) + 1;
682 struct fuse_req *req = fuse_get_req_nopages(fc);
686 req->in.h.opcode = FUSE_SYMLINK;
688 req->in.args[0].size = entry->d_name.len + 1;
689 req->in.args[0].value = entry->d_name.name;
690 req->in.args[1].size = len;
691 req->in.args[1].value = link;
692 return create_new_entry(fc, req, dir, entry, S_IFLNK);
695 static int fuse_unlink(struct inode *dir, struct dentry *entry)
698 struct fuse_conn *fc = get_fuse_conn(dir);
699 struct fuse_req *req = fuse_get_req_nopages(fc);
703 req->in.h.opcode = FUSE_UNLINK;
704 req->in.h.nodeid = get_node_id(dir);
706 req->in.args[0].size = entry->d_name.len + 1;
707 req->in.args[0].value = entry->d_name.name;
708 fuse_request_send(fc, req);
709 err = req->out.h.error;
710 fuse_put_request(fc, req);
712 struct inode *inode = entry->d_inode;
713 struct fuse_inode *fi = get_fuse_inode(inode);
715 spin_lock(&fc->lock);
716 fi->attr_version = ++fc->attr_version;
718 * If i_nlink == 0 then unlink doesn't make sense, yet this can
719 * happen if userspace filesystem is careless. It would be
720 * difficult to enforce correct nlink usage so just ignore this
723 if (inode->i_nlink > 0)
725 spin_unlock(&fc->lock);
726 fuse_invalidate_attr(inode);
727 fuse_invalidate_attr(dir);
728 fuse_invalidate_entry_cache(entry);
729 } else if (err == -EINTR)
730 fuse_invalidate_entry(entry);
734 static int fuse_rmdir(struct inode *dir, struct dentry *entry)
737 struct fuse_conn *fc = get_fuse_conn(dir);
738 struct fuse_req *req = fuse_get_req_nopages(fc);
742 req->in.h.opcode = FUSE_RMDIR;
743 req->in.h.nodeid = get_node_id(dir);
745 req->in.args[0].size = entry->d_name.len + 1;
746 req->in.args[0].value = entry->d_name.name;
747 fuse_request_send(fc, req);
748 err = req->out.h.error;
749 fuse_put_request(fc, req);
751 clear_nlink(entry->d_inode);
752 fuse_invalidate_attr(dir);
753 fuse_invalidate_entry_cache(entry);
754 } else if (err == -EINTR)
755 fuse_invalidate_entry(entry);
759 static int fuse_rename(struct inode *olddir, struct dentry *oldent,
760 struct inode *newdir, struct dentry *newent)
763 struct fuse_rename_in inarg;
764 struct fuse_conn *fc = get_fuse_conn(olddir);
765 struct fuse_req *req = fuse_get_req_nopages(fc);
770 memset(&inarg, 0, sizeof(inarg));
771 inarg.newdir = get_node_id(newdir);
772 req->in.h.opcode = FUSE_RENAME;
773 req->in.h.nodeid = get_node_id(olddir);
775 req->in.args[0].size = sizeof(inarg);
776 req->in.args[0].value = &inarg;
777 req->in.args[1].size = oldent->d_name.len + 1;
778 req->in.args[1].value = oldent->d_name.name;
779 req->in.args[2].size = newent->d_name.len + 1;
780 req->in.args[2].value = newent->d_name.name;
781 fuse_request_send(fc, req);
782 err = req->out.h.error;
783 fuse_put_request(fc, req);
786 fuse_invalidate_attr(oldent->d_inode);
788 fuse_invalidate_attr(olddir);
789 if (olddir != newdir)
790 fuse_invalidate_attr(newdir);
792 /* newent will end up negative */
793 if (newent->d_inode) {
794 fuse_invalidate_attr(newent->d_inode);
795 fuse_invalidate_entry_cache(newent);
797 } else if (err == -EINTR) {
798 /* If request was interrupted, DEITY only knows if the
799 rename actually took place. If the invalidation
800 fails (e.g. some process has CWD under the renamed
801 directory), then there can be inconsistency between
802 the dcache and the real filesystem. Tough luck. */
803 fuse_invalidate_entry(oldent);
805 fuse_invalidate_entry(newent);
811 static int fuse_link(struct dentry *entry, struct inode *newdir,
812 struct dentry *newent)
815 struct fuse_link_in inarg;
816 struct inode *inode = entry->d_inode;
817 struct fuse_conn *fc = get_fuse_conn(inode);
818 struct fuse_req *req = fuse_get_req_nopages(fc);
822 memset(&inarg, 0, sizeof(inarg));
823 inarg.oldnodeid = get_node_id(inode);
824 req->in.h.opcode = FUSE_LINK;
826 req->in.args[0].size = sizeof(inarg);
827 req->in.args[0].value = &inarg;
828 req->in.args[1].size = newent->d_name.len + 1;
829 req->in.args[1].value = newent->d_name.name;
830 err = create_new_entry(fc, req, newdir, newent, inode->i_mode);
831 /* Contrary to "normal" filesystems it can happen that link
832 makes two "logical" inodes point to the same "physical"
833 inode. We invalidate the attributes of the old one, so it
834 will reflect changes in the backing inode (link count,
838 struct fuse_inode *fi = get_fuse_inode(inode);
840 spin_lock(&fc->lock);
841 fi->attr_version = ++fc->attr_version;
843 spin_unlock(&fc->lock);
844 fuse_invalidate_attr(inode);
845 } else if (err == -EINTR) {
846 fuse_invalidate_attr(inode);
851 static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr,
854 unsigned int blkbits;
856 stat->dev = inode->i_sb->s_dev;
857 stat->ino = attr->ino;
858 stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
859 stat->nlink = attr->nlink;
860 stat->uid = make_kuid(&init_user_ns, attr->uid);
861 stat->gid = make_kgid(&init_user_ns, attr->gid);
862 stat->rdev = inode->i_rdev;
863 stat->atime.tv_sec = attr->atime;
864 stat->atime.tv_nsec = attr->atimensec;
865 stat->mtime.tv_sec = attr->mtime;
866 stat->mtime.tv_nsec = attr->mtimensec;
867 stat->ctime.tv_sec = attr->ctime;
868 stat->ctime.tv_nsec = attr->ctimensec;
869 stat->size = attr->size;
870 stat->blocks = attr->blocks;
872 if (attr->blksize != 0)
873 blkbits = ilog2(attr->blksize);
875 blkbits = inode->i_sb->s_blocksize_bits;
877 stat->blksize = 1 << blkbits;
880 static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
884 struct fuse_getattr_in inarg;
885 struct fuse_attr_out outarg;
886 struct fuse_conn *fc = get_fuse_conn(inode);
887 struct fuse_req *req;
890 req = fuse_get_req_nopages(fc);
894 attr_version = fuse_get_attr_version(fc);
896 memset(&inarg, 0, sizeof(inarg));
897 memset(&outarg, 0, sizeof(outarg));
898 /* Directories have separate file-handle space */
899 if (file && S_ISREG(inode->i_mode)) {
900 struct fuse_file *ff = file->private_data;
902 inarg.getattr_flags |= FUSE_GETATTR_FH;
905 req->in.h.opcode = FUSE_GETATTR;
906 req->in.h.nodeid = get_node_id(inode);
908 req->in.args[0].size = sizeof(inarg);
909 req->in.args[0].value = &inarg;
910 req->out.numargs = 1;
912 req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
914 req->out.args[0].size = sizeof(outarg);
915 req->out.args[0].value = &outarg;
916 fuse_request_send(fc, req);
917 err = req->out.h.error;
918 fuse_put_request(fc, req);
920 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
921 make_bad_inode(inode);
924 fuse_change_attributes(inode, &outarg.attr,
925 attr_timeout(&outarg),
928 fuse_fillattr(inode, &outarg.attr, stat);
934 int fuse_update_attributes(struct inode *inode, struct kstat *stat,
935 struct file *file, bool *refreshed)
937 struct fuse_inode *fi = get_fuse_inode(inode);
941 if (fi->i_time < get_jiffies_64()) {
943 err = fuse_do_getattr(inode, stat, file);
948 generic_fillattr(inode, stat);
949 stat->mode = fi->orig_i_mode;
950 stat->ino = fi->orig_ino;
954 if (refreshed != NULL)
960 int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
961 u64 child_nodeid, struct qstr *name)
964 struct inode *parent;
966 struct dentry *entry;
968 parent = ilookup5(sb, parent_nodeid, fuse_inode_eq, &parent_nodeid);
972 mutex_lock(&parent->i_mutex);
973 if (!S_ISDIR(parent->i_mode))
977 dir = d_find_alias(parent);
981 entry = d_lookup(dir, name);
986 fuse_invalidate_attr(parent);
987 fuse_invalidate_entry(entry);
989 if (child_nodeid != 0 && entry->d_inode) {
990 mutex_lock(&entry->d_inode->i_mutex);
991 if (get_node_id(entry->d_inode) != child_nodeid) {
995 if (d_mountpoint(entry)) {
999 if (S_ISDIR(entry->d_inode->i_mode)) {
1000 shrink_dcache_parent(entry);
1001 if (!simple_empty(entry)) {
1005 entry->d_inode->i_flags |= S_DEAD;
1008 clear_nlink(entry->d_inode);
1011 mutex_unlock(&entry->d_inode->i_mutex);
1020 mutex_unlock(&parent->i_mutex);
1026 * Calling into a user-controlled filesystem gives the filesystem
1027 * daemon ptrace-like capabilities over the current process. This
1028 * means, that the filesystem daemon is able to record the exact
1029 * filesystem operations performed, and can also control the behavior
1030 * of the requester process in otherwise impossible ways. For example
1031 * it can delay the operation for arbitrary length of time allowing
1032 * DoS against the requester.
1034 * For this reason only those processes can call into the filesystem,
1035 * for which the owner of the mount has ptrace privilege. This
1036 * excludes processes started by other users, suid or sgid processes.
1038 int fuse_allow_current_process(struct fuse_conn *fc)
1040 const struct cred *cred;
1042 if (fc->flags & FUSE_ALLOW_OTHER)
1045 cred = current_cred();
1046 if (uid_eq(cred->euid, fc->user_id) &&
1047 uid_eq(cred->suid, fc->user_id) &&
1048 uid_eq(cred->uid, fc->user_id) &&
1049 gid_eq(cred->egid, fc->group_id) &&
1050 gid_eq(cred->sgid, fc->group_id) &&
1051 gid_eq(cred->gid, fc->group_id))
1057 static int fuse_access(struct inode *inode, int mask)
1059 struct fuse_conn *fc = get_fuse_conn(inode);
1060 struct fuse_req *req;
1061 struct fuse_access_in inarg;
1067 req = fuse_get_req_nopages(fc);
1069 return PTR_ERR(req);
1071 memset(&inarg, 0, sizeof(inarg));
1072 inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC);
1073 req->in.h.opcode = FUSE_ACCESS;
1074 req->in.h.nodeid = get_node_id(inode);
1075 req->in.numargs = 1;
1076 req->in.args[0].size = sizeof(inarg);
1077 req->in.args[0].value = &inarg;
1078 fuse_request_send(fc, req);
1079 err = req->out.h.error;
1080 fuse_put_request(fc, req);
1081 if (err == -ENOSYS) {
1088 static int fuse_perm_getattr(struct inode *inode, int mask)
1090 if (mask & MAY_NOT_BLOCK)
1093 return fuse_do_getattr(inode, NULL, NULL);
1097 * Check permission. The two basic access models of FUSE are:
1099 * 1) Local access checking ('default_permissions' mount option) based
1100 * on file mode. This is the plain old disk filesystem permission
1103 * 2) "Remote" access checking, where server is responsible for
1104 * checking permission in each inode operation. An exception to this
1105 * is if ->permission() was invoked from sys_access() in which case an
1106 * access request is sent. Execute permission is still checked
1107 * locally based on file mode.
1109 static int fuse_permission(struct inode *inode, int mask)
1111 struct fuse_conn *fc = get_fuse_conn(inode);
1112 bool refreshed = false;
1115 if (!fuse_allow_current_process(fc))
1119 * If attributes are needed, refresh them before proceeding
1121 if ((fc->flags & FUSE_DEFAULT_PERMISSIONS) ||
1122 ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
1123 struct fuse_inode *fi = get_fuse_inode(inode);
1125 if (fi->i_time < get_jiffies_64()) {
1128 err = fuse_perm_getattr(inode, mask);
1134 if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
1135 err = generic_permission(inode, mask);
1137 /* If permission is denied, try to refresh file
1138 attributes. This is also needed, because the root
1139 node will at first have no permissions */
1140 if (err == -EACCES && !refreshed) {
1141 err = fuse_perm_getattr(inode, mask);
1143 err = generic_permission(inode, mask);
1146 /* Note: the opposite of the above test does not
1147 exist. So if permissions are revoked this won't be
1148 noticed immediately, only after the attribute
1149 timeout has expired */
1150 } else if (mask & (MAY_ACCESS | MAY_CHDIR)) {
1151 if (mask & MAY_NOT_BLOCK)
1154 err = fuse_access(inode, mask);
1155 } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
1156 if (!(inode->i_mode & S_IXUGO)) {
1160 err = fuse_perm_getattr(inode, mask);
1161 if (!err && !(inode->i_mode & S_IXUGO))
1168 static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
1169 struct dir_context *ctx)
1171 while (nbytes >= FUSE_NAME_OFFSET) {
1172 struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
1173 size_t reclen = FUSE_DIRENT_SIZE(dirent);
1174 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
1176 if (reclen > nbytes)
1179 if (!dir_emit(ctx, dirent->name, dirent->namelen,
1180 dirent->ino, dirent->type))
1185 ctx->pos = dirent->off;
1191 static int fuse_direntplus_link(struct file *file,
1192 struct fuse_direntplus *direntplus,
1196 struct fuse_entry_out *o = &direntplus->entry_out;
1197 struct fuse_dirent *dirent = &direntplus->dirent;
1198 struct dentry *parent = file->f_path.dentry;
1199 struct qstr name = QSTR_INIT(dirent->name, dirent->namelen);
1200 struct dentry *dentry;
1201 struct dentry *alias;
1202 struct inode *dir = parent->d_inode;
1203 struct fuse_conn *fc;
1204 struct inode *inode;
1208 * Unlike in the case of fuse_lookup, zero nodeid does not mean
1209 * ENOENT. Instead, it only means the userspace filesystem did
1210 * not want to return attributes/handle for this entry.
1217 if (name.name[0] == '.') {
1219 * We could potentially refresh the attributes of the directory
1224 if (name.name[1] == '.' && name.len == 2)
1228 if (invalid_nodeid(o->nodeid))
1230 if (!fuse_valid_type(o->attr.mode))
1233 fc = get_fuse_conn(dir);
1235 name.hash = full_name_hash(name.name, name.len);
1236 dentry = d_lookup(parent, &name);
1238 inode = dentry->d_inode;
1241 } else if (get_node_id(inode) != o->nodeid ||
1242 ((o->attr.mode ^ inode->i_mode) & S_IFMT)) {
1243 err = d_invalidate(dentry);
1246 } else if (is_bad_inode(inode)) {
1250 struct fuse_inode *fi;
1251 fi = get_fuse_inode(inode);
1252 spin_lock(&fc->lock);
1254 spin_unlock(&fc->lock);
1256 fuse_change_attributes(inode, &o->attr,
1257 entry_attr_timeout(o),
1261 * The other branch to 'found' comes via fuse_iget()
1262 * which bumps nlookup inside
1269 dentry = d_alloc(parent, &name);
1274 inode = fuse_iget(dir->i_sb, o->nodeid, o->generation,
1275 &o->attr, entry_attr_timeout(o), attr_version);
1279 alias = fuse_materialise_dentry(dentry, inode);
1280 err = PTR_ERR(alias);
1290 fuse_change_entry_timeout(dentry, o);
1298 static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
1299 struct dir_context *ctx, u64 attr_version)
1301 struct fuse_direntplus *direntplus;
1302 struct fuse_dirent *dirent;
1307 while (nbytes >= FUSE_NAME_OFFSET_DIRENTPLUS) {
1308 direntplus = (struct fuse_direntplus *) buf;
1309 dirent = &direntplus->dirent;
1310 reclen = FUSE_DIRENTPLUS_SIZE(direntplus);
1312 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
1314 if (reclen > nbytes)
1318 /* We fill entries into dstbuf only as much as
1319 it can hold. But we still continue iterating
1320 over remaining entries to link them. If not,
1321 we need to send a FORGET for each of those
1322 which we did not link.
1324 over = !dir_emit(ctx, dirent->name, dirent->namelen,
1325 dirent->ino, dirent->type);
1326 ctx->pos = dirent->off;
1332 ret = fuse_direntplus_link(file, direntplus, attr_version);
1334 fuse_force_forget(file, direntplus->entry_out.nodeid);
1340 static int fuse_readdir(struct file *file, struct dir_context *ctx)
1345 struct inode *inode = file_inode(file);
1346 struct fuse_conn *fc = get_fuse_conn(inode);
1347 struct fuse_req *req;
1348 u64 attr_version = 0;
1350 if (is_bad_inode(inode))
1353 req = fuse_get_req(fc, 1);
1355 return PTR_ERR(req);
1357 page = alloc_page(GFP_KERNEL);
1359 fuse_put_request(fc, req);
1363 plus = fuse_use_readdirplus(inode, ctx);
1364 req->out.argpages = 1;
1366 req->pages[0] = page;
1367 req->page_descs[0].length = PAGE_SIZE;
1369 attr_version = fuse_get_attr_version(fc);
1370 fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
1373 fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
1376 fuse_request_send(fc, req);
1377 nbytes = req->out.args[0].size;
1378 err = req->out.h.error;
1379 fuse_put_request(fc, req);
1382 err = parse_dirplusfile(page_address(page), nbytes,
1386 err = parse_dirfile(page_address(page), nbytes, file,
1392 fuse_invalidate_attr(inode); /* atime changed */
1396 static char *read_link(struct dentry *dentry)
1398 struct inode *inode = dentry->d_inode;
1399 struct fuse_conn *fc = get_fuse_conn(inode);
1400 struct fuse_req *req = fuse_get_req_nopages(fc);
1404 return ERR_CAST(req);
1406 link = (char *) __get_free_page(GFP_KERNEL);
1408 link = ERR_PTR(-ENOMEM);
1411 req->in.h.opcode = FUSE_READLINK;
1412 req->in.h.nodeid = get_node_id(inode);
1413 req->out.argvar = 1;
1414 req->out.numargs = 1;
1415 req->out.args[0].size = PAGE_SIZE - 1;
1416 req->out.args[0].value = link;
1417 fuse_request_send(fc, req);
1418 if (req->out.h.error) {
1419 free_page((unsigned long) link);
1420 link = ERR_PTR(req->out.h.error);
1422 link[req->out.args[0].size] = '\0';
1424 fuse_put_request(fc, req);
1425 fuse_invalidate_attr(inode); /* atime changed */
1429 static void free_link(char *link)
1432 free_page((unsigned long) link);
1435 static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd)
1437 nd_set_link(nd, read_link(dentry));
1441 static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
1443 free_link(nd_get_link(nd));
1446 static int fuse_dir_open(struct inode *inode, struct file *file)
1448 return fuse_open_common(inode, file, true);
1451 static int fuse_dir_release(struct inode *inode, struct file *file)
1453 fuse_release_common(file, FUSE_RELEASEDIR);
1458 static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
1461 return fuse_fsync_common(file, start, end, datasync, 1);
1464 static long fuse_dir_ioctl(struct file *file, unsigned int cmd,
1467 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1469 /* FUSE_IOCTL_DIR only supported for API version >= 7.18 */
1473 return fuse_ioctl_common(file, cmd, arg, FUSE_IOCTL_DIR);
1476 static long fuse_dir_compat_ioctl(struct file *file, unsigned int cmd,
1479 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1484 return fuse_ioctl_common(file, cmd, arg,
1485 FUSE_IOCTL_COMPAT | FUSE_IOCTL_DIR);
1488 static bool update_mtime(unsigned ivalid)
1490 /* Always update if mtime is explicitly set */
1491 if (ivalid & ATTR_MTIME_SET)
1494 /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
1495 if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
1498 /* In all other cases update */
1502 static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
1504 unsigned ivalid = iattr->ia_valid;
1506 if (ivalid & ATTR_MODE)
1507 arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode;
1508 if (ivalid & ATTR_UID)
1509 arg->valid |= FATTR_UID, arg->uid = from_kuid(&init_user_ns, iattr->ia_uid);
1510 if (ivalid & ATTR_GID)
1511 arg->valid |= FATTR_GID, arg->gid = from_kgid(&init_user_ns, iattr->ia_gid);
1512 if (ivalid & ATTR_SIZE)
1513 arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size;
1514 if (ivalid & ATTR_ATIME) {
1515 arg->valid |= FATTR_ATIME;
1516 arg->atime = iattr->ia_atime.tv_sec;
1517 arg->atimensec = iattr->ia_atime.tv_nsec;
1518 if (!(ivalid & ATTR_ATIME_SET))
1519 arg->valid |= FATTR_ATIME_NOW;
1521 if ((ivalid & ATTR_MTIME) && update_mtime(ivalid)) {
1522 arg->valid |= FATTR_MTIME;
1523 arg->mtime = iattr->ia_mtime.tv_sec;
1524 arg->mtimensec = iattr->ia_mtime.tv_nsec;
1525 if (!(ivalid & ATTR_MTIME_SET))
1526 arg->valid |= FATTR_MTIME_NOW;
1531 * Prevent concurrent writepages on inode
1533 * This is done by adding a negative bias to the inode write counter
1534 * and waiting for all pending writes to finish.
1536 void fuse_set_nowrite(struct inode *inode)
1538 struct fuse_conn *fc = get_fuse_conn(inode);
1539 struct fuse_inode *fi = get_fuse_inode(inode);
1541 BUG_ON(!mutex_is_locked(&inode->i_mutex));
1543 spin_lock(&fc->lock);
1544 BUG_ON(fi->writectr < 0);
1545 fi->writectr += FUSE_NOWRITE;
1546 spin_unlock(&fc->lock);
1547 wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
1551 * Allow writepages on inode
1553 * Remove the bias from the writecounter and send any queued
1556 static void __fuse_release_nowrite(struct inode *inode)
1558 struct fuse_inode *fi = get_fuse_inode(inode);
1560 BUG_ON(fi->writectr != FUSE_NOWRITE);
1562 fuse_flush_writepages(inode);
1565 void fuse_release_nowrite(struct inode *inode)
1567 struct fuse_conn *fc = get_fuse_conn(inode);
1569 spin_lock(&fc->lock);
1570 __fuse_release_nowrite(inode);
1571 spin_unlock(&fc->lock);
1575 * Set attributes, and at the same time refresh them.
1577 * Truncation is slightly complicated, because the 'truncate' request
1578 * may fail, in which case we don't want to touch the mapping.
1579 * vmtruncate() doesn't allow for this case, so do the rlimit checking
1580 * and the actual truncation by hand.
1582 int fuse_do_setattr(struct inode *inode, struct iattr *attr,
1585 struct fuse_conn *fc = get_fuse_conn(inode);
1586 struct fuse_req *req;
1587 struct fuse_setattr_in inarg;
1588 struct fuse_attr_out outarg;
1589 bool is_truncate = false;
1593 if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
1594 attr->ia_valid |= ATTR_FORCE;
1596 err = inode_change_ok(inode, attr);
1600 if (attr->ia_valid & ATTR_OPEN) {
1601 if (fc->atomic_o_trunc)
1606 if (attr->ia_valid & ATTR_SIZE)
1609 req = fuse_get_req_nopages(fc);
1611 return PTR_ERR(req);
1614 fuse_set_nowrite(inode);
1616 memset(&inarg, 0, sizeof(inarg));
1617 memset(&outarg, 0, sizeof(outarg));
1618 iattr_to_fattr(attr, &inarg);
1620 struct fuse_file *ff = file->private_data;
1621 inarg.valid |= FATTR_FH;
1624 if (attr->ia_valid & ATTR_SIZE) {
1625 /* For mandatory locking in truncate */
1626 inarg.valid |= FATTR_LOCKOWNER;
1627 inarg.lock_owner = fuse_lock_owner_id(fc, current->files);
1629 req->in.h.opcode = FUSE_SETATTR;
1630 req->in.h.nodeid = get_node_id(inode);
1631 req->in.numargs = 1;
1632 req->in.args[0].size = sizeof(inarg);
1633 req->in.args[0].value = &inarg;
1634 req->out.numargs = 1;
1636 req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
1638 req->out.args[0].size = sizeof(outarg);
1639 req->out.args[0].value = &outarg;
1640 fuse_request_send(fc, req);
1641 err = req->out.h.error;
1642 fuse_put_request(fc, req);
1645 fuse_invalidate_attr(inode);
1649 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1650 make_bad_inode(inode);
1655 spin_lock(&fc->lock);
1656 fuse_change_attributes_common(inode, &outarg.attr,
1657 attr_timeout(&outarg));
1658 oldsize = inode->i_size;
1659 i_size_write(inode, outarg.attr.size);
1662 /* NOTE: this may release/reacquire fc->lock */
1663 __fuse_release_nowrite(inode);
1665 spin_unlock(&fc->lock);
1668 * Only call invalidate_inode_pages2() after removing
1669 * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
1671 if (S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
1672 truncate_pagecache(inode, oldsize, outarg.attr.size);
1673 invalidate_inode_pages2(inode->i_mapping);
1680 fuse_release_nowrite(inode);
1685 static int fuse_setattr(struct dentry *entry, struct iattr *attr)
1687 struct inode *inode = entry->d_inode;
1689 if (!fuse_allow_current_process(get_fuse_conn(inode)))
1692 if (attr->ia_valid & ATTR_FILE)
1693 return fuse_do_setattr(inode, attr, attr->ia_file);
1695 return fuse_do_setattr(inode, attr, NULL);
1698 static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
1701 struct inode *inode = entry->d_inode;
1702 struct fuse_conn *fc = get_fuse_conn(inode);
1704 if (!fuse_allow_current_process(fc))
1707 return fuse_update_attributes(inode, stat, NULL, NULL);
1710 static int fuse_setxattr(struct dentry *entry, const char *name,
1711 const void *value, size_t size, int flags)
1713 struct inode *inode = entry->d_inode;
1714 struct fuse_conn *fc = get_fuse_conn(inode);
1715 struct fuse_req *req;
1716 struct fuse_setxattr_in inarg;
1719 if (fc->no_setxattr)
1722 req = fuse_get_req_nopages(fc);
1724 return PTR_ERR(req);
1726 memset(&inarg, 0, sizeof(inarg));
1728 inarg.flags = flags;
1729 req->in.h.opcode = FUSE_SETXATTR;
1730 req->in.h.nodeid = get_node_id(inode);
1731 req->in.numargs = 3;
1732 req->in.args[0].size = sizeof(inarg);
1733 req->in.args[0].value = &inarg;
1734 req->in.args[1].size = strlen(name) + 1;
1735 req->in.args[1].value = name;
1736 req->in.args[2].size = size;
1737 req->in.args[2].value = value;
1738 fuse_request_send(fc, req);
1739 err = req->out.h.error;
1740 fuse_put_request(fc, req);
1741 if (err == -ENOSYS) {
1742 fc->no_setxattr = 1;
1748 static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
1749 void *value, size_t size)
1751 struct inode *inode = entry->d_inode;
1752 struct fuse_conn *fc = get_fuse_conn(inode);
1753 struct fuse_req *req;
1754 struct fuse_getxattr_in inarg;
1755 struct fuse_getxattr_out outarg;
1758 if (fc->no_getxattr)
1761 req = fuse_get_req_nopages(fc);
1763 return PTR_ERR(req);
1765 memset(&inarg, 0, sizeof(inarg));
1767 req->in.h.opcode = FUSE_GETXATTR;
1768 req->in.h.nodeid = get_node_id(inode);
1769 req->in.numargs = 2;
1770 req->in.args[0].size = sizeof(inarg);
1771 req->in.args[0].value = &inarg;
1772 req->in.args[1].size = strlen(name) + 1;
1773 req->in.args[1].value = name;
1774 /* This is really two different operations rolled into one */
1775 req->out.numargs = 1;
1777 req->out.argvar = 1;
1778 req->out.args[0].size = size;
1779 req->out.args[0].value = value;
1781 req->out.args[0].size = sizeof(outarg);
1782 req->out.args[0].value = &outarg;
1784 fuse_request_send(fc, req);
1785 ret = req->out.h.error;
1787 ret = size ? req->out.args[0].size : outarg.size;
1789 if (ret == -ENOSYS) {
1790 fc->no_getxattr = 1;
1794 fuse_put_request(fc, req);
1798 static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
1800 struct inode *inode = entry->d_inode;
1801 struct fuse_conn *fc = get_fuse_conn(inode);
1802 struct fuse_req *req;
1803 struct fuse_getxattr_in inarg;
1804 struct fuse_getxattr_out outarg;
1807 if (!fuse_allow_current_process(fc))
1810 if (fc->no_listxattr)
1813 req = fuse_get_req_nopages(fc);
1815 return PTR_ERR(req);
1817 memset(&inarg, 0, sizeof(inarg));
1819 req->in.h.opcode = FUSE_LISTXATTR;
1820 req->in.h.nodeid = get_node_id(inode);
1821 req->in.numargs = 1;
1822 req->in.args[0].size = sizeof(inarg);
1823 req->in.args[0].value = &inarg;
1824 /* This is really two different operations rolled into one */
1825 req->out.numargs = 1;
1827 req->out.argvar = 1;
1828 req->out.args[0].size = size;
1829 req->out.args[0].value = list;
1831 req->out.args[0].size = sizeof(outarg);
1832 req->out.args[0].value = &outarg;
1834 fuse_request_send(fc, req);
1835 ret = req->out.h.error;
1837 ret = size ? req->out.args[0].size : outarg.size;
1839 if (ret == -ENOSYS) {
1840 fc->no_listxattr = 1;
1844 fuse_put_request(fc, req);
1848 static int fuse_removexattr(struct dentry *entry, const char *name)
1850 struct inode *inode = entry->d_inode;
1851 struct fuse_conn *fc = get_fuse_conn(inode);
1852 struct fuse_req *req;
1855 if (fc->no_removexattr)
1858 req = fuse_get_req_nopages(fc);
1860 return PTR_ERR(req);
1862 req->in.h.opcode = FUSE_REMOVEXATTR;
1863 req->in.h.nodeid = get_node_id(inode);
1864 req->in.numargs = 1;
1865 req->in.args[0].size = strlen(name) + 1;
1866 req->in.args[0].value = name;
1867 fuse_request_send(fc, req);
1868 err = req->out.h.error;
1869 fuse_put_request(fc, req);
1870 if (err == -ENOSYS) {
1871 fc->no_removexattr = 1;
1877 static const struct inode_operations fuse_dir_inode_operations = {
1878 .lookup = fuse_lookup,
1879 .mkdir = fuse_mkdir,
1880 .symlink = fuse_symlink,
1881 .unlink = fuse_unlink,
1882 .rmdir = fuse_rmdir,
1883 .rename = fuse_rename,
1885 .setattr = fuse_setattr,
1886 .create = fuse_create,
1887 .atomic_open = fuse_atomic_open,
1888 .mknod = fuse_mknod,
1889 .permission = fuse_permission,
1890 .getattr = fuse_getattr,
1891 .setxattr = fuse_setxattr,
1892 .getxattr = fuse_getxattr,
1893 .listxattr = fuse_listxattr,
1894 .removexattr = fuse_removexattr,
1897 static const struct file_operations fuse_dir_operations = {
1898 .llseek = generic_file_llseek,
1899 .read = generic_read_dir,
1900 .iterate = fuse_readdir,
1901 .open = fuse_dir_open,
1902 .release = fuse_dir_release,
1903 .fsync = fuse_dir_fsync,
1904 .unlocked_ioctl = fuse_dir_ioctl,
1905 .compat_ioctl = fuse_dir_compat_ioctl,
1908 static const struct inode_operations fuse_common_inode_operations = {
1909 .setattr = fuse_setattr,
1910 .permission = fuse_permission,
1911 .getattr = fuse_getattr,
1912 .setxattr = fuse_setxattr,
1913 .getxattr = fuse_getxattr,
1914 .listxattr = fuse_listxattr,
1915 .removexattr = fuse_removexattr,
1918 static const struct inode_operations fuse_symlink_inode_operations = {
1919 .setattr = fuse_setattr,
1920 .follow_link = fuse_follow_link,
1921 .put_link = fuse_put_link,
1922 .readlink = generic_readlink,
1923 .getattr = fuse_getattr,
1924 .setxattr = fuse_setxattr,
1925 .getxattr = fuse_getxattr,
1926 .listxattr = fuse_listxattr,
1927 .removexattr = fuse_removexattr,
1930 void fuse_init_common(struct inode *inode)
1932 inode->i_op = &fuse_common_inode_operations;
1935 void fuse_init_dir(struct inode *inode)
1937 inode->i_op = &fuse_dir_inode_operations;
1938 inode->i_fop = &fuse_dir_operations;
1941 void fuse_init_symlink(struct inode *inode)
1943 inode->i_op = &fuse_symlink_inode_operations;