Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1 | /* |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 149f607 | 2005-01-10 12:29:28 +0000 | [diff] [blame] | 3 | Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 4 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 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 | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 12 | #include <linux/file.h> |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 13 | #ifdef KERNEL_2_6 |
| 14 | #include <linux/gfp.h> |
| 15 | #else |
| 16 | #include <linux/mm.h> |
| 17 | #endif |
| 18 | #include <linux/sched.h> |
Miklos Szeredi | 7a98395 | 2005-01-28 09:58:19 +0000 | [diff] [blame] | 19 | #ifdef KERNEL_2_6_8_PLUS |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 20 | #include <linux/namei.h> |
| 21 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 22 | |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 23 | static inline unsigned long time_to_jiffies(unsigned long sec, |
| 24 | unsigned long nsec) |
| 25 | { |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 26 | struct timespec ts = {sec, nsec}; |
| 27 | return jiffies + timespec_to_jiffies(&ts); |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 30 | static void fuse_lookup_init(struct fuse_req *req, struct inode *dir, |
| 31 | struct dentry *entry, |
| 32 | struct fuse_entry_out *outarg) |
| 33 | { |
| 34 | req->in.h.opcode = FUSE_LOOKUP; |
| 35 | req->in.h.nodeid = get_node_id(dir); |
| 36 | req->inode = dir; |
| 37 | req->in.numargs = 1; |
| 38 | req->in.args[0].size = entry->d_name.len + 1; |
| 39 | req->in.args[0].value = entry->d_name.name; |
| 40 | req->out.numargs = 1; |
| 41 | req->out.args[0].size = sizeof(struct fuse_entry_out); |
| 42 | req->out.args[0].value = outarg; |
| 43 | } |
| 44 | |
| 45 | static int fuse_dentry_revalidate(struct dentry *entry, struct nameidata *nd) |
| 46 | { |
| 47 | if (!entry->d_inode || is_bad_inode(entry->d_inode)) |
| 48 | return 0; |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 49 | else if (time_after(jiffies, entry->d_time)) { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 50 | int err; |
| 51 | int version; |
| 52 | struct fuse_entry_out outarg; |
| 53 | struct inode *inode = entry->d_inode; |
| 54 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 55 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 56 | struct fuse_req *req = fuse_get_request_nonint(fc); |
| 57 | if (!req) |
| 58 | return 0; |
| 59 | |
| 60 | fuse_lookup_init(req, entry->d_parent->d_inode, entry, &outarg); |
| 61 | request_send_nonint(fc, req); |
| 62 | version = req->out.h.unique; |
| 63 | err = req->out.h.error; |
| 64 | fuse_put_request(fc, req); |
| 65 | if (err || outarg.nodeid != get_node_id(inode) || |
| 66 | (outarg.attr.mode ^ inode->i_mode) & S_IFMT) |
| 67 | return 0; |
| 68 | |
| 69 | fuse_change_attributes(inode, &outarg.attr); |
| 70 | inode->i_version = version; |
| 71 | entry->d_time = time_to_jiffies(outarg.entry_valid, |
| 72 | outarg.entry_valid_nsec); |
| 73 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 74 | outarg.attr_valid_nsec); |
| 75 | } |
| 76 | return 1; |
| 77 | } |
| 78 | #ifndef KERNEL_2_6 |
| 79 | static int fuse_dentry_revalidate_2_4(struct dentry *entry, int flags) |
| 80 | { |
| 81 | return fuse_dentry_revalidate(entry, NULL); |
| 82 | } |
| 83 | #endif |
| 84 | |
| 85 | static struct dentry_operations fuse_dentry_operations = { |
| 86 | #ifdef KERNEL_2_6 |
| 87 | .d_revalidate = fuse_dentry_revalidate, |
| 88 | #else |
| 89 | .d_revalidate = fuse_dentry_revalidate_2_4, |
| 90 | #endif |
| 91 | }; |
| 92 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 93 | static int fuse_lookup_iget(struct inode *dir, struct dentry *entry, |
| 94 | struct inode **inodep) |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 95 | { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 96 | int err; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 97 | int version; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 98 | struct fuse_entry_out outarg; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 99 | struct inode *inode = NULL; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 100 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 101 | struct fuse_req *req; |
Miklos Szeredi | 5e5d61f | 2002-10-24 11:50:33 +0000 | [diff] [blame] | 102 | |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 103 | if (entry->d_name.len > FUSE_NAME_MAX) |
| 104 | return -ENAMETOOLONG; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 105 | |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 106 | req = fuse_get_request(fc); |
| 107 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 108 | return -ERESTARTNOINTR; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 109 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 110 | fuse_lookup_init(req, dir, entry, &outarg); |
| 111 | request_send(fc, req); |
| 112 | version = req->out.h.unique; |
| 113 | err = req->out.h.error; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 114 | if (!err) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 115 | inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 116 | &outarg.attr, version); |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 117 | if (!inode) { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 118 | fuse_send_forget(fc, req, outarg.nodeid, version); |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 119 | return -ENOMEM; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 120 | } |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 121 | } |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 122 | fuse_put_request(fc, req); |
| 123 | if (err && err != -ENOENT) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 124 | return err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 125 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 126 | if (inode) { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 127 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 128 | entry->d_time = time_to_jiffies(outarg.entry_valid, |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 129 | outarg.entry_valid_nsec); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 130 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 131 | outarg.attr_valid_nsec); |
| 132 | } |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 133 | |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 134 | entry->d_op = &fuse_dentry_operations; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 135 | *inodep = inode; |
| 136 | return 0; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 139 | void fuse_invalidate_attr(struct inode *inode) |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 140 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 141 | get_fuse_inode(inode)->i_time = jiffies - 1; |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 144 | static void fuse_invalidate_entry(struct dentry *entry) |
| 145 | { |
| 146 | d_invalidate(entry); |
| 147 | entry->d_time = jiffies - 1; |
| 148 | } |
| 149 | |
| 150 | static int create_new_entry(struct fuse_conn *fc, struct fuse_req *req, |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 151 | struct inode *dir, struct dentry *entry, |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 152 | int mode) |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 153 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 154 | struct fuse_entry_out outarg; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 155 | struct inode *inode; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 156 | struct fuse_inode *fi; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 157 | int version; |
| 158 | int err; |
| 159 | |
| 160 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 161 | req->inode = dir; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 162 | req->out.numargs = 1; |
| 163 | req->out.args[0].size = sizeof(outarg); |
| 164 | req->out.args[0].value = &outarg; |
| 165 | request_send(fc, req); |
| 166 | version = req->out.h.unique; |
| 167 | err = req->out.h.error; |
| 168 | if (err) { |
| 169 | fuse_put_request(fc, req); |
| 170 | return err; |
| 171 | } |
| 172 | inode = fuse_iget(dir->i_sb, outarg.nodeid, outarg.generation, |
| 173 | &outarg.attr, version); |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 174 | if (!inode) { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 175 | fuse_send_forget(fc, req, outarg.nodeid, version); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 176 | return -ENOMEM; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 177 | } |
| 178 | fuse_put_request(fc, req); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 179 | |
| 180 | /* Don't allow userspace to do really stupid things... */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 181 | if ((inode->i_mode ^ mode) & S_IFMT) { |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 182 | iput(inode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 183 | return -EIO; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 186 | entry->d_time = time_to_jiffies(outarg.entry_valid, |
| 187 | outarg.entry_valid_nsec); |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 188 | |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 189 | fi = get_fuse_inode(inode); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 190 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 191 | outarg.attr_valid_nsec); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 192 | |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 193 | d_instantiate(entry, inode); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 194 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 198 | static int fuse_mknod(struct inode *dir, struct dentry *entry, int mode, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 199 | dev_t rdev) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 200 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 201 | struct fuse_mknod_in inarg; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 202 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 203 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 204 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 205 | return -ERESTARTNOINTR; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 206 | |
| 207 | memset(&inarg, 0, sizeof(inarg)); |
| 208 | inarg.mode = mode; |
Miklos Szeredi | 7c35cf9 | 2004-01-14 16:56:49 +0000 | [diff] [blame] | 209 | inarg.rdev = new_encode_dev(rdev); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 210 | req->in.h.opcode = FUSE_MKNOD; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 211 | req->in.numargs = 2; |
| 212 | req->in.args[0].size = sizeof(inarg); |
| 213 | req->in.args[0].value = &inarg; |
| 214 | req->in.args[1].size = entry->d_name.len + 1; |
| 215 | req->in.args[1].value = entry->d_name.name; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 216 | return create_new_entry(fc, req, dir, entry, mode); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 219 | static int fuse_create(struct inode *dir, struct dentry *entry, int mode, |
| 220 | struct nameidata *nd) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 221 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 222 | return fuse_mknod(dir, entry, mode, 0); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 225 | static int fuse_mkdir(struct inode *dir, struct dentry *entry, int mode) |
| 226 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 227 | struct fuse_mkdir_in inarg; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 228 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 229 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 230 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 231 | return -ERESTARTNOINTR; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 232 | |
| 233 | memset(&inarg, 0, sizeof(inarg)); |
| 234 | inarg.mode = mode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 235 | req->in.h.opcode = FUSE_MKDIR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 236 | req->in.numargs = 2; |
| 237 | req->in.args[0].size = sizeof(inarg); |
| 238 | req->in.args[0].value = &inarg; |
| 239 | req->in.args[1].size = entry->d_name.len + 1; |
| 240 | req->in.args[1].value = entry->d_name.name; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 241 | return create_new_entry(fc, req, dir, entry, S_IFDIR); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static int fuse_symlink(struct inode *dir, struct dentry *entry, |
| 245 | const char *link) |
| 246 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 247 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 248 | unsigned len = strlen(link) + 1; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 249 | struct fuse_req *req; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 250 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 251 | if (len > FUSE_SYMLINK_MAX) |
| 252 | return -ENAMETOOLONG; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 253 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 254 | req = fuse_get_request(fc); |
| 255 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 256 | return -ERESTARTNOINTR; |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 257 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 258 | req->in.h.opcode = FUSE_SYMLINK; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 259 | req->in.numargs = 2; |
| 260 | req->in.args[0].size = entry->d_name.len + 1; |
| 261 | req->in.args[0].value = entry->d_name.name; |
| 262 | req->in.args[1].size = len; |
| 263 | req->in.args[1].value = link; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 264 | return create_new_entry(fc, req, dir, entry, S_IFLNK); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 267 | static int fuse_unlink(struct inode *dir, struct dentry *entry) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 268 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 269 | int err; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 270 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 271 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 272 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 273 | return -ERESTARTNOINTR; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 274 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 275 | req->in.h.opcode = FUSE_UNLINK; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 276 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 277 | req->inode = dir; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 278 | req->in.numargs = 1; |
| 279 | req->in.args[0].size = entry->d_name.len + 1; |
| 280 | req->in.args[0].value = entry->d_name.name; |
| 281 | request_send(fc, req); |
| 282 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 283 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 284 | if (!err) { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 285 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 286 | |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 287 | /* Set nlink to zero so the inode can be cleared, if |
| 288 | the inode does have more links this will be |
| 289 | discovered at the next lookup/getattr */ |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 290 | inode->i_nlink = 0; |
| 291 | fuse_invalidate_attr(inode); |
| 292 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 293 | } else if (err == -EINTR) |
| 294 | fuse_invalidate_entry(entry); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 295 | return err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static int fuse_rmdir(struct inode *dir, struct dentry *entry) |
| 299 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 300 | int err; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 301 | struct fuse_conn *fc = get_fuse_conn(dir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 302 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 303 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 304 | return -ERESTARTNOINTR; |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 305 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 306 | req->in.h.opcode = FUSE_RMDIR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 307 | req->in.h.nodeid = get_node_id(dir); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 308 | req->inode = dir; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 309 | req->in.numargs = 1; |
| 310 | req->in.args[0].size = entry->d_name.len + 1; |
| 311 | req->in.args[0].value = entry->d_name.name; |
| 312 | request_send(fc, req); |
| 313 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 314 | fuse_put_request(fc, req); |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 315 | if (!err) { |
Miklos Szeredi | f4f8b89 | 2004-01-27 17:04:59 +0000 | [diff] [blame] | 316 | entry->d_inode->i_nlink = 0; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 317 | fuse_invalidate_attr(dir); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 318 | } else if (err == -EINTR) |
| 319 | fuse_invalidate_entry(entry); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 320 | return err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static int fuse_rename(struct inode *olddir, struct dentry *oldent, |
| 324 | struct inode *newdir, struct dentry *newent) |
| 325 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 326 | int err; |
| 327 | struct fuse_rename_in inarg; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 328 | struct fuse_conn *fc = get_fuse_conn(olddir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 329 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 330 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 331 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 332 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 333 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 334 | inarg.newdir = get_node_id(newdir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 335 | req->in.h.opcode = FUSE_RENAME; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 336 | req->in.h.nodeid = get_node_id(olddir); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 337 | req->inode = olddir; |
| 338 | req->inode2 = newdir; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 339 | req->in.numargs = 3; |
| 340 | req->in.args[0].size = sizeof(inarg); |
| 341 | req->in.args[0].value = &inarg; |
| 342 | req->in.args[1].size = oldent->d_name.len + 1; |
| 343 | req->in.args[1].value = oldent->d_name.name; |
| 344 | req->in.args[2].size = newent->d_name.len + 1; |
| 345 | req->in.args[2].value = newent->d_name.name; |
| 346 | request_send(fc, req); |
| 347 | err = req->out.h.error; |
| 348 | fuse_put_request(fc, req); |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 349 | if (!err) { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 350 | fuse_invalidate_attr(olddir); |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 351 | if (olddir != newdir) |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 352 | fuse_invalidate_attr(newdir); |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 353 | } else if (err == -EINTR) { |
| 354 | /* If request was interrupted, DEITY only knows if the |
| 355 | rename actually took place. If the invalidation |
| 356 | fails (e.g. some process has CWD under the renamed |
| 357 | directory), then there can be inconsistency between |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 358 | the dcache and the real filesystem. Tough luck. */ |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 359 | fuse_invalidate_entry(oldent); |
| 360 | if (newent->d_inode) |
| 361 | fuse_invalidate_entry(newent); |
Miklos Szeredi | 015fe70 | 2004-07-12 11:52:24 +0000 | [diff] [blame] | 362 | } |
Miklos Szeredi | cdae16e | 2005-01-14 11:43:22 +0000 | [diff] [blame] | 363 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 364 | return err; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | static int fuse_link(struct dentry *entry, struct inode *newdir, |
| 368 | struct dentry *newent) |
| 369 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 370 | int err; |
| 371 | struct fuse_link_in inarg; |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 372 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 373 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 374 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 375 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 376 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 377 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 378 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | ed6b5dd | 2005-01-26 17:07:59 +0000 | [diff] [blame] | 379 | inarg.oldnodeid = get_node_id(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 380 | req->in.h.opcode = FUSE_LINK; |
Miklos Szeredi | ed6b5dd | 2005-01-26 17:07:59 +0000 | [diff] [blame] | 381 | req->inode2 = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 382 | req->in.numargs = 2; |
| 383 | req->in.args[0].size = sizeof(inarg); |
| 384 | req->in.args[0].value = &inarg; |
| 385 | req->in.args[1].size = newent->d_name.len + 1; |
| 386 | req->in.args[1].value = newent->d_name.name; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 387 | err = create_new_entry(fc, req, newdir, newent, inode->i_mode); |
| 388 | /* Contrary to "normal" filesystems it can happen that link |
| 389 | makes two "logical" inodes point to the same "physical" |
| 390 | inode. We invalidate the attributes of the old one, so it |
| 391 | will reflect changes in the backing inode (link count, |
| 392 | etc.) |
| 393 | */ |
| 394 | if (!err || err == -EINTR) |
| 395 | fuse_invalidate_attr(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 396 | return err; |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 397 | } |
| 398 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 399 | int fuse_do_getattr(struct inode *inode) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 400 | { |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 401 | int err; |
| 402 | struct fuse_attr_out arg; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 403 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 404 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 405 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 406 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 407 | |
| 408 | req->in.h.opcode = FUSE_GETATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 409 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 410 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 411 | req->out.numargs = 1; |
| 412 | req->out.args[0].size = sizeof(arg); |
| 413 | req->out.args[0].value = &arg; |
| 414 | request_send(fc, req); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 415 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 416 | fuse_put_request(fc, req); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 417 | if (!err) { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 418 | if ((inode->i_mode ^ arg.attr.mode) & S_IFMT) { |
Miklos Szeredi | e22acbe | 2005-01-20 08:37:30 +0000 | [diff] [blame] | 419 | #ifndef FUSE_MAINLINE |
Miklos Szeredi | dbe0f65 | 2005-01-15 14:32:56 +0000 | [diff] [blame] | 420 | if (get_node_id(inode) != FUSE_ROOT_ID) |
| 421 | make_bad_inode(inode); |
Miklos Szeredi | e22acbe | 2005-01-20 08:37:30 +0000 | [diff] [blame] | 422 | #else |
| 423 | make_bad_inode(inode); |
| 424 | #endif |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 425 | err = -EIO; |
| 426 | } else { |
| 427 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 428 | fuse_change_attributes(inode, &arg.attr); |
| 429 | fi->i_time = time_to_jiffies(arg.attr_valid, |
| 430 | arg.attr_valid_nsec); |
| 431 | } |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 432 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 433 | return err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame^] | 436 | static int fuse_allow_task(struct fuse_conn *fc, struct task_struct *task) |
| 437 | { |
| 438 | if (fc->flags & FUSE_ALLOW_OTHER) |
| 439 | return 1; |
| 440 | |
| 441 | /* Calling into a user-controlled filesystem gives the |
| 442 | filesystem daemon ptrace-like capabilities over the |
| 443 | requester process. This means, that the filesystem daemon |
| 444 | is able to record the exact filesystem operations |
| 445 | performed, and can also control the behavior of the |
| 446 | requester process in otherwise impossible ways. For |
| 447 | example it can delay the operation for arbitrary length of |
| 448 | time allowing DoS against the requester. |
| 449 | |
| 450 | For this reason only those processes can call into the |
| 451 | filesystem, for which the owner of the mount has ptrace |
| 452 | privilege. This excludes processes started by other users, |
| 453 | suid or sgid processes. */ |
| 454 | if (task->euid == fc->user_id && |
| 455 | task->suid == fc->user_id && |
| 456 | task->uid == fc->user_id && |
| 457 | task->egid == fc->group_id && |
| 458 | task->sgid == fc->group_id && |
| 459 | task->gid == fc->group_id) |
| 460 | return 1; |
| 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 465 | static int fuse_revalidate(struct dentry *entry) |
| 466 | { |
| 467 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 468 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 469 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 470 | |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame^] | 471 | if (!fuse_allow_task(fc, current)) |
| 472 | return -EACCES; |
| 473 | if (get_node_id(inode) != FUSE_ROOT_ID && |
| 474 | time_before_eq(jiffies, fi->i_time)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 475 | return 0; |
| 476 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 477 | return fuse_do_getattr(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 480 | static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 481 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 482 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 483 | |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame^] | 484 | if (!fuse_allow_task(fc, current)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 485 | return -EACCES; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 486 | else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 487 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 488 | int err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 489 | #else |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 490 | int err = vfs_permission(inode, mask); |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 491 | #endif |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 492 | |
| 493 | /* If permission is denied, try to refresh file |
| 494 | attributes. This is also needed, because the root |
| 495 | node will at first have no permissions */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 496 | if (err == -EACCES) { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 497 | err = fuse_do_getattr(inode); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 498 | if (!err) |
| 499 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 500 | err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 501 | #else |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 502 | err = vfs_permission(inode, mask); |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 503 | #endif |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /* FIXME: Need some mechanism to revoke permissions: |
| 507 | currently if the filesystem suddenly changes the |
Miklos Szeredi | 064efb0 | 2004-11-09 17:30:29 +0000 | [diff] [blame] | 508 | file mode, we will not be informed about it, and |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 509 | continue to allow access to the file/directory. |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 510 | |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 511 | This is actually not so grave, since the user can |
| 512 | simply keep access to the file/directory anyway by |
| 513 | keeping it open... */ |
| 514 | |
| 515 | return err; |
Miklos Szeredi | 96dfad7 | 2004-11-30 00:00:02 +0000 | [diff] [blame] | 516 | } else { |
| 517 | int mode = inode->i_mode; |
| 518 | if ((mask & MAY_WRITE) && IS_RDONLY(inode) && |
| 519 | (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) |
| 520 | return -EROFS; |
| 521 | if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO)) |
| 522 | return -EACCES; |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 523 | return 0; |
Miklos Szeredi | 96dfad7 | 2004-11-30 00:00:02 +0000 | [diff] [blame] | 524 | } |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 527 | static int parse_dirfile(char *buf, size_t nbytes, struct file *file, |
| 528 | void *dstbuf, filldir_t filldir) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 529 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 530 | while (nbytes >= FUSE_NAME_OFFSET) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 531 | struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 532 | size_t reclen = FUSE_DIRENT_SIZE(dirent); |
| 533 | int over; |
Miklos Szeredi | 18fce98 | 2005-04-01 21:07:35 +0000 | [diff] [blame] | 534 | if (!dirent->namelen || dirent->namelen > FUSE_NAME_MAX) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 535 | return -EIO; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 536 | if (reclen > nbytes) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 537 | break; |
| 538 | |
| 539 | over = filldir(dstbuf, dirent->name, dirent->namelen, |
Miklos Szeredi | 18fce98 | 2005-04-01 21:07:35 +0000 | [diff] [blame] | 540 | file->f_pos, dirent->ino, dirent->type); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 541 | if (over) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 542 | break; |
| 543 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 544 | buf += reclen; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 545 | nbytes -= reclen; |
Miklos Szeredi | 18fce98 | 2005-04-01 21:07:35 +0000 | [diff] [blame] | 546 | file->f_pos = dirent->off; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 549 | return 0; |
| 550 | } |
| 551 | |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 552 | static inline size_t fuse_send_readdir(struct fuse_req *req, struct file *file, |
| 553 | struct inode *inode, loff_t pos, |
| 554 | size_t count) |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 555 | { |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 556 | return fuse_send_read_common(req, file, inode, pos, count, 1); |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 559 | static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir) |
| 560 | { |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 561 | int err; |
| 562 | size_t nbytes; |
| 563 | struct page *page; |
Miklos Szeredi | e22acbe | 2005-01-20 08:37:30 +0000 | [diff] [blame] | 564 | struct inode *inode = file->f_dentry->d_inode; |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 565 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 566 | struct fuse_req *req = fuse_get_request_nonint(fc); |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 567 | if (!req) |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 568 | return -EINTR; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 569 | |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 570 | page = alloc_page(GFP_KERNEL); |
| 571 | if (!page) { |
| 572 | fuse_put_request(fc, req); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 573 | return -ENOMEM; |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 574 | } |
| 575 | req->num_pages = 1; |
| 576 | req->pages[0] = page; |
| 577 | nbytes = fuse_send_readdir(req, file, inode, file->f_pos, PAGE_SIZE); |
| 578 | err = req->out.h.error; |
| 579 | fuse_put_request(fc, req); |
| 580 | if (!err) |
| 581 | err = parse_dirfile(page_address(page), nbytes, file, dstbuf, |
| 582 | filldir); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 583 | |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 584 | __free_page(page); |
| 585 | return err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 588 | static char *read_link(struct dentry *dentry) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 589 | { |
| 590 | struct inode *inode = dentry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 591 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 592 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 593 | char *link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 594 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 595 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 596 | return ERR_PTR(-ERESTARTNOINTR); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 597 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 598 | link = (char *) __get_free_page(GFP_KERNEL); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 599 | if (!link) { |
| 600 | link = ERR_PTR(-ENOMEM); |
| 601 | goto out; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 602 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 603 | req->in.h.opcode = FUSE_READLINK; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 604 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 605 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 606 | req->out.argvar = 1; |
| 607 | req->out.numargs = 1; |
| 608 | req->out.args[0].size = PAGE_SIZE - 1; |
| 609 | req->out.args[0].value = link; |
| 610 | request_send(fc, req); |
| 611 | if (req->out.h.error) { |
| 612 | free_page((unsigned long) link); |
| 613 | link = ERR_PTR(req->out.h.error); |
| 614 | } else |
| 615 | link[req->out.args[0].size] = '\0'; |
| 616 | out: |
| 617 | fuse_put_request(fc, req); |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 618 | return link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | static void free_link(char *link) |
| 622 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 623 | if (!IS_ERR(link)) |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 624 | free_page((unsigned long) link); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Miklos Szeredi | 7a98395 | 2005-01-28 09:58:19 +0000 | [diff] [blame] | 627 | #ifdef KERNEL_2_6_8_PLUS |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 628 | static int fuse_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 629 | { |
| 630 | nd_set_link(nd, read_link(dentry)); |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | static void fuse_put_link(struct dentry *dentry, struct nameidata *nd) |
| 635 | { |
| 636 | free_link(nd_get_link(nd)); |
| 637 | } |
| 638 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 639 | static int fuse_readlink(struct dentry *dentry, char __user *buffer, |
| 640 | int buflen) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 641 | { |
| 642 | int ret; |
| 643 | char *link; |
| 644 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 645 | link = read_link(dentry); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 646 | ret = vfs_readlink(dentry, buffer, buflen, link); |
| 647 | free_link(link); |
| 648 | return ret; |
| 649 | } |
| 650 | |
| 651 | static int fuse_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 652 | { |
| 653 | int ret; |
| 654 | char *link; |
| 655 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 656 | link = read_link(dentry); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 657 | ret = vfs_follow_link(nd, link); |
| 658 | free_link(link); |
| 659 | return ret; |
| 660 | } |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 661 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 662 | |
| 663 | static int fuse_dir_open(struct inode *inode, struct file *file) |
| 664 | { |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 665 | return fuse_open_common(inode, file, 1); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int fuse_dir_release(struct inode *inode, struct file *file) |
| 669 | { |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 670 | return fuse_release_common(inode, file, 1); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 673 | static int fuse_dir_fsync(struct file *file, struct dentry *de, int datasync) |
| 674 | { |
Miklos Szeredi | b7640d2 | 2005-04-08 15:15:28 +0000 | [diff] [blame] | 675 | /* nfsd can call this with no file */ |
| 676 | return file ? fuse_fsync_common(file, de, datasync, 1) : 0; |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 677 | } |
| 678 | |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 679 | static unsigned iattr_to_fattr(struct iattr *iattr, struct fuse_attr *fattr) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 680 | { |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 681 | unsigned ivalid = iattr->ia_valid; |
| 682 | unsigned fvalid = 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 683 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 684 | memset(fattr, 0, sizeof(*fattr)); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 685 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 686 | if (ivalid & ATTR_MODE) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 687 | fvalid |= FATTR_MODE, fattr->mode = iattr->ia_mode; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 688 | if (ivalid & ATTR_UID) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 689 | fvalid |= FATTR_UID, fattr->uid = iattr->ia_uid; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 690 | if (ivalid & ATTR_GID) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 691 | fvalid |= FATTR_GID, fattr->gid = iattr->ia_gid; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 692 | if (ivalid & ATTR_SIZE) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 693 | fvalid |= FATTR_SIZE, fattr->size = iattr->ia_size; |
| 694 | /* You can only _set_ these together (they may change by themselves) */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 695 | if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) { |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 696 | fvalid |= FATTR_ATIME | FATTR_MTIME; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 697 | #ifdef KERNEL_2_6 |
| 698 | fattr->atime = iattr->ia_atime.tv_sec; |
| 699 | fattr->mtime = iattr->ia_mtime.tv_sec; |
| 700 | #else |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 701 | fattr->atime = iattr->ia_atime; |
| 702 | fattr->mtime = iattr->ia_mtime; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 703 | #endif |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | return fvalid; |
| 707 | } |
| 708 | |
| 709 | static int fuse_setattr(struct dentry *entry, struct iattr *attr) |
| 710 | { |
| 711 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 712 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 713 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 714 | struct fuse_req *req; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 715 | struct fuse_setattr_in inarg; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 716 | struct fuse_attr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 717 | int err; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 718 | int is_truncate = 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 719 | |
Miklos Szeredi | 94ed76a | 2004-07-26 19:38:45 +0000 | [diff] [blame] | 720 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
| 721 | err = inode_change_ok(inode, attr); |
| 722 | if (err) |
| 723 | return err; |
| 724 | } |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 725 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 726 | if (attr->ia_valid & ATTR_SIZE) { |
| 727 | unsigned long limit; |
| 728 | is_truncate = 1; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 729 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 730 | limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 731 | #else |
| 732 | limit = current->rlim[RLIMIT_FSIZE].rlim_cur; |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 733 | #endif |
| 734 | if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 735 | send_sig(SIGXFSZ, current, 0); |
| 736 | return -EFBIG; |
| 737 | } |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 738 | } |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 739 | |
| 740 | req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 741 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 742 | return -ERESTARTNOINTR; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 743 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 744 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 745 | inarg.valid = iattr_to_fattr(attr, &inarg.attr); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 746 | req->in.h.opcode = FUSE_SETATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 747 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 748 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 749 | req->in.numargs = 1; |
| 750 | req->in.args[0].size = sizeof(inarg); |
| 751 | req->in.args[0].value = &inarg; |
| 752 | req->out.numargs = 1; |
| 753 | req->out.args[0].size = sizeof(outarg); |
| 754 | req->out.args[0].value = &outarg; |
| 755 | request_send(fc, req); |
| 756 | err = req->out.h.error; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 757 | fuse_put_request(fc, req); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 758 | if (!err) { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 759 | if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { |
Miklos Szeredi | e22acbe | 2005-01-20 08:37:30 +0000 | [diff] [blame] | 760 | #ifndef FUSE_MAINLINE |
Miklos Szeredi | dbe0f65 | 2005-01-15 14:32:56 +0000 | [diff] [blame] | 761 | if (get_node_id(inode) != FUSE_ROOT_ID) |
| 762 | make_bad_inode(inode); |
Miklos Szeredi | e22acbe | 2005-01-20 08:37:30 +0000 | [diff] [blame] | 763 | #else |
| 764 | make_bad_inode(inode); |
| 765 | #endif |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 766 | err = -EIO; |
| 767 | } else { |
| 768 | if (is_truncate) { |
| 769 | loff_t origsize = i_size_read(inode); |
| 770 | i_size_write(inode, outarg.attr.size); |
| 771 | if (origsize > outarg.attr.size) |
| 772 | vmtruncate(inode, outarg.attr.size); |
| 773 | } |
| 774 | fuse_change_attributes(inode, &outarg.attr); |
| 775 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 776 | outarg.attr_valid_nsec); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 777 | } |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 778 | } else if (err == -EINTR) |
| 779 | fuse_invalidate_attr(inode); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 780 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 781 | return err; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 784 | #ifdef KERNEL_2_6 |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 785 | static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry, |
| 786 | struct kstat *stat) |
| 787 | { |
| 788 | struct inode *inode = entry->d_inode; |
| 789 | int err = fuse_revalidate(entry); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 790 | if (!err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 791 | generic_fillattr(inode, stat); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 792 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 793 | return err; |
| 794 | } |
| 795 | |
| 796 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 797 | struct nameidata *nd) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 798 | { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 799 | struct inode *inode; |
| 800 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 801 | if (err) |
| 802 | return ERR_PTR(err); |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame^] | 803 | if (inode && S_ISDIR(inode->i_mode)) { |
| 804 | /* Don't allow creating an alias to a directory */ |
| 805 | struct dentry *alias = d_find_alias(inode); |
| 806 | if (alias && !(alias->d_flags & DCACHE_DISCONNECTED)) { |
| 807 | dput(alias); |
| 808 | iput(inode); |
| 809 | return ERR_PTR(-EIO); |
| 810 | } |
| 811 | } |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 812 | return d_splice_alias(inode, entry); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 813 | } |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 814 | #else /* KERNEL_2_6 */ |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 815 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry) |
| 816 | { |
| 817 | struct inode *inode; |
| 818 | struct dentry *alias; |
| 819 | |
| 820 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 821 | if (err) |
| 822 | return ERR_PTR(err); |
| 823 | |
| 824 | if (inode && S_ISDIR(inode->i_mode) && |
| 825 | (alias = d_find_alias(inode)) != NULL) { |
| 826 | dput(alias); |
| 827 | iput(inode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 828 | return ERR_PTR(-EIO); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | d_add(entry, inode); |
| 832 | return NULL; |
| 833 | } |
| 834 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 835 | static int fuse_mknod_2_4(struct inode *dir, struct dentry *entry, int mode, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 836 | int rdev) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 837 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 838 | return fuse_mknod(dir, entry, mode, rdev); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 839 | } |
| 840 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 841 | static int fuse_create_2_4(struct inode *dir, struct dentry *entry, int mode) |
| 842 | { |
| 843 | return fuse_create(dir, entry, mode, NULL); |
| 844 | } |
| 845 | |
| 846 | static int fuse_permission_2_4(struct inode *inode, int mask) |
| 847 | { |
| 848 | return fuse_permission(inode, mask, NULL); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 849 | } |
| 850 | #endif /* KERNEL_2_6 */ |
| 851 | |
| 852 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 853 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 854 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 855 | const void *value, size_t size, int flags) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 856 | #else |
| 857 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 858 | void *value, size_t size, int flags) |
| 859 | #endif |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 860 | { |
| 861 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 862 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 863 | struct fuse_req *req; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 864 | struct fuse_setxattr_in inarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 865 | int err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 866 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 867 | if (size > FUSE_XATTR_SIZE_MAX) |
| 868 | return -E2BIG; |
| 869 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 870 | if (fc->no_setxattr) |
| 871 | return -EOPNOTSUPP; |
| 872 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 873 | req = fuse_get_request(fc); |
| 874 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 875 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 876 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 877 | memset(&inarg, 0, sizeof(inarg)); |
| 878 | inarg.size = size; |
| 879 | inarg.flags = flags; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 880 | req->in.h.opcode = FUSE_SETXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 881 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 882 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 883 | req->in.numargs = 3; |
| 884 | req->in.args[0].size = sizeof(inarg); |
| 885 | req->in.args[0].value = &inarg; |
| 886 | req->in.args[1].size = strlen(name) + 1; |
| 887 | req->in.args[1].value = name; |
| 888 | req->in.args[2].size = size; |
| 889 | req->in.args[2].value = value; |
| 890 | request_send(fc, req); |
| 891 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 892 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 893 | if (err == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 894 | fc->no_setxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 895 | err = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 896 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 897 | return err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | static ssize_t fuse_getxattr(struct dentry *entry, const char *name, |
| 901 | void *value, size_t size) |
| 902 | { |
| 903 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 904 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 905 | struct fuse_req *req; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 906 | struct fuse_getxattr_in inarg; |
| 907 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 908 | ssize_t ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 909 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 910 | if (fc->no_getxattr) |
| 911 | return -EOPNOTSUPP; |
| 912 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 913 | req = fuse_get_request(fc); |
| 914 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 915 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 916 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 917 | memset(&inarg, 0, sizeof(inarg)); |
| 918 | inarg.size = size; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 919 | req->in.h.opcode = FUSE_GETXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 920 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 921 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 922 | req->in.numargs = 2; |
| 923 | req->in.args[0].size = sizeof(inarg); |
| 924 | req->in.args[0].value = &inarg; |
| 925 | req->in.args[1].size = strlen(name) + 1; |
| 926 | req->in.args[1].value = name; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 927 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 928 | req->out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 929 | if (size) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 930 | req->out.argvar = 1; |
| 931 | req->out.args[0].size = size; |
| 932 | req->out.args[0].value = value; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 933 | } else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 934 | req->out.args[0].size = sizeof(outarg); |
| 935 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 936 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 937 | request_send(fc, req); |
| 938 | ret = req->out.h.error; |
| 939 | if (!ret) |
| 940 | ret = size ? req->out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 941 | else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 942 | if (ret == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 943 | fc->no_getxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 944 | ret = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 945 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 946 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 947 | fuse_put_request(fc, req); |
| 948 | return ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) |
| 952 | { |
| 953 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 954 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 955 | struct fuse_req *req; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 956 | struct fuse_getxattr_in inarg; |
| 957 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 958 | ssize_t ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 959 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 960 | if (fc->no_listxattr) |
| 961 | return -EOPNOTSUPP; |
| 962 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 963 | req = fuse_get_request(fc); |
| 964 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 965 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 966 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 967 | memset(&inarg, 0, sizeof(inarg)); |
| 968 | inarg.size = size; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 969 | req->in.h.opcode = FUSE_LISTXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 970 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 971 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 972 | req->in.numargs = 1; |
| 973 | req->in.args[0].size = sizeof(inarg); |
| 974 | req->in.args[0].value = &inarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 975 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 976 | req->out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 977 | if (size) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 978 | req->out.argvar = 1; |
| 979 | req->out.args[0].size = size; |
| 980 | req->out.args[0].value = list; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 981 | } else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 982 | req->out.args[0].size = sizeof(outarg); |
| 983 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 984 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 985 | request_send(fc, req); |
| 986 | ret = req->out.h.error; |
| 987 | if (!ret) |
| 988 | ret = size ? req->out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 989 | else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 990 | if (ret == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 991 | fc->no_listxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 992 | ret = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 993 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 994 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 995 | fuse_put_request(fc, req); |
| 996 | return ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | static int fuse_removexattr(struct dentry *entry, const char *name) |
| 1000 | { |
| 1001 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1002 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1003 | struct fuse_req *req; |
| 1004 | int err; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 1005 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1006 | if (fc->no_removexattr) |
| 1007 | return -EOPNOTSUPP; |
| 1008 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1009 | req = fuse_get_request(fc); |
| 1010 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 1011 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1012 | |
| 1013 | req->in.h.opcode = FUSE_REMOVEXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1014 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1015 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1016 | req->in.numargs = 1; |
| 1017 | req->in.args[0].size = strlen(name) + 1; |
| 1018 | req->in.args[0].value = name; |
| 1019 | request_send(fc, req); |
| 1020 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 1021 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1022 | if (err == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1023 | fc->no_removexattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1024 | err = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1025 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1026 | return err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1027 | } |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1028 | #endif |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1029 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1030 | static struct inode_operations fuse_dir_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1031 | .lookup = fuse_lookup, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1032 | .mkdir = fuse_mkdir, |
| 1033 | .symlink = fuse_symlink, |
| 1034 | .unlink = fuse_unlink, |
| 1035 | .rmdir = fuse_rmdir, |
| 1036 | .rename = fuse_rename, |
| 1037 | .link = fuse_link, |
| 1038 | .setattr = fuse_setattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1039 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1040 | .create = fuse_create, |
| 1041 | .mknod = fuse_mknod, |
| 1042 | .permission = fuse_permission, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1043 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1044 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1045 | .create = fuse_create_2_4, |
| 1046 | .mknod = fuse_mknod_2_4, |
| 1047 | .permission = fuse_permission_2_4, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1048 | .revalidate = fuse_revalidate, |
| 1049 | #endif |
| 1050 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1051 | .setxattr = fuse_setxattr, |
| 1052 | .getxattr = fuse_getxattr, |
| 1053 | .listxattr = fuse_listxattr, |
| 1054 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1055 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1056 | }; |
| 1057 | |
| 1058 | static struct file_operations fuse_dir_operations = { |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 1059 | .llseek = generic_file_llseek, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1060 | .read = generic_read_dir, |
| 1061 | .readdir = fuse_readdir, |
| 1062 | .open = fuse_dir_open, |
| 1063 | .release = fuse_dir_release, |
Miklos Szeredi | 4283ee7 | 2005-03-21 12:09:04 +0000 | [diff] [blame] | 1064 | .fsync = fuse_dir_fsync, |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1065 | }; |
| 1066 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1067 | static struct inode_operations fuse_common_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1068 | .setattr = fuse_setattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1069 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1070 | .permission = fuse_permission, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1071 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1072 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1073 | .permission = fuse_permission_2_4, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1074 | .revalidate = fuse_revalidate, |
| 1075 | #endif |
| 1076 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1077 | .setxattr = fuse_setxattr, |
| 1078 | .getxattr = fuse_getxattr, |
| 1079 | .listxattr = fuse_listxattr, |
| 1080 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1081 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1082 | }; |
| 1083 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1084 | static struct inode_operations fuse_symlink_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1085 | .setattr = fuse_setattr, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1086 | .follow_link = fuse_follow_link, |
Miklos Szeredi | 7a98395 | 2005-01-28 09:58:19 +0000 | [diff] [blame] | 1087 | #ifdef KERNEL_2_6_8_PLUS |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 1088 | .put_link = fuse_put_link, |
| 1089 | .readlink = generic_readlink, |
| 1090 | #else |
| 1091 | .readlink = fuse_readlink, |
| 1092 | #endif |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1093 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1094 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1095 | #else |
| 1096 | .revalidate = fuse_revalidate, |
| 1097 | #endif |
| 1098 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1099 | .setxattr = fuse_setxattr, |
| 1100 | .getxattr = fuse_getxattr, |
| 1101 | .listxattr = fuse_listxattr, |
| 1102 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1103 | #endif |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1104 | }; |
| 1105 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1106 | void fuse_init_common(struct inode *inode) |
| 1107 | { |
| 1108 | inode->i_op = &fuse_common_inode_operations; |
| 1109 | } |
| 1110 | |
| 1111 | void fuse_init_dir(struct inode *inode) |
| 1112 | { |
| 1113 | inode->i_op = &fuse_dir_inode_operations; |
| 1114 | inode->i_fop = &fuse_dir_operations; |
| 1115 | } |
| 1116 | |
| 1117 | void fuse_init_symlink(struct inode *inode) |
| 1118 | { |
| 1119 | inode->i_op = &fuse_symlink_inode_operations; |
| 1120 | } |