2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 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/gfp.h>
14 #include <linux/sched.h>
15 #include <linux/namei.h>
17 static inline unsigned long time_to_jiffies(unsigned long sec,
20 struct timespec ts = {sec, nsec};
21 return jiffies + timespec_to_jiffies(&ts);
24 static void fuse_lookup_init(struct fuse_req *req, struct inode *dir,
26 struct fuse_entry_out *outarg)
28 req->in.h.opcode = FUSE_LOOKUP;
29 req->in.h.nodeid = get_node_id(dir);
32 req->in.args[0].size = entry->d_name.len + 1;
33 req->in.args[0].value = entry->d_name.name;
35 req->out.args[0].size = sizeof(struct fuse_entry_out);
36 req->out.args[0].value = outarg;
39 static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd)
41 if (!entry->d_inode || is_bad_inode(entry->d_inode))
43 else if (time_after(jiffies, entry->d_time)) {
45 struct fuse_entry_out outarg;
46 struct inode *inode = entry->d_inode;
47 struct fuse_inode *fi = get_fuse_inode(inode);
48 struct fuse_conn *fc = get_fuse_conn(inode);
49 struct fuse_req *req = fuse_get_request(fc);
53 fuse_lookup_init(req, entry->d_parent->d_inode, entry, &outarg);
54 request_send(fc, req);
55 err = req->out.h.error;
57 if (outarg.nodeid != get_node_id(inode)) {
58 fuse_send_forget(fc, req, outarg.nodeid, 1);
63 fuse_put_request(fc, req);
64 if (err || (outarg.attr.mode ^ inode->i_mode) & S_IFMT)
67 fuse_change_attributes(inode, &outarg.attr);
68 entry->d_time = time_to_jiffies(outarg.entry_valid,
69 outarg.entry_valid_nsec);
70 fi->i_time = time_to_jiffies(outarg.attr_valid,
71 outarg.attr_valid_nsec);
76 static struct dentry_operations fuse_dentry_operations = {
77 .d_revalidate = fuse_dentry_revalidate,
80 static int fuse_lookup_iget(struct inode *dir, struct dentry *entry,
81 struct inode **inodep)
84 struct fuse_entry_out outarg;
85 struct inode *inode = NULL;
86 struct fuse_conn *fc = get_fuse_conn(dir);
89 if (entry->d_name.len > FUSE_NAME_MAX)
92 req = fuse_get_request(fc);
96 fuse_lookup_init(req, dir, entry, &outarg);
97 request_send(fc, req);
98 err = req->out.h.error;
99 if (!err && (!outarg.nodeid || outarg.nodeid == FUSE_ROOT_ID))
102 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
105 fuse_send_forget(fc, req, outarg.nodeid, 1);
109 fuse_put_request(fc, req);
110 if (err && err != -ENOENT)
114 struct fuse_inode *fi = get_fuse_inode(inode);
115 entry->d_time = time_to_jiffies(outarg.entry_valid,
116 outarg.entry_valid_nsec);
117 fi->i_time = time_to_jiffies(outarg.attr_valid,
118 outarg.attr_valid_nsec);
121 entry->d_op = &fuse_dentry_operations;
126 void fuse_invalidate_attr(struct inode *inode)
128 get_fuse_inode(inode)->i_time = jiffies - 1;
131 static void fuse_invalidate_entry(struct dentry *entry)
134 entry->d_time = jiffies - 1;
137 static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req,
138 struct inode *dir, struct dentry *entry,
141 struct fuse_entry_out outarg;
143 struct fuse_inode *fi;
146 req->in.h.nodeid = get_node_id(dir);
148 req->out.numargs = 1;
149 req->out.args[0].size = sizeof(outarg);
150 req->out.args[0].value = &outarg;
151 request_send(fc, req);
152 err = req->out.h.error;
154 fuse_put_request(fc, req);
157 if (!outarg.nodeid || outarg.nodeid == FUSE_ROOT_ID) {
158 fuse_put_request(fc, req);
161 inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation,
164 fuse_send_forget(fc, req, outarg.nodeid, 1);
167 fuse_put_request(fc, req);
169 /* Don't allow userspace to do really stupid things... */
170 if ((inode->i_mode ^ mode) & S_IFMT) {
175 entry->d_time = time_to_jiffies(outarg.entry_valid,
176 outarg.entry_valid_nsec);
178 fi = get_fuse_inode(inode);
179 fi->i_time = time_to_jiffies(outarg.attr_valid,
180 outarg.attr_valid_nsec);
182 d_instantiate(entry, inode);
183 fuse_invalidate_attr(dir);
187 static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode,
190 struct fuse_mknod_in inarg;
191 struct fuse_conn *fc = get_fuse_conn(dir);
192 struct fuse_req *req = fuse_get_request(fc);
196 memset(&inarg, 0, sizeof(inarg));
198 inarg.rdev = new_encode_dev(rdev);
199 req->in.h.opcode = FUSE_MKNOD;
201 req->in.args[0].size = sizeof(inarg);
202 req->in.args[0].value = &inarg;
203 req->in.args[1].size = entry->d_name.len + 1;
204 req->in.args[1].value = entry->d_name.name;
205 return create_new_entry(fc, req, dir, entry, mode);
208 static int fuse_create(struct inode *dir, struct dentry *entry, int mode,
209 struct nameidata *nd)
211 return fuse_mknod(dir, entry, mode, 0);
214 static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode)
216 struct fuse_mkdir_in inarg;
217 struct fuse_conn *fc = get_fuse_conn(dir);
218 struct fuse_req *req = fuse_get_request(fc);
222 memset(&inarg, 0, sizeof(inarg));
224 req->in.h.opcode = FUSE_MKDIR;
226 req->in.args[0].size = sizeof(inarg);
227 req->in.args[0].value = &inarg;
228 req->in.args[1].size = entry->d_name.len + 1;
229 req->in.args[1].value = entry->d_name.name;
230 return create_new_entry(fc, req, dir, entry, S_IFDIR);
233 static int fuse_symlink(struct inode *dir, struct dentry *entry,
236 struct fuse_conn *fc = get_fuse_conn(dir);
237 unsigned len = strlen(link) + 1;
238 struct fuse_req *req;
240 if (len > FUSE_SYMLINK_MAX)
241 return -ENAMETOOLONG;
243 req = fuse_get_request(fc);
247 req->in.h.opcode = FUSE_SYMLINK;
249 req->in.args[0].size = entry->d_name.len + 1;
250 req->in.args[0].value = entry->d_name.name;
251 req->in.args[1].size = len;
252 req->in.args[1].value = link;
253 return create_new_entry(fc, req, dir, entry, S_IFLNK);
256 static int fuse_unlink(struct inode *dir, struct dentry *entry)
259 struct fuse_conn *fc = get_fuse_conn(dir);
260 struct fuse_req *req = fuse_get_request(fc);
264 req->in.h.opcode = FUSE_UNLINK;
265 req->in.h.nodeid = get_node_id(dir);
268 req->in.args[0].size = entry->d_name.len + 1;
269 req->in.args[0].value = entry->d_name.name;
270 request_send(fc, req);
271 err = req->out.h.error;
272 fuse_put_request(fc, req);
274 struct inode *inode = entry->d_inode;
276 /* Set nlink to zero so the inode can be cleared, if
277 the inode does have more links this will be
278 discovered at the next lookup/getattr */
280 fuse_invalidate_attr(inode);
281 fuse_invalidate_attr(dir);
282 } else if (err == -EINTR)
283 fuse_invalidate_entry(entry);
287 static int fuse_rmdir(struct inode *dir, struct dentry *entry)
290 struct fuse_conn *fc = get_fuse_conn(dir);
291 struct fuse_req *req = fuse_get_request(fc);
295 req->in.h.opcode = FUSE_RMDIR;
296 req->in.h.nodeid = get_node_id(dir);
299 req->in.args[0].size = entry->d_name.len + 1;
300 req->in.args[0].value = entry->d_name.name;
301 request_send(fc, req);
302 err = req->out.h.error;
303 fuse_put_request(fc, req);
305 entry->d_inode->i_nlink = 0;
306 fuse_invalidate_attr(dir);
307 } else if (err == -EINTR)
308 fuse_invalidate_entry(entry);
312 static int fuse_rename(struct inode *olddir, struct dentry *oldent,
313 struct inode *newdir, struct dentry *newent)
316 struct fuse_rename_in inarg;
317 struct fuse_conn *fc = get_fuse_conn(olddir);
318 struct fuse_req *req = fuse_get_request(fc);
322 memset(&inarg, 0, sizeof(inarg));
323 inarg.newdir = get_node_id(newdir);
324 req->in.h.opcode = FUSE_RENAME;
325 req->in.h.nodeid = get_node_id(olddir);
327 req->inode2 = newdir;
329 req->in.args[0].size = sizeof(inarg);
330 req->in.args[0].value = &inarg;
331 req->in.args[1].size = oldent->d_name.len + 1;
332 req->in.args[1].value = oldent->d_name.name;
333 req->in.args[2].size = newent->d_name.len + 1;
334 req->in.args[2].value = newent->d_name.name;
335 request_send(fc, req);
336 err = req->out.h.error;
337 fuse_put_request(fc, req);
339 fuse_invalidate_attr(olddir);
340 if (olddir != newdir)
341 fuse_invalidate_attr(newdir);
342 } else if (err == -EINTR) {
343 /* If request was interrupted, DEITY only knows if the
344 rename actually took place. If the invalidation
345 fails (e.g. some process has CWD under the renamed
346 directory), then there can be inconsistency between
347 the dcache and the real filesystem. Tough luck. */
348 fuse_invalidate_entry(oldent);
350 fuse_invalidate_entry(newent);
356 static int fuse_link(struct dentry *entry, struct inode *newdir,
357 struct dentry *newent)
360 struct fuse_link_in inarg;
361 struct inode *inode = entry->d_inode;
362 struct fuse_conn *fc = get_fuse_conn(inode);
363 struct fuse_req *req = fuse_get_request(fc);
367 memset(&inarg, 0, sizeof(inarg));
368 inarg.oldnodeid = get_node_id(inode);
369 req->in.h.opcode = FUSE_LINK;
372 req->in.args[0].size = sizeof(inarg);
373 req->in.args[0].value = &inarg;
374 req->in.args[1].size = newent->d_name.len + 1;
375 req->in.args[1].value = newent->d_name.name;
376 err = create_new_entry(fc, req, newdir, newent, inode->i_mode);
377 /* Contrary to "normal" filesystems it can happen that link
378 makes two "logical" inodes point to the same "physical"
379 inode. We invalidate the attributes of the old one, so it
380 will reflect changes in the backing inode (link count,
383 if (!err || err == -EINTR)
384 fuse_invalidate_attr(inode);
388 int fuse_do_getattr(struct inode *inode)
391 struct fuse_attr_out arg;
392 struct fuse_conn *fc = get_fuse_conn(inode);
393 struct fuse_req *req = fuse_get_request(fc);
397 req->in.h.opcode = FUSE_GETATTR;
398 req->in.h.nodeid = get_node_id(inode);
400 req->out.numargs = 1;
401 req->out.args[0].size = sizeof(arg);
402 req->out.args[0].value = &arg;
403 request_send(fc, req);
404 err = req->out.h.error;
405 fuse_put_request(fc, req);
407 if ((inode->i_mode ^ arg.attr.mode) & S_IFMT) {
408 make_bad_inode(inode);
411 struct fuse_inode *fi = get_fuse_inode(inode);
412 fuse_change_attributes(inode, &arg.attr);
413 fi->i_time = time_to_jiffies(arg.attr_valid,
414 arg.attr_valid_nsec);
421 * Calling into a user-controlled filesystem gives the filesystem
422 * daemon ptrace-like capabilities over the requester process. This
423 * means, that the filesystem daemon is able to record the exact
424 * filesystem operations performed, and can also control the behavior
425 * of the requester process in otherwise impossible ways. For example
426 * it can delay the operation for arbitrary length of time allowing
427 * DoS against the requester.
429 * For this reason only those processes can call into the filesystem,
430 * for which the owner of the mount has ptrace privilege. This
431 * excludes processes started by other users, suid or sgid processes.
433 static int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task)
435 if (fc->flags & FUSE_ALLOW_OTHER)
438 if (task->euid == fc->user_id &&
439 task->suid == fc->user_id &&
440 task->uid == fc->user_id &&
441 task->egid == fc->group_id &&
442 task->sgid == fc->group_id &&
443 task->gid == fc->group_id)
449 static int fuse_revalidate(struct dentry *entry)
451 struct inode *inode = entry->d_inode;
452 struct fuse_inode *fi = get_fuse_inode(inode);
453 struct fuse_conn *fc = get_fuse_conn(inode);
455 if (!fuse_allow_task(fc, current))
457 if (get_node_id(inode) != FUSE_ROOT_ID &&
458 time_before_eq(jiffies, fi->i_time))
461 return fuse_do_getattr(inode);
464 static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd)
466 struct fuse_conn *fc = get_fuse_conn(inode);
468 if (!fuse_allow_task(fc, current))
470 else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
471 int err = generic_permission(inode, mask, NULL);
473 /* If permission is denied, try to refresh file
474 attributes. This is also needed, because the root
475 node will at first have no permissions */
476 if (err == -EACCES) {
477 err = fuse_do_getattr(inode);
479 err = generic_permission(inode, mask, NULL);
482 /* FIXME: Need some mechanism to revoke permissions:
483 currently if the filesystem suddenly changes the
484 file mode, we will not be informed about it, and
485 continue to allow access to the file/directory.
487 This is actually not so grave, since the user can
488 simply keep access to the file/directory anyway by
489 keeping it open... */
493 int mode = inode->i_mode;
494 if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO))
500 static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
501 void *dstbuf, filldir_t filldir)
503 while (nbytes >= FUSE_NAME_OFFSET) {
504 struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
505 size_t reclen = FUSE_DIRENT_SIZE(dirent);
507 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
512 over = filldir(dstbuf, dirent->name, dirent->namelen,
513 file->f_pos, dirent->ino, dirent->type);
519 file->f_pos = dirent->off;
525 static inline size_t fuse_send_readdir(struct fuse_req *req, struct file *file,
526 struct inode *inode, loff_t pos,
529 return fuse_send_read_common(req, file, inode, pos, count, 1);
532 static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
537 struct inode *inode = file->f_dentry->d_inode;
538 struct fuse_conn *fc = get_fuse_conn(inode);
539 struct fuse_req *req = fuse_get_request(fc);
543 page = alloc_page(GFP_KERNEL);
545 fuse_put_request(fc, req);
549 req->pages[0] = page;
550 nbytes = fuse_send_readdir(req, file, inode, file->f_pos, PAGE_SIZE);
551 err = req->out.h.error;
552 fuse_put_request(fc, req);
554 err = parse_dirfile(page_address(page), nbytes, file, dstbuf,
558 fuse_invalidate_attr(inode); /* atime changed */
562 static char *read_link(struct dentry *dentry)
564 struct inode *inode = dentry->d_inode;
565 struct fuse_conn *fc = get_fuse_conn(inode);
566 struct fuse_req *req = fuse_get_request(fc);
570 return ERR_PTR(-EINTR);
572 link = (char *) __get_free_page(GFP_KERNEL);
574 link = ERR_PTR(-ENOMEM);
577 req->in.h.opcode = FUSE_READLINK;
578 req->in.h.nodeid = get_node_id(inode);
581 req->out.numargs = 1;
582 req->out.args[0].size = PAGE_SIZE - 1;
583 req->out.args[0].value = link;
584 request_send(fc, req);
585 if (req->out.h.error) {
586 free_page((unsigned long) link);
587 link = ERR_PTR(req->out.h.error);
589 link[req->out.args[0].size] = '\0';
591 fuse_put_request(fc, req);
592 fuse_invalidate_attr(inode); /* atime changed */
596 static void free_link(char *link)
599 free_page((unsigned long) link);
602 static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd)
604 nd_set_link(nd, read_link(dentry));
608 static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
610 free_link(nd_get_link(nd));
613 static int fuse_dir_open(struct inode *inode, struct file *file)
615 return fuse_open_common(inode, file, 1);
618 static int fuse_dir_release(struct inode *inode, struct file *file)
620 return fuse_release_common(inode, file, 1);
623 static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync)
625 /* nfsd can call this with no file */
626 return file ? fuse_fsync_common(file, de, datasync, 1) : 0;
629 static unsigned iattr_to_fattr(struct iattr *iattr, struct fuse_attr *fattr)
631 unsigned ivalid = iattr->ia_valid;
634 memset(fattr, 0, sizeof(*fattr));
636 if (ivalid & ATTR_MODE)
637 fvalid |= FATTR_MODE, fattr->mode = iattr->ia_mode;
638 if (ivalid & ATTR_UID)
639 fvalid |= FATTR_UID, fattr->uid = iattr->ia_uid;
640 if (ivalid & ATTR_GID)
641 fvalid |= FATTR_GID, fattr->gid = iattr->ia_gid;
642 if (ivalid & ATTR_SIZE)
643 fvalid |= FATTR_SIZE, fattr->size = iattr->ia_size;
644 /* You can only _set_ these together (they may change by themselves) */
645 if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) {
646 fvalid |= FATTR_ATIME | FATTR_MTIME;
647 fattr->atime = iattr->ia_atime.tv_sec;
648 fattr->mtime = iattr->ia_mtime.tv_sec;
654 static int fuse_setattr(struct dentry *entry, struct iattr *attr)
656 struct inode *inode = entry->d_inode;
657 struct fuse_conn *fc = get_fuse_conn(inode);
658 struct fuse_inode *fi = get_fuse_inode(inode);
659 struct fuse_req *req;
660 struct fuse_setattr_in inarg;
661 struct fuse_attr_out outarg;
665 if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
666 err = inode_change_ok(inode, attr);
671 if (attr->ia_valid & ATTR_SIZE) {
674 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
675 if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) {
676 send_sig(SIGXFSZ, current, 0);
681 req = fuse_get_request(fc);
685 memset(&inarg, 0, sizeof(inarg));
686 inarg.valid = iattr_to_fattr(attr, &inarg.attr);
687 req->in.h.opcode = FUSE_SETATTR;
688 req->in.h.nodeid = get_node_id(inode);
691 req->in.args[0].size = sizeof(inarg);
692 req->in.args[0].value = &inarg;
693 req->out.numargs = 1;
694 req->out.args[0].size = sizeof(outarg);
695 req->out.args[0].value = &outarg;
696 request_send(fc, req);
697 err = req->out.h.error;
698 fuse_put_request(fc, req);
700 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
701 make_bad_inode(inode);
705 loff_t origsize = i_size_read(inode);
706 i_size_write(inode, outarg.attr.size);
707 if (origsize > outarg.attr.size)
708 vmtruncate(inode, outarg.attr.size);
710 fuse_change_attributes(inode, &outarg.attr);
711 fi->i_time = time_to_jiffies(outarg.attr_valid,
712 outarg.attr_valid_nsec);
714 } else if (err == -EINTR)
715 fuse_invalidate_attr(inode);
720 static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
723 struct inode *inode = entry->d_inode;
724 int err = fuse_revalidate(entry);
726 generic_fillattr(inode, stat);
731 static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
732 struct nameidata *nd)
735 int err = fuse_lookup_iget(dir, entry, &inode);
738 if (inode && S_ISDIR(inode->i_mode)) {
739 /* Don't allow creating an alias to a directory */
740 struct dentry *alias = d_find_alias(inode);
744 return ERR_PTR(-EIO);
751 static int fuse_setxattr(struct dentry *entry, const char *name,
752 const void *value, size_t size, int flags)
754 struct inode *inode = entry->d_inode;
755 struct fuse_conn *fc = get_fuse_conn(inode);
756 struct fuse_req *req;
757 struct fuse_setxattr_in inarg;
760 if (size > FUSE_XATTR_SIZE_MAX)
766 req = fuse_get_request(fc);
770 memset(&inarg, 0, sizeof(inarg));
773 req->in.h.opcode = FUSE_SETXATTR;
774 req->in.h.nodeid = get_node_id(inode);
777 req->in.args[0].size = sizeof(inarg);
778 req->in.args[0].value = &inarg;
779 req->in.args[1].size = strlen(name) + 1;
780 req->in.args[1].value = name;
781 req->in.args[2].size = size;
782 req->in.args[2].value = value;
783 request_send(fc, req);
784 err = req->out.h.error;
785 fuse_put_request(fc, req);
786 if (err == -ENOSYS) {
793 static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
794 void *value, size_t size)
796 struct inode *inode = entry->d_inode;
797 struct fuse_conn *fc = get_fuse_conn(inode);
798 struct fuse_req *req;
799 struct fuse_getxattr_in inarg;
800 struct fuse_getxattr_out outarg;
806 req = fuse_get_request(fc);
810 memset(&inarg, 0, sizeof(inarg));
812 req->in.h.opcode = FUSE_GETXATTR;
813 req->in.h.nodeid = get_node_id(inode);
816 req->in.args[0].size = sizeof(inarg);
817 req->in.args[0].value = &inarg;
818 req->in.args[1].size = strlen(name) + 1;
819 req->in.args[1].value = name;
820 /* This is really two different operations rolled into one */
821 req->out.numargs = 1;
824 req->out.args[0].size = size;
825 req->out.args[0].value = value;
827 req->out.args[0].size = sizeof(outarg);
828 req->out.args[0].value = &outarg;
830 request_send(fc, req);
831 ret = req->out.h.error;
833 ret = size ? req->out.args[0].size : outarg.size;
835 if (ret == -ENOSYS) {
840 fuse_put_request(fc, req);
844 static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
846 struct inode *inode = entry->d_inode;
847 struct fuse_conn *fc = get_fuse_conn(inode);
848 struct fuse_req *req;
849 struct fuse_getxattr_in inarg;
850 struct fuse_getxattr_out outarg;
853 if (fc->no_listxattr)
856 req = fuse_get_request(fc);
860 memset(&inarg, 0, sizeof(inarg));
862 req->in.h.opcode = FUSE_LISTXATTR;
863 req->in.h.nodeid = get_node_id(inode);
866 req->in.args[0].size = sizeof(inarg);
867 req->in.args[0].value = &inarg;
868 /* This is really two different operations rolled into one */
869 req->out.numargs = 1;
872 req->out.args[0].size = size;
873 req->out.args[0].value = list;
875 req->out.args[0].size = sizeof(outarg);
876 req->out.args[0].value = &outarg;
878 request_send(fc, req);
879 ret = req->out.h.error;
881 ret = size ? req->out.args[0].size : outarg.size;
883 if (ret == -ENOSYS) {
884 fc->no_listxattr = 1;
888 fuse_put_request(fc, req);
892 static int fuse_removexattr(struct dentry *entry, const char *name)
894 struct inode *inode = entry->d_inode;
895 struct fuse_conn *fc = get_fuse_conn(inode);
896 struct fuse_req *req;
899 if (fc->no_removexattr)
902 req = fuse_get_request(fc);
906 req->in.h.opcode = FUSE_REMOVEXATTR;
907 req->in.h.nodeid = get_node_id(inode);
910 req->in.args[0].size = strlen(name) + 1;
911 req->in.args[0].value = name;
912 request_send(fc, req);
913 err = req->out.h.error;
914 fuse_put_request(fc, req);
915 if (err == -ENOSYS) {
916 fc->no_removexattr = 1;
922 static struct inode_operations fuse_dir_inode_operations = {
923 .lookup = fuse_lookup,
925 .symlink = fuse_symlink,
926 .unlink = fuse_unlink,
928 .rename = fuse_rename,
930 .setattr = fuse_setattr,
931 .create = fuse_create,
933 .permission = fuse_permission,
934 .getattr = fuse_getattr,
935 .setxattr = fuse_setxattr,
936 .getxattr = fuse_getxattr,
937 .listxattr = fuse_listxattr,
938 .removexattr = fuse_removexattr,
941 static struct file_operations fuse_dir_operations = {
942 .llseek = generic_file_llseek,
943 .read = generic_read_dir,
944 .readdir = fuse_readdir,
945 .open = fuse_dir_open,
946 .release = fuse_dir_release,
947 .fsync = fuse_dir_fsync,
950 static struct inode_operations fuse_common_inode_operations = {
951 .setattr = fuse_setattr,
952 .permission = fuse_permission,
953 .getattr = fuse_getattr,
954 .setxattr = fuse_setxattr,
955 .getxattr = fuse_getxattr,
956 .listxattr = fuse_listxattr,
957 .removexattr = fuse_removexattr,
960 static struct inode_operations fuse_symlink_inode_operations = {
961 .setattr = fuse_setattr,
962 .follow_link = fuse_follow_link,
963 .put_link = fuse_put_link,
964 .readlink = generic_readlink,
965 .getattr = fuse_getattr,
966 .setxattr = fuse_setxattr,
967 .getxattr = fuse_getxattr,
968 .listxattr = fuse_listxattr,
969 .removexattr = fuse_removexattr,
972 void fuse_init_common(struct inode *inode)
974 inode->i_op = &fuse_common_inode_operations;
977 void fuse_init_dir(struct inode *inode)
979 inode->i_op = &fuse_dir_inode_operations;
980 inode->i_fop = &fuse_dir_operations;
983 void fuse_init_symlink(struct inode *inode)
985 inode->i_op = &fuse_symlink_inode_operations;