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.

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