You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1850 lines
52 KiB

  1. /*
  2. FUSE: Filesystem in Userspace
  3. Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
  4. This program can be distributed under the terms of the GNU LGPLv2.
  5. See the file COPYING.LIB.
  6. */
  7. #ifndef _FUSE_LOWLEVEL_H_
  8. #define _FUSE_LOWLEVEL_H_
  9. /** @file
  10. *
  11. * Low level API
  12. *
  13. * IMPORTANT: you should define FUSE_USE_VERSION before including this
  14. * header. To use the newest API define it to 26 (recommended for any
  15. * new application), to use the old API define it to 24 (default) or
  16. * 25
  17. */
  18. #ifndef FUSE_USE_VERSION
  19. #define FUSE_USE_VERSION 24
  20. #endif
  21. #include "fuse_common.h"
  22. #include <utime.h>
  23. #include <fcntl.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/statvfs.h>
  27. #include <sys/uio.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* ----------------------------------------------------------- *
  32. * Miscellaneous definitions *
  33. * ----------------------------------------------------------- */
  34. /** The node ID of the root inode */
  35. #define FUSE_ROOT_ID 1
  36. /** Inode number type */
  37. typedef unsigned long fuse_ino_t;
  38. /** Request pointer type */
  39. typedef struct fuse_req *fuse_req_t;
  40. /**
  41. * Session
  42. *
  43. * This provides hooks for processing requests, and exiting
  44. */
  45. struct fuse_session;
  46. /**
  47. * Channel
  48. *
  49. * A communication channel, providing hooks for sending and receiving
  50. * messages
  51. */
  52. struct fuse_chan;
  53. /** Directory entry parameters supplied to fuse_reply_entry() */
  54. struct fuse_entry_param {
  55. /** Unique inode number
  56. *
  57. * In lookup, zero means negative entry (from version 2.5)
  58. * Returning ENOENT also means negative entry, but by setting zero
  59. * ino the kernel may cache negative entries for entry_timeout
  60. * seconds.
  61. */
  62. fuse_ino_t ino;
  63. /** Generation number for this entry.
  64. *
  65. * If the file system will be exported over NFS, the
  66. * ino/generation pairs need to be unique over the file
  67. * system's lifetime (rather than just the mount time). So if
  68. * the file system reuses an inode after it has been deleted,
  69. * it must assign a new, previously unused generation number
  70. * to the inode at the same time.
  71. *
  72. * The generation must be non-zero, otherwise FUSE will treat
  73. * it as an error.
  74. *
  75. */
  76. unsigned long generation;
  77. /** Inode attributes.
  78. *
  79. * Even if attr_timeout == 0, attr must be correct. For example,
  80. * for open(), FUSE uses attr.st_size from lookup() to determine
  81. * how many bytes to request. If this value is not correct,
  82. * incorrect data will be returned.
  83. */
  84. struct stat attr;
  85. /** Validity timeout (in seconds) for the attributes */
  86. double attr_timeout;
  87. /** Validity timeout (in seconds) for the name */
  88. double entry_timeout;
  89. };
  90. /** Additional context associated with requests */
  91. struct fuse_ctx {
  92. /** User ID of the calling process */
  93. uid_t uid;
  94. /** Group ID of the calling process */
  95. gid_t gid;
  96. /** Thread ID of the calling process */
  97. pid_t pid;
  98. /** Umask of the calling process (introduced in version 2.8) */
  99. mode_t umask;
  100. };
  101. struct fuse_forget_data {
  102. uint64_t ino;
  103. uint64_t nlookup;
  104. };
  105. /* 'to_set' flags in setattr */
  106. #define FUSE_SET_ATTR_MODE (1 << 0)
  107. #define FUSE_SET_ATTR_UID (1 << 1)
  108. #define FUSE_SET_ATTR_GID (1 << 2)
  109. #define FUSE_SET_ATTR_SIZE (1 << 3)
  110. #define FUSE_SET_ATTR_ATIME (1 << 4)
  111. #define FUSE_SET_ATTR_MTIME (1 << 5)
  112. #define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
  113. #define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
  114. /* ----------------------------------------------------------- *
  115. * Request methods and replies *
  116. * ----------------------------------------------------------- */
  117. /**
  118. * Low level filesystem operations
  119. *
  120. * Most of the methods (with the exception of init and destroy)
  121. * receive a request handle (fuse_req_t) as their first argument.
  122. * This handle must be passed to one of the specified reply functions.
  123. *
  124. * This may be done inside the method invocation, or after the call
  125. * has returned. The request handle is valid until one of the reply
  126. * functions is called.
  127. *
  128. * Other pointer arguments (name, fuse_file_info, etc) are not valid
  129. * after the call has returned, so if they are needed later, their
  130. * contents have to be copied.
  131. *
  132. * The filesystem sometimes needs to handle a return value of -ENOENT
  133. * from the reply function, which means, that the request was
  134. * interrupted, and the reply discarded. For example if
  135. * fuse_reply_open() return -ENOENT means, that the release method for
  136. * this file will not be called.
  137. */
  138. struct fuse_lowlevel_ops {
  139. /**
  140. * Initialize filesystem
  141. *
  142. * Called before any other filesystem method
  143. *
  144. * There's no reply to this function
  145. *
  146. * @param userdata the user data passed to fuse_lowlevel_new()
  147. */
  148. void (*init) (void *userdata, struct fuse_conn_info *conn);
  149. /**
  150. * Clean up filesystem
  151. *
  152. * Called on filesystem exit
  153. *
  154. * There's no reply to this function
  155. *
  156. * @param userdata the user data passed to fuse_lowlevel_new()
  157. */
  158. void (*destroy) (void *userdata);
  159. /**
  160. * Look up a directory entry by name and get its attributes.
  161. *
  162. * Valid replies:
  163. * fuse_reply_entry
  164. * fuse_reply_err
  165. *
  166. * @param req request handle
  167. * @param parent inode number of the parent directory
  168. * @param name the name to look up
  169. */
  170. void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
  171. /**
  172. * Forget about an inode
  173. *
  174. * This function is called when the kernel removes an inode
  175. * from its internal caches.
  176. *
  177. * The inode's lookup count increases by one for every call to
  178. * fuse_reply_entry and fuse_reply_create. The nlookup parameter
  179. * indicates by how much the lookup count should be decreased.
  180. *
  181. * Inodes with a non-zero lookup count may receive request from
  182. * the kernel even after calls to unlink, rmdir or (when
  183. * overwriting an existing file) rename. Filesystems must handle
  184. * such requests properly and it is recommended to defer removal
  185. * of the inode until the lookup count reaches zero. Calls to
  186. * unlink, remdir or rename will be followed closely by forget
  187. * unless the file or directory is open, in which case the
  188. * kernel issues forget only after the release or releasedir
  189. * calls.
  190. *
  191. * Note that if a file system will be exported over NFS the
  192. * inodes lifetime must extend even beyond forget. See the
  193. * generation field in struct fuse_entry_param above.
  194. *
  195. * On unmount the lookup count for all inodes implicitly drops
  196. * to zero. It is not guaranteed that the file system will
  197. * receive corresponding forget messages for the affected
  198. * inodes.
  199. *
  200. * Valid replies:
  201. * fuse_reply_none
  202. *
  203. * @param req request handle
  204. * @param ino the inode number
  205. * @param nlookup the number of lookups to forget
  206. */
  207. void (*forget) (fuse_req_t req, fuse_ino_t ino, unsigned long nlookup);
  208. /**
  209. * Get file attributes
  210. *
  211. * Valid replies:
  212. * fuse_reply_attr
  213. * fuse_reply_err
  214. *
  215. * @param req request handle
  216. * @param ino the inode number
  217. * @param fi for future use, currently always NULL
  218. */
  219. void (*getattr) (fuse_req_t req, fuse_ino_t ino,
  220. struct fuse_file_info *fi);
  221. /**
  222. * Set file attributes
  223. *
  224. * In the 'attr' argument only members indicated by the 'to_set'
  225. * bitmask contain valid values. Other members contain undefined
  226. * values.
  227. *
  228. * If the setattr was invoked from the ftruncate() system call
  229. * under Linux kernel versions 2.6.15 or later, the fi->fh will
  230. * contain the value set by the open method or will be undefined
  231. * if the open method didn't set any value. Otherwise (not
  232. * ftruncate call, or kernel version earlier than 2.6.15) the fi
  233. * parameter will be NULL.
  234. *
  235. * Valid replies:
  236. * fuse_reply_attr
  237. * fuse_reply_err
  238. *
  239. * @param req request handle
  240. * @param ino the inode number
  241. * @param attr the attributes
  242. * @param to_set bit mask of attributes which should be set
  243. * @param fi file information, or NULL
  244. *
  245. * Changed in version 2.5:
  246. * file information filled in for ftruncate
  247. */
  248. void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
  249. int to_set, struct fuse_file_info *fi);
  250. /**
  251. * Read symbolic link
  252. *
  253. * Valid replies:
  254. * fuse_reply_readlink
  255. * fuse_reply_err
  256. *
  257. * @param req request handle
  258. * @param ino the inode number
  259. */
  260. void (*readlink) (fuse_req_t req, fuse_ino_t ino);
  261. /**
  262. * Create file node
  263. *
  264. * Create a regular file, character device, block device, fifo or
  265. * socket node.
  266. *
  267. * Valid replies:
  268. * fuse_reply_entry
  269. * fuse_reply_err
  270. *
  271. * @param req request handle
  272. * @param parent inode number of the parent directory
  273. * @param name to create
  274. * @param mode file type and mode with which to create the new file
  275. * @param rdev the device number (only valid if created file is a device)
  276. */
  277. void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
  278. mode_t mode, dev_t rdev);
  279. /**
  280. * Create a directory
  281. *
  282. * Valid replies:
  283. * fuse_reply_entry
  284. * fuse_reply_err
  285. *
  286. * @param req request handle
  287. * @param parent inode number of the parent directory
  288. * @param name to create
  289. * @param mode with which to create the new file
  290. */
  291. void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
  292. mode_t mode);
  293. /**
  294. * Remove a file
  295. *
  296. * If the file's inode's lookup count is non-zero, the file
  297. * system is expected to postpone any removal of the inode
  298. * until the lookup count reaches zero (see description of the
  299. * forget function).
  300. *
  301. * Valid replies:
  302. * fuse_reply_err
  303. *
  304. * @param req request handle
  305. * @param parent inode number of the parent directory
  306. * @param name to remove
  307. */
  308. void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
  309. /**
  310. * Remove a directory
  311. *
  312. * If the directory's inode's lookup count is non-zero, the
  313. * file system is expected to postpone any removal of the
  314. * inode until the lookup count reaches zero (see description
  315. * of the forget function).
  316. *
  317. * Valid replies:
  318. * fuse_reply_err
  319. *
  320. * @param req request handle
  321. * @param parent inode number of the parent directory
  322. * @param name to remove
  323. */
  324. void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
  325. /**
  326. * Create a symbolic link
  327. *
  328. * Valid replies:
  329. * fuse_reply_entry
  330. * fuse_reply_err
  331. *
  332. * @param req request handle
  333. * @param link the contents of the symbolic link
  334. * @param parent inode number of the parent directory
  335. * @param name to create
  336. */
  337. void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
  338. const char *name);
  339. /** Rename a file
  340. *
  341. * If the target exists it should be atomically replaced. If
  342. * the target's inode's lookup count is non-zero, the file
  343. * system is expected to postpone any removal of the inode
  344. * until the lookup count reaches zero (see description of the
  345. * forget function).
  346. *
  347. * Valid replies:
  348. * fuse_reply_err
  349. *
  350. * @param req request handle
  351. * @param parent inode number of the old parent directory
  352. * @param name old name
  353. * @param newparent inode number of the new parent directory
  354. * @param newname new name
  355. */
  356. void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
  357. fuse_ino_t newparent, const char *newname);
  358. /**
  359. * Create a hard link
  360. *
  361. * Valid replies:
  362. * fuse_reply_entry
  363. * fuse_reply_err
  364. *
  365. * @param req request handle
  366. * @param ino the old inode number
  367. * @param newparent inode number of the new parent directory
  368. * @param newname new name to create
  369. */
  370. void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
  371. const char *newname);
  372. /**
  373. * Open a file
  374. *
  375. * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and
  376. * O_TRUNC) are available in fi->flags.
  377. *
  378. * Filesystem may store an arbitrary file handle (pointer, index,
  379. * etc) in fi->fh, and use this in other all other file operations
  380. * (read, write, flush, release, fsync).
  381. *
  382. * Filesystem may also implement stateless file I/O and not store
  383. * anything in fi->fh.
  384. *
  385. * There are also some flags (direct_io, keep_cache) which the
  386. * filesystem may set in fi, to change the way the file is opened.
  387. * See fuse_file_info structure in <fuse_common.h> for more details.
  388. *
  389. * Valid replies:
  390. * fuse_reply_open
  391. * fuse_reply_err
  392. *
  393. * @param req request handle
  394. * @param ino the inode number
  395. * @param fi file information
  396. */
  397. void (*open) (fuse_req_t req, fuse_ino_t ino,
  398. struct fuse_file_info *fi);
  399. /**
  400. * Read data
  401. *
  402. * Read should send exactly the number of bytes requested except
  403. * on EOF or error, otherwise the rest of the data will be
  404. * substituted with zeroes. An exception to this is when the file
  405. * has been opened in 'direct_io' mode, in which case the return
  406. * value of the read system call will reflect the return value of
  407. * this operation.
  408. *
  409. * fi->fh will contain the value set by the open method, or will
  410. * be undefined if the open method didn't set any value.
  411. *
  412. * Valid replies:
  413. * fuse_reply_buf
  414. * fuse_reply_iov
  415. * fuse_reply_data
  416. * fuse_reply_err
  417. *
  418. * @param req request handle
  419. * @param ino the inode number
  420. * @param size number of bytes to read
  421. * @param off offset to read from
  422. * @param fi file information
  423. */
  424. void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
  425. struct fuse_file_info *fi);
  426. /**
  427. * Write data
  428. *
  429. * Write should return exactly the number of bytes requested
  430. * except on error. An exception to this is when the file has
  431. * been opened in 'direct_io' mode, in which case the return value
  432. * of the write system call will reflect the return value of this
  433. * operation.
  434. *
  435. * fi->fh will contain the value set by the open method, or will
  436. * be undefined if the open method didn't set any value.
  437. *
  438. * Valid replies:
  439. * fuse_reply_write
  440. * fuse_reply_err
  441. *
  442. * @param req request handle
  443. * @param ino the inode number
  444. * @param buf data to write
  445. * @param size number of bytes to write
  446. * @param off offset to write to
  447. * @param fi file information
  448. */
  449. void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
  450. size_t size, off_t off, struct fuse_file_info *fi);
  451. /**
  452. * Flush method
  453. *
  454. * This is called on each close() of the opened file.
  455. *
  456. * Since file descriptors can be duplicated (dup, dup2, fork), for
  457. * one open call there may be many flush calls.
  458. *
  459. * Filesystems shouldn't assume that flush will always be called
  460. * after some writes, or that if will be called at all.
  461. *
  462. * fi->fh will contain the value set by the open method, or will
  463. * be undefined if the open method didn't set any value.
  464. *
  465. * NOTE: the name of the method is misleading, since (unlike
  466. * fsync) the filesystem is not forced to flush pending writes.
  467. * One reason to flush data, is if the filesystem wants to return
  468. * write errors.
  469. *
  470. * If the filesystem supports file locking operations (setlk,
  471. * getlk) it should remove all locks belonging to 'fi->owner'.
  472. *
  473. * Valid replies:
  474. * fuse_reply_err
  475. *
  476. * @param req request handle
  477. * @param ino the inode number
  478. * @param fi file information
  479. */
  480. void (*flush) (fuse_req_t req, fuse_ino_t ino,
  481. struct fuse_file_info *fi);
  482. /**
  483. * Release an open file
  484. *
  485. * Release is called when there are no more references to an open
  486. * file: all file descriptors are closed and all memory mappings
  487. * are unmapped.
  488. *
  489. * For every open call there will be exactly one release call.
  490. *
  491. * The filesystem may reply with an error, but error values are
  492. * not returned to close() or munmap() which triggered the
  493. * release.
  494. *
  495. * fi->fh will contain the value set by the open method, or will
  496. * be undefined if the open method didn't set any value.
  497. * fi->flags will contain the same flags as for open.
  498. *
  499. * Valid replies:
  500. * fuse_reply_err
  501. *
  502. * @param req request handle
  503. * @param ino the inode number
  504. * @param fi file information
  505. */
  506. void (*release) (fuse_req_t req, fuse_ino_t ino,
  507. struct fuse_file_info *fi);
  508. /**
  509. * Synchronize file contents
  510. *
  511. * If the datasync parameter is non-zero, then only the user data
  512. * should be flushed, not the meta data.
  513. *
  514. * Valid replies:
  515. * fuse_reply_err
  516. *
  517. * @param req request handle
  518. * @param ino the inode number
  519. * @param datasync flag indicating if only data should be flushed
  520. * @param fi file information
  521. */
  522. void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
  523. struct fuse_file_info *fi);
  524. /**
  525. * Open a directory
  526. *
  527. * Filesystem may store an arbitrary file handle (pointer, index,
  528. * etc) in fi->fh, and use this in other all other directory
  529. * stream operations (readdir, releasedir, fsyncdir).
  530. *
  531. * Filesystem may also implement stateless directory I/O and not
  532. * store anything in fi->fh, though that makes it impossible to
  533. * implement standard conforming directory stream operations in
  534. * case the contents of the directory can change between opendir
  535. * and releasedir.
  536. *
  537. * Valid replies:
  538. * fuse_reply_open
  539. * fuse_reply_err
  540. *
  541. * @param req request handle
  542. * @param ino the inode number
  543. * @param fi file information
  544. */
  545. void (*opendir) (fuse_req_t req, fuse_ino_t ino,
  546. struct fuse_file_info *fi);
  547. /**
  548. * Read directory
  549. *
  550. * Send a buffer filled using fuse_add_direntry(), with size not
  551. * exceeding the requested size. Send an empty buffer on end of
  552. * stream.
  553. *
  554. * fi->fh will contain the value set by the opendir method, or
  555. * will be undefined if the opendir method didn't set any value.
  556. *
  557. * Valid replies:
  558. * fuse_reply_buf
  559. * fuse_reply_data
  560. * fuse_reply_err
  561. *
  562. * @param req request handle
  563. * @param ino the inode number
  564. * @param size maximum number of bytes to send
  565. * @param off offset to continue reading the directory stream
  566. * @param fi file information
  567. */
  568. void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
  569. struct fuse_file_info *fi);
  570. /**
  571. * Release an open directory
  572. *
  573. * For every opendir call there will be exactly one releasedir
  574. * call.
  575. *
  576. * fi->fh will contain the value set by the opendir method, or
  577. * will be undefined if the opendir method didn't set any value.
  578. *
  579. * Valid replies:
  580. * fuse_reply_err
  581. *
  582. * @param req request handle
  583. * @param ino the inode number
  584. * @param fi file information
  585. */
  586. void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
  587. struct fuse_file_info *fi);
  588. /**
  589. * Synchronize directory contents
  590. *
  591. * If the datasync parameter is non-zero, then only the directory
  592. * contents should be flushed, not the meta data.
  593. *
  594. * fi->fh will contain the value set by the opendir method, or
  595. * will be undefined if the opendir method didn't set any value.
  596. *
  597. * Valid replies:
  598. * fuse_reply_err
  599. *
  600. * @param req request handle
  601. * @param ino the inode number
  602. * @param datasync flag indicating if only data should be flushed
  603. * @param fi file information
  604. */
  605. void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
  606. struct fuse_file_info *fi);
  607. /**
  608. * Get file system statistics
  609. *
  610. * Valid replies:
  611. * fuse_reply_statfs
  612. * fuse_reply_err
  613. *
  614. * @param req request handle
  615. * @param ino the inode number, zero means "undefined"
  616. */
  617. void (*statfs) (fuse_req_t req, fuse_ino_t ino);
  618. /**
  619. * Set an extended attribute
  620. *
  621. * Valid replies:
  622. * fuse_reply_err
  623. */
  624. void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
  625. const char *value, size_t size, int flags);
  626. /**
  627. * Get an extended attribute
  628. *
  629. * If size is zero, the size of the value should be sent with
  630. * fuse_reply_xattr.
  631. *
  632. * If the size is non-zero, and the value fits in the buffer, the
  633. * value should be sent with fuse_reply_buf.
  634. *
  635. * If the size is too small for the value, the ERANGE error should
  636. * be sent.
  637. *
  638. * Valid replies:
  639. * fuse_reply_buf
  640. * fuse_reply_data
  641. * fuse_reply_xattr
  642. * fuse_reply_err
  643. *
  644. * @param req request handle
  645. * @param ino the inode number
  646. * @param name of the extended attribute
  647. * @param size maximum size of the value to send
  648. */
  649. void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
  650. size_t size);
  651. /**
  652. * List extended attribute names
  653. *
  654. * If size is zero, the total size of the attribute list should be
  655. * sent with fuse_reply_xattr.
  656. *
  657. * If the size is non-zero, and the null character separated
  658. * attribute list fits in the buffer, the list should be sent with
  659. * fuse_reply_buf.
  660. *
  661. * If the size is too small for the list, the ERANGE error should
  662. * be sent.
  663. *
  664. * Valid replies:
  665. * fuse_reply_buf
  666. * fuse_reply_data
  667. * fuse_reply_xattr
  668. * fuse_reply_err
  669. *
  670. * @param req request handle
  671. * @param ino the inode number
  672. * @param size maximum size of the list to send
  673. */
  674. void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
  675. /**
  676. * Remove an extended attribute
  677. *
  678. * Valid replies:
  679. * fuse_reply_err
  680. *
  681. * @param req request handle
  682. * @param ino the inode number
  683. * @param name of the extended attribute
  684. */
  685. void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
  686. /**
  687. * Check file access permissions
  688. *
  689. * This will be called for the access() system call. If the
  690. * 'default_permissions' mount option is given, this method is not
  691. * called.
  692. *
  693. * This method is not called under Linux kernel versions 2.4.x
  694. *
  695. * Introduced in version 2.5
  696. *
  697. * Valid replies:
  698. * fuse_reply_err
  699. *
  700. * @param req request handle
  701. * @param ino the inode number
  702. * @param mask requested access mode
  703. */
  704. void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
  705. /**
  706. * Create and open a file
  707. *
  708. * If the file does not exist, first create it with the specified
  709. * mode, and then open it.
  710. *
  711. * Open flags (with the exception of O_NOCTTY) are available in
  712. * fi->flags.
  713. *
  714. * Filesystem may store an arbitrary file handle (pointer, index,
  715. * etc) in fi->fh, and use this in other all other file operations
  716. * (read, write, flush, release, fsync).
  717. *
  718. * There are also some flags (direct_io, keep_cache) which the
  719. * filesystem may set in fi, to change the way the file is opened.
  720. * See fuse_file_info structure in <fuse_common.h> for more details.
  721. *
  722. * If this method is not implemented or under Linux kernel
  723. * versions earlier than 2.6.15, the mknod() and open() methods
  724. * will be called instead.
  725. *
  726. * Introduced in version 2.5
  727. *
  728. * Valid replies:
  729. * fuse_reply_create
  730. * fuse_reply_err
  731. *
  732. * @param req request handle
  733. * @param parent inode number of the parent directory
  734. * @param name to create
  735. * @param mode file type and mode with which to create the new file
  736. * @param fi file information
  737. */
  738. void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
  739. mode_t mode, struct fuse_file_info *fi);
  740. /**
  741. * Test for a POSIX file lock
  742. *
  743. * Introduced in version 2.6
  744. *
  745. * Valid replies:
  746. * fuse_reply_lock
  747. * fuse_reply_err
  748. *
  749. * @param req request handle
  750. * @param ino the inode number
  751. * @param fi file information
  752. * @param lock the region/type to test
  753. */
  754. void (*getlk) (fuse_req_t req, fuse_ino_t ino,
  755. struct fuse_file_info *fi, struct flock *lock);
  756. /**
  757. * Acquire, modify or release a POSIX file lock
  758. *
  759. * For POSIX threads (NPTL) there's a 1-1 relation between pid and
  760. * owner, but otherwise this is not always the case. For checking
  761. * lock ownership, 'fi->owner' must be used. The l_pid field in
  762. * 'struct flock' should only be used to fill in this field in
  763. * getlk().
  764. *
  765. * Note: if the locking methods are not implemented, the kernel
  766. * will still allow file locking to work locally. Hence these are
  767. * only interesting for network filesystems and similar.
  768. *
  769. * Introduced in version 2.6
  770. *
  771. * Valid replies:
  772. * fuse_reply_err
  773. *
  774. * @param req request handle
  775. * @param ino the inode number
  776. * @param fi file information
  777. * @param lock the region/type to set
  778. * @param sleep locking operation may sleep
  779. */
  780. void (*setlk) (fuse_req_t req, fuse_ino_t ino,
  781. struct fuse_file_info *fi,
  782. struct flock *lock, int sleep);
  783. /**
  784. * Map block index within file to block index within device
  785. *
  786. * Note: This makes sense only for block device backed filesystems
  787. * mounted with the 'blkdev' option
  788. *
  789. * Introduced in version 2.6
  790. *
  791. * Valid replies:
  792. * fuse_reply_bmap
  793. * fuse_reply_err
  794. *
  795. * @param req request handle
  796. * @param ino the inode number
  797. * @param blocksize unit of block index
  798. * @param idx block index within file
  799. */
  800. void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
  801. uint64_t idx);
  802. /**
  803. * Ioctl
  804. *
  805. * Note: For unrestricted ioctls (not allowed for FUSE
  806. * servers), data in and out areas can be discovered by giving
  807. * iovs and setting FUSE_IOCTL_RETRY in @flags. For
  808. * restricted ioctls, kernel prepares in/out data area
  809. * according to the information encoded in cmd.
  810. *
  811. * Introduced in version 2.8
  812. *
  813. * Valid replies:
  814. * fuse_reply_ioctl_retry
  815. * fuse_reply_ioctl
  816. * fuse_reply_ioctl_iov
  817. * fuse_reply_err
  818. *
  819. * @param req request handle
  820. * @param ino the inode number
  821. * @param cmd ioctl command
  822. * @param arg ioctl argument
  823. * @param fi file information
  824. * @param flags for FUSE_IOCTL_* flags
  825. * @param in_buf data fetched from the caller
  826. * @param in_bufsz number of fetched bytes
  827. * @param out_bufsz maximum size of output data
  828. */
  829. void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg,
  830. struct fuse_file_info *fi, unsigned flags,
  831. const void *in_buf, size_t in_bufsz, size_t out_bufsz);
  832. /**
  833. * Poll for IO readiness
  834. *
  835. * Introduced in version 2.8
  836. *
  837. * Note: If ph is non-NULL, the client should notify
  838. * when IO readiness events occur by calling
  839. * fuse_lowelevel_notify_poll() with the specified ph.
  840. *
  841. * Regardless of the number of times poll with a non-NULL ph
  842. * is received, single notification is enough to clear all.
  843. * Notifying more times incurs overhead but doesn't harm
  844. * correctness.
  845. *
  846. * The callee is responsible for destroying ph with
  847. * fuse_pollhandle_destroy() when no longer in use.
  848. *
  849. * Valid replies:
  850. * fuse_reply_poll
  851. * fuse_reply_err
  852. *
  853. * @param req request handle
  854. * @param ino the inode number
  855. * @param fi file information
  856. * @param ph poll handle to be used for notification
  857. */
  858. void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
  859. struct fuse_pollhandle *ph);
  860. /**
  861. * Write data made available in a buffer
  862. *
  863. * This is a more generic version of the ->write() method. If
  864. * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the
  865. * kernel supports splicing from the fuse device, then the
  866. * data will be made available in pipe for supporting zero
  867. * copy data transfer.
  868. *
  869. * buf->count is guaranteed to be one (and thus buf->idx is
  870. * always zero). The write_buf handler must ensure that
  871. * bufv->off is correctly updated (reflecting the number of
  872. * bytes read from bufv->buf[0]).
  873. *
  874. * Introduced in version 2.9
  875. *
  876. * Valid replies:
  877. * fuse_reply_write
  878. * fuse_reply_err
  879. *
  880. * @param req request handle
  881. * @param ino the inode number
  882. * @param bufv buffer containing the data
  883. * @param off offset to write to
  884. * @param fi file information
  885. */
  886. void (*write_buf) (fuse_req_t req, fuse_ino_t ino,
  887. struct fuse_bufvec *bufv, off_t off,
  888. struct fuse_file_info *fi);
  889. /**
  890. * Callback function for the retrieve request
  891. *
  892. * Introduced in version 2.9
  893. *
  894. * Valid replies:
  895. * fuse_reply_none
  896. *
  897. * @param req request handle
  898. * @param cookie user data supplied to fuse_lowlevel_notify_retrieve()
  899. * @param ino the inode number supplied to fuse_lowlevel_notify_retrieve()
  900. * @param offset the offset supplied to fuse_lowlevel_notify_retrieve()
  901. * @param bufv the buffer containing the returned data
  902. */
  903. void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino,
  904. off_t offset, struct fuse_bufvec *bufv);
  905. /**
  906. * Forget about multiple inodes
  907. *
  908. * See description of the forget function for more
  909. * information.
  910. *
  911. * Introduced in version 2.9
  912. *
  913. * Valid replies:
  914. * fuse_reply_none
  915. *
  916. * @param req request handle
  917. */
  918. void (*forget_multi) (fuse_req_t req, size_t count,
  919. struct fuse_forget_data *forgets);
  920. /**
  921. * Acquire, modify or release a BSD file lock
  922. *
  923. * Note: if the locking methods are not implemented, the kernel
  924. * will still allow file locking to work locally. Hence these are
  925. * only interesting for network filesystems and similar.
  926. *
  927. * Introduced in version 2.9
  928. *
  929. * Valid replies:
  930. * fuse_reply_err
  931. *
  932. * @param req request handle
  933. * @param ino the inode number
  934. * @param fi file information
  935. * @param op the locking operation, see flock(2)
  936. */
  937. void (*flock) (fuse_req_t req, fuse_ino_t ino,
  938. struct fuse_file_info *fi, int op);
  939. /**
  940. * Allocate requested space. If this function returns success then
  941. * subsequent writes to the specified range shall not fail due to the lack
  942. * of free space on the file system storage media.
  943. *
  944. * Introduced in version 2.9
  945. *
  946. * Valid replies:
  947. * fuse_reply_err
  948. *
  949. * @param req request handle
  950. * @param ino the inode number
  951. * @param offset starting point for allocated region
  952. * @param length size of allocated region
  953. * @param mode determines the operation to be performed on the given range,
  954. * see fallocate(2)
  955. */
  956. void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode,
  957. off_t offset, off_t length, struct fuse_file_info *fi);
  958. };
  959. /**
  960. * Reply with an error code or success
  961. *
  962. * Possible requests:
  963. * all except forget
  964. *
  965. * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
  966. * removexattr and setlk may send a zero code
  967. *
  968. * @param req request handle
  969. * @param err the positive error value, or zero for success
  970. * @return zero for success, -errno for failure to send reply
  971. */
  972. int fuse_reply_err(fuse_req_t req, int err);
  973. /**
  974. * Don't send reply
  975. *
  976. * Possible requests:
  977. * forget
  978. *
  979. * @param req request handle
  980. */
  981. void fuse_reply_none(fuse_req_t req);
  982. /**
  983. * Reply with a directory entry
  984. *
  985. * Possible requests:
  986. * lookup, mknod, mkdir, symlink, link
  987. *
  988. * Side effects:
  989. * increments the lookup count on success
  990. *
  991. * @param req request handle
  992. * @param e the entry parameters
  993. * @return zero for success, -errno for failure to send reply
  994. */
  995. int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
  996. /**
  997. * Reply with a directory entry and open parameters
  998. *
  999. * currently the following members of 'fi' are used:
  1000. * fh, direct_io, keep_cache
  1001. *
  1002. * Possible requests:
  1003. * create
  1004. *
  1005. * Side effects:
  1006. * increments the lookup count on success
  1007. *
  1008. * @param req request handle
  1009. * @param e the entry parameters
  1010. * @param fi file information
  1011. * @return zero for success, -errno for failure to send reply
  1012. */
  1013. int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
  1014. const struct fuse_file_info *fi);
  1015. /**
  1016. * Reply with attributes
  1017. *
  1018. * Possible requests:
  1019. * getattr, setattr
  1020. *
  1021. * @param req request handle
  1022. * @param attr the attributes
  1023. * @param attr_timeout validity timeout (in seconds) for the attributes
  1024. * @return zero for success, -errno for failure to send reply
  1025. */
  1026. int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
  1027. double attr_timeout);
  1028. /**
  1029. * Reply with the contents of a symbolic link
  1030. *
  1031. * Possible requests:
  1032. * readlink
  1033. *
  1034. * @param req request handle
  1035. * @param link symbolic link contents
  1036. * @return zero for success, -errno for failure to send reply
  1037. */
  1038. int fuse_reply_readlink(fuse_req_t req, const char *link);
  1039. /**
  1040. * Reply with open parameters
  1041. *
  1042. * currently the following members of 'fi' are used:
  1043. * fh, direct_io, keep_cache
  1044. *
  1045. * Possible requests:
  1046. * open, opendir
  1047. *
  1048. * @param req request handle
  1049. * @param fi file information
  1050. * @return zero for success, -errno for failure to send reply
  1051. */
  1052. int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
  1053. /**
  1054. * Reply with number of bytes written
  1055. *
  1056. * Possible requests:
  1057. * write
  1058. *
  1059. * @param req request handle
  1060. * @param count the number of bytes written
  1061. * @return zero for success, -errno for failure to send reply
  1062. */
  1063. int fuse_reply_write(fuse_req_t req, size_t count);
  1064. /**
  1065. * Reply with data
  1066. *
  1067. * Possible requests:
  1068. * read, readdir, getxattr, listxattr
  1069. *
  1070. * @param req request handle
  1071. * @param buf buffer containing data
  1072. * @param size the size of data in bytes
  1073. * @return zero for success, -errno for failure to send reply
  1074. */
  1075. int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
  1076. /**
  1077. * Reply with data copied/moved from buffer(s)
  1078. *
  1079. * Possible requests:
  1080. * read, readdir, getxattr, listxattr
  1081. *
  1082. * @param req request handle
  1083. * @param bufv buffer vector
  1084. * @param flags flags controlling the copy
  1085. * @return zero for success, -errno for failure to send reply
  1086. */
  1087. int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
  1088. enum fuse_buf_copy_flags flags);
  1089. /**
  1090. * Reply with data vector
  1091. *
  1092. * Possible requests:
  1093. * read, readdir, getxattr, listxattr
  1094. *
  1095. * @param req request handle
  1096. * @param iov the vector containing the data
  1097. * @param count the size of vector
  1098. * @return zero for success, -errno for failure to send reply
  1099. */
  1100. int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
  1101. /**
  1102. * Reply with filesystem statistics
  1103. *
  1104. * Possible requests:
  1105. * statfs
  1106. *
  1107. * @param req request handle
  1108. * @param stbuf filesystem statistics
  1109. * @return zero for success, -errno for failure to send reply
  1110. */
  1111. int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
  1112. /**
  1113. * Reply with needed buffer size
  1114. *
  1115. * Possible requests:
  1116. * getxattr, listxattr
  1117. *
  1118. * @param req request handle
  1119. * @param count the buffer size needed in bytes
  1120. * @return zero for success, -errno for failure to send reply
  1121. */
  1122. int fuse_reply_xattr(fuse_req_t req, size_t count);
  1123. /**
  1124. * Reply with file lock information
  1125. *
  1126. * Possible requests:
  1127. * getlk
  1128. *
  1129. * @param req request handle
  1130. * @param lock the lock information
  1131. * @return zero for success, -errno for failure to send reply
  1132. */
  1133. int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
  1134. /**
  1135. * Reply with block index
  1136. *
  1137. * Possible requests:
  1138. * bmap
  1139. *
  1140. * @param req request handle
  1141. * @param idx block index within device
  1142. * @return zero for success, -errno for failure to send reply
  1143. */
  1144. int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
  1145. /* ----------------------------------------------------------- *
  1146. * Filling a buffer in readdir *
  1147. * ----------------------------------------------------------- */
  1148. /**
  1149. * Add a directory entry to the buffer
  1150. *
  1151. * Buffer needs to be large enough to hold the entry. If it's not,
  1152. * then the entry is not filled in but the size of the entry is still
  1153. * returned. The caller can check this by comparing the bufsize
  1154. * parameter with the returned entry size. If the entry size is
  1155. * larger than the buffer size, the operation failed.
  1156. *
  1157. * From the 'stbuf' argument the st_ino field and bits 12-15 of the
  1158. * st_mode field are used. The other fields are ignored.
  1159. *
  1160. * Note: offsets do not necessarily represent physical offsets, and
  1161. * could be any marker, that enables the implementation to find a
  1162. * specific point in the directory stream.
  1163. *
  1164. * @param req request handle
  1165. * @param buf the point where the new entry will be added to the buffer
  1166. * @param bufsize remaining size of the buffer
  1167. * @param name the name of the entry
  1168. * @param stbuf the file attributes
  1169. * @param off the offset of the next entry
  1170. * @return the space needed for the entry
  1171. */
  1172. size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
  1173. const char *name, const struct stat *stbuf,
  1174. off_t off);
  1175. /**
  1176. * Reply to ask for data fetch and output buffer preparation. ioctl
  1177. * will be retried with the specified input data fetched and output
  1178. * buffer prepared.
  1179. *
  1180. * Possible requests:
  1181. * ioctl
  1182. *
  1183. * @param req request handle
  1184. * @param in_iov iovec specifying data to fetch from the caller
  1185. * @param in_count number of entries in in_iov
  1186. * @param out_iov iovec specifying addresses to write output to
  1187. * @param out_count number of entries in out_iov
  1188. * @return zero for success, -errno for failure to send reply
  1189. */
  1190. int fuse_reply_ioctl_retry(fuse_req_t req,
  1191. const struct iovec *in_iov, size_t in_count,
  1192. const struct iovec *out_iov, size_t out_count);
  1193. /**
  1194. * Reply to finish ioctl
  1195. *
  1196. * Possible requests:
  1197. * ioctl
  1198. *
  1199. * @param req request handle
  1200. * @param result result to be passed to the caller
  1201. * @param buf buffer containing output data
  1202. * @param size length of output data
  1203. */
  1204. int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size);
  1205. /**
  1206. * Reply to finish ioctl with iov buffer
  1207. *
  1208. * Possible requests:
  1209. * ioctl
  1210. *
  1211. * @param req request handle
  1212. * @param result result to be passed to the caller
  1213. * @param iov the vector containing the data
  1214. * @param count the size of vector
  1215. */
  1216. int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
  1217. int count);
  1218. /**
  1219. * Reply with poll result event mask
  1220. *
  1221. * @param req request handle
  1222. * @param revents poll result event mask
  1223. */
  1224. int fuse_reply_poll(fuse_req_t req, unsigned revents);
  1225. /* ----------------------------------------------------------- *
  1226. * Notification *
  1227. * ----------------------------------------------------------- */
  1228. /**
  1229. * Notify IO readiness event
  1230. *
  1231. * For more information, please read comment for poll operation.
  1232. *
  1233. * @param ph poll handle to notify IO readiness event for
  1234. */
  1235. int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
  1236. /**
  1237. * Notify to invalidate cache for an inode
  1238. *
  1239. * @param ch the channel through which to send the invalidation
  1240. * @param ino the inode number
  1241. * @param off the offset in the inode where to start invalidating
  1242. * or negative to invalidate attributes only
  1243. * @param len the amount of cache to invalidate or 0 for all
  1244. * @return zero for success, -errno for failure
  1245. */
  1246. int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino,
  1247. off_t off, off_t len);
  1248. /**
  1249. * Notify to invalidate parent attributes and the dentry matching
  1250. * parent/name
  1251. *
  1252. * To avoid a deadlock don't call this function from a filesystem operation and
  1253. * don't call it with a lock held that can also be held by a filesystem
  1254. * operation.
  1255. *
  1256. * @param ch the channel through which to send the invalidation
  1257. * @param parent inode number
  1258. * @param name file name
  1259. * @param namelen strlen() of file name
  1260. * @return zero for success, -errno for failure
  1261. */
  1262. int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent,
  1263. const char *name, size_t namelen);
  1264. /**
  1265. * Notify to invalidate parent attributes and delete the dentry matching
  1266. * parent/name if the dentry's inode number matches child (otherwise it
  1267. * will invalidate the matching dentry).
  1268. *
  1269. * To avoid a deadlock don't call this function from a filesystem operation and
  1270. * don't call it with a lock held that can also be held by a filesystem
  1271. * operation.
  1272. *
  1273. * @param ch the channel through which to send the notification
  1274. * @param parent inode number
  1275. * @param child inode number
  1276. * @param name file name
  1277. * @param namelen strlen() of file name
  1278. * @return zero for success, -errno for failure
  1279. */
  1280. int fuse_lowlevel_notify_delete(struct fuse_chan *ch,
  1281. fuse_ino_t parent, fuse_ino_t child,
  1282. const char *name, size_t namelen);
  1283. /**
  1284. * Store data to the kernel buffers
  1285. *
  1286. * Synchronously store data in the kernel buffers belonging to the
  1287. * given inode. The stored data is marked up-to-date (no read will be
  1288. * performed against it, unless it's invalidated or evicted from the
  1289. * cache).
  1290. *
  1291. * If the stored data overflows the current file size, then the size
  1292. * is extended, similarly to a write(2) on the filesystem.
  1293. *
  1294. * If this function returns an error, then the store wasn't fully
  1295. * completed, but it may have been partially completed.
  1296. *
  1297. * @param ch the channel through which to send the invalidation
  1298. * @param ino the inode number
  1299. * @param offset the starting offset into the file to store to
  1300. * @param bufv buffer vector
  1301. * @param flags flags controlling the copy
  1302. * @return zero for success, -errno for failure
  1303. */
  1304. int fuse_lowlevel_notify_store(struct fuse_chan *ch, fuse_ino_t ino,
  1305. off_t offset, struct fuse_bufvec *bufv,
  1306. enum fuse_buf_copy_flags flags);
  1307. /**
  1308. * Retrieve data from the kernel buffers
  1309. *
  1310. * Retrieve data in the kernel buffers belonging to the given inode.
  1311. * If successful then the retrieve_reply() method will be called with
  1312. * the returned data.
  1313. *
  1314. * Only present pages are returned in the retrieve reply. Retrieving
  1315. * stops when it finds a non-present page and only data prior to that is
  1316. * returned.
  1317. *
  1318. * If this function returns an error, then the retrieve will not be
  1319. * completed and no reply will be sent.
  1320. *
  1321. * This function doesn't change the dirty state of pages in the kernel
  1322. * buffer. For dirty pages the write() method will be called
  1323. * regardless of having been retrieved previously.
  1324. *
  1325. * @param ch the channel through which to send the invalidation
  1326. * @param ino the inode number
  1327. * @param size the number of bytes to retrieve
  1328. * @param offset the starting offset into the file to retrieve from
  1329. * @param cookie user data to supply to the reply callback
  1330. * @return zero for success, -errno for failure
  1331. */
  1332. int fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, fuse_ino_t ino,
  1333. size_t size, off_t offset, void *cookie);
  1334. /* ----------------------------------------------------------- *
  1335. * Utility functions *
  1336. * ----------------------------------------------------------- */
  1337. /**
  1338. * Get the userdata from the request
  1339. *
  1340. * @param req request handle
  1341. * @return the user data passed to fuse_lowlevel_new()
  1342. */
  1343. void *fuse_req_userdata(fuse_req_t req);
  1344. /**
  1345. * Get the context from the request
  1346. *
  1347. * The pointer returned by this function will only be valid for the
  1348. * request's lifetime
  1349. *
  1350. * @param req request handle
  1351. * @return the context structure
  1352. */
  1353. const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
  1354. /**
  1355. * Get the current supplementary group IDs for the specified request
  1356. *
  1357. * Similar to the getgroups(2) system call, except the return value is
  1358. * always the total number of group IDs, even if it is larger than the
  1359. * specified size.
  1360. *
  1361. * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
  1362. * the group list to userspace, hence this function needs to parse
  1363. * "/proc/$TID/task/$TID/status" to get the group IDs.
  1364. *
  1365. * This feature may not be supported on all operating systems. In
  1366. * such a case this function will return -ENOSYS.
  1367. *
  1368. * @param req request handle
  1369. * @param size size of given array
  1370. * @param list array of group IDs to be filled in
  1371. * @return the total number of supplementary group IDs or -errno on failure
  1372. */
  1373. int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
  1374. /**
  1375. * Callback function for an interrupt
  1376. *
  1377. * @param req interrupted request
  1378. * @param data user data
  1379. */
  1380. typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
  1381. /**
  1382. * Register/unregister callback for an interrupt
  1383. *
  1384. * If an interrupt has already happened, then the callback function is
  1385. * called from within this function, hence it's not possible for
  1386. * interrupts to be lost.
  1387. *
  1388. * @param req request handle
  1389. * @param func the callback function or NULL for unregister
  1390. * @param data user data passed to the callback function
  1391. */
  1392. void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
  1393. void *data);
  1394. /**
  1395. * Check if a request has already been interrupted
  1396. *
  1397. * @param req request handle
  1398. * @return 1 if the request has been interrupted, 0 otherwise
  1399. */
  1400. int fuse_req_interrupted(fuse_req_t req);
  1401. /* ----------------------------------------------------------- *
  1402. * Filesystem setup *
  1403. * ----------------------------------------------------------- */
  1404. /* Deprecated, don't use */
  1405. int fuse_lowlevel_is_lib_option(const char *opt);
  1406. /**
  1407. * Create a low level session
  1408. *
  1409. * @param args argument vector
  1410. * @param op the low level filesystem operations
  1411. * @param op_size sizeof(struct fuse_lowlevel_ops)
  1412. * @param userdata user data
  1413. * @return the created session object, or NULL on failure
  1414. */
  1415. struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
  1416. const struct fuse_lowlevel_ops *op,
  1417. size_t op_size, void *userdata);
  1418. /* ----------------------------------------------------------- *
  1419. * Session interface *
  1420. * ----------------------------------------------------------- */
  1421. /**
  1422. * Session operations
  1423. *
  1424. * This is used in session creation
  1425. */
  1426. struct fuse_session_ops {
  1427. /**
  1428. * Hook to process a request (mandatory)
  1429. *
  1430. * @param data user data passed to fuse_session_new()
  1431. * @param buf buffer containing the raw request
  1432. * @param len request length
  1433. * @param ch channel on which the request was received
  1434. */
  1435. void (*process) (void *data, const char *buf, size_t len,
  1436. struct fuse_chan *ch);
  1437. /**
  1438. * Hook for session exit and reset (optional)
  1439. *
  1440. * @param data user data passed to fuse_session_new()
  1441. * @param val exited status (1 - exited, 0 - not exited)
  1442. */
  1443. void (*exit) (void *data, int val);
  1444. /**
  1445. * Hook for querying the current exited status (optional)
  1446. *
  1447. * @param data user data passed to fuse_session_new()
  1448. * @return 1 if exited, 0 if not exited
  1449. */
  1450. int (*exited) (void *data);
  1451. /**
  1452. * Hook for cleaning up the channel on destroy (optional)
  1453. *
  1454. * @param data user data passed to fuse_session_new()
  1455. */
  1456. void (*destroy) (void *data);
  1457. };
  1458. /**
  1459. * Create a new session
  1460. *
  1461. * @param op session operations
  1462. * @param data user data
  1463. * @return new session object, or NULL on failure
  1464. */
  1465. struct fuse_session *fuse_session_new(struct fuse_session_ops *op, void *data);
  1466. /**
  1467. * Assign a channel to a session
  1468. *
  1469. * Note: currently only a single channel may be assigned. This may
  1470. * change in the future
  1471. *
  1472. * If a session is destroyed, the assigned channel is also destroyed
  1473. *
  1474. * @param se the session
  1475. * @param ch the channel
  1476. */
  1477. void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch);
  1478. /**
  1479. * Remove a channel from a session
  1480. *
  1481. * If the channel is not assigned to a session, then this is a no-op
  1482. *
  1483. * @param ch the channel to remove
  1484. */
  1485. void fuse_session_remove_chan(struct fuse_chan *ch);
  1486. /**
  1487. * Iterate over the channels assigned to a session
  1488. *
  1489. * The iterating function needs to start with a NULL channel, and
  1490. * after that needs to pass the previously returned channel to the
  1491. * function.
  1492. *
  1493. * @param se the session
  1494. * @param ch the previous channel, or NULL
  1495. * @return the next channel, or NULL if no more channels exist
  1496. */
  1497. struct fuse_chan *fuse_session_next_chan(struct fuse_session *se,
  1498. struct fuse_chan *ch);
  1499. /**
  1500. * Process a raw request
  1501. *
  1502. * @param se the session
  1503. * @param buf buffer containing the raw request
  1504. * @param len request length
  1505. * @param ch channel on which the request was received
  1506. */
  1507. void fuse_session_process(struct fuse_session *se, const char *buf, size_t len,
  1508. struct fuse_chan *ch);
  1509. /**
  1510. * Process a raw request supplied in a generic buffer
  1511. *
  1512. * This is a more generic version of fuse_session_process(). The
  1513. * fuse_buf may contain a memory buffer or a pipe file descriptor.
  1514. *
  1515. * @param se the session
  1516. * @param buf the fuse_buf containing the request
  1517. * @param ch channel on which the request was received
  1518. */
  1519. void fuse_session_process_buf(struct fuse_session *se,
  1520. const struct fuse_buf *buf, struct fuse_chan *ch);
  1521. /**
  1522. * Receive a raw request supplied in a generic buffer
  1523. *
  1524. * This is a more generic version of fuse_chan_recv(). The fuse_buf
  1525. * supplied to this function contains a suitably allocated memory
  1526. * buffer. This may be overwritten with a file descriptor buffer.
  1527. *
  1528. * @param se the session
  1529. * @param buf the fuse_buf to store the request in
  1530. * @param chp pointer to the channel
  1531. * @return the actual size of the raw request, or -errno on error
  1532. */
  1533. int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
  1534. struct fuse_chan **chp);
  1535. /**
  1536. * Destroy a session
  1537. *
  1538. * @param se the session
  1539. */
  1540. void fuse_session_destroy(struct fuse_session *se);
  1541. /**
  1542. * Exit a session
  1543. *
  1544. * @param se the session
  1545. */
  1546. void fuse_session_exit(struct fuse_session *se);
  1547. /**
  1548. * Reset the exited status of a session
  1549. *
  1550. * @param se the session
  1551. */
  1552. void fuse_session_reset(struct fuse_session *se);
  1553. /**
  1554. * Query the exited status of a session
  1555. *
  1556. * @param se the session
  1557. * @return 1 if exited, 0 if not exited
  1558. */
  1559. int fuse_session_exited(struct fuse_session *se);
  1560. /**
  1561. * Get the user data provided to the session
  1562. *
  1563. * @param se the session
  1564. * @return the user data
  1565. */
  1566. void *fuse_session_data(struct fuse_session *se);
  1567. /**
  1568. * Enter a single threaded event loop
  1569. *
  1570. * @param se the session
  1571. * @return 0 on success, -1 on error
  1572. */
  1573. int fuse_session_loop(struct fuse_session *se);
  1574. /**
  1575. * Enter a multi-threaded event loop
  1576. *
  1577. * @param se the session
  1578. * @return 0 on success, -1 on error
  1579. */
  1580. int fuse_session_loop_mt(struct fuse_session *se, const int threads);
  1581. /* ----------------------------------------------------------- *
  1582. * Channel interface *
  1583. * ----------------------------------------------------------- */
  1584. /**
  1585. * Channel operations
  1586. *
  1587. * This is used in channel creation
  1588. */
  1589. struct fuse_chan_ops {
  1590. /**
  1591. * Hook for receiving a raw request
  1592. *
  1593. * @param ch pointer to the channel
  1594. * @param buf the buffer to store the request in
  1595. * @param size the size of the buffer
  1596. * @return the actual size of the raw request, or -1 on error
  1597. */
  1598. int (*receive)(struct fuse_chan **chp, char *buf, size_t size);
  1599. /**
  1600. * Hook for sending a raw reply
  1601. *
  1602. * A return value of -ENOENT means, that the request was
  1603. * interrupted, and the reply was discarded
  1604. *
  1605. * @param ch the channel
  1606. * @param iov vector of blocks
  1607. * @param count the number of blocks in vector
  1608. * @return zero on success, -errno on failure
  1609. */
  1610. int (*send)(struct fuse_chan *ch, const struct iovec iov[],
  1611. size_t count);
  1612. /**
  1613. * Destroy the channel
  1614. *
  1615. * @param ch the channel
  1616. */
  1617. void (*destroy)(struct fuse_chan *ch);
  1618. };
  1619. /**
  1620. * Create a new channel
  1621. *
  1622. * @param op channel operations
  1623. * @param fd file descriptor of the channel
  1624. * @param bufsize the minimal receive buffer size
  1625. * @param data user data
  1626. * @return the new channel object, or NULL on failure
  1627. */
  1628. struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd,
  1629. size_t bufsize, void *data);
  1630. /**
  1631. * Query the file descriptor of the channel
  1632. *
  1633. * @param ch the channel
  1634. * @return the file descriptor passed to fuse_chan_new()
  1635. */
  1636. int fuse_chan_fd(struct fuse_chan *ch);
  1637. /**
  1638. * Query the minimal receive buffer size
  1639. *
  1640. * @param ch the channel
  1641. * @return the buffer size passed to fuse_chan_new()
  1642. */
  1643. size_t fuse_chan_bufsize(struct fuse_chan *ch);
  1644. /**
  1645. * Query the user data
  1646. *
  1647. * @param ch the channel
  1648. * @return the user data passed to fuse_chan_new()
  1649. */
  1650. void *fuse_chan_data(struct fuse_chan *ch);
  1651. /**
  1652. * Query the session to which this channel is assigned
  1653. *
  1654. * @param ch the channel
  1655. * @return the session, or NULL if the channel is not assigned
  1656. */
  1657. struct fuse_session *fuse_chan_session(struct fuse_chan *ch);
  1658. /**
  1659. * Receive a raw request
  1660. *
  1661. * A return value of -ENODEV means, that the filesystem was unmounted
  1662. *
  1663. * @param ch pointer to the channel
  1664. * @param buf the buffer to store the request in
  1665. * @param size the size of the buffer
  1666. * @return the actual size of the raw request, or -errno on error
  1667. */
  1668. int fuse_chan_recv(struct fuse_chan **ch, char *buf, size_t size);
  1669. /**
  1670. * Send a raw reply
  1671. *
  1672. * A return value of -ENOENT means, that the request was
  1673. * interrupted, and the reply was discarded
  1674. *
  1675. * @param ch the channel
  1676. * @param iov vector of blocks
  1677. * @param count the number of blocks in vector
  1678. * @return zero on success, -errno on failure
  1679. */
  1680. int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[],
  1681. size_t count);
  1682. /**
  1683. * Destroy a channel
  1684. *
  1685. * @param ch the channel
  1686. */
  1687. void fuse_chan_destroy(struct fuse_chan *ch);
  1688. /* ----------------------------------------------------------- *
  1689. * Compatibility stuff *
  1690. * ----------------------------------------------------------- */
  1691. #if FUSE_USE_VERSION < 26
  1692. # include "fuse_lowlevel_compat.h"
  1693. # define fuse_chan_ops fuse_chan_ops_compat24
  1694. # define fuse_chan_new fuse_chan_new_compat24
  1695. # if FUSE_USE_VERSION == 25
  1696. # define fuse_lowlevel_ops fuse_lowlevel_ops_compat25
  1697. # define fuse_lowlevel_new fuse_lowlevel_new_compat25
  1698. # elif FUSE_USE_VERSION == 24
  1699. # define fuse_lowlevel_ops fuse_lowlevel_ops_compat
  1700. # define fuse_lowlevel_new fuse_lowlevel_new_compat
  1701. # define fuse_file_info fuse_file_info_compat
  1702. # define fuse_reply_statfs fuse_reply_statfs_compat
  1703. # define fuse_reply_open fuse_reply_open_compat
  1704. # else
  1705. # error Compatibility with low-level API version < 24 not supported
  1706. # endif
  1707. #endif
  1708. #ifdef __cplusplus
  1709. }
  1710. #endif
  1711. #endif /* _FUSE_LOWLEVEL_H_ */