USB: make autosuspend delay a module parameter
[linux-2.6/mini2440.git] / fs / fuse / file.c
blob2fd06927e851674e14968cda55898ec832ab2ac0
1 /*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2006 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7 */
9 #include "fuse_i.h"
11 #include <linux/pagemap.h>
12 #include <linux/slab.h>
13 #include <linux/kernel.h>
15 static const struct file_operations fuse_direct_io_file_operations;
17 static int fuse_send_open(struct inode *inode, struct file *file, int isdir,
18 struct fuse_open_out *outargp)
20 struct fuse_conn *fc = get_fuse_conn(inode);
21 struct fuse_open_in inarg;
22 struct fuse_req *req;
23 int err;
25 req = fuse_get_req(fc);
26 if (IS_ERR(req))
27 return PTR_ERR(req);
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->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);
43 return err;
46 struct fuse_file *fuse_file_alloc(void)
48 struct fuse_file *ff;
49 ff = kmalloc(sizeof(struct fuse_file), GFP_KERNEL);
50 if (ff) {
51 ff->reserved_req = fuse_request_alloc();
52 if (!ff->reserved_req) {
53 kfree(ff);
54 ff = NULL;
57 return ff;
60 void fuse_file_free(struct fuse_file *ff)
62 fuse_request_free(ff->reserved_req);
63 kfree(ff);
66 void fuse_finish_open(struct inode *inode, struct file *file,
67 struct fuse_file *ff, struct fuse_open_out *outarg)
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_mapping_pages(inode->i_mapping, 0, -1);
73 ff->fh = outarg->fh;
74 file->private_data = ff;
77 int fuse_open_common(struct inode *inode, struct file *file, int isdir)
79 struct fuse_open_out outarg;
80 struct fuse_file *ff;
81 int err;
83 /* VFS checks this, but only _after_ ->open() */
84 if (file->f_flags & O_DIRECT)
85 return -EINVAL;
87 err = generic_file_open(inode, file);
88 if (err)
89 return err;
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) {
94 err = fuse_do_getattr(inode);
95 if (err)
96 return err;
99 ff = fuse_file_alloc();
100 if (!ff)
101 return -ENOMEM;
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);
112 return err;
115 struct fuse_req *fuse_release_fill(struct fuse_file *ff, u64 nodeid, int flags,
116 int opcode)
118 struct fuse_req *req = ff->reserved_req;
119 struct fuse_release_in *inarg = &req->misc.release_in;
121 inarg->fh = ff->fh;
122 inarg->flags = flags;
123 req->in.h.opcode = opcode;
124 req->in.h.nodeid = nodeid;
125 req->in.numargs = 1;
126 req->in.args[0].size = sizeof(struct fuse_release_in);
127 req->in.args[0].value = inarg;
128 kfree(ff);
130 return req;
133 int fuse_release_common(struct inode *inode, struct file *file, int isdir)
135 struct fuse_file *ff = file->private_data;
136 if (ff) {
137 struct fuse_conn *fc = get_fuse_conn(inode);
138 struct fuse_req *req;
140 req = fuse_release_fill(ff, get_node_id(inode), file->f_flags,
141 isdir ? FUSE_RELEASEDIR : FUSE_RELEASE);
143 /* Hold vfsmount and dentry until release is finished */
144 req->vfsmount = mntget(file->f_path.mnt);
145 req->dentry = dget(file->f_path.dentry);
146 request_send_background(fc, req);
149 /* Return value is ignored by VFS */
150 return 0;
153 static int fuse_open(struct inode *inode, struct file *file)
155 return fuse_open_common(inode, file, 0);
158 static int fuse_release(struct inode *inode, struct file *file)
160 return fuse_release_common(inode, file, 0);
164 * Scramble the ID space with XTEA, so that the value of the files_struct
165 * pointer is not exposed to userspace.
167 static u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id)
169 u32 *k = fc->scramble_key;
170 u64 v = (unsigned long) id;
171 u32 v0 = v;
172 u32 v1 = v >> 32;
173 u32 sum = 0;
174 int i;
176 for (i = 0; i < 32; i++) {
177 v0 += ((v1 << 4 ^ v1 >> 5) + v1) ^ (sum + k[sum & 3]);
178 sum += 0x9E3779B9;
179 v1 += ((v0 << 4 ^ v0 >> 5) + v0) ^ (sum + k[sum>>11 & 3]);
182 return (u64) v0 + ((u64) v1 << 32);
185 static int fuse_flush(struct file *file, fl_owner_t id)
187 struct inode *inode = file->f_path.dentry->d_inode;
188 struct fuse_conn *fc = get_fuse_conn(inode);
189 struct fuse_file *ff = file->private_data;
190 struct fuse_req *req;
191 struct fuse_flush_in inarg;
192 int err;
194 if (is_bad_inode(inode))
195 return -EIO;
197 if (fc->no_flush)
198 return 0;
200 req = fuse_get_req_nofail(fc, file);
201 memset(&inarg, 0, sizeof(inarg));
202 inarg.fh = ff->fh;
203 inarg.lock_owner = fuse_lock_owner_id(fc, id);
204 req->in.h.opcode = FUSE_FLUSH;
205 req->in.h.nodeid = get_node_id(inode);
206 req->in.numargs = 1;
207 req->in.args[0].size = sizeof(inarg);
208 req->in.args[0].value = &inarg;
209 req->force = 1;
210 request_send(fc, req);
211 err = req->out.h.error;
212 fuse_put_request(fc, req);
213 if (err == -ENOSYS) {
214 fc->no_flush = 1;
215 err = 0;
217 return err;
220 int fuse_fsync_common(struct file *file, struct dentry *de, int datasync,
221 int isdir)
223 struct inode *inode = de->d_inode;
224 struct fuse_conn *fc = get_fuse_conn(inode);
225 struct fuse_file *ff = file->private_data;
226 struct fuse_req *req;
227 struct fuse_fsync_in inarg;
228 int err;
230 if (is_bad_inode(inode))
231 return -EIO;
233 if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir))
234 return 0;
236 req = fuse_get_req(fc);
237 if (IS_ERR(req))
238 return PTR_ERR(req);
240 memset(&inarg, 0, sizeof(inarg));
241 inarg.fh = ff->fh;
242 inarg.fsync_flags = datasync ? 1 : 0;
243 req->in.h.opcode = isdir ? FUSE_FSYNCDIR : FUSE_FSYNC;
244 req->in.h.nodeid = get_node_id(inode);
245 req->in.numargs = 1;
246 req->in.args[0].size = sizeof(inarg);
247 req->in.args[0].value = &inarg;
248 request_send(fc, req);
249 err = req->out.h.error;
250 fuse_put_request(fc, req);
251 if (err == -ENOSYS) {
252 if (isdir)
253 fc->no_fsyncdir = 1;
254 else
255 fc->no_fsync = 1;
256 err = 0;
258 return err;
261 static int fuse_fsync(struct file *file, struct dentry *de, int datasync)
263 return fuse_fsync_common(file, de, datasync, 0);
266 void fuse_read_fill(struct fuse_req *req, struct file *file,
267 struct inode *inode, loff_t pos, size_t count, int opcode)
269 struct fuse_file *ff = file->private_data;
270 struct fuse_read_in *inarg = &req->misc.read_in;
272 inarg->fh = ff->fh;
273 inarg->offset = pos;
274 inarg->size = count;
275 req->in.h.opcode = opcode;
276 req->in.h.nodeid = get_node_id(inode);
277 req->in.numargs = 1;
278 req->in.args[0].size = sizeof(struct fuse_read_in);
279 req->in.args[0].value = inarg;
280 req->out.argpages = 1;
281 req->out.argvar = 1;
282 req->out.numargs = 1;
283 req->out.args[0].size = count;
286 static size_t fuse_send_read(struct fuse_req *req, struct file *file,
287 struct inode *inode, loff_t pos, size_t count)
289 struct fuse_conn *fc = get_fuse_conn(inode);
290 fuse_read_fill(req, file, inode, pos, count, FUSE_READ);
291 request_send(fc, req);
292 return req->out.args[0].size;
295 static int fuse_readpage(struct file *file, struct page *page)
297 struct inode *inode = page->mapping->host;
298 struct fuse_conn *fc = get_fuse_conn(inode);
299 struct fuse_req *req;
300 int err;
302 err = -EIO;
303 if (is_bad_inode(inode))
304 goto out;
306 req = fuse_get_req(fc);
307 err = PTR_ERR(req);
308 if (IS_ERR(req))
309 goto out;
311 req->out.page_zeroing = 1;
312 req->num_pages = 1;
313 req->pages[0] = page;
314 fuse_send_read(req, file, inode, page_offset(page), PAGE_CACHE_SIZE);
315 err = req->out.h.error;
316 fuse_put_request(fc, req);
317 if (!err)
318 SetPageUptodate(page);
319 fuse_invalidate_attr(inode); /* atime changed */
320 out:
321 unlock_page(page);
322 return err;
325 static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_req *req)
327 int i;
329 fuse_invalidate_attr(req->pages[0]->mapping->host); /* atime changed */
331 for (i = 0; i < req->num_pages; i++) {
332 struct page *page = req->pages[i];
333 if (!req->out.h.error)
334 SetPageUptodate(page);
335 else
336 SetPageError(page);
337 unlock_page(page);
339 fuse_put_request(fc, req);
342 static void fuse_send_readpages(struct fuse_req *req, struct file *file,
343 struct inode *inode)
345 struct fuse_conn *fc = get_fuse_conn(inode);
346 loff_t pos = page_offset(req->pages[0]);
347 size_t count = req->num_pages << PAGE_CACHE_SHIFT;
348 req->out.page_zeroing = 1;
349 fuse_read_fill(req, file, inode, pos, count, FUSE_READ);
350 if (fc->async_read) {
351 get_file(file);
352 req->file = file;
353 req->end = fuse_readpages_end;
354 request_send_background(fc, req);
355 } else {
356 request_send(fc, req);
357 fuse_readpages_end(fc, req);
361 struct fuse_readpages_data {
362 struct fuse_req *req;
363 struct file *file;
364 struct inode *inode;
367 static int fuse_readpages_fill(void *_data, struct page *page)
369 struct fuse_readpages_data *data = _data;
370 struct fuse_req *req = data->req;
371 struct inode *inode = data->inode;
372 struct fuse_conn *fc = get_fuse_conn(inode);
374 if (req->num_pages &&
375 (req->num_pages == FUSE_MAX_PAGES_PER_REQ ||
376 (req->num_pages + 1) * PAGE_CACHE_SIZE > fc->max_read ||
377 req->pages[req->num_pages - 1]->index + 1 != page->index)) {
378 fuse_send_readpages(req, data->file, inode);
379 data->req = req = fuse_get_req(fc);
380 if (IS_ERR(req)) {
381 unlock_page(page);
382 return PTR_ERR(req);
385 req->pages[req->num_pages] = page;
386 req->num_pages ++;
387 return 0;
390 static int fuse_readpages(struct file *file, struct address_space *mapping,
391 struct list_head *pages, unsigned nr_pages)
393 struct inode *inode = mapping->host;
394 struct fuse_conn *fc = get_fuse_conn(inode);
395 struct fuse_readpages_data data;
396 int err;
398 err = -EIO;
399 if (is_bad_inode(inode))
400 goto out;
402 data.file = file;
403 data.inode = inode;
404 data.req = fuse_get_req(fc);
405 err = PTR_ERR(data.req);
406 if (IS_ERR(data.req))
407 goto out;
409 err = read_cache_pages(mapping, pages, fuse_readpages_fill, &data);
410 if (!err) {
411 if (data.req->num_pages)
412 fuse_send_readpages(data.req, file, inode);
413 else
414 fuse_put_request(fc, data.req);
416 out:
417 return err;
420 static size_t fuse_send_write(struct fuse_req *req, struct file *file,
421 struct inode *inode, loff_t pos, size_t count)
423 struct fuse_conn *fc = get_fuse_conn(inode);
424 struct fuse_file *ff = file->private_data;
425 struct fuse_write_in inarg;
426 struct fuse_write_out outarg;
428 memset(&inarg, 0, sizeof(struct fuse_write_in));
429 inarg.fh = ff->fh;
430 inarg.offset = pos;
431 inarg.size = count;
432 req->in.h.opcode = FUSE_WRITE;
433 req->in.h.nodeid = get_node_id(inode);
434 req->in.argpages = 1;
435 req->in.numargs = 2;
436 req->in.args[0].size = sizeof(struct fuse_write_in);
437 req->in.args[0].value = &inarg;
438 req->in.args[1].size = count;
439 req->out.numargs = 1;
440 req->out.args[0].size = sizeof(struct fuse_write_out);
441 req->out.args[0].value = &outarg;
442 request_send(fc, req);
443 return outarg.size;
446 static int fuse_prepare_write(struct file *file, struct page *page,
447 unsigned offset, unsigned to)
449 /* No op */
450 return 0;
453 static int fuse_commit_write(struct file *file, struct page *page,
454 unsigned offset, unsigned to)
456 int err;
457 size_t nres;
458 unsigned count = to - offset;
459 struct inode *inode = page->mapping->host;
460 struct fuse_conn *fc = get_fuse_conn(inode);
461 loff_t pos = page_offset(page) + offset;
462 struct fuse_req *req;
464 if (is_bad_inode(inode))
465 return -EIO;
467 req = fuse_get_req(fc);
468 if (IS_ERR(req))
469 return PTR_ERR(req);
471 req->num_pages = 1;
472 req->pages[0] = page;
473 req->page_offset = offset;
474 nres = fuse_send_write(req, file, inode, pos, count);
475 err = req->out.h.error;
476 fuse_put_request(fc, req);
477 if (!err && nres != count)
478 err = -EIO;
479 if (!err) {
480 pos += count;
481 spin_lock(&fc->lock);
482 if (pos > inode->i_size)
483 i_size_write(inode, pos);
484 spin_unlock(&fc->lock);
486 if (offset == 0 && to == PAGE_CACHE_SIZE)
487 SetPageUptodate(page);
489 fuse_invalidate_attr(inode);
490 return err;
493 static void fuse_release_user_pages(struct fuse_req *req, int write)
495 unsigned i;
497 for (i = 0; i < req->num_pages; i++) {
498 struct page *page = req->pages[i];
499 if (write)
500 set_page_dirty_lock(page);
501 put_page(page);
505 static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf,
506 unsigned nbytes, int write)
508 unsigned long user_addr = (unsigned long) buf;
509 unsigned offset = user_addr & ~PAGE_MASK;
510 int npages;
512 /* This doesn't work with nfsd */
513 if (!current->mm)
514 return -EPERM;
516 nbytes = min(nbytes, (unsigned) FUSE_MAX_PAGES_PER_REQ << PAGE_SHIFT);
517 npages = (nbytes + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
518 npages = min(max(npages, 1), FUSE_MAX_PAGES_PER_REQ);
519 down_read(&current->mm->mmap_sem);
520 npages = get_user_pages(current, current->mm, user_addr, npages, write,
521 0, req->pages, NULL);
522 up_read(&current->mm->mmap_sem);
523 if (npages < 0)
524 return npages;
526 req->num_pages = npages;
527 req->page_offset = offset;
528 return 0;
531 static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
532 size_t count, loff_t *ppos, int write)
534 struct inode *inode = file->f_path.dentry->d_inode;
535 struct fuse_conn *fc = get_fuse_conn(inode);
536 size_t nmax = write ? fc->max_write : fc->max_read;
537 loff_t pos = *ppos;
538 ssize_t res = 0;
539 struct fuse_req *req;
541 if (is_bad_inode(inode))
542 return -EIO;
544 req = fuse_get_req(fc);
545 if (IS_ERR(req))
546 return PTR_ERR(req);
548 while (count) {
549 size_t nres;
550 size_t nbytes = min(count, nmax);
551 int err = fuse_get_user_pages(req, buf, nbytes, !write);
552 if (err) {
553 res = err;
554 break;
556 nbytes = (req->num_pages << PAGE_SHIFT) - req->page_offset;
557 nbytes = min(count, nbytes);
558 if (write)
559 nres = fuse_send_write(req, file, inode, pos, nbytes);
560 else
561 nres = fuse_send_read(req, file, inode, pos, nbytes);
562 fuse_release_user_pages(req, !write);
563 if (req->out.h.error) {
564 if (!res)
565 res = req->out.h.error;
566 break;
567 } else if (nres > nbytes) {
568 res = -EIO;
569 break;
571 count -= nres;
572 res += nres;
573 pos += nres;
574 buf += nres;
575 if (nres != nbytes)
576 break;
577 if (count) {
578 fuse_put_request(fc, req);
579 req = fuse_get_req(fc);
580 if (IS_ERR(req))
581 break;
584 fuse_put_request(fc, req);
585 if (res > 0) {
586 if (write) {
587 spin_lock(&fc->lock);
588 if (pos > inode->i_size)
589 i_size_write(inode, pos);
590 spin_unlock(&fc->lock);
592 *ppos = pos;
594 fuse_invalidate_attr(inode);
596 return res;
599 static ssize_t fuse_direct_read(struct file *file, char __user *buf,
600 size_t count, loff_t *ppos)
602 return fuse_direct_io(file, buf, count, ppos, 0);
605 static ssize_t fuse_direct_write(struct file *file, const char __user *buf,
606 size_t count, loff_t *ppos)
608 struct inode *inode = file->f_path.dentry->d_inode;
609 ssize_t res;
610 /* Don't allow parallel writes to the same file */
611 mutex_lock(&inode->i_mutex);
612 res = fuse_direct_io(file, buf, count, ppos, 1);
613 mutex_unlock(&inode->i_mutex);
614 return res;
617 static int fuse_file_mmap(struct file *file, struct vm_area_struct *vma)
619 if ((vma->vm_flags & VM_SHARED)) {
620 if ((vma->vm_flags & VM_WRITE))
621 return -ENODEV;
622 else
623 vma->vm_flags &= ~VM_MAYWRITE;
625 return generic_file_mmap(file, vma);
628 static int fuse_set_page_dirty(struct page *page)
630 printk("fuse_set_page_dirty: should not happen\n");
631 dump_stack();
632 return 0;
635 static int convert_fuse_file_lock(const struct fuse_file_lock *ffl,
636 struct file_lock *fl)
638 switch (ffl->type) {
639 case F_UNLCK:
640 break;
642 case F_RDLCK:
643 case F_WRLCK:
644 if (ffl->start > OFFSET_MAX || ffl->end > OFFSET_MAX ||
645 ffl->end < ffl->start)
646 return -EIO;
648 fl->fl_start = ffl->start;
649 fl->fl_end = ffl->end;
650 fl->fl_pid = ffl->pid;
651 break;
653 default:
654 return -EIO;
656 fl->fl_type = ffl->type;
657 return 0;
660 static void fuse_lk_fill(struct fuse_req *req, struct file *file,
661 const struct file_lock *fl, int opcode, pid_t pid)
663 struct inode *inode = file->f_path.dentry->d_inode;
664 struct fuse_conn *fc = get_fuse_conn(inode);
665 struct fuse_file *ff = file->private_data;
666 struct fuse_lk_in *arg = &req->misc.lk_in;
668 arg->fh = ff->fh;
669 arg->owner = fuse_lock_owner_id(fc, fl->fl_owner);
670 arg->lk.start = fl->fl_start;
671 arg->lk.end = fl->fl_end;
672 arg->lk.type = fl->fl_type;
673 arg->lk.pid = pid;
674 req->in.h.opcode = opcode;
675 req->in.h.nodeid = get_node_id(inode);
676 req->in.numargs = 1;
677 req->in.args[0].size = sizeof(*arg);
678 req->in.args[0].value = arg;
681 static int fuse_getlk(struct file *file, struct file_lock *fl)
683 struct inode *inode = file->f_path.dentry->d_inode;
684 struct fuse_conn *fc = get_fuse_conn(inode);
685 struct fuse_req *req;
686 struct fuse_lk_out outarg;
687 int err;
689 req = fuse_get_req(fc);
690 if (IS_ERR(req))
691 return PTR_ERR(req);
693 fuse_lk_fill(req, file, fl, FUSE_GETLK, 0);
694 req->out.numargs = 1;
695 req->out.args[0].size = sizeof(outarg);
696 req->out.args[0].value = &outarg;
697 request_send(fc, req);
698 err = req->out.h.error;
699 fuse_put_request(fc, req);
700 if (!err)
701 err = convert_fuse_file_lock(&outarg.lk, fl);
703 return err;
706 static int fuse_setlk(struct file *file, struct file_lock *fl)
708 struct inode *inode = file->f_path.dentry->d_inode;
709 struct fuse_conn *fc = get_fuse_conn(inode);
710 struct fuse_req *req;
711 int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK;
712 pid_t pid = fl->fl_type != F_UNLCK ? current->tgid : 0;
713 int err;
715 /* Unlock on close is handled by the flush method */
716 if (fl->fl_flags & FL_CLOSE)
717 return 0;
719 req = fuse_get_req(fc);
720 if (IS_ERR(req))
721 return PTR_ERR(req);
723 fuse_lk_fill(req, file, fl, opcode, pid);
724 request_send(fc, req);
725 err = req->out.h.error;
726 /* locking is restartable */
727 if (err == -EINTR)
728 err = -ERESTARTSYS;
729 fuse_put_request(fc, req);
730 return err;
733 static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl)
735 struct inode *inode = file->f_path.dentry->d_inode;
736 struct fuse_conn *fc = get_fuse_conn(inode);
737 int err;
739 if (cmd == F_GETLK) {
740 if (fc->no_lock) {
741 if (!posix_test_lock(file, fl, fl))
742 fl->fl_type = F_UNLCK;
743 err = 0;
744 } else
745 err = fuse_getlk(file, fl);
746 } else {
747 if (fc->no_lock)
748 err = posix_lock_file_wait(file, fl);
749 else
750 err = fuse_setlk(file, fl);
752 return err;
755 static sector_t fuse_bmap(struct address_space *mapping, sector_t block)
757 struct inode *inode = mapping->host;
758 struct fuse_conn *fc = get_fuse_conn(inode);
759 struct fuse_req *req;
760 struct fuse_bmap_in inarg;
761 struct fuse_bmap_out outarg;
762 int err;
764 if (!inode->i_sb->s_bdev || fc->no_bmap)
765 return 0;
767 req = fuse_get_req(fc);
768 if (IS_ERR(req))
769 return 0;
771 memset(&inarg, 0, sizeof(inarg));
772 inarg.block = block;
773 inarg.blocksize = inode->i_sb->s_blocksize;
774 req->in.h.opcode = FUSE_BMAP;
775 req->in.h.nodeid = get_node_id(inode);
776 req->in.numargs = 1;
777 req->in.args[0].size = sizeof(inarg);
778 req->in.args[0].value = &inarg;
779 req->out.numargs = 1;
780 req->out.args[0].size = sizeof(outarg);
781 req->out.args[0].value = &outarg;
782 request_send(fc, req);
783 err = req->out.h.error;
784 fuse_put_request(fc, req);
785 if (err == -ENOSYS)
786 fc->no_bmap = 1;
788 return err ? 0 : outarg.block;
791 static const struct file_operations fuse_file_operations = {
792 .llseek = generic_file_llseek,
793 .read = do_sync_read,
794 .aio_read = generic_file_aio_read,
795 .write = do_sync_write,
796 .aio_write = generic_file_aio_write,
797 .mmap = fuse_file_mmap,
798 .open = fuse_open,
799 .flush = fuse_flush,
800 .release = fuse_release,
801 .fsync = fuse_fsync,
802 .lock = fuse_file_lock,
803 .sendfile = generic_file_sendfile,
806 static const struct file_operations fuse_direct_io_file_operations = {
807 .llseek = generic_file_llseek,
808 .read = fuse_direct_read,
809 .write = fuse_direct_write,
810 .open = fuse_open,
811 .flush = fuse_flush,
812 .release = fuse_release,
813 .fsync = fuse_fsync,
814 .lock = fuse_file_lock,
815 /* no mmap and sendfile */
818 static const struct address_space_operations fuse_file_aops = {
819 .readpage = fuse_readpage,
820 .prepare_write = fuse_prepare_write,
821 .commit_write = fuse_commit_write,
822 .readpages = fuse_readpages,
823 .set_page_dirty = fuse_set_page_dirty,
824 .bmap = fuse_bmap,
827 void fuse_init_file_inode(struct inode *inode)
829 inode->i_fop = &fuse_file_operations;
830 inode->i_data.a_ops = &fuse_file_aops;