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.

1830 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. /** Inode number type */
  37. typedef uint64_t fuse_ino_t;
  38. /** Request pointer type */
  39. typedef struct fuse_req *fuse_req_t;
  40. /**
  41. * Session
  42. *
  43. * This provides hooks for processing requests, and exiting
  44. */
  45. struct fuse_session;
  46. /**
  47. * Channel
  48. *
  49. * A communication channel, providing hooks for sending and receiving
  50. * messages
  51. */
  52. struct fuse_chan;
  53. /** Directory entry parameters supplied to fuse_reply_entry() */
  54. struct fuse_entry_param
  55. {
  56. /** Unique inode number
  57. *
  58. * In lookup, zero means negative entry (from version 2.5)
  59. * Returning ENOENT also means negative entry, but by setting zero
  60. * ino the kernel may cache negative entries for entry_timeout
  61. * seconds.
  62. */
  63. fuse_ino_t ino;
  64. /** Generation number for this entry.
  65. *
  66. * If the file system will be exported over NFS, the
  67. * ino/generation pairs need to be unique over the file
  68. * system's lifetime (rather than just the mount time). So if
  69. * the file system reuses an inode after it has been deleted,
  70. * it must assign a new, previously unused generation number
  71. * to the inode at the same time.
  72. *
  73. * The generation must be non-zero, otherwise FUSE will treat
  74. * it as an error.
  75. *
  76. */
  77. uint64_t generation;
  78. /** Inode attributes.
  79. *
  80. * Even if attr_timeout == 0, attr must be correct. For example,
  81. * for open(), FUSE uses attr.st_size from lookup() to determine
  82. * how many bytes to request. If this value is not correct,
  83. * incorrect data will be returned.
  84. */
  85. struct stat attr;
  86. fuse_timeouts_t timeout;
  87. };
  88. /** Additional context associated with requests */
  89. struct fuse_ctx
  90. {
  91. /** User ID of the calling process */
  92. uid_t uid;
  93. /** Group ID of the calling process */
  94. gid_t gid;
  95. /** Thread ID of the calling process */
  96. pid_t pid;
  97. /** Umask of the calling process (introduced in version 2.8) */
  98. mode_t umask;
  99. };
  100. struct fuse_forget_data
  101. {
  102. fuse_ino_t ino;
  103. uint64_t nlookup;
  104. };
  105. /* ----------------------------------------------------------- *
  106. * Request methods and replies *
  107. * ----------------------------------------------------------- */
  108. /**
  109. * Low level filesystem operations
  110. *
  111. * Most of the methods (with the exception of init and destroy)
  112. * receive a request handle (fuse_req_t) as their first argument.
  113. * This handle must be passed to one of the specified reply functions.
  114. *
  115. * This may be done inside the method invocation, or after the call
  116. * has returned. The request handle is valid until one of the reply
  117. * functions is called.
  118. *
  119. * Other pointer arguments (name, fuse_file_info, etc) are not valid
  120. * after the call has returned, so if they are needed later, their
  121. * contents have to be copied.
  122. *
  123. * The filesystem sometimes needs to handle a return value of -ENOENT
  124. * from the reply function, which means, that the request was
  125. * interrupted, and the reply discarded. For example if
  126. * fuse_reply_open() return -ENOENT means, that the release method for
  127. * this file will not be called.
  128. */
  129. struct fuse_lowlevel_ops
  130. {
  131. /**
  132. * Initialize filesystem
  133. *
  134. * Called before any other filesystem method
  135. *
  136. * There's no reply to this function
  137. *
  138. * @param userdata the user data passed to fuse_lowlevel_new()
  139. */
  140. void (*init) (void *userdata, struct fuse_conn_info *conn);
  141. /**
  142. * Clean up filesystem
  143. *
  144. * Called on filesystem exit
  145. *
  146. * There's no reply to this function
  147. *
  148. * @param userdata the user data passed to fuse_lowlevel_new()
  149. */
  150. void (*destroy) (void *userdata);
  151. /**
  152. * Look up a directory entry by name and get its attributes.
  153. *
  154. * Valid replies:
  155. * fuse_reply_entry
  156. * fuse_reply_err
  157. *
  158. * @param req request handle
  159. * @param parent inode number of the parent directory
  160. * @param name the name to look up
  161. */
  162. void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
  163. /**
  164. * Forget about an inode
  165. *
  166. * This function is called when the kernel removes an inode
  167. * from its internal caches.
  168. *
  169. * The inode's lookup count increases by one for every call to
  170. * fuse_reply_entry and fuse_reply_create. The nlookup parameter
  171. * indicates by how much the lookup count should be decreased.
  172. *
  173. * Inodes with a non-zero lookup count may receive request from
  174. * the kernel even after calls to unlink, rmdir or (when
  175. * overwriting an existing file) rename. Filesystems must handle
  176. * such requests properly and it is recommended to defer removal
  177. * of the inode until the lookup count reaches zero. Calls to
  178. * unlink, remdir or rename will be followed closely by forget
  179. * unless the file or directory is open, in which case the
  180. * kernel issues forget only after the release or releasedir
  181. * calls.
  182. *
  183. * Note that if a file system will be exported over NFS the
  184. * inodes lifetime must extend even beyond forget. See the
  185. * generation field in struct fuse_entry_param above.
  186. *
  187. * On unmount the lookup count for all inodes implicitly drops
  188. * to zero. It is not guaranteed that the file system will
  189. * receive corresponding forget messages for the affected
  190. * inodes.
  191. *
  192. * Valid replies:
  193. * fuse_reply_none
  194. *
  195. * @param req request handle
  196. * @param ino the inode number
  197. * @param nlookup the number of lookups to forget
  198. */
  199. void (*forget) (fuse_req_t req, fuse_ino_t ino, uint64_t nlookup);
  200. /**
  201. * Get file attributes
  202. *
  203. * Valid replies:
  204. * fuse_reply_attr
  205. * fuse_reply_err
  206. *
  207. * @param req request handle
  208. * @param ino the inode number
  209. * @param fi for future use, currently always NULL
  210. */
  211. void (*getattr) (fuse_req_t req, fuse_ino_t ino,
  212. struct fuse_file_info *fi);
  213. /**
  214. * Set file attributes
  215. *
  216. * In the 'attr' argument only members indicated by the 'to_set'
  217. * bitmask contain valid values. Other members contain undefined
  218. * values.
  219. *
  220. * If the setattr was invoked from the ftruncate() system call
  221. * under Linux kernel versions 2.6.15 or later, the fi->fh will
  222. * contain the value set by the open method or will be undefined
  223. * if the open method didn't set any value. Otherwise (not
  224. * ftruncate call, or kernel version earlier than 2.6.15) the fi
  225. * parameter will be NULL.
  226. *
  227. * Valid replies:
  228. * fuse_reply_attr
  229. * fuse_reply_err
  230. *
  231. * @param req request handle
  232. * @param ino the inode number
  233. * @param attr the attributes
  234. * @param to_set bit mask of attributes which should be set
  235. * @param fi file information, or NULL
  236. *
  237. * Changed in version 2.5:
  238. * file information filled in for ftruncate
  239. */
  240. void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr,
  241. int to_set, struct fuse_file_info *fi);
  242. /**
  243. * Read symbolic link
  244. *
  245. * Valid replies:
  246. * fuse_reply_readlink
  247. * fuse_reply_err
  248. *
  249. * @param req request handle
  250. * @param ino the inode number
  251. */
  252. void (*readlink) (fuse_req_t req, fuse_ino_t ino);
  253. /**
  254. * Create file node
  255. *
  256. * Create a regular file, character device, block device, fifo or
  257. * socket node.
  258. *
  259. * Valid replies:
  260. * fuse_reply_entry
  261. * fuse_reply_err
  262. *
  263. * @param req request handle
  264. * @param parent inode number of the parent directory
  265. * @param name to create
  266. * @param mode file type and mode with which to create the new file
  267. * @param rdev the device number (only valid if created file is a device)
  268. */
  269. void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name,
  270. mode_t mode, dev_t rdev);
  271. /**
  272. * Create a directory
  273. *
  274. * Valid replies:
  275. * fuse_reply_entry
  276. * fuse_reply_err
  277. *
  278. * @param req request handle
  279. * @param parent inode number of the parent directory
  280. * @param name to create
  281. * @param mode with which to create the new file
  282. */
  283. void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name,
  284. mode_t mode);
  285. /**
  286. * Remove a file
  287. *
  288. * If the file's inode's lookup count is non-zero, the file
  289. * system is expected to postpone any removal of the inode
  290. * until the lookup count reaches zero (see description of the
  291. * forget function).
  292. *
  293. * Valid replies:
  294. * fuse_reply_err
  295. *
  296. * @param req request handle
  297. * @param parent inode number of the parent directory
  298. * @param name to remove
  299. */
  300. void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
  301. /**
  302. * Remove a directory
  303. *
  304. * If the directory's inode's lookup count is non-zero, the
  305. * file system is expected to postpone any removal of the
  306. * inode until the lookup count reaches zero (see description
  307. * of the forget function).
  308. *
  309. * Valid replies:
  310. * fuse_reply_err
  311. *
  312. * @param req request handle
  313. * @param parent inode number of the parent directory
  314. * @param name to remove
  315. */
  316. void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
  317. /**
  318. * Create a symbolic link
  319. *
  320. * Valid replies:
  321. * fuse_reply_entry
  322. * fuse_reply_err
  323. *
  324. * @param req request handle
  325. * @param link the contents of the symbolic link
  326. * @param parent inode number of the parent directory
  327. * @param name to create
  328. */
  329. void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent,
  330. const char *name);
  331. /** Rename a file
  332. *
  333. * If the target exists it should be atomically replaced. If
  334. * the target's inode's lookup count is non-zero, the file
  335. * system is expected to postpone any removal of the inode
  336. * until the lookup count reaches zero (see description of the
  337. * forget function).
  338. *
  339. * Valid replies:
  340. * fuse_reply_err
  341. *
  342. * @param req request handle
  343. * @param parent inode number of the old parent directory
  344. * @param name old name
  345. * @param newparent inode number of the new parent directory
  346. * @param newname new name
  347. */
  348. void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name,
  349. fuse_ino_t newparent, const char *newname);
  350. /**
  351. * Create a hard link
  352. *
  353. * Valid replies:
  354. * fuse_reply_entry
  355. * fuse_reply_err
  356. *
  357. * @param req request handle
  358. * @param ino the old inode number
  359. * @param newparent inode number of the new parent directory
  360. * @param newname new name to create
  361. */
  362. void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent,
  363. const char *newname);
  364. /**
  365. * Open a file
  366. *
  367. * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and
  368. * O_TRUNC) are available in fi->flags.
  369. *
  370. * Filesystem may store an arbitrary file handle (pointer, index,
  371. * etc) in fi->fh, and use this in other all other file operations
  372. * (read, write, flush, release, fsync).
  373. *
  374. * Filesystem may also implement stateless file I/O and not store
  375. * anything in fi->fh.
  376. *
  377. * There are also some flags (direct_io, keep_cache) which the
  378. * filesystem may set in fi, to change the way the file is opened.
  379. * See fuse_file_info structure in <fuse_common.h> for more details.
  380. *
  381. * Valid replies:
  382. * fuse_reply_open
  383. * fuse_reply_err
  384. *
  385. * @param req request handle
  386. * @param ino the inode number
  387. * @param fi file information
  388. */
  389. void (*open) (fuse_req_t req, fuse_ino_t ino,
  390. struct fuse_file_info *fi);
  391. /**
  392. * Read data
  393. *
  394. * Read should send exactly the number of bytes requested except
  395. * on EOF or error, otherwise the rest of the data will be
  396. * substituted with zeroes. An exception to this is when the file
  397. * has been opened in 'direct_io' mode, in which case the return
  398. * value of the read system call will reflect the return value of
  399. * this operation.
  400. *
  401. * fi->fh will contain the value set by the open method, or will
  402. * be undefined if the open method didn't set any value.
  403. *
  404. * Valid replies:
  405. * fuse_reply_buf
  406. * fuse_reply_iov
  407. * fuse_reply_data
  408. * fuse_reply_err
  409. *
  410. * @param req request handle
  411. * @param ino the inode number
  412. * @param size number of bytes to read
  413. * @param off offset to read from
  414. * @param fi file information
  415. */
  416. void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
  417. struct fuse_file_info *fi);
  418. /**
  419. * Write data
  420. *
  421. * Write should return exactly the number of bytes requested
  422. * except on error. An exception to this is when the file has
  423. * been opened in 'direct_io' mode, in which case the return value
  424. * of the write system call will reflect the return value of this
  425. * operation.
  426. *
  427. * fi->fh will contain the value set by the open method, or will
  428. * be undefined if the open method didn't set any value.
  429. *
  430. * Valid replies:
  431. * fuse_reply_write
  432. * fuse_reply_err
  433. *
  434. * @param req request handle
  435. * @param ino the inode number
  436. * @param buf data to write
  437. * @param size number of bytes to write
  438. * @param off offset to write to
  439. * @param fi file information
  440. */
  441. void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf,
  442. size_t size, off_t off, struct fuse_file_info *fi);
  443. /**
  444. * Flush method
  445. *
  446. * This is called on each close() of the opened file.
  447. *
  448. * Since file descriptors can be duplicated (dup, dup2, fork), for
  449. * one open call there may be many flush calls.
  450. *
  451. * Filesystems shouldn't assume that flush will always be called
  452. * after some writes, or that if will be called at all.
  453. *
  454. * fi->fh will contain the value set by the open method, or will
  455. * be undefined if the open method didn't set any value.
  456. *
  457. * NOTE: the name of the method is misleading, since (unlike
  458. * fsync) the filesystem is not forced to flush pending writes.
  459. * One reason to flush data, is if the filesystem wants to return
  460. * write errors.
  461. *
  462. * If the filesystem supports file locking operations (setlk,
  463. * getlk) it should remove all locks belonging to 'fi->owner'.
  464. *
  465. * Valid replies:
  466. * fuse_reply_err
  467. *
  468. * @param req request handle
  469. * @param ino the inode number
  470. * @param fi file information
  471. */
  472. void (*flush) (fuse_req_t req, fuse_ino_t ino,
  473. struct fuse_file_info *fi);
  474. /**
  475. * Release an open file
  476. *
  477. * Release is called when there are no more references to an open
  478. * file: all file descriptors are closed and all memory mappings
  479. * are unmapped.
  480. *
  481. * For every open call there will be exactly one release call.
  482. *
  483. * The filesystem may reply with an error, but error values are
  484. * not returned to close() or munmap() which triggered the
  485. * release.
  486. *
  487. * fi->fh will contain the value set by the open method, or will
  488. * be undefined if the open method didn't set any value.
  489. * fi->flags will contain the same flags as for open.
  490. *
  491. * Valid replies:
  492. * fuse_reply_err
  493. *
  494. * @param req request handle
  495. * @param ino the inode number
  496. * @param fi file information
  497. */
  498. void (*release) (fuse_req_t req, fuse_ino_t ino,
  499. struct fuse_file_info *fi);
  500. /**
  501. * Synchronize file contents
  502. *
  503. * If the datasync parameter is non-zero, then only the user data
  504. * should be flushed, not the meta data.
  505. *
  506. * Valid replies:
  507. * fuse_reply_err
  508. *
  509. * @param req request handle
  510. * @param ino the inode number
  511. * @param datasync flag indicating if only data should be flushed
  512. * @param fi file information
  513. */
  514. void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync,
  515. struct fuse_file_info *fi);
  516. /**
  517. * Open a directory
  518. *
  519. * Filesystem may store an arbitrary file handle (pointer, index,
  520. * etc) in fi->fh, and use this in other all other directory
  521. * stream operations (readdir, releasedir, fsyncdir).
  522. *
  523. * Filesystem may also implement stateless directory I/O and not
  524. * store anything in fi->fh, though that makes it impossible to
  525. * implement standard conforming directory stream operations in
  526. * case the contents of the directory can change between opendir
  527. * and releasedir.
  528. *
  529. * Valid replies:
  530. * fuse_reply_open
  531. * fuse_reply_err
  532. *
  533. * @param req request handle
  534. * @param ino the inode number
  535. * @param fi file information
  536. */
  537. void (*opendir) (fuse_req_t req, fuse_ino_t ino,
  538. struct fuse_file_info *fi);
  539. /**
  540. * Read directory
  541. *
  542. * Send a buffer filled using fuse_add_direntry(), with size not
  543. * exceeding the requested size. Send an empty buffer on end of
  544. * stream.
  545. *
  546. * fi->fh will contain the value set by the opendir method, or
  547. * will be undefined if the opendir method didn't set any value.
  548. *
  549. * Valid replies:
  550. * fuse_reply_buf
  551. * fuse_reply_data
  552. * fuse_reply_err
  553. *
  554. * @param req request handle
  555. * @param ino the inode number
  556. * @param size maximum number of bytes to send
  557. * @param off offset to continue reading the directory stream
  558. * @param fi file information
  559. */
  560. void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off,
  561. struct fuse_file_info *llffi);
  562. void (*readdir_plus)(fuse_req_t req, fuse_ino_t ino,
  563. size_t size, off_t off,
  564. struct fuse_file_info *ffi);
  565. /**
  566. * Release an open directory
  567. *
  568. * For every opendir call there will be exactly one releasedir
  569. * call.
  570. *
  571. * fi->fh will contain the value set by the opendir method, or
  572. * will be undefined if the opendir method didn't set any value.
  573. *
  574. * Valid replies:
  575. * fuse_reply_err
  576. *
  577. * @param req request handle
  578. * @param ino the inode number
  579. * @param fi file information
  580. */
  581. void (*releasedir) (fuse_req_t req, fuse_ino_t ino,
  582. struct fuse_file_info *fi);
  583. /**
  584. * Synchronize directory contents
  585. *
  586. * If the datasync parameter is non-zero, then only the directory
  587. * contents should be flushed, not the meta data.
  588. *
  589. * fi->fh will contain the value set by the opendir method, or
  590. * will be undefined if the opendir method didn't set any value.
  591. *
  592. * Valid replies:
  593. * fuse_reply_err
  594. *
  595. * @param req request handle
  596. * @param ino the inode number
  597. * @param datasync flag indicating if only data should be flushed
  598. * @param fi file information
  599. */
  600. void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync,
  601. struct fuse_file_info *fi);
  602. /**
  603. * Get file system statistics
  604. *
  605. * Valid replies:
  606. * fuse_reply_statfs
  607. * fuse_reply_err
  608. *
  609. * @param req request handle
  610. * @param ino the inode number, zero means "undefined"
  611. */
  612. void (*statfs) (fuse_req_t req, fuse_ino_t ino);
  613. /**
  614. * Set an extended attribute
  615. *
  616. * Valid replies:
  617. * fuse_reply_err
  618. */
  619. void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
  620. const char *value, size_t size, int flags);
  621. /**
  622. * Get an extended attribute
  623. *
  624. * If size is zero, the size of the value should be sent with
  625. * fuse_reply_xattr.
  626. *
  627. * If the size is non-zero, and the value fits in the buffer, the
  628. * value should be sent with fuse_reply_buf.
  629. *
  630. * If the size is too small for the value, the ERANGE error should
  631. * be sent.
  632. *
  633. * Valid replies:
  634. * fuse_reply_buf
  635. * fuse_reply_data
  636. * fuse_reply_xattr
  637. * fuse_reply_err
  638. *
  639. * @param req request handle
  640. * @param ino the inode number
  641. * @param name of the extended attribute
  642. * @param size maximum size of the value to send
  643. */
  644. void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name,
  645. size_t size);
  646. /**
  647. * List extended attribute names
  648. *
  649. * If size is zero, the total size of the attribute list should be
  650. * sent with fuse_reply_xattr.
  651. *
  652. * If the size is non-zero, and the null character separated
  653. * attribute list fits in the buffer, the list should be sent with
  654. * fuse_reply_buf.
  655. *
  656. * If the size is too small for the list, the ERANGE error should
  657. * be sent.
  658. *
  659. * Valid replies:
  660. * fuse_reply_buf
  661. * fuse_reply_data
  662. * fuse_reply_xattr
  663. * fuse_reply_err
  664. *
  665. * @param req request handle
  666. * @param ino the inode number
  667. * @param size maximum size of the list to send
  668. */
  669. void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
  670. /**
  671. * Remove an extended attribute
  672. *
  673. * Valid replies:
  674. * fuse_reply_err
  675. *
  676. * @param req request handle
  677. * @param ino the inode number
  678. * @param name of the extended attribute
  679. */
  680. void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
  681. /**
  682. * Check file access permissions
  683. *
  684. * This will be called for the access() system call. If the
  685. * 'default_permissions' mount option is given, this method is not
  686. * called.
  687. *
  688. * This method is not called under Linux kernel versions 2.4.x
  689. *
  690. * Introduced in version 2.5
  691. *
  692. * Valid replies:
  693. * fuse_reply_err
  694. *
  695. * @param req request handle
  696. * @param ino the inode number
  697. * @param mask requested access mode
  698. */
  699. void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
  700. /**
  701. * Create and open a file
  702. *
  703. * If the file does not exist, first create it with the specified
  704. * mode, and then open it.
  705. *
  706. * Open flags (with the exception of O_NOCTTY) are available in
  707. * fi->flags.
  708. *
  709. * Filesystem may store an arbitrary file handle (pointer, index,
  710. * etc) in fi->fh, and use this in other all other file operations
  711. * (read, write, flush, release, fsync).
  712. *
  713. * There are also some flags (direct_io, keep_cache) which the
  714. * filesystem may set in fi, to change the way the file is opened.
  715. * See fuse_file_info structure in <fuse_common.h> for more details.
  716. *
  717. * If this method is not implemented or under Linux kernel
  718. * versions earlier than 2.6.15, the mknod() and open() methods
  719. * will be called instead.
  720. *
  721. * Introduced in version 2.5
  722. *
  723. * Valid replies:
  724. * fuse_reply_create
  725. * fuse_reply_err
  726. *
  727. * @param req request handle
  728. * @param parent inode number of the parent directory
  729. * @param name to create
  730. * @param mode file type and mode with which to create the new file
  731. * @param fi file information
  732. */
  733. void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name,
  734. mode_t mode, struct fuse_file_info *fi);
  735. /**
  736. * Test for a POSIX file lock
  737. *
  738. * Introduced in version 2.6
  739. *
  740. * Valid replies:
  741. * fuse_reply_lock
  742. * fuse_reply_err
  743. *
  744. * @param req request handle
  745. * @param ino the inode number
  746. * @param fi file information
  747. * @param lock the region/type to test
  748. */
  749. void (*getlk) (fuse_req_t req, fuse_ino_t ino,
  750. struct fuse_file_info *fi, struct flock *lock);
  751. /**
  752. * Acquire, modify or release a POSIX file lock
  753. *
  754. * For POSIX threads (NPTL) there's a 1-1 relation between pid and
  755. * owner, but otherwise this is not always the case. For checking
  756. * lock ownership, 'fi->owner' must be used. The l_pid field in
  757. * 'struct flock' should only be used to fill in this field in
  758. * getlk().
  759. *
  760. * Note: if the locking methods are not implemented, the kernel
  761. * will still allow file locking to work locally. Hence these are
  762. * only interesting for network filesystems and similar.
  763. *
  764. * Introduced in version 2.6
  765. *
  766. * Valid replies:
  767. * fuse_reply_err
  768. *
  769. * @param req request handle
  770. * @param ino the inode number
  771. * @param fi file information
  772. * @param lock the region/type to set
  773. * @param sleep locking operation may sleep
  774. */
  775. void (*setlk) (fuse_req_t req, fuse_ino_t ino,
  776. struct fuse_file_info *fi,
  777. struct flock *lock, int sleep);
  778. /**
  779. * Map block index within file to block index within device
  780. *
  781. * Note: This makes sense only for block device backed filesystems
  782. * mounted with the 'blkdev' option
  783. *
  784. * Introduced in version 2.6
  785. *
  786. * Valid replies:
  787. * fuse_reply_bmap
  788. * fuse_reply_err
  789. *
  790. * @param req request handle
  791. * @param ino the inode number
  792. * @param blocksize unit of block index
  793. * @param idx block index within file
  794. */
  795. void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize,
  796. uint64_t idx);
  797. /**
  798. * Ioctl
  799. *
  800. * Note: For unrestricted ioctls (not allowed for FUSE
  801. * servers), data in and out areas can be discovered by giving
  802. * iovs and setting FUSE_IOCTL_RETRY in @flags. For
  803. * restricted ioctls, kernel prepares in/out data area
  804. * according to the information encoded in cmd.
  805. *
  806. * Introduced in version 2.8
  807. *
  808. * Valid replies:
  809. * fuse_reply_ioctl_retry
  810. * fuse_reply_ioctl
  811. * fuse_reply_ioctl_iov
  812. * fuse_reply_err
  813. *
  814. * @param req request handle
  815. * @param ino the inode number
  816. * @param cmd ioctl command
  817. * @param arg ioctl argument
  818. * @param fi file information
  819. * @param flags for FUSE_IOCTL_* flags
  820. * @param in_buf data fetched from the caller
  821. * @param in_bufsz number of fetched bytes
  822. * @param out_bufsz maximum size of output data
  823. */
  824. void (*ioctl) (fuse_req_t req, fuse_ino_t ino, unsigned long cmd, void *arg,
  825. struct fuse_file_info *fi, unsigned flags,
  826. const void *in_buf, uint32_t in_bufsz, uint32_t out_bufsz);
  827. /**
  828. * Poll for IO readiness
  829. *
  830. * Introduced in version 2.8
  831. *
  832. * Note: If ph is non-NULL, the client should notify
  833. * when IO readiness events occur by calling
  834. * fuse_lowelevel_notify_poll() with the specified ph.
  835. *
  836. * Regardless of the number of times poll with a non-NULL ph
  837. * is received, single notification is enough to clear all.
  838. * Notifying more times incurs overhead but doesn't harm
  839. * correctness.
  840. *
  841. * The callee is responsible for destroying ph with
  842. * fuse_pollhandle_destroy() when no longer in use.
  843. *
  844. * Valid replies:
  845. * fuse_reply_poll
  846. * fuse_reply_err
  847. *
  848. * @param req request handle
  849. * @param ino the inode number
  850. * @param fi file information
  851. * @param ph poll handle to be used for notification
  852. */
  853. void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi,
  854. struct fuse_pollhandle *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, fuse_ino_t ino,
  882. struct fuse_bufvec *bufv, off_t off,
  883. struct fuse_file_info *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, fuse_ino_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, fuse_ino_t ino,
  933. struct fuse_file_info *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, fuse_ino_t ino, int mode,
  952. off_t offset, off_t length, struct fuse_file_info *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. fuse_ino_t ino_in,
  991. off_t off_in,
  992. struct fuse_file_info *fi_in,
  993. fuse_ino_t ino_out,
  994. off_t off_out,
  995. struct fuse_file_info *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 struct fuse_file_info *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 struct fuse_file_info *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(struct fuse_pollhandle *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, fuse_ino_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, fuse_ino_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. fuse_ino_t parent, fuse_ino_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, fuse_ino_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, fuse_ino_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. * Callback function for an interrupt
  1387. *
  1388. * @param req interrupted request
  1389. * @param data user data
  1390. */
  1391. typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data);
  1392. /**
  1393. * Register/unregister callback for an interrupt
  1394. *
  1395. * If an interrupt has already happened, then the callback function is
  1396. * called from within this function, hence it's not possible for
  1397. * interrupts to be lost.
  1398. *
  1399. * @param req request handle
  1400. * @param func the callback function or NULL for unregister
  1401. * @param data user data passed to the callback function
  1402. */
  1403. void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func,
  1404. void *data);
  1405. /**
  1406. * Check if a request has already been interrupted
  1407. *
  1408. * @param req request handle
  1409. * @return 1 if the request has been interrupted, 0 otherwise
  1410. */
  1411. int fuse_req_interrupted(fuse_req_t req);
  1412. /* ----------------------------------------------------------- *
  1413. * Filesystem setup *
  1414. * ----------------------------------------------------------- */
  1415. /* Deprecated, don't use */
  1416. int fuse_lowlevel_is_lib_option(const char *opt);
  1417. /**
  1418. * Create a low level session
  1419. *
  1420. * @param args argument vector
  1421. * @param op the low level filesystem operations
  1422. * @param op_size sizeof(struct fuse_lowlevel_ops)
  1423. * @param userdata user data
  1424. * @return the created session object, or NULL on failure
  1425. */
  1426. struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
  1427. const struct fuse_lowlevel_ops *op,
  1428. size_t op_size, void *userdata);
  1429. /* ----------------------------------------------------------- *
  1430. * Session interface *
  1431. * ----------------------------------------------------------- */
  1432. /**
  1433. * Session operations
  1434. *
  1435. * This is used in session creation
  1436. */
  1437. struct fuse_session_ops
  1438. {
  1439. /**
  1440. * Hook to process a request (mandatory)
  1441. *
  1442. * @param data user data passed to fuse_session_new()
  1443. * @param buf buffer containing the raw request
  1444. * @param len request length
  1445. * @param ch channel on which the request was received
  1446. */
  1447. void (*process) (void *data, const char *buf, size_t len,
  1448. struct fuse_chan *ch);
  1449. /**
  1450. * Hook for session exit and reset (optional)
  1451. *
  1452. * @param data user data passed to fuse_session_new()
  1453. * @param val exited status (1 - exited, 0 - not exited)
  1454. */
  1455. void (*exit) (void *data, int val);
  1456. /**
  1457. * Hook for querying the current exited status (optional)
  1458. *
  1459. * @param data user data passed to fuse_session_new()
  1460. * @return 1 if exited, 0 if not exited
  1461. */
  1462. int (*exited) (void *data);
  1463. /**
  1464. * Hook for cleaning up the channel on destroy (optional)
  1465. *
  1466. * @param data user data passed to fuse_session_new()
  1467. */
  1468. void (*destroy) (void *data);
  1469. };
  1470. /**
  1471. * Create a new session
  1472. *
  1473. * @param op session operations
  1474. * @param data user data
  1475. * @return new session object, or NULL on failure
  1476. */
  1477. struct fuse_session *fuse_session_new(struct fuse_session_ops *op, void *data);
  1478. /**
  1479. * Assign a channel to a session
  1480. *
  1481. * Note: currently only a single channel may be assigned. This may
  1482. * change in the future
  1483. *
  1484. * If a session is destroyed, the assigned channel is also destroyed
  1485. *
  1486. * @param se the session
  1487. * @param ch the channel
  1488. */
  1489. void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch);
  1490. /**
  1491. * Remove a channel from a session
  1492. *
  1493. * If the channel is not assigned to a session, then this is a no-op
  1494. *
  1495. * @param ch the channel to remove
  1496. */
  1497. void fuse_session_remove_chan(struct fuse_chan *ch);
  1498. /**
  1499. * Iterate over the channels assigned to a session
  1500. *
  1501. * The iterating function needs to start with a NULL channel, and
  1502. * after that needs to pass the previously returned channel to the
  1503. * function.
  1504. *
  1505. * @param se the session
  1506. * @param ch the previous channel, or NULL
  1507. * @return the next channel, or NULL if no more channels exist
  1508. */
  1509. struct fuse_chan *fuse_session_next_chan(struct fuse_session *se,
  1510. struct fuse_chan *ch);
  1511. /**
  1512. * Process a raw request
  1513. *
  1514. * @param se the session
  1515. * @param buf buffer containing the raw request
  1516. * @param len request length
  1517. * @param ch channel on which the request was received
  1518. */
  1519. void fuse_session_process(struct fuse_session *se, const char *buf, size_t len,
  1520. struct fuse_chan *ch);
  1521. /**
  1522. * Process a raw request supplied in a generic buffer
  1523. *
  1524. * This is a more generic version of fuse_session_process(). The
  1525. * fuse_buf may contain a memory buffer or a pipe file descriptor.
  1526. *
  1527. * @param se the session
  1528. * @param buf the fuse_buf containing the request
  1529. * @param ch channel on which the request was received
  1530. */
  1531. void fuse_session_process_buf(struct fuse_session *se,
  1532. const struct fuse_buf *buf, struct fuse_chan *ch);
  1533. /**
  1534. * Receive a raw request supplied in a generic buffer
  1535. *
  1536. * This is a more generic version of fuse_chan_recv(). The fuse_buf
  1537. * supplied to this function contains a suitably allocated memory
  1538. * buffer. This may be overwritten with a file descriptor buffer.
  1539. *
  1540. * @param se the session
  1541. * @param buf the fuse_buf to store the request in
  1542. * @param chp pointer to the channel
  1543. * @return the actual size of the raw request, or -errno on error
  1544. */
  1545. int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
  1546. struct fuse_chan **chp);
  1547. /**
  1548. * Destroy a session
  1549. *
  1550. * @param se the session
  1551. */
  1552. void fuse_session_destroy(struct fuse_session *se);
  1553. /**
  1554. * Exit a session
  1555. *
  1556. * @param se the session
  1557. */
  1558. void fuse_session_exit(struct fuse_session *se);
  1559. /**
  1560. * Reset the exited status of a session
  1561. *
  1562. * @param se the session
  1563. */
  1564. void fuse_session_reset(struct fuse_session *se);
  1565. /**
  1566. * Query the exited status of a session
  1567. *
  1568. * @param se the session
  1569. * @return 1 if exited, 0 if not exited
  1570. */
  1571. int fuse_session_exited(struct fuse_session *se);
  1572. /**
  1573. * Get the user data provided to the session
  1574. *
  1575. * @param se the session
  1576. * @return the user data
  1577. */
  1578. void *fuse_session_data(struct fuse_session *se);
  1579. /**
  1580. * Enter a multi-threaded event loop
  1581. *
  1582. * @param se the session
  1583. * @return 0 on success, -1 on error
  1584. */
  1585. int fuse_session_loop_mt(struct fuse_session *se, const int threads);
  1586. /* ----------------------------------------------------------- *
  1587. * Channel interface *
  1588. * ----------------------------------------------------------- */
  1589. /**
  1590. * Channel operations
  1591. *
  1592. * This is used in channel creation
  1593. */
  1594. struct fuse_chan_ops
  1595. {
  1596. /**
  1597. * Hook for receiving a raw request
  1598. *
  1599. * @param ch pointer to the channel
  1600. * @param buf the buffer to store the request in
  1601. * @param size the size of the buffer
  1602. * @return the actual size of the raw request, or -1 on error
  1603. */
  1604. int (*receive)(struct fuse_chan **chp, char *buf, size_t size);
  1605. /**
  1606. * Hook for sending a raw reply
  1607. *
  1608. * A return value of -ENOENT means, that the request was
  1609. * interrupted, and the reply was discarded
  1610. *
  1611. * @param ch the channel
  1612. * @param iov vector of blocks
  1613. * @param count the number of blocks in vector
  1614. * @return zero on success, -errno on failure
  1615. */
  1616. int (*send)(struct fuse_chan *ch, const struct iovec iov[],
  1617. size_t count);
  1618. /**
  1619. * Destroy the channel
  1620. *
  1621. * @param ch the channel
  1622. */
  1623. void (*destroy)(struct fuse_chan *ch);
  1624. };
  1625. /**
  1626. * Create a new channel
  1627. *
  1628. * @param op channel operations
  1629. * @param fd file descriptor of the channel
  1630. * @param bufsize the minimal receive buffer size
  1631. * @param data user data
  1632. * @return the new channel object, or NULL on failure
  1633. */
  1634. struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd,
  1635. size_t bufsize, void *data);
  1636. /**
  1637. * Query the file descriptor of the channel
  1638. *
  1639. * @param ch the channel
  1640. * @return the file descriptor passed to fuse_chan_new()
  1641. */
  1642. int fuse_chan_fd(struct fuse_chan *ch);
  1643. /**
  1644. * Query the minimal receive buffer size
  1645. *
  1646. * @param ch the channel
  1647. * @return the buffer size passed to fuse_chan_new()
  1648. */
  1649. size_t fuse_chan_bufsize(struct fuse_chan *ch);
  1650. /**
  1651. * Query the user data
  1652. *
  1653. * @param ch the channel
  1654. * @return the user data passed to fuse_chan_new()
  1655. */
  1656. void *fuse_chan_data(struct fuse_chan *ch);
  1657. /**
  1658. * Query the session to which this channel is assigned
  1659. *
  1660. * @param ch the channel
  1661. * @return the session, or NULL if the channel is not assigned
  1662. */
  1663. struct fuse_session *fuse_chan_session(struct fuse_chan *ch);
  1664. /**
  1665. * Receive a raw request
  1666. *
  1667. * A return value of -ENODEV means, that the filesystem was unmounted
  1668. *
  1669. * @param ch pointer to the channel
  1670. * @param buf the buffer to store the request in
  1671. * @param size the size of the buffer
  1672. * @return the actual size of the raw request, or -errno on error
  1673. */
  1674. int fuse_chan_recv(struct fuse_chan **ch, char *buf, size_t size);
  1675. /**
  1676. * Send a raw reply
  1677. *
  1678. * A return value of -ENOENT means, that the request was
  1679. * interrupted, and the reply was discarded
  1680. *
  1681. * @param ch the channel
  1682. * @param iov vector of blocks
  1683. * @param count the number of blocks in vector
  1684. * @return zero on success, -errno on failure
  1685. */
  1686. int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[],
  1687. size_t count);
  1688. /**
  1689. * Destroy a channel
  1690. *
  1691. * @param ch the channel
  1692. */
  1693. void fuse_chan_destroy(struct fuse_chan *ch);
  1694. EXTERN_C_END
  1695. #endif /* _FUSE_LOWLEVEL_H_ */