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.

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