Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 56cf34f | 2006-04-11 21:16:51 +0200 | [diff] [blame] | 3 | Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
| 9 | #include "fuse_i.h" |
| 10 | |
| 11 | #include <linux/pagemap.h> |
| 12 | #include <linux/slab.h> |
| 13 | #include <linux/kernel.h> |
| 14 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 15 | static const struct file_operations fuse_direct_io_file_operations; |
Miklos Szeredi | 45323fb | 2005-09-09 13:10:37 -0700 | [diff] [blame] | 16 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 17 | static int fuse_send_open(struct inode *inode, struct file *file, int isdir, |
| 18 | struct fuse_open_out *outargp) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 19 | { |
| 20 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 21 | struct fuse_open_in inarg; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 22 | struct fuse_req *req; |
| 23 | int err; |
| 24 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 25 | req = fuse_get_req(fc); |
| 26 | if (IS_ERR(req)) |
| 27 | return PTR_ERR(req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 28 | |
| 29 | memset(&inarg, 0, sizeof(inarg)); |
| 30 | inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); |
| 31 | req->in.h.opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN; |
| 32 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 33 | req->in.numargs = 1; |
| 34 | req->in.args[0].size = sizeof(inarg); |
| 35 | req->in.args[0].value = &inarg; |
| 36 | req->out.numargs = 1; |
| 37 | req->out.args[0].size = sizeof(*outargp); |
| 38 | req->out.args[0].value = outargp; |
| 39 | request_send(fc, req); |
| 40 | err = req->out.h.error; |
| 41 | fuse_put_request(fc, req); |
| 42 | |
| 43 | return err; |
| 44 | } |
| 45 | |
| 46 | struct fuse_file *fuse_file_alloc(void) |
| 47 | { |
| 48 | struct fuse_file *ff; |
| 49 | ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL); |
| 50 | if (ff) { |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 51 | ff->reserved_req = fuse_request_alloc(); |
| 52 | if (!ff->reserved_req) { |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 53 | kfree(ff); |
| 54 | ff = NULL; |
| 55 | } |
| 56 | } |
| 57 | return ff; |
| 58 | } |
| 59 | |
| 60 | void fuse_file_free(struct fuse_file *ff) |
| 61 | { |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 62 | fuse_request_free(ff->reserved_req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 63 | kfree(ff); |
| 64 | } |
| 65 | |
| 66 | void fuse_finish_open(struct inode *inode, struct file *file, |
| 67 | struct fuse_file *ff, struct fuse_open_out *outarg) |
| 68 | { |
| 69 | if (outarg->open_flags & FOPEN_DIRECT_IO) |
| 70 | file->f_op = &fuse_direct_io_file_operations; |
| 71 | if (!(outarg->open_flags & FOPEN_KEEP_CACHE)) |
| 72 | invalidate_inode_pages(inode->i_mapping); |
| 73 | ff->fh = outarg->fh; |
| 74 | file->private_data = ff; |
| 75 | } |
| 76 | |
| 77 | int fuse_open_common(struct inode *inode, struct file *file, int isdir) |
| 78 | { |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 79 | struct fuse_open_out outarg; |
| 80 | struct fuse_file *ff; |
| 81 | int err; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 82 | |
Miklos Szeredi | dd190d0 | 2005-09-30 11:59:02 -0700 | [diff] [blame] | 83 | /* VFS checks this, but only _after_ ->open() */ |
| 84 | if (file->f_flags & O_DIRECT) |
| 85 | return -EINVAL; |
| 86 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 87 | err = generic_file_open(inode, file); |
| 88 | if (err) |
| 89 | return err; |
| 90 | |
| 91 | /* If opening the root node, no lookup has been performed on |
| 92 | it, so the attributes must be refreshed */ |
| 93 | if (get_node_id(inode) == FUSE_ROOT_ID) { |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 94 | err = fuse_do_getattr(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 95 | if (err) |
| 96 | return err; |
| 97 | } |
| 98 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 99 | ff = fuse_file_alloc(); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 100 | if (!ff) |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 101 | return -ENOMEM; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 102 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 103 | err = fuse_send_open(inode, file, isdir, &outarg); |
| 104 | if (err) |
| 105 | fuse_file_free(ff); |
| 106 | else { |
| 107 | if (isdir) |
| 108 | outarg.open_flags &= ~FOPEN_DIRECT_IO; |
| 109 | fuse_finish_open(inode, file, ff, &outarg); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 112 | return err; |
| 113 | } |
| 114 | |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 115 | struct fuse_req *fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, |
| 116 | int opcode) |
Miklos Szeredi | 64c6d8e | 2006-01-16 22:14:42 -0800 | [diff] [blame] | 117 | { |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 118 | struct fuse_req *req = ff->reserved_req; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 119 | struct fuse_release_in *inarg = &req->misc.release_in; |
| 120 | |
| 121 | inarg->fh = ff->fh; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 122 | inarg->flags = flags; |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 123 | req->in.h.opcode = opcode; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 124 | req->in.h.nodeid = nodeid; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 125 | req->in.numargs = 1; |
| 126 | req->in.args[0].size = sizeof(struct fuse_release_in); |
| 127 | req->in.args[0].value = inarg; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 128 | kfree(ff); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 129 | |
| 130 | return req; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | int fuse_release_common(struct inode *inode, struct file *file, int isdir) |
| 134 | { |
| 135 | struct fuse_file *ff = file->private_data; |
| 136 | if (ff) { |
| 137 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 138 | struct fuse_req *req; |
| 139 | |
| 140 | req = fuse_release_fill(ff, get_node_id(inode), file->f_flags, |
| 141 | isdir ? FUSE_RELEASEDIR : FUSE_RELEASE); |
| 142 | |
| 143 | /* Hold vfsmount and dentry until release is finished */ |
| 144 | req->vfsmount = mntget(file->f_vfsmnt); |
| 145 | req->dentry = dget(file->f_dentry); |
| 146 | request_send_background(fc, req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 147 | } |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 148 | |
| 149 | /* Return value is ignored by VFS */ |
| 150 | return 0; |
| 151 | } |
| 152 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 153 | static int fuse_open(struct inode *inode, struct file *file) |
| 154 | { |
| 155 | return fuse_open_common(inode, file, 0); |
| 156 | } |
| 157 | |
| 158 | static int fuse_release(struct inode *inode, struct file *file) |
| 159 | { |
| 160 | return fuse_release_common(inode, file, 0); |
| 161 | } |
| 162 | |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 163 | /* |
| 164 | * It would be nice to scramble the ID space, so that the value of the |
| 165 | * files_struct pointer is not exposed to userspace. Symmetric crypto |
| 166 | * functions are overkill, since the inverse function doesn't need to |
| 167 | * be implemented (though it does have to exist). Is there something |
| 168 | * simpler? |
| 169 | */ |
| 170 | static inline u64 fuse_lock_owner_id(fl_owner_t id) |
| 171 | { |
| 172 | return (unsigned long) id; |
| 173 | } |
| 174 | |
Miklos Szeredi | 75e1fcc | 2006-06-23 02:05:12 -0700 | [diff] [blame] | 175 | static int fuse_flush(struct file *file, fl_owner_t id) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 176 | { |
| 177 | struct inode *inode = file->f_dentry->d_inode; |
| 178 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 179 | struct fuse_file *ff = file->private_data; |
| 180 | struct fuse_req *req; |
| 181 | struct fuse_flush_in inarg; |
| 182 | int err; |
| 183 | |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 184 | if (is_bad_inode(inode)) |
| 185 | return -EIO; |
| 186 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 187 | if (fc->no_flush) |
| 188 | return 0; |
| 189 | |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 190 | req = fuse_get_req_nofail(fc, file); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 191 | memset(&inarg, 0, sizeof(inarg)); |
| 192 | inarg.fh = ff->fh; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 193 | inarg.lock_owner = fuse_lock_owner_id(id); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 194 | req->in.h.opcode = FUSE_FLUSH; |
| 195 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 196 | req->in.numargs = 1; |
| 197 | req->in.args[0].size = sizeof(inarg); |
| 198 | req->in.args[0].value = &inarg; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 199 | req->force = 1; |
Miklos Szeredi | 7c352bd | 2005-09-09 13:10:39 -0700 | [diff] [blame] | 200 | request_send(fc, req); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 201 | err = req->out.h.error; |
| 202 | fuse_put_request(fc, req); |
| 203 | if (err == -ENOSYS) { |
| 204 | fc->no_flush = 1; |
| 205 | err = 0; |
| 206 | } |
| 207 | return err; |
| 208 | } |
| 209 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 210 | int fuse_fsync_common(struct file *file, struct dentry *de, int datasync, |
| 211 | int isdir) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 212 | { |
| 213 | struct inode *inode = de->d_inode; |
| 214 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 215 | struct fuse_file *ff = file->private_data; |
| 216 | struct fuse_req *req; |
| 217 | struct fuse_fsync_in inarg; |
| 218 | int err; |
| 219 | |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 220 | if (is_bad_inode(inode)) |
| 221 | return -EIO; |
| 222 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 223 | if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir)) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 224 | return 0; |
| 225 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 226 | req = fuse_get_req(fc); |
| 227 | if (IS_ERR(req)) |
| 228 | return PTR_ERR(req); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 229 | |
| 230 | memset(&inarg, 0, sizeof(inarg)); |
| 231 | inarg.fh = ff->fh; |
| 232 | inarg.fsync_flags = datasync ? 1 : 0; |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 233 | req->in.h.opcode = isdir ? FUSE_FSYNCDIR : FUSE_FSYNC; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 234 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 235 | req->in.numargs = 1; |
| 236 | req->in.args[0].size = sizeof(inarg); |
| 237 | req->in.args[0].value = &inarg; |
| 238 | request_send(fc, req); |
| 239 | err = req->out.h.error; |
| 240 | fuse_put_request(fc, req); |
| 241 | if (err == -ENOSYS) { |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 242 | if (isdir) |
| 243 | fc->no_fsyncdir = 1; |
| 244 | else |
| 245 | fc->no_fsync = 1; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 246 | err = 0; |
| 247 | } |
| 248 | return err; |
| 249 | } |
| 250 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 251 | static int fuse_fsync(struct file *file, struct dentry *de, int datasync) |
| 252 | { |
| 253 | return fuse_fsync_common(file, de, datasync, 0); |
| 254 | } |
| 255 | |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 256 | void fuse_read_fill(struct fuse_req *req, struct file *file, |
| 257 | struct inode *inode, loff_t pos, size_t count, int opcode) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 258 | { |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 259 | struct fuse_file *ff = file->private_data; |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 260 | struct fuse_read_in *inarg = &req->misc.read_in; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 261 | |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 262 | inarg->fh = ff->fh; |
| 263 | inarg->offset = pos; |
| 264 | inarg->size = count; |
| 265 | req->in.h.opcode = opcode; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 266 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 267 | req->in.numargs = 1; |
| 268 | req->in.args[0].size = sizeof(struct fuse_read_in); |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 269 | req->in.args[0].value = inarg; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 270 | req->out.argpages = 1; |
| 271 | req->out.argvar = 1; |
| 272 | req->out.numargs = 1; |
| 273 | req->out.args[0].size = count; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Miklos Szeredi | 8bfc016 | 2006-01-16 22:14:28 -0800 | [diff] [blame] | 276 | static size_t fuse_send_read(struct fuse_req *req, struct file *file, |
| 277 | struct inode *inode, loff_t pos, size_t count) |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 278 | { |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 279 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 280 | fuse_read_fill(req, file, inode, pos, count, FUSE_READ); |
| 281 | request_send(fc, req); |
| 282 | return req->out.args[0].size; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 285 | static int fuse_readpage(struct file *file, struct page *page) |
| 286 | { |
| 287 | struct inode *inode = page->mapping->host; |
| 288 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 289 | struct fuse_req *req; |
| 290 | int err; |
| 291 | |
| 292 | err = -EIO; |
| 293 | if (is_bad_inode(inode)) |
| 294 | goto out; |
| 295 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 296 | req = fuse_get_req(fc); |
| 297 | err = PTR_ERR(req); |
| 298 | if (IS_ERR(req)) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 299 | goto out; |
| 300 | |
| 301 | req->out.page_zeroing = 1; |
| 302 | req->num_pages = 1; |
| 303 | req->pages[0] = page; |
Miklos Szeredi | 4633a22 | 2006-01-06 00:19:36 -0800 | [diff] [blame] | 304 | fuse_send_read(req, file, inode, page_offset(page), PAGE_CACHE_SIZE); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 305 | err = req->out.h.error; |
| 306 | fuse_put_request(fc, req); |
| 307 | if (!err) |
| 308 | SetPageUptodate(page); |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 309 | fuse_invalidate_attr(inode); /* atime changed */ |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 310 | out: |
| 311 | unlock_page(page); |
| 312 | return err; |
| 313 | } |
| 314 | |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 315 | static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_req *req) |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 316 | { |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 317 | int i; |
| 318 | |
| 319 | fuse_invalidate_attr(req->pages[0]->mapping->host); /* atime changed */ |
| 320 | |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 321 | for (i = 0; i < req->num_pages; i++) { |
| 322 | struct page *page = req->pages[i]; |
| 323 | if (!req->out.h.error) |
| 324 | SetPageUptodate(page); |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 325 | else |
| 326 | SetPageError(page); |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 327 | unlock_page(page); |
| 328 | } |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 329 | fuse_put_request(fc, req); |
| 330 | } |
| 331 | |
| 332 | static void fuse_send_readpages(struct fuse_req *req, struct file *file, |
| 333 | struct inode *inode) |
| 334 | { |
| 335 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 336 | loff_t pos = page_offset(req->pages[0]); |
| 337 | size_t count = req->num_pages << PAGE_CACHE_SHIFT; |
| 338 | req->out.page_zeroing = 1; |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 339 | fuse_read_fill(req, file, inode, pos, count, FUSE_READ); |
Miklos Szeredi | 9cd6845 | 2006-02-01 03:04:40 -0800 | [diff] [blame] | 340 | if (fc->async_read) { |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 341 | get_file(file); |
| 342 | req->file = file; |
Miklos Szeredi | 9cd6845 | 2006-02-01 03:04:40 -0800 | [diff] [blame] | 343 | req->end = fuse_readpages_end; |
| 344 | request_send_background(fc, req); |
| 345 | } else { |
| 346 | request_send(fc, req); |
| 347 | fuse_readpages_end(fc, req); |
| 348 | } |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | struct fuse_readpages_data { |
| 352 | struct fuse_req *req; |
| 353 | struct file *file; |
| 354 | struct inode *inode; |
| 355 | }; |
| 356 | |
| 357 | static int fuse_readpages_fill(void *_data, struct page *page) |
| 358 | { |
| 359 | struct fuse_readpages_data *data = _data; |
| 360 | struct fuse_req *req = data->req; |
| 361 | struct inode *inode = data->inode; |
| 362 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 363 | |
| 364 | if (req->num_pages && |
| 365 | (req->num_pages == FUSE_MAX_PAGES_PER_REQ || |
| 366 | (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read || |
| 367 | req->pages[req->num_pages - 1]->index + 1 != page->index)) { |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 368 | fuse_send_readpages(req, data->file, inode); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 369 | data->req = req = fuse_get_req(fc); |
| 370 | if (IS_ERR(req)) { |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 371 | unlock_page(page); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 372 | return PTR_ERR(req); |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 373 | } |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 374 | } |
| 375 | req->pages[req->num_pages] = page; |
| 376 | req->num_pages ++; |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | static int fuse_readpages(struct file *file, struct address_space *mapping, |
| 381 | struct list_head *pages, unsigned nr_pages) |
| 382 | { |
| 383 | struct inode *inode = mapping->host; |
| 384 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 385 | struct fuse_readpages_data data; |
| 386 | int err; |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 387 | |
| 388 | if (is_bad_inode(inode)) |
| 389 | return -EIO; |
| 390 | |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 391 | data.file = file; |
| 392 | data.inode = inode; |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 393 | data.req = fuse_get_req(fc); |
| 394 | if (IS_ERR(data.req)) |
| 395 | return PTR_ERR(data.req); |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 396 | |
| 397 | err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data); |
Miklos Szeredi | d3406ff | 2006-04-10 22:54:49 -0700 | [diff] [blame] | 398 | if (!err) { |
| 399 | if (data.req->num_pages) |
| 400 | fuse_send_readpages(data.req, file, inode); |
| 401 | else |
| 402 | fuse_put_request(fc, data.req); |
| 403 | } |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 404 | return err; |
| 405 | } |
| 406 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 407 | static size_t fuse_send_write(struct fuse_req *req, struct file *file, |
| 408 | struct inode *inode, loff_t pos, size_t count) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 409 | { |
| 410 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 411 | struct fuse_file *ff = file->private_data; |
| 412 | struct fuse_write_in inarg; |
| 413 | struct fuse_write_out outarg; |
| 414 | |
| 415 | memset(&inarg, 0, sizeof(struct fuse_write_in)); |
| 416 | inarg.fh = ff->fh; |
| 417 | inarg.offset = pos; |
| 418 | inarg.size = count; |
| 419 | req->in.h.opcode = FUSE_WRITE; |
| 420 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 421 | req->in.argpages = 1; |
| 422 | req->in.numargs = 2; |
| 423 | req->in.args[0].size = sizeof(struct fuse_write_in); |
| 424 | req->in.args[0].value = &inarg; |
| 425 | req->in.args[1].size = count; |
| 426 | req->out.numargs = 1; |
| 427 | req->out.args[0].size = sizeof(struct fuse_write_out); |
| 428 | req->out.args[0].value = &outarg; |
Miklos Szeredi | 7c352bd | 2005-09-09 13:10:39 -0700 | [diff] [blame] | 429 | request_send(fc, req); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 430 | return outarg.size; |
| 431 | } |
| 432 | |
| 433 | static int fuse_prepare_write(struct file *file, struct page *page, |
| 434 | unsigned offset, unsigned to) |
| 435 | { |
| 436 | /* No op */ |
| 437 | return 0; |
| 438 | } |
| 439 | |
| 440 | static int fuse_commit_write(struct file *file, struct page *page, |
| 441 | unsigned offset, unsigned to) |
| 442 | { |
| 443 | int err; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 444 | size_t nres; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 445 | unsigned count = to - offset; |
| 446 | struct inode *inode = page->mapping->host; |
| 447 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 4633a22 | 2006-01-06 00:19:36 -0800 | [diff] [blame] | 448 | loff_t pos = page_offset(page) + offset; |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 449 | struct fuse_req *req; |
| 450 | |
| 451 | if (is_bad_inode(inode)) |
| 452 | return -EIO; |
| 453 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 454 | req = fuse_get_req(fc); |
| 455 | if (IS_ERR(req)) |
| 456 | return PTR_ERR(req); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 457 | |
| 458 | req->num_pages = 1; |
| 459 | req->pages[0] = page; |
| 460 | req->page_offset = offset; |
| 461 | nres = fuse_send_write(req, file, inode, pos, count); |
| 462 | err = req->out.h.error; |
| 463 | fuse_put_request(fc, req); |
| 464 | if (!err && nres != count) |
| 465 | err = -EIO; |
| 466 | if (!err) { |
| 467 | pos += count; |
| 468 | if (pos > i_size_read(inode)) |
| 469 | i_size_write(inode, pos); |
| 470 | |
| 471 | if (offset == 0 && to == PAGE_CACHE_SIZE) { |
| 472 | clear_page_dirty(page); |
| 473 | SetPageUptodate(page); |
| 474 | } |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 475 | } |
| 476 | fuse_invalidate_attr(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 477 | return err; |
| 478 | } |
| 479 | |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 480 | static void fuse_release_user_pages(struct fuse_req *req, int write) |
| 481 | { |
| 482 | unsigned i; |
| 483 | |
| 484 | for (i = 0; i < req->num_pages; i++) { |
| 485 | struct page *page = req->pages[i]; |
| 486 | if (write) |
| 487 | set_page_dirty_lock(page); |
| 488 | put_page(page); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf, |
| 493 | unsigned nbytes, int write) |
| 494 | { |
| 495 | unsigned long user_addr = (unsigned long) buf; |
| 496 | unsigned offset = user_addr & ~PAGE_MASK; |
| 497 | int npages; |
| 498 | |
| 499 | /* This doesn't work with nfsd */ |
| 500 | if (!current->mm) |
| 501 | return -EPERM; |
| 502 | |
| 503 | nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT); |
| 504 | npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; |
Miklos Szeredi | 6ad84ac | 2006-01-06 00:19:42 -0800 | [diff] [blame] | 505 | npages = min(max(npages, 1), FUSE_MAX_PAGES_PER_REQ); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 506 | down_read(¤t->mm->mmap_sem); |
| 507 | npages = get_user_pages(current, current->mm, user_addr, npages, write, |
| 508 | 0, req->pages, NULL); |
| 509 | up_read(¤t->mm->mmap_sem); |
| 510 | if (npages < 0) |
| 511 | return npages; |
| 512 | |
| 513 | req->num_pages = npages; |
| 514 | req->page_offset = offset; |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static ssize_t fuse_direct_io(struct file *file, const char __user *buf, |
| 519 | size_t count, loff_t *ppos, int write) |
| 520 | { |
| 521 | struct inode *inode = file->f_dentry->d_inode; |
| 522 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 523 | size_t nmax = write ? fc->max_write : fc->max_read; |
| 524 | loff_t pos = *ppos; |
| 525 | ssize_t res = 0; |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 526 | struct fuse_req *req; |
| 527 | |
| 528 | if (is_bad_inode(inode)) |
| 529 | return -EIO; |
| 530 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 531 | req = fuse_get_req(fc); |
| 532 | if (IS_ERR(req)) |
| 533 | return PTR_ERR(req); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 534 | |
| 535 | while (count) { |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 536 | size_t nres; |
| 537 | size_t nbytes = min(count, nmax); |
| 538 | int err = fuse_get_user_pages(req, buf, nbytes, !write); |
| 539 | if (err) { |
| 540 | res = err; |
| 541 | break; |
| 542 | } |
Miklos Szeredi | 6ad84ac | 2006-01-06 00:19:42 -0800 | [diff] [blame] | 543 | nbytes = (req->num_pages << PAGE_SHIFT) - req->page_offset; |
| 544 | nbytes = min(count, nbytes); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 545 | if (write) |
| 546 | nres = fuse_send_write(req, file, inode, pos, nbytes); |
| 547 | else |
| 548 | nres = fuse_send_read(req, file, inode, pos, nbytes); |
| 549 | fuse_release_user_pages(req, !write); |
| 550 | if (req->out.h.error) { |
| 551 | if (!res) |
| 552 | res = req->out.h.error; |
| 553 | break; |
| 554 | } else if (nres > nbytes) { |
| 555 | res = -EIO; |
| 556 | break; |
| 557 | } |
| 558 | count -= nres; |
| 559 | res += nres; |
| 560 | pos += nres; |
| 561 | buf += nres; |
| 562 | if (nres != nbytes) |
| 563 | break; |
Miklos Szeredi | 56cf34f | 2006-04-11 21:16:51 +0200 | [diff] [blame] | 564 | if (count) { |
| 565 | fuse_put_request(fc, req); |
| 566 | req = fuse_get_req(fc); |
| 567 | if (IS_ERR(req)) |
| 568 | break; |
| 569 | } |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 570 | } |
| 571 | fuse_put_request(fc, req); |
| 572 | if (res > 0) { |
| 573 | if (write && pos > i_size_read(inode)) |
| 574 | i_size_write(inode, pos); |
| 575 | *ppos = pos; |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 576 | } |
| 577 | fuse_invalidate_attr(inode); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 578 | |
| 579 | return res; |
| 580 | } |
| 581 | |
| 582 | static ssize_t fuse_direct_read(struct file *file, char __user *buf, |
| 583 | size_t count, loff_t *ppos) |
| 584 | { |
| 585 | return fuse_direct_io(file, buf, count, ppos, 0); |
| 586 | } |
| 587 | |
| 588 | static ssize_t fuse_direct_write(struct file *file, const char __user *buf, |
| 589 | size_t count, loff_t *ppos) |
| 590 | { |
| 591 | struct inode *inode = file->f_dentry->d_inode; |
| 592 | ssize_t res; |
| 593 | /* Don't allow parallel writes to the same file */ |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 594 | mutex_lock(&inode->i_mutex); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 595 | res = fuse_direct_io(file, buf, count, ppos, 1); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 596 | mutex_unlock(&inode->i_mutex); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 597 | return res; |
| 598 | } |
| 599 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 600 | static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) |
| 601 | { |
| 602 | if ((vma->vm_flags & VM_SHARED)) { |
| 603 | if ((vma->vm_flags & VM_WRITE)) |
| 604 | return -ENODEV; |
| 605 | else |
| 606 | vma->vm_flags &= ~VM_MAYWRITE; |
| 607 | } |
| 608 | return generic_file_mmap(file, vma); |
| 609 | } |
| 610 | |
| 611 | static int fuse_set_page_dirty(struct page *page) |
| 612 | { |
| 613 | printk("fuse_set_page_dirty: should not happen\n"); |
| 614 | dump_stack(); |
| 615 | return 0; |
| 616 | } |
| 617 | |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 618 | static int convert_fuse_file_lock(const struct fuse_file_lock *ffl, |
| 619 | struct file_lock *fl) |
| 620 | { |
| 621 | switch (ffl->type) { |
| 622 | case F_UNLCK: |
| 623 | break; |
| 624 | |
| 625 | case F_RDLCK: |
| 626 | case F_WRLCK: |
| 627 | if (ffl->start > OFFSET_MAX || ffl->end > OFFSET_MAX || |
| 628 | ffl->end < ffl->start) |
| 629 | return -EIO; |
| 630 | |
| 631 | fl->fl_start = ffl->start; |
| 632 | fl->fl_end = ffl->end; |
| 633 | fl->fl_pid = ffl->pid; |
| 634 | break; |
| 635 | |
| 636 | default: |
| 637 | return -EIO; |
| 638 | } |
| 639 | fl->fl_type = ffl->type; |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | static void fuse_lk_fill(struct fuse_req *req, struct file *file, |
| 644 | const struct file_lock *fl, int opcode, pid_t pid) |
| 645 | { |
| 646 | struct inode *inode = file->f_dentry->d_inode; |
| 647 | struct fuse_file *ff = file->private_data; |
| 648 | struct fuse_lk_in *arg = &req->misc.lk_in; |
| 649 | |
| 650 | arg->fh = ff->fh; |
| 651 | arg->owner = fuse_lock_owner_id(fl->fl_owner); |
| 652 | arg->lk.start = fl->fl_start; |
| 653 | arg->lk.end = fl->fl_end; |
| 654 | arg->lk.type = fl->fl_type; |
| 655 | arg->lk.pid = pid; |
| 656 | req->in.h.opcode = opcode; |
| 657 | req->in.h.nodeid = get_node_id(inode); |
| 658 | req->in.numargs = 1; |
| 659 | req->in.args[0].size = sizeof(*arg); |
| 660 | req->in.args[0].value = arg; |
| 661 | } |
| 662 | |
| 663 | static int fuse_getlk(struct file *file, struct file_lock *fl) |
| 664 | { |
| 665 | struct inode *inode = file->f_dentry->d_inode; |
| 666 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 667 | struct fuse_req *req; |
| 668 | struct fuse_lk_out outarg; |
| 669 | int err; |
| 670 | |
| 671 | req = fuse_get_req(fc); |
| 672 | if (IS_ERR(req)) |
| 673 | return PTR_ERR(req); |
| 674 | |
| 675 | fuse_lk_fill(req, file, fl, FUSE_GETLK, 0); |
| 676 | req->out.numargs = 1; |
| 677 | req->out.args[0].size = sizeof(outarg); |
| 678 | req->out.args[0].value = &outarg; |
| 679 | request_send(fc, req); |
| 680 | err = req->out.h.error; |
| 681 | fuse_put_request(fc, req); |
| 682 | if (!err) |
| 683 | err = convert_fuse_file_lock(&outarg.lk, fl); |
| 684 | |
| 685 | return err; |
| 686 | } |
| 687 | |
| 688 | static int fuse_setlk(struct file *file, struct file_lock *fl) |
| 689 | { |
| 690 | struct inode *inode = file->f_dentry->d_inode; |
| 691 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 692 | struct fuse_req *req; |
| 693 | int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK; |
| 694 | pid_t pid = fl->fl_type != F_UNLCK ? current->tgid : 0; |
| 695 | int err; |
| 696 | |
| 697 | /* Unlock on close is handled by the flush method */ |
| 698 | if (fl->fl_flags & FL_CLOSE) |
| 699 | return 0; |
| 700 | |
| 701 | req = fuse_get_req(fc); |
| 702 | if (IS_ERR(req)) |
| 703 | return PTR_ERR(req); |
| 704 | |
| 705 | fuse_lk_fill(req, file, fl, opcode, pid); |
| 706 | request_send(fc, req); |
| 707 | err = req->out.h.error; |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame^] | 708 | /* locking is restartable */ |
| 709 | if (err == -EINTR) |
| 710 | err = -ERESTARTSYS; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 711 | fuse_put_request(fc, req); |
| 712 | return err; |
| 713 | } |
| 714 | |
| 715 | static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl) |
| 716 | { |
| 717 | struct inode *inode = file->f_dentry->d_inode; |
| 718 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 719 | int err; |
| 720 | |
| 721 | if (cmd == F_GETLK) { |
| 722 | if (fc->no_lock) { |
| 723 | if (!posix_test_lock(file, fl, fl)) |
| 724 | fl->fl_type = F_UNLCK; |
| 725 | err = 0; |
| 726 | } else |
| 727 | err = fuse_getlk(file, fl); |
| 728 | } else { |
| 729 | if (fc->no_lock) |
| 730 | err = posix_lock_file_wait(file, fl); |
| 731 | else |
| 732 | err = fuse_setlk(file, fl); |
| 733 | } |
| 734 | return err; |
| 735 | } |
| 736 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 737 | static const struct file_operations fuse_file_operations = { |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 738 | .llseek = generic_file_llseek, |
| 739 | .read = generic_file_read, |
| 740 | .write = generic_file_write, |
| 741 | .mmap = fuse_file_mmap, |
| 742 | .open = fuse_open, |
| 743 | .flush = fuse_flush, |
| 744 | .release = fuse_release, |
| 745 | .fsync = fuse_fsync, |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 746 | .lock = fuse_file_lock, |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 747 | .sendfile = generic_file_sendfile, |
| 748 | }; |
| 749 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 750 | static const struct file_operations fuse_direct_io_file_operations = { |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 751 | .llseek = generic_file_llseek, |
| 752 | .read = fuse_direct_read, |
| 753 | .write = fuse_direct_write, |
| 754 | .open = fuse_open, |
| 755 | .flush = fuse_flush, |
| 756 | .release = fuse_release, |
| 757 | .fsync = fuse_fsync, |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 758 | .lock = fuse_file_lock, |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 759 | /* no mmap and sendfile */ |
| 760 | }; |
| 761 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 762 | static struct address_space_operations fuse_file_aops = { |
| 763 | .readpage = fuse_readpage, |
| 764 | .prepare_write = fuse_prepare_write, |
| 765 | .commit_write = fuse_commit_write, |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 766 | .readpages = fuse_readpages, |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 767 | .set_page_dirty = fuse_set_page_dirty, |
| 768 | }; |
| 769 | |
| 770 | void fuse_init_file_inode(struct inode *inode) |
| 771 | { |
Miklos Szeredi | 45323fb | 2005-09-09 13:10:37 -0700 | [diff] [blame] | 772 | inode->i_fop = &fuse_file_operations; |
| 773 | inode->i_data.a_ops = &fuse_file_aops; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 774 | } |