fuse: add nocreds to fuse_args
[linux-2.6-block.git] / fs / fuse / fuse_i.h
1 /*
2   FUSE: Filesystem in Userspace
3   Copyright (C) 2001-2008  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 #ifndef _FS_FUSE_I_H
10 #define _FS_FUSE_I_H
11
12 #ifndef pr_fmt
13 # define pr_fmt(fmt) "fuse: " fmt
14 #endif
15
16 #include <linux/fuse.h>
17 #include <linux/fs.h>
18 #include <linux/mount.h>
19 #include <linux/wait.h>
20 #include <linux/list.h>
21 #include <linux/spinlock.h>
22 #include <linux/mm.h>
23 #include <linux/backing-dev.h>
24 #include <linux/mutex.h>
25 #include <linux/rwsem.h>
26 #include <linux/rbtree.h>
27 #include <linux/poll.h>
28 #include <linux/workqueue.h>
29 #include <linux/kref.h>
30 #include <linux/xattr.h>
31 #include <linux/pid_namespace.h>
32 #include <linux/refcount.h>
33 #include <linux/user_namespace.h>
34
35 /** Default max number of pages that can be used in a single read request */
36 #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
37
38 /** Maximum of max_pages received in init_out */
39 #define FUSE_MAX_MAX_PAGES 256
40
41 /** Bias for fi->writectr, meaning new writepages must not be sent */
42 #define FUSE_NOWRITE INT_MIN
43
44 /** It could be as large as PATH_MAX, but would that have any uses? */
45 #define FUSE_NAME_MAX 1024
46
47 /** Number of dentries for each connection in the control filesystem */
48 #define FUSE_CTL_NUM_DENTRIES 5
49
50 /** Number of page pointers embedded in fuse_req */
51 #define FUSE_REQ_INLINE_PAGES 1
52
53 /** List of active connections */
54 extern struct list_head fuse_conn_list;
55
56 /** Global mutex protecting fuse_conn_list and the control filesystem */
57 extern struct mutex fuse_mutex;
58
59 /** Module parameters */
60 extern unsigned max_user_bgreq;
61 extern unsigned max_user_congthresh;
62
63 /* One forget request */
64 struct fuse_forget_link {
65         struct fuse_forget_one forget_one;
66         struct fuse_forget_link *next;
67 };
68
69 /** FUSE inode */
70 struct fuse_inode {
71         /** Inode data */
72         struct inode inode;
73
74         /** Unique ID, which identifies the inode between userspace
75          * and kernel */
76         u64 nodeid;
77
78         /** Number of lookups on this inode */
79         u64 nlookup;
80
81         /** The request used for sending the FORGET message */
82         struct fuse_forget_link *forget;
83
84         /** Time in jiffies until the file attributes are valid */
85         u64 i_time;
86
87         /* Which attributes are invalid */
88         u32 inval_mask;
89
90         /** The sticky bit in inode->i_mode may have been removed, so
91             preserve the original mode */
92         umode_t orig_i_mode;
93
94         /** 64 bit inode number */
95         u64 orig_ino;
96
97         /** Version of last attribute change */
98         u64 attr_version;
99
100         union {
101                 /* Write related fields (regular file only) */
102                 struct {
103                         /* Files usable in writepage.  Protected by fi->lock */
104                         struct list_head write_files;
105
106                         /* Writepages pending on truncate or fsync */
107                         struct list_head queued_writes;
108
109                         /* Number of sent writes, a negative bias
110                          * (FUSE_NOWRITE) means more writes are blocked */
111                         int writectr;
112
113                         /* Waitq for writepage completion */
114                         wait_queue_head_t page_waitq;
115
116                         /* List of writepage requestst (pending or sent) */
117                         struct list_head writepages;
118                 };
119
120                 /* readdir cache (directory only) */
121                 struct {
122                         /* true if fully cached */
123                         bool cached;
124
125                         /* size of cache */
126                         loff_t size;
127
128                         /* position at end of cache (position of next entry) */
129                         loff_t pos;
130
131                         /* version of the cache */
132                         u64 version;
133
134                         /* modification time of directory when cache was
135                          * started */
136                         struct timespec64 mtime;
137
138                         /* iversion of directory when cache was started */
139                         u64 iversion;
140
141                         /* protects above fields */
142                         spinlock_t lock;
143                 } rdc;
144         };
145
146         /** Miscellaneous bits describing inode state */
147         unsigned long state;
148
149         /** Lock for serializing lookup and readdir for back compatibility*/
150         struct mutex mutex;
151
152         /** Lock to protect write related fields */
153         spinlock_t lock;
154 };
155
156 /** FUSE inode state bits */
157 enum {
158         /** Advise readdirplus  */
159         FUSE_I_ADVISE_RDPLUS,
160         /** Initialized with readdirplus */
161         FUSE_I_INIT_RDPLUS,
162         /** An operation changing file size is in progress  */
163         FUSE_I_SIZE_UNSTABLE,
164 };
165
166 struct fuse_conn;
167
168 /** FUSE specific file data */
169 struct fuse_file {
170         /** Fuse connection for this file */
171         struct fuse_conn *fc;
172
173         /*
174          * Request reserved for flush and release.
175          * Modified under relative fuse_inode::lock.
176          */
177         struct fuse_req *reserved_req;
178
179         /** Kernel file handle guaranteed to be unique */
180         u64 kh;
181
182         /** File handle used by userspace */
183         u64 fh;
184
185         /** Node id of this file */
186         u64 nodeid;
187
188         /** Refcount */
189         refcount_t count;
190
191         /** FOPEN_* flags returned by open */
192         u32 open_flags;
193
194         /** Entry on inode's write_files list */
195         struct list_head write_entry;
196
197         /* Readdir related */
198         struct {
199                 /*
200                  * Protects below fields against (crazy) parallel readdir on
201                  * same open file.  Uncontended in the normal case.
202                  */
203                 struct mutex lock;
204
205                 /* Dir stream position */
206                 loff_t pos;
207
208                 /* Offset in cache */
209                 loff_t cache_off;
210
211                 /* Version of cache we are reading */
212                 u64 version;
213
214         } readdir;
215
216         /** RB node to be linked on fuse_conn->polled_files */
217         struct rb_node polled_node;
218
219         /** Wait queue head for poll */
220         wait_queue_head_t poll_wait;
221
222         /** Has flock been performed on this file? */
223         bool flock:1;
224 };
225
226 /** One input argument of a request */
227 struct fuse_in_arg {
228         unsigned size;
229         const void *value;
230 };
231
232 /** The request input */
233 struct fuse_in {
234         /** The request header */
235         struct fuse_in_header h;
236
237         /** True if the data for the last argument is in req->pages */
238         unsigned argpages:1;
239
240         /** Number of arguments */
241         unsigned numargs;
242
243         /** Array of arguments */
244         struct fuse_in_arg args[3];
245 };
246
247 /** One output argument of a request */
248 struct fuse_arg {
249         unsigned size;
250         void *value;
251 };
252
253 /** The request output */
254 struct fuse_out {
255         /** Header returned from userspace */
256         struct fuse_out_header h;
257
258         /*
259          * The following bitfields are not changed during the request
260          * processing
261          */
262
263         /** Last argument is variable length (can be shorter than
264             arg->size) */
265         unsigned argvar:1;
266
267         /** Last argument is a list of pages to copy data to */
268         unsigned argpages:1;
269
270         /** Zero partially or not copied pages */
271         unsigned page_zeroing:1;
272
273         /** Pages may be replaced with new ones */
274         unsigned page_replace:1;
275
276         /** Number or arguments */
277         unsigned numargs;
278
279         /** Array of arguments */
280         struct fuse_arg args[2];
281 };
282
283 /** FUSE page descriptor */
284 struct fuse_page_desc {
285         unsigned int length;
286         unsigned int offset;
287 };
288
289 struct fuse_args {
290         uint64_t nodeid;
291         uint32_t opcode;
292         unsigned short in_numargs;
293         unsigned short out_numargs;
294         bool force:1;
295         bool noreply:1;
296         bool nocreds:1;
297         bool out_argvar:1;
298         struct fuse_in_arg in_args[3];
299         struct fuse_arg out_args[2];
300 };
301
302 #define FUSE_ARGS(args) struct fuse_args args = {}
303
304 /** The request IO state (for asynchronous processing) */
305 struct fuse_io_priv {
306         struct kref refcnt;
307         int async;
308         spinlock_t lock;
309         unsigned reqs;
310         ssize_t bytes;
311         size_t size;
312         __u64 offset;
313         bool write;
314         bool should_dirty;
315         int err;
316         struct kiocb *iocb;
317         struct completion *done;
318         bool blocking;
319 };
320
321 #define FUSE_IO_PRIV_SYNC(i) \
322 {                                       \
323         .refcnt = KREF_INIT(1),         \
324         .async = 0,                     \
325         .iocb = i,                      \
326 }
327
328 /**
329  * Request flags
330  *
331  * FR_ISREPLY:          set if the request has reply
332  * FR_FORCE:            force sending of the request even if interrupted
333  * FR_BACKGROUND:       request is sent in the background
334  * FR_WAITING:          request is counted as "waiting"
335  * FR_ABORTED:          the request was aborted
336  * FR_INTERRUPTED:      the request has been interrupted
337  * FR_LOCKED:           data is being copied to/from the request
338  * FR_PENDING:          request is not yet in userspace
339  * FR_SENT:             request is in userspace, waiting for an answer
340  * FR_FINISHED:         request is finished
341  * FR_PRIVATE:          request is on private list
342  */
343 enum fuse_req_flag {
344         FR_ISREPLY,
345         FR_FORCE,
346         FR_BACKGROUND,
347         FR_WAITING,
348         FR_ABORTED,
349         FR_INTERRUPTED,
350         FR_LOCKED,
351         FR_PENDING,
352         FR_SENT,
353         FR_FINISHED,
354         FR_PRIVATE,
355 };
356
357 /**
358  * A request to the client
359  *
360  * .waitq.lock protects the following fields:
361  *   - FR_ABORTED
362  *   - FR_LOCKED (may also be modified under fc->lock, tested under both)
363  */
364 struct fuse_req {
365         /** This can be on either pending processing or io lists in
366             fuse_conn */
367         struct list_head list;
368
369         /** Entry on the interrupts list  */
370         struct list_head intr_entry;
371
372         /** refcount */
373         refcount_t count;
374
375         /* Request flags, updated with test/set/clear_bit() */
376         unsigned long flags;
377
378         /** The request input */
379         struct fuse_in in;
380
381         /** The request output */
382         struct fuse_out out;
383
384         /** Used to wake up the task waiting for completion of request*/
385         wait_queue_head_t waitq;
386
387         /** Data for asynchronous requests */
388         union {
389                 struct {
390                         struct fuse_release_in in;
391                         struct inode *inode;
392                 } release;
393                 struct fuse_init_in init_in;
394                 struct fuse_init_out init_out;
395                 struct cuse_init_in cuse_init_in;
396                 struct {
397                         struct fuse_read_in in;
398                         u64 attr_ver;
399                 } read;
400                 struct {
401                         struct fuse_write_in in;
402                         struct fuse_write_out out;
403                         struct fuse_req *next;
404                 } write;
405                 struct fuse_notify_retrieve_in retrieve_in;
406         } misc;
407
408         /** page vector */
409         struct page **pages;
410
411         /** page-descriptor vector */
412         struct fuse_page_desc *page_descs;
413
414         /** size of the 'pages' array */
415         unsigned max_pages;
416
417         /** inline page vector */
418         struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
419
420         /** inline page-descriptor vector */
421         struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES];
422
423         /** number of pages in vector */
424         unsigned num_pages;
425
426         /** File used in the request (or NULL) */
427         struct fuse_file *ff;
428
429         /** Inode used in the request or NULL */
430         struct inode *inode;
431
432         /** AIO control block */
433         struct fuse_io_priv *io;
434
435         /** Link on fi->writepages */
436         struct list_head writepages_entry;
437
438         /** Request completion callback */
439         void (*end)(struct fuse_conn *, struct fuse_req *);
440
441 };
442
443 struct fuse_iqueue {
444         /** Connection established */
445         unsigned connected;
446
447         /** Lock protecting accesses to members of this structure */
448         spinlock_t lock;
449
450         /** Readers of the connection are waiting on this */
451         wait_queue_head_t waitq;
452
453         /** The next unique request id */
454         u64 reqctr;
455
456         /** The list of pending requests */
457         struct list_head pending;
458
459         /** Pending interrupts */
460         struct list_head interrupts;
461
462         /** Queue of pending forgets */
463         struct fuse_forget_link forget_list_head;
464         struct fuse_forget_link *forget_list_tail;
465
466         /** Batching of FORGET requests (positive indicates FORGET batch) */
467         int forget_batch;
468
469         /** O_ASYNC requests */
470         struct fasync_struct *fasync;
471 };
472
473 #define FUSE_PQ_HASH_BITS 8
474 #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS)
475
476 struct fuse_pqueue {
477         /** Connection established */
478         unsigned connected;
479
480         /** Lock protecting accessess to  members of this structure */
481         spinlock_t lock;
482
483         /** Hash table of requests being processed */
484         struct list_head *processing;
485
486         /** The list of requests under I/O */
487         struct list_head io;
488 };
489
490 /**
491  * Fuse device instance
492  */
493 struct fuse_dev {
494         /** Fuse connection for this device */
495         struct fuse_conn *fc;
496
497         /** Processing queue */
498         struct fuse_pqueue pq;
499
500         /** list entry on fc->devices */
501         struct list_head entry;
502 };
503
504 /**
505  * A Fuse connection.
506  *
507  * This structure is created, when the filesystem is mounted, and is
508  * destroyed, when the client device is closed and the filesystem is
509  * unmounted.
510  */
511 struct fuse_conn {
512         /** Lock protecting accessess to  members of this structure */
513         spinlock_t lock;
514
515         /** Refcount */
516         refcount_t count;
517
518         /** Number of fuse_dev's */
519         atomic_t dev_count;
520
521         struct rcu_head rcu;
522
523         /** The user id for this mount */
524         kuid_t user_id;
525
526         /** The group id for this mount */
527         kgid_t group_id;
528
529         /** The pid namespace for this mount */
530         struct pid_namespace *pid_ns;
531
532         /** The user namespace for this mount */
533         struct user_namespace *user_ns;
534
535         /** Maximum read size */
536         unsigned max_read;
537
538         /** Maximum write size */
539         unsigned max_write;
540
541         /** Maxmum number of pages that can be used in a single request */
542         unsigned int max_pages;
543
544         /** Input queue */
545         struct fuse_iqueue iq;
546
547         /** The next unique kernel file handle */
548         atomic64_t khctr;
549
550         /** rbtree of fuse_files waiting for poll events indexed by ph */
551         struct rb_root polled_files;
552
553         /** Maximum number of outstanding background requests */
554         unsigned max_background;
555
556         /** Number of background requests at which congestion starts */
557         unsigned congestion_threshold;
558
559         /** Number of requests currently in the background */
560         unsigned num_background;
561
562         /** Number of background requests currently queued for userspace */
563         unsigned active_background;
564
565         /** The list of background requests set aside for later queuing */
566         struct list_head bg_queue;
567
568         /** Protects: max_background, congestion_threshold, num_background,
569          * active_background, bg_queue, blocked */
570         spinlock_t bg_lock;
571
572         /** Flag indicating that INIT reply has been received. Allocating
573          * any fuse request will be suspended until the flag is set */
574         int initialized;
575
576         /** Flag indicating if connection is blocked.  This will be
577             the case before the INIT reply is received, and if there
578             are too many outstading backgrounds requests */
579         int blocked;
580
581         /** waitq for blocked connection */
582         wait_queue_head_t blocked_waitq;
583
584         /** Connection established, cleared on umount, connection
585             abort and device release */
586         unsigned connected;
587
588         /** Connection aborted via sysfs */
589         bool aborted;
590
591         /** Connection failed (version mismatch).  Cannot race with
592             setting other bitfields since it is only set once in INIT
593             reply, before any other request, and never cleared */
594         unsigned conn_error:1;
595
596         /** Connection successful.  Only set in INIT */
597         unsigned conn_init:1;
598
599         /** Do readpages asynchronously?  Only set in INIT */
600         unsigned async_read:1;
601
602         /** Return an unique read error after abort.  Only set in INIT */
603         unsigned abort_err:1;
604
605         /** Do not send separate SETATTR request before open(O_TRUNC)  */
606         unsigned atomic_o_trunc:1;
607
608         /** Filesystem supports NFS exporting.  Only set in INIT */
609         unsigned export_support:1;
610
611         /** write-back cache policy (default is write-through) */
612         unsigned writeback_cache:1;
613
614         /** allow parallel lookups and readdir (default is serialized) */
615         unsigned parallel_dirops:1;
616
617         /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
618         unsigned handle_killpriv:1;
619
620         /** cache READLINK responses in page cache */
621         unsigned cache_symlinks:1;
622
623         /*
624          * The following bitfields are only for optimization purposes
625          * and hence races in setting them will not cause malfunction
626          */
627
628         /** Is open/release not implemented by fs? */
629         unsigned no_open:1;
630
631         /** Is opendir/releasedir not implemented by fs? */
632         unsigned no_opendir:1;
633
634         /** Is fsync not implemented by fs? */
635         unsigned no_fsync:1;
636
637         /** Is fsyncdir not implemented by fs? */
638         unsigned no_fsyncdir:1;
639
640         /** Is flush not implemented by fs? */
641         unsigned no_flush:1;
642
643         /** Is setxattr not implemented by fs? */
644         unsigned no_setxattr:1;
645
646         /** Is getxattr not implemented by fs? */
647         unsigned no_getxattr:1;
648
649         /** Is listxattr not implemented by fs? */
650         unsigned no_listxattr:1;
651
652         /** Is removexattr not implemented by fs? */
653         unsigned no_removexattr:1;
654
655         /** Are posix file locking primitives not implemented by fs? */
656         unsigned no_lock:1;
657
658         /** Is access not implemented by fs? */
659         unsigned no_access:1;
660
661         /** Is create not implemented by fs? */
662         unsigned no_create:1;
663
664         /** Is interrupt not implemented by fs? */
665         unsigned no_interrupt:1;
666
667         /** Is bmap not implemented by fs? */
668         unsigned no_bmap:1;
669
670         /** Is poll not implemented by fs? */
671         unsigned no_poll:1;
672
673         /** Do multi-page cached writes */
674         unsigned big_writes:1;
675
676         /** Don't apply umask to creation modes */
677         unsigned dont_mask:1;
678
679         /** Are BSD file locking primitives not implemented by fs? */
680         unsigned no_flock:1;
681
682         /** Is fallocate not implemented by fs? */
683         unsigned no_fallocate:1;
684
685         /** Is rename with flags implemented by fs? */
686         unsigned no_rename2:1;
687
688         /** Use enhanced/automatic page cache invalidation. */
689         unsigned auto_inval_data:1;
690
691         /** Filesystem is fully reponsible for page cache invalidation. */
692         unsigned explicit_inval_data:1;
693
694         /** Does the filesystem support readdirplus? */
695         unsigned do_readdirplus:1;
696
697         /** Does the filesystem want adaptive readdirplus? */
698         unsigned readdirplus_auto:1;
699
700         /** Does the filesystem support asynchronous direct-IO submission? */
701         unsigned async_dio:1;
702
703         /** Is lseek not implemented by fs? */
704         unsigned no_lseek:1;
705
706         /** Does the filesystem support posix acls? */
707         unsigned posix_acl:1;
708
709         /** Check permissions based on the file mode or not? */
710         unsigned default_permissions:1;
711
712         /** Allow other than the mounter user to access the filesystem ? */
713         unsigned allow_other:1;
714
715         /** Does the filesystem support copy_file_range? */
716         unsigned no_copy_file_range:1;
717
718         /** The number of requests waiting for completion */
719         atomic_t num_waiting;
720
721         /** Negotiated minor version */
722         unsigned minor;
723
724         /** Entry on the fuse_conn_list */
725         struct list_head entry;
726
727         /** Device ID from super block */
728         dev_t dev;
729
730         /** Dentries in the control filesystem */
731         struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
732
733         /** number of dentries used in the above array */
734         int ctl_ndents;
735
736         /** Key for lock owner ID scrambling */
737         u32 scramble_key[4];
738
739         /** Reserved request for the DESTROY message */
740         struct fuse_req *destroy_req;
741
742         /** Version counter for attribute changes */
743         atomic64_t attr_version;
744
745         /** Called on final put */
746         void (*release)(struct fuse_conn *);
747
748         /** Super block for this connection. */
749         struct super_block *sb;
750
751         /** Read/write semaphore to hold when accessing sb. */
752         struct rw_semaphore killsb;
753
754         /** List of device instances belonging to this connection */
755         struct list_head devices;
756 };
757
758 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
759 {
760         return sb->s_fs_info;
761 }
762
763 static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
764 {
765         return get_fuse_conn_super(inode->i_sb);
766 }
767
768 static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
769 {
770         return container_of(inode, struct fuse_inode, inode);
771 }
772
773 static inline u64 get_node_id(struct inode *inode)
774 {
775         return get_fuse_inode(inode)->nodeid;
776 }
777
778 static inline int invalid_nodeid(u64 nodeid)
779 {
780         return !nodeid || nodeid == FUSE_ROOT_ID;
781 }
782
783 static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
784 {
785         return atomic64_read(&fc->attr_version);
786 }
787
788 /** Device operations */
789 extern const struct file_operations fuse_dev_operations;
790
791 extern const struct dentry_operations fuse_dentry_operations;
792 extern const struct dentry_operations fuse_root_dentry_operations;
793
794 /**
795  * Inode to nodeid comparison.
796  */
797 int fuse_inode_eq(struct inode *inode, void *_nodeidp);
798
799 /**
800  * Get a filled in inode
801  */
802 struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
803                         int generation, struct fuse_attr *attr,
804                         u64 attr_valid, u64 attr_version);
805
806 int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
807                      struct fuse_entry_out *outarg, struct inode **inode);
808
809 /**
810  * Send FORGET command
811  */
812 void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
813                        u64 nodeid, u64 nlookup);
814
815 struct fuse_forget_link *fuse_alloc_forget(void);
816
817 /**
818  * Initialize READ or READDIR request
819  */
820 void fuse_read_fill(struct fuse_req *req, struct file *file,
821                     loff_t pos, size_t count, int opcode);
822
823 /**
824  * Send OPEN or OPENDIR request
825  */
826 int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
827
828 struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
829 void fuse_file_free(struct fuse_file *ff);
830 void fuse_finish_open(struct inode *inode, struct file *file);
831
832 void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
833
834 /**
835  * Send RELEASE or RELEASEDIR request
836  */
837 void fuse_release_common(struct file *file, bool isdir);
838
839 /**
840  * Send FSYNC or FSYNCDIR request
841  */
842 int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
843                       int datasync, int opcode);
844
845 /**
846  * Notify poll wakeup
847  */
848 int fuse_notify_poll_wakeup(struct fuse_conn *fc,
849                             struct fuse_notify_poll_wakeup_out *outarg);
850
851 /**
852  * Initialize file operations on a regular file
853  */
854 void fuse_init_file_inode(struct inode *inode);
855
856 /**
857  * Initialize inode operations on regular files and special files
858  */
859 void fuse_init_common(struct inode *inode);
860
861 /**
862  * Initialize inode and file operations on a directory
863  */
864 void fuse_init_dir(struct inode *inode);
865
866 /**
867  * Initialize inode operations on a symlink
868  */
869 void fuse_init_symlink(struct inode *inode);
870
871 /**
872  * Change attributes of an inode
873  */
874 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
875                             u64 attr_valid, u64 attr_version);
876
877 void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
878                                    u64 attr_valid);
879
880 /**
881  * Initialize the client device
882  */
883 int fuse_dev_init(void);
884
885 /**
886  * Cleanup the client device
887  */
888 void fuse_dev_cleanup(void);
889
890 int fuse_ctl_init(void);
891 void __exit fuse_ctl_cleanup(void);
892
893 /**
894  * Allocate a request
895  */
896 struct fuse_req *fuse_request_alloc(unsigned npages);
897
898 struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
899
900 bool fuse_req_realloc_pages(struct fuse_conn *fc, struct fuse_req *req,
901                             gfp_t flags);
902
903
904 /**
905  * Free a request
906  */
907 void fuse_request_free(struct fuse_req *req);
908
909 /**
910  * Get a request, may fail with -ENOMEM,
911  * caller should specify # elements in req->pages[] explicitly
912  */
913 struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages);
914 struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
915                                              unsigned npages);
916
917 /*
918  * Increment reference count on request
919  */
920 void __fuse_get_request(struct fuse_req *req);
921
922 /**
923  * Decrement reference count of a request.  If count goes to zero free
924  * the request.
925  */
926 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
927
928 /**
929  * Send a request (synchronous)
930  */
931 void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
932
933 /**
934  * Simple request sending that does request allocation and freeing
935  */
936 ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
937
938 /**
939  * Send a request in the background
940  */
941 void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
942 bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
943
944 /* Abort all requests */
945 void fuse_abort_conn(struct fuse_conn *fc);
946 void fuse_wait_aborted(struct fuse_conn *fc);
947
948 /**
949  * Invalidate inode attributes
950  */
951 void fuse_invalidate_attr(struct inode *inode);
952
953 void fuse_invalidate_entry_cache(struct dentry *entry);
954
955 void fuse_invalidate_atime(struct inode *inode);
956
957 u64 entry_attr_timeout(struct fuse_entry_out *o);
958 void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o);
959
960 /**
961  * Acquire reference to fuse_conn
962  */
963 struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
964
965 /**
966  * Initialize fuse_conn
967  */
968 void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns);
969
970 /**
971  * Release reference to fuse_conn
972  */
973 void fuse_conn_put(struct fuse_conn *fc);
974
975 struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
976 void fuse_dev_free(struct fuse_dev *fud);
977
978 /**
979  * Add connection to control filesystem
980  */
981 int fuse_ctl_add_conn(struct fuse_conn *fc);
982
983 /**
984  * Remove connection from control filesystem
985  */
986 void fuse_ctl_remove_conn(struct fuse_conn *fc);
987
988 /**
989  * Is file type valid?
990  */
991 int fuse_valid_type(int m);
992
993 /**
994  * Is current process allowed to perform filesystem operation?
995  */
996 int fuse_allow_current_process(struct fuse_conn *fc);
997
998 u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
999
1000 void fuse_update_ctime(struct inode *inode);
1001
1002 int fuse_update_attributes(struct inode *inode, struct file *file);
1003
1004 void fuse_flush_writepages(struct inode *inode);
1005
1006 void fuse_set_nowrite(struct inode *inode);
1007 void fuse_release_nowrite(struct inode *inode);
1008
1009 /**
1010  * File-system tells the kernel to invalidate cache for the given node id.
1011  */
1012 int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
1013                              loff_t offset, loff_t len);
1014
1015 /**
1016  * File-system tells the kernel to invalidate parent attributes and
1017  * the dentry matching parent/name.
1018  *
1019  * If the child_nodeid is non-zero and:
1020  *    - matches the inode number for the dentry matching parent/name,
1021  *    - is not a mount point
1022  *    - is a file or oan empty directory
1023  * then the dentry is unhashed (d_delete()).
1024  */
1025 int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
1026                              u64 child_nodeid, struct qstr *name);
1027
1028 int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
1029                  bool isdir);
1030
1031 /**
1032  * fuse_direct_io() flags
1033  */
1034
1035 /** If set, it is WRITE; otherwise - READ */
1036 #define FUSE_DIO_WRITE (1 << 0)
1037
1038 /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
1039 #define FUSE_DIO_CUSE  (1 << 1)
1040
1041 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
1042                        loff_t *ppos, int flags);
1043 long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
1044                    unsigned int flags);
1045 long fuse_ioctl_common(struct file *file, unsigned int cmd,
1046                        unsigned long arg, unsigned int flags);
1047 __poll_t fuse_file_poll(struct file *file, poll_table *wait);
1048 int fuse_dev_release(struct inode *inode, struct file *file);
1049
1050 bool fuse_write_update_size(struct inode *inode, loff_t pos);
1051
1052 int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
1053 int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
1054
1055 int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
1056                     struct file *file);
1057
1058 void fuse_set_initialized(struct fuse_conn *fc);
1059
1060 void fuse_unlock_inode(struct inode *inode, bool locked);
1061 bool fuse_lock_inode(struct inode *inode);
1062
1063 int fuse_setxattr(struct inode *inode, const char *name, const void *value,
1064                   size_t size, int flags);
1065 ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
1066                       size_t size);
1067 ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
1068 int fuse_removexattr(struct inode *inode, const char *name);
1069 extern const struct xattr_handler *fuse_xattr_handlers[];
1070 extern const struct xattr_handler *fuse_acl_xattr_handlers[];
1071 extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];
1072
1073 struct posix_acl;
1074 struct posix_acl *fuse_get_acl(struct inode *inode, int type);
1075 int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
1076
1077
1078 /* readdir.c */
1079 int fuse_readdir(struct file *file, struct dir_context *ctx);
1080
1081 #endif /* _FS_FUSE_I_H */