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))
268 shrink_submounts_and_drop(entry);
273 static int invalid_nodeid(u64 nodeid)
275 return !nodeid || nodeid == FUSE_ROOT_ID;
278 const struct dentry_operations fuse_dentry_operations = {
279 .d_revalidate = fuse_dentry_revalidate,
282 int fuse_valid_type(int m)
284 return S_ISREG(m) || S_ISDIR(m) || S_ISLNK(m) || S_ISCHR(m) ||
285 S_ISBLK(m) || S_ISFIFO(m) || S_ISSOCK(m);
288 int fuse_lookup_name(struct super_block *sb, u64 nodeid, struct qstr *name,
289 struct fuse_entry_out *outarg, struct inode **inode)
291 struct fuse_conn *fc = get_fuse_conn_super(sb);
292 struct fuse_req *req;
293 struct fuse_forget_link *forget;
299 if (name->len > FUSE_NAME_MAX)
302 req = fuse_get_req_nopages(fc);
307 forget = fuse_alloc_forget();
310 fuse_put_request(fc, req);
314 attr_version = fuse_get_attr_version(fc);
316 fuse_lookup_init(fc, req, nodeid, name, outarg);
317 fuse_request_send(fc, req);
318 err = req->out.h.error;
319 fuse_put_request(fc, req);
320 /* Zero nodeid is same as -ENOENT, but with valid timeout */
321 if (err || !outarg->nodeid)
327 if (!fuse_valid_type(outarg->attr.mode))
330 *inode = fuse_iget(sb, outarg->nodeid, outarg->generation,
331 &outarg->attr, entry_attr_timeout(outarg),
335 fuse_queue_forget(fc, forget, outarg->nodeid, 1);
346 static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
350 struct fuse_entry_out outarg;
352 struct dentry *newent;
353 bool outarg_valid = true;
355 err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
357 if (err == -ENOENT) {
358 outarg_valid = false;
365 if (inode && get_node_id(inode) == FUSE_ROOT_ID)
368 newent = d_materialise_unique(entry, inode);
369 err = PTR_ERR(newent);
373 entry = newent ? newent : entry;
375 fuse_change_entry_timeout(entry, &outarg);
377 fuse_invalidate_entry_cache(entry);
379 fuse_advise_use_readdirplus(dir);
389 * Atomic create+open operation
391 * If the filesystem doesn't support this, then fall back to separate
392 * 'mknod' + 'open' requests.
394 static int fuse_create_open(struct inode *dir, struct dentry *entry,
395 struct file *file, unsigned flags,
396 umode_t mode, int *opened)
400 struct fuse_conn *fc = get_fuse_conn(dir);
401 struct fuse_req *req;
402 struct fuse_forget_link *forget;
403 struct fuse_create_in inarg;
404 struct fuse_open_out outopen;
405 struct fuse_entry_out outentry;
406 struct fuse_file *ff;
408 /* Userspace expects S_IFREG in create mode */
409 BUG_ON((mode & S_IFMT) != S_IFREG);
411 forget = fuse_alloc_forget();
416 req = fuse_get_req_nopages(fc);
419 goto out_put_forget_req;
422 ff = fuse_file_alloc(fc);
424 goto out_put_request;
427 mode &= ~current_umask();
430 memset(&inarg, 0, sizeof(inarg));
431 memset(&outentry, 0, sizeof(outentry));
434 inarg.umask = current_umask();
435 req->in.h.opcode = FUSE_CREATE;
436 req->in.h.nodeid = get_node_id(dir);
438 req->in.args[0].size = fc->minor < 12 ? sizeof(struct fuse_open_in) :
440 req->in.args[0].value = &inarg;
441 req->in.args[1].size = entry->d_name.len + 1;
442 req->in.args[1].value = entry->d_name.name;
443 req->out.numargs = 2;
445 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
447 req->out.args[0].size = sizeof(outentry);
448 req->out.args[0].value = &outentry;
449 req->out.args[1].size = sizeof(outopen);
450 req->out.args[1].value = &outopen;
451 fuse_request_send(fc, req);
452 err = req->out.h.error;
457 if (!S_ISREG(outentry.attr.mode) || invalid_nodeid(outentry.nodeid))
460 fuse_put_request(fc, req);
462 ff->nodeid = outentry.nodeid;
463 ff->open_flags = outopen.open_flags;
464 inode = fuse_iget(dir->i_sb, outentry.nodeid, outentry.generation,
465 &outentry.attr, entry_attr_timeout(&outentry), 0);
467 flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
468 fuse_sync_release(ff, flags);
469 fuse_queue_forget(fc, forget, outentry.nodeid, 1);
474 d_instantiate(entry, inode);
475 fuse_change_entry_timeout(entry, &outentry);
476 fuse_invalidate_attr(dir);
477 err = finish_open(file, entry, generic_file_open, opened);
479 fuse_sync_release(ff, flags);
481 file->private_data = fuse_file_get(ff);
482 fuse_finish_open(inode, file);
489 fuse_put_request(fc, req);
496 static int fuse_mknod(struct inode *, struct dentry *, umode_t, dev_t);
497 static int fuse_atomic_open(struct inode *dir, struct dentry *entry,
498 struct file *file, unsigned flags,
499 umode_t mode, int *opened)
502 struct fuse_conn *fc = get_fuse_conn(dir);
503 struct dentry *res = NULL;
505 if (d_unhashed(entry)) {
506 res = fuse_lookup(dir, entry, 0);
514 if (!(flags & O_CREAT) || entry->d_inode)
518 *opened |= FILE_CREATED;
523 err = fuse_create_open(dir, entry, file, flags, mode, opened);
524 if (err == -ENOSYS) {
533 err = fuse_mknod(dir, entry, mode, 0);
537 return finish_no_open(file, res);
541 * Code shared between mknod, mkdir, symlink and link
543 static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
544 struct inode *dir, struct dentry *entry,
547 struct fuse_entry_out outarg;
550 struct fuse_forget_link *forget;
552 forget = fuse_alloc_forget();
554 fuse_put_request(fc, req);
558 memset(&outarg, 0, sizeof(outarg));
559 req->in.h.nodeid = get_node_id(dir);
560 req->out.numargs = 1;
562 req->out.args[0].size = FUSE_COMPAT_ENTRY_OUT_SIZE;
564 req->out.args[0].size = sizeof(outarg);
565 req->out.args[0].value = &outarg;
566 fuse_request_send(fc, req);
567 err = req->out.h.error;
568 fuse_put_request(fc, req);
570 goto out_put_forget_req;
573 if (invalid_nodeid(outarg.nodeid))
574 goto out_put_forget_req;
576 if ((outarg.attr.mode ^ mode) & S_IFMT)
577 goto out_put_forget_req;
579 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
580 &outarg.attr, entry_attr_timeout(&outarg), 0);
582 fuse_queue_forget(fc, forget, outarg.nodeid, 1);
587 err = d_instantiate_no_diralias(entry, inode);
593 fuse_change_entry_timeout(entry, &outarg);
594 fuse_invalidate_attr(dir);
602 static int fuse_mknod(struct inode *dir, struct dentry *entry, umode_t mode,
605 struct fuse_mknod_in inarg;
606 struct fuse_conn *fc = get_fuse_conn(dir);
607 struct fuse_req *req = fuse_get_req_nopages(fc);
612 mode &= ~current_umask();
614 memset(&inarg, 0, sizeof(inarg));
616 inarg.rdev = new_encode_dev(rdev);
617 inarg.umask = current_umask();
618 req->in.h.opcode = FUSE_MKNOD;
620 req->in.args[0].size = fc->minor < 12 ? FUSE_COMPAT_MKNOD_IN_SIZE :
622 req->in.args[0].value = &inarg;
623 req->in.args[1].size = entry->d_name.len + 1;
624 req->in.args[1].value = entry->d_name.name;
625 return create_new_entry(fc, req, dir, entry, mode);
628 static int fuse_create(struct inode *dir, struct dentry *entry, umode_t mode,
631 return fuse_mknod(dir, entry, mode, 0);
634 static int fuse_mkdir(struct inode *dir, struct dentry *entry, umode_t mode)
636 struct fuse_mkdir_in inarg;
637 struct fuse_conn *fc = get_fuse_conn(dir);
638 struct fuse_req *req = fuse_get_req_nopages(fc);
643 mode &= ~current_umask();
645 memset(&inarg, 0, sizeof(inarg));
647 inarg.umask = current_umask();
648 req->in.h.opcode = FUSE_MKDIR;
650 req->in.args[0].size = sizeof(inarg);
651 req->in.args[0].value = &inarg;
652 req->in.args[1].size = entry->d_name.len + 1;
653 req->in.args[1].value = entry->d_name.name;
654 return create_new_entry(fc, req, dir, entry, S_IFDIR);
657 static int fuse_symlink(struct inode *dir, struct dentry *entry,
660 struct fuse_conn *fc = get_fuse_conn(dir);
661 unsigned len = strlen(link) + 1;
662 struct fuse_req *req = fuse_get_req_nopages(fc);
666 req->in.h.opcode = FUSE_SYMLINK;
668 req->in.args[0].size = entry->d_name.len + 1;
669 req->in.args[0].value = entry->d_name.name;
670 req->in.args[1].size = len;
671 req->in.args[1].value = link;
672 return create_new_entry(fc, req, dir, entry, S_IFLNK);
675 static int fuse_unlink(struct inode *dir, struct dentry *entry)
678 struct fuse_conn *fc = get_fuse_conn(dir);
679 struct fuse_req *req = fuse_get_req_nopages(fc);
683 req->in.h.opcode = FUSE_UNLINK;
684 req->in.h.nodeid = get_node_id(dir);
686 req->in.args[0].size = entry->d_name.len + 1;
687 req->in.args[0].value = entry->d_name.name;
688 fuse_request_send(fc, req);
689 err = req->out.h.error;
690 fuse_put_request(fc, req);
692 struct inode *inode = entry->d_inode;
693 struct fuse_inode *fi = get_fuse_inode(inode);
695 spin_lock(&fc->lock);
696 fi->attr_version = ++fc->attr_version;
698 * If i_nlink == 0 then unlink doesn't make sense, yet this can
699 * happen if userspace filesystem is careless. It would be
700 * difficult to enforce correct nlink usage so just ignore this
703 if (inode->i_nlink > 0)
705 spin_unlock(&fc->lock);
706 fuse_invalidate_attr(inode);
707 fuse_invalidate_attr(dir);
708 fuse_invalidate_entry_cache(entry);
709 } else if (err == -EINTR)
710 fuse_invalidate_entry(entry);
714 static int fuse_rmdir(struct inode *dir, struct dentry *entry)
717 struct fuse_conn *fc = get_fuse_conn(dir);
718 struct fuse_req *req = fuse_get_req_nopages(fc);
722 req->in.h.opcode = FUSE_RMDIR;
723 req->in.h.nodeid = get_node_id(dir);
725 req->in.args[0].size = entry->d_name.len + 1;
726 req->in.args[0].value = entry->d_name.name;
727 fuse_request_send(fc, req);
728 err = req->out.h.error;
729 fuse_put_request(fc, req);
731 clear_nlink(entry->d_inode);
732 fuse_invalidate_attr(dir);
733 fuse_invalidate_entry_cache(entry);
734 } else if (err == -EINTR)
735 fuse_invalidate_entry(entry);
739 static int fuse_rename(struct inode *olddir, struct dentry *oldent,
740 struct inode *newdir, struct dentry *newent)
743 struct fuse_rename_in inarg;
744 struct fuse_conn *fc = get_fuse_conn(olddir);
745 struct fuse_req *req = fuse_get_req_nopages(fc);
750 memset(&inarg, 0, sizeof(inarg));
751 inarg.newdir = get_node_id(newdir);
752 req->in.h.opcode = FUSE_RENAME;
753 req->in.h.nodeid = get_node_id(olddir);
755 req->in.args[0].size = sizeof(inarg);
756 req->in.args[0].value = &inarg;
757 req->in.args[1].size = oldent->d_name.len + 1;
758 req->in.args[1].value = oldent->d_name.name;
759 req->in.args[2].size = newent->d_name.len + 1;
760 req->in.args[2].value = newent->d_name.name;
761 fuse_request_send(fc, req);
762 err = req->out.h.error;
763 fuse_put_request(fc, req);
766 fuse_invalidate_attr(oldent->d_inode);
768 fuse_invalidate_attr(olddir);
769 if (olddir != newdir)
770 fuse_invalidate_attr(newdir);
772 /* newent will end up negative */
773 if (newent->d_inode) {
774 fuse_invalidate_attr(newent->d_inode);
775 fuse_invalidate_entry_cache(newent);
777 } else if (err == -EINTR) {
778 /* If request was interrupted, DEITY only knows if the
779 rename actually took place. If the invalidation
780 fails (e.g. some process has CWD under the renamed
781 directory), then there can be inconsistency between
782 the dcache and the real filesystem. Tough luck. */
783 fuse_invalidate_entry(oldent);
785 fuse_invalidate_entry(newent);
791 static int fuse_link(struct dentry *entry, struct inode *newdir,
792 struct dentry *newent)
795 struct fuse_link_in inarg;
796 struct inode *inode = entry->d_inode;
797 struct fuse_conn *fc = get_fuse_conn(inode);
798 struct fuse_req *req = fuse_get_req_nopages(fc);
802 memset(&inarg, 0, sizeof(inarg));
803 inarg.oldnodeid = get_node_id(inode);
804 req->in.h.opcode = FUSE_LINK;
806 req->in.args[0].size = sizeof(inarg);
807 req->in.args[0].value = &inarg;
808 req->in.args[1].size = newent->d_name.len + 1;
809 req->in.args[1].value = newent->d_name.name;
810 err = create_new_entry(fc, req, newdir, newent, inode->i_mode);
811 /* Contrary to "normal" filesystems it can happen that link
812 makes two "logical" inodes point to the same "physical"
813 inode. We invalidate the attributes of the old one, so it
814 will reflect changes in the backing inode (link count,
818 struct fuse_inode *fi = get_fuse_inode(inode);
820 spin_lock(&fc->lock);
821 fi->attr_version = ++fc->attr_version;
823 spin_unlock(&fc->lock);
824 fuse_invalidate_attr(inode);
825 } else if (err == -EINTR) {
826 fuse_invalidate_attr(inode);
831 static void fuse_fillattr(struct inode *inode, struct fuse_attr *attr,
834 unsigned int blkbits;
836 stat->dev = inode->i_sb->s_dev;
837 stat->ino = attr->ino;
838 stat->mode = (inode->i_mode & S_IFMT) | (attr->mode & 07777);
839 stat->nlink = attr->nlink;
840 stat->uid = make_kuid(&init_user_ns, attr->uid);
841 stat->gid = make_kgid(&init_user_ns, attr->gid);
842 stat->rdev = inode->i_rdev;
843 stat->atime.tv_sec = attr->atime;
844 stat->atime.tv_nsec = attr->atimensec;
845 stat->mtime.tv_sec = attr->mtime;
846 stat->mtime.tv_nsec = attr->mtimensec;
847 stat->ctime.tv_sec = attr->ctime;
848 stat->ctime.tv_nsec = attr->ctimensec;
849 stat->size = attr->size;
850 stat->blocks = attr->blocks;
852 if (attr->blksize != 0)
853 blkbits = ilog2(attr->blksize);
855 blkbits = inode->i_sb->s_blocksize_bits;
857 stat->blksize = 1 << blkbits;
860 static int fuse_do_getattr(struct inode *inode, struct kstat *stat,
864 struct fuse_getattr_in inarg;
865 struct fuse_attr_out outarg;
866 struct fuse_conn *fc = get_fuse_conn(inode);
867 struct fuse_req *req;
870 req = fuse_get_req_nopages(fc);
874 attr_version = fuse_get_attr_version(fc);
876 memset(&inarg, 0, sizeof(inarg));
877 memset(&outarg, 0, sizeof(outarg));
878 /* Directories have separate file-handle space */
879 if (file && S_ISREG(inode->i_mode)) {
880 struct fuse_file *ff = file->private_data;
882 inarg.getattr_flags |= FUSE_GETATTR_FH;
885 req->in.h.opcode = FUSE_GETATTR;
886 req->in.h.nodeid = get_node_id(inode);
888 req->in.args[0].size = sizeof(inarg);
889 req->in.args[0].value = &inarg;
890 req->out.numargs = 1;
892 req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
894 req->out.args[0].size = sizeof(outarg);
895 req->out.args[0].value = &outarg;
896 fuse_request_send(fc, req);
897 err = req->out.h.error;
898 fuse_put_request(fc, req);
900 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
901 make_bad_inode(inode);
904 fuse_change_attributes(inode, &outarg.attr,
905 attr_timeout(&outarg),
908 fuse_fillattr(inode, &outarg.attr, stat);
914 int fuse_update_attributes(struct inode *inode, struct kstat *stat,
915 struct file *file, bool *refreshed)
917 struct fuse_inode *fi = get_fuse_inode(inode);
921 if (fi->i_time < get_jiffies_64()) {
923 err = fuse_do_getattr(inode, stat, file);
928 generic_fillattr(inode, stat);
929 stat->mode = fi->orig_i_mode;
930 stat->ino = fi->orig_ino;
934 if (refreshed != NULL)
940 int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
941 u64 child_nodeid, struct qstr *name)
944 struct inode *parent;
946 struct dentry *entry;
948 parent = ilookup5(sb, parent_nodeid, fuse_inode_eq, &parent_nodeid);
952 mutex_lock(&parent->i_mutex);
953 if (!S_ISDIR(parent->i_mode))
957 dir = d_find_alias(parent);
961 entry = d_lookup(dir, name);
966 fuse_invalidate_attr(parent);
967 fuse_invalidate_entry(entry);
969 if (child_nodeid != 0 && entry->d_inode) {
970 mutex_lock(&entry->d_inode->i_mutex);
971 if (get_node_id(entry->d_inode) != child_nodeid) {
975 if (d_mountpoint(entry)) {
979 if (S_ISDIR(entry->d_inode->i_mode)) {
980 shrink_dcache_parent(entry);
981 if (!simple_empty(entry)) {
985 entry->d_inode->i_flags |= S_DEAD;
988 clear_nlink(entry->d_inode);
991 mutex_unlock(&entry->d_inode->i_mutex);
1000 mutex_unlock(&parent->i_mutex);
1006 * Calling into a user-controlled filesystem gives the filesystem
1007 * daemon ptrace-like capabilities over the current process. This
1008 * means, that the filesystem daemon is able to record the exact
1009 * filesystem operations performed, and can also control the behavior
1010 * of the requester process in otherwise impossible ways. For example
1011 * it can delay the operation for arbitrary length of time allowing
1012 * DoS against the requester.
1014 * For this reason only those processes can call into the filesystem,
1015 * for which the owner of the mount has ptrace privilege. This
1016 * excludes processes started by other users, suid or sgid processes.
1018 int fuse_allow_current_process(struct fuse_conn *fc)
1020 const struct cred *cred;
1022 if (fc->flags & FUSE_ALLOW_OTHER)
1025 cred = current_cred();
1026 if (uid_eq(cred->euid, fc->user_id) &&
1027 uid_eq(cred->suid, fc->user_id) &&
1028 uid_eq(cred->uid, fc->user_id) &&
1029 gid_eq(cred->egid, fc->group_id) &&
1030 gid_eq(cred->sgid, fc->group_id) &&
1031 gid_eq(cred->gid, fc->group_id))
1037 static int fuse_access(struct inode *inode, int mask)
1039 struct fuse_conn *fc = get_fuse_conn(inode);
1040 struct fuse_req *req;
1041 struct fuse_access_in inarg;
1044 BUG_ON(mask & MAY_NOT_BLOCK);
1049 req = fuse_get_req_nopages(fc);
1051 return PTR_ERR(req);
1053 memset(&inarg, 0, sizeof(inarg));
1054 inarg.mask = mask & (MAY_READ | MAY_WRITE | MAY_EXEC);
1055 req->in.h.opcode = FUSE_ACCESS;
1056 req->in.h.nodeid = get_node_id(inode);
1057 req->in.numargs = 1;
1058 req->in.args[0].size = sizeof(inarg);
1059 req->in.args[0].value = &inarg;
1060 fuse_request_send(fc, req);
1061 err = req->out.h.error;
1062 fuse_put_request(fc, req);
1063 if (err == -ENOSYS) {
1070 static int fuse_perm_getattr(struct inode *inode, int mask)
1072 if (mask & MAY_NOT_BLOCK)
1075 return fuse_do_getattr(inode, NULL, NULL);
1079 * Check permission. The two basic access models of FUSE are:
1081 * 1) Local access checking ('default_permissions' mount option) based
1082 * on file mode. This is the plain old disk filesystem permission
1085 * 2) "Remote" access checking, where server is responsible for
1086 * checking permission in each inode operation. An exception to this
1087 * is if ->permission() was invoked from sys_access() in which case an
1088 * access request is sent. Execute permission is still checked
1089 * locally based on file mode.
1091 static int fuse_permission(struct inode *inode, int mask)
1093 struct fuse_conn *fc = get_fuse_conn(inode);
1094 bool refreshed = false;
1097 if (!fuse_allow_current_process(fc))
1101 * If attributes are needed, refresh them before proceeding
1103 if ((fc->flags & FUSE_DEFAULT_PERMISSIONS) ||
1104 ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
1105 struct fuse_inode *fi = get_fuse_inode(inode);
1107 if (fi->i_time < get_jiffies_64()) {
1110 err = fuse_perm_getattr(inode, mask);
1116 if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
1117 err = generic_permission(inode, mask);
1119 /* If permission is denied, try to refresh file
1120 attributes. This is also needed, because the root
1121 node will at first have no permissions */
1122 if (err == -EACCES && !refreshed) {
1123 err = fuse_perm_getattr(inode, mask);
1125 err = generic_permission(inode, mask);
1128 /* Note: the opposite of the above test does not
1129 exist. So if permissions are revoked this won't be
1130 noticed immediately, only after the attribute
1131 timeout has expired */
1132 } else if (mask & (MAY_ACCESS | MAY_CHDIR)) {
1133 err = fuse_access(inode, mask);
1134 } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
1135 if (!(inode->i_mode & S_IXUGO)) {
1139 err = fuse_perm_getattr(inode, mask);
1140 if (!err && !(inode->i_mode & S_IXUGO))
1147 static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
1148 struct dir_context *ctx)
1150 while (nbytes >= FUSE_NAME_OFFSET) {
1151 struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
1152 size_t reclen = FUSE_DIRENT_SIZE(dirent);
1153 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
1155 if (reclen > nbytes)
1157 if (memchr(dirent->name, '/', dirent->namelen) != NULL)
1160 if (!dir_emit(ctx, dirent->name, dirent->namelen,
1161 dirent->ino, dirent->type))
1166 ctx->pos = dirent->off;
1172 static int fuse_direntplus_link(struct file *file,
1173 struct fuse_direntplus *direntplus,
1177 struct fuse_entry_out *o = &direntplus->entry_out;
1178 struct fuse_dirent *dirent = &direntplus->dirent;
1179 struct dentry *parent = file->f_path.dentry;
1180 struct qstr name = QSTR_INIT(dirent->name, dirent->namelen);
1181 struct dentry *dentry;
1182 struct dentry *alias;
1183 struct inode *dir = parent->d_inode;
1184 struct fuse_conn *fc;
1185 struct inode *inode;
1189 * Unlike in the case of fuse_lookup, zero nodeid does not mean
1190 * ENOENT. Instead, it only means the userspace filesystem did
1191 * not want to return attributes/handle for this entry.
1198 if (name.name[0] == '.') {
1200 * We could potentially refresh the attributes of the directory
1205 if (name.name[1] == '.' && name.len == 2)
1209 if (invalid_nodeid(o->nodeid))
1211 if (!fuse_valid_type(o->attr.mode))
1214 fc = get_fuse_conn(dir);
1216 name.hash = full_name_hash(name.name, name.len);
1217 dentry = d_lookup(parent, &name);
1219 inode = dentry->d_inode;
1222 } else if (get_node_id(inode) != o->nodeid ||
1223 ((o->attr.mode ^ inode->i_mode) & S_IFMT)) {
1224 err = d_invalidate(dentry);
1227 } else if (is_bad_inode(inode)) {
1231 struct fuse_inode *fi;
1232 fi = get_fuse_inode(inode);
1233 spin_lock(&fc->lock);
1235 spin_unlock(&fc->lock);
1237 fuse_change_attributes(inode, &o->attr,
1238 entry_attr_timeout(o),
1242 * The other branch to 'found' comes via fuse_iget()
1243 * which bumps nlookup inside
1250 dentry = d_alloc(parent, &name);
1255 inode = fuse_iget(dir->i_sb, o->nodeid, o->generation,
1256 &o->attr, entry_attr_timeout(o), attr_version);
1260 alias = d_materialise_unique(dentry, inode);
1261 err = PTR_ERR(alias);
1271 if (fc->readdirplus_auto)
1272 set_bit(FUSE_I_INIT_RDPLUS, &get_fuse_inode(inode)->state);
1273 fuse_change_entry_timeout(dentry, o);
1281 static int parse_dirplusfile(char *buf, size_t nbytes, struct file *file,
1282 struct dir_context *ctx, u64 attr_version)
1284 struct fuse_direntplus *direntplus;
1285 struct fuse_dirent *dirent;
1290 while (nbytes >= FUSE_NAME_OFFSET_DIRENTPLUS) {
1291 direntplus = (struct fuse_direntplus *) buf;
1292 dirent = &direntplus->dirent;
1293 reclen = FUSE_DIRENTPLUS_SIZE(direntplus);
1295 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
1297 if (reclen > nbytes)
1299 if (memchr(dirent->name, '/', dirent->namelen) != NULL)
1303 /* We fill entries into dstbuf only as much as
1304 it can hold. But we still continue iterating
1305 over remaining entries to link them. If not,
1306 we need to send a FORGET for each of those
1307 which we did not link.
1309 over = !dir_emit(ctx, dirent->name, dirent->namelen,
1310 dirent->ino, dirent->type);
1311 ctx->pos = dirent->off;
1317 ret = fuse_direntplus_link(file, direntplus, attr_version);
1319 fuse_force_forget(file, direntplus->entry_out.nodeid);
1325 static int fuse_readdir(struct file *file, struct dir_context *ctx)
1330 struct inode *inode = file_inode(file);
1331 struct fuse_conn *fc = get_fuse_conn(inode);
1332 struct fuse_req *req;
1333 u64 attr_version = 0;
1335 if (is_bad_inode(inode))
1338 req = fuse_get_req(fc, 1);
1340 return PTR_ERR(req);
1342 page = alloc_page(GFP_KERNEL);
1344 fuse_put_request(fc, req);
1348 plus = fuse_use_readdirplus(inode, ctx);
1349 req->out.argpages = 1;
1351 req->pages[0] = page;
1352 req->page_descs[0].length = PAGE_SIZE;
1354 attr_version = fuse_get_attr_version(fc);
1355 fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
1358 fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
1361 fuse_request_send(fc, req);
1362 nbytes = req->out.args[0].size;
1363 err = req->out.h.error;
1364 fuse_put_request(fc, req);
1367 err = parse_dirplusfile(page_address(page), nbytes,
1371 err = parse_dirfile(page_address(page), nbytes, file,
1377 fuse_invalidate_attr(inode); /* atime changed */
1381 static char *read_link(struct dentry *dentry)
1383 struct inode *inode = dentry->d_inode;
1384 struct fuse_conn *fc = get_fuse_conn(inode);
1385 struct fuse_req *req = fuse_get_req_nopages(fc);
1389 return ERR_CAST(req);
1391 link = (char *) __get_free_page(GFP_KERNEL);
1393 link = ERR_PTR(-ENOMEM);
1396 req->in.h.opcode = FUSE_READLINK;
1397 req->in.h.nodeid = get_node_id(inode);
1398 req->out.argvar = 1;
1399 req->out.numargs = 1;
1400 req->out.args[0].size = PAGE_SIZE - 1;
1401 req->out.args[0].value = link;
1402 fuse_request_send(fc, req);
1403 if (req->out.h.error) {
1404 free_page((unsigned long) link);
1405 link = ERR_PTR(req->out.h.error);
1407 link[req->out.args[0].size] = '\0';
1409 fuse_put_request(fc, req);
1410 fuse_invalidate_attr(inode); /* atime changed */
1414 static void free_link(char *link)
1417 free_page((unsigned long) link);
1420 static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd)
1422 nd_set_link(nd, read_link(dentry));
1426 static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
1428 free_link(nd_get_link(nd));
1431 static int fuse_dir_open(struct inode *inode, struct file *file)
1433 return fuse_open_common(inode, file, true);
1436 static int fuse_dir_release(struct inode *inode, struct file *file)
1438 fuse_release_common(file, FUSE_RELEASEDIR);
1443 static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
1446 return fuse_fsync_common(file, start, end, datasync, 1);
1449 static long fuse_dir_ioctl(struct file *file, unsigned int cmd,
1452 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1454 /* FUSE_IOCTL_DIR only supported for API version >= 7.18 */
1458 return fuse_ioctl_common(file, cmd, arg, FUSE_IOCTL_DIR);
1461 static long fuse_dir_compat_ioctl(struct file *file, unsigned int cmd,
1464 struct fuse_conn *fc = get_fuse_conn(file->f_mapping->host);
1469 return fuse_ioctl_common(file, cmd, arg,
1470 FUSE_IOCTL_COMPAT | FUSE_IOCTL_DIR);
1473 static bool update_mtime(unsigned ivalid)
1475 /* Always update if mtime is explicitly set */
1476 if (ivalid & ATTR_MTIME_SET)
1479 /* If it's an open(O_TRUNC) or an ftruncate(), don't update */
1480 if ((ivalid & ATTR_SIZE) && (ivalid & (ATTR_OPEN | ATTR_FILE)))
1483 /* In all other cases update */
1487 static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
1489 unsigned ivalid = iattr->ia_valid;
1491 if (ivalid & ATTR_MODE)
1492 arg->valid |= FATTR_MODE, arg->mode = iattr->ia_mode;
1493 if (ivalid & ATTR_UID)
1494 arg->valid |= FATTR_UID, arg->uid = from_kuid(&init_user_ns, iattr->ia_uid);
1495 if (ivalid & ATTR_GID)
1496 arg->valid |= FATTR_GID, arg->gid = from_kgid(&init_user_ns, iattr->ia_gid);
1497 if (ivalid & ATTR_SIZE)
1498 arg->valid |= FATTR_SIZE, arg->size = iattr->ia_size;
1499 if (ivalid & ATTR_ATIME) {
1500 arg->valid |= FATTR_ATIME;
1501 arg->atime = iattr->ia_atime.tv_sec;
1502 arg->atimensec = iattr->ia_atime.tv_nsec;
1503 if (!(ivalid & ATTR_ATIME_SET))
1504 arg->valid |= FATTR_ATIME_NOW;
1506 if ((ivalid & ATTR_MTIME) && update_mtime(ivalid)) {
1507 arg->valid |= FATTR_MTIME;
1508 arg->mtime = iattr->ia_mtime.tv_sec;
1509 arg->mtimensec = iattr->ia_mtime.tv_nsec;
1510 if (!(ivalid & ATTR_MTIME_SET))
1511 arg->valid |= FATTR_MTIME_NOW;
1516 * Prevent concurrent writepages on inode
1518 * This is done by adding a negative bias to the inode write counter
1519 * and waiting for all pending writes to finish.
1521 void fuse_set_nowrite(struct inode *inode)
1523 struct fuse_conn *fc = get_fuse_conn(inode);
1524 struct fuse_inode *fi = get_fuse_inode(inode);
1526 BUG_ON(!mutex_is_locked(&inode->i_mutex));
1528 spin_lock(&fc->lock);
1529 BUG_ON(fi->writectr < 0);
1530 fi->writectr += FUSE_NOWRITE;
1531 spin_unlock(&fc->lock);
1532 wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
1536 * Allow writepages on inode
1538 * Remove the bias from the writecounter and send any queued
1541 static void __fuse_release_nowrite(struct inode *inode)
1543 struct fuse_inode *fi = get_fuse_inode(inode);
1545 BUG_ON(fi->writectr != FUSE_NOWRITE);
1547 fuse_flush_writepages(inode);
1550 void fuse_release_nowrite(struct inode *inode)
1552 struct fuse_conn *fc = get_fuse_conn(inode);
1554 spin_lock(&fc->lock);
1555 __fuse_release_nowrite(inode);
1556 spin_unlock(&fc->lock);
1560 * Set attributes, and at the same time refresh them.
1562 * Truncation is slightly complicated, because the 'truncate' request
1563 * may fail, in which case we don't want to touch the mapping.
1564 * vmtruncate() doesn't allow for this case, so do the rlimit checking
1565 * and the actual truncation by hand.
1567 int fuse_do_setattr(struct inode *inode, struct iattr *attr,
1570 struct fuse_conn *fc = get_fuse_conn(inode);
1571 struct fuse_inode *fi = get_fuse_inode(inode);
1572 struct fuse_req *req;
1573 struct fuse_setattr_in inarg;
1574 struct fuse_attr_out outarg;
1575 bool is_truncate = false;
1579 if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
1580 attr->ia_valid |= ATTR_FORCE;
1582 err = inode_change_ok(inode, attr);
1586 if (attr->ia_valid & ATTR_OPEN) {
1587 if (fc->atomic_o_trunc)
1592 if (attr->ia_valid & ATTR_SIZE)
1595 req = fuse_get_req_nopages(fc);
1597 return PTR_ERR(req);
1600 fuse_set_nowrite(inode);
1601 set_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1604 memset(&inarg, 0, sizeof(inarg));
1605 memset(&outarg, 0, sizeof(outarg));
1606 iattr_to_fattr(attr, &inarg);
1608 struct fuse_file *ff = file->private_data;
1609 inarg.valid |= FATTR_FH;
1612 if (attr->ia_valid & ATTR_SIZE) {
1613 /* For mandatory locking in truncate */
1614 inarg.valid |= FATTR_LOCKOWNER;
1615 inarg.lock_owner = fuse_lock_owner_id(fc, current->files);
1617 req->in.h.opcode = FUSE_SETATTR;
1618 req->in.h.nodeid = get_node_id(inode);
1619 req->in.numargs = 1;
1620 req->in.args[0].size = sizeof(inarg);
1621 req->in.args[0].value = &inarg;
1622 req->out.numargs = 1;
1624 req->out.args[0].size = FUSE_COMPAT_ATTR_OUT_SIZE;
1626 req->out.args[0].size = sizeof(outarg);
1627 req->out.args[0].value = &outarg;
1628 fuse_request_send(fc, req);
1629 err = req->out.h.error;
1630 fuse_put_request(fc, req);
1633 fuse_invalidate_attr(inode);
1637 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
1638 make_bad_inode(inode);
1643 spin_lock(&fc->lock);
1644 fuse_change_attributes_common(inode, &outarg.attr,
1645 attr_timeout(&outarg));
1646 oldsize = inode->i_size;
1647 i_size_write(inode, outarg.attr.size);
1650 /* NOTE: this may release/reacquire fc->lock */
1651 __fuse_release_nowrite(inode);
1653 spin_unlock(&fc->lock);
1656 * Only call invalidate_inode_pages2() after removing
1657 * FUSE_NOWRITE, otherwise fuse_launder_page() would deadlock.
1659 if (S_ISREG(inode->i_mode) && oldsize != outarg.attr.size) {
1660 truncate_pagecache(inode, outarg.attr.size);
1661 invalidate_inode_pages2(inode->i_mapping);
1664 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1669 fuse_release_nowrite(inode);
1671 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
1675 static int fuse_setattr(struct dentry *entry, struct iattr *attr)
1677 struct inode *inode = entry->d_inode;
1679 if (!fuse_allow_current_process(get_fuse_conn(inode)))
1682 if (attr->ia_valid & ATTR_FILE)
1683 return fuse_do_setattr(inode, attr, attr->ia_file);
1685 return fuse_do_setattr(inode, attr, NULL);
1688 static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
1691 struct inode *inode = entry->d_inode;
1692 struct fuse_conn *fc = get_fuse_conn(inode);
1694 if (!fuse_allow_current_process(fc))
1697 return fuse_update_attributes(inode, stat, NULL, NULL);
1700 static int fuse_setxattr(struct dentry *entry, const char *name,
1701 const void *value, size_t size, int flags)
1703 struct inode *inode = entry->d_inode;
1704 struct fuse_conn *fc = get_fuse_conn(inode);
1705 struct fuse_req *req;
1706 struct fuse_setxattr_in inarg;
1709 if (fc->no_setxattr)
1712 req = fuse_get_req_nopages(fc);
1714 return PTR_ERR(req);
1716 memset(&inarg, 0, sizeof(inarg));
1718 inarg.flags = flags;
1719 req->in.h.opcode = FUSE_SETXATTR;
1720 req->in.h.nodeid = get_node_id(inode);
1721 req->in.numargs = 3;
1722 req->in.args[0].size = sizeof(inarg);
1723 req->in.args[0].value = &inarg;
1724 req->in.args[1].size = strlen(name) + 1;
1725 req->in.args[1].value = name;
1726 req->in.args[2].size = size;
1727 req->in.args[2].value = value;
1728 fuse_request_send(fc, req);
1729 err = req->out.h.error;
1730 fuse_put_request(fc, req);
1731 if (err == -ENOSYS) {
1732 fc->no_setxattr = 1;
1736 fuse_invalidate_attr(inode);
1740 static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
1741 void *value, size_t size)
1743 struct inode *inode = entry->d_inode;
1744 struct fuse_conn *fc = get_fuse_conn(inode);
1745 struct fuse_req *req;
1746 struct fuse_getxattr_in inarg;
1747 struct fuse_getxattr_out outarg;
1750 if (fc->no_getxattr)
1753 req = fuse_get_req_nopages(fc);
1755 return PTR_ERR(req);
1757 memset(&inarg, 0, sizeof(inarg));
1759 req->in.h.opcode = FUSE_GETXATTR;
1760 req->in.h.nodeid = get_node_id(inode);
1761 req->in.numargs = 2;
1762 req->in.args[0].size = sizeof(inarg);
1763 req->in.args[0].value = &inarg;
1764 req->in.args[1].size = strlen(name) + 1;
1765 req->in.args[1].value = name;
1766 /* This is really two different operations rolled into one */
1767 req->out.numargs = 1;
1769 req->out.argvar = 1;
1770 req->out.args[0].size = size;
1771 req->out.args[0].value = value;
1773 req->out.args[0].size = sizeof(outarg);
1774 req->out.args[0].value = &outarg;
1776 fuse_request_send(fc, req);
1777 ret = req->out.h.error;
1779 ret = size ? req->out.args[0].size : outarg.size;
1781 if (ret == -ENOSYS) {
1782 fc->no_getxattr = 1;
1786 fuse_put_request(fc, req);
1790 static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
1792 struct inode *inode = entry->d_inode;
1793 struct fuse_conn *fc = get_fuse_conn(inode);
1794 struct fuse_req *req;
1795 struct fuse_getxattr_in inarg;
1796 struct fuse_getxattr_out outarg;
1799 if (!fuse_allow_current_process(fc))
1802 if (fc->no_listxattr)
1805 req = fuse_get_req_nopages(fc);
1807 return PTR_ERR(req);
1809 memset(&inarg, 0, sizeof(inarg));
1811 req->in.h.opcode = FUSE_LISTXATTR;
1812 req->in.h.nodeid = get_node_id(inode);
1813 req->in.numargs = 1;
1814 req->in.args[0].size = sizeof(inarg);
1815 req->in.args[0].value = &inarg;
1816 /* This is really two different operations rolled into one */
1817 req->out.numargs = 1;
1819 req->out.argvar = 1;
1820 req->out.args[0].size = size;
1821 req->out.args[0].value = list;
1823 req->out.args[0].size = sizeof(outarg);
1824 req->out.args[0].value = &outarg;
1826 fuse_request_send(fc, req);
1827 ret = req->out.h.error;
1829 ret = size ? req->out.args[0].size : outarg.size;
1831 if (ret == -ENOSYS) {
1832 fc->no_listxattr = 1;
1836 fuse_put_request(fc, req);
1840 static int fuse_removexattr(struct dentry *entry, const char *name)
1842 struct inode *inode = entry->d_inode;
1843 struct fuse_conn *fc = get_fuse_conn(inode);
1844 struct fuse_req *req;
1847 if (fc->no_removexattr)
1850 req = fuse_get_req_nopages(fc);
1852 return PTR_ERR(req);
1854 req->in.h.opcode = FUSE_REMOVEXATTR;
1855 req->in.h.nodeid = get_node_id(inode);
1856 req->in.numargs = 1;
1857 req->in.args[0].size = strlen(name) + 1;
1858 req->in.args[0].value = name;
1859 fuse_request_send(fc, req);
1860 err = req->out.h.error;
1861 fuse_put_request(fc, req);
1862 if (err == -ENOSYS) {
1863 fc->no_removexattr = 1;
1867 fuse_invalidate_attr(inode);
1871 static const struct inode_operations fuse_dir_inode_operations = {
1872 .lookup = fuse_lookup,
1873 .mkdir = fuse_mkdir,
1874 .symlink = fuse_symlink,
1875 .unlink = fuse_unlink,
1876 .rmdir = fuse_rmdir,
1877 .rename = fuse_rename,
1879 .setattr = fuse_setattr,
1880 .create = fuse_create,
1881 .atomic_open = fuse_atomic_open,
1882 .mknod = fuse_mknod,
1883 .permission = fuse_permission,
1884 .getattr = fuse_getattr,
1885 .setxattr = fuse_setxattr,
1886 .getxattr = fuse_getxattr,
1887 .listxattr = fuse_listxattr,
1888 .removexattr = fuse_removexattr,
1891 static const struct file_operations fuse_dir_operations = {
1892 .llseek = generic_file_llseek,
1893 .read = generic_read_dir,
1894 .iterate = fuse_readdir,
1895 .open = fuse_dir_open,
1896 .release = fuse_dir_release,
1897 .fsync = fuse_dir_fsync,
1898 .unlocked_ioctl = fuse_dir_ioctl,
1899 .compat_ioctl = fuse_dir_compat_ioctl,
1902 static const struct inode_operations fuse_common_inode_operations = {
1903 .setattr = fuse_setattr,
1904 .permission = fuse_permission,
1905 .getattr = fuse_getattr,
1906 .setxattr = fuse_setxattr,
1907 .getxattr = fuse_getxattr,
1908 .listxattr = fuse_listxattr,
1909 .removexattr = fuse_removexattr,
1912 static const struct inode_operations fuse_symlink_inode_operations = {
1913 .setattr = fuse_setattr,
1914 .follow_link = fuse_follow_link,
1915 .put_link = fuse_put_link,
1916 .readlink = generic_readlink,
1917 .getattr = fuse_getattr,
1918 .setxattr = fuse_setxattr,
1919 .getxattr = fuse_getxattr,
1920 .listxattr = fuse_listxattr,
1921 .removexattr = fuse_removexattr,
1924 void fuse_init_common(struct inode *inode)
1926 inode->i_op = &fuse_common_inode_operations;
1929 void fuse_init_dir(struct inode *inode)
1931 inode->i_op = &fuse_dir_inode_operations;
1932 inode->i_fop = &fuse_dir_operations;
1935 void fuse_init_symlink(struct inode *inode)
1937 inode->i_op = &fuse_symlink_inode_operations;