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 file *filp)
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;
186 inode = ACCESS_ONCE(entry->d_inode);
187 if (inode && is_bad_inode(inode))
189 else if (fuse_dentry_time(entry) < get_jiffies_64()) {
191 struct fuse_entry_out outarg;
192 struct fuse_req *req;
193 struct fuse_forget_link *forget;
196 /* For negative dentries, always do a fresh lookup */
200 if (flags & LOOKUP_RCU)
203 fc = get_fuse_conn(inode);
204 req = fuse_get_req_nopages(fc);
208 forget = fuse_alloc_forget();
210 fuse_put_request(fc, req);
214 attr_version = fuse_get_attr_version(fc);
216 parent = dget_parent(entry);
217 fuse_lookup_init(fc, req, get_node_id(parent->d_inode),
218 &entry->d_name, &outarg);
219 fuse_request_send(fc, req);
221 err = req->out.h.error;
222 fuse_put_request(fc, req);
223 /* Zero nodeid is same as -ENOENT */
224 if (!err && !outarg.nodeid)
227 struct fuse_inode *fi = get_fuse_inode(inode);
228 if (outarg.nodeid != get_node_id(inode)) {
229 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
232 spin_lock(&fc->lock);
234 spin_unlock(&fc->lock);
237 if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
240 fuse_change_attributes(inode, &outarg.attr,
241 entry_attr_timeout(&outarg),
243 fuse_change_entry_timeout(entry, &outarg);
245 fc = get_fuse_conn(inode);
246 if (fc->readdirplus_auto) {
247 parent = dget_parent(entry);
248 fuse_advise_use_readdirplus(parent->d_inode);
255 static int invalid_nodeid(u64 nodeid)
257 return !nodeid || nodeid == FUSE_ROOT_ID;
260 const struct dentry_operations fuse_dentry_operations = {
261 .d_revalidate = fuse_dentry_revalidate,
264 int fuse_valid_type(int m)
266 return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
267 S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
271 * Add a directory inode to a dentry, ensuring that no other dentry
272 * refers to this inode. Called with fc->inst_mutex.
274 static struct dentry *fuse_d_add_directory(struct dentry *entry,
277 struct dentry *alias = d_find_alias(inode);
278 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
279 /* This tries to shrink the subtree below alias */
280 fuse_invalidate_entry(alias);
282 if (!hlist_empty(&inode->i_dentry))
283 return ERR_PTR(-EBUSY);
287 return d_splice_alias(inode, entry);
290 int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
291 struct fuse_entry_out *outarg, struct inode **inode)
293 struct fuse_conn *fc = get_fuse_conn_super(sb);
294 struct fuse_req *req;
295 struct fuse_forget_link *forget;
301 if (name->len > FUSE_NAME_MAX)
304 req = fuse_get_req_nopages(fc);
309 forget = fuse_alloc_forget();
312 fuse_put_request(fc, req);
316 attr_version = fuse_get_attr_version(fc);
318 fuse_lookup_init(fc, req, nodeid, name, outarg);
319 fuse_request_send(fc, req);
320 err = req->out.h.error;
321 fuse_put_request(fc, req);
322 /* Zero nodeid is same as -ENOENT, but with valid timeout */
323 if (err || !outarg->nodeid)
329 if (!fuse_valid_type(outarg->attr.mode))
332 *inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
333 &outarg->attr, entry_attr_timeout(outarg),
337 fuse_queue_forget(fc, forget, outarg->nodeid, 1);
348 static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
352 struct fuse_entry_out outarg;
354 struct dentry *newent;
355 struct fuse_conn *fc = get_fuse_conn(dir);
356 bool outarg_valid = true;
358 err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
360 if (err == -ENOENT) {
361 outarg_valid = false;
368 if (inode && get_node_id(inode) == FUSE_ROOT_ID)
371 if (inode && S_ISDIR(inode->i_mode)) {
372 mutex_lock(&fc->inst_mutex);
373 newent = fuse_d_add_directory(entry, inode);
374 mutex_unlock(&fc->inst_mutex);
375 err = PTR_ERR(newent);
379 newent = d_splice_alias(inode, entry);
382 entry = newent ? newent : entry;
384 fuse_change_entry_timeout(entry, &outarg);
386 fuse_invalidate_entry_cache(entry);
388 fuse_advise_use_readdirplus(dir);
398 * Atomic create+open operation
400 * If the filesystem doesn't support this, then fall back to separate
401 * 'mknod' + 'open' requests.
403 static int fuse_create_open(struct inode *dir, struct dentry *entry,
404 struct file *file, unsigned flags,
405 umode_t mode, int *opened)
409 struct fuse_conn *fc = get_fuse_conn(dir);
410 struct fuse_req *req;
411 struct fuse_forget_link *forget;
412 struct fuse_create_in inarg;
413 struct fuse_open_out outopen;
414 struct fuse_entry_out outentry;
415 struct fuse_file *ff;
417 /* Userspace expects S_IFREG in create mode */
418 BUG_ON((mode & S_IFMT) != S_IFREG);
420 forget = fuse_alloc_forget();
425 req = fuse_get_req_nopages(fc);
428 goto out_put_forget_req;
431 ff = fuse_file_alloc(fc);
433 goto out_put_request;
436 mode &= ~current_umask();
439 memset(&inarg, 0, sizeof(inarg));
440 memset(&outentry, 0, sizeof(outentry));
443 inarg.umask = current_umask();
444 req->in.h.opcode = FUSE_CREATE;
445 req->in.h.nodeid = get_node_id(dir);
447 req->in.args[0].size = fc->minor < 12 ? sizeof(struct fuse_open_in) :
449 req->in.args[0].value = &inarg;
450 req->in.args[1].size = entry->d_name.len + 1;
451 req->in.args[1].value = entry->d_name.name;
452 req->out.numargs = 2;
454 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
456 req->out.args[0].size = sizeof(outentry);
457 req->out.args[0].value = &outentry;
458 req->out.args[1].size = sizeof(outopen);
459 req->out.args[1].value = &outopen;
460 fuse_request_send(fc, req);
461 err = req->out.h.error;
466 if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid))
469 fuse_put_request(fc, req);
471 ff->nodeid = outentry.nodeid;
472 ff->open_flags = outopen.open_flags;
473 inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
474 &outentry.attr, entry_attr_timeout(&outentry), 0);
476 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
477 fuse_sync_release(ff, flags);
478 fuse_queue_forget(fc, forget, outentry.nodeid, 1);
483 d_instantiate(entry, inode);
484 fuse_change_entry_timeout(entry, &outentry);
485 fuse_invalidate_attr(dir);
486 err = finish_open(file, entry, generic_file_open, opened);
488 fuse_sync_release(ff, flags);
490 file->private_data = fuse_file_get(ff);
491 fuse_finish_open(inode, file);
498 fuse_put_request(fc, req);
505 static int fuse_mknod(struct inode *, struct dentry *, umode_t, dev_t);
506 static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
507 struct file *file, unsigned flags,
508 umode_t mode, int *opened)
511 struct fuse_conn *fc = get_fuse_conn(dir);
512 struct dentry *res = NULL;
514 if (d_unhashed(entry)) {
515 res = fuse_lookup(dir, entry, 0);
523 if (!(flags & O_CREAT) || entry->d_inode)
527 *opened |= FILE_CREATED;
532 err = fuse_create_open(dir, entry, file, flags, mode, opened);
533 if (err == -ENOSYS) {
542 err = fuse_mknod(dir, entry, mode, 0);
546 return finish_no_open(file, res);
550 * Code shared between mknod, mkdir, symlink and link
552 static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
553 struct inode *dir, struct dentry *entry,
556 struct fuse_entry_out outarg;
559 struct fuse_forget_link *forget;
561 forget = fuse_alloc_forget();
563 fuse_put_request(fc, req);
567 memset(&outarg, 0, sizeof(outarg));
568 req->in.h.nodeid = get_node_id(dir);
569 req->out.numargs = 1;
571 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
573 req->out.args[0].size = sizeof(outarg);
574 req->out.args[0].value = &outarg;
575 fuse_request_send(fc, req);
576 err = req->out.h.error;
577 fuse_put_request(fc, req);
579 goto out_put_forget_req;
582 if (invalid_nodeid(outarg.nodeid))
583 goto out_put_forget_req;
585 if ((outarg.attr.mode ^ mode) & S_IFMT)
586 goto out_put_forget_req;
588 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
589 &outarg.attr, entry_attr_timeout(&outarg), 0);
591 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
596 if (S_ISDIR(inode->i_mode)) {
597 struct dentry *alias;
598 mutex_lock(&fc->inst_mutex);
599 alias = d_find_alias(inode);
601 /* New directory must have moved since mkdir */
602 mutex_unlock(&fc->inst_mutex);
607 d_instantiate(entry, inode);
608 mutex_unlock(&fc->inst_mutex);
610 d_instantiate(entry, inode);
612 fuse_change_entry_timeout(entry, &outarg);
613 fuse_invalidate_attr(dir);
621 static int fuse_mknod(struct inode *dir, struct dentry *entry, umode_t mode,
624 struct fuse_mknod_in inarg;
625 struct fuse_conn *fc = get_fuse_conn(dir);
626 struct fuse_req *req = fuse_get_req_nopages(fc);
631 mode &= ~current_umask();
633 memset(&inarg, 0, sizeof(inarg));
635 inarg.rdev = new_encode_dev(rdev);
636 inarg.umask = current_umask();
637 req->in.h.opcode = FUSE_MKNOD;
639 req->in.args[0].size = fc->minor < 12 ? FUSE_COMPAT_MKNOD_IN_SIZE :
641 req->in.args[0].value = &inarg;
642 req->in.args[1].size = entry->d_name.len + 1;
643 req->in.args[1].value = entry->d_name.name;
644 return create_new_entry(fc, req, dir, entry, mode);
647 static int fuse_create(struct inode *dir, struct dentry *entry, umode_t mode,
650 return fuse_mknod(dir, entry, mode, 0);
653 static int fuse_mkdir(struct inode *dir, struct dentry *entry, umode_t mode)
655 struct fuse_mkdir_in inarg;
656 struct fuse_conn *fc = get_fuse_conn(dir);
657 struct fuse_req *req = fuse_get_req_nopages(fc);
662 mode &= ~current_umask();
664 memset(&inarg, 0, sizeof(inarg));
666 inarg.umask = current_umask();
667 req->in.h.opcode = FUSE_MKDIR;
669 req->in.args[0].size = sizeof(inarg);
670 req->in.args[0].value = &inarg;
671 req->in.args[1].size = entry->d_name.len + 1;
672 req->in.args[1].value = entry->d_name.name;
673 return create_new_entry(fc, req, dir, entry, S_IFDIR);
676 static int fuse_symlink(struct inode *dir, struct dentry *entry,
679 struct fuse_conn *fc = get_fuse_conn(dir);
680 unsigned len = strlen(link) + 1;
681 struct fuse_req *req = fuse_get_req_nopages(fc);
685 req->in.h.opcode = FUSE_SYMLINK;
687 req->in.args[0].size = entry->d_name.len + 1;
688 req->in.args[0].value = entry->d_name.name;
689 req->in.args[1].size = len;
690 req->in.args[1].value = link;
691 return create_new_entry(fc, req, dir, entry, S_IFLNK);
694 static int fuse_unlink(struct inode *dir, struct dentry *entry)
697 struct fuse_conn *fc = get_fuse_conn(dir);
698 struct fuse_req *req = fuse_get_req_nopages(fc);
702 req->in.h.opcode = FUSE_UNLINK;
703 req->in.h.nodeid = get_node_id(dir);
705 req->in.args[0].size = entry->d_name.len + 1;
706 req->in.args[0].value = entry->d_name.name;
707 fuse_request_send(fc, req);
708 err = req->out.h.error;
709 fuse_put_request(fc, req);
711 struct inode *inode = entry->d_inode;
712 struct fuse_inode *fi = get_fuse_inode(inode);
714 spin_lock(&fc->lock);
715 fi->attr_version = ++fc->attr_version;
717 * If i_nlink == 0 then unlink doesn't make sense, yet this can
718 * happen if userspace filesystem is careless. It would be
719 * difficult to enforce correct nlink usage so just ignore this
722 if (inode->i_nlink > 0)
724 spin_unlock(&fc->lock);
725 fuse_invalidate_attr(inode);
726 fuse_invalidate_attr(dir);
727 fuse_invalidate_entry_cache(entry);
728 } else if (err == -EINTR)
729 fuse_invalidate_entry(entry);
733 static int fuse_rmdir(struct inode *dir, struct dentry *entry)
736 struct fuse_conn *fc = get_fuse_conn(dir);
737 struct fuse_req *req = fuse_get_req_nopages(fc);
741 req->in.h.opcode = FUSE_RMDIR;
742 req->in.h.nodeid = get_node_id(dir);
744 req->in.args[0].size = entry->d_name.len + 1;
745 req->in.args[0].value = entry->d_name.name;
746 fuse_request_send(fc, req);
747 err = req->out.h.error;
748 fuse_put_request(fc, req);
750 clear_nlink(entry->d_inode);
751 fuse_invalidate_attr(dir);
752 fuse_invalidate_entry_cache(entry);
753 } else if (err == -EINTR)
754 fuse_invalidate_entry(entry);
758 static int fuse_rename(struct inode *olddir, struct dentry *oldent,
759 struct inode *newdir, struct dentry *newent)
762 struct fuse_rename_in inarg;
763 struct fuse_conn *fc = get_fuse_conn(olddir);
764 struct fuse_req *req = fuse_get_req_nopages(fc);
769 memset(&inarg, 0, sizeof(inarg));
770 inarg.newdir = get_node_id(newdir);
771 req->in.h.opcode = FUSE_RENAME;
772 req->in.h.nodeid = get_node_id(olddir);
774 req->in.args[0].size = sizeof(inarg);
775 req->in.args[0].value = &inarg;
776 req->in.args[1].size = oldent->d_name.len + 1;
777 req->in.args[1].value = oldent->d_name.name;
778 req->in.args[2].size = newent->d_name.len + 1;
779 req->in.args[2].value = newent->d_name.name;
780 fuse_request_send(fc, req);
781 err = req->out.h.error;
782 fuse_put_request(fc, req);
785 fuse_invalidate_attr(oldent->d_inode);
787 fuse_invalidate_attr(olddir);
788 if (olddir != newdir)
789 fuse_invalidate_attr(newdir);
791 /* newent will end up negative */
792 if (newent->d_inode) {
793 fuse_invalidate_attr(newent->d_inode);
794 fuse_invalidate_entry_cache(newent);
796 } else if (err == -EINTR) {
797 /* If request was interrupted, DEITY only knows if the
798 rename actually took place. If the invalidation
799 fails (e.g. some process has CWD under the renamed
800 directory), then there can be inconsistency between
801 the dcache and the real filesystem. Tough luck. */
802 fuse_invalidate_entry(oldent);
804 fuse_invalidate_entry(newent);
810 static int fuse_link(struct dentry *entry, struct inode *newdir,
811 struct dentry *newent)
814 struct fuse_link_in inarg;
815 struct inode *inode = entry->d_inode;
816 struct fuse_conn *fc = get_fuse_conn(inode);
817 struct fuse_req *req = fuse_get_req_nopages(fc);
821 memset(&inarg, 0, sizeof(inarg));
822 inarg.oldnodeid = get_node_id(inode);
823 req->in.h.opcode = FUSE_LINK;
825 req->in.args[0].size = sizeof(inarg);
826 req->in.args[0].value = &inarg;
827 req->in.args[1].size = newent->d_name.len + 1;
828 req->in.args[1].value = newent->d_name.name;
829 err = create_new_entry(fc, req, newdir, newent, inode->i_mode);
830 /* Contrary to "normal" filesystems it can happen that link
831 makes two "logical" inodes point to the same "physical"
832 inode. We invalidate the attributes of the old one, so it
833 will reflect changes in the backing inode (link count,
837 struct fuse_inode *fi = get_fuse_inode(inode);
839 spin_lock(&fc->lock);
840 fi->attr_version = ++fc->attr_version;
842 spin_unlock(&fc->lock);
843 fuse_invalidate_attr(inode);
844 } else if (err == -EINTR) {
845 fuse_invalidate_attr(inode);
850 static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr,
853 unsigned int blkbits;
855 stat->dev = inode->i_sb->s_dev;
856 stat->ino = attr->ino;
857 stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
858 stat->nlink = attr->nlink;
859 stat->uid = make_kuid(&init_user_ns, attr->uid);
860 stat->gid = make_kgid(&init_user_ns, attr->gid);
861 stat->rdev = inode->i_rdev;
862 stat->atime.tv_sec = attr->atime;
863 stat->atime.tv_nsec = attr->atimensec;
864 stat->mtime.tv_sec = attr->mtime;
865 stat->mtime.tv_nsec = attr->mtimensec;
866 stat->ctime.tv_sec = attr->ctime;
867 stat->ctime.tv_nsec = attr->ctimensec;
868 stat->size = attr->size;
869 stat->blocks = attr->blocks;
871 if (attr->blksize != 0)
872 blkbits = ilog2(attr->blksize);
874 blkbits = inode->i_sb->s_blocksize_bits;
876 stat->blksize = 1 << blkbits;
879 static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
883 struct fuse_getattr_in inarg;
884 struct fuse_attr_out outarg;
885 struct fuse_conn *fc = get_fuse_conn(inode);
886 struct fuse_req *req;
889 req = fuse_get_req_nopages(fc);
893 attr_version = fuse_get_attr_version(fc);
895 memset(&inarg, 0, sizeof(inarg));
896 memset(&outarg, 0, sizeof(outarg));
897 /* Directories have separate file-handle space */
898 if (file && S_ISREG(inode->i_mode)) {
899 struct fuse_file *ff = file->private_data;
901 inarg.getattr_flags |= FUSE_GETATTR_FH;
904 req->in.h.opcode = FUSE_GETATTR;
905 req->in.h.nodeid = get_node_id(inode);
907 req->in.args[0].size = sizeof(inarg);
908 req->in.args[0].value = &inarg;
909 req->out.numargs = 1;
911 req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
913 req->out.args[0].size = sizeof(outarg);
914 req->out.args[0].value = &outarg;
915 fuse_request_send(fc, req);
916 err = req->out.h.error;
917 fuse_put_request(fc, req);
919 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
920 make_bad_inode(inode);
923 fuse_change_attributes(inode, &outarg.attr,
924 attr_timeout(&outarg),
927 fuse_fillattr(inode, &outarg.attr, stat);
933 int fuse_update_attributes(struct inode *inode, struct kstat *stat,
934 struct file *file, bool *refreshed)
936 struct fuse_inode *fi = get_fuse_inode(inode);
940 if (fi->i_time < get_jiffies_64()) {
942 err = fuse_do_getattr(inode, stat, file);
947 generic_fillattr(inode, stat);
948 stat->mode = fi->orig_i_mode;
949 stat->ino = fi->orig_ino;
953 if (refreshed != NULL)
959 int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
960 u64 child_nodeid, struct qstr *name)
963 struct inode *parent;
965 struct dentry *entry;
967 parent = ilookup5(sb, parent_nodeid, fuse_inode_eq, &parent_nodeid);
971 mutex_lock(&parent->i_mutex);
972 if (!S_ISDIR(parent->i_mode))
976 dir = d_find_alias(parent);
980 entry = d_lookup(dir, name);
985 fuse_invalidate_attr(parent);
986 fuse_invalidate_entry(entry);
988 if (child_nodeid != 0 && entry->d_inode) {
989 mutex_lock(&entry->d_inode->i_mutex);
990 if (get_node_id(entry->d_inode) != child_nodeid) {
994 if (d_mountpoint(entry)) {
998 if (S_ISDIR(entry->d_inode->i_mode)) {
999 shrink_dcache_parent(entry);
1000 if (!simple_empty(entry)) {
1004 entry->d_inode->i_flags |= S_DEAD;
1007 clear_nlink(entry->d_inode);
1010 mutex_unlock(&entry->d_inode->i_mutex);
1019 mutex_unlock(&parent->i_mutex);
1025 * Calling into a user-controlled filesystem gives the filesystem
1026 * daemon ptrace-like capabilities over the current process. This
1027 * means, that the filesystem daemon is able to record the exact
1028 * filesystem operations performed, and can also control the behavior
1029 * of the requester process in otherwise impossible ways. For example
1030 * it can delay the operation for arbitrary length of time allowing
1031 * DoS against the requester.
1033 * For this reason only those processes can call into the filesystem,
1034 * for which the owner of the mount has ptrace privilege. This
1035 * excludes processes started by other users, suid or sgid processes.
1037 int fuse_allow_current_process(struct fuse_conn *fc)
1039 const struct cred *cred;
1041 if (fc->flags & FUSE_ALLOW_OTHER)
1044 cred = current_cred();
1045 if (uid_eq(cred->euid, fc->user_id) &&
1046 uid_eq(cred->suid, fc->user_id) &&
1047 uid_eq(cred->uid, fc->user_id) &&
1048 gid_eq(cred->egid, fc->group_id) &&
1049 gid_eq(cred->sgid, fc->group_id) &&
1050 gid_eq(cred->gid, fc->group_id))
1056 static int fuse_access(struct inode *inode, int mask)
1058 struct fuse_conn *fc = get_fuse_conn(inode);
1059 struct fuse_req *req;
1060 struct fuse_access_in inarg;
1066 req = fuse_get_req_nopages(fc);
1068 return PTR_ERR(req);
1070 memset(&inarg, 0, sizeof(inarg));
1071 inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC);
1072 req->in.h.opcode = FUSE_ACCESS;
1073 req->in.h.nodeid = get_node_id(inode);
1074 req->in.numargs = 1;
1075 req->in.args[0].size = sizeof(inarg);
1076 req->in.args[0].value = &inarg;
1077 fuse_request_send(fc, req);
1078 err = req->out.h.error;
1079 fuse_put_request(fc, req);
1080 if (err == -ENOSYS) {
1087 static int fuse_perm_getattr(struct inode *inode, int mask)
1089 if (mask & MAY_NOT_BLOCK)
1092 return fuse_do_getattr(inode, NULL, NULL);
1096 * Check permission. The two basic access models of FUSE are:
1098 * 1) Local access checking ('default_permissions' mount option) based
1099 * on file mode. This is the plain old disk filesystem permission
1102 * 2) "Remote" access checking, where server is responsible for
1103 * checking permission in each inode operation. An exception to this
1104 * is if ->permission() was invoked from sys_access() in which case an
1105 * access request is sent. Execute permission is still checked
1106 * locally based on file mode.
1108 static int fuse_permission(struct inode *inode, int mask)
1110 struct fuse_conn *fc = get_fuse_conn(inode);
1111 bool refreshed = false;
1114 if (!fuse_allow_current_process(fc))
1118 * If attributes are needed, refresh them before proceeding
1120 if ((fc->flags & FUSE_DEFAULT_PERMISSIONS) ||
1121 ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
1122 struct fuse_inode *fi = get_fuse_inode(inode);
1124 if (fi->i_time < get_jiffies_64()) {
1127 err = fuse_perm_getattr(inode, mask);
1133 if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
1134 err = generic_permission(inode, mask);
1136 /* If permission is denied, try to refresh file
1137 attributes. This is also needed, because the root
1138 node will at first have no permissions */
1139 if (err == -EACCES && !refreshed) {
1140 err = fuse_perm_getattr(inode, mask);
1142 err = generic_permission(inode, mask);
1145 /* Note: the opposite of the above test does not
1146 exist. So if permissions are revoked this won't be
1147 noticed immediately, only after the attribute
1148 timeout has expired */
1149 } else if (mask & (MAY_ACCESS | MAY_CHDIR)) {
1150 if (mask & MAY_NOT_BLOCK)
1153 err = fuse_access(inode, mask);
1154 } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
1155 if (!(inode->i_mode & S_IXUGO)) {
1159 err = fuse_perm_getattr(inode, mask);
1160 if (!err && !(inode->i_mode & S_IXUGO))
1167 static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
1168 void *dstbuf, filldir_t filldir)
1170 while (nbytes >= FUSE_NAME_OFFSET) {
1171 struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
1172 size_t reclen = FUSE_DIRENT_SIZE(dirent);
1174 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
1176 if (reclen > nbytes)
1179 over = filldir(dstbuf, dirent->name, dirent->namelen,
1180 file->f_pos, dirent->ino, dirent->type);
1186 file->f_pos = dirent->off;
1192 static int fuse_direntplus_link(struct file *file,
1193 struct fuse_direntplus *direntplus,
1197 struct fuse_entry_out *o = &direntplus->entry_out;
1198 struct fuse_dirent *dirent = &direntplus->dirent;
1199 struct dentry *parent = file->f_path.dentry;
1200 struct qstr name = QSTR_INIT(dirent->name, dirent->namelen);
1201 struct dentry *dentry;
1202 struct dentry *alias;
1203 struct inode *dir = parent->d_inode;
1204 struct fuse_conn *fc;
1205 struct inode *inode;
1209 * Unlike in the case of fuse_lookup, zero nodeid does not mean
1210 * ENOENT. Instead, it only means the userspace filesystem did
1211 * not want to return attributes/handle for this entry.
1218 if (name.name[0] == '.') {
1220 * We could potentially refresh the attributes of the directory
1225 if (name.name[1] == '.' && name.len == 2)
1228 fc = get_fuse_conn(dir);
1230 name.hash = full_name_hash(name.name, name.len);
1231 dentry = d_lookup(parent, &name);
1233 inode = dentry->d_inode;
1236 } else if (get_node_id(inode) != o->nodeid) {
1237 err = d_invalidate(dentry);
1241 struct fuse_inode *fi;
1242 fi = get_fuse_inode(inode);
1243 spin_lock(&fc->lock);
1245 spin_unlock(&fc->lock);
1248 * The other branch to 'found' comes via fuse_iget()
1249 * which bumps nlookup inside
1257 dentry = d_alloc(parent, &name);
1262 inode = fuse_iget(dir->i_sb, o->nodeid, o->generation,
1263 &o->attr, entry_attr_timeout(o), attr_version);
1267 if (S_ISDIR(inode->i_mode)) {
1268 mutex_lock(&fc->inst_mutex);
1269 alias = fuse_d_add_directory(dentry, inode);
1270 mutex_unlock(&fc->inst_mutex);
1271 err = PTR_ERR(alias);
1272 if (IS_ERR(alias)) {
1277 alias = d_splice_alias(inode, dentry);
1286 fuse_change_attributes(inode, &o->attr, entry_attr_timeout(o),
1289 fuse_change_entry_timeout(dentry, o);
1298 static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
1299 void *dstbuf, filldir_t filldir, 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 = filldir(dstbuf, dirent->name, dirent->namelen,
1325 file->f_pos, dirent->ino,
1327 file->f_pos = dirent->off;
1333 ret = fuse_direntplus_link(file, direntplus, attr_version);
1335 fuse_force_forget(file, direntplus->entry_out.nodeid);
1341 static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
1346 struct inode *inode = file_inode(file);
1347 struct fuse_conn *fc = get_fuse_conn(inode);
1348 struct fuse_req *req;
1349 u64 attr_version = 0;
1351 if (is_bad_inode(inode))
1354 req = fuse_get_req(fc, 1);
1356 return PTR_ERR(req);
1358 page = alloc_page(GFP_KERNEL);
1360 fuse_put_request(fc, req);
1364 plus = fuse_use_readdirplus(inode, file);
1365 req->out.argpages = 1;
1367 req->pages[0] = page;
1368 req->page_descs[0].length = PAGE_SIZE;
1370 attr_version = fuse_get_attr_version(fc);
1371 fuse_read_fill(req, file, file->f_pos, PAGE_SIZE,
1374 fuse_read_fill(req, file, file->f_pos, PAGE_SIZE,
1377 fuse_request_send(fc, req);
1378 nbytes = req->out.args[0].size;
1379 err = req->out.h.error;
1380 fuse_put_request(fc, req);
1383 err = parse_dirplusfile(page_address(page), nbytes,
1384 file, dstbuf, filldir,
1387 err = parse_dirfile(page_address(page), nbytes, file,
1393 fuse_invalidate_attr(inode); /* atime changed */
1397 static char *read_link(struct dentry *dentry)
1399 struct inode *inode = dentry->d_inode;
1400 struct fuse_conn *fc = get_fuse_conn(inode);
1401 struct fuse_req *req = fuse_get_req_nopages(fc);
1405 return ERR_CAST(req);
1407 link = (char *) __get_free_page(GFP_KERNEL);
1409 link = ERR_PTR(-ENOMEM);
1412 req->in.h.opcode = FUSE_READLINK;
1413 req->in.h.nodeid = get_node_id(inode);
1414 req->out.argvar = 1;
1415 req->out.numargs = 1;
1416 req->out.args[0].size = PAGE_SIZE - 1;
1417 req->out.args[0].value = link;
1418 fuse_request_send(fc, req);
1419 if (req->out.h.error) {
1420 free_page((unsigned long) link);
1421 link = ERR_PTR(req->out.h.error);
1423 link[req->out.args[0].size] = '\0';
1425 fuse_put_request(fc, req);
1426 fuse_invalidate_attr(inode); /* atime changed */
1430 static void free_link(char *link)
1433 free_page((unsigned long) link);
1436 static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd)
1438 nd_set_link(nd, read_link(dentry));
1442 static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
1444 free_link(nd_get_link(nd));
1447 static int fuse_dir_open(struct inode *inode, struct file *file)
1449 return fuse_open_common(inode, file, true);
1452 static int fuse_dir_release(struct inode *inode, struct file *file)
1454 fuse_release_common(file, FUSE_RELEASEDIR);
1459 static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
1462 return fuse_fsync_common(file, start, end, datasync, 1);
1465 static long fuse_dir_ioctl(struct file *file, unsigned int cmd,
1468 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1470 /* FUSE_IOCTL_DIR only supported for API version >= 7.18 */
1474 return fuse_ioctl_common(file, cmd, arg, FUSE_IOCTL_DIR);
1477 static long fuse_dir_compat_ioctl(struct file *file, unsigned int cmd,
1480 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1485 return fuse_ioctl_common(file, cmd, arg,
1486 FUSE_IOCTL_COMPAT | FUSE_IOCTL_DIR);
1489 static bool update_mtime(unsigned ivalid)
1491 /* Always update if mtime is explicitly set */
1492 if (ivalid & ATTR_MTIME_SET)
1495 /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
1496 if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
1499 /* In all other cases update */
1503 static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
1505 unsigned ivalid = iattr->ia_valid;
1507 if (ivalid & ATTR_MODE)
1508 arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode;
1509 if (ivalid & ATTR_UID)
1510 arg->valid |= FATTR_UID, arg->uid = from_kuid(&init_user_ns, iattr->ia_uid);
1511 if (ivalid & ATTR_GID)
1512 arg->valid |= FATTR_GID, arg->gid = from_kgid(&init_user_ns, iattr->ia_gid);
1513 if (ivalid & ATTR_SIZE)
1514 arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size;
1515 if (ivalid & ATTR_ATIME) {
1516 arg->valid |= FATTR_ATIME;
1517 arg->atime = iattr->ia_atime.tv_sec;
1518 arg->atimensec = iattr->ia_atime.tv_nsec;
1519 if (!(ivalid & ATTR_ATIME_SET))
1520 arg->valid |= FATTR_ATIME_NOW;
1522 if ((ivalid & ATTR_MTIME) && update_mtime(ivalid)) {
1523 arg->valid |= FATTR_MTIME;
1524 arg->mtime = iattr->ia_mtime.tv_sec;
1525 arg->mtimensec = iattr->ia_mtime.tv_nsec;
1526 if (!(ivalid & ATTR_MTIME_SET))
1527 arg->valid |= FATTR_MTIME_NOW;
1532 * Prevent concurrent writepages on inode
1534 * This is done by adding a negative bias to the inode write counter
1535 * and waiting for all pending writes to finish.
1537 void fuse_set_nowrite(struct inode *inode)
1539 struct fuse_conn *fc = get_fuse_conn(inode);
1540 struct fuse_inode *fi = get_fuse_inode(inode);
1542 BUG_ON(!mutex_is_locked(&inode->i_mutex));
1544 spin_lock(&fc->lock);
1545 BUG_ON(fi->writectr < 0);
1546 fi->writectr += FUSE_NOWRITE;
1547 spin_unlock(&fc->lock);
1548 wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
1552 * Allow writepages on inode
1554 * Remove the bias from the writecounter and send any queued
1557 static void __fuse_release_nowrite(struct inode *inode)
1559 struct fuse_inode *fi = get_fuse_inode(inode);
1561 BUG_ON(fi->writectr != FUSE_NOWRITE);
1563 fuse_flush_writepages(inode);
1566 void fuse_release_nowrite(struct inode *inode)
1568 struct fuse_conn *fc = get_fuse_conn(inode);
1570 spin_lock(&fc->lock);
1571 __fuse_release_nowrite(inode);
1572 spin_unlock(&fc->lock);
1576 * Set attributes, and at the same time refresh them.
1578 * Truncation is slightly complicated, because the 'truncate' request
1579 * may fail, in which case we don't want to touch the mapping.
1580 * vmtruncate() doesn't allow for this case, so do the rlimit checking
1581 * and the actual truncation by hand.
1583 int fuse_do_setattr(struct inode *inode, struct iattr *attr,
1586 struct fuse_conn *fc = get_fuse_conn(inode);
1587 struct fuse_req *req;
1588 struct fuse_setattr_in inarg;
1589 struct fuse_attr_out outarg;
1590 bool is_truncate = false;
1594 if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
1595 attr->ia_valid |= ATTR_FORCE;
1597 err = inode_change_ok(inode, attr);
1601 if (attr->ia_valid & ATTR_OPEN) {
1602 if (fc->atomic_o_trunc)
1607 if (attr->ia_valid & ATTR_SIZE)
1610 req = fuse_get_req_nopages(fc);
1612 return PTR_ERR(req);
1615 fuse_set_nowrite(inode);
1617 memset(&inarg, 0, sizeof(inarg));
1618 memset(&outarg, 0, sizeof(outarg));
1619 iattr_to_fattr(attr, &inarg);
1621 struct fuse_file *ff = file->private_data;
1622 inarg.valid |= FATTR_FH;
1625 if (attr->ia_valid & ATTR_SIZE) {
1626 /* For mandatory locking in truncate */
1627 inarg.valid |= FATTR_LOCKOWNER;
1628 inarg.lock_owner = fuse_lock_owner_id(fc, current->files);
1630 req->in.h.opcode = FUSE_SETATTR;
1631 req->in.h.nodeid = get_node_id(inode);
1632 req->in.numargs = 1;
1633 req->in.args[0].size = sizeof(inarg);
1634 req->in.args[0].value = &inarg;
1635 req->out.numargs = 1;
1637 req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
1639 req->out.args[0].size = sizeof(outarg);
1640 req->out.args[0].value = &outarg;
1641 fuse_request_send(fc, req);
1642 err = req->out.h.error;
1643 fuse_put_request(fc, req);
1646 fuse_invalidate_attr(inode);
1650 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1651 make_bad_inode(inode);
1656 spin_lock(&fc->lock);
1657 fuse_change_attributes_common(inode, &outarg.attr,
1658 attr_timeout(&outarg));
1659 oldsize = inode->i_size;
1660 i_size_write(inode, outarg.attr.size);
1663 /* NOTE: this may release/reacquire fc->lock */
1664 __fuse_release_nowrite(inode);
1666 spin_unlock(&fc->lock);
1669 * Only call invalidate_inode_pages2() after removing
1670 * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
1672 if (S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
1673 truncate_pagecache(inode, oldsize, outarg.attr.size);
1674 invalidate_inode_pages2(inode->i_mapping);
1681 fuse_release_nowrite(inode);
1686 static int fuse_setattr(struct dentry *entry, struct iattr *attr)
1688 struct inode *inode = entry->d_inode;
1690 if (!fuse_allow_current_process(get_fuse_conn(inode)))
1693 if (attr->ia_valid & ATTR_FILE)
1694 return fuse_do_setattr(inode, attr, attr->ia_file);
1696 return fuse_do_setattr(inode, attr, NULL);
1699 static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
1702 struct inode *inode = entry->d_inode;
1703 struct fuse_conn *fc = get_fuse_conn(inode);
1705 if (!fuse_allow_current_process(fc))
1708 return fuse_update_attributes(inode, stat, NULL, NULL);
1711 static int fuse_setxattr(struct dentry *entry, const char *name,
1712 const void *value, size_t size, int flags)
1714 struct inode *inode = entry->d_inode;
1715 struct fuse_conn *fc = get_fuse_conn(inode);
1716 struct fuse_req *req;
1717 struct fuse_setxattr_in inarg;
1720 if (fc->no_setxattr)
1723 req = fuse_get_req_nopages(fc);
1725 return PTR_ERR(req);
1727 memset(&inarg, 0, sizeof(inarg));
1729 inarg.flags = flags;
1730 req->in.h.opcode = FUSE_SETXATTR;
1731 req->in.h.nodeid = get_node_id(inode);
1732 req->in.numargs = 3;
1733 req->in.args[0].size = sizeof(inarg);
1734 req->in.args[0].value = &inarg;
1735 req->in.args[1].size = strlen(name) + 1;
1736 req->in.args[1].value = name;
1737 req->in.args[2].size = size;
1738 req->in.args[2].value = value;
1739 fuse_request_send(fc, req);
1740 err = req->out.h.error;
1741 fuse_put_request(fc, req);
1742 if (err == -ENOSYS) {
1743 fc->no_setxattr = 1;
1749 static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
1750 void *value, size_t size)
1752 struct inode *inode = entry->d_inode;
1753 struct fuse_conn *fc = get_fuse_conn(inode);
1754 struct fuse_req *req;
1755 struct fuse_getxattr_in inarg;
1756 struct fuse_getxattr_out outarg;
1759 if (fc->no_getxattr)
1762 req = fuse_get_req_nopages(fc);
1764 return PTR_ERR(req);
1766 memset(&inarg, 0, sizeof(inarg));
1768 req->in.h.opcode = FUSE_GETXATTR;
1769 req->in.h.nodeid = get_node_id(inode);
1770 req->in.numargs = 2;
1771 req->in.args[0].size = sizeof(inarg);
1772 req->in.args[0].value = &inarg;
1773 req->in.args[1].size = strlen(name) + 1;
1774 req->in.args[1].value = name;
1775 /* This is really two different operations rolled into one */
1776 req->out.numargs = 1;
1778 req->out.argvar = 1;
1779 req->out.args[0].size = size;
1780 req->out.args[0].value = value;
1782 req->out.args[0].size = sizeof(outarg);
1783 req->out.args[0].value = &outarg;
1785 fuse_request_send(fc, req);
1786 ret = req->out.h.error;
1788 ret = size ? req->out.args[0].size : outarg.size;
1790 if (ret == -ENOSYS) {
1791 fc->no_getxattr = 1;
1795 fuse_put_request(fc, req);
1799 static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
1801 struct inode *inode = entry->d_inode;
1802 struct fuse_conn *fc = get_fuse_conn(inode);
1803 struct fuse_req *req;
1804 struct fuse_getxattr_in inarg;
1805 struct fuse_getxattr_out outarg;
1808 if (!fuse_allow_current_process(fc))
1811 if (fc->no_listxattr)
1814 req = fuse_get_req_nopages(fc);
1816 return PTR_ERR(req);
1818 memset(&inarg, 0, sizeof(inarg));
1820 req->in.h.opcode = FUSE_LISTXATTR;
1821 req->in.h.nodeid = get_node_id(inode);
1822 req->in.numargs = 1;
1823 req->in.args[0].size = sizeof(inarg);
1824 req->in.args[0].value = &inarg;
1825 /* This is really two different operations rolled into one */
1826 req->out.numargs = 1;
1828 req->out.argvar = 1;
1829 req->out.args[0].size = size;
1830 req->out.args[0].value = list;
1832 req->out.args[0].size = sizeof(outarg);
1833 req->out.args[0].value = &outarg;
1835 fuse_request_send(fc, req);
1836 ret = req->out.h.error;
1838 ret = size ? req->out.args[0].size : outarg.size;
1840 if (ret == -ENOSYS) {
1841 fc->no_listxattr = 1;
1845 fuse_put_request(fc, req);
1849 static int fuse_removexattr(struct dentry *entry, const char *name)
1851 struct inode *inode = entry->d_inode;
1852 struct fuse_conn *fc = get_fuse_conn(inode);
1853 struct fuse_req *req;
1856 if (fc->no_removexattr)
1859 req = fuse_get_req_nopages(fc);
1861 return PTR_ERR(req);
1863 req->in.h.opcode = FUSE_REMOVEXATTR;
1864 req->in.h.nodeid = get_node_id(inode);
1865 req->in.numargs = 1;
1866 req->in.args[0].size = strlen(name) + 1;
1867 req->in.args[0].value = name;
1868 fuse_request_send(fc, req);
1869 err = req->out.h.error;
1870 fuse_put_request(fc, req);
1871 if (err == -ENOSYS) {
1872 fc->no_removexattr = 1;
1878 static const struct inode_operations fuse_dir_inode_operations = {
1879 .lookup = fuse_lookup,
1880 .mkdir = fuse_mkdir,
1881 .symlink = fuse_symlink,
1882 .unlink = fuse_unlink,
1883 .rmdir = fuse_rmdir,
1884 .rename = fuse_rename,
1886 .setattr = fuse_setattr,
1887 .create = fuse_create,
1888 .atomic_open = fuse_atomic_open,
1889 .mknod = fuse_mknod,
1890 .permission = fuse_permission,
1891 .getattr = fuse_getattr,
1892 .setxattr = fuse_setxattr,
1893 .getxattr = fuse_getxattr,
1894 .listxattr = fuse_listxattr,
1895 .removexattr = fuse_removexattr,
1898 static const struct file_operations fuse_dir_operations = {
1899 .llseek = generic_file_llseek,
1900 .read = generic_read_dir,
1901 .readdir = fuse_readdir,
1902 .open = fuse_dir_open,
1903 .release = fuse_dir_release,
1904 .fsync = fuse_dir_fsync,
1905 .unlocked_ioctl = fuse_dir_ioctl,
1906 .compat_ioctl = fuse_dir_compat_ioctl,
1909 static const struct inode_operations fuse_common_inode_operations = {
1910 .setattr = fuse_setattr,
1911 .permission = fuse_permission,
1912 .getattr = fuse_getattr,
1913 .setxattr = fuse_setxattr,
1914 .getxattr = fuse_getxattr,
1915 .listxattr = fuse_listxattr,
1916 .removexattr = fuse_removexattr,
1919 static const struct inode_operations fuse_symlink_inode_operations = {
1920 .setattr = fuse_setattr,
1921 .follow_link = fuse_follow_link,
1922 .put_link = fuse_put_link,
1923 .readlink = generic_readlink,
1924 .getattr = fuse_getattr,
1925 .setxattr = fuse_setxattr,
1926 .getxattr = fuse_getxattr,
1927 .listxattr = fuse_listxattr,
1928 .removexattr = fuse_removexattr,
1931 void fuse_init_common(struct inode *inode)
1933 inode->i_op = &fuse_common_inode_operations;
1936 void fuse_init_dir(struct inode *inode)
1938 inode->i_op = &fuse_dir_inode_operations;
1939 inode->i_fop = &fuse_dir_operations;
1942 void fuse_init_symlink(struct inode *inode)
1944 inode->i_op = &fuse_symlink_inode_operations;