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.

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