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 | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame^] | 19 | #ifdef KERNEL_2_6_7_PLUS |
| 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 | 0fcfa03 | 2004-12-13 15:22:28 +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 | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 379 | inarg.newdir = get_node_id(newdir); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 380 | req->in.h.opcode = FUSE_LINK; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 381 | req->inode2 = newdir; |
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) { |
| 419 | make_bad_inode(inode); |
| 420 | err = -EIO; |
| 421 | } else { |
| 422 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 423 | fuse_change_attributes(inode, &arg.attr); |
| 424 | fi->i_time = time_to_jiffies(arg.attr_valid, |
| 425 | arg.attr_valid_nsec); |
| 426 | } |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 427 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 428 | return err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 431 | static int fuse_revalidate(struct dentry *entry) |
| 432 | { |
| 433 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 434 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 435 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 436 | |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 437 | if (get_node_id(inode) == FUSE_ROOT_ID) { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 438 | if (!(fc->flags & FUSE_ALLOW_OTHER) && |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 439 | current->fsuid != fc->user_id && |
Miklos Szeredi | 180ff69 | 2004-11-01 16:01:05 +0000 | [diff] [blame] | 440 | (!(fc->flags & FUSE_ALLOW_ROOT) || |
| 441 | current->fsuid != 0)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 442 | return -EACCES; |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame^] | 443 | } else if (time_before_eq(jiffies, fi->i_time)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 444 | return 0; |
| 445 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 446 | return fuse_do_getattr(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 449 | static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 450 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 451 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 452 | |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 453 | if (!(fc->flags & FUSE_ALLOW_OTHER) && current->fsuid != fc->user_id && |
Miklos Szeredi | 180ff69 | 2004-11-01 16:01:05 +0000 | [diff] [blame] | 454 | (!(fc->flags & FUSE_ALLOW_ROOT) || current->fsuid != 0)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 455 | return -EACCES; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 456 | else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 457 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 458 | int err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 459 | #else |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 460 | int err = vfs_permission(inode, mask); |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 461 | #endif |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 462 | |
| 463 | /* If permission is denied, try to refresh file |
| 464 | attributes. This is also needed, because the root |
| 465 | node will at first have no permissions */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 466 | if (err == -EACCES) { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 467 | err = fuse_do_getattr(inode); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 468 | if (!err) |
| 469 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 470 | err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 471 | #else |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 472 | err = vfs_permission(inode, mask); |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 473 | #endif |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /* FIXME: Need some mechanism to revoke permissions: |
| 477 | currently if the filesystem suddenly changes the |
Miklos Szeredi | 064efb0 | 2004-11-09 17:30:29 +0000 | [diff] [blame] | 478 | file mode, we will not be informed about it, and |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 479 | continue to allow access to the file/directory. |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 480 | |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 481 | This is actually not so grave, since the user can |
| 482 | simply keep access to the file/directory anyway by |
| 483 | keeping it open... */ |
| 484 | |
| 485 | return err; |
Miklos Szeredi | 96dfad7 | 2004-11-30 00:00:02 +0000 | [diff] [blame] | 486 | } else { |
| 487 | int mode = inode->i_mode; |
| 488 | if ((mask & MAY_WRITE) && IS_RDONLY(inode) && |
| 489 | (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) |
| 490 | return -EROFS; |
| 491 | if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO)) |
| 492 | return -EACCES; |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 493 | return 0; |
Miklos Szeredi | 96dfad7 | 2004-11-30 00:00:02 +0000 | [diff] [blame] | 494 | } |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 497 | static int parse_dirfile(char *buf, size_t nbytes, struct file *file, |
| 498 | void *dstbuf, filldir_t filldir) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 499 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 500 | while (nbytes >= FUSE_NAME_OFFSET) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 501 | struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 502 | size_t reclen = FUSE_DIRENT_SIZE(dirent); |
| 503 | int over; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 504 | if (dirent->namelen > FUSE_NAME_MAX) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 505 | return -EIO; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 506 | if (reclen > nbytes) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 507 | break; |
| 508 | |
| 509 | over = filldir(dstbuf, dirent->name, dirent->namelen, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 510 | file->f_pos, dirent->ino, dirent->type); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 511 | if (over) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 512 | break; |
| 513 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 514 | buf += reclen; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 515 | file->f_pos += reclen; |
| 516 | nbytes -= reclen; |
| 517 | } |
| 518 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 519 | return 0; |
| 520 | } |
| 521 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 522 | static int fuse_checkdir(struct file *cfile, struct file *file) |
| 523 | { |
| 524 | struct inode *inode; |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 525 | if (!cfile) |
| 526 | return -EIO; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 527 | inode = cfile->f_dentry->d_inode; |
| 528 | if (!S_ISREG(inode->i_mode)) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 529 | fput(cfile); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 530 | return -EIO; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 531 | } |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 532 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 533 | file->private_data = cfile; |
| 534 | return 0; |
| 535 | } |
| 536 | |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 537 | static int fuse_getdir(struct file *file) |
| 538 | { |
| 539 | struct inode *inode = file->f_dentry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 540 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 541 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 542 | struct fuse_getdir_out_i outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 543 | int err; |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 544 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 545 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 546 | return -ERESTARTNOINTR; |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 547 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 548 | req->in.h.opcode = FUSE_GETDIR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 549 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 550 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 551 | req->out.numargs = 1; |
| 552 | req->out.args[0].size = sizeof(struct fuse_getdir_out); |
| 553 | req->out.args[0].value = &outarg; |
| 554 | request_send(fc, req); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 555 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 556 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 557 | if (!err) |
| 558 | err = fuse_checkdir(outarg.file, file); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 559 | return err; |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 562 | static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir) |
| 563 | { |
| 564 | struct file *cfile = file->private_data; |
| 565 | char *buf; |
| 566 | int ret; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 567 | |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 568 | if (!cfile) { |
| 569 | ret = fuse_getdir(file); |
| 570 | if (ret) |
| 571 | return ret; |
| 572 | |
| 573 | cfile = file->private_data; |
| 574 | } |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 575 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 576 | buf = (char *) __get_free_page(GFP_KERNEL); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 577 | if (!buf) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 578 | return -ENOMEM; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 579 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 580 | ret = kernel_read(cfile, file->f_pos, buf, PAGE_SIZE); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 581 | if (ret > 0) |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 582 | ret = parse_dirfile(buf, ret, file, dstbuf, filldir); |
| 583 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 584 | free_page((unsigned long) buf); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 585 | return ret; |
| 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 | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame^] | 627 | #ifdef KERNEL_2_6_7_PLUS |
| 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 | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 665 | file->private_data = NULL; |
| 666 | return 0; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static int fuse_dir_release(struct inode *inode, struct file *file) |
| 670 | { |
| 671 | struct file *cfile = file->private_data; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 672 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 673 | if (cfile) |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 674 | fput(cfile); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 675 | |
| 676 | return 0; |
| 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) { |
| 760 | make_bad_inode(inode); |
| 761 | err = -EIO; |
| 762 | } else { |
| 763 | if (is_truncate) { |
| 764 | loff_t origsize = i_size_read(inode); |
| 765 | i_size_write(inode, outarg.attr.size); |
| 766 | if (origsize > outarg.attr.size) |
| 767 | vmtruncate(inode, outarg.attr.size); |
| 768 | } |
| 769 | fuse_change_attributes(inode, &outarg.attr); |
| 770 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 771 | outarg.attr_valid_nsec); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 772 | } |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 773 | } else if (err == -EINTR) |
| 774 | fuse_invalidate_attr(inode); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 775 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 776 | return err; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 777 | } |
| 778 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 779 | #ifdef KERNEL_2_6 |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 780 | static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry, |
| 781 | struct kstat *stat) |
| 782 | { |
| 783 | struct inode *inode = entry->d_inode; |
| 784 | int err = fuse_revalidate(entry); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 785 | if (!err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 786 | generic_fillattr(inode, stat); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 787 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 788 | return err; |
| 789 | } |
| 790 | |
| 791 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 792 | struct nameidata *nd) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 793 | { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 794 | struct inode *inode; |
| 795 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 796 | if (err) |
| 797 | return ERR_PTR(err); |
| 798 | return d_splice_alias(inode, entry); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 799 | } |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 800 | #else /* KERNEL_2_6 */ |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 801 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry) |
| 802 | { |
| 803 | struct inode *inode; |
| 804 | struct dentry *alias; |
| 805 | |
| 806 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 807 | if (err) |
| 808 | return ERR_PTR(err); |
| 809 | |
| 810 | if (inode && S_ISDIR(inode->i_mode) && |
| 811 | (alias = d_find_alias(inode)) != NULL) { |
| 812 | dput(alias); |
| 813 | iput(inode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 814 | return ERR_PTR(-EIO); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | d_add(entry, inode); |
| 818 | return NULL; |
| 819 | } |
| 820 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 821 | 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] | 822 | int rdev) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 823 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 824 | return fuse_mknod(dir, entry, mode, rdev); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 827 | static int fuse_create_2_4(struct inode *dir, struct dentry *entry, int mode) |
| 828 | { |
| 829 | return fuse_create(dir, entry, mode, NULL); |
| 830 | } |
| 831 | |
| 832 | static int fuse_permission_2_4(struct inode *inode, int mask) |
| 833 | { |
| 834 | return fuse_permission(inode, mask, NULL); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 835 | } |
| 836 | #endif /* KERNEL_2_6 */ |
| 837 | |
| 838 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 839 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 840 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 841 | const void *value, size_t size, int flags) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 842 | #else |
| 843 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 844 | void *value, size_t size, int flags) |
| 845 | #endif |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 846 | { |
| 847 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 848 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 849 | struct fuse_req *req; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 850 | struct fuse_setxattr_in inarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 851 | int err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 852 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 853 | if (size > FUSE_XATTR_SIZE_MAX) |
| 854 | return -E2BIG; |
| 855 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 856 | if (fc->no_setxattr) |
| 857 | return -EOPNOTSUPP; |
| 858 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 859 | req = fuse_get_request(fc); |
| 860 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 861 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 862 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 863 | memset(&inarg, 0, sizeof(inarg)); |
| 864 | inarg.size = size; |
| 865 | inarg.flags = flags; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 866 | req->in.h.opcode = FUSE_SETXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 867 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 868 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 869 | req->in.numargs = 3; |
| 870 | req->in.args[0].size = sizeof(inarg); |
| 871 | req->in.args[0].value = &inarg; |
| 872 | req->in.args[1].size = strlen(name) + 1; |
| 873 | req->in.args[1].value = name; |
| 874 | req->in.args[2].size = size; |
| 875 | req->in.args[2].value = value; |
| 876 | request_send(fc, req); |
| 877 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 878 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 879 | if (err == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 880 | fc->no_setxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 881 | err = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 882 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 883 | return err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static ssize_t fuse_getxattr(struct dentry *entry, const char *name, |
| 887 | void *value, size_t size) |
| 888 | { |
| 889 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 890 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 891 | struct fuse_req *req; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 892 | struct fuse_getxattr_in inarg; |
| 893 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 894 | ssize_t ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 895 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 896 | if (fc->no_getxattr) |
| 897 | return -EOPNOTSUPP; |
| 898 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 899 | req = fuse_get_request(fc); |
| 900 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 901 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 902 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 903 | memset(&inarg, 0, sizeof(inarg)); |
| 904 | inarg.size = size; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 905 | req->in.h.opcode = FUSE_GETXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 906 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 907 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 908 | req->in.numargs = 2; |
| 909 | req->in.args[0].size = sizeof(inarg); |
| 910 | req->in.args[0].value = &inarg; |
| 911 | req->in.args[1].size = strlen(name) + 1; |
| 912 | req->in.args[1].value = name; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 913 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 914 | req->out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 915 | if (size) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 916 | req->out.argvar = 1; |
| 917 | req->out.args[0].size = size; |
| 918 | req->out.args[0].value = value; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 919 | } else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 920 | req->out.args[0].size = sizeof(outarg); |
| 921 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 922 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 923 | request_send(fc, req); |
| 924 | ret = req->out.h.error; |
| 925 | if (!ret) |
| 926 | ret = size ? req->out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 927 | else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 928 | if (ret == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 929 | fc->no_getxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 930 | ret = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 931 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 932 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 933 | fuse_put_request(fc, req); |
| 934 | return ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) |
| 938 | { |
| 939 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 940 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 941 | struct fuse_req *req; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 942 | struct fuse_getxattr_in inarg; |
| 943 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 944 | ssize_t ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 945 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 946 | if (fc->no_listxattr) |
| 947 | return -EOPNOTSUPP; |
| 948 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 949 | req = fuse_get_request(fc); |
| 950 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 951 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 952 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 953 | memset(&inarg, 0, sizeof(inarg)); |
| 954 | inarg.size = size; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 955 | req->in.h.opcode = FUSE_LISTXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 956 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 957 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 958 | req->in.numargs = 1; |
| 959 | req->in.args[0].size = sizeof(inarg); |
| 960 | req->in.args[0].value = &inarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 961 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 962 | req->out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 963 | if (size) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 964 | req->out.argvar = 1; |
| 965 | req->out.args[0].size = size; |
| 966 | req->out.args[0].value = list; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 967 | } else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 968 | req->out.args[0].size = sizeof(outarg); |
| 969 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 970 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 971 | request_send(fc, req); |
| 972 | ret = req->out.h.error; |
| 973 | if (!ret) |
| 974 | ret = size ? req->out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 975 | else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 976 | if (ret == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 977 | fc->no_listxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 978 | ret = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 979 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 980 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 981 | fuse_put_request(fc, req); |
| 982 | return ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static int fuse_removexattr(struct dentry *entry, const char *name) |
| 986 | { |
| 987 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 988 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 989 | struct fuse_req *req; |
| 990 | int err; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 991 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 992 | if (fc->no_removexattr) |
| 993 | return -EOPNOTSUPP; |
| 994 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 995 | req = fuse_get_request(fc); |
| 996 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 997 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 998 | |
| 999 | req->in.h.opcode = FUSE_REMOVEXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 1000 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1001 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1002 | req->in.numargs = 1; |
| 1003 | req->in.args[0].size = strlen(name) + 1; |
| 1004 | req->in.args[0].value = name; |
| 1005 | request_send(fc, req); |
| 1006 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 1007 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1008 | if (err == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1009 | fc->no_removexattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1010 | err = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 1011 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 1012 | return err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1013 | } |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1014 | #endif |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1015 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1016 | static struct inode_operations fuse_dir_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1017 | .lookup = fuse_lookup, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1018 | .mkdir = fuse_mkdir, |
| 1019 | .symlink = fuse_symlink, |
| 1020 | .unlink = fuse_unlink, |
| 1021 | .rmdir = fuse_rmdir, |
| 1022 | .rename = fuse_rename, |
| 1023 | .link = fuse_link, |
| 1024 | .setattr = fuse_setattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1025 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1026 | .create = fuse_create, |
| 1027 | .mknod = fuse_mknod, |
| 1028 | .permission = fuse_permission, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1029 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1030 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1031 | .create = fuse_create_2_4, |
| 1032 | .mknod = fuse_mknod_2_4, |
| 1033 | .permission = fuse_permission_2_4, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1034 | .revalidate = fuse_revalidate, |
| 1035 | #endif |
| 1036 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1037 | .setxattr = fuse_setxattr, |
| 1038 | .getxattr = fuse_getxattr, |
| 1039 | .listxattr = fuse_listxattr, |
| 1040 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1041 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1042 | }; |
| 1043 | |
| 1044 | static struct file_operations fuse_dir_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1045 | .read = generic_read_dir, |
| 1046 | .readdir = fuse_readdir, |
| 1047 | .open = fuse_dir_open, |
| 1048 | .release = fuse_dir_release, |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1049 | }; |
| 1050 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1051 | static struct inode_operations fuse_common_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1052 | .setattr = fuse_setattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1053 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1054 | .permission = fuse_permission, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1055 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1056 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1057 | .permission = fuse_permission_2_4, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1058 | .revalidate = fuse_revalidate, |
| 1059 | #endif |
| 1060 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1061 | .setxattr = fuse_setxattr, |
| 1062 | .getxattr = fuse_getxattr, |
| 1063 | .listxattr = fuse_listxattr, |
| 1064 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1065 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1066 | }; |
| 1067 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1068 | static struct inode_operations fuse_symlink_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1069 | .setattr = fuse_setattr, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1070 | .follow_link = fuse_follow_link, |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame^] | 1071 | #ifdef KERNEL_2_6_7_PLUS |
| 1072 | .put_link = fuse_put_link, |
| 1073 | .readlink = generic_readlink, |
| 1074 | #else |
| 1075 | .readlink = fuse_readlink, |
| 1076 | #endif |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1077 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1078 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1079 | #else |
| 1080 | .revalidate = fuse_revalidate, |
| 1081 | #endif |
| 1082 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1083 | .setxattr = fuse_setxattr, |
| 1084 | .getxattr = fuse_getxattr, |
| 1085 | .listxattr = fuse_listxattr, |
| 1086 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1087 | #endif |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1088 | }; |
| 1089 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1090 | void fuse_init_common(struct inode *inode) |
| 1091 | { |
| 1092 | inode->i_op = &fuse_common_inode_operations; |
| 1093 | } |
| 1094 | |
| 1095 | void fuse_init_dir(struct inode *inode) |
| 1096 | { |
| 1097 | inode->i_op = &fuse_dir_inode_operations; |
| 1098 | inode->i_fop = &fuse_dir_operations; |
| 1099 | } |
| 1100 | |
| 1101 | void fuse_init_symlink(struct inode *inode) |
| 1102 | { |
| 1103 | inode->i_op = &fuse_symlink_inode_operations; |
| 1104 | } |