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.

1896 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 <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, uint32_t in_bufsz, uint32_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. * Copy a range of data from one file to another
  960. *
  961. * Performs an optimized copy between two file descriptors without
  962. * the
  963. * additional cost of transferring data through the FUSE kernel
  964. * module
  965. * to user space (glibc) and then back into the FUSE filesystem
  966. * again.
  967. *
  968. * In case this method is not implemented, glibc falls back to
  969. * reading
  970. * data from the source and writing to the destination. Effectively
  971. * doing an inefficient copy of the data.
  972. *
  973. * If this request is answered with an error code of ENOSYS, this is
  974. * treated as a permanent failure with error code EOPNOTSUPP,
  975. * i.e. all
  976. * future copy_file_range() requests will fail with EOPNOTSUPP
  977. * without
  978. * being send to the filesystem process.
  979. *
  980. * Valid replies:
  981. * fuse_reply_write
  982. * fuse_reply_err
  983. *
  984. * @param req request handle
  985. * @param ino_in the inode number of the source file
  986. * @param off_in starting point from were the data should be read
  987. * @param fi_in file information of the source file
  988. * @param ino_out the inode number of the destination file
  989. * @param off_out starting point where the data should be written
  990. * @param fi_out file information of the destination file
  991. * @param len maximum size of the data to copy
  992. * @param flags passed along with the copy_file_range() syscall
  993. */
  994. void (*copy_file_range)(fuse_req_t req,
  995. fuse_ino_t ino_in,
  996. off_t off_in,
  997. struct fuse_file_info *fi_in,
  998. fuse_ino_t ino_out,
  999. off_t off_out,
  1000. struct fuse_file_info *fi_out,
  1001. size_t len,
  1002. int flags);
  1003. };
  1004. /**
  1005. * Reply with an error code or success
  1006. *
  1007. * Possible requests:
  1008. * all except forget
  1009. *
  1010. * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr,
  1011. * removexattr and setlk may send a zero code
  1012. *
  1013. * @param req request handle
  1014. * @param err the positive error value, or zero for success
  1015. * @return zero for success, -errno for failure to send reply
  1016. */
  1017. int fuse_reply_err(fuse_req_t req, int err);
  1018. /**
  1019. * Don't send reply
  1020. *
  1021. * Possible requests:
  1022. * forget
  1023. *
  1024. * @param req request handle
  1025. */
  1026. void fuse_reply_none(fuse_req_t req);
  1027. /**
  1028. * Reply with a directory entry
  1029. *
  1030. * Possible requests:
  1031. * lookup, mknod, mkdir, symlink, link
  1032. *
  1033. * Side effects:
  1034. * increments the lookup count on success
  1035. *
  1036. * @param req request handle
  1037. * @param e the entry parameters
  1038. * @return zero for success, -errno for failure to send reply
  1039. */
  1040. int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e);
  1041. /**
  1042. * Reply with a directory entry and open parameters
  1043. *
  1044. * currently the following members of 'fi' are used:
  1045. * fh, direct_io, keep_cache
  1046. *
  1047. * Possible requests:
  1048. * create
  1049. *
  1050. * Side effects:
  1051. * increments the lookup count on success
  1052. *
  1053. * @param req request handle
  1054. * @param e the entry parameters
  1055. * @param fi file information
  1056. * @return zero for success, -errno for failure to send reply
  1057. */
  1058. int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e,
  1059. const struct fuse_file_info *fi);
  1060. /**
  1061. * Reply with attributes
  1062. *
  1063. * Possible requests:
  1064. * getattr, setattr
  1065. *
  1066. * @param req request handle
  1067. * @param attr the attributes
  1068. * @param attr_timeout validity timeout (in seconds) for the attributes
  1069. * @return zero for success, -errno for failure to send reply
  1070. */
  1071. int fuse_reply_attr(fuse_req_t req, const struct stat *attr,
  1072. double attr_timeout);
  1073. /**
  1074. * Reply with the contents of a symbolic link
  1075. *
  1076. * Possible requests:
  1077. * readlink
  1078. *
  1079. * @param req request handle
  1080. * @param link symbolic link contents
  1081. * @return zero for success, -errno for failure to send reply
  1082. */
  1083. int fuse_reply_readlink(fuse_req_t req, const char *link);
  1084. /**
  1085. * Reply with open parameters
  1086. *
  1087. * currently the following members of 'fi' are used:
  1088. * fh, direct_io, keep_cache
  1089. *
  1090. * Possible requests:
  1091. * open, opendir
  1092. *
  1093. * @param req request handle
  1094. * @param fi file information
  1095. * @return zero for success, -errno for failure to send reply
  1096. */
  1097. int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi);
  1098. /**
  1099. * Reply with number of bytes written
  1100. *
  1101. * Possible requests:
  1102. * write
  1103. *
  1104. * @param req request handle
  1105. * @param count the number of bytes written
  1106. * @return zero for success, -errno for failure to send reply
  1107. */
  1108. int fuse_reply_write(fuse_req_t req, size_t count);
  1109. /**
  1110. * Reply with data
  1111. *
  1112. * Possible requests:
  1113. * read, readdir, getxattr, listxattr
  1114. *
  1115. * @param req request handle
  1116. * @param buf buffer containing data
  1117. * @param size the size of data in bytes
  1118. * @return zero for success, -errno for failure to send reply
  1119. */
  1120. int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
  1121. /**
  1122. * Reply with data copied/moved from buffer(s)
  1123. *
  1124. * Possible requests:
  1125. * read, readdir, getxattr, listxattr
  1126. *
  1127. * @param req request handle
  1128. * @param bufv buffer vector
  1129. * @param flags flags controlling the copy
  1130. * @return zero for success, -errno for failure to send reply
  1131. */
  1132. int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
  1133. enum fuse_buf_copy_flags flags);
  1134. /**
  1135. * Reply with data vector
  1136. *
  1137. * Possible requests:
  1138. * read, readdir, getxattr, listxattr
  1139. *
  1140. * @param req request handle
  1141. * @param iov the vector containing the data
  1142. * @param count the size of vector
  1143. * @return zero for success, -errno for failure to send reply
  1144. */
  1145. int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count);
  1146. /**
  1147. * Reply with filesystem statistics
  1148. *
  1149. * Possible requests:
  1150. * statfs
  1151. *
  1152. * @param req request handle
  1153. * @param stbuf filesystem statistics
  1154. * @return zero for success, -errno for failure to send reply
  1155. */
  1156. int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf);
  1157. /**
  1158. * Reply with needed buffer size
  1159. *
  1160. * Possible requests:
  1161. * getxattr, listxattr
  1162. *
  1163. * @param req request handle
  1164. * @param count the buffer size needed in bytes
  1165. * @return zero for success, -errno for failure to send reply
  1166. */
  1167. int fuse_reply_xattr(fuse_req_t req, size_t count);
  1168. /**
  1169. * Reply with file lock information
  1170. *
  1171. * Possible requests:
  1172. * getlk
  1173. *
  1174. * @param req request handle
  1175. * @param lock the lock information
  1176. * @return zero for success, -errno for failure to send reply
  1177. */
  1178. int fuse_reply_lock(fuse_req_t req, const struct flock *lock);
  1179. /**
  1180. * Reply with block index
  1181. *
  1182. * Possible requests:
  1183. * bmap
  1184. *
  1185. * @param req request handle
  1186. * @param idx block index within device
  1187. * @return zero for success, -errno for failure to send reply
  1188. */
  1189. int fuse_reply_bmap(fuse_req_t req, uint64_t idx);
  1190. /* ----------------------------------------------------------- *
  1191. * Filling a buffer in readdir *
  1192. * ----------------------------------------------------------- */
  1193. /**
  1194. * Add a directory entry to the buffer
  1195. *
  1196. * Buffer needs to be large enough to hold the entry. If it's not,
  1197. * then the entry is not filled in but the size of the entry is still
  1198. * returned. The caller can check this by comparing the bufsize
  1199. * parameter with the returned entry size. If the entry size is
  1200. * larger than the buffer size, the operation failed.
  1201. *
  1202. * From the 'stbuf' argument the st_ino field and bits 12-15 of the
  1203. * st_mode field are used. The other fields are ignored.
  1204. *
  1205. * Note: offsets do not necessarily represent physical offsets, and
  1206. * could be any marker, that enables the implementation to find a
  1207. * specific point in the directory stream.
  1208. *
  1209. * @param req request handle
  1210. * @param buf the point where the new entry will be added to the buffer
  1211. * @param bufsize remaining size of the buffer
  1212. * @param name the name of the entry
  1213. * @param stbuf the file attributes
  1214. * @param off the offset of the next entry
  1215. * @return the space needed for the entry
  1216. */
  1217. size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize,
  1218. const char *name, const struct stat *stbuf,
  1219. off_t off);
  1220. /**
  1221. * Reply to ask for data fetch and output buffer preparation. ioctl
  1222. * will be retried with the specified input data fetched and output
  1223. * buffer prepared.
  1224. *
  1225. * Possible requests:
  1226. * ioctl
  1227. *
  1228. * @param req request handle
  1229. * @param in_iov iovec specifying data to fetch from the caller
  1230. * @param in_count number of entries in in_iov
  1231. * @param out_iov iovec specifying addresses to write output to
  1232. * @param out_count number of entries in out_iov
  1233. * @return zero for success, -errno for failure to send reply
  1234. */
  1235. int fuse_reply_ioctl_retry(fuse_req_t req,
  1236. const struct iovec *in_iov, size_t in_count,
  1237. const struct iovec *out_iov, size_t out_count);
  1238. /**
  1239. * Reply to finish ioctl
  1240. *
  1241. * Possible requests:
  1242. * ioctl
  1243. *
  1244. * @param req request handle
  1245. * @param result result to be passed to the caller
  1246. * @param buf buffer containing output data
  1247. * @param size length of output data
  1248. */
  1249. int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, uint32_t size);
  1250. /**
  1251. * Reply to finish ioctl with iov buffer
  1252. *
  1253. * Possible requests:
  1254. * ioctl
  1255. *
  1256. * @param req request handle
  1257. * @param result result to be passed to the caller
  1258. * @param iov the vector containing the data
  1259. * @param count the size of vector
  1260. */
  1261. int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov,
  1262. int count);
  1263. /**
  1264. * Reply with poll result event mask
  1265. *
  1266. * @param req request handle
  1267. * @param revents poll result event mask
  1268. */
  1269. int fuse_reply_poll(fuse_req_t req, unsigned revents);
  1270. /* ----------------------------------------------------------- *
  1271. * Notification *
  1272. * ----------------------------------------------------------- */
  1273. /**
  1274. * Notify IO readiness event
  1275. *
  1276. * For more information, please read comment for poll operation.
  1277. *
  1278. * @param ph poll handle to notify IO readiness event for
  1279. */
  1280. int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph);
  1281. /**
  1282. * Notify to invalidate cache for an inode
  1283. *
  1284. * @param ch the channel through which to send the invalidation
  1285. * @param ino the inode number
  1286. * @param off the offset in the inode where to start invalidating
  1287. * or negative to invalidate attributes only
  1288. * @param len the amount of cache to invalidate or 0 for all
  1289. * @return zero for success, -errno for failure
  1290. */
  1291. int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino,
  1292. off_t off, off_t len);
  1293. /**
  1294. * Notify to invalidate parent attributes and the dentry matching
  1295. * parent/name
  1296. *
  1297. * To avoid a deadlock don't call this function from a filesystem operation and
  1298. * don't call it with a lock held that can also be held by a filesystem
  1299. * operation.
  1300. *
  1301. * @param ch the channel through which to send the invalidation
  1302. * @param parent inode number
  1303. * @param name file name
  1304. * @param namelen strlen() of file name
  1305. * @return zero for success, -errno for failure
  1306. */
  1307. int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent,
  1308. const char *name, size_t namelen);
  1309. /**
  1310. * Notify to invalidate parent attributes and delete the dentry matching
  1311. * parent/name if the dentry's inode number matches child (otherwise it
  1312. * will invalidate the matching dentry).
  1313. *
  1314. * To avoid a deadlock don't call this function from a filesystem operation and
  1315. * don't call it with a lock held that can also be held by a filesystem
  1316. * operation.
  1317. *
  1318. * @param ch the channel through which to send the notification
  1319. * @param parent inode number
  1320. * @param child inode number
  1321. * @param name file name
  1322. * @param namelen strlen() of file name
  1323. * @return zero for success, -errno for failure
  1324. */
  1325. int fuse_lowlevel_notify_delete(struct fuse_chan *ch,
  1326. fuse_ino_t parent, fuse_ino_t child,
  1327. const char *name, size_t namelen);
  1328. /**
  1329. * Store data to the kernel buffers
  1330. *
  1331. * Synchronously store data in the kernel buffers belonging to the
  1332. * given inode. The stored data is marked up-to-date (no read will be
  1333. * performed against it, unless it's invalidated or evicted from the
  1334. * cache).
  1335. *
  1336. * If the stored data overflows the current file size, then the size
  1337. * is extended, similarly to a write(2) on the filesystem.
  1338. *
  1339. * If this function returns an error, then the store wasn't fully
  1340. * completed, but it may have been partially completed.
  1341. *
  1342. * @param ch the channel through which to send the invalidation
  1343. * @param ino the inode number
  1344. * @param offset the starting offset into the file to store to
  1345. * @param bufv buffer vector
  1346. * @param flags flags controlling the copy
  1347. * @return zero for success, -errno for failure
  1348. */
  1349. int fuse_lowlevel_notify_store(struct fuse_chan *ch, fuse_ino_t ino,
  1350. off_t offset, struct fuse_bufvec *bufv,
  1351. enum fuse_buf_copy_flags flags);
  1352. /**
  1353. * Retrieve data from the kernel buffers
  1354. *
  1355. * Retrieve data in the kernel buffers belonging to the given inode.
  1356. * If successful then the retrieve_reply() method will be called with
  1357. * the returned data.
  1358. *
  1359. * Only present pages are returned in the retrieve reply. Retrieving
  1360. * stops when it finds a non-present page and only data prior to that is
  1361. * returned.
  1362. *
  1363. * If this function returns an error, then the retrieve will not be
  1364. * completed and no reply will be sent.
  1365. *
  1366. * This function doesn't change the dirty state of pages in the kernel
  1367. * buffer. For dirty pages the write() method will be called
  1368. * regardless of having been retrieved previously.
  1369. *
  1370. * @param ch the channel through which to send the invalidation
  1371. * @param ino the inode number
  1372. * @param size the number of bytes to retrieve
  1373. * @param offset the starting offset into the file to retrieve from
  1374. * @param cookie user data to supply to the reply callback
  1375. * @return zero for success, -errno for failure
  1376. */
  1377. int fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, fuse_ino_t ino,
  1378. size_t size, off_t offset, void *cookie);
  1379. /* ----------------------------------------------------------- *
  1380. * Utility functions *
  1381. * ----------------------------------------------------------- */
  1382. /**
  1383. * Get the userdata from the request
  1384. *
  1385. * @param req request handle
  1386. * @return the user data passed to fuse_lowlevel_new()
  1387. */
  1388. void *fuse_req_userdata(fuse_req_t req);
  1389. /**
  1390. * Get the context from the request
  1391. *
  1392. * The pointer returned by this function will only be valid for the
  1393. * request's lifetime
  1394. *
  1395. * @param req request handle
  1396. * @return the context structure
  1397. */
  1398. const struct fuse_ctx *fuse_req_ctx(fuse_req_t req);
  1399. /**
  1400. * Get the current supplementary group IDs for the specified request
  1401. *
  1402. * Similar to the getgroups(2) system call, except the return value is
  1403. * always the total number of group IDs, even if it is larger than the
  1404. * specified size.
  1405. *
  1406. * The current fuse kernel module in linux (as of 2.6.30) doesn't pass
  1407. * the group list to userspace, hence this function needs to parse
  1408. * "/proc/$TID/task/$TID/status" to get the group IDs.
  1409. *
  1410. * This feature may not be supported on all operating systems. In
  1411. * such a case this function will return -ENOSYS.
  1412. *
  1413. * @param req request handle
  1414. * @param size size of given array
  1415. * @param list array of group IDs to be filled in
  1416. * @return the total number of supplementary group IDs or -errno on failure
  1417. */
  1418. int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]);
  1419. /**
  1420. * Callback function for an interrupt
  1421. *
  1422. * @param req interrupted request
  1423. * @param data user data
  1424. */
  1425. typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
  1426. /**
  1427. * Register/unregister callback for an interrupt
  1428. *
  1429. * If an interrupt has already happened, then the callback function is
  1430. * called from within this function, hence it's not possible for
  1431. * interrupts to be lost.
  1432. *
  1433. * @param req request handle
  1434. * @param func the callback function or NULL for unregister
  1435. * @param data user data passed to the callback function
  1436. */
  1437. void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
  1438. void *data);
  1439. /**
  1440. * Check if a request has already been interrupted
  1441. *
  1442. * @param req request handle
  1443. * @return 1 if the request has been interrupted, 0 otherwise
  1444. */
  1445. int fuse_req_interrupted(fuse_req_t req);
  1446. /* ----------------------------------------------------------- *
  1447. * Filesystem setup *
  1448. * ----------------------------------------------------------- */
  1449. /* Deprecated, don't use */
  1450. int fuse_lowlevel_is_lib_option(const char *opt);
  1451. /**
  1452. * Create a low level session
  1453. *
  1454. * @param args argument vector
  1455. * @param op the low level filesystem operations
  1456. * @param op_size sizeof(struct fuse_lowlevel_ops)
  1457. * @param userdata user data
  1458. * @return the created session object, or NULL on failure
  1459. */
  1460. struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
  1461. const struct fuse_lowlevel_ops *op,
  1462. size_t op_size, void *userdata);
  1463. /* ----------------------------------------------------------- *
  1464. * Session interface *
  1465. * ----------------------------------------------------------- */
  1466. /**
  1467. * Session operations
  1468. *
  1469. * This is used in session creation
  1470. */
  1471. struct fuse_session_ops {
  1472. /**
  1473. * Hook to process a request (mandatory)
  1474. *
  1475. * @param data user data passed to fuse_session_new()
  1476. * @param buf buffer containing the raw request
  1477. * @param len request length
  1478. * @param ch channel on which the request was received
  1479. */
  1480. void (*process) (void *data, const char *buf, size_t len,
  1481. struct fuse_chan *ch);
  1482. /**
  1483. * Hook for session exit and reset (optional)
  1484. *
  1485. * @param data user data passed to fuse_session_new()
  1486. * @param val exited status (1 - exited, 0 - not exited)
  1487. */
  1488. void (*exit) (void *data, int val);
  1489. /**
  1490. * Hook for querying the current exited status (optional)
  1491. *
  1492. * @param data user data passed to fuse_session_new()
  1493. * @return 1 if exited, 0 if not exited
  1494. */
  1495. int (*exited) (void *data);
  1496. /**
  1497. * Hook for cleaning up the channel on destroy (optional)
  1498. *
  1499. * @param data user data passed to fuse_session_new()
  1500. */
  1501. void (*destroy) (void *data);
  1502. };
  1503. /**
  1504. * Create a new session
  1505. *
  1506. * @param op session operations
  1507. * @param data user data
  1508. * @return new session object, or NULL on failure
  1509. */
  1510. struct fuse_session *fuse_session_new(struct fuse_session_ops *op, void *data);
  1511. /**
  1512. * Assign a channel to a session
  1513. *
  1514. * Note: currently only a single channel may be assigned. This may
  1515. * change in the future
  1516. *
  1517. * If a session is destroyed, the assigned channel is also destroyed
  1518. *
  1519. * @param se the session
  1520. * @param ch the channel
  1521. */
  1522. void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch);
  1523. /**
  1524. * Remove a channel from a session
  1525. *
  1526. * If the channel is not assigned to a session, then this is a no-op
  1527. *
  1528. * @param ch the channel to remove
  1529. */
  1530. void fuse_session_remove_chan(struct fuse_chan *ch);
  1531. /**
  1532. * Iterate over the channels assigned to a session
  1533. *
  1534. * The iterating function needs to start with a NULL channel, and
  1535. * after that needs to pass the previously returned channel to the
  1536. * function.
  1537. *
  1538. * @param se the session
  1539. * @param ch the previous channel, or NULL
  1540. * @return the next channel, or NULL if no more channels exist
  1541. */
  1542. struct fuse_chan *fuse_session_next_chan(struct fuse_session *se,
  1543. struct fuse_chan *ch);
  1544. /**
  1545. * Process a raw request
  1546. *
  1547. * @param se the session
  1548. * @param buf buffer containing the raw request
  1549. * @param len request length
  1550. * @param ch channel on which the request was received
  1551. */
  1552. void fuse_session_process(struct fuse_session *se, const char *buf, size_t len,
  1553. struct fuse_chan *ch);
  1554. /**
  1555. * Process a raw request supplied in a generic buffer
  1556. *
  1557. * This is a more generic version of fuse_session_process(). The
  1558. * fuse_buf may contain a memory buffer or a pipe file descriptor.
  1559. *
  1560. * @param se the session
  1561. * @param buf the fuse_buf containing the request
  1562. * @param ch channel on which the request was received
  1563. */
  1564. void fuse_session_process_buf(struct fuse_session *se,
  1565. const struct fuse_buf *buf, struct fuse_chan *ch);
  1566. /**
  1567. * Receive a raw request supplied in a generic buffer
  1568. *
  1569. * This is a more generic version of fuse_chan_recv(). The fuse_buf
  1570. * supplied to this function contains a suitably allocated memory
  1571. * buffer. This may be overwritten with a file descriptor buffer.
  1572. *
  1573. * @param se the session
  1574. * @param buf the fuse_buf to store the request in
  1575. * @param chp pointer to the channel
  1576. * @return the actual size of the raw request, or -errno on error
  1577. */
  1578. int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
  1579. struct fuse_chan **chp);
  1580. /**
  1581. * Destroy a session
  1582. *
  1583. * @param se the session
  1584. */
  1585. void fuse_session_destroy(struct fuse_session *se);
  1586. /**
  1587. * Exit a session
  1588. *
  1589. * @param se the session
  1590. */
  1591. void fuse_session_exit(struct fuse_session *se);
  1592. /**
  1593. * Reset the exited status of a session
  1594. *
  1595. * @param se the session
  1596. */
  1597. void fuse_session_reset(struct fuse_session *se);
  1598. /**
  1599. * Query the exited status of a session
  1600. *
  1601. * @param se the session
  1602. * @return 1 if exited, 0 if not exited
  1603. */
  1604. int fuse_session_exited(struct fuse_session *se);
  1605. /**
  1606. * Get the user data provided to the session
  1607. *
  1608. * @param se the session
  1609. * @return the user data
  1610. */
  1611. void *fuse_session_data(struct fuse_session *se);
  1612. /**
  1613. * Enter a single threaded event loop
  1614. *
  1615. * @param se the session
  1616. * @return 0 on success, -1 on error
  1617. */
  1618. int fuse_session_loop(struct fuse_session *se);
  1619. /**
  1620. * Enter a multi-threaded event loop
  1621. *
  1622. * @param se the session
  1623. * @return 0 on success, -1 on error
  1624. */
  1625. int fuse_session_loop_mt(struct fuse_session *se, const int threads);
  1626. /* ----------------------------------------------------------- *
  1627. * Channel interface *
  1628. * ----------------------------------------------------------- */
  1629. /**
  1630. * Channel operations
  1631. *
  1632. * This is used in channel creation
  1633. */
  1634. struct fuse_chan_ops {
  1635. /**
  1636. * Hook for receiving a raw request
  1637. *
  1638. * @param ch pointer to the channel
  1639. * @param buf the buffer to store the request in
  1640. * @param size the size of the buffer
  1641. * @return the actual size of the raw request, or -1 on error
  1642. */
  1643. int (*receive)(struct fuse_chan **chp, char *buf, size_t size);
  1644. /**
  1645. * Hook for sending a raw reply
  1646. *
  1647. * A return value of -ENOENT means, that the request was
  1648. * interrupted, and the reply was discarded
  1649. *
  1650. * @param ch the channel
  1651. * @param iov vector of blocks
  1652. * @param count the number of blocks in vector
  1653. * @return zero on success, -errno on failure
  1654. */
  1655. int (*send)(struct fuse_chan *ch, const struct iovec iov[],
  1656. size_t count);
  1657. /**
  1658. * Destroy the channel
  1659. *
  1660. * @param ch the channel
  1661. */
  1662. void (*destroy)(struct fuse_chan *ch);
  1663. };
  1664. /**
  1665. * Create a new channel
  1666. *
  1667. * @param op channel operations
  1668. * @param fd file descriptor of the channel
  1669. * @param bufsize the minimal receive buffer size
  1670. * @param data user data
  1671. * @return the new channel object, or NULL on failure
  1672. */
  1673. struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd,
  1674. size_t bufsize, void *data);
  1675. /**
  1676. * Query the file descriptor of the channel
  1677. *
  1678. * @param ch the channel
  1679. * @return the file descriptor passed to fuse_chan_new()
  1680. */
  1681. int fuse_chan_fd(struct fuse_chan *ch);
  1682. /**
  1683. * Query the minimal receive buffer size
  1684. *
  1685. * @param ch the channel
  1686. * @return the buffer size passed to fuse_chan_new()
  1687. */
  1688. size_t fuse_chan_bufsize(struct fuse_chan *ch);
  1689. /**
  1690. * Query the user data
  1691. *
  1692. * @param ch the channel
  1693. * @return the user data passed to fuse_chan_new()
  1694. */
  1695. void *fuse_chan_data(struct fuse_chan *ch);
  1696. /**
  1697. * Query the session to which this channel is assigned
  1698. *
  1699. * @param ch the channel
  1700. * @return the session, or NULL if the channel is not assigned
  1701. */
  1702. struct fuse_session *fuse_chan_session(struct fuse_chan *ch);
  1703. /**
  1704. * Receive a raw request
  1705. *
  1706. * A return value of -ENODEV means, that the filesystem was unmounted
  1707. *
  1708. * @param ch pointer to the channel
  1709. * @param buf the buffer to store the request in
  1710. * @param size the size of the buffer
  1711. * @return the actual size of the raw request, or -errno on error
  1712. */
  1713. int fuse_chan_recv(struct fuse_chan **ch, char *buf, size_t size);
  1714. /**
  1715. * Send a raw reply
  1716. *
  1717. * A return value of -ENOENT means, that the request was
  1718. * interrupted, and the reply was discarded
  1719. *
  1720. * @param ch the channel
  1721. * @param iov vector of blocks
  1722. * @param count the number of blocks in vector
  1723. * @return zero on success, -errno on failure
  1724. */
  1725. int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[],
  1726. size_t count);
  1727. /**
  1728. * Destroy a channel
  1729. *
  1730. * @param ch the channel
  1731. */
  1732. void fuse_chan_destroy(struct fuse_chan *ch);
  1733. /* ----------------------------------------------------------- *
  1734. * Compatibility stuff *
  1735. * ----------------------------------------------------------- */
  1736. #if FUSE_USE_VERSION < 26
  1737. # include "fuse_lowlevel_compat.h"
  1738. # define fuse_chan_ops fuse_chan_ops_compat24
  1739. # define fuse_chan_new fuse_chan_new_compat24
  1740. # if FUSE_USE_VERSION == 25
  1741. # define fuse_lowlevel_ops fuse_lowlevel_ops_compat25
  1742. # define fuse_lowlevel_new fuse_lowlevel_new_compat25
  1743. # elif FUSE_USE_VERSION == 24
  1744. # define fuse_lowlevel_ops fuse_lowlevel_ops_compat
  1745. # define fuse_lowlevel_new fuse_lowlevel_new_compat
  1746. # define fuse_file_info fuse_file_info_compat
  1747. # define fuse_reply_statfs fuse_reply_statfs_compat
  1748. # define fuse_reply_open fuse_reply_open_compat
  1749. # else
  1750. # error Compatibility with low-level API version < 24 not supported
  1751. # endif
  1752. #endif
  1753. #ifdef __cplusplus
  1754. }
  1755. #endif
  1756. #endif /* _FUSE_LOWLEVEL_H_ */