fuse_i.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU GPL.
  5. See the file COPYING.
  6. */
  7. #ifndef _FS_FUSE_I_H
  8. #define _FS_FUSE_I_H
  9. #include <linux/fuse.h>
  10. #include <linux/fs.h>
  11. #include <linux/mount.h>
  12. #include <linux/wait.h>
  13. #include <linux/list.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/mm.h>
  16. #include <linux/backing-dev.h>
  17. #include <linux/mutex.h>
  18. #include <linux/rwsem.h>
  19. #include <linux/rbtree.h>
  20. #include <linux/poll.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/kref.h>
  23. #include <linux/xattr.h>
  24. /** Max number of pages that can be used in a single read request */
  25. #define FUSE_MAX_PAGES_PER_REQ 32
  26. /** Bias for fi->writectr, meaning new writepages must not be sent */
  27. #define FUSE_NOWRITE INT_MIN
  28. /** It could be as large as PATH_MAX, but would that have any uses? */
  29. #define FUSE_NAME_MAX 1024
  30. /** Number of dentries for each connection in the control filesystem */
  31. #define FUSE_CTL_NUM_DENTRIES 5
  32. /** Number of page pointers embedded in fuse_req */
  33. #define FUSE_REQ_INLINE_PAGES 1
  34. /** List of active connections */
  35. extern struct list_head fuse_conn_list;
  36. /** Global mutex protecting fuse_conn_list and the control filesystem */
  37. extern struct mutex fuse_mutex;
  38. /** Module parameters */
  39. extern unsigned max_user_bgreq;
  40. extern unsigned max_user_congthresh;
  41. /* One forget request */
  42. struct fuse_forget_link {
  43. struct fuse_forget_one forget_one;
  44. struct fuse_forget_link *next;
  45. };
  46. /** FUSE inode */
  47. struct fuse_inode {
  48. /** Inode data */
  49. struct inode inode;
  50. /** Unique ID, which identifies the inode between userspace
  51. * and kernel */
  52. u64 nodeid;
  53. /** Number of lookups on this inode */
  54. u64 nlookup;
  55. /** The request used for sending the FORGET message */
  56. struct fuse_forget_link *forget;
  57. /** Time in jiffies until the file attributes are valid */
  58. u64 i_time;
  59. /** The sticky bit in inode->i_mode may have been removed, so
  60. preserve the original mode */
  61. umode_t orig_i_mode;
  62. /** 64 bit inode number */
  63. u64 orig_ino;
  64. /** Version of last attribute change */
  65. u64 attr_version;
  66. /** Files usable in writepage. Protected by fc->lock */
  67. struct list_head write_files;
  68. /** Writepages pending on truncate or fsync */
  69. struct list_head queued_writes;
  70. /** Number of sent writes, a negative bias (FUSE_NOWRITE)
  71. * means more writes are blocked */
  72. int writectr;
  73. /** Waitq for writepage completion */
  74. wait_queue_head_t page_waitq;
  75. /** List of writepage requestst (pending or sent) */
  76. struct list_head writepages;
  77. /** Miscellaneous bits describing inode state */
  78. unsigned long state;
  79. /** Lock for serializing lookup and readdir for back compatibility*/
  80. struct mutex mutex;
  81. };
  82. /** FUSE inode state bits */
  83. enum {
  84. /** Advise readdirplus */
  85. FUSE_I_ADVISE_RDPLUS,
  86. /** Initialized with readdirplus */
  87. FUSE_I_INIT_RDPLUS,
  88. /** An operation changing file size is in progress */
  89. FUSE_I_SIZE_UNSTABLE,
  90. };
  91. struct fuse_conn;
  92. /** FUSE specific file data */
  93. struct fuse_file {
  94. /** Fuse connection for this file */
  95. struct fuse_conn *fc;
  96. /** Request reserved for flush and release */
  97. struct fuse_req *reserved_req;
  98. /** Kernel file handle guaranteed to be unique */
  99. u64 kh;
  100. /** File handle used by userspace */
  101. u64 fh;
  102. /** Node id of this file */
  103. u64 nodeid;
  104. /** Refcount */
  105. atomic_t count;
  106. /** FOPEN_* flags returned by open */
  107. u32 open_flags;
  108. /** Entry on inode's write_files list */
  109. struct list_head write_entry;
  110. /** RB node to be linked on fuse_conn->polled_files */
  111. struct rb_node polled_node;
  112. /** Wait queue head for poll */
  113. wait_queue_head_t poll_wait;
  114. /** Has flock been performed on this file? */
  115. bool flock:1;
  116. };
  117. /** One input argument of a request */
  118. struct fuse_in_arg {
  119. unsigned size;
  120. const void *value;
  121. };
  122. /** The request input */
  123. struct fuse_in {
  124. /** The request header */
  125. struct fuse_in_header h;
  126. /** True if the data for the last argument is in req->pages */
  127. unsigned argpages:1;
  128. /** Number of arguments */
  129. unsigned numargs;
  130. /** Array of arguments */
  131. struct fuse_in_arg args[3];
  132. };
  133. /** One output argument of a request */
  134. struct fuse_arg {
  135. unsigned size;
  136. void *value;
  137. };
  138. /** The request output */
  139. struct fuse_out {
  140. /** Header returned from userspace */
  141. struct fuse_out_header h;
  142. /*
  143. * The following bitfields are not changed during the request
  144. * processing
  145. */
  146. /** Last argument is variable length (can be shorter than
  147. arg->size) */
  148. unsigned argvar:1;
  149. /** Last argument is a list of pages to copy data to */
  150. unsigned argpages:1;
  151. /** Zero partially or not copied pages */
  152. unsigned page_zeroing:1;
  153. /** Pages may be replaced with new ones */
  154. unsigned page_replace:1;
  155. /** Number or arguments */
  156. unsigned numargs;
  157. /** Array of arguments */
  158. struct fuse_arg args[2];
  159. };
  160. /** FUSE page descriptor */
  161. struct fuse_page_desc {
  162. unsigned int length;
  163. unsigned int offset;
  164. };
  165. struct fuse_args {
  166. struct {
  167. struct {
  168. uint32_t opcode;
  169. uint64_t nodeid;
  170. } h;
  171. unsigned numargs;
  172. struct fuse_in_arg args[3];
  173. } in;
  174. struct {
  175. unsigned argvar:1;
  176. unsigned numargs;
  177. struct fuse_arg args[2];
  178. } out;
  179. };
  180. #define FUSE_ARGS(args) struct fuse_args args = {}
  181. /** The request IO state (for asynchronous processing) */
  182. struct fuse_io_priv {
  183. struct kref refcnt;
  184. int async;
  185. spinlock_t lock;
  186. unsigned reqs;
  187. ssize_t bytes;
  188. size_t size;
  189. __u64 offset;
  190. bool write;
  191. int err;
  192. struct kiocb *iocb;
  193. struct file *file;
  194. struct completion *done;
  195. bool blocking;
  196. };
  197. #define FUSE_IO_PRIV_SYNC(f) \
  198. { \
  199. .refcnt = { ATOMIC_INIT(1) }, \
  200. .async = 0, \
  201. .file = f, \
  202. }
  203. /**
  204. * Request flags
  205. *
  206. * FR_ISREPLY: set if the request has reply
  207. * FR_FORCE: force sending of the request even if interrupted
  208. * FR_BACKGROUND: request is sent in the background
  209. * FR_WAITING: request is counted as "waiting"
  210. * FR_ABORTED: the request was aborted
  211. * FR_INTERRUPTED: the request has been interrupted
  212. * FR_LOCKED: data is being copied to/from the request
  213. * FR_PENDING: request is not yet in userspace
  214. * FR_SENT: request is in userspace, waiting for an answer
  215. * FR_FINISHED: request is finished
  216. * FR_PRIVATE: request is on private list
  217. */
  218. enum fuse_req_flag {
  219. FR_ISREPLY,
  220. FR_FORCE,
  221. FR_BACKGROUND,
  222. FR_WAITING,
  223. FR_ABORTED,
  224. FR_INTERRUPTED,
  225. FR_LOCKED,
  226. FR_PENDING,
  227. FR_SENT,
  228. FR_FINISHED,
  229. FR_PRIVATE,
  230. };
  231. /**
  232. * A request to the client
  233. *
  234. * .waitq.lock protects the following fields:
  235. * - FR_ABORTED
  236. * - FR_LOCKED (may also be modified under fc->lock, tested under both)
  237. */
  238. struct fuse_req {
  239. /** This can be on either pending processing or io lists in
  240. fuse_conn */
  241. struct list_head list;
  242. /** Entry on the interrupts list */
  243. struct list_head intr_entry;
  244. /** refcount */
  245. atomic_t count;
  246. /** Unique ID for the interrupt request */
  247. u64 intr_unique;
  248. /* Request flags, updated with test/set/clear_bit() */
  249. unsigned long flags;
  250. /** The request input */
  251. struct fuse_in in;
  252. /** The request output */
  253. struct fuse_out out;
  254. /** Used to wake up the task waiting for completion of request*/
  255. wait_queue_head_t waitq;
  256. /** Data for asynchronous requests */
  257. union {
  258. struct {
  259. struct fuse_release_in in;
  260. struct inode *inode;
  261. } release;
  262. struct fuse_init_in init_in;
  263. struct fuse_init_out init_out;
  264. struct cuse_init_in cuse_init_in;
  265. struct {
  266. struct fuse_read_in in;
  267. u64 attr_ver;
  268. } read;
  269. struct {
  270. struct fuse_write_in in;
  271. struct fuse_write_out out;
  272. struct fuse_req *next;
  273. } write;
  274. struct fuse_notify_retrieve_in retrieve_in;
  275. } misc;
  276. /** page vector */
  277. struct page **pages;
  278. /** page-descriptor vector */
  279. struct fuse_page_desc *page_descs;
  280. /** size of the 'pages' array */
  281. unsigned max_pages;
  282. /** inline page vector */
  283. struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
  284. /** inline page-descriptor vector */
  285. struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES];
  286. /** number of pages in vector */
  287. unsigned num_pages;
  288. /** File used in the request (or NULL) */
  289. struct fuse_file *ff;
  290. /** Inode used in the request or NULL */
  291. struct inode *inode;
  292. /** AIO control block */
  293. struct fuse_io_priv *io;
  294. /** Link on fi->writepages */
  295. struct list_head writepages_entry;
  296. /** Request completion callback */
  297. void (*end)(struct fuse_conn *, struct fuse_req *);
  298. /** Request is stolen from fuse_file->reserved_req */
  299. struct file *stolen_file;
  300. };
  301. struct fuse_iqueue {
  302. /** Connection established */
  303. unsigned connected;
  304. /** Readers of the connection are waiting on this */
  305. wait_queue_head_t waitq;
  306. /** The next unique request id */
  307. u64 reqctr;
  308. /** The list of pending requests */
  309. struct list_head pending;
  310. /** Pending interrupts */
  311. struct list_head interrupts;
  312. /** Queue of pending forgets */
  313. struct fuse_forget_link forget_list_head;
  314. struct fuse_forget_link *forget_list_tail;
  315. /** Batching of FORGET requests (positive indicates FORGET batch) */
  316. int forget_batch;
  317. /** O_ASYNC requests */
  318. struct fasync_struct *fasync;
  319. };
  320. struct fuse_pqueue {
  321. /** Connection established */
  322. unsigned connected;
  323. /** Lock protecting accessess to members of this structure */
  324. spinlock_t lock;
  325. /** The list of requests being processed */
  326. struct list_head processing;
  327. /** The list of requests under I/O */
  328. struct list_head io;
  329. };
  330. /**
  331. * Fuse device instance
  332. */
  333. struct fuse_dev {
  334. /** Fuse connection for this device */
  335. struct fuse_conn *fc;
  336. /** Processing queue */
  337. struct fuse_pqueue pq;
  338. /** list entry on fc->devices */
  339. struct list_head entry;
  340. };
  341. /**
  342. * A Fuse connection.
  343. *
  344. * This structure is created, when the filesystem is mounted, and is
  345. * destroyed, when the client device is closed and the filesystem is
  346. * unmounted.
  347. */
  348. struct fuse_conn {
  349. /** Lock protecting accessess to members of this structure */
  350. spinlock_t lock;
  351. /** Refcount */
  352. atomic_t count;
  353. /** Number of fuse_dev's */
  354. atomic_t dev_count;
  355. struct rcu_head rcu;
  356. /** The user id for this mount */
  357. kuid_t user_id;
  358. /** The group id for this mount */
  359. kgid_t group_id;
  360. /** Maximum read size */
  361. unsigned max_read;
  362. /** Maximum write size */
  363. unsigned max_write;
  364. /** Input queue */
  365. struct fuse_iqueue iq;
  366. /** The next unique kernel file handle */
  367. u64 khctr;
  368. /** rbtree of fuse_files waiting for poll events indexed by ph */
  369. struct rb_root polled_files;
  370. /** Maximum number of outstanding background requests */
  371. unsigned max_background;
  372. /** Number of background requests at which congestion starts */
  373. unsigned congestion_threshold;
  374. /** Number of requests currently in the background */
  375. unsigned num_background;
  376. /** Number of background requests currently queued for userspace */
  377. unsigned active_background;
  378. /** The list of background requests set aside for later queuing */
  379. struct list_head bg_queue;
  380. /** Flag indicating that INIT reply has been received. Allocating
  381. * any fuse request will be suspended until the flag is set */
  382. int initialized;
  383. /** Flag indicating if connection is blocked. This will be
  384. the case before the INIT reply is received, and if there
  385. are too many outstading backgrounds requests */
  386. int blocked;
  387. /** waitq for blocked connection */
  388. wait_queue_head_t blocked_waitq;
  389. /** waitq for reserved requests */
  390. wait_queue_head_t reserved_req_waitq;
  391. /** Connection established, cleared on umount, connection
  392. abort and device release */
  393. unsigned connected;
  394. /** Connection failed (version mismatch). Cannot race with
  395. setting other bitfields since it is only set once in INIT
  396. reply, before any other request, and never cleared */
  397. unsigned conn_error:1;
  398. /** Connection successful. Only set in INIT */
  399. unsigned conn_init:1;
  400. /** Do readpages asynchronously? Only set in INIT */
  401. unsigned async_read:1;
  402. /** Do not send separate SETATTR request before open(O_TRUNC) */
  403. unsigned atomic_o_trunc:1;
  404. /** Filesystem supports NFS exporting. Only set in INIT */
  405. unsigned export_support:1;
  406. /** Set if bdi is valid */
  407. unsigned bdi_initialized:1;
  408. /** write-back cache policy (default is write-through) */
  409. unsigned writeback_cache:1;
  410. /** allow parallel lookups and readdir (default is serialized) */
  411. unsigned parallel_dirops:1;
  412. /** handle fs handles killing suid/sgid/cap on write/chown/trunc */
  413. unsigned handle_killpriv:1;
  414. /*
  415. * The following bitfields are only for optimization purposes
  416. * and hence races in setting them will not cause malfunction
  417. */
  418. /** Is open/release not implemented by fs? */
  419. unsigned no_open:1;
  420. /** Is fsync not implemented by fs? */
  421. unsigned no_fsync:1;
  422. /** Is fsyncdir not implemented by fs? */
  423. unsigned no_fsyncdir:1;
  424. /** Is flush not implemented by fs? */
  425. unsigned no_flush:1;
  426. /** Is setxattr not implemented by fs? */
  427. unsigned no_setxattr:1;
  428. /** Is getxattr not implemented by fs? */
  429. unsigned no_getxattr:1;
  430. /** Is listxattr not implemented by fs? */
  431. unsigned no_listxattr:1;
  432. /** Is removexattr not implemented by fs? */
  433. unsigned no_removexattr:1;
  434. /** Are posix file locking primitives not implemented by fs? */
  435. unsigned no_lock:1;
  436. /** Is access not implemented by fs? */
  437. unsigned no_access:1;
  438. /** Is create not implemented by fs? */
  439. unsigned no_create:1;
  440. /** Is interrupt not implemented by fs? */
  441. unsigned no_interrupt:1;
  442. /** Is bmap not implemented by fs? */
  443. unsigned no_bmap:1;
  444. /** Is poll not implemented by fs? */
  445. unsigned no_poll:1;
  446. /** Do multi-page cached writes */
  447. unsigned big_writes:1;
  448. /** Don't apply umask to creation modes */
  449. unsigned dont_mask:1;
  450. /** Are BSD file locking primitives not implemented by fs? */
  451. unsigned no_flock:1;
  452. /** Is fallocate not implemented by fs? */
  453. unsigned no_fallocate:1;
  454. /** Is rename with flags implemented by fs? */
  455. unsigned no_rename2:1;
  456. /** Use enhanced/automatic page cache invalidation. */
  457. unsigned auto_inval_data:1;
  458. /** Does the filesystem support readdirplus? */
  459. unsigned do_readdirplus:1;
  460. /** Does the filesystem want adaptive readdirplus? */
  461. unsigned readdirplus_auto:1;
  462. /** Does the filesystem support asynchronous direct-IO submission? */
  463. unsigned async_dio:1;
  464. /** Is lseek not implemented by fs? */
  465. unsigned no_lseek:1;
  466. /** Does the filesystem support posix acls? */
  467. unsigned posix_acl:1;
  468. /** Check permissions based on the file mode or not? */
  469. unsigned default_permissions:1;
  470. /** Allow other than the mounter user to access the filesystem ? */
  471. unsigned allow_other:1;
  472. /** The number of requests waiting for completion */
  473. atomic_t num_waiting;
  474. /** Negotiated minor version */
  475. unsigned minor;
  476. /** Backing dev info */
  477. struct backing_dev_info bdi;
  478. /** Entry on the fuse_conn_list */
  479. struct list_head entry;
  480. /** Device ID from super block */
  481. dev_t dev;
  482. /** Dentries in the control filesystem */
  483. struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES];
  484. /** number of dentries used in the above array */
  485. int ctl_ndents;
  486. /** Key for lock owner ID scrambling */
  487. u32 scramble_key[4];
  488. /** Reserved request for the DESTROY message */
  489. struct fuse_req *destroy_req;
  490. /** Version counter for attribute changes */
  491. u64 attr_version;
  492. /** Called on final put */
  493. void (*release)(struct fuse_conn *);
  494. /** Super block for this connection. */
  495. struct super_block *sb;
  496. /** Read/write semaphore to hold when accessing sb. */
  497. struct rw_semaphore killsb;
  498. /** List of device instances belonging to this connection */
  499. struct list_head devices;
  500. };
  501. static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb)
  502. {
  503. return sb->s_fs_info;
  504. }
  505. static inline struct fuse_conn *get_fuse_conn(struct inode *inode)
  506. {
  507. return get_fuse_conn_super(inode->i_sb);
  508. }
  509. static inline struct fuse_inode *get_fuse_inode(struct inode *inode)
  510. {
  511. return container_of(inode, struct fuse_inode, inode);
  512. }
  513. static inline u64 get_node_id(struct inode *inode)
  514. {
  515. return get_fuse_inode(inode)->nodeid;
  516. }
  517. /** Device operations */
  518. extern const struct file_operations fuse_dev_operations;
  519. extern const struct dentry_operations fuse_dentry_operations;
  520. extern const struct dentry_operations fuse_root_dentry_operations;
  521. /**
  522. * Inode to nodeid comparison.
  523. */
  524. int fuse_inode_eq(struct inode *inode, void *_nodeidp);
  525. /**
  526. * Get a filled in inode
  527. */
  528. struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
  529. int generation, struct fuse_attr *attr,
  530. u64 attr_valid, u64 attr_version);
  531. int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name,
  532. struct fuse_entry_out *outarg, struct inode **inode);
  533. /**
  534. * Send FORGET command
  535. */
  536. void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget,
  537. u64 nodeid, u64 nlookup);
  538. struct fuse_forget_link *fuse_alloc_forget(void);
  539. /* Used by READDIRPLUS */
  540. void fuse_force_forget(struct file *file, u64 nodeid);
  541. /**
  542. * Initialize READ or READDIR request
  543. */
  544. void fuse_read_fill(struct fuse_req *req, struct file *file,
  545. loff_t pos, size_t count, int opcode);
  546. /**
  547. * Send OPEN or OPENDIR request
  548. */
  549. int fuse_open_common(struct inode *inode, struct file *file, bool isdir);
  550. struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
  551. struct fuse_file *fuse_file_get(struct fuse_file *ff);
  552. void fuse_file_free(struct fuse_file *ff);
  553. void fuse_finish_open(struct inode *inode, struct file *file);
  554. void fuse_sync_release(struct fuse_file *ff, int flags);
  555. /**
  556. * Send RELEASE or RELEASEDIR request
  557. */
  558. void fuse_release_common(struct file *file, int opcode);
  559. /**
  560. * Send FSYNC or FSYNCDIR request
  561. */
  562. int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
  563. int datasync, int isdir);
  564. /**
  565. * Notify poll wakeup
  566. */
  567. int fuse_notify_poll_wakeup(struct fuse_conn *fc,
  568. struct fuse_notify_poll_wakeup_out *outarg);
  569. /**
  570. * Initialize file operations on a regular file
  571. */
  572. void fuse_init_file_inode(struct inode *inode);
  573. /**
  574. * Initialize inode operations on regular files and special files
  575. */
  576. void fuse_init_common(struct inode *inode);
  577. /**
  578. * Initialize inode and file operations on a directory
  579. */
  580. void fuse_init_dir(struct inode *inode);
  581. /**
  582. * Initialize inode operations on a symlink
  583. */
  584. void fuse_init_symlink(struct inode *inode);
  585. /**
  586. * Change attributes of an inode
  587. */
  588. void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
  589. u64 attr_valid, u64 attr_version);
  590. void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
  591. u64 attr_valid);
  592. /**
  593. * Initialize the client device
  594. */
  595. int fuse_dev_init(void);
  596. /**
  597. * Cleanup the client device
  598. */
  599. void fuse_dev_cleanup(void);
  600. int fuse_ctl_init(void);
  601. void __exit fuse_ctl_cleanup(void);
  602. /**
  603. * Allocate a request
  604. */
  605. struct fuse_req *fuse_request_alloc(unsigned npages);
  606. struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
  607. /**
  608. * Free a request
  609. */
  610. void fuse_request_free(struct fuse_req *req);
  611. /**
  612. * Get a request, may fail with -ENOMEM,
  613. * caller should specify # elements in req->pages[] explicitly
  614. */
  615. struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages);
  616. struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
  617. unsigned npages);
  618. /*
  619. * Increment reference count on request
  620. */
  621. void __fuse_get_request(struct fuse_req *req);
  622. /**
  623. * Gets a requests for a file operation, always succeeds
  624. */
  625. struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
  626. struct file *file);
  627. /**
  628. * Decrement reference count of a request. If count goes to zero free
  629. * the request.
  630. */
  631. void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);
  632. /**
  633. * Send a request (synchronous)
  634. */
  635. void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req);
  636. /**
  637. * Simple request sending that does request allocation and freeing
  638. */
  639. ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args);
  640. /**
  641. * Send a request in the background
  642. */
  643. void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
  644. void fuse_request_send_background_locked(struct fuse_conn *fc,
  645. struct fuse_req *req);
  646. /* Abort all requests */
  647. void fuse_abort_conn(struct fuse_conn *fc);
  648. /**
  649. * Invalidate inode attributes
  650. */
  651. void fuse_invalidate_attr(struct inode *inode);
  652. void fuse_invalidate_entry_cache(struct dentry *entry);
  653. void fuse_invalidate_atime(struct inode *inode);
  654. /**
  655. * Acquire reference to fuse_conn
  656. */
  657. struct fuse_conn *fuse_conn_get(struct fuse_conn *fc);
  658. /**
  659. * Initialize fuse_conn
  660. */
  661. void fuse_conn_init(struct fuse_conn *fc);
  662. /**
  663. * Release reference to fuse_conn
  664. */
  665. void fuse_conn_put(struct fuse_conn *fc);
  666. struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc);
  667. void fuse_dev_free(struct fuse_dev *fud);
  668. /**
  669. * Add connection to control filesystem
  670. */
  671. int fuse_ctl_add_conn(struct fuse_conn *fc);
  672. /**
  673. * Remove connection from control filesystem
  674. */
  675. void fuse_ctl_remove_conn(struct fuse_conn *fc);
  676. /**
  677. * Is file type valid?
  678. */
  679. int fuse_valid_type(int m);
  680. /**
  681. * Is current process allowed to perform filesystem operation?
  682. */
  683. int fuse_allow_current_process(struct fuse_conn *fc);
  684. u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id);
  685. void fuse_update_ctime(struct inode *inode);
  686. int fuse_update_attributes(struct inode *inode, struct kstat *stat,
  687. struct file *file, bool *refreshed);
  688. void fuse_flush_writepages(struct inode *inode);
  689. void fuse_set_nowrite(struct inode *inode);
  690. void fuse_release_nowrite(struct inode *inode);
  691. u64 fuse_get_attr_version(struct fuse_conn *fc);
  692. /**
  693. * File-system tells the kernel to invalidate cache for the given node id.
  694. */
  695. int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
  696. loff_t offset, loff_t len);
  697. /**
  698. * File-system tells the kernel to invalidate parent attributes and
  699. * the dentry matching parent/name.
  700. *
  701. * If the child_nodeid is non-zero and:
  702. * - matches the inode number for the dentry matching parent/name,
  703. * - is not a mount point
  704. * - is a file or oan empty directory
  705. * then the dentry is unhashed (d_delete()).
  706. */
  707. int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid,
  708. u64 child_nodeid, struct qstr *name);
  709. int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file,
  710. bool isdir);
  711. /**
  712. * fuse_direct_io() flags
  713. */
  714. /** If set, it is WRITE; otherwise - READ */
  715. #define FUSE_DIO_WRITE (1 << 0)
  716. /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */
  717. #define FUSE_DIO_CUSE (1 << 1)
  718. ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
  719. loff_t *ppos, int flags);
  720. long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg,
  721. unsigned int flags);
  722. long fuse_ioctl_common(struct file *file, unsigned int cmd,
  723. unsigned long arg, unsigned int flags);
  724. unsigned fuse_file_poll(struct file *file, poll_table *wait);
  725. int fuse_dev_release(struct inode *inode, struct file *file);
  726. bool fuse_write_update_size(struct inode *inode, loff_t pos);
  727. int fuse_flush_times(struct inode *inode, struct fuse_file *ff);
  728. int fuse_write_inode(struct inode *inode, struct writeback_control *wbc);
  729. int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
  730. struct file *file);
  731. void fuse_set_initialized(struct fuse_conn *fc);
  732. void fuse_unlock_inode(struct inode *inode);
  733. void fuse_lock_inode(struct inode *inode);
  734. int fuse_setxattr(struct inode *inode, const char *name, const void *value,
  735. size_t size, int flags);
  736. ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value,
  737. size_t size);
  738. ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size);
  739. int fuse_removexattr(struct inode *inode, const char *name);
  740. extern const struct xattr_handler *fuse_xattr_handlers[];
  741. extern const struct xattr_handler *fuse_acl_xattr_handlers[];
  742. struct posix_acl;
  743. struct posix_acl *fuse_get_acl(struct inode *inode, int type);
  744. int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type);
  745. #endif /* _FS_FUSE_I_H */