blob: 18aafa6c9af4b66c2095619ee2ad434e1d73b120 [file] [log] [blame]
Miklos Szeredib6aeade2005-09-09 13:10:30 -07001/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
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
Miklos Szeredi45323fb2005-09-09 13:10:37 -070015static struct file_operations fuse_direct_io_file_operations;
16
Miklos Szeredifd72faa2005-11-07 00:59:51 -080017static int fuse_send_open(struct inode *inode, struct file *file, int isdir,
18 struct fuse_open_out *outargp)
Miklos Szeredib6aeade2005-09-09 13:10:30 -070019{
20 struct fuse_conn *fc = get_fuse_conn(inode);
Miklos Szeredib6aeade2005-09-09 13:10:30 -070021 struct fuse_open_in inarg;
Miklos Szeredifd72faa2005-11-07 00:59:51 -080022 struct fuse_req *req;
23 int err;
24
25 req = fuse_get_request(fc);
26 if (!req)
27 return -EINTR;
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);
33 req->inode = inode;
34 req->in.numargs = 1;
35 req->in.args[0].size = sizeof(inarg);
36 req->in.args[0].value = &inarg;
37 req->out.numargs = 1;
38 req->out.args[0].size = sizeof(*outargp);
39 req->out.args[0].value = outargp;
40 request_send(fc, req);
41 err = req->out.h.error;
42 fuse_put_request(fc, req);
43
44 return err;
45}
46
47struct fuse_file *fuse_file_alloc(void)
48{
49 struct fuse_file *ff;
50 ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
51 if (ff) {
52 ff->release_req = fuse_request_alloc();
53 if (!ff->release_req) {
54 kfree(ff);
55 ff = NULL;
56 }
57 }
58 return ff;
59}
60
61void fuse_file_free(struct fuse_file *ff)
62{
63 fuse_request_free(ff->release_req);
64 kfree(ff);
65}
66
67void fuse_finish_open(struct inode *inode, struct file *file,
68 struct fuse_file *ff, struct fuse_open_out *outarg)
69{
70 if (outarg->open_flags & FOPEN_DIRECT_IO)
71 file->f_op = &fuse_direct_io_file_operations;
72 if (!(outarg->open_flags & FOPEN_KEEP_CACHE))
73 invalidate_inode_pages(inode->i_mapping);
74 ff->fh = outarg->fh;
75 file->private_data = ff;
76}
77
78int fuse_open_common(struct inode *inode, struct file *file, int isdir)
79{
Miklos Szeredib6aeade2005-09-09 13:10:30 -070080 struct fuse_open_out outarg;
81 struct fuse_file *ff;
82 int err;
Miklos Szeredib6aeade2005-09-09 13:10:30 -070083
Miklos Szeredidd190d02005-09-30 11:59:02 -070084 /* VFS checks this, but only _after_ ->open() */
85 if (file->f_flags & O_DIRECT)
86 return -EINVAL;
87
Miklos Szeredib6aeade2005-09-09 13:10:30 -070088 err = generic_file_open(inode, file);
89 if (err)
90 return err;
91
92 /* If opening the root node, no lookup has been performed on
93 it, so the attributes must be refreshed */
94 if (get_node_id(inode) == FUSE_ROOT_ID) {
Miklos Szeredifd72faa2005-11-07 00:59:51 -080095 err = fuse_do_getattr(inode);
Miklos Szeredib6aeade2005-09-09 13:10:30 -070096 if (err)
97 return err;
98 }
99
Miklos Szeredifd72faa2005-11-07 00:59:51 -0800100 ff = fuse_file_alloc();
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700101 if (!ff)
Miklos Szeredifd72faa2005-11-07 00:59:51 -0800102 return -ENOMEM;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700103
Miklos Szeredifd72faa2005-11-07 00:59:51 -0800104 err = fuse_send_open(inode, file, isdir, &outarg);
105 if (err)
106 fuse_file_free(ff);
107 else {
108 if (isdir)
109 outarg.open_flags &= ~FOPEN_DIRECT_IO;
110 fuse_finish_open(inode, file, ff, &outarg);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700111 }
112
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700113 return err;
114}
115
Miklos Szeredifd72faa2005-11-07 00:59:51 -0800116void fuse_send_release(struct fuse_conn *fc, struct fuse_file *ff,
117 u64 nodeid, struct inode *inode, int flags, int isdir)
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700118{
Miklos Szeredifd72faa2005-11-07 00:59:51 -0800119 struct fuse_req * req = ff->release_req;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700120 struct fuse_release_in *inarg = &req->misc.release_in;
121
122 inarg->fh = ff->fh;
Miklos Szeredifd72faa2005-11-07 00:59:51 -0800123 inarg->flags = flags;
Miklos Szeredi04730fe2005-09-09 13:10:36 -0700124 req->in.h.opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;
Miklos Szeredifd72faa2005-11-07 00:59:51 -0800125 req->in.h.nodeid = nodeid;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700126 req->inode = inode;
127 req->in.numargs = 1;
128 req->in.args[0].size = sizeof(struct fuse_release_in);
129 req->in.args[0].value = inarg;
130 request_send_background(fc, req);
131 kfree(ff);
Miklos Szeredifd72faa2005-11-07 00:59:51 -0800132}
133
134int fuse_release_common(struct inode *inode, struct file *file, int isdir)
135{
136 struct fuse_file *ff = file->private_data;
137 if (ff) {
138 struct fuse_conn *fc = get_fuse_conn(inode);
139 u64 nodeid = get_node_id(inode);
140 fuse_send_release(fc, ff, nodeid, inode, file->f_flags, isdir);
141 }
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700142
143 /* Return value is ignored by VFS */
144 return 0;
145}
146
Miklos Szeredi04730fe2005-09-09 13:10:36 -0700147static int fuse_open(struct inode *inode, struct file *file)
148{
149 return fuse_open_common(inode, file, 0);
150}
151
152static int fuse_release(struct inode *inode, struct file *file)
153{
154 return fuse_release_common(inode, file, 0);
155}
156
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700157static int fuse_flush(struct file *file)
158{
159 struct inode *inode = file->f_dentry->d_inode;
160 struct fuse_conn *fc = get_fuse_conn(inode);
161 struct fuse_file *ff = file->private_data;
162 struct fuse_req *req;
163 struct fuse_flush_in inarg;
164 int err;
165
166 if (fc->no_flush)
167 return 0;
168
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700169 req = fuse_get_request(fc);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700170 if (!req)
171 return -EINTR;
172
173 memset(&inarg, 0, sizeof(inarg));
174 inarg.fh = ff->fh;
175 req->in.h.opcode = FUSE_FLUSH;
176 req->in.h.nodeid = get_node_id(inode);
177 req->inode = inode;
178 req->file = file;
179 req->in.numargs = 1;
180 req->in.args[0].size = sizeof(inarg);
181 req->in.args[0].value = &inarg;
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700182 request_send(fc, req);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700183 err = req->out.h.error;
184 fuse_put_request(fc, req);
185 if (err == -ENOSYS) {
186 fc->no_flush = 1;
187 err = 0;
188 }
189 return err;
190}
191
Miklos Szeredi82547982005-09-09 13:10:38 -0700192int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
193 int isdir)
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700194{
195 struct inode *inode = de->d_inode;
196 struct fuse_conn *fc = get_fuse_conn(inode);
197 struct fuse_file *ff = file->private_data;
198 struct fuse_req *req;
199 struct fuse_fsync_in inarg;
200 int err;
201
Miklos Szeredi82547982005-09-09 13:10:38 -0700202 if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir))
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700203 return 0;
204
205 req = fuse_get_request(fc);
206 if (!req)
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700207 return -EINTR;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700208
209 memset(&inarg, 0, sizeof(inarg));
210 inarg.fh = ff->fh;
211 inarg.fsync_flags = datasync ? 1 : 0;
Miklos Szeredi82547982005-09-09 13:10:38 -0700212 req->in.h.opcode = isdir ? FUSE_FSYNCDIR : FUSE_FSYNC;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700213 req->in.h.nodeid = get_node_id(inode);
214 req->inode = inode;
215 req->file = file;
216 req->in.numargs = 1;
217 req->in.args[0].size = sizeof(inarg);
218 req->in.args[0].value = &inarg;
219 request_send(fc, req);
220 err = req->out.h.error;
221 fuse_put_request(fc, req);
222 if (err == -ENOSYS) {
Miklos Szeredi82547982005-09-09 13:10:38 -0700223 if (isdir)
224 fc->no_fsyncdir = 1;
225 else
226 fc->no_fsync = 1;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700227 err = 0;
228 }
229 return err;
230}
231
Miklos Szeredi82547982005-09-09 13:10:38 -0700232static int fuse_fsync(struct file *file, struct dentry *de, int datasync)
233{
234 return fuse_fsync_common(file, de, datasync, 0);
235}
236
Miklos Szeredi04730fe2005-09-09 13:10:36 -0700237size_t fuse_send_read_common(struct fuse_req *req, struct file *file,
238 struct inode *inode, loff_t pos, size_t count,
239 int isdir)
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700240{
241 struct fuse_conn *fc = get_fuse_conn(inode);
242 struct fuse_file *ff = file->private_data;
243 struct fuse_read_in inarg;
244
245 memset(&inarg, 0, sizeof(struct fuse_read_in));
246 inarg.fh = ff->fh;
247 inarg.offset = pos;
248 inarg.size = count;
Miklos Szeredi04730fe2005-09-09 13:10:36 -0700249 req->in.h.opcode = isdir ? FUSE_READDIR : FUSE_READ;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700250 req->in.h.nodeid = get_node_id(inode);
251 req->inode = inode;
252 req->file = file;
253 req->in.numargs = 1;
254 req->in.args[0].size = sizeof(struct fuse_read_in);
255 req->in.args[0].value = &inarg;
256 req->out.argpages = 1;
257 req->out.argvar = 1;
258 req->out.numargs = 1;
259 req->out.args[0].size = count;
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700260 request_send(fc, req);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700261 return req->out.args[0].size;
262}
263
Miklos Szeredi04730fe2005-09-09 13:10:36 -0700264static inline size_t fuse_send_read(struct fuse_req *req, struct file *file,
265 struct inode *inode, loff_t pos,
266 size_t count)
267{
268 return fuse_send_read_common(req, file, inode, pos, count, 0);
269}
270
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700271static int fuse_readpage(struct file *file, struct page *page)
272{
273 struct inode *inode = page->mapping->host;
274 struct fuse_conn *fc = get_fuse_conn(inode);
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700275 struct fuse_req *req = fuse_get_request(fc);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700276 int err = -EINTR;
277 if (!req)
278 goto out;
279
280 req->out.page_zeroing = 1;
281 req->num_pages = 1;
282 req->pages[0] = page;
Miklos Szeredi4633a222006-01-06 00:19:36 -0800283 fuse_send_read(req, file, inode, page_offset(page), PAGE_CACHE_SIZE);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700284 err = req->out.h.error;
285 fuse_put_request(fc, req);
286 if (!err)
287 SetPageUptodate(page);
Miklos Szeredib36c31b2005-09-09 13:10:38 -0700288 fuse_invalidate_attr(inode); /* atime changed */
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700289 out:
290 unlock_page(page);
291 return err;
292}
293
Miklos Szeredidb50b962005-09-09 13:10:33 -0700294static int fuse_send_readpages(struct fuse_req *req, struct file *file,
295 struct inode *inode)
296{
Miklos Szeredi4633a222006-01-06 00:19:36 -0800297 loff_t pos = page_offset(req->pages[0]);
Miklos Szeredidb50b962005-09-09 13:10:33 -0700298 size_t count = req->num_pages << PAGE_CACHE_SHIFT;
299 unsigned i;
300 req->out.page_zeroing = 1;
301 fuse_send_read(req, file, inode, pos, count);
302 for (i = 0; i < req->num_pages; i++) {
303 struct page *page = req->pages[i];
304 if (!req->out.h.error)
305 SetPageUptodate(page);
306 unlock_page(page);
307 }
308 return req->out.h.error;
309}
310
311struct fuse_readpages_data {
312 struct fuse_req *req;
313 struct file *file;
314 struct inode *inode;
315};
316
317static int fuse_readpages_fill(void *_data, struct page *page)
318{
319 struct fuse_readpages_data *data = _data;
320 struct fuse_req *req = data->req;
321 struct inode *inode = data->inode;
322 struct fuse_conn *fc = get_fuse_conn(inode);
323
324 if (req->num_pages &&
325 (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
326 (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read ||
327 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
328 int err = fuse_send_readpages(req, data->file, inode);
329 if (err) {
330 unlock_page(page);
331 return err;
332 }
333 fuse_reset_request(req);
334 }
335 req->pages[req->num_pages] = page;
336 req->num_pages ++;
337 return 0;
338}
339
340static int fuse_readpages(struct file *file, struct address_space *mapping,
341 struct list_head *pages, unsigned nr_pages)
342{
343 struct inode *inode = mapping->host;
344 struct fuse_conn *fc = get_fuse_conn(inode);
345 struct fuse_readpages_data data;
346 int err;
347 data.file = file;
348 data.inode = inode;
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700349 data.req = fuse_get_request(fc);
Miklos Szeredidb50b962005-09-09 13:10:33 -0700350 if (!data.req)
351 return -EINTR;
352
353 err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data);
354 if (!err && data.req->num_pages)
355 err = fuse_send_readpages(data.req, file, inode);
356 fuse_put_request(fc, data.req);
Miklos Szeredib36c31b2005-09-09 13:10:38 -0700357 fuse_invalidate_attr(inode); /* atime changed */
Miklos Szeredidb50b962005-09-09 13:10:33 -0700358 return err;
359}
360
Miklos Szeredi04730fe2005-09-09 13:10:36 -0700361static size_t fuse_send_write(struct fuse_req *req, struct file *file,
362 struct inode *inode, loff_t pos, size_t count)
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700363{
364 struct fuse_conn *fc = get_fuse_conn(inode);
365 struct fuse_file *ff = file->private_data;
366 struct fuse_write_in inarg;
367 struct fuse_write_out outarg;
368
369 memset(&inarg, 0, sizeof(struct fuse_write_in));
370 inarg.fh = ff->fh;
371 inarg.offset = pos;
372 inarg.size = count;
373 req->in.h.opcode = FUSE_WRITE;
374 req->in.h.nodeid = get_node_id(inode);
375 req->inode = inode;
376 req->file = file;
377 req->in.argpages = 1;
378 req->in.numargs = 2;
379 req->in.args[0].size = sizeof(struct fuse_write_in);
380 req->in.args[0].value = &inarg;
381 req->in.args[1].size = count;
382 req->out.numargs = 1;
383 req->out.args[0].size = sizeof(struct fuse_write_out);
384 req->out.args[0].value = &outarg;
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700385 request_send(fc, req);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700386 return outarg.size;
387}
388
389static int fuse_prepare_write(struct file *file, struct page *page,
390 unsigned offset, unsigned to)
391{
392 /* No op */
393 return 0;
394}
395
396static int fuse_commit_write(struct file *file, struct page *page,
397 unsigned offset, unsigned to)
398{
399 int err;
Miklos Szeredi04730fe2005-09-09 13:10:36 -0700400 size_t nres;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700401 unsigned count = to - offset;
402 struct inode *inode = page->mapping->host;
403 struct fuse_conn *fc = get_fuse_conn(inode);
Miklos Szeredi4633a222006-01-06 00:19:36 -0800404 loff_t pos = page_offset(page) + offset;
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700405 struct fuse_req *req = fuse_get_request(fc);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700406 if (!req)
407 return -EINTR;
408
409 req->num_pages = 1;
410 req->pages[0] = page;
411 req->page_offset = offset;
412 nres = fuse_send_write(req, file, inode, pos, count);
413 err = req->out.h.error;
414 fuse_put_request(fc, req);
415 if (!err && nres != count)
416 err = -EIO;
417 if (!err) {
418 pos += count;
419 if (pos > i_size_read(inode))
420 i_size_write(inode, pos);
421
422 if (offset == 0 && to == PAGE_CACHE_SIZE) {
423 clear_page_dirty(page);
424 SetPageUptodate(page);
425 }
Miklos Szeredib36c31b2005-09-09 13:10:38 -0700426 }
427 fuse_invalidate_attr(inode);
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700428 return err;
429}
430
Miklos Szeredi413ef8c2005-09-09 13:10:35 -0700431static void fuse_release_user_pages(struct fuse_req *req, int write)
432{
433 unsigned i;
434
435 for (i = 0; i < req->num_pages; i++) {
436 struct page *page = req->pages[i];
437 if (write)
438 set_page_dirty_lock(page);
439 put_page(page);
440 }
441}
442
443static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf,
444 unsigned nbytes, int write)
445{
446 unsigned long user_addr = (unsigned long) buf;
447 unsigned offset = user_addr & ~PAGE_MASK;
448 int npages;
449
450 /* This doesn't work with nfsd */
451 if (!current->mm)
452 return -EPERM;
453
454 nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT);
455 npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
456 npages = min(npages, FUSE_MAX_PAGES_PER_REQ);
457 down_read(&current->mm->mmap_sem);
458 npages = get_user_pages(current, current->mm, user_addr, npages, write,
459 0, req->pages, NULL);
460 up_read(&current->mm->mmap_sem);
461 if (npages < 0)
462 return npages;
463
464 req->num_pages = npages;
465 req->page_offset = offset;
466 return 0;
467}
468
469static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
470 size_t count, loff_t *ppos, int write)
471{
472 struct inode *inode = file->f_dentry->d_inode;
473 struct fuse_conn *fc = get_fuse_conn(inode);
474 size_t nmax = write ? fc->max_write : fc->max_read;
475 loff_t pos = *ppos;
476 ssize_t res = 0;
477 struct fuse_req *req = fuse_get_request(fc);
478 if (!req)
Miklos Szeredi7c352bd2005-09-09 13:10:39 -0700479 return -EINTR;
Miklos Szeredi413ef8c2005-09-09 13:10:35 -0700480
481 while (count) {
482 size_t tmp;
483 size_t nres;
484 size_t nbytes = min(count, nmax);
485 int err = fuse_get_user_pages(req, buf, nbytes, !write);
486 if (err) {
487 res = err;
488 break;
489 }
490 tmp = (req->num_pages << PAGE_SHIFT) - req->page_offset;
491 nbytes = min(nbytes, tmp);
492 if (write)
493 nres = fuse_send_write(req, file, inode, pos, nbytes);
494 else
495 nres = fuse_send_read(req, file, inode, pos, nbytes);
496 fuse_release_user_pages(req, !write);
497 if (req->out.h.error) {
498 if (!res)
499 res = req->out.h.error;
500 break;
501 } else if (nres > nbytes) {
502 res = -EIO;
503 break;
504 }
505 count -= nres;
506 res += nres;
507 pos += nres;
508 buf += nres;
509 if (nres != nbytes)
510 break;
511 if (count)
512 fuse_reset_request(req);
513 }
514 fuse_put_request(fc, req);
515 if (res > 0) {
516 if (write && pos > i_size_read(inode))
517 i_size_write(inode, pos);
518 *ppos = pos;
Miklos Szeredib36c31b2005-09-09 13:10:38 -0700519 }
520 fuse_invalidate_attr(inode);
Miklos Szeredi413ef8c2005-09-09 13:10:35 -0700521
522 return res;
523}
524
525static ssize_t fuse_direct_read(struct file *file, char __user *buf,
526 size_t count, loff_t *ppos)
527{
528 return fuse_direct_io(file, buf, count, ppos, 0);
529}
530
531static ssize_t fuse_direct_write(struct file *file, const char __user *buf,
532 size_t count, loff_t *ppos)
533{
534 struct inode *inode = file->f_dentry->d_inode;
535 ssize_t res;
536 /* Don't allow parallel writes to the same file */
537 down(&inode->i_sem);
538 res = fuse_direct_io(file, buf, count, ppos, 1);
539 up(&inode->i_sem);
540 return res;
541}
542
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700543static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
544{
545 if ((vma->vm_flags & VM_SHARED)) {
546 if ((vma->vm_flags & VM_WRITE))
547 return -ENODEV;
548 else
549 vma->vm_flags &= ~VM_MAYWRITE;
550 }
551 return generic_file_mmap(file, vma);
552}
553
554static int fuse_set_page_dirty(struct page *page)
555{
556 printk("fuse_set_page_dirty: should not happen\n");
557 dump_stack();
558 return 0;
559}
560
561static struct file_operations fuse_file_operations = {
562 .llseek = generic_file_llseek,
563 .read = generic_file_read,
564 .write = generic_file_write,
565 .mmap = fuse_file_mmap,
566 .open = fuse_open,
567 .flush = fuse_flush,
568 .release = fuse_release,
569 .fsync = fuse_fsync,
570 .sendfile = generic_file_sendfile,
571};
572
Miklos Szeredi413ef8c2005-09-09 13:10:35 -0700573static struct file_operations fuse_direct_io_file_operations = {
574 .llseek = generic_file_llseek,
575 .read = fuse_direct_read,
576 .write = fuse_direct_write,
577 .open = fuse_open,
578 .flush = fuse_flush,
579 .release = fuse_release,
580 .fsync = fuse_fsync,
581 /* no mmap and sendfile */
582};
583
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700584static struct address_space_operations fuse_file_aops = {
585 .readpage = fuse_readpage,
586 .prepare_write = fuse_prepare_write,
587 .commit_write = fuse_commit_write,
Miklos Szeredidb50b962005-09-09 13:10:33 -0700588 .readpages = fuse_readpages,
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700589 .set_page_dirty = fuse_set_page_dirty,
590};
591
592void fuse_init_file_inode(struct inode *inode)
593{
Miklos Szeredi45323fb2005-09-09 13:10:37 -0700594 inode->i_fop = &fuse_file_operations;
595 inode->i_data.a_ops = &fuse_file_aops;
Miklos Szeredib6aeade2005-09-09 13:10:30 -0700596}