fuse_i.h 24 KB

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