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 | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 436 | static int fuse_revalidate(struct dentry *entry) |
| 437 | { |
| 438 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 439 | struct fuse_inode *fi = get_fuse_inode(inode); |
| 440 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 441 | |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 442 | if (get_node_id(inode) == FUSE_ROOT_ID) { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 443 | if (!(fc->flags & FUSE_ALLOW_OTHER) && |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 444 | current->fsuid != fc->user_id && |
Miklos Szeredi | 180ff69 | 2004-11-01 16:01:05 +0000 | [diff] [blame] | 445 | (!(fc->flags & FUSE_ALLOW_ROOT) || |
Miklos Szeredi | 9ed69ba | 2005-01-13 12:11:49 +0000 | [diff] [blame] | 446 | !capable(CAP_DAC_OVERRIDE))) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 447 | return -EACCES; |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 448 | } else if (time_before_eq(jiffies, fi->i_time)) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 449 | return 0; |
| 450 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 451 | return fuse_do_getattr(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 454 | static int fuse_permission(struct inode *inode, int mask, struct nameidata *nd) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 455 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 456 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 457 | |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 458 | if (!(fc->flags & FUSE_ALLOW_OTHER) && current->fsuid != fc->user_id && |
Miklos Szeredi | 9ed69ba | 2005-01-13 12:11:49 +0000 | [diff] [blame] | 459 | (!(fc->flags & FUSE_ALLOW_ROOT) || !capable(CAP_DAC_OVERRIDE))) |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 460 | return -EACCES; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 461 | else if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 462 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 463 | int err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 464 | #else |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 465 | int err = vfs_permission(inode, mask); |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 466 | #endif |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 467 | |
| 468 | /* If permission is denied, try to refresh file |
| 469 | attributes. This is also needed, because the root |
| 470 | node will at first have no permissions */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 471 | if (err == -EACCES) { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 472 | err = fuse_do_getattr(inode); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 473 | if (!err) |
| 474 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 475 | err = generic_permission(inode, mask, NULL); |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 476 | #else |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 477 | err = vfs_permission(inode, mask); |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 478 | #endif |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | /* FIXME: Need some mechanism to revoke permissions: |
| 482 | currently if the filesystem suddenly changes the |
Miklos Szeredi | 064efb0 | 2004-11-09 17:30:29 +0000 | [diff] [blame] | 483 | file mode, we will not be informed about it, and |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 484 | continue to allow access to the file/directory. |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 485 | |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 486 | This is actually not so grave, since the user can |
| 487 | simply keep access to the file/directory anyway by |
| 488 | keeping it open... */ |
| 489 | |
| 490 | return err; |
Miklos Szeredi | 96dfad7 | 2004-11-30 00:00:02 +0000 | [diff] [blame] | 491 | } else { |
| 492 | int mode = inode->i_mode; |
| 493 | if ((mask & MAY_WRITE) && IS_RDONLY(inode) && |
| 494 | (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))) |
| 495 | return -EROFS; |
| 496 | if ((mask & MAY_EXEC) && !S_ISDIR(mode) && !(mode & S_IXUGO)) |
| 497 | return -EACCES; |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 498 | return 0; |
Miklos Szeredi | 96dfad7 | 2004-11-30 00:00:02 +0000 | [diff] [blame] | 499 | } |
Miklos Szeredi | fe25def | 2001-12-20 15:38:05 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 502 | static int parse_dirfile(char *buf, size_t nbytes, struct file *file, |
| 503 | void *dstbuf, filldir_t filldir) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 504 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 505 | while (nbytes >= FUSE_NAME_OFFSET) { |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 506 | struct fuse_dirent *dirent = (struct fuse_dirent *) buf; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 507 | size_t reclen = FUSE_DIRENT_SIZE(dirent); |
| 508 | int over; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 509 | if (dirent->namelen > FUSE_NAME_MAX) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 510 | return -EIO; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 511 | if (reclen > nbytes) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 512 | break; |
| 513 | |
| 514 | over = filldir(dstbuf, dirent->name, dirent->namelen, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 515 | file->f_pos, dirent->ino, dirent->type); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 516 | if (over) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 517 | break; |
| 518 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 519 | buf += reclen; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 520 | file->f_pos += reclen; |
| 521 | nbytes -= reclen; |
| 522 | } |
| 523 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 524 | return 0; |
| 525 | } |
| 526 | |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 527 | static inline size_t fuse_send_readdir(struct fuse_req *req, struct file *file, |
| 528 | struct inode *inode, loff_t pos, |
| 529 | size_t count) |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 530 | { |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 531 | return fuse_send_read_common(req, file, inode, pos, count, 1); |
Miklos Szeredi | 152f29e | 2004-06-03 17:52:32 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 534 | static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir) |
| 535 | { |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 536 | int err; |
| 537 | size_t nbytes; |
| 538 | struct page *page; |
Miklos Szeredi | e22acbe | 2005-01-20 08:37:30 +0000 | [diff] [blame] | 539 | struct inode *inode = file->f_dentry->d_inode; |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 540 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 541 | struct fuse_req *req = fuse_get_request_nonint(fc); |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 542 | if (!req) |
Miklos Szeredi | 3ead28e | 2005-01-18 21:23:41 +0000 | [diff] [blame] | 543 | return -EINTR; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 544 | |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 545 | page = alloc_page(GFP_KERNEL); |
| 546 | if (!page) { |
| 547 | fuse_put_request(fc, req); |
Miklos Szeredi | b483c93 | 2001-10-29 14:57:57 +0000 | [diff] [blame] | 548 | return -ENOMEM; |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 549 | } |
| 550 | req->num_pages = 1; |
| 551 | req->pages[0] = page; |
| 552 | nbytes = fuse_send_readdir(req, file, inode, file->f_pos, PAGE_SIZE); |
| 553 | err = req->out.h.error; |
| 554 | fuse_put_request(fc, req); |
| 555 | if (!err) |
| 556 | err = parse_dirfile(page_address(page), nbytes, file, dstbuf, |
| 557 | filldir); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 558 | |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 559 | __free_page(page); |
| 560 | return err; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 561 | } |
| 562 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 563 | static char *read_link(struct dentry *dentry) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 564 | { |
| 565 | struct inode *inode = dentry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 566 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 567 | struct fuse_req *req = fuse_get_request(fc); |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 568 | char *link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 569 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 570 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 571 | return ERR_PTR(-ERESTARTNOINTR); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 572 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 573 | link = (char *) __get_free_page(GFP_KERNEL); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 574 | if (!link) { |
| 575 | link = ERR_PTR(-ENOMEM); |
| 576 | goto out; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 577 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 578 | req->in.h.opcode = FUSE_READLINK; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 579 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 580 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 581 | req->out.argvar = 1; |
| 582 | req->out.numargs = 1; |
| 583 | req->out.args[0].size = PAGE_SIZE - 1; |
| 584 | req->out.args[0].value = link; |
| 585 | request_send(fc, req); |
| 586 | if (req->out.h.error) { |
| 587 | free_page((unsigned long) link); |
| 588 | link = ERR_PTR(req->out.h.error); |
| 589 | } else |
| 590 | link[req->out.args[0].size] = '\0'; |
| 591 | out: |
| 592 | fuse_put_request(fc, req); |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 593 | return link; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | static void free_link(char *link) |
| 597 | { |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 598 | if (!IS_ERR(link)) |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 599 | free_page((unsigned long) link); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 600 | } |
| 601 | |
Miklos Szeredi | 7a98395 | 2005-01-28 09:58:19 +0000 | [diff] [blame^] | 602 | #ifdef KERNEL_2_6_8_PLUS |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 603 | static int fuse_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 604 | { |
| 605 | nd_set_link(nd, read_link(dentry)); |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static void fuse_put_link(struct dentry *dentry, struct nameidata *nd) |
| 610 | { |
| 611 | free_link(nd_get_link(nd)); |
| 612 | } |
| 613 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 614 | static int fuse_readlink(struct dentry *dentry, char __user *buffer, |
| 615 | int buflen) |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 616 | { |
| 617 | int ret; |
| 618 | char *link; |
| 619 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 620 | link = read_link(dentry); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 621 | ret = vfs_readlink(dentry, buffer, buflen, link); |
| 622 | free_link(link); |
| 623 | return ret; |
| 624 | } |
| 625 | |
| 626 | static int fuse_follow_link(struct dentry *dentry, struct nameidata *nd) |
| 627 | { |
| 628 | int ret; |
| 629 | char *link; |
| 630 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 631 | link = read_link(dentry); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 632 | ret = vfs_follow_link(nd, link); |
| 633 | free_link(link); |
| 634 | return ret; |
| 635 | } |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 636 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 637 | |
| 638 | static int fuse_dir_open(struct inode *inode, struct file *file) |
| 639 | { |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 640 | return fuse_open_common(inode, file, 1); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | static int fuse_dir_release(struct inode *inode, struct file *file) |
| 644 | { |
Miklos Szeredi | 1adb227 | 2005-01-18 21:19:58 +0000 | [diff] [blame] | 645 | return fuse_release_common(inode, file, 1); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 648 | static unsigned iattr_to_fattr(struct iattr *iattr, struct fuse_attr *fattr) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 649 | { |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 650 | unsigned ivalid = iattr->ia_valid; |
| 651 | unsigned fvalid = 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 652 | |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 653 | memset(fattr, 0, sizeof(*fattr)); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 654 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 655 | if (ivalid & ATTR_MODE) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 656 | fvalid |= FATTR_MODE, fattr->mode = iattr->ia_mode; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 657 | if (ivalid & ATTR_UID) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 658 | fvalid |= FATTR_UID, fattr->uid = iattr->ia_uid; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 659 | if (ivalid & ATTR_GID) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 660 | fvalid |= FATTR_GID, fattr->gid = iattr->ia_gid; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 661 | if (ivalid & ATTR_SIZE) |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 662 | fvalid |= FATTR_SIZE, fattr->size = iattr->ia_size; |
| 663 | /* You can only _set_ these together (they may change by themselves) */ |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 664 | if ((ivalid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME)) { |
Miklos Szeredi | b595861 | 2004-02-20 14:10:49 +0000 | [diff] [blame] | 665 | fvalid |= FATTR_ATIME | FATTR_MTIME; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 666 | #ifdef KERNEL_2_6 |
| 667 | fattr->atime = iattr->ia_atime.tv_sec; |
| 668 | fattr->mtime = iattr->ia_mtime.tv_sec; |
| 669 | #else |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 670 | fattr->atime = iattr->ia_atime; |
| 671 | fattr->mtime = iattr->ia_mtime; |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 672 | #endif |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | return fvalid; |
| 676 | } |
| 677 | |
| 678 | static int fuse_setattr(struct dentry *entry, struct iattr *attr) |
| 679 | { |
| 680 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 681 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 682 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 683 | struct fuse_req *req; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 684 | struct fuse_setattr_in inarg; |
Miklos Szeredi | 254d5ed | 2004-03-02 11:11:24 +0000 | [diff] [blame] | 685 | struct fuse_attr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 686 | int err; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 687 | int is_truncate = 0; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 688 | |
Miklos Szeredi | 94ed76a | 2004-07-26 19:38:45 +0000 | [diff] [blame] | 689 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) { |
| 690 | err = inode_change_ok(inode, attr); |
| 691 | if (err) |
| 692 | return err; |
| 693 | } |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 694 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 695 | if (attr->ia_valid & ATTR_SIZE) { |
| 696 | unsigned long limit; |
| 697 | is_truncate = 1; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 698 | #ifdef KERNEL_2_6_10_PLUS |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 699 | limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 700 | #else |
| 701 | limit = current->rlim[RLIMIT_FSIZE].rlim_cur; |
Miklos Szeredi | 08ddb8e | 2004-11-14 09:19:51 +0000 | [diff] [blame] | 702 | #endif |
| 703 | if (limit != RLIM_INFINITY && attr->ia_size > (loff_t) limit) { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 704 | send_sig(SIGXFSZ, current, 0); |
| 705 | return -EFBIG; |
| 706 | } |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 707 | } |
Miklos Szeredi | 58615e0 | 2004-07-04 21:21:08 +0000 | [diff] [blame] | 708 | |
| 709 | req = fuse_get_request(fc); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 710 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 711 | return -ERESTARTNOINTR; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 712 | |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 713 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 714 | inarg.valid = iattr_to_fattr(attr, &inarg.attr); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 715 | req->in.h.opcode = FUSE_SETATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 716 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 717 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 718 | req->in.numargs = 1; |
| 719 | req->in.args[0].size = sizeof(inarg); |
| 720 | req->in.args[0].value = &inarg; |
| 721 | req->out.numargs = 1; |
| 722 | req->out.args[0].size = sizeof(outarg); |
| 723 | req->out.args[0].value = &outarg; |
| 724 | request_send(fc, req); |
| 725 | err = req->out.h.error; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 726 | fuse_put_request(fc, req); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 727 | if (!err) { |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 728 | if ((inode->i_mode ^ outarg.attr.mode) & S_IFMT) { |
Miklos Szeredi | e22acbe | 2005-01-20 08:37:30 +0000 | [diff] [blame] | 729 | #ifndef FUSE_MAINLINE |
Miklos Szeredi | dbe0f65 | 2005-01-15 14:32:56 +0000 | [diff] [blame] | 730 | if (get_node_id(inode) != FUSE_ROOT_ID) |
| 731 | make_bad_inode(inode); |
Miklos Szeredi | e22acbe | 2005-01-20 08:37:30 +0000 | [diff] [blame] | 732 | #else |
| 733 | make_bad_inode(inode); |
| 734 | #endif |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 735 | err = -EIO; |
| 736 | } else { |
| 737 | if (is_truncate) { |
| 738 | loff_t origsize = i_size_read(inode); |
| 739 | i_size_write(inode, outarg.attr.size); |
| 740 | if (origsize > outarg.attr.size) |
| 741 | vmtruncate(inode, outarg.attr.size); |
| 742 | } |
| 743 | fuse_change_attributes(inode, &outarg.attr); |
| 744 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
| 745 | outarg.attr_valid_nsec); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 746 | } |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 747 | } else if (err == -EINTR) |
| 748 | fuse_invalidate_attr(inode); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 749 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 750 | return err; |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 751 | } |
| 752 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 753 | #ifdef KERNEL_2_6 |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 754 | static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry, |
| 755 | struct kstat *stat) |
| 756 | { |
| 757 | struct inode *inode = entry->d_inode; |
| 758 | int err = fuse_revalidate(entry); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 759 | if (!err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 760 | generic_fillattr(inode, stat); |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 761 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 762 | return err; |
| 763 | } |
| 764 | |
| 765 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 766 | struct nameidata *nd) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 767 | { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 768 | struct inode *inode; |
| 769 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 770 | if (err) |
| 771 | return ERR_PTR(err); |
| 772 | return d_splice_alias(inode, entry); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 773 | } |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 774 | #else /* KERNEL_2_6 */ |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 775 | static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry) |
| 776 | { |
| 777 | struct inode *inode; |
| 778 | struct dentry *alias; |
| 779 | |
| 780 | int err = fuse_lookup_iget(dir, entry, &inode); |
| 781 | if (err) |
| 782 | return ERR_PTR(err); |
| 783 | |
| 784 | if (inode && S_ISDIR(inode->i_mode) && |
| 785 | (alias = d_find_alias(inode)) != NULL) { |
| 786 | dput(alias); |
| 787 | iput(inode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 788 | return ERR_PTR(-EIO); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | d_add(entry, inode); |
| 792 | return NULL; |
| 793 | } |
| 794 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 795 | 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] | 796 | int rdev) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 797 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 798 | return fuse_mknod(dir, entry, mode, rdev); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 801 | static int fuse_create_2_4(struct inode *dir, struct dentry *entry, int mode) |
| 802 | { |
| 803 | return fuse_create(dir, entry, mode, NULL); |
| 804 | } |
| 805 | |
| 806 | static int fuse_permission_2_4(struct inode *inode, int mask) |
| 807 | { |
| 808 | return fuse_permission(inode, mask, NULL); |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 809 | } |
| 810 | #endif /* KERNEL_2_6 */ |
| 811 | |
| 812 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 813 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 814 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 815 | const void *value, size_t size, int flags) |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 816 | #else |
| 817 | static int fuse_setxattr(struct dentry *entry, const char *name, |
| 818 | void *value, size_t size, int flags) |
| 819 | #endif |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 820 | { |
| 821 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 822 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 823 | struct fuse_req *req; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 824 | struct fuse_setxattr_in inarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 825 | int err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 826 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 827 | if (size > FUSE_XATTR_SIZE_MAX) |
| 828 | return -E2BIG; |
| 829 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 830 | if (fc->no_setxattr) |
| 831 | return -EOPNOTSUPP; |
| 832 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 833 | req = fuse_get_request(fc); |
| 834 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 835 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 836 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 837 | memset(&inarg, 0, sizeof(inarg)); |
| 838 | inarg.size = size; |
| 839 | inarg.flags = flags; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 840 | req->in.h.opcode = FUSE_SETXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 841 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 842 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 843 | req->in.numargs = 3; |
| 844 | req->in.args[0].size = sizeof(inarg); |
| 845 | req->in.args[0].value = &inarg; |
| 846 | req->in.args[1].size = strlen(name) + 1; |
| 847 | req->in.args[1].value = name; |
| 848 | req->in.args[2].size = size; |
| 849 | req->in.args[2].value = value; |
| 850 | request_send(fc, req); |
| 851 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 852 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 853 | if (err == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 854 | fc->no_setxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 855 | err = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 856 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 857 | return err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static ssize_t fuse_getxattr(struct dentry *entry, const char *name, |
| 861 | void *value, size_t size) |
| 862 | { |
| 863 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 864 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 865 | struct fuse_req *req; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 866 | struct fuse_getxattr_in inarg; |
| 867 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 868 | ssize_t ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 869 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 870 | if (fc->no_getxattr) |
| 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; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 879 | req->in.h.opcode = FUSE_GETXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 880 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 881 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 882 | req->in.numargs = 2; |
| 883 | req->in.args[0].size = sizeof(inarg); |
| 884 | req->in.args[0].value = &inarg; |
| 885 | req->in.args[1].size = strlen(name) + 1; |
| 886 | req->in.args[1].value = name; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 887 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 888 | req->out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 889 | if (size) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 890 | req->out.argvar = 1; |
| 891 | req->out.args[0].size = size; |
| 892 | req->out.args[0].value = value; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 893 | } else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 894 | req->out.args[0].size = sizeof(outarg); |
| 895 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 896 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 897 | request_send(fc, req); |
| 898 | ret = req->out.h.error; |
| 899 | if (!ret) |
| 900 | ret = size ? req->out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 901 | else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 902 | if (ret == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 903 | fc->no_getxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 904 | ret = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 905 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 906 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 907 | fuse_put_request(fc, req); |
| 908 | return ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size) |
| 912 | { |
| 913 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 914 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 915 | struct fuse_req *req; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 916 | struct fuse_getxattr_in inarg; |
| 917 | struct fuse_getxattr_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 918 | ssize_t ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 919 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 920 | if (fc->no_listxattr) |
| 921 | return -EOPNOTSUPP; |
| 922 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 923 | req = fuse_get_request(fc); |
| 924 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 925 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 926 | |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 927 | memset(&inarg, 0, sizeof(inarg)); |
| 928 | inarg.size = size; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 929 | req->in.h.opcode = FUSE_LISTXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 930 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 931 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 932 | req->in.numargs = 1; |
| 933 | req->in.args[0].size = sizeof(inarg); |
| 934 | req->in.args[0].value = &inarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 935 | /* This is really two different operations rolled into one */ |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 936 | req->out.numargs = 1; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 937 | if (size) { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 938 | req->out.argvar = 1; |
| 939 | req->out.args[0].size = size; |
| 940 | req->out.args[0].value = list; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 941 | } else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 942 | req->out.args[0].size = sizeof(outarg); |
| 943 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 03cebae | 2004-03-31 10:19:18 +0000 | [diff] [blame] | 944 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 945 | request_send(fc, req); |
| 946 | ret = req->out.h.error; |
| 947 | if (!ret) |
| 948 | ret = size ? req->out.args[0].size : outarg.size; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 949 | else { |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 950 | if (ret == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 951 | fc->no_listxattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 952 | ret = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 953 | } |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 954 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 955 | fuse_put_request(fc, req); |
| 956 | return ret; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | static int fuse_removexattr(struct dentry *entry, const char *name) |
| 960 | { |
| 961 | struct inode *inode = entry->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 962 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 963 | struct fuse_req *req; |
| 964 | int err; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 965 | |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 966 | if (fc->no_removexattr) |
| 967 | return -EOPNOTSUPP; |
| 968 | |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 969 | req = fuse_get_request(fc); |
| 970 | if (!req) |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 971 | return -ERESTARTNOINTR; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 972 | |
| 973 | req->in.h.opcode = FUSE_REMOVEXATTR; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 974 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 975 | req->inode = inode; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 976 | req->in.numargs = 1; |
| 977 | req->in.args[0].size = strlen(name) + 1; |
| 978 | req->in.args[0].value = name; |
| 979 | request_send(fc, req); |
| 980 | err = req->out.h.error; |
Miklos Szeredi | 0fcfa03 | 2004-12-13 15:22:28 +0000 | [diff] [blame] | 981 | fuse_put_request(fc, req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 982 | if (err == -ENOSYS) { |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 983 | fc->no_removexattr = 1; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 984 | err = -EOPNOTSUPP; |
Miklos Szeredi | 63b8c1c | 2004-06-03 14:45:04 +0000 | [diff] [blame] | 985 | } |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 986 | return err; |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 987 | } |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 988 | #endif |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 989 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 990 | static struct inode_operations fuse_dir_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 991 | .lookup = fuse_lookup, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 992 | .mkdir = fuse_mkdir, |
| 993 | .symlink = fuse_symlink, |
| 994 | .unlink = fuse_unlink, |
| 995 | .rmdir = fuse_rmdir, |
| 996 | .rename = fuse_rename, |
| 997 | .link = fuse_link, |
| 998 | .setattr = fuse_setattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 999 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1000 | .create = fuse_create, |
| 1001 | .mknod = fuse_mknod, |
| 1002 | .permission = fuse_permission, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1003 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1004 | #else |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1005 | .create = fuse_create_2_4, |
| 1006 | .mknod = fuse_mknod_2_4, |
| 1007 | .permission = fuse_permission_2_4, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1008 | .revalidate = fuse_revalidate, |
| 1009 | #endif |
| 1010 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1011 | .setxattr = fuse_setxattr, |
| 1012 | .getxattr = fuse_getxattr, |
| 1013 | .listxattr = fuse_listxattr, |
| 1014 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1015 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1016 | }; |
| 1017 | |
| 1018 | static struct file_operations fuse_dir_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1019 | .read = generic_read_dir, |
| 1020 | .readdir = fuse_readdir, |
| 1021 | .open = fuse_dir_open, |
| 1022 | .release = fuse_dir_release, |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1023 | }; |
| 1024 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1025 | static struct inode_operations fuse_common_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1026 | .setattr = fuse_setattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1027 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 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 | .permission = fuse_permission_2_4, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1032 | .revalidate = fuse_revalidate, |
| 1033 | #endif |
| 1034 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1035 | .setxattr = fuse_setxattr, |
| 1036 | .getxattr = fuse_getxattr, |
| 1037 | .listxattr = fuse_listxattr, |
| 1038 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1039 | #endif |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1040 | }; |
| 1041 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 1042 | static struct inode_operations fuse_symlink_inode_operations = { |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1043 | .setattr = fuse_setattr, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1044 | .follow_link = fuse_follow_link, |
Miklos Szeredi | 7a98395 | 2005-01-28 09:58:19 +0000 | [diff] [blame^] | 1045 | #ifdef KERNEL_2_6_8_PLUS |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 1046 | .put_link = fuse_put_link, |
| 1047 | .readlink = generic_readlink, |
| 1048 | #else |
| 1049 | .readlink = fuse_readlink, |
| 1050 | #endif |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1051 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 1052 | .getattr = fuse_getattr, |
Miklos Szeredi | 689f563 | 2004-05-04 08:49:16 +0000 | [diff] [blame] | 1053 | #else |
| 1054 | .revalidate = fuse_revalidate, |
| 1055 | #endif |
| 1056 | #ifdef HAVE_KERNEL_XATTR |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame] | 1057 | .setxattr = fuse_setxattr, |
| 1058 | .getxattr = fuse_getxattr, |
| 1059 | .listxattr = fuse_listxattr, |
| 1060 | .removexattr = fuse_removexattr, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 1061 | #endif |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 1062 | }; |
| 1063 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 1064 | void fuse_init_common(struct inode *inode) |
| 1065 | { |
| 1066 | inode->i_op = &fuse_common_inode_operations; |
| 1067 | } |
| 1068 | |
| 1069 | void fuse_init_dir(struct inode *inode) |
| 1070 | { |
| 1071 | inode->i_op = &fuse_dir_inode_operations; |
| 1072 | inode->i_fop = &fuse_dir_operations; |
| 1073 | } |
| 1074 | |
| 1075 | void fuse_init_symlink(struct inode *inode) |
| 1076 | { |
| 1077 | inode->i_op = &fuse_symlink_inode_operations; |
| 1078 | } |