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.
11 #include <linux/pagemap.h>
12 #include <linux/slab.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
16 static const struct file_operations fuse_direct_io_file_operations
;
18 static int fuse_send_open(struct inode
*inode
, struct file
*file
, int isdir
,
19 struct fuse_open_out
*outargp
)
21 struct fuse_conn
*fc
= get_fuse_conn(inode
);
22 struct fuse_open_in inarg
;
26 req
= fuse_get_req(fc
);
30 memset(&inarg
, 0, sizeof(inarg
));
31 inarg
.flags
= file
->f_flags
& ~(O_CREAT
| O_EXCL
| O_NOCTTY
);
32 if (!fc
->atomic_o_trunc
)
33 inarg
.flags
&= ~O_TRUNC
;
34 req
->in
.h
.opcode
= isdir
? FUSE_OPENDIR
: FUSE_OPEN
;
35 req
->in
.h
.nodeid
= get_node_id(inode
);
37 req
->in
.args
[0].size
= sizeof(inarg
);
38 req
->in
.args
[0].value
= &inarg
;
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
);
49 struct fuse_file
*fuse_file_alloc(void)
52 ff
= kmalloc(sizeof(struct fuse_file
), GFP_KERNEL
);
54 ff
->reserved_req
= fuse_request_alloc();
55 if (!ff
->reserved_req
) {
59 atomic_set(&ff
->count
, 0);
64 void fuse_file_free(struct fuse_file
*ff
)
66 fuse_request_free(ff
->reserved_req
);
70 static struct fuse_file
*fuse_file_get(struct fuse_file
*ff
)
72 atomic_inc(&ff
->count
);
76 static void fuse_release_end(struct fuse_conn
*fc
, struct fuse_req
*req
)
79 mntput(req
->vfsmount
);
80 fuse_put_request(fc
, req
);
83 static void fuse_file_put(struct fuse_file
*ff
)
85 if (atomic_dec_and_test(&ff
->count
)) {
86 struct fuse_req
*req
= ff
->reserved_req
;
87 struct fuse_conn
*fc
= get_fuse_conn(req
->dentry
->d_inode
);
88 req
->end
= fuse_release_end
;
89 request_send_background(fc
, req
);
94 void fuse_finish_open(struct inode
*inode
, struct file
*file
,
95 struct fuse_file
*ff
, struct fuse_open_out
*outarg
)
97 if (outarg
->open_flags
& FOPEN_DIRECT_IO
)
98 file
->f_op
= &fuse_direct_io_file_operations
;
99 if (!(outarg
->open_flags
& FOPEN_KEEP_CACHE
))
100 invalidate_inode_pages2(inode
->i_mapping
);
102 file
->private_data
= fuse_file_get(ff
);
105 int fuse_open_common(struct inode
*inode
, struct file
*file
, int isdir
)
107 struct fuse_open_out outarg
;
108 struct fuse_file
*ff
;
111 /* VFS checks this, but only _after_ ->open() */
112 if (file
->f_flags
& O_DIRECT
)
115 err
= generic_file_open(inode
, file
);
119 ff
= fuse_file_alloc();
123 err
= fuse_send_open(inode
, file
, isdir
, &outarg
);
128 outarg
.open_flags
&= ~FOPEN_DIRECT_IO
;
129 fuse_finish_open(inode
, file
, ff
, &outarg
);
135 void fuse_release_fill(struct fuse_file
*ff
, u64 nodeid
, int flags
, int opcode
)
137 struct fuse_req
*req
= ff
->reserved_req
;
138 struct fuse_release_in
*inarg
= &req
->misc
.release_in
;
141 inarg
->flags
= flags
;
142 req
->in
.h
.opcode
= opcode
;
143 req
->in
.h
.nodeid
= nodeid
;
145 req
->in
.args
[0].size
= sizeof(struct fuse_release_in
);
146 req
->in
.args
[0].value
= inarg
;
149 int fuse_release_common(struct inode
*inode
, struct file
*file
, int isdir
)
151 struct fuse_file
*ff
= file
->private_data
;
153 fuse_release_fill(ff
, get_node_id(inode
), file
->f_flags
,
154 isdir
? FUSE_RELEASEDIR
: FUSE_RELEASE
);
156 /* Hold vfsmount and dentry until release is finished */
157 ff
->reserved_req
->vfsmount
= mntget(file
->f_path
.mnt
);
158 ff
->reserved_req
->dentry
= dget(file
->f_path
.dentry
);
160 * Normally this will send the RELEASE request,
161 * however if some asynchronous READ or WRITE requests
162 * are outstanding, the sending will be delayed
167 /* Return value is ignored by VFS */
171 static int fuse_open(struct inode
*inode
, struct file
*file
)
173 return fuse_open_common(inode
, file
, 0);
176 static int fuse_release(struct inode
*inode
, struct file
*file
)
178 return fuse_release_common(inode
, file
, 0);
182 * Scramble the ID space with XTEA, so that the value of the files_struct
183 * pointer is not exposed to userspace.
185 static u64
fuse_lock_owner_id(struct fuse_conn
*fc
, fl_owner_t id
)
187 u32
*k
= fc
->scramble_key
;
188 u64 v
= (unsigned long) id
;
194 for (i
= 0; i
< 32; i
++) {
195 v0
+= ((v1
<< 4 ^ v1
>> 5) + v1
) ^ (sum
+ k
[sum
& 3]);
197 v1
+= ((v0
<< 4 ^ v0
>> 5) + v0
) ^ (sum
+ k
[sum
>>11 & 3]);
200 return (u64
) v0
+ ((u64
) v1
<< 32);
203 static int fuse_flush(struct file
*file
, fl_owner_t id
)
205 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
206 struct fuse_conn
*fc
= get_fuse_conn(inode
);
207 struct fuse_file
*ff
= file
->private_data
;
208 struct fuse_req
*req
;
209 struct fuse_flush_in inarg
;
212 if (is_bad_inode(inode
))
218 req
= fuse_get_req_nofail(fc
, file
);
219 memset(&inarg
, 0, sizeof(inarg
));
221 inarg
.lock_owner
= fuse_lock_owner_id(fc
, id
);
222 req
->in
.h
.opcode
= FUSE_FLUSH
;
223 req
->in
.h
.nodeid
= get_node_id(inode
);
225 req
->in
.args
[0].size
= sizeof(inarg
);
226 req
->in
.args
[0].value
= &inarg
;
228 request_send(fc
, req
);
229 err
= req
->out
.h
.error
;
230 fuse_put_request(fc
, req
);
231 if (err
== -ENOSYS
) {
238 int fuse_fsync_common(struct file
*file
, struct dentry
*de
, int datasync
,
241 struct inode
*inode
= de
->d_inode
;
242 struct fuse_conn
*fc
= get_fuse_conn(inode
);
243 struct fuse_file
*ff
= file
->private_data
;
244 struct fuse_req
*req
;
245 struct fuse_fsync_in inarg
;
248 if (is_bad_inode(inode
))
251 if ((!isdir
&& fc
->no_fsync
) || (isdir
&& fc
->no_fsyncdir
))
254 req
= fuse_get_req(fc
);
258 memset(&inarg
, 0, sizeof(inarg
));
260 inarg
.fsync_flags
= datasync
? 1 : 0;
261 req
->in
.h
.opcode
= isdir
? FUSE_FSYNCDIR
: FUSE_FSYNC
;
262 req
->in
.h
.nodeid
= get_node_id(inode
);
264 req
->in
.args
[0].size
= sizeof(inarg
);
265 req
->in
.args
[0].value
= &inarg
;
266 request_send(fc
, req
);
267 err
= req
->out
.h
.error
;
268 fuse_put_request(fc
, req
);
269 if (err
== -ENOSYS
) {
279 static int fuse_fsync(struct file
*file
, struct dentry
*de
, int datasync
)
281 return fuse_fsync_common(file
, de
, datasync
, 0);
284 void fuse_read_fill(struct fuse_req
*req
, struct fuse_file
*ff
,
285 struct inode
*inode
, loff_t pos
, size_t count
, int opcode
)
287 struct fuse_read_in
*inarg
= &req
->misc
.read_in
;
292 req
->in
.h
.opcode
= opcode
;
293 req
->in
.h
.nodeid
= get_node_id(inode
);
295 req
->in
.args
[0].size
= sizeof(struct fuse_read_in
);
296 req
->in
.args
[0].value
= inarg
;
297 req
->out
.argpages
= 1;
299 req
->out
.numargs
= 1;
300 req
->out
.args
[0].size
= count
;
303 static size_t fuse_send_read(struct fuse_req
*req
, struct file
*file
,
304 struct inode
*inode
, loff_t pos
, size_t count
)
306 struct fuse_conn
*fc
= get_fuse_conn(inode
);
307 struct fuse_file
*ff
= file
->private_data
;
308 fuse_read_fill(req
, ff
, inode
, pos
, count
, FUSE_READ
);
309 request_send(fc
, req
);
310 return req
->out
.args
[0].size
;
313 static int fuse_readpage(struct file
*file
, struct page
*page
)
315 struct inode
*inode
= page
->mapping
->host
;
316 struct fuse_conn
*fc
= get_fuse_conn(inode
);
317 struct fuse_req
*req
;
321 if (is_bad_inode(inode
))
324 req
= fuse_get_req(fc
);
329 req
->out
.page_zeroing
= 1;
331 req
->pages
[0] = page
;
332 fuse_send_read(req
, file
, inode
, page_offset(page
), PAGE_CACHE_SIZE
);
333 err
= req
->out
.h
.error
;
334 fuse_put_request(fc
, req
);
336 SetPageUptodate(page
);
337 fuse_invalidate_attr(inode
); /* atime changed */
343 static void fuse_readpages_end(struct fuse_conn
*fc
, struct fuse_req
*req
)
347 fuse_invalidate_attr(req
->pages
[0]->mapping
->host
); /* atime changed */
349 for (i
= 0; i
< req
->num_pages
; i
++) {
350 struct page
*page
= req
->pages
[i
];
351 if (!req
->out
.h
.error
)
352 SetPageUptodate(page
);
358 fuse_file_put(req
->ff
);
359 fuse_put_request(fc
, req
);
362 static void fuse_send_readpages(struct fuse_req
*req
, struct fuse_file
*ff
,
365 struct fuse_conn
*fc
= get_fuse_conn(inode
);
366 loff_t pos
= page_offset(req
->pages
[0]);
367 size_t count
= req
->num_pages
<< PAGE_CACHE_SHIFT
;
368 req
->out
.page_zeroing
= 1;
369 fuse_read_fill(req
, ff
, inode
, pos
, count
, FUSE_READ
);
370 if (fc
->async_read
) {
371 req
->ff
= fuse_file_get(ff
);
372 req
->end
= fuse_readpages_end
;
373 request_send_background(fc
, req
);
375 request_send(fc
, req
);
376 fuse_readpages_end(fc
, req
);
380 struct fuse_fill_data
{
381 struct fuse_req
*req
;
382 struct fuse_file
*ff
;
386 static int fuse_readpages_fill(void *_data
, struct page
*page
)
388 struct fuse_fill_data
*data
= _data
;
389 struct fuse_req
*req
= data
->req
;
390 struct inode
*inode
= data
->inode
;
391 struct fuse_conn
*fc
= get_fuse_conn(inode
);
393 if (req
->num_pages
&&
394 (req
->num_pages
== FUSE_MAX_PAGES_PER_REQ
||
395 (req
->num_pages
+ 1) * PAGE_CACHE_SIZE
> fc
->max_read
||
396 req
->pages
[req
->num_pages
- 1]->index
+ 1 != page
->index
)) {
397 fuse_send_readpages(req
, data
->ff
, inode
);
398 data
->req
= req
= fuse_get_req(fc
);
404 req
->pages
[req
->num_pages
] = page
;
409 static int fuse_readpages(struct file
*file
, struct address_space
*mapping
,
410 struct list_head
*pages
, unsigned nr_pages
)
412 struct inode
*inode
= mapping
->host
;
413 struct fuse_conn
*fc
= get_fuse_conn(inode
);
414 struct fuse_fill_data data
;
418 if (is_bad_inode(inode
))
421 data
.ff
= file
->private_data
;
423 data
.req
= fuse_get_req(fc
);
424 err
= PTR_ERR(data
.req
);
425 if (IS_ERR(data
.req
))
428 err
= read_cache_pages(mapping
, pages
, fuse_readpages_fill
, &data
);
430 if (data
.req
->num_pages
)
431 fuse_send_readpages(data
.req
, data
.ff
, inode
);
433 fuse_put_request(fc
, data
.req
);
439 static size_t fuse_send_write(struct fuse_req
*req
, struct file
*file
,
440 struct inode
*inode
, loff_t pos
, size_t count
)
442 struct fuse_conn
*fc
= get_fuse_conn(inode
);
443 struct fuse_file
*ff
= file
->private_data
;
444 struct fuse_write_in inarg
;
445 struct fuse_write_out outarg
;
447 memset(&inarg
, 0, sizeof(struct fuse_write_in
));
451 req
->in
.h
.opcode
= FUSE_WRITE
;
452 req
->in
.h
.nodeid
= get_node_id(inode
);
453 req
->in
.argpages
= 1;
455 req
->in
.args
[0].size
= sizeof(struct fuse_write_in
);
456 req
->in
.args
[0].value
= &inarg
;
457 req
->in
.args
[1].size
= count
;
458 req
->out
.numargs
= 1;
459 req
->out
.args
[0].size
= sizeof(struct fuse_write_out
);
460 req
->out
.args
[0].value
= &outarg
;
461 request_send(fc
, req
);
465 static int fuse_write_begin(struct file
*file
, struct address_space
*mapping
,
466 loff_t pos
, unsigned len
, unsigned flags
,
467 struct page
**pagep
, void **fsdata
)
469 pgoff_t index
= pos
>> PAGE_CACHE_SHIFT
;
471 *pagep
= __grab_cache_page(mapping
, index
);
477 static int fuse_buffered_write(struct file
*file
, struct inode
*inode
,
478 loff_t pos
, unsigned count
, struct page
*page
)
482 struct fuse_conn
*fc
= get_fuse_conn(inode
);
483 struct fuse_inode
*fi
= get_fuse_inode(inode
);
484 unsigned offset
= pos
& (PAGE_CACHE_SIZE
- 1);
485 struct fuse_req
*req
;
487 if (is_bad_inode(inode
))
490 req
= fuse_get_req(fc
);
495 req
->pages
[0] = page
;
496 req
->page_offset
= offset
;
497 nres
= fuse_send_write(req
, file
, inode
, pos
, count
);
498 err
= req
->out
.h
.error
;
499 fuse_put_request(fc
, req
);
504 spin_lock(&fc
->lock
);
505 fi
->attr_version
= ++fc
->attr_version
;
506 if (pos
> inode
->i_size
)
507 i_size_write(inode
, pos
);
508 spin_unlock(&fc
->lock
);
510 if (count
== PAGE_CACHE_SIZE
)
511 SetPageUptodate(page
);
513 fuse_invalidate_attr(inode
);
514 return err
? err
: nres
;
517 static int fuse_write_end(struct file
*file
, struct address_space
*mapping
,
518 loff_t pos
, unsigned len
, unsigned copied
,
519 struct page
*page
, void *fsdata
)
521 struct inode
*inode
= mapping
->host
;
525 res
= fuse_buffered_write(file
, inode
, pos
, copied
, page
);
528 page_cache_release(page
);
532 static void fuse_release_user_pages(struct fuse_req
*req
, int write
)
536 for (i
= 0; i
< req
->num_pages
; i
++) {
537 struct page
*page
= req
->pages
[i
];
539 set_page_dirty_lock(page
);
544 static int fuse_get_user_pages(struct fuse_req
*req
, const char __user
*buf
,
545 unsigned nbytes
, int write
)
547 unsigned long user_addr
= (unsigned long) buf
;
548 unsigned offset
= user_addr
& ~PAGE_MASK
;
551 /* This doesn't work with nfsd */
555 nbytes
= min(nbytes
, (unsigned) FUSE_MAX_PAGES_PER_REQ
<< PAGE_SHIFT
);
556 npages
= (nbytes
+ offset
+ PAGE_SIZE
- 1) >> PAGE_SHIFT
;
557 npages
= min(max(npages
, 1), FUSE_MAX_PAGES_PER_REQ
);
558 down_read(¤t
->mm
->mmap_sem
);
559 npages
= get_user_pages(current
, current
->mm
, user_addr
, npages
, write
,
560 0, req
->pages
, NULL
);
561 up_read(¤t
->mm
->mmap_sem
);
565 req
->num_pages
= npages
;
566 req
->page_offset
= offset
;
570 static ssize_t
fuse_direct_io(struct file
*file
, const char __user
*buf
,
571 size_t count
, loff_t
*ppos
, int write
)
573 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
574 struct fuse_conn
*fc
= get_fuse_conn(inode
);
575 size_t nmax
= write
? fc
->max_write
: fc
->max_read
;
578 struct fuse_req
*req
;
580 if (is_bad_inode(inode
))
583 req
= fuse_get_req(fc
);
589 size_t nbytes
= min(count
, nmax
);
590 int err
= fuse_get_user_pages(req
, buf
, nbytes
, !write
);
595 nbytes
= (req
->num_pages
<< PAGE_SHIFT
) - req
->page_offset
;
596 nbytes
= min(count
, nbytes
);
598 nres
= fuse_send_write(req
, file
, inode
, pos
, nbytes
);
600 nres
= fuse_send_read(req
, file
, inode
, pos
, nbytes
);
601 fuse_release_user_pages(req
, !write
);
602 if (req
->out
.h
.error
) {
604 res
= req
->out
.h
.error
;
606 } else if (nres
> nbytes
) {
617 fuse_put_request(fc
, req
);
618 req
= fuse_get_req(fc
);
623 fuse_put_request(fc
, req
);
626 spin_lock(&fc
->lock
);
627 if (pos
> inode
->i_size
)
628 i_size_write(inode
, pos
);
629 spin_unlock(&fc
->lock
);
633 fuse_invalidate_attr(inode
);
638 static ssize_t
fuse_direct_read(struct file
*file
, char __user
*buf
,
639 size_t count
, loff_t
*ppos
)
641 return fuse_direct_io(file
, buf
, count
, ppos
, 0);
644 static ssize_t
fuse_direct_write(struct file
*file
, const char __user
*buf
,
645 size_t count
, loff_t
*ppos
)
647 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
649 /* Don't allow parallel writes to the same file */
650 mutex_lock(&inode
->i_mutex
);
651 res
= generic_write_checks(file
, ppos
, &count
, 0);
653 res
= fuse_direct_io(file
, buf
, count
, ppos
, 1);
654 mutex_unlock(&inode
->i_mutex
);
658 static int fuse_file_mmap(struct file
*file
, struct vm_area_struct
*vma
)
660 if ((vma
->vm_flags
& VM_SHARED
)) {
661 if ((vma
->vm_flags
& VM_WRITE
))
664 vma
->vm_flags
&= ~VM_MAYWRITE
;
666 return generic_file_mmap(file
, vma
);
669 static int fuse_set_page_dirty(struct page
*page
)
671 printk("fuse_set_page_dirty: should not happen\n");
676 static int convert_fuse_file_lock(const struct fuse_file_lock
*ffl
,
677 struct file_lock
*fl
)
685 if (ffl
->start
> OFFSET_MAX
|| ffl
->end
> OFFSET_MAX
||
686 ffl
->end
< ffl
->start
)
689 fl
->fl_start
= ffl
->start
;
690 fl
->fl_end
= ffl
->end
;
691 fl
->fl_pid
= ffl
->pid
;
697 fl
->fl_type
= ffl
->type
;
701 static void fuse_lk_fill(struct fuse_req
*req
, struct file
*file
,
702 const struct file_lock
*fl
, int opcode
, pid_t pid
,
705 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
706 struct fuse_conn
*fc
= get_fuse_conn(inode
);
707 struct fuse_file
*ff
= file
->private_data
;
708 struct fuse_lk_in
*arg
= &req
->misc
.lk_in
;
711 arg
->owner
= fuse_lock_owner_id(fc
, fl
->fl_owner
);
712 arg
->lk
.start
= fl
->fl_start
;
713 arg
->lk
.end
= fl
->fl_end
;
714 arg
->lk
.type
= fl
->fl_type
;
717 arg
->lk_flags
|= FUSE_LK_FLOCK
;
718 req
->in
.h
.opcode
= opcode
;
719 req
->in
.h
.nodeid
= get_node_id(inode
);
721 req
->in
.args
[0].size
= sizeof(*arg
);
722 req
->in
.args
[0].value
= arg
;
725 static int fuse_getlk(struct file
*file
, struct file_lock
*fl
)
727 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
728 struct fuse_conn
*fc
= get_fuse_conn(inode
);
729 struct fuse_req
*req
;
730 struct fuse_lk_out outarg
;
733 req
= fuse_get_req(fc
);
737 fuse_lk_fill(req
, file
, fl
, FUSE_GETLK
, 0, 0);
738 req
->out
.numargs
= 1;
739 req
->out
.args
[0].size
= sizeof(outarg
);
740 req
->out
.args
[0].value
= &outarg
;
741 request_send(fc
, req
);
742 err
= req
->out
.h
.error
;
743 fuse_put_request(fc
, req
);
745 err
= convert_fuse_file_lock(&outarg
.lk
, fl
);
750 static int fuse_setlk(struct file
*file
, struct file_lock
*fl
, int flock
)
752 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
753 struct fuse_conn
*fc
= get_fuse_conn(inode
);
754 struct fuse_req
*req
;
755 int opcode
= (fl
->fl_flags
& FL_SLEEP
) ? FUSE_SETLKW
: FUSE_SETLK
;
756 pid_t pid
= fl
->fl_type
!= F_UNLCK
? current
->tgid
: 0;
759 /* Unlock on close is handled by the flush method */
760 if (fl
->fl_flags
& FL_CLOSE
)
763 req
= fuse_get_req(fc
);
767 fuse_lk_fill(req
, file
, fl
, opcode
, pid
, flock
);
768 request_send(fc
, req
);
769 err
= req
->out
.h
.error
;
770 /* locking is restartable */
773 fuse_put_request(fc
, req
);
777 static int fuse_file_lock(struct file
*file
, int cmd
, struct file_lock
*fl
)
779 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
780 struct fuse_conn
*fc
= get_fuse_conn(inode
);
783 if (cmd
== F_GETLK
) {
785 posix_test_lock(file
, fl
);
788 err
= fuse_getlk(file
, fl
);
791 err
= posix_lock_file_wait(file
, fl
);
793 err
= fuse_setlk(file
, fl
, 0);
798 static int fuse_file_flock(struct file
*file
, int cmd
, struct file_lock
*fl
)
800 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
801 struct fuse_conn
*fc
= get_fuse_conn(inode
);
805 err
= flock_lock_file_wait(file
, fl
);
807 /* emulate flock with POSIX locks */
808 fl
->fl_owner
= (fl_owner_t
) file
;
809 err
= fuse_setlk(file
, fl
, 1);
815 static sector_t
fuse_bmap(struct address_space
*mapping
, sector_t block
)
817 struct inode
*inode
= mapping
->host
;
818 struct fuse_conn
*fc
= get_fuse_conn(inode
);
819 struct fuse_req
*req
;
820 struct fuse_bmap_in inarg
;
821 struct fuse_bmap_out outarg
;
824 if (!inode
->i_sb
->s_bdev
|| fc
->no_bmap
)
827 req
= fuse_get_req(fc
);
831 memset(&inarg
, 0, sizeof(inarg
));
833 inarg
.blocksize
= inode
->i_sb
->s_blocksize
;
834 req
->in
.h
.opcode
= FUSE_BMAP
;
835 req
->in
.h
.nodeid
= get_node_id(inode
);
837 req
->in
.args
[0].size
= sizeof(inarg
);
838 req
->in
.args
[0].value
= &inarg
;
839 req
->out
.numargs
= 1;
840 req
->out
.args
[0].size
= sizeof(outarg
);
841 req
->out
.args
[0].value
= &outarg
;
842 request_send(fc
, req
);
843 err
= req
->out
.h
.error
;
844 fuse_put_request(fc
, req
);
848 return err
? 0 : outarg
.block
;
851 static const struct file_operations fuse_file_operations
= {
852 .llseek
= generic_file_llseek
,
853 .read
= do_sync_read
,
854 .aio_read
= generic_file_aio_read
,
855 .write
= do_sync_write
,
856 .aio_write
= generic_file_aio_write
,
857 .mmap
= fuse_file_mmap
,
860 .release
= fuse_release
,
862 .lock
= fuse_file_lock
,
863 .flock
= fuse_file_flock
,
864 .splice_read
= generic_file_splice_read
,
867 static const struct file_operations fuse_direct_io_file_operations
= {
868 .llseek
= generic_file_llseek
,
869 .read
= fuse_direct_read
,
870 .write
= fuse_direct_write
,
873 .release
= fuse_release
,
875 .lock
= fuse_file_lock
,
876 .flock
= fuse_file_flock
,
877 /* no mmap and splice_read */
880 static const struct address_space_operations fuse_file_aops
= {
881 .readpage
= fuse_readpage
,
882 .write_begin
= fuse_write_begin
,
883 .write_end
= fuse_write_end
,
884 .readpages
= fuse_readpages
,
885 .set_page_dirty
= fuse_set_page_dirty
,
889 void fuse_init_file_inode(struct inode
*inode
)
891 inode
->i_fop
= &fuse_file_operations
;
892 inode
->i_data
.a_ops
= &fuse_file_aops
;