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.

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