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.

1799 lines
52 KiB

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