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> |
Alexey Dobriyan | e8edc6e | 2007-05-21 01:22:52 +0400 | [diff] [blame] | 14 | #include <linux/sched.h> |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 15 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 16 | static const struct file_operations fuse_direct_io_file_operations; |
Miklos Szeredi | 45323fb | 2005-09-09 13:10:37 -0700 | [diff] [blame] | 17 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 18 | static int fuse_send_open(struct inode *inode, struct file *file, int isdir, |
| 19 | struct fuse_open_out *outargp) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 20 | { |
| 21 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 22 | struct fuse_open_in inarg; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 23 | struct fuse_req *req; |
| 24 | int err; |
| 25 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 26 | req = fuse_get_req(fc); |
| 27 | if (IS_ERR(req)) |
| 28 | return PTR_ERR(req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 29 | |
| 30 | memset(&inarg, 0, sizeof(inarg)); |
Miklos Szeredi | 6ff958e | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 31 | inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY); |
| 32 | if (!fc->atomic_o_trunc) |
| 33 | inarg.flags &= ~O_TRUNC; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 34 | req->in.h.opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN; |
| 35 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 36 | req->in.numargs = 1; |
| 37 | req->in.args[0].size = sizeof(inarg); |
| 38 | req->in.args[0].value = &inarg; |
| 39 | req->out.numargs = 1; |
| 40 | req->out.args[0].size = sizeof(*outargp); |
| 41 | req->out.args[0].value = outargp; |
| 42 | request_send(fc, req); |
| 43 | err = req->out.h.error; |
| 44 | fuse_put_request(fc, req); |
| 45 | |
| 46 | return err; |
| 47 | } |
| 48 | |
| 49 | struct fuse_file *fuse_file_alloc(void) |
| 50 | { |
| 51 | struct fuse_file *ff; |
| 52 | ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL); |
| 53 | if (ff) { |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 54 | ff->reserved_req = fuse_request_alloc(); |
| 55 | if (!ff->reserved_req) { |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 56 | kfree(ff); |
| 57 | ff = NULL; |
Adrian Bunk | 8744969 | 2007-11-14 17:00:02 -0800 | [diff] [blame] | 58 | } else { |
| 59 | INIT_LIST_HEAD(&ff->write_entry); |
| 60 | atomic_set(&ff->count, 0); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | return ff; |
| 64 | } |
| 65 | |
| 66 | void fuse_file_free(struct fuse_file *ff) |
| 67 | { |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 68 | fuse_request_free(ff->reserved_req); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 69 | kfree(ff); |
| 70 | } |
| 71 | |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 72 | static struct fuse_file *fuse_file_get(struct fuse_file *ff) |
| 73 | { |
| 74 | atomic_inc(&ff->count); |
| 75 | return ff; |
| 76 | } |
| 77 | |
Miklos Szeredi | 819c4b3 | 2007-10-16 23:31:04 -0700 | [diff] [blame] | 78 | static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req) |
| 79 | { |
Miklos Szeredi | b57d426 | 2008-02-06 01:38:39 -0800 | [diff] [blame] | 80 | dput(req->misc.release.dentry); |
| 81 | mntput(req->misc.release.vfsmount); |
Miklos Szeredi | 819c4b3 | 2007-10-16 23:31:04 -0700 | [diff] [blame] | 82 | fuse_put_request(fc, req); |
| 83 | } |
| 84 | |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 85 | static void fuse_file_put(struct fuse_file *ff) |
| 86 | { |
| 87 | if (atomic_dec_and_test(&ff->count)) { |
| 88 | struct fuse_req *req = ff->reserved_req; |
Miklos Szeredi | b57d426 | 2008-02-06 01:38:39 -0800 | [diff] [blame] | 89 | struct inode *inode = req->misc.release.dentry->d_inode; |
| 90 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 819c4b3 | 2007-10-16 23:31:04 -0700 | [diff] [blame] | 91 | req->end = fuse_release_end; |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 92 | request_send_background(fc, req); |
| 93 | kfree(ff); |
| 94 | } |
| 95 | } |
| 96 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 97 | void fuse_finish_open(struct inode *inode, struct file *file, |
| 98 | struct fuse_file *ff, struct fuse_open_out *outarg) |
| 99 | { |
| 100 | if (outarg->open_flags & FOPEN_DIRECT_IO) |
| 101 | file->f_op = &fuse_direct_io_file_operations; |
| 102 | if (!(outarg->open_flags & FOPEN_KEEP_CACHE)) |
Miklos Szeredi | b100997 | 2007-10-16 23:31:01 -0700 | [diff] [blame] | 103 | invalidate_inode_pages2(inode->i_mapping); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 104 | ff->fh = outarg->fh; |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 105 | file->private_data = fuse_file_get(ff); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | int fuse_open_common(struct inode *inode, struct file *file, int isdir) |
| 109 | { |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 110 | struct fuse_open_out outarg; |
| 111 | struct fuse_file *ff; |
| 112 | int err; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 113 | |
Miklos Szeredi | dd190d0 | 2005-09-30 11:59:02 -0700 | [diff] [blame] | 114 | /* VFS checks this, but only _after_ ->open() */ |
| 115 | if (file->f_flags & O_DIRECT) |
| 116 | return -EINVAL; |
| 117 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 118 | err = generic_file_open(inode, file); |
| 119 | if (err) |
| 120 | return err; |
| 121 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 122 | ff = fuse_file_alloc(); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 123 | if (!ff) |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 124 | return -ENOMEM; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 125 | |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 126 | err = fuse_send_open(inode, file, isdir, &outarg); |
| 127 | if (err) |
| 128 | fuse_file_free(ff); |
| 129 | else { |
| 130 | if (isdir) |
| 131 | outarg.open_flags &= ~FOPEN_DIRECT_IO; |
| 132 | fuse_finish_open(inode, file, ff, &outarg); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 135 | return err; |
| 136 | } |
| 137 | |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 138 | void fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags, int opcode) |
Miklos Szeredi | 64c6d8e | 2006-01-16 22:14:42 -0800 | [diff] [blame] | 139 | { |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 140 | struct fuse_req *req = ff->reserved_req; |
Miklos Szeredi | b57d426 | 2008-02-06 01:38:39 -0800 | [diff] [blame] | 141 | struct fuse_release_in *inarg = &req->misc.release.in; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 142 | |
| 143 | inarg->fh = ff->fh; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 144 | inarg->flags = flags; |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 145 | req->in.h.opcode = opcode; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 146 | req->in.h.nodeid = nodeid; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 147 | req->in.numargs = 1; |
| 148 | req->in.args[0].size = sizeof(struct fuse_release_in); |
| 149 | req->in.args[0].value = inarg; |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | int fuse_release_common(struct inode *inode, struct file *file, int isdir) |
| 153 | { |
| 154 | struct fuse_file *ff = file->private_data; |
| 155 | if (ff) { |
Miklos Szeredi | 93a8c3c | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 156 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | b57d426 | 2008-02-06 01:38:39 -0800 | [diff] [blame] | 157 | struct fuse_req *req = ff->reserved_req; |
Miklos Szeredi | 93a8c3c | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 158 | |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 159 | fuse_release_fill(ff, get_node_id(inode), file->f_flags, |
| 160 | isdir ? FUSE_RELEASEDIR : FUSE_RELEASE); |
Miklos Szeredi | 51eb01e | 2006-06-25 05:48:50 -0700 | [diff] [blame] | 161 | |
| 162 | /* Hold vfsmount and dentry until release is finished */ |
Miklos Szeredi | b57d426 | 2008-02-06 01:38:39 -0800 | [diff] [blame] | 163 | req->misc.release.vfsmount = mntget(file->f_path.mnt); |
| 164 | req->misc.release.dentry = dget(file->f_path.dentry); |
Miklos Szeredi | 93a8c3c | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 165 | |
| 166 | spin_lock(&fc->lock); |
| 167 | list_del(&ff->write_entry); |
| 168 | spin_unlock(&fc->lock); |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 169 | /* |
| 170 | * Normally this will send the RELEASE request, |
| 171 | * however if some asynchronous READ or WRITE requests |
| 172 | * are outstanding, the sending will be delayed |
| 173 | */ |
| 174 | fuse_file_put(ff); |
Miklos Szeredi | fd72faa | 2005-11-07 00:59:51 -0800 | [diff] [blame] | 175 | } |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 176 | |
| 177 | /* Return value is ignored by VFS */ |
| 178 | return 0; |
| 179 | } |
| 180 | |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 181 | static int fuse_open(struct inode *inode, struct file *file) |
| 182 | { |
| 183 | return fuse_open_common(inode, file, 0); |
| 184 | } |
| 185 | |
| 186 | static int fuse_release(struct inode *inode, struct file *file) |
| 187 | { |
| 188 | return fuse_release_common(inode, file, 0); |
| 189 | } |
| 190 | |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 191 | /* |
Miklos Szeredi | 9c8ef56 | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 192 | * Scramble the ID space with XTEA, so that the value of the files_struct |
| 193 | * pointer is not exposed to userspace. |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 194 | */ |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 195 | u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id) |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 196 | { |
Miklos Szeredi | 9c8ef56 | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 197 | u32 *k = fc->scramble_key; |
| 198 | u64 v = (unsigned long) id; |
| 199 | u32 v0 = v; |
| 200 | u32 v1 = v >> 32; |
| 201 | u32 sum = 0; |
| 202 | int i; |
| 203 | |
| 204 | for (i = 0; i < 32; i++) { |
| 205 | v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]); |
| 206 | sum += 0x9E3779B9; |
| 207 | v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]); |
| 208 | } |
| 209 | |
| 210 | return (u64) v0 + ((u64) v1 << 32); |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Miklos Szeredi | 75e1fcc | 2006-06-23 02:05:12 -0700 | [diff] [blame] | 213 | static int fuse_flush(struct file *file, fl_owner_t id) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 214 | { |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 215 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 216 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 217 | struct fuse_file *ff = file->private_data; |
| 218 | struct fuse_req *req; |
| 219 | struct fuse_flush_in inarg; |
| 220 | int err; |
| 221 | |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 222 | if (is_bad_inode(inode)) |
| 223 | return -EIO; |
| 224 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 225 | if (fc->no_flush) |
| 226 | return 0; |
| 227 | |
Miklos Szeredi | 33649c9 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 228 | req = fuse_get_req_nofail(fc, file); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 229 | memset(&inarg, 0, sizeof(inarg)); |
| 230 | inarg.fh = ff->fh; |
Miklos Szeredi | 9c8ef56 | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 231 | inarg.lock_owner = fuse_lock_owner_id(fc, id); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 232 | req->in.h.opcode = FUSE_FLUSH; |
| 233 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 234 | req->in.numargs = 1; |
| 235 | req->in.args[0].size = sizeof(inarg); |
| 236 | req->in.args[0].value = &inarg; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 237 | req->force = 1; |
Miklos Szeredi | 7c352bd | 2005-09-09 13:10:39 -0700 | [diff] [blame] | 238 | request_send(fc, req); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 239 | err = req->out.h.error; |
| 240 | fuse_put_request(fc, req); |
| 241 | if (err == -ENOSYS) { |
| 242 | fc->no_flush = 1; |
| 243 | err = 0; |
| 244 | } |
| 245 | return err; |
| 246 | } |
| 247 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 248 | int fuse_fsync_common(struct file *file, struct dentry *de, int datasync, |
| 249 | int isdir) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 250 | { |
| 251 | struct inode *inode = de->d_inode; |
| 252 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 253 | struct fuse_file *ff = file->private_data; |
| 254 | struct fuse_req *req; |
| 255 | struct fuse_fsync_in inarg; |
| 256 | int err; |
| 257 | |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 258 | if (is_bad_inode(inode)) |
| 259 | return -EIO; |
| 260 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 261 | if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir)) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 262 | return 0; |
| 263 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 264 | req = fuse_get_req(fc); |
| 265 | if (IS_ERR(req)) |
| 266 | return PTR_ERR(req); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 267 | |
| 268 | memset(&inarg, 0, sizeof(inarg)); |
| 269 | inarg.fh = ff->fh; |
| 270 | inarg.fsync_flags = datasync ? 1 : 0; |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 271 | req->in.h.opcode = isdir ? FUSE_FSYNCDIR : FUSE_FSYNC; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 272 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 273 | req->in.numargs = 1; |
| 274 | req->in.args[0].size = sizeof(inarg); |
| 275 | req->in.args[0].value = &inarg; |
| 276 | request_send(fc, req); |
| 277 | err = req->out.h.error; |
| 278 | fuse_put_request(fc, req); |
| 279 | if (err == -ENOSYS) { |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 280 | if (isdir) |
| 281 | fc->no_fsyncdir = 1; |
| 282 | else |
| 283 | fc->no_fsync = 1; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 284 | err = 0; |
| 285 | } |
| 286 | return err; |
| 287 | } |
| 288 | |
Miklos Szeredi | 8254798 | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 289 | static int fuse_fsync(struct file *file, struct dentry *de, int datasync) |
| 290 | { |
| 291 | return fuse_fsync_common(file, de, datasync, 0); |
| 292 | } |
| 293 | |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 294 | void fuse_read_fill(struct fuse_req *req, struct file *file, |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 295 | struct inode *inode, loff_t pos, size_t count, int opcode) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 296 | { |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 297 | struct fuse_read_in *inarg = &req->misc.read_in; |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 298 | struct fuse_file *ff = file->private_data; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 299 | |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 300 | inarg->fh = ff->fh; |
| 301 | inarg->offset = pos; |
| 302 | inarg->size = count; |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 303 | inarg->flags = file->f_flags; |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 304 | req->in.h.opcode = opcode; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 305 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 306 | req->in.numargs = 1; |
| 307 | req->in.args[0].size = sizeof(struct fuse_read_in); |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 308 | req->in.args[0].value = inarg; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 309 | req->out.argpages = 1; |
| 310 | req->out.argvar = 1; |
| 311 | req->out.numargs = 1; |
| 312 | req->out.args[0].size = count; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Miklos Szeredi | 8bfc016 | 2006-01-16 22:14:28 -0800 | [diff] [blame] | 315 | static size_t fuse_send_read(struct fuse_req *req, struct file *file, |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 316 | struct inode *inode, loff_t pos, size_t count, |
| 317 | fl_owner_t owner) |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 318 | { |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 319 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 320 | |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 321 | fuse_read_fill(req, file, inode, pos, count, FUSE_READ); |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 322 | if (owner != NULL) { |
| 323 | struct fuse_read_in *inarg = &req->misc.read_in; |
| 324 | |
| 325 | inarg->read_flags |= FUSE_READ_LOCKOWNER; |
| 326 | inarg->lock_owner = fuse_lock_owner_id(fc, owner); |
| 327 | } |
Miklos Szeredi | 361b1eb5 | 2006-01-16 22:14:45 -0800 | [diff] [blame] | 328 | request_send(fc, req); |
| 329 | return req->out.args[0].size; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 332 | static int fuse_readpage(struct file *file, struct page *page) |
| 333 | { |
| 334 | struct inode *inode = page->mapping->host; |
| 335 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 336 | struct fuse_req *req; |
| 337 | int err; |
| 338 | |
| 339 | err = -EIO; |
| 340 | if (is_bad_inode(inode)) |
| 341 | goto out; |
| 342 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 343 | req = fuse_get_req(fc); |
| 344 | err = PTR_ERR(req); |
| 345 | if (IS_ERR(req)) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 346 | goto out; |
| 347 | |
| 348 | req->out.page_zeroing = 1; |
| 349 | req->num_pages = 1; |
| 350 | req->pages[0] = page; |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 351 | fuse_send_read(req, file, inode, page_offset(page), PAGE_CACHE_SIZE, |
| 352 | NULL); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 353 | err = req->out.h.error; |
| 354 | fuse_put_request(fc, req); |
| 355 | if (!err) |
| 356 | SetPageUptodate(page); |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 357 | fuse_invalidate_attr(inode); /* atime changed */ |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 358 | out: |
| 359 | unlock_page(page); |
| 360 | return err; |
| 361 | } |
| 362 | |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 363 | 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] | 364 | { |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 365 | int i; |
| 366 | |
| 367 | fuse_invalidate_attr(req->pages[0]->mapping->host); /* atime changed */ |
| 368 | |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 369 | for (i = 0; i < req->num_pages; i++) { |
| 370 | struct page *page = req->pages[i]; |
| 371 | if (!req->out.h.error) |
| 372 | SetPageUptodate(page); |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 373 | else |
| 374 | SetPageError(page); |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 375 | unlock_page(page); |
| 376 | } |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 377 | if (req->ff) |
| 378 | fuse_file_put(req->ff); |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 379 | fuse_put_request(fc, req); |
| 380 | } |
| 381 | |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 382 | static void fuse_send_readpages(struct fuse_req *req, struct file *file, |
Miklos Szeredi | c1aa96a | 2006-01-16 22:14:46 -0800 | [diff] [blame] | 383 | struct inode *inode) |
| 384 | { |
| 385 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 386 | loff_t pos = page_offset(req->pages[0]); |
| 387 | size_t count = req->num_pages << PAGE_CACHE_SHIFT; |
| 388 | req->out.page_zeroing = 1; |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 389 | fuse_read_fill(req, file, inode, pos, count, FUSE_READ); |
Miklos Szeredi | 9cd6845 | 2006-02-01 03:04:40 -0800 | [diff] [blame] | 390 | if (fc->async_read) { |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 391 | struct fuse_file *ff = file->private_data; |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 392 | req->ff = fuse_file_get(ff); |
Miklos Szeredi | 9cd6845 | 2006-02-01 03:04:40 -0800 | [diff] [blame] | 393 | req->end = fuse_readpages_end; |
| 394 | request_send_background(fc, req); |
| 395 | } else { |
| 396 | request_send(fc, req); |
| 397 | fuse_readpages_end(fc, req); |
| 398 | } |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 401 | struct fuse_fill_data { |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 402 | struct fuse_req *req; |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 403 | struct file *file; |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 404 | struct inode *inode; |
| 405 | }; |
| 406 | |
| 407 | static int fuse_readpages_fill(void *_data, struct page *page) |
| 408 | { |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 409 | struct fuse_fill_data *data = _data; |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 410 | struct fuse_req *req = data->req; |
| 411 | struct inode *inode = data->inode; |
| 412 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 413 | |
| 414 | if (req->num_pages && |
| 415 | (req->num_pages == FUSE_MAX_PAGES_PER_REQ || |
| 416 | (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read || |
| 417 | req->pages[req->num_pages - 1]->index + 1 != page->index)) { |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 418 | fuse_send_readpages(req, data->file, inode); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 419 | data->req = req = fuse_get_req(fc); |
| 420 | if (IS_ERR(req)) { |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 421 | unlock_page(page); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 422 | return PTR_ERR(req); |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 423 | } |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 424 | } |
| 425 | req->pages[req->num_pages] = page; |
| 426 | req->num_pages ++; |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static int fuse_readpages(struct file *file, struct address_space *mapping, |
| 431 | struct list_head *pages, unsigned nr_pages) |
| 432 | { |
| 433 | struct inode *inode = mapping->host; |
| 434 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | c756e0a | 2007-10-16 23:31:00 -0700 | [diff] [blame] | 435 | struct fuse_fill_data data; |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 436 | int err; |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 437 | |
Alexander Zarochentsev | 1d7ea73 | 2006-08-13 23:24:27 -0700 | [diff] [blame] | 438 | err = -EIO; |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 439 | if (is_bad_inode(inode)) |
OGAWA Hirofumi | 2e99002 | 2006-11-02 22:07:09 -0800 | [diff] [blame] | 440 | goto out; |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 441 | |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 442 | data.file = file; |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 443 | data.inode = inode; |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 444 | data.req = fuse_get_req(fc); |
Alexander Zarochentsev | 1d7ea73 | 2006-08-13 23:24:27 -0700 | [diff] [blame] | 445 | err = PTR_ERR(data.req); |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 446 | if (IS_ERR(data.req)) |
OGAWA Hirofumi | 2e99002 | 2006-11-02 22:07:09 -0800 | [diff] [blame] | 447 | goto out; |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 448 | |
| 449 | err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data); |
Miklos Szeredi | d3406ff | 2006-04-10 22:54:49 -0700 | [diff] [blame] | 450 | if (!err) { |
| 451 | if (data.req->num_pages) |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 452 | fuse_send_readpages(data.req, file, inode); |
Miklos Szeredi | d3406ff | 2006-04-10 22:54:49 -0700 | [diff] [blame] | 453 | else |
| 454 | fuse_put_request(fc, data.req); |
| 455 | } |
OGAWA Hirofumi | 2e99002 | 2006-11-02 22:07:09 -0800 | [diff] [blame] | 456 | out: |
Alexander Zarochentsev | 1d7ea73 | 2006-08-13 23:24:27 -0700 | [diff] [blame] | 457 | return err; |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Miklos Szeredi | bcb4be8 | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 460 | static ssize_t fuse_file_aio_read(struct kiocb *iocb, const struct iovec *iov, |
| 461 | unsigned long nr_segs, loff_t pos) |
| 462 | { |
| 463 | struct inode *inode = iocb->ki_filp->f_mapping->host; |
| 464 | |
| 465 | if (pos + iov_length(iov, nr_segs) > i_size_read(inode)) { |
| 466 | int err; |
| 467 | /* |
| 468 | * If trying to read past EOF, make sure the i_size |
| 469 | * attribute is up-to-date. |
| 470 | */ |
| 471 | err = fuse_update_attributes(inode, NULL, iocb->ki_filp, NULL); |
| 472 | if (err) |
| 473 | return err; |
| 474 | } |
| 475 | |
| 476 | return generic_file_aio_read(iocb, iov, nr_segs, pos); |
| 477 | } |
| 478 | |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 479 | static void fuse_write_fill(struct fuse_req *req, struct file *file, |
Miklos Szeredi | b25e82e | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 480 | struct inode *inode, loff_t pos, size_t count, |
| 481 | int writepage) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 482 | { |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 483 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 484 | struct fuse_file *ff = file->private_data; |
Miklos Szeredi | b25e82e | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 485 | struct fuse_write_in *inarg = &req->misc.write.in; |
| 486 | struct fuse_write_out *outarg = &req->misc.write.out; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 487 | |
Miklos Szeredi | b25e82e | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 488 | memset(inarg, 0, sizeof(struct fuse_write_in)); |
| 489 | inarg->fh = ff->fh; |
| 490 | inarg->offset = pos; |
| 491 | inarg->size = count; |
| 492 | inarg->write_flags = writepage ? FUSE_WRITE_CACHE : 0; |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 493 | inarg->flags = file->f_flags; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 494 | req->in.h.opcode = FUSE_WRITE; |
| 495 | req->in.h.nodeid = get_node_id(inode); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 496 | req->in.argpages = 1; |
| 497 | req->in.numargs = 2; |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 498 | if (fc->minor < 9) |
| 499 | req->in.args[0].size = FUSE_COMPAT_WRITE_IN_SIZE; |
| 500 | else |
| 501 | req->in.args[0].size = sizeof(struct fuse_write_in); |
Miklos Szeredi | b25e82e | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 502 | req->in.args[0].value = inarg; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 503 | req->in.args[1].size = count; |
| 504 | req->out.numargs = 1; |
| 505 | req->out.args[0].size = sizeof(struct fuse_write_out); |
Miklos Szeredi | b25e82e | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 506 | req->out.args[0].value = outarg; |
| 507 | } |
| 508 | |
| 509 | static size_t fuse_send_write(struct fuse_req *req, struct file *file, |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 510 | struct inode *inode, loff_t pos, size_t count, |
| 511 | fl_owner_t owner) |
Miklos Szeredi | b25e82e | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 512 | { |
| 513 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | a664309 | 2007-11-28 16:22:00 -0800 | [diff] [blame] | 514 | fuse_write_fill(req, file, inode, pos, count, 0); |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 515 | if (owner != NULL) { |
| 516 | struct fuse_write_in *inarg = &req->misc.write.in; |
| 517 | inarg->write_flags |= FUSE_WRITE_LOCKOWNER; |
| 518 | inarg->lock_owner = fuse_lock_owner_id(fc, owner); |
| 519 | } |
Miklos Szeredi | 7c352bd | 2005-09-09 13:10:39 -0700 | [diff] [blame] | 520 | request_send(fc, req); |
Miklos Szeredi | b25e82e | 2007-10-18 03:07:03 -0700 | [diff] [blame] | 521 | return req->misc.write.out.size; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 524 | static int fuse_write_begin(struct file *file, struct address_space *mapping, |
| 525 | loff_t pos, unsigned len, unsigned flags, |
| 526 | struct page **pagep, void **fsdata) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 527 | { |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 528 | pgoff_t index = pos >> PAGE_CACHE_SHIFT; |
| 529 | |
| 530 | *pagep = __grab_cache_page(mapping, index); |
| 531 | if (!*pagep) |
| 532 | return -ENOMEM; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 533 | return 0; |
| 534 | } |
| 535 | |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 536 | static int fuse_buffered_write(struct file *file, struct inode *inode, |
| 537 | loff_t pos, unsigned count, struct page *page) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 538 | { |
| 539 | int err; |
Miklos Szeredi | 04730fe | 2005-09-09 13:10:36 -0700 | [diff] [blame] | 540 | size_t nres; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 541 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 542 | struct fuse_inode *fi = get_fuse_inode(inode); |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 543 | unsigned offset = pos & (PAGE_CACHE_SIZE - 1); |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 544 | struct fuse_req *req; |
| 545 | |
| 546 | if (is_bad_inode(inode)) |
| 547 | return -EIO; |
| 548 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 549 | req = fuse_get_req(fc); |
| 550 | if (IS_ERR(req)) |
| 551 | return PTR_ERR(req); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 552 | |
| 553 | req->num_pages = 1; |
| 554 | req->pages[0] = page; |
| 555 | req->page_offset = offset; |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 556 | nres = fuse_send_write(req, file, inode, pos, count, NULL); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 557 | err = req->out.h.error; |
| 558 | fuse_put_request(fc, req); |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 559 | if (!err && !nres) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 560 | err = -EIO; |
| 561 | if (!err) { |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 562 | pos += nres; |
Miklos Szeredi | 9ffbb91 | 2006-10-17 00:10:06 -0700 | [diff] [blame] | 563 | spin_lock(&fc->lock); |
Miklos Szeredi | 1fb69e7 | 2007-10-18 03:06:58 -0700 | [diff] [blame] | 564 | fi->attr_version = ++fc->attr_version; |
Miklos Szeredi | 9ffbb91 | 2006-10-17 00:10:06 -0700 | [diff] [blame] | 565 | if (pos > inode->i_size) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 566 | i_size_write(inode, pos); |
Miklos Szeredi | 9ffbb91 | 2006-10-17 00:10:06 -0700 | [diff] [blame] | 567 | spin_unlock(&fc->lock); |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 568 | |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 569 | if (count == PAGE_CACHE_SIZE) |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 570 | SetPageUptodate(page); |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 571 | } |
| 572 | fuse_invalidate_attr(inode); |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 573 | return err ? err : nres; |
| 574 | } |
| 575 | |
| 576 | static int fuse_write_end(struct file *file, struct address_space *mapping, |
| 577 | loff_t pos, unsigned len, unsigned copied, |
| 578 | struct page *page, void *fsdata) |
| 579 | { |
| 580 | struct inode *inode = mapping->host; |
| 581 | int res = 0; |
| 582 | |
| 583 | if (copied) |
| 584 | res = fuse_buffered_write(file, inode, pos, copied, page); |
| 585 | |
| 586 | unlock_page(page); |
| 587 | page_cache_release(page); |
| 588 | return res; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 591 | static void fuse_release_user_pages(struct fuse_req *req, int write) |
| 592 | { |
| 593 | unsigned i; |
| 594 | |
| 595 | for (i = 0; i < req->num_pages; i++) { |
| 596 | struct page *page = req->pages[i]; |
| 597 | if (write) |
| 598 | set_page_dirty_lock(page); |
| 599 | put_page(page); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf, |
| 604 | unsigned nbytes, int write) |
| 605 | { |
| 606 | unsigned long user_addr = (unsigned long) buf; |
| 607 | unsigned offset = user_addr & ~PAGE_MASK; |
| 608 | int npages; |
| 609 | |
| 610 | /* This doesn't work with nfsd */ |
| 611 | if (!current->mm) |
| 612 | return -EPERM; |
| 613 | |
| 614 | nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT); |
| 615 | npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT; |
Miklos Szeredi | 6ad84ac | 2006-01-06 00:19:42 -0800 | [diff] [blame] | 616 | npages = min(max(npages, 1), FUSE_MAX_PAGES_PER_REQ); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 617 | down_read(¤t->mm->mmap_sem); |
| 618 | npages = get_user_pages(current, current->mm, user_addr, npages, write, |
| 619 | 0, req->pages, NULL); |
| 620 | up_read(¤t->mm->mmap_sem); |
| 621 | if (npages < 0) |
| 622 | return npages; |
| 623 | |
| 624 | req->num_pages = npages; |
| 625 | req->page_offset = offset; |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | static ssize_t fuse_direct_io(struct file *file, const char __user *buf, |
| 630 | size_t count, loff_t *ppos, int write) |
| 631 | { |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 632 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 633 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 634 | size_t nmax = write ? fc->max_write : fc->max_read; |
| 635 | loff_t pos = *ppos; |
| 636 | ssize_t res = 0; |
Miklos Szeredi | 248d86e | 2006-01-06 00:19:39 -0800 | [diff] [blame] | 637 | struct fuse_req *req; |
| 638 | |
| 639 | if (is_bad_inode(inode)) |
| 640 | return -EIO; |
| 641 | |
Miklos Szeredi | ce1d5a4 | 2006-04-10 22:54:58 -0700 | [diff] [blame] | 642 | req = fuse_get_req(fc); |
| 643 | if (IS_ERR(req)) |
| 644 | return PTR_ERR(req); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 645 | |
| 646 | while (count) { |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 647 | size_t nres; |
| 648 | size_t nbytes = min(count, nmax); |
| 649 | int err = fuse_get_user_pages(req, buf, nbytes, !write); |
| 650 | if (err) { |
| 651 | res = err; |
| 652 | break; |
| 653 | } |
Miklos Szeredi | 6ad84ac | 2006-01-06 00:19:42 -0800 | [diff] [blame] | 654 | nbytes = (req->num_pages << PAGE_SHIFT) - req->page_offset; |
| 655 | nbytes = min(count, nbytes); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 656 | if (write) |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 657 | nres = fuse_send_write(req, file, inode, pos, nbytes, |
| 658 | current->files); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 659 | else |
Miklos Szeredi | f333211 | 2007-10-18 03:07:04 -0700 | [diff] [blame] | 660 | nres = fuse_send_read(req, file, inode, pos, nbytes, |
| 661 | current->files); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 662 | fuse_release_user_pages(req, !write); |
| 663 | if (req->out.h.error) { |
| 664 | if (!res) |
| 665 | res = req->out.h.error; |
| 666 | break; |
| 667 | } else if (nres > nbytes) { |
| 668 | res = -EIO; |
| 669 | break; |
| 670 | } |
| 671 | count -= nres; |
| 672 | res += nres; |
| 673 | pos += nres; |
| 674 | buf += nres; |
| 675 | if (nres != nbytes) |
| 676 | break; |
Miklos Szeredi | 56cf34f | 2006-04-11 21:16:51 +0200 | [diff] [blame] | 677 | if (count) { |
| 678 | fuse_put_request(fc, req); |
| 679 | req = fuse_get_req(fc); |
| 680 | if (IS_ERR(req)) |
| 681 | break; |
| 682 | } |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 683 | } |
| 684 | fuse_put_request(fc, req); |
| 685 | if (res > 0) { |
Miklos Szeredi | 9ffbb91 | 2006-10-17 00:10:06 -0700 | [diff] [blame] | 686 | if (write) { |
| 687 | spin_lock(&fc->lock); |
| 688 | if (pos > inode->i_size) |
| 689 | i_size_write(inode, pos); |
| 690 | spin_unlock(&fc->lock); |
| 691 | } |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 692 | *ppos = pos; |
Miklos Szeredi | b36c31b | 2005-09-09 13:10:38 -0700 | [diff] [blame] | 693 | } |
| 694 | fuse_invalidate_attr(inode); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 695 | |
| 696 | return res; |
| 697 | } |
| 698 | |
| 699 | static ssize_t fuse_direct_read(struct file *file, char __user *buf, |
| 700 | size_t count, loff_t *ppos) |
| 701 | { |
| 702 | return fuse_direct_io(file, buf, count, ppos, 0); |
| 703 | } |
| 704 | |
| 705 | static ssize_t fuse_direct_write(struct file *file, const char __user *buf, |
| 706 | size_t count, loff_t *ppos) |
| 707 | { |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 708 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 709 | ssize_t res; |
| 710 | /* Don't allow parallel writes to the same file */ |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 711 | mutex_lock(&inode->i_mutex); |
Miklos Szeredi | 889f784 | 2007-05-23 13:57:54 -0700 | [diff] [blame] | 712 | res = generic_write_checks(file, ppos, &count, 0); |
| 713 | if (!res) |
| 714 | res = fuse_direct_io(file, buf, count, ppos, 1); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 715 | mutex_unlock(&inode->i_mutex); |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 716 | return res; |
| 717 | } |
| 718 | |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 719 | static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma) |
| 720 | { |
| 721 | if ((vma->vm_flags & VM_SHARED)) { |
| 722 | if ((vma->vm_flags & VM_WRITE)) |
| 723 | return -ENODEV; |
| 724 | else |
| 725 | vma->vm_flags &= ~VM_MAYWRITE; |
| 726 | } |
| 727 | return generic_file_mmap(file, vma); |
| 728 | } |
| 729 | |
| 730 | static int fuse_set_page_dirty(struct page *page) |
| 731 | { |
| 732 | printk("fuse_set_page_dirty: should not happen\n"); |
| 733 | dump_stack(); |
| 734 | return 0; |
| 735 | } |
| 736 | |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 737 | static int convert_fuse_file_lock(const struct fuse_file_lock *ffl, |
| 738 | struct file_lock *fl) |
| 739 | { |
| 740 | switch (ffl->type) { |
| 741 | case F_UNLCK: |
| 742 | break; |
| 743 | |
| 744 | case F_RDLCK: |
| 745 | case F_WRLCK: |
| 746 | if (ffl->start > OFFSET_MAX || ffl->end > OFFSET_MAX || |
| 747 | ffl->end < ffl->start) |
| 748 | return -EIO; |
| 749 | |
| 750 | fl->fl_start = ffl->start; |
| 751 | fl->fl_end = ffl->end; |
| 752 | fl->fl_pid = ffl->pid; |
| 753 | break; |
| 754 | |
| 755 | default: |
| 756 | return -EIO; |
| 757 | } |
| 758 | fl->fl_type = ffl->type; |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | static void fuse_lk_fill(struct fuse_req *req, struct file *file, |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 763 | const struct file_lock *fl, int opcode, pid_t pid, |
| 764 | int flock) |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 765 | { |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 766 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | 9c8ef56 | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 767 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 768 | struct fuse_file *ff = file->private_data; |
| 769 | struct fuse_lk_in *arg = &req->misc.lk_in; |
| 770 | |
| 771 | arg->fh = ff->fh; |
Miklos Szeredi | 9c8ef56 | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 772 | arg->owner = fuse_lock_owner_id(fc, fl->fl_owner); |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 773 | arg->lk.start = fl->fl_start; |
| 774 | arg->lk.end = fl->fl_end; |
| 775 | arg->lk.type = fl->fl_type; |
| 776 | arg->lk.pid = pid; |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 777 | if (flock) |
| 778 | arg->lk_flags |= FUSE_LK_FLOCK; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 779 | req->in.h.opcode = opcode; |
| 780 | req->in.h.nodeid = get_node_id(inode); |
| 781 | req->in.numargs = 1; |
| 782 | req->in.args[0].size = sizeof(*arg); |
| 783 | req->in.args[0].value = arg; |
| 784 | } |
| 785 | |
| 786 | static int fuse_getlk(struct file *file, struct file_lock *fl) |
| 787 | { |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 788 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 789 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 790 | struct fuse_req *req; |
| 791 | struct fuse_lk_out outarg; |
| 792 | int err; |
| 793 | |
| 794 | req = fuse_get_req(fc); |
| 795 | if (IS_ERR(req)) |
| 796 | return PTR_ERR(req); |
| 797 | |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 798 | fuse_lk_fill(req, file, fl, FUSE_GETLK, 0, 0); |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 799 | req->out.numargs = 1; |
| 800 | req->out.args[0].size = sizeof(outarg); |
| 801 | req->out.args[0].value = &outarg; |
| 802 | request_send(fc, req); |
| 803 | err = req->out.h.error; |
| 804 | fuse_put_request(fc, req); |
| 805 | if (!err) |
| 806 | err = convert_fuse_file_lock(&outarg.lk, fl); |
| 807 | |
| 808 | return err; |
| 809 | } |
| 810 | |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 811 | static int fuse_setlk(struct file *file, struct file_lock *fl, int flock) |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 812 | { |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 813 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 814 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 815 | struct fuse_req *req; |
| 816 | int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK; |
| 817 | pid_t pid = fl->fl_type != F_UNLCK ? current->tgid : 0; |
| 818 | int err; |
| 819 | |
| 820 | /* Unlock on close is handled by the flush method */ |
| 821 | if (fl->fl_flags & FL_CLOSE) |
| 822 | return 0; |
| 823 | |
| 824 | req = fuse_get_req(fc); |
| 825 | if (IS_ERR(req)) |
| 826 | return PTR_ERR(req); |
| 827 | |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 828 | fuse_lk_fill(req, file, fl, opcode, pid, flock); |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 829 | request_send(fc, req); |
| 830 | err = req->out.h.error; |
Miklos Szeredi | a4d27e7 | 2006-06-25 05:48:54 -0700 | [diff] [blame] | 831 | /* locking is restartable */ |
| 832 | if (err == -EINTR) |
| 833 | err = -ERESTARTSYS; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 834 | fuse_put_request(fc, req); |
| 835 | return err; |
| 836 | } |
| 837 | |
| 838 | static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl) |
| 839 | { |
Josef Sipek | 7706a9d | 2006-12-08 02:37:02 -0800 | [diff] [blame] | 840 | struct inode *inode = file->f_path.dentry->d_inode; |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 841 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 842 | int err; |
| 843 | |
| 844 | if (cmd == F_GETLK) { |
| 845 | if (fc->no_lock) { |
Marc Eshel | 9d6a8c5 | 2007-02-21 00:55:18 -0500 | [diff] [blame] | 846 | posix_test_lock(file, fl); |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 847 | err = 0; |
| 848 | } else |
| 849 | err = fuse_getlk(file, fl); |
| 850 | } else { |
| 851 | if (fc->no_lock) |
| 852 | err = posix_lock_file_wait(file, fl); |
| 853 | else |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 854 | err = fuse_setlk(file, fl, 0); |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 855 | } |
| 856 | return err; |
| 857 | } |
| 858 | |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 859 | static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl) |
| 860 | { |
| 861 | struct inode *inode = file->f_path.dentry->d_inode; |
| 862 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 863 | int err; |
| 864 | |
| 865 | if (fc->no_lock) { |
| 866 | err = flock_lock_file_wait(file, fl); |
| 867 | } else { |
| 868 | /* emulate flock with POSIX locks */ |
| 869 | fl->fl_owner = (fl_owner_t) file; |
| 870 | err = fuse_setlk(file, fl, 1); |
| 871 | } |
| 872 | |
| 873 | return err; |
| 874 | } |
| 875 | |
Miklos Szeredi | b2d2272 | 2006-12-06 20:35:51 -0800 | [diff] [blame] | 876 | static sector_t fuse_bmap(struct address_space *mapping, sector_t block) |
| 877 | { |
| 878 | struct inode *inode = mapping->host; |
| 879 | struct fuse_conn *fc = get_fuse_conn(inode); |
| 880 | struct fuse_req *req; |
| 881 | struct fuse_bmap_in inarg; |
| 882 | struct fuse_bmap_out outarg; |
| 883 | int err; |
| 884 | |
| 885 | if (!inode->i_sb->s_bdev || fc->no_bmap) |
| 886 | return 0; |
| 887 | |
| 888 | req = fuse_get_req(fc); |
| 889 | if (IS_ERR(req)) |
| 890 | return 0; |
| 891 | |
| 892 | memset(&inarg, 0, sizeof(inarg)); |
| 893 | inarg.block = block; |
| 894 | inarg.blocksize = inode->i_sb->s_blocksize; |
| 895 | req->in.h.opcode = FUSE_BMAP; |
| 896 | req->in.h.nodeid = get_node_id(inode); |
| 897 | req->in.numargs = 1; |
| 898 | req->in.args[0].size = sizeof(inarg); |
| 899 | req->in.args[0].value = &inarg; |
| 900 | req->out.numargs = 1; |
| 901 | req->out.args[0].size = sizeof(outarg); |
| 902 | req->out.args[0].value = &outarg; |
| 903 | request_send(fc, req); |
| 904 | err = req->out.h.error; |
| 905 | fuse_put_request(fc, req); |
| 906 | if (err == -ENOSYS) |
| 907 | fc->no_bmap = 1; |
| 908 | |
| 909 | return err ? 0 : outarg.block; |
| 910 | } |
| 911 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 912 | static const struct file_operations fuse_file_operations = { |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 913 | .llseek = generic_file_llseek, |
Badari Pulavarty | 543ade1 | 2006-09-30 23:28:48 -0700 | [diff] [blame] | 914 | .read = do_sync_read, |
Miklos Szeredi | bcb4be8 | 2007-11-28 16:21:59 -0800 | [diff] [blame] | 915 | .aio_read = fuse_file_aio_read, |
Badari Pulavarty | 543ade1 | 2006-09-30 23:28:48 -0700 | [diff] [blame] | 916 | .write = do_sync_write, |
| 917 | .aio_write = generic_file_aio_write, |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 918 | .mmap = fuse_file_mmap, |
| 919 | .open = fuse_open, |
| 920 | .flush = fuse_flush, |
| 921 | .release = fuse_release, |
| 922 | .fsync = fuse_fsync, |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 923 | .lock = fuse_file_lock, |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 924 | .flock = fuse_file_flock, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 925 | .splice_read = generic_file_splice_read, |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 926 | }; |
| 927 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 928 | static const struct file_operations fuse_direct_io_file_operations = { |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 929 | .llseek = generic_file_llseek, |
| 930 | .read = fuse_direct_read, |
| 931 | .write = fuse_direct_write, |
| 932 | .open = fuse_open, |
| 933 | .flush = fuse_flush, |
| 934 | .release = fuse_release, |
| 935 | .fsync = fuse_fsync, |
Miklos Szeredi | 7142125 | 2006-06-25 05:48:52 -0700 | [diff] [blame] | 936 | .lock = fuse_file_lock, |
Miklos Szeredi | a9ff4f8 | 2007-10-18 03:07:02 -0700 | [diff] [blame] | 937 | .flock = fuse_file_flock, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 938 | /* no mmap and splice_read */ |
Miklos Szeredi | 413ef8c | 2005-09-09 13:10:35 -0700 | [diff] [blame] | 939 | }; |
| 940 | |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 941 | static const struct address_space_operations fuse_file_aops = { |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 942 | .readpage = fuse_readpage, |
Nick Piggin | 5e6f58a | 2007-10-16 01:25:17 -0700 | [diff] [blame] | 943 | .write_begin = fuse_write_begin, |
| 944 | .write_end = fuse_write_end, |
Miklos Szeredi | db50b96 | 2005-09-09 13:10:33 -0700 | [diff] [blame] | 945 | .readpages = fuse_readpages, |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 946 | .set_page_dirty = fuse_set_page_dirty, |
Miklos Szeredi | b2d2272 | 2006-12-06 20:35:51 -0800 | [diff] [blame] | 947 | .bmap = fuse_bmap, |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 948 | }; |
| 949 | |
| 950 | void fuse_init_file_inode(struct inode *inode) |
| 951 | { |
Miklos Szeredi | 45323fb | 2005-09-09 13:10:37 -0700 | [diff] [blame] | 952 | inode->i_fop = &fuse_file_operations; |
| 953 | inode->i_data.a_ops = &fuse_file_aops; |
Miklos Szeredi | b6aeade | 2005-09-09 13:10:30 -0700 | [diff] [blame] | 954 | } |