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.

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