1
2
3
4
5
6
7
8
9#ifndef _FS_FUSE_I_H
10#define _FS_FUSE_I_H
11
12#include <linux/fuse.h>
13#include <linux/fs.h>
14#include <linux/mount.h>
15#include <linux/wait.h>
16#include <linux/list.h>
17#include <linux/spinlock.h>
18#include <linux/mm.h>
19#include <linux/backing-dev.h>
20#include <linux/mutex.h>
21#include <linux/rwsem.h>
22#include <linux/rbtree.h>
23#include <linux/poll.h>
24#include <linux/workqueue.h>
25#include <linux/kref.h>
26#include <linux/xattr.h>
27
28
29#define FUSE_MAX_PAGES_PER_REQ 32
30
31
32#define FUSE_NOWRITE INT_MIN
33
34
35#define FUSE_NAME_MAX 1024
36
37
38#define FUSE_CTL_NUM_DENTRIES 5
39
40
41#define FUSE_REQ_INLINE_PAGES 1
42
43
44extern struct list_head fuse_conn_list;
45
46
47extern struct mutex fuse_mutex;
48
49
50extern unsigned max_user_bgreq;
51extern unsigned max_user_congthresh;
52
53
54struct fuse_forget_link {
55 struct fuse_forget_one forget_one;
56 struct fuse_forget_link *next;
57};
58
59
60struct fuse_inode {
61
62 struct inode inode;
63
64
65
66 u64 nodeid;
67
68
69 u64 nlookup;
70
71
72 struct fuse_forget_link *forget;
73
74
75 u64 i_time;
76
77
78
79 umode_t orig_i_mode;
80
81
82 u64 orig_ino;
83
84
85 u64 attr_version;
86
87
88 struct list_head write_files;
89
90
91 struct list_head queued_writes;
92
93
94
95 int writectr;
96
97
98 wait_queue_head_t page_waitq;
99
100
101 struct list_head writepages;
102
103
104 unsigned long state;
105
106
107 struct mutex mutex;
108};
109
110
111enum {
112
113 FUSE_I_ADVISE_RDPLUS,
114
115 FUSE_I_INIT_RDPLUS,
116
117 FUSE_I_SIZE_UNSTABLE,
118};
119
120struct fuse_conn;
121
122
123struct fuse_file {
124
125 struct fuse_conn *fc;
126
127
128 struct fuse_req *reserved_req;
129
130
131 u64 kh;
132
133
134 u64 fh;
135
136
137 u64 nodeid;
138
139
140 atomic_t count;
141
142
143 u32 open_flags;
144
145
146 struct list_head write_entry;
147
148
149 struct rb_node polled_node;
150
151
152 wait_queue_head_t poll_wait;
153
154
155 bool flock:1;
156};
157
158
159struct fuse_in_arg {
160 unsigned size;
161 const void *value;
162};
163
164
165struct fuse_in {
166
167 struct fuse_in_header h;
168
169
170 unsigned argpages:1;
171
172
173 unsigned numargs;
174
175
176 struct fuse_in_arg args[3];
177};
178
179
180struct fuse_arg {
181 unsigned size;
182 void *value;
183};
184
185
186struct fuse_out {
187
188 struct fuse_out_header h;
189
190
191
192
193
194
195
196
197 unsigned argvar:1;
198
199
200 unsigned argpages:1;
201
202
203 unsigned page_zeroing:1;
204
205
206 unsigned page_replace:1;
207
208
209 unsigned numargs;
210
211
212 struct fuse_arg args[2];
213};
214
215
216struct fuse_page_desc {
217 unsigned int length;
218 unsigned int offset;
219};
220
221struct fuse_args {
222 struct {
223 struct {
224 uint32_t opcode;
225 uint64_t nodeid;
226 } h;
227 unsigned numargs;
228 struct fuse_in_arg args[3];
229
230 } in;
231 struct {
232 unsigned argvar:1;
233 unsigned numargs;
234 struct fuse_arg args[2];
235 } out;
236};
237
238#define FUSE_ARGS(args) struct fuse_args args = {}
239
240
241struct fuse_io_priv {
242 struct kref refcnt;
243 int async;
244 spinlock_t lock;
245 unsigned reqs;
246 ssize_t bytes;
247 size_t size;
248 __u64 offset;
249 bool write;
250 int err;
251 struct kiocb *iocb;
252 struct file *file;
253 struct completion *done;
254 bool blocking;
255};
256
257#define FUSE_IO_PRIV_SYNC(f) \
258{ \
259 .refcnt = { ATOMIC_INIT(1) }, \
260 .async = 0, \
261 .file = f, \
262}
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279enum fuse_req_flag {
280 FR_ISREPLY,
281 FR_FORCE,
282 FR_BACKGROUND,
283 FR_WAITING,
284 FR_ABORTED,
285 FR_INTERRUPTED,
286 FR_LOCKED,
287 FR_PENDING,
288 FR_SENT,
289 FR_FINISHED,
290 FR_PRIVATE,
291};
292
293
294
295
296
297
298
299
300struct fuse_req {
301
302
303 struct list_head list;
304
305
306 struct list_head intr_entry;
307
308
309 atomic_t count;
310
311
312 u64 intr_unique;
313
314
315 unsigned long flags;
316
317
318 struct fuse_in in;
319
320
321 struct fuse_out out;
322
323
324 wait_queue_head_t waitq;
325
326
327 union {
328 struct {
329 struct fuse_release_in in;
330 struct inode *inode;
331 } release;
332 struct fuse_init_in init_in;
333 struct fuse_init_out init_out;
334 struct cuse_init_in cuse_init_in;
335 struct {
336 struct fuse_read_in in;
337 u64 attr_ver;
338 } read;
339 struct {
340 struct fuse_write_in in;
341 struct fuse_write_out out;
342 struct fuse_req *next;
343 } write;
344 struct fuse_notify_retrieve_in retrieve_in;
345 } misc;
346
347
348 struct page **pages;
349
350
351 struct fuse_page_desc *page_descs;
352
353
354 unsigned max_pages;
355
356
357 struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
358
359
360 struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES];
361
362
363 unsigned num_pages;
364
365
366 struct fuse_file *ff;
367
368
369 struct inode *inode;
370
371
372 struct fuse_io_priv *io;
373
374
375 struct list_head writepages_entry;
376
377
378 void (*end)(struct fuse_conn *, struct fuse_req *);
379
380
381 struct file *stolen_file;
382};
383
384struct fuse_iqueue {
385
386 unsigned connected;
387
388
389 wait_queue_head_t waitq;
390
391
392 u64 reqctr;
393
394
395 struct list_head pending;
396
397
398 struct list_head interrupts;
399
400
401 struct fuse_forget_link forget_list_head;
402 struct fuse_forget_link *forget_list_tail;
403
404
405 int forget_batch;
406
407
408 struct fasync_struct *fasync;
409};
410
411struct fuse_pqueue {
412
413 unsigned connected;
414
415
416 spinlock_t lock;
417
418
419 struct list_head processing;
420
421
422 struct list_head io;
423};
424
425
426
427
428struct fuse_dev {
429
430 struct fuse_conn *fc;
431
432
433 struct fuse_pqueue pq;
434
435
436 struct list_head entry;
437};
438
439
440
441
442
443
444
445
446struct fuse_conn {
447
448 spinlock_t lock;
449
450
451 atomic_t count;
452
453
454 atomic_t dev_count;
455
456 struct rcu_head rcu;
457
458
459 kuid_t user_id;
460
461
462 kgid_t group_id;
463
464
465 unsigned max_read;
466
467
468 unsigned max_write;
469
470
471 struct fuse_iqueue iq;
472
473
474 u64 khctr;
475
476
477 struct rb_root polled_files;
478
479
480 unsigned max_background;
481
482
483 unsigned congestion_threshold;
484
485
486 unsigned num_background;
487
488
489 unsigned active_background;
490
491
492 struct list_head bg_queue;
493
494
495
496 int initialized;
497
498
499
500
501 int blocked;
502
503
504 wait_queue_head_t blocked_waitq;
505
506
507 wait_queue_head_t reserved_req_waitq;
508
509
510
511 unsigned connected;
512
513
514
515
516 unsigned conn_error:1;
517
518
519 unsigned conn_init:1;
520
521
522 unsigned async_read:1;
523
524
525 unsigned atomic_o_trunc:1;
526
527
528 unsigned export_support:1;
529
530
531 unsigned bdi_initialized:1;
532
533
534 unsigned writeback_cache:1;
535
536
537 unsigned parallel_dirops:1;
538
539
540 unsigned handle_killpriv:1;
541
542
543
544
545
546
547
548 unsigned no_open:1;
549
550
551 unsigned no_fsync:1;
552
553
554 unsigned no_fsyncdir:1;
555
556
557 unsigned no_flush:1;
558
559
560 unsigned no_setxattr:1;
561
562
563 unsigned no_getxattr:1;
564
565
566 unsigned no_listxattr:1;
567
568
569 unsigned no_removexattr:1;
570
571
572 unsigned no_lock:1;
573
574
575 unsigned no_access:1;
576
577
578 unsigned no_create:1;
579
580
581 unsigned no_interrupt:1;
582
583
584 unsigned no_bmap:1;
585
586
587 unsigned no_poll:1;
588
589
590 unsigned big_writes:1;
591
592
593 unsigned dont_mask:1;
594
595
596 unsigned no_flock:1;
597
598
599 unsigned no_fallocate:1;
600
601
602 unsigned no_rename2:1;
603
604
605 unsigned auto_inval_data:1;
606
607
608 unsigned do_readdirplus:1;
609
610
611 unsigned readdirplus_auto:1;
612
613
614 unsigned async_dio:1;
615
616
617 unsigned no_lseek:1;
618
619
620 unsigned posix_acl:1;
621
622
623 unsigned default_permissions:1;
624
625
626 unsigned allow_other:1;
627
628
629 atomic_t num_waiting;
630
631
632 unsigned minor;
633
634
635 struct backing_dev_info bdi;
636
637
638 struct list_head entry;
639
640
641 dev_t dev;
642
643
644 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
645
646
647 int ctl_ndents;
648
649
650 u32 scramble_key[4];
651
652
653 struct fuse_req *destroy_req;
654
655
656 u64 attr_version;
657
658
659 void (*release)(struct fuse_conn *);
660
661
662 struct super_block *sb;
663
664
665 struct rw_semaphore killsb;
666
667
668 struct list_head devices;
669};
670
671static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
672{
673 return sb->s_fs_info;
674}
675
676static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
677{
678 return get_fuse_conn_super(inode->i_sb);
679}
680
681static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
682{
683 return container_of(inode, struct fuse_inode, inode);
684}
685
686static inline u64 get_node_id(struct inode *inode)
687{
688 return get_fuse_inode(inode)->nodeid;
689}
690
691
692extern const struct file_operations fuse_dev_operations;
693
694extern const struct dentry_operations fuse_dentry_operations;
695extern const struct dentry_operations fuse_root_dentry_operations;
696
697
698
699
700int fuse_inode_eq(struct inode *inode, void *_nodeidp);
701
702
703
704
705struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
706 int generation, struct fuse_attr *attr,
707 u64 attr_valid, u64 attr_version);
708
709int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
710 struct fuse_entry_out *outarg, struct inode **inode);
711
712
713
714
715void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
716 u64 nodeid, u64 nlookup);
717
718struct fuse_forget_link *fuse_alloc_forget(void);
719
720
721void fuse_force_forget(struct file *file, u64 nodeid);
722
723
724
725
726void fuse_read_fill(struct fuse_req *req, struct file *file,
727 loff_t pos, size_t count, int opcode);
728
729
730
731
732int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
733
734struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
735struct fuse_file *fuse_file_get(struct fuse_file *ff);
736void fuse_file_free(struct fuse_file *ff);
737void fuse_finish_open(struct inode *inode, struct file *file);
738
739void fuse_sync_release(struct fuse_file *ff, int flags);
740
741
742
743
744void fuse_release_common(struct file *file, int opcode);
745
746
747
748
749int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
750 int datasync, int isdir);
751
752
753
754
755int fuse_notify_poll_wakeup(struct fuse_conn *fc,
756 struct fuse_notify_poll_wakeup_out *outarg);
757
758
759
760
761void fuse_init_file_inode(struct inode *inode);
762
763
764
765
766void fuse_init_common(struct inode *inode);
767
768
769
770
771void fuse_init_dir(struct inode *inode);
772
773
774
775
776void fuse_init_symlink(struct inode *inode);
777
778
779
780
781void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
782 u64 attr_valid, u64 attr_version);
783
784void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
785 u64 attr_valid);
786
787
788
789
790int fuse_dev_init(void);
791
792
793
794
795void fuse_dev_cleanup(void);
796
797int fuse_ctl_init(void);
798void __exit fuse_ctl_cleanup(void);
799
800
801
802
803struct fuse_req *fuse_request_alloc(unsigned npages);
804
805struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
806
807
808
809
810void fuse_request_free(struct fuse_req *req);
811
812
813
814
815
816struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages);
817struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
818 unsigned npages);
819
820
821
822
823void __fuse_get_request(struct fuse_req *req);
824
825
826
827
828struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
829 struct file *file);
830
831
832
833
834
835void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
836
837
838
839
840void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
841
842
843
844
845ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
846
847
848
849
850void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
851
852void fuse_request_send_background_locked(struct fuse_conn *fc,
853 struct fuse_req *req);
854
855
856void fuse_abort_conn(struct fuse_conn *fc);
857
858
859
860
861void fuse_invalidate_attr(struct inode *inode);
862
863void fuse_invalidate_entry_cache(struct dentry *entry);
864
865void fuse_invalidate_atime(struct inode *inode);
866
867
868
869
870struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
871
872
873
874
875void fuse_conn_init(struct fuse_conn *fc);
876
877
878
879
880void fuse_conn_put(struct fuse_conn *fc);
881
882struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
883void fuse_dev_free(struct fuse_dev *fud);
884
885
886
887
888int fuse_ctl_add_conn(struct fuse_conn *fc);
889
890
891
892
893void fuse_ctl_remove_conn(struct fuse_conn *fc);
894
895
896
897
898int fuse_valid_type(int m);
899
900
901
902
903int fuse_allow_current_process(struct fuse_conn *fc);
904
905u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
906
907void fuse_update_ctime(struct inode *inode);
908
909int fuse_update_attributes(struct inode *inode, struct kstat *stat,
910 struct file *file, bool *refreshed);
911
912void fuse_flush_writepages(struct inode *inode);
913
914void fuse_set_nowrite(struct inode *inode);
915void fuse_release_nowrite(struct inode *inode);
916
917u64 fuse_get_attr_version(struct fuse_conn *fc);
918
919
920
921
922int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
923 loff_t offset, loff_t len);
924
925
926
927
928
929
930
931
932
933
934
935int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
936 u64 child_nodeid, struct qstr *name);
937
938int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
939 bool isdir);
940
941
942
943
944
945
946#define FUSE_DIO_WRITE (1 << 0)
947
948
949#define FUSE_DIO_CUSE (1 << 1)
950
951ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
952 loff_t *ppos, int flags);
953long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
954 unsigned int flags);
955long fuse_ioctl_common(struct file *file, unsigned int cmd,
956 unsigned long arg, unsigned int flags);
957unsigned fuse_file_poll(struct file *file, poll_table *wait);
958int fuse_dev_release(struct inode *inode, struct file *file);
959
960bool fuse_write_update_size(struct inode *inode, loff_t pos);
961
962int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
963int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
964
965int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
966 struct file *file);
967
968void fuse_set_initialized(struct fuse_conn *fc);
969
970void fuse_unlock_inode(struct inode *inode);
971void fuse_lock_inode(struct inode *inode);
972
973int fuse_setxattr(struct inode *inode, const char *name, const void *value,
974 size_t size, int flags);
975ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
976 size_t size);
977ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
978int fuse_removexattr(struct inode *inode, const char *name);
979extern const struct xattr_handler *fuse_xattr_handlers[];
980extern const struct xattr_handler *fuse_acl_xattr_handlers[];
981
982struct posix_acl;
983struct posix_acl *fuse_get_acl(struct inode *inode, int type);
984int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
985
986#endif
987