Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
| 3 | Copyright (C) 2001 Miklos Szeredi (mszeredi@inf.bme.hu) |
| 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
| 9 | #include "fuse_i.h" |
| 10 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 11 | #include <linux/pagemap.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 12 | #include <linux/slab.h> |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 13 | #include <linux/file.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 14 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 15 | static struct inode_operations fuse_dir_inode_operations; |
| 16 | static struct inode_operations fuse_file_inode_operations; |
| 17 | static struct inode_operations fuse_symlink_inode_operations; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 18 | |
| 19 | static struct file_operations fuse_dir_operations; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 20 | |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 21 | static struct dentry_operations fuse_dentry_operations; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 22 | |
Miklos Szeredi | 7c35cf9 | 2004-01-14 16:56:49 +0000 | [diff] [blame] | 23 | #ifndef KERNEL_2_6 |
| 24 | #define new_decode_dev(x) (x) |
| 25 | #define new_encode_dev(x) (x) |
| 26 | #endif |
| 27 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 28 | static void change_attributes(struct inode *inode, struct fuse_attr *attr) |
| 29 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 30 | if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size) { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 31 | #ifdef KERNEL_2_6 |
| 32 | invalidate_inode_pages(inode->i_mapping); |
| 33 | #else |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 34 | invalidate_inode_pages(inode); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 35 | #endif |
| 36 | } |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 37 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 38 | inode->i_mode = (inode->i_mode & S_IFMT) + (attr->mode & 07777); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 39 | inode->i_nlink = attr->nlink; |
| 40 | inode->i_uid = attr->uid; |
| 41 | inode->i_gid = attr->gid; |
Miklos Szeredi | d1199f8 | 2004-02-06 15:29:22 +0000 | [diff] [blame] | 42 | i_size_write(inode, attr->size); |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 43 | inode->i_blksize = PAGE_CACHE_SIZE; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 44 | inode->i_blocks = attr->blocks; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 45 | #ifdef KERNEL_2_6 |
| 46 | inode->i_atime.tv_sec = attr->atime; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 47 | inode->i_atime.tv_nsec = attr->atimensec; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 48 | inode->i_mtime.tv_sec = attr->mtime; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 49 | inode->i_mtime.tv_nsec = attr->mtimensec; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 50 | inode->i_ctime.tv_sec = attr->ctime; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 51 | inode->i_ctime.tv_nsec = attr->ctimensec; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 52 | #else |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 53 | inode->i_atime = attr->atime; |
| 54 | inode->i_mtime = attr->mtime; |
| 55 | inode->i_ctime = attr->ctime; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 56 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 59 | static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 60 | { |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 61 | inode->i_mode = attr->mode & S_IFMT; |
Miklos Szeredi | d1199f8 | 2004-02-06 15:29:22 +0000 | [diff] [blame] | 62 | i_size_write(inode, attr->size); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 63 | if (S_ISREG(inode->i_mode)) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 64 | inode->i_op = &fuse_file_inode_operations; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 65 | fuse_init_file_inode(inode); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 66 | } |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 67 | else if (S_ISDIR(inode->i_mode)) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 68 | inode->i_op = &fuse_dir_inode_operations; |
| 69 | inode->i_fop = &fuse_dir_operations; |
| 70 | } |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 71 | else if (S_ISLNK(inode->i_mode)) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 72 | inode->i_op = &fuse_symlink_inode_operations; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 73 | } |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 74 | else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || |
| 75 | S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)){ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 76 | inode->i_op = &fuse_file_inode_operations; |
Miklos Szeredi | 7c35cf9 | 2004-01-14 16:56:49 +0000 | [diff] [blame] | 77 | init_special_inode(inode, inode->i_mode, |
| 78 | new_decode_dev(attr->rdev)); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 79 | } else |
| 80 | printk("fuse_init_inode: bad file type: %o\n", inode->i_mode); |
| 81 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 82 | inode->u.generic_ip = inode; |
| 83 | } |
| 84 | |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 85 | struct inode *fuse_iget(struct super_block *sb, ino_t ino, int generation, |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 86 | struct fuse_attr *attr, int version) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 87 | { |
| 88 | struct inode *inode; |
| 89 | |
| 90 | inode = iget(sb, ino); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 91 | if (inode) { |
| 92 | if (!inode->u.generic_ip) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 93 | inode->i_generation = generation; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 94 | fuse_init_inode(inode, attr); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 95 | } else if (inode->i_generation != generation) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 96 | printk("fuse_iget: bad generation for ino %lu\n", ino); |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 97 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 98 | change_attributes(inode, attr); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 99 | inode->i_version = version; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | return inode; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 105 | static int fuse_do_lookup(struct inode *dir, struct dentry *entry, |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 106 | struct fuse_entry_out *outarg, int *version) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 107 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 108 | struct fuse_conn *fc = INO_FC(dir); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 109 | struct fuse_in in = FUSE_IN_INIT; |
| 110 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 111 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 112 | |
| 113 | if (entry->d_name.len > FUSE_NAME_MAX) |
| 114 | return -ENAMETOOLONG; |
| 115 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 116 | in.h.opcode = FUSE_LOOKUP; |
| 117 | in.h.ino = dir->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 118 | in.numargs = 1; |
| 119 | in.args[0].size = entry->d_name.len + 1; |
| 120 | in.args[0].value = entry->d_name.name; |
| 121 | out.numargs = 1; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 122 | out.args[0].size = sizeof(struct fuse_entry_out); |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 123 | out.args[0].value = outarg; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 124 | request_send(fc, &in, &out); |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 125 | |
| 126 | *version = out.h.unique; |
| 127 | return out.h.error; |
| 128 | } |
| 129 | |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 130 | static inline unsigned long time_to_jiffies(unsigned long sec, |
| 131 | unsigned long nsec) |
| 132 | { |
| 133 | /* prevent wrapping of jiffies */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 134 | if (sec + 1 >= LONG_MAX / HZ) |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 135 | return 0; |
| 136 | |
| 137 | return jiffies + sec * HZ + nsec / (1000000000 / HZ); |
| 138 | } |
| 139 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 140 | static int fuse_lookup_iget(struct inode *dir, struct dentry *entry, |
| 141 | struct inode **inodep) |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 142 | { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 143 | int err; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 144 | struct fuse_entry_out outarg; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 145 | int version; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 146 | struct inode *inode = NULL; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 147 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 148 | err = fuse_do_lookup(dir, entry, &outarg, &version); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 149 | if (!err) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 150 | inode = fuse_iget(dir->i_sb, outarg.ino, outarg.generation, |
| 151 | &outarg.attr, version); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 152 | if (!inode) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 153 | return -ENOMEM; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 154 | } else if (err != -ENOENT) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 155 | return err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 156 | |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 157 | entry->d_time = time_to_jiffies(outarg.entry_valid, |
| 158 | outarg.entry_valid_nsec); |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 159 | entry->d_op = &fuse_dentry_operations; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 160 | *inodep = inode; |
| 161 | return 0; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 164 | static int lookup_new_entry(struct inode *dir, struct dentry *entry, |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 165 | struct fuse_entry_out *outarg, int version, |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 166 | int mode) |
| 167 | { |
| 168 | struct inode *inode; |
| 169 | inode = fuse_iget(dir->i_sb, outarg->ino, outarg->generation, |
| 170 | &outarg->attr, version); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 171 | if (!inode) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 172 | return -ENOMEM; |
| 173 | |
| 174 | /* Don't allow userspace to do really stupid things... */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 175 | if ((inode->i_mode ^ mode) & S_IFMT) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 176 | iput(inode); |
| 177 | printk("fuse_mknod: inode has wrong type\n"); |
| 178 | return -EINVAL; |
| 179 | } |
| 180 | |
| 181 | d_instantiate(entry, inode); |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 186 | static int _fuse_mknod(struct inode *dir, struct dentry *entry, int mode, |
| 187 | dev_t rdev) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 188 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 189 | struct fuse_conn *fc = INO_FC(dir); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 190 | struct fuse_in in = FUSE_IN_INIT; |
| 191 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 192 | struct fuse_mknod_in inarg; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 193 | struct fuse_entry_out outarg; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 194 | |
| 195 | memset(&inarg, 0, sizeof(inarg)); |
| 196 | inarg.mode = mode; |
Miklos Szeredi | 7c35cf9 | 2004-01-14 16:56:49 +0000 | [diff] [blame] | 197 | inarg.rdev = new_encode_dev(rdev); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 198 | |
| 199 | in.h.opcode = FUSE_MKNOD; |
| 200 | in.h.ino = dir->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 201 | in.numargs = 2; |
| 202 | in.args[0].size = sizeof(inarg); |
| 203 | in.args[0].value = &inarg; |
| 204 | in.args[1].size = entry->d_name.len + 1; |
| 205 | in.args[1].value = entry->d_name.name; |
| 206 | out.numargs = 1; |
| 207 | out.args[0].size = sizeof(outarg); |
| 208 | out.args[0].value = &outarg; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 209 | request_send(fc, &in, &out); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 210 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 211 | if (out.h.error) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 212 | return out.h.error; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 213 | |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 214 | return lookup_new_entry(dir, entry, &outarg, out.h.unique, mode); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 217 | static int _fuse_create(struct inode *dir, struct dentry *entry, int mode) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 218 | { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 219 | return _fuse_mknod(dir, entry, mode, 0); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 222 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 223 | static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode) |
| 224 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 225 | struct fuse_conn *fc = INO_FC(dir); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 226 | struct fuse_in in = FUSE_IN_INIT; |
| 227 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 228 | struct fuse_mkdir_in inarg; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 229 | struct fuse_entry_out outarg; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 230 | |
| 231 | memset(&inarg, 0, sizeof(inarg)); |
| 232 | inarg.mode = mode; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 233 | |
| 234 | in.h.opcode = FUSE_MKDIR; |
| 235 | in.h.ino = dir->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 236 | in.numargs = 2; |
| 237 | in.args[0].size = sizeof(inarg); |
| 238 | in.args[0].value = &inarg; |
| 239 | in.args[1].size = entry->d_name.len + 1; |
| 240 | in.args[1].value = entry->d_name.name; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 241 | out.numargs = 1; |
| 242 | out.args[0].size = sizeof(outarg); |
| 243 | out.args[0].value = &outarg; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 244 | request_send(fc, &in, &out); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 245 | if (out.h.error) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 246 | return out.h.error; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 247 | |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 248 | return lookup_new_entry(dir, entry, &outarg, out.h.unique, S_IFDIR); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static int fuse_symlink(struct inode *dir, struct dentry *entry, |
| 252 | const char *link) |
| 253 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 254 | struct fuse_conn *fc = INO_FC(dir); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 255 | struct fuse_in in = FUSE_IN_INIT; |
| 256 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 257 | struct fuse_entry_out outarg; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 258 | unsigned int len = strlen(link) + 1; |
| 259 | |
| 260 | if (len > FUSE_SYMLINK_MAX) |
| 261 | return -ENAMETOOLONG; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 262 | |
| 263 | in.h.opcode = FUSE_SYMLINK; |
| 264 | in.h.ino = dir->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 265 | in.numargs = 2; |
| 266 | in.args[0].size = entry->d_name.len + 1; |
| 267 | in.args[0].value = entry->d_name.name; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 268 | in.args[1].size = len; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 269 | in.args[1].value = link; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 270 | out.numargs = 1; |
| 271 | out.args[0].size = sizeof(outarg); |
| 272 | out.args[0].value = &outarg; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 273 | request_send(fc, &in, &out); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 274 | if (out.h.error) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 275 | return out.h.error; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 276 | |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 277 | return lookup_new_entry(dir, entry, &outarg, out.h.unique, S_IFLNK); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 280 | static int fuse_unlink(struct inode *dir, struct dentry *entry) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 281 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 282 | struct fuse_conn *fc = INO_FC(dir); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 283 | struct fuse_in in = FUSE_IN_INIT; |
| 284 | struct fuse_out out = FUSE_OUT_INIT; |
| 285 | |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 286 | in.h.opcode = FUSE_UNLINK; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 287 | in.h.ino = dir->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 288 | in.numargs = 1; |
| 289 | in.args[0].size = entry->d_name.len + 1; |
| 290 | in.args[0].value = entry->d_name.name; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 291 | request_send(fc, &in, &out); |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 292 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 293 | if (!out.h.error) { |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 294 | /* Set nlink to zero so the inode can be cleared, if |
| 295 | the inode does have more links this will be |
| 296 | discovered at the next lookup/getattr */ |
| 297 | /* FIXME: mark inode "not uptodate" */ |
| 298 | entry->d_inode->i_nlink = 0; |
Miklos Szeredi | f4f8b89 | 2004-01-27 17:04:59 +0000 | [diff] [blame] | 299 | } |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 300 | |
| 301 | return out.h.error; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | static int fuse_rmdir(struct inode *dir, struct dentry *entry) |
| 305 | { |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 306 | struct fuse_conn *fc = INO_FC(dir); |
| 307 | struct fuse_in in = FUSE_IN_INIT; |
| 308 | struct fuse_out out = FUSE_OUT_INIT; |
| 309 | |
| 310 | in.h.opcode = FUSE_RMDIR; |
| 311 | in.h.ino = dir->i_ino; |
| 312 | in.numargs = 1; |
| 313 | in.args[0].size = entry->d_name.len + 1; |
| 314 | in.args[0].value = entry->d_name.name; |
| 315 | request_send(fc, &in, &out); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 316 | if (!out.h.error) |
Miklos Szeredi | f4f8b89 | 2004-01-27 17:04:59 +0000 | [diff] [blame] | 317 | entry->d_inode->i_nlink = 0; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 318 | |
| 319 | return out.h.error; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | static int fuse_rename(struct inode *olddir, struct dentry *oldent, |
| 323 | struct inode *newdir, struct dentry *newent) |
| 324 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 325 | struct fuse_conn *fc = INO_FC(olddir); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 326 | struct fuse_in in = FUSE_IN_INIT; |
| 327 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 328 | struct fuse_rename_in inarg; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 329 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 330 | memset(&inarg, 0, sizeof(inarg)); |
| 331 | inarg.newdir = newdir->i_ino; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 332 | |
| 333 | in.h.opcode = FUSE_RENAME; |
| 334 | in.h.ino = olddir->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 335 | in.numargs = 3; |
| 336 | in.args[0].size = sizeof(inarg); |
| 337 | in.args[0].value = &inarg; |
| 338 | in.args[1].size = oldent->d_name.len + 1; |
| 339 | in.args[1].value = oldent->d_name.name; |
| 340 | in.args[2].size = newent->d_name.len + 1; |
| 341 | in.args[2].value = newent->d_name.name; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 342 | request_send(fc, &in, &out); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 343 | |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 344 | return out.h.error; |
| 345 | } |
| 346 | |
| 347 | static int fuse_link(struct dentry *entry, struct inode *newdir, |
| 348 | struct dentry *newent) |
| 349 | { |
| 350 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 351 | struct fuse_conn *fc = INO_FC(inode); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 352 | struct fuse_in in = FUSE_IN_INIT; |
| 353 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 354 | struct fuse_link_in inarg; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 355 | struct fuse_entry_out outarg; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 356 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 357 | memset(&inarg, 0, sizeof(inarg)); |
| 358 | inarg.newdir = newdir->i_ino; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 359 | |
| 360 | in.h.opcode = FUSE_LINK; |
| 361 | in.h.ino = inode->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 362 | in.numargs = 2; |
| 363 | in.args[0].size = sizeof(inarg); |
| 364 | in.args[0].value = &inarg; |
| 365 | in.args[1].size = newent->d_name.len + 1; |
| 366 | in.args[1].value = newent->d_name.name; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 367 | out.numargs = 1; |
| 368 | out.args[0].size = sizeof(outarg); |
| 369 | out.args[0].value = &outarg; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 370 | request_send(fc, &in, &out); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 371 | if (out.h.error) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 372 | return out.h.error; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 373 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 374 | /* Invalidate old entry, so attributes are refreshed */ |
| 375 | d_invalidate(entry); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 376 | return lookup_new_entry(newdir, newent, &outarg, out.h.unique, |
| 377 | inode->i_mode); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 380 | int fuse_do_getattr(struct inode *inode) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 381 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 382 | struct fuse_conn *fc = INO_FC(inode); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 383 | struct fuse_in in = FUSE_IN_INIT; |
| 384 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 385 | struct fuse_attr_out arg; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 386 | |
| 387 | in.h.opcode = FUSE_GETATTR; |
| 388 | in.h.ino = inode->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 389 | out.numargs = 1; |
| 390 | out.args[0].size = sizeof(arg); |
| 391 | out.args[0].value = &arg; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 392 | request_send(fc, &in, &out); |
| 393 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 394 | if (!out.h.error) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 395 | change_attributes(inode, &arg.attr); |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 396 | |
| 397 | return out.h.error; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 400 | static int fuse_revalidate(struct dentry *entry) |
| 401 | { |
| 402 | struct inode *inode = entry->d_inode; |
| 403 | struct fuse_conn *fc = INO_FC(inode); |
| 404 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 405 | if (inode->i_ino == FUSE_ROOT_INO) { |
| 406 | if (!(fc->flags & FUSE_ALLOW_OTHER) && |
| 407 | current->fsuid != fc->uid) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 408 | return -EACCES; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 409 | } else if (!entry->d_time || time_before_eq(jiffies, entry->d_time)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 410 | return 0; |
| 411 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 412 | return fuse_do_getattr(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 415 | static int _fuse_permission(struct inode *inode, int mask) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 416 | { |
| 417 | struct fuse_conn *fc = INO_FC(inode); |
| 418 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 419 | if (!(fc->flags & FUSE_ALLOW_OTHER) && current->fsuid != fc->uid) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 420 | return -EACCES; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 421 | else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 422 | int err = vfs_permission(inode, mask); |
| 423 | |
| 424 | /* If permission is denied, try to refresh file |
| 425 | attributes. This is also needed, because the root |
| 426 | node will at first have no permissions */ |
| 427 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 428 | if (err == -EACCES) { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 429 | err = fuse_do_getattr(inode); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 430 | if (!err) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 431 | err = vfs_permission(inode, mask); |
| 432 | } |
| 433 | |
| 434 | /* FIXME: Need some mechanism to revoke permissions: |
| 435 | currently if the filesystem suddenly changes the |
| 436 | file mode, we will not be informed abot that, and |
| 437 | continue to allow access to the file/directory. |
| 438 | |
| 439 | This is actually not so grave, since the user can |
| 440 | simply keep access to the file/directory anyway by |
| 441 | keeping it open... */ |
| 442 | |
| 443 | return err; |
Miklos Szeredi | 69cc79a | 2004-02-17 08:57:29 +0000 | [diff] [blame] | 444 | } else |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 445 | return 0; |
| 446 | } |
| 447 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 448 | static int parse_dirfile(char *buf, size_t nbytes, struct file *file, |
| 449 | void *dstbuf, filldir_t filldir) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 450 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 451 | while (nbytes >= FUSE_NAME_OFFSET) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 452 | struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 453 | size_t reclen = FUSE_DIRENT_SIZE(dirent); |
| 454 | int over; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 455 | if (dirent->namelen > NAME_MAX) { |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 456 | printk("fuse_readdir: name too long\n"); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 457 | return -EPROTO; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 458 | } |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 459 | if (reclen > nbytes) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 460 | break; |
| 461 | |
| 462 | over = filldir(dstbuf, dirent->name, dirent->namelen, |
| 463 | file->f_pos, dirent->ino, dirent->type); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 464 | if (over) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 465 | break; |
| 466 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 467 | buf += reclen; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 468 | file->f_pos += reclen; |
| 469 | nbytes -= reclen; |
| 470 | } |
| 471 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame^] | 475 | static int fuse_getdir(struct file *file) |
| 476 | { |
| 477 | struct inode *inode = file->f_dentry->d_inode; |
| 478 | struct fuse_conn *fc = INO_FC(inode); |
| 479 | struct fuse_in in = FUSE_IN_INIT; |
| 480 | struct fuse_out out = FUSE_OUT_INIT; |
| 481 | struct fuse_getdir_out_i outarg; |
| 482 | |
| 483 | in.h.opcode = FUSE_GETDIR; |
| 484 | in.h.ino = inode->i_ino; |
| 485 | out.numargs = 1; |
| 486 | out.args[0].size = sizeof(struct fuse_getdir_out); |
| 487 | out.args[0].value = &outarg; |
| 488 | request_send(fc, &in, &out); |
| 489 | if (!out.h.error) { |
| 490 | struct file *cfile = outarg.file; |
| 491 | struct inode *inode; |
| 492 | if (!cfile) { |
| 493 | printk("fuse_getdir: invalid file\n"); |
| 494 | return -EPROTO; |
| 495 | } |
| 496 | inode = cfile->f_dentry->d_inode; |
| 497 | if (!S_ISREG(inode->i_mode)) { |
| 498 | printk("fuse_getdir: not a regular file\n"); |
| 499 | fput(cfile); |
| 500 | return -EPROTO; |
| 501 | } |
| 502 | |
| 503 | file->private_data = cfile; |
| 504 | } |
| 505 | |
| 506 | return out.h.error; |
| 507 | } |
| 508 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 509 | #define DIR_BUFSIZE 2048 |
| 510 | static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir) |
| 511 | { |
| 512 | struct file *cfile = file->private_data; |
| 513 | char *buf; |
| 514 | int ret; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 515 | |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame^] | 516 | if (!cfile) { |
| 517 | ret = fuse_getdir(file); |
| 518 | if (ret) |
| 519 | return ret; |
| 520 | |
| 521 | cfile = file->private_data; |
| 522 | } |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 523 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 524 | buf = kmalloc(DIR_BUFSIZE, GFP_KERNEL); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 525 | if (!buf) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 526 | return -ENOMEM; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 527 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 528 | ret = kernel_read(cfile, file->f_pos, buf, DIR_BUFSIZE); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 529 | if (ret < 0) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 530 | printk("fuse_readdir: failed to read container file\n"); |
| 531 | else |
| 532 | ret = parse_dirfile(buf, ret, file, dstbuf, filldir); |
| 533 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 534 | kfree(buf); |
| 535 | return ret; |
| 536 | } |
| 537 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 538 | static char *read_link(struct dentry *dentry) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 539 | { |
| 540 | struct inode *inode = dentry->d_inode; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 541 | struct fuse_conn *fc = INO_FC(inode); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 542 | struct fuse_in in = FUSE_IN_INIT; |
| 543 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 544 | char *link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 545 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 546 | link = (char *) __get_free_page(GFP_KERNEL); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 547 | if (!link) |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 548 | return ERR_PTR(-ENOMEM); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 549 | |
| 550 | in.h.opcode = FUSE_READLINK; |
| 551 | in.h.ino = inode->i_ino; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 552 | out.argvar = 1; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 553 | out.numargs = 1; |
| 554 | out.args[0].size = PAGE_SIZE - 1; |
| 555 | out.args[0].value = link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 556 | request_send(fc, &in, &out); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 557 | if (out.h.error) { |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 558 | free_page((unsigned long) link); |
| 559 | return ERR_PTR(out.h.error); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 562 | link[out.args[0].size] = '\0'; |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 563 | return link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | static void free_link(char *link) |
| 567 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 568 | if (!IS_ERR(link)) |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 569 | free_page((unsigned long) link); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static int fuse_readlink(struct dentry *dentry, char *buffer, int buflen) |
| 573 | { |
| 574 | int ret; |
| 575 | char *link; |
| 576 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 577 | link = read_link(dentry); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 578 | ret = vfs_readlink(dentry, buffer, buflen, link); |
| 579 | free_link(link); |
| 580 | return ret; |
| 581 | } |
| 582 | |
| 583 | static int fuse_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 584 | { |
| 585 | int ret; |
| 586 | char *link; |
| 587 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 588 | link = read_link(dentry); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 589 | ret = vfs_follow_link(nd, link); |
| 590 | free_link(link); |
| 591 | return ret; |
| 592 | } |
| 593 | |
| 594 | static int fuse_dir_open(struct inode *inode, struct file *file) |
| 595 | { |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame^] | 596 | file->private_data = NULL; |
| 597 | return 0; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static int fuse_dir_release(struct inode *inode, struct file *file) |
| 601 | { |
| 602 | struct file *cfile = file->private_data; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 603 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 604 | if (cfile) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 605 | fput(cfile); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 606 | |
| 607 | return 0; |
| 608 | } |
| 609 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 610 | static unsigned int iattr_to_fattr(struct iattr *iattr, |
| 611 | struct fuse_attr *fattr) |
| 612 | { |
| 613 | unsigned int ivalid = iattr->ia_valid; |
| 614 | unsigned int fvalid = 0; |
| 615 | |
| 616 | memset(fattr, 0, sizeof(*fattr)); |
| 617 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 618 | if (ivalid & ATTR_MODE) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 619 | fvalid |= FATTR_MODE, fattr->mode = iattr->ia_mode; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 620 | if (ivalid & ATTR_UID) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 621 | fvalid |= FATTR_UID, fattr->uid = iattr->ia_uid; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 622 | if (ivalid & ATTR_GID) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 623 | fvalid |= FATTR_GID, fattr->gid = iattr->ia_gid; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 624 | if (ivalid & ATTR_SIZE) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 625 | fvalid |= FATTR_SIZE, fattr->size = iattr->ia_size; |
| 626 | /* You can only _set_ these together (they may change by themselves) */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 627 | if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) { |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 628 | fvalid |= FATTR_ATIME | FATTR_MTIME; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 629 | #ifdef KERNEL_2_6 |
| 630 | fattr->atime = iattr->ia_atime.tv_sec; |
| 631 | fattr->mtime = iattr->ia_mtime.tv_sec; |
| 632 | #else |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 633 | fattr->atime = iattr->ia_atime; |
| 634 | fattr->mtime = iattr->ia_mtime; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 635 | #endif |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | return fvalid; |
| 639 | } |
| 640 | |
| 641 | static int fuse_setattr(struct dentry *entry, struct iattr *attr) |
| 642 | { |
| 643 | struct inode *inode = entry->d_inode; |
| 644 | struct fuse_conn *fc = INO_FC(inode); |
| 645 | struct fuse_in in = FUSE_IN_INIT; |
| 646 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 647 | struct fuse_setattr_in inarg; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 648 | struct fuse_attr_out outarg; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 649 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 650 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 651 | inarg.valid = iattr_to_fattr(attr, &inarg.attr); |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 652 | |
| 653 | in.h.opcode = FUSE_SETATTR; |
| 654 | in.h.ino = inode->i_ino; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 655 | in.numargs = 1; |
| 656 | in.args[0].size = sizeof(inarg); |
| 657 | in.args[0].value = &inarg; |
| 658 | out.numargs = 1; |
| 659 | out.args[0].size = sizeof(outarg); |
| 660 | out.args[0].value = &outarg; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 661 | request_send(fc, &in, &out); |
| 662 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 663 | if (!out.h.error) { |
| 664 | if (attr->ia_valid & ATTR_SIZE && |
| 665 | outarg.attr.size < i_size_read(inode)) |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 666 | vmtruncate(inode, outarg.attr.size); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 667 | |
Miklos Szeredi | f3ea83b | 2001-11-07 14:55:16 +0000 | [diff] [blame] | 668 | change_attributes(inode, &outarg.attr); |
| 669 | } |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 670 | return out.h.error; |
| 671 | } |
| 672 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 673 | static int _fuse_dentry_revalidate(struct dentry *entry) |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 674 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 675 | if (!entry->d_inode) |
Miklos Szeredi | 97c61e9 | 2001-11-07 12:09:43 +0000 | [diff] [blame] | 676 | return 0; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 677 | else if (entry->d_time && time_after(jiffies, entry->d_time)) { |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 678 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 679 | struct fuse_entry_out outarg; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 680 | int version; |
| 681 | int ret; |
| 682 | |
| 683 | ret = fuse_do_lookup(entry->d_parent->d_inode, entry, &outarg, |
| 684 | &version); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 685 | if (ret) |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 686 | return 0; |
| 687 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 688 | if (outarg.ino != inode->i_ino) |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 689 | return 0; |
| 690 | |
| 691 | change_attributes(inode, &outarg.attr); |
| 692 | inode->i_version = version; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 693 | entry->d_time = time_to_jiffies(outarg.entry_valid, |
| 694 | outarg.entry_valid_nsec); |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 695 | } |
| 696 | return 1; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 699 | #ifdef KERNEL_2_6 |
| 700 | |
| 701 | #define fuse_mknod _fuse_mknod |
| 702 | |
| 703 | static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry, |
| 704 | struct kstat *stat) |
| 705 | { |
| 706 | struct inode *inode = entry->d_inode; |
| 707 | int err = fuse_revalidate(entry); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 708 | if (!err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 709 | generic_fillattr(inode, stat); |
| 710 | |
| 711 | return err; |
| 712 | } |
| 713 | |
| 714 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, |
| 715 | struct nameidata *nd) |
| 716 | { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 717 | struct inode *inode; |
| 718 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 719 | if (err) |
| 720 | return ERR_PTR(err); |
| 721 | return d_splice_alias(inode, entry); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static int fuse_create(struct inode *dir, struct dentry *entry, int mode, |
| 725 | struct nameidata *nd) |
| 726 | { |
| 727 | return _fuse_create(dir, entry, mode); |
| 728 | } |
| 729 | |
| 730 | static int fuse_permission(struct inode *inode, int mask, |
| 731 | struct nameidata *nd) |
| 732 | { |
| 733 | return _fuse_permission(inode, mask); |
| 734 | } |
| 735 | |
| 736 | static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd) |
| 737 | { |
| 738 | return _fuse_dentry_revalidate(entry); |
| 739 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 740 | |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 741 | #else /* KERNEL_2_6 */ |
| 742 | |
| 743 | #define fuse_create _fuse_create |
| 744 | #define fuse_permission _fuse_permission |
| 745 | |
| 746 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry) |
| 747 | { |
| 748 | struct inode *inode; |
| 749 | struct dentry *alias; |
| 750 | |
| 751 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 752 | if (err) |
| 753 | return ERR_PTR(err); |
| 754 | |
| 755 | if (inode && S_ISDIR(inode->i_mode) && |
| 756 | (alias = d_find_alias(inode)) != NULL) { |
| 757 | dput(alias); |
| 758 | iput(inode); |
| 759 | printk("fuse: cannot assign an existing directory\n"); |
| 760 | return ERR_PTR(-EPROTO); |
| 761 | } |
| 762 | |
| 763 | d_add(entry, inode); |
| 764 | return NULL; |
| 765 | } |
| 766 | |
| 767 | static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode, |
| 768 | int rdev) |
| 769 | { |
| 770 | return fuse_mknod(dir, entry, mode, rdev); |
| 771 | } |
| 772 | |
| 773 | static int fuse_dentry_revalidate(struct dentry *entry, int flags) |
| 774 | { |
| 775 | return _fuse_dentry_revalidate(entry); |
| 776 | } |
| 777 | #endif /* KERNEL_2_6 */ |
| 778 | |
| 779 | #ifdef HAVE_KERNEL_XATTR |
| 780 | |
| 781 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 782 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 783 | const void *value, size_t size, int flags) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 784 | #else |
| 785 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 786 | void *value, size_t size, int flags) |
| 787 | #endif |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 788 | { |
| 789 | struct inode *inode = entry->d_inode; |
| 790 | struct fuse_conn *fc = INO_FC(inode); |
| 791 | struct fuse_in in = FUSE_IN_INIT; |
| 792 | struct fuse_out out = FUSE_OUT_INIT; |
| 793 | struct fuse_setxattr_in inarg; |
| 794 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 795 | if (size > FUSE_XATTR_SIZE_MAX) |
| 796 | return -E2BIG; |
| 797 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 798 | if (fc->no_setxattr) |
| 799 | return -EOPNOTSUPP; |
| 800 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 801 | memset(&inarg, 0, sizeof(inarg)); |
| 802 | inarg.size = size; |
| 803 | inarg.flags = flags; |
| 804 | |
| 805 | in.h.opcode = FUSE_SETXATTR; |
| 806 | in.h.ino = inode->i_ino; |
| 807 | in.numargs = 3; |
| 808 | in.args[0].size = sizeof(inarg); |
| 809 | in.args[0].value = &inarg; |
| 810 | in.args[1].size = strlen(name) + 1; |
| 811 | in.args[1].value = name; |
| 812 | in.args[2].size = size; |
| 813 | in.args[2].value = value; |
| 814 | request_send(fc, &in, &out); |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 815 | if (out.h.error == -ENOSYS) { |
| 816 | fc->no_setxattr = 1; |
| 817 | return -EOPNOTSUPP; |
| 818 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 819 | return out.h.error; |
| 820 | } |
| 821 | |
| 822 | static ssize_t fuse_getxattr(struct dentry *entry, const char *name, |
| 823 | void *value, size_t size) |
| 824 | { |
| 825 | struct inode *inode = entry->d_inode; |
| 826 | struct fuse_conn *fc = INO_FC(inode); |
| 827 | struct fuse_in in = FUSE_IN_INIT; |
| 828 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 829 | struct fuse_getxattr_in inarg; |
| 830 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 831 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 832 | if (fc->no_getxattr) |
| 833 | return -EOPNOTSUPP; |
| 834 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 835 | memset(&inarg, 0, sizeof(inarg)); |
| 836 | inarg.size = size; |
| 837 | |
| 838 | in.h.opcode = FUSE_GETXATTR; |
| 839 | in.h.ino = inode->i_ino; |
| 840 | in.numargs = 2; |
| 841 | in.args[0].size = sizeof(inarg); |
| 842 | in.args[0].value = &inarg; |
| 843 | in.args[1].size = strlen(name) + 1; |
| 844 | in.args[1].value = name; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 845 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 846 | out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 847 | if (size) { |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 848 | out.argvar = 1; |
| 849 | out.args[0].size = size; |
| 850 | out.args[0].value = value; |
| 851 | } else { |
| 852 | out.args[0].size = sizeof(outarg); |
| 853 | out.args[0].value = &outarg; |
| 854 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 855 | request_send(fc, &in, &out); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 856 | if (!out.h.error) |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 857 | return size ? out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 858 | else { |
| 859 | if (out.h.error == -ENOSYS) { |
| 860 | fc->no_getxattr = 1; |
| 861 | return -EOPNOTSUPP; |
| 862 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 863 | return out.h.error; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 864 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) |
| 868 | { |
| 869 | struct inode *inode = entry->d_inode; |
| 870 | struct fuse_conn *fc = INO_FC(inode); |
| 871 | struct fuse_in in = FUSE_IN_INIT; |
| 872 | struct fuse_out out = FUSE_OUT_INIT; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 873 | struct fuse_getxattr_in inarg; |
| 874 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 875 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 876 | if (fc->no_listxattr) |
| 877 | return -EOPNOTSUPP; |
| 878 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 879 | memset(&inarg, 0, sizeof(inarg)); |
| 880 | inarg.size = size; |
| 881 | |
| 882 | in.h.opcode = FUSE_LISTXATTR; |
| 883 | in.h.ino = inode->i_ino; |
| 884 | in.numargs = 1; |
| 885 | in.args[0].size = sizeof(inarg); |
| 886 | in.args[0].value = &inarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 887 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 888 | out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 889 | if (size) { |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 890 | out.argvar = 1; |
| 891 | out.args[0].size = size; |
| 892 | out.args[0].value = list; |
| 893 | } else { |
| 894 | out.args[0].size = sizeof(outarg); |
| 895 | out.args[0].value = &outarg; |
| 896 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 897 | request_send(fc, &in, &out); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 898 | if (!out.h.error) |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 899 | return size ? out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 900 | else { |
| 901 | if (out.h.error == -ENOSYS) { |
| 902 | fc->no_listxattr = 1; |
| 903 | return -EOPNOTSUPP; |
| 904 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 905 | return out.h.error; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 906 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | static int fuse_removexattr(struct dentry *entry, const char *name) |
| 910 | { |
| 911 | struct inode *inode = entry->d_inode; |
| 912 | struct fuse_conn *fc = INO_FC(inode); |
| 913 | struct fuse_in in = FUSE_IN_INIT; |
| 914 | struct fuse_out out = FUSE_OUT_INIT; |
| 915 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 916 | if (fc->no_removexattr) |
| 917 | return -EOPNOTSUPP; |
| 918 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 919 | in.h.opcode = FUSE_REMOVEXATTR; |
| 920 | in.h.ino = inode->i_ino; |
| 921 | in.numargs = 1; |
| 922 | in.args[0].size = strlen(name) + 1; |
| 923 | in.args[0].value = name; |
| 924 | request_send(fc, &in, &out); |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 925 | if (out.h.error == -ENOSYS) { |
| 926 | fc->no_removexattr = 1; |
| 927 | return -EOPNOTSUPP; |
| 928 | } |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 929 | return out.h.error; |
| 930 | |
| 931 | } |
| 932 | |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 933 | #endif |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 934 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 935 | static struct inode_operations fuse_dir_inode_operations = |
| 936 | { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 937 | .lookup = fuse_lookup, |
| 938 | .create = fuse_create, |
| 939 | .mknod = fuse_mknod, |
| 940 | .mkdir = fuse_mkdir, |
| 941 | .symlink = fuse_symlink, |
| 942 | .unlink = fuse_unlink, |
| 943 | .rmdir = fuse_rmdir, |
| 944 | .rename = fuse_rename, |
| 945 | .link = fuse_link, |
| 946 | .setattr = fuse_setattr, |
| 947 | .permission = fuse_permission, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 948 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 949 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 950 | #else |
| 951 | .revalidate = fuse_revalidate, |
| 952 | #endif |
| 953 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 954 | .setxattr = fuse_setxattr, |
| 955 | .getxattr = fuse_getxattr, |
| 956 | .listxattr = fuse_listxattr, |
| 957 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 958 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 959 | }; |
| 960 | |
| 961 | static struct file_operations fuse_dir_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 962 | .read = generic_read_dir, |
| 963 | .readdir = fuse_readdir, |
| 964 | .open = fuse_dir_open, |
| 965 | .release = fuse_dir_release, |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 966 | }; |
| 967 | |
| 968 | static struct inode_operations fuse_file_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 969 | .setattr = fuse_setattr, |
| 970 | .permission = fuse_permission, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 971 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 972 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 973 | #else |
| 974 | .revalidate = fuse_revalidate, |
| 975 | #endif |
| 976 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 977 | .setxattr = fuse_setxattr, |
| 978 | .getxattr = fuse_getxattr, |
| 979 | .listxattr = fuse_listxattr, |
| 980 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 981 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 982 | }; |
| 983 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 984 | static struct inode_operations fuse_symlink_inode_operations = |
| 985 | { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 986 | .setattr = fuse_setattr, |
| 987 | .readlink = fuse_readlink, |
| 988 | .follow_link = fuse_follow_link, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 989 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 990 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 991 | #else |
| 992 | .revalidate = fuse_revalidate, |
| 993 | #endif |
| 994 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 995 | .setxattr = fuse_setxattr, |
| 996 | .getxattr = fuse_getxattr, |
| 997 | .listxattr = fuse_listxattr, |
| 998 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 999 | #endif |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1000 | }; |
| 1001 | |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 1002 | static struct dentry_operations fuse_dentry_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1003 | .d_revalidate = fuse_dentry_revalidate, |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1004 | }; |
| 1005 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1006 | /* |
| 1007 | * Local Variables: |
| 1008 | * indent-tabs-mode: t |
| 1009 | * c-basic-offset: 8 |
| 1010 | * End: |
| 1011 | */ |