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