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_WRITE) && IS_RDONLY(inode) &&
495 (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
497 if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO))
503 static int parse_dirfile(char *buf, size_t nbytes, struct file *file,
504 void *dstbuf, filldir_t filldir)
506 while (nbytes >= FUSE_NAME_OFFSET) {
507 struct fuse_dirent *dirent = (struct fuse_dirent *) buf;
508 size_t reclen = FUSE_DIRENT_SIZE(dirent);
510 if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX)
515 over = filldir(dstbuf, dirent->name, dirent->namelen,
516 file->f_pos, dirent->ino, dirent->type);
522 file->f_pos = dirent->off;
528 static inline size_t fuse_send_readdir(struct fuse_req *req, struct file *file,
529 struct inode *inode, loff_t pos,
532 return fuse_send_read_common(req, file, inode, pos, count, 1);
535 static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
540 struct inode *inode = file->f_dentry->d_inode;
541 struct fuse_conn *fc = get_fuse_conn(inode);
542 struct fuse_req *req = fuse_get_request(fc);
546 page = alloc_page(GFP_KERNEL);
548 fuse_put_request(fc, req);
552 req->pages[0] = page;
553 nbytes = fuse_send_readdir(req, file, inode, file->f_pos, PAGE_SIZE);
554 err = req->out.h.error;
555 fuse_put_request(fc, req);
557 err = parse_dirfile(page_address(page), nbytes, file, dstbuf,
561 fuse_invalidate_attr(inode); /* atime changed */
565 static char *read_link(struct dentry *dentry)
567 struct inode *inode = dentry->d_inode;
568 struct fuse_conn *fc = get_fuse_conn(inode);
569 struct fuse_req *req = fuse_get_request(fc);
573 return ERR_PTR(-EINTR);
575 link = (char *) __get_free_page(GFP_KERNEL);
577 link = ERR_PTR(-ENOMEM);
580 req->in.h.opcode = FUSE_READLINK;
581 req->in.h.nodeid = get_node_id(inode);
584 req->out.numargs = 1;
585 req->out.args[0].size = PAGE_SIZE - 1;
586 req->out.args[0].value = link;
587 request_send(fc, req);
588 if (req->out.h.error) {
589 free_page((unsigned long) link);
590 link = ERR_PTR(req->out.h.error);
592 link[req->out.args[0].size] = '\0';
594 fuse_put_request(fc, req);
595 fuse_invalidate_attr(inode); /* atime changed */
599 static void free_link(char *link)
602 free_page((unsigned long) link);
605 static void *fuse_follow_link(struct dentry *dentry, struct nameidata *nd)
607 nd_set_link(nd, read_link(dentry));
611 static void fuse_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
613 free_link(nd_get_link(nd));
616 static int fuse_dir_open(struct inode *inode, struct file *file)
618 return fuse_open_common(inode, file, 1);
621 static int fuse_dir_release(struct inode *inode, struct file *file)
623 return fuse_release_common(inode, file, 1);
626 static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync)
628 /* nfsd can call this with no file */
629 return file ? fuse_fsync_common(file, de, datasync, 1) : 0;
632 static unsigned iattr_to_fattr(struct iattr *iattr, struct fuse_attr *fattr)
634 unsigned ivalid = iattr->ia_valid;
637 memset(fattr, 0, sizeof(*fattr));
639 if (ivalid & ATTR_MODE)
640 fvalid |= FATTR_MODE, fattr->mode = iattr->ia_mode;
641 if (ivalid & ATTR_UID)
642 fvalid |= FATTR_UID, fattr->uid = iattr->ia_uid;
643 if (ivalid & ATTR_GID)
644 fvalid |= FATTR_GID, fattr->gid = iattr->ia_gid;
645 if (ivalid & ATTR_SIZE)
646 fvalid |= FATTR_SIZE, fattr->size = iattr->ia_size;
647 /* You can only _set_ these together (they may change by themselves) */
648 if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) {
649 fvalid |= FATTR_ATIME | FATTR_MTIME;
650 fattr->atime = iattr->ia_atime.tv_sec;
651 fattr->mtime = iattr->ia_mtime.tv_sec;
657 static int fuse_setattr(struct dentry *entry, struct iattr *attr)
659 struct inode *inode = entry->d_inode;
660 struct fuse_conn *fc = get_fuse_conn(inode);
661 struct fuse_inode *fi = get_fuse_inode(inode);
662 struct fuse_req *req;
663 struct fuse_setattr_in inarg;
664 struct fuse_attr_out outarg;
668 if (fc->flags & FUSE_DEFAULT_PERMISSIONS) {
669 err = inode_change_ok(inode, attr);
674 if (attr->ia_valid & ATTR_SIZE) {
677 limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
678 if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) {
679 send_sig(SIGXFSZ, current, 0);
684 req = fuse_get_request(fc);
688 memset(&inarg, 0, sizeof(inarg));
689 inarg.valid = iattr_to_fattr(attr, &inarg.attr);
690 req->in.h.opcode = FUSE_SETATTR;
691 req->in.h.nodeid = get_node_id(inode);
694 req->in.args[0].size = sizeof(inarg);
695 req->in.args[0].value = &inarg;
696 req->out.numargs = 1;
697 req->out.args[0].size = sizeof(outarg);
698 req->out.args[0].value = &outarg;
699 request_send(fc, req);
700 err = req->out.h.error;
701 fuse_put_request(fc, req);
703 if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) {
704 make_bad_inode(inode);
708 loff_t origsize = i_size_read(inode);
709 i_size_write(inode, outarg.attr.size);
710 if (origsize > outarg.attr.size)
711 vmtruncate(inode, outarg.attr.size);
713 fuse_change_attributes(inode, &outarg.attr);
714 fi->i_time = time_to_jiffies(outarg.attr_valid,
715 outarg.attr_valid_nsec);
717 } else if (err == -EINTR)
718 fuse_invalidate_attr(inode);
723 static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,
726 struct inode *inode = entry->d_inode;
727 int err = fuse_revalidate(entry);
729 generic_fillattr(inode, stat);
734 static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
735 struct nameidata *nd)
738 int err = fuse_lookup_iget(dir, entry, &inode);
741 if (inode && S_ISDIR(inode->i_mode)) {
742 /* Don't allow creating an alias to a directory */
743 struct dentry *alias = d_find_alias(inode);
744 if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) {
747 return ERR_PTR(-EIO);
750 return d_splice_alias(inode, entry);
753 static int fuse_setxattr(struct dentry *entry, const char *name,
754 const void *value, size_t size, int flags)
756 struct inode *inode = entry->d_inode;
757 struct fuse_conn *fc = get_fuse_conn(inode);
758 struct fuse_req *req;
759 struct fuse_setxattr_in inarg;
762 if (size > FUSE_XATTR_SIZE_MAX)
768 req = fuse_get_request(fc);
772 memset(&inarg, 0, sizeof(inarg));
775 req->in.h.opcode = FUSE_SETXATTR;
776 req->in.h.nodeid = get_node_id(inode);
779 req->in.args[0].size = sizeof(inarg);
780 req->in.args[0].value = &inarg;
781 req->in.args[1].size = strlen(name) + 1;
782 req->in.args[1].value = name;
783 req->in.args[2].size = size;
784 req->in.args[2].value = value;
785 request_send(fc, req);
786 err = req->out.h.error;
787 fuse_put_request(fc, req);
788 if (err == -ENOSYS) {
795 static ssize_t fuse_getxattr(struct dentry *entry, const char *name,
796 void *value, size_t size)
798 struct inode *inode = entry->d_inode;
799 struct fuse_conn *fc = get_fuse_conn(inode);
800 struct fuse_req *req;
801 struct fuse_getxattr_in inarg;
802 struct fuse_getxattr_out outarg;
808 req = fuse_get_request(fc);
812 memset(&inarg, 0, sizeof(inarg));
814 req->in.h.opcode = FUSE_GETXATTR;
815 req->in.h.nodeid = get_node_id(inode);
818 req->in.args[0].size = sizeof(inarg);
819 req->in.args[0].value = &inarg;
820 req->in.args[1].size = strlen(name) + 1;
821 req->in.args[1].value = name;
822 /* This is really two different operations rolled into one */
823 req->out.numargs = 1;
826 req->out.args[0].size = size;
827 req->out.args[0].value = value;
829 req->out.args[0].size = sizeof(outarg);
830 req->out.args[0].value = &outarg;
832 request_send(fc, req);
833 ret = req->out.h.error;
835 ret = size ? req->out.args[0].size : outarg.size;
837 if (ret == -ENOSYS) {
842 fuse_put_request(fc, req);
846 static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size)
848 struct inode *inode = entry->d_inode;
849 struct fuse_conn *fc = get_fuse_conn(inode);
850 struct fuse_req *req;
851 struct fuse_getxattr_in inarg;
852 struct fuse_getxattr_out outarg;
855 if (fc->no_listxattr)
858 req = fuse_get_request(fc);
862 memset(&inarg, 0, sizeof(inarg));
864 req->in.h.opcode = FUSE_LISTXATTR;
865 req->in.h.nodeid = get_node_id(inode);
868 req->in.args[0].size = sizeof(inarg);
869 req->in.args[0].value = &inarg;
870 /* This is really two different operations rolled into one */
871 req->out.numargs = 1;
874 req->out.args[0].size = size;
875 req->out.args[0].value = list;
877 req->out.args[0].size = sizeof(outarg);
878 req->out.args[0].value = &outarg;
880 request_send(fc, req);
881 ret = req->out.h.error;
883 ret = size ? req->out.args[0].size : outarg.size;
885 if (ret == -ENOSYS) {
886 fc->no_listxattr = 1;
890 fuse_put_request(fc, req);
894 static int fuse_removexattr(struct dentry *entry, const char *name)
896 struct inode *inode = entry->d_inode;
897 struct fuse_conn *fc = get_fuse_conn(inode);
898 struct fuse_req *req;
901 if (fc->no_removexattr)
904 req = fuse_get_request(fc);
908 req->in.h.opcode = FUSE_REMOVEXATTR;
909 req->in.h.nodeid = get_node_id(inode);
912 req->in.args[0].size = strlen(name) + 1;
913 req->in.args[0].value = name;
914 request_send(fc, req);
915 err = req->out.h.error;
916 fuse_put_request(fc, req);
917 if (err == -ENOSYS) {
918 fc->no_removexattr = 1;
924 static struct inode_operations fuse_dir_inode_operations = {
925 .lookup = fuse_lookup,
927 .symlink = fuse_symlink,
928 .unlink = fuse_unlink,
930 .rename = fuse_rename,
932 .setattr = fuse_setattr,
933 .create = fuse_create,
935 .permission = fuse_permission,
936 .getattr = fuse_getattr,
937 .setxattr = fuse_setxattr,
938 .getxattr = fuse_getxattr,
939 .listxattr = fuse_listxattr,
940 .removexattr = fuse_removexattr,
943 static struct file_operations fuse_dir_operations = {
944 .llseek = generic_file_llseek,
945 .read = generic_read_dir,
946 .readdir = fuse_readdir,
947 .open = fuse_dir_open,
948 .release = fuse_dir_release,
949 .fsync = fuse_dir_fsync,
952 static struct inode_operations fuse_common_inode_operations = {
953 .setattr = fuse_setattr,
954 .permission = fuse_permission,
955 .getattr = fuse_getattr,
956 .setxattr = fuse_setxattr,
957 .getxattr = fuse_getxattr,
958 .listxattr = fuse_listxattr,
959 .removexattr = fuse_removexattr,
962 static struct inode_operations fuse_symlink_inode_operations = {
963 .setattr = fuse_setattr,
964 .follow_link = fuse_follow_link,
965 .put_link = fuse_put_link,
966 .readlink = generic_readlink,
967 .getattr = fuse_getattr,
968 .setxattr = fuse_setxattr,
969 .getxattr = fuse_getxattr,
970 .listxattr = fuse_listxattr,
971 .removexattr = fuse_removexattr,
974 void fuse_init_common(struct inode *inode)
976 inode->i_op = &fuse_common_inode_operations;
979 void fuse_init_dir(struct inode *inode)
981 inode->i_op = &fuse_dir_inode_operations;
982 inode->i_fop = &fuse_dir_operations;
985 void fuse_init_symlink(struct inode *inode)
987 inode->i_op = &fuse_symlink_inode_operations;