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.

483 lines
12 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  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. /** @file */
  8. #if !defined(_FUSE_H_) && !defined(_FUSE_LOWLEVEL_H_)
  9. #error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h> instead."
  10. #endif
  11. #ifndef _FUSE_COMMON_H_
  12. #define _FUSE_COMMON_H_
  13. #include "extern_c.h"
  14. #include "fuse_opt.h"
  15. #include "fuse_timeouts.h"
  16. #include <stdint.h>
  17. #include <sys/types.h>
  18. /** Major version of FUSE library interface */
  19. #define FUSE_MAJOR_VERSION 2
  20. /** Minor version of FUSE library interface */
  21. #define FUSE_MINOR_VERSION 9
  22. #define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
  23. #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
  24. /* This interface uses 64 bit off_t */
  25. #if _FILE_OFFSET_BITS != 64
  26. #error Please add -D_FILE_OFFSET_BITS=64 to your compile flags!
  27. #endif
  28. #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
  29. #define FUSE_MAX_MAX_PAGES 256
  30. EXTERN_C_BEGIN
  31. /**
  32. * Information about open files
  33. *
  34. * Changed in version 2.5
  35. */
  36. struct
  37. fuse_file_info
  38. {
  39. /** Open flags. Available in open() and release() */
  40. int flags;
  41. /** In case of a write operation indicates if this was caused by a
  42. writepage */
  43. uint32_t writepage : 1;
  44. /** Can be filled in by open, to use direct I/O on this file.
  45. Introduced in version 2.4 */
  46. uint32_t direct_io : 1;
  47. /** Can be filled in by open, to indicate, that cached file data
  48. need not be invalidated. Introduced in version 2.4 */
  49. uint32_t keep_cache : 1;
  50. /** Indicates a flush operation. Set in flush operation, also
  51. maybe set in highlevel lock operation and lowlevel release
  52. operation. Introduced in version 2.6 */
  53. uint32_t flush : 1;
  54. /** Can be filled in by open, to indicate that the file is not
  55. seekable. Introduced in version 2.8 */
  56. uint32_t nonseekable : 1;
  57. /* Indicates that flock locks for this file should be
  58. released. If set, lock_owner shall contain a valid value.
  59. May only be set in ->release(). Introduced in version
  60. 2.9 */
  61. uint32_t flock_release : 1;
  62. /* Requests the kernel to cache entries returned by readdir */
  63. uint32_t cache_readdir : 1;
  64. uint32_t auto_cache : 1;
  65. /** File handle. May be filled in by filesystem in open().
  66. Available in all other file operations */
  67. uint64_t fh;
  68. /** Lock owner id. Available in locking operations and flush */
  69. uint64_t lock_owner;
  70. };
  71. /**
  72. * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want'
  73. *
  74. * FUSE_CAP_ASYNC_READ: filesystem supports asynchronous read requests
  75. * FUSE_CAP_POSIX_LOCKS: filesystem supports "remote" locking
  76. * FUSE_CAP_ATOMIC_O_TRUNC: filesystem handles the O_TRUNC open flag
  77. * FUSE_CAP_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
  78. * FUSE_CAP_BIG_WRITES: filesystem can handle write size larger than 4kB
  79. * FUSE_CAP_DONT_MASK: don't apply umask to file mode on create operations
  80. * FUSE_CAP_SPLICE_WRITE: ability to use splice() to write to the fuse device
  81. * FUSE_CAP_SPLICE_MOVE: ability to move data to the fuse device with splice()
  82. * FUSE_CAP_SPLICE_READ: ability to use splice() to read from the fuse device
  83. * FUSE_CAP_IOCTL_DIR: ioctl support on directories
  84. * FUSE_CAP_CACHE_SYMLINKS: cache READLINK responses
  85. */
  86. #define FUSE_CAP_ASYNC_READ (1 << 0)
  87. #define FUSE_CAP_POSIX_LOCKS (1 << 1)
  88. #define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
  89. #define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
  90. #define FUSE_CAP_BIG_WRITES (1 << 5)
  91. #define FUSE_CAP_DONT_MASK (1 << 6)
  92. #define FUSE_CAP_SPLICE_WRITE (1 << 7)
  93. #define FUSE_CAP_SPLICE_MOVE (1 << 8)
  94. #define FUSE_CAP_SPLICE_READ (1 << 9)
  95. #define FUSE_CAP_FLOCK_LOCKS (1 << 10)
  96. #define FUSE_CAP_IOCTL_DIR (1 << 11)
  97. #define FUSE_CAP_READDIR_PLUS (1 << 13)
  98. #define FUSE_CAP_READDIR_PLUS_AUTO (1 << 14)
  99. #define FUSE_CAP_ASYNC_DIO (1 << 15)
  100. #define FUSE_CAP_WRITEBACK_CACHE (1 << 16)
  101. #define FUSE_CAP_PARALLEL_DIROPS (1 << 18)
  102. #define FUSE_CAP_POSIX_ACL (1 << 19)
  103. #define FUSE_CAP_CACHE_SYMLINKS (1 << 20)
  104. #define FUSE_CAP_MAX_PAGES (1 << 21)
  105. /**
  106. * Ioctl flags
  107. *
  108. * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
  109. * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
  110. * FUSE_IOCTL_RETRY: retry with new iovecs
  111. * FUSE_IOCTL_DIR: is a directory
  112. *
  113. * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
  114. */
  115. #define FUSE_IOCTL_COMPAT (1 << 0)
  116. #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
  117. #define FUSE_IOCTL_RETRY (1 << 2)
  118. #define FUSE_IOCTL_DIR (1 << 4)
  119. #define FUSE_IOCTL_MAX_IOV 256
  120. /**
  121. * Connection information, passed to the ->init() method
  122. *
  123. * Some of the elements are read-write, these can be changed to
  124. * indicate the value requested by the filesystem. The requested
  125. * value must usually be smaller than the indicated value.
  126. */
  127. struct fuse_conn_info {
  128. /**
  129. * Major version of the protocol (read-only)
  130. */
  131. unsigned proto_major;
  132. /**
  133. * Minor version of the protocol (read-only)
  134. */
  135. unsigned proto_minor;
  136. /**
  137. * Maximum size of the write buffer
  138. */
  139. unsigned max_write;
  140. /**
  141. * Maximum readahead
  142. */
  143. unsigned max_readahead;
  144. /**
  145. * Capability flags, that the kernel supports
  146. */
  147. unsigned capable;
  148. /**
  149. * Capability flags, that the filesystem wants to enable
  150. */
  151. unsigned want;
  152. /**
  153. * Maximum number of backgrounded requests
  154. */
  155. unsigned max_background;
  156. /**
  157. * Kernel congestion threshold parameter
  158. */
  159. unsigned congestion_threshold;
  160. /**
  161. * Max pages
  162. */
  163. uint16_t max_pages;
  164. /**
  165. * For future use.
  166. */
  167. unsigned reserved[22];
  168. };
  169. struct fuse_session;
  170. struct fuse_chan;
  171. struct fuse_pollhandle;
  172. /**
  173. * Create a FUSE mountpoint
  174. *
  175. * Returns a control file descriptor suitable for passing to
  176. * fuse_new()
  177. *
  178. * @param mountpoint the mount point path
  179. * @param args argument vector
  180. * @return the communication channel on success, NULL on failure
  181. */
  182. struct fuse_chan *fuse_mount(const char *mountpoint,
  183. struct fuse_args *args);
  184. /**
  185. * Umount a FUSE mountpoint
  186. *
  187. * @param mountpoint the mount point path
  188. * @param ch the communication channel
  189. */
  190. void fuse_unmount(const char *mountpoint, struct fuse_chan *ch);
  191. /**
  192. * Parse common options
  193. *
  194. * The following options are parsed:
  195. *
  196. * '-f' foreground
  197. * '-d' '-odebug' foreground, but keep the debug option
  198. * '-h' '--help' help
  199. * '-ho' help without header
  200. * '-ofsname=..' file system name, if not present, then set to the program
  201. * name
  202. *
  203. * All parameters may be NULL
  204. *
  205. * @param args argument vector
  206. * @param mountpoint the returned mountpoint, should be freed after use
  207. * @param foreground set to 1 if one of the relevant options is present
  208. * @return 0 on success, -1 on failure
  209. */
  210. int fuse_parse_cmdline(struct fuse_args *args,
  211. char **mountpoint,
  212. int *foreground);
  213. /**
  214. * Go into the background
  215. *
  216. * @param foreground if true, stay in the foreground
  217. * @return 0 on success, -1 on failure
  218. */
  219. int fuse_daemonize(int foreground);
  220. /**
  221. * Get the version of the library
  222. *
  223. * @return the version
  224. */
  225. int fuse_version(void);
  226. /**
  227. * Destroy poll handle
  228. *
  229. * @param ph the poll handle
  230. */
  231. void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
  232. /* ----------------------------------------------------------- *
  233. * Data buffer *
  234. * ----------------------------------------------------------- */
  235. /**
  236. * Buffer flags
  237. */
  238. #define FUSE_BUF_FLAG_NONE (1 << 0)
  239. /**
  240. * Buffer contains a file descriptor
  241. *
  242. * If this flag is set, the .fd field is valid, otherwise the
  243. * .mem fields is valid.
  244. */
  245. #define FUSE_BUF_FLAG_IS_FD (1 << 1)
  246. /**
  247. * Seek on the file descriptor
  248. *
  249. * If this flag is set then the .pos field is valid and is
  250. * used to seek to the given offset before performing
  251. * operation on file descriptor.
  252. */
  253. #define FUSE_BUF_FLAG_FD_SEEK (1 << 2)
  254. /**
  255. * Retry operation on file descriptor
  256. *
  257. * If this flag is set then retry operation on file descriptor
  258. * until .size bytes have been copied or an error or EOF is
  259. * detected.
  260. */
  261. #define FUSE_BUF_FLAG_FD_RETRY (1 << 3)
  262. /**
  263. * Buffer copy flags
  264. */
  265. #define FUSE_BUF_COPY_FLAG_NONE 0
  266. /**
  267. * Don't use splice(2)
  268. *
  269. * Always fall back to using read and write instead of
  270. * splice(2) to copy data from one file descriptor to another.
  271. *
  272. * If this flag is not set, then only fall back if splice is
  273. * unavailable.
  274. */
  275. #define FUSE_BUF_COPY_FLAG_NO_SPLICE (1 << 1)
  276. /**
  277. * Force splice
  278. *
  279. * Always use splice(2) to copy data from one file descriptor
  280. * to another. If splice is not available, return -EINVAL.
  281. */
  282. #define FUSE_BUF_COPY_FLAG_FORCE_SPLICE (1 << 2)
  283. /**
  284. * Try to move data with splice.
  285. *
  286. * If splice is used, try to move pages from the source to the
  287. * destination instead of copying. See documentation of
  288. * SPLICE_F_MOVE in splice(2) man page.
  289. */
  290. #define FUSE_BUF_COPY_FLAG_SPLICE_MOVE (1 << 3)
  291. /**
  292. * Don't block on the pipe when copying data with splice
  293. *
  294. * Makes the operations on the pipe non-blocking (if the pipe
  295. * is full or empty). See SPLICE_F_NONBLOCK in the splice(2)
  296. * man page.
  297. */
  298. #define FUSE_BUF_COPY_FLAG_SPLICE_NONBLOCK (1 << 4)
  299. /**
  300. * Single data buffer
  301. *
  302. * Generic data buffer for I/O, extended attributes, etc... Data may
  303. * be supplied as a memory pointer or as a file descriptor
  304. */
  305. struct fuse_buf {
  306. /**
  307. * Size of data in bytes
  308. */
  309. size_t size;
  310. /**
  311. * Buffer flags
  312. */
  313. int flags;
  314. /**
  315. * Memory pointer
  316. *
  317. * Used unless FUSE_BUF_IS_FD flag is set.
  318. */
  319. char *mem;
  320. /**
  321. * File descriptor
  322. *
  323. * Used if FUSE_BUF_IS_FD flag is set.
  324. */
  325. int fd;
  326. /**
  327. * File position
  328. *
  329. * Used if FUSE_BUF_FD_SEEK flag is set.
  330. */
  331. off_t pos;
  332. };
  333. /**
  334. * Data buffer vector
  335. *
  336. * An array of data buffers, each containing a memory pointer or a
  337. * file descriptor.
  338. *
  339. * Allocate dynamically to add more than one buffer.
  340. */
  341. struct fuse_bufvec {
  342. /**
  343. * Number of buffers in the array
  344. */
  345. size_t count;
  346. /**
  347. * Index of current buffer within the array
  348. */
  349. size_t idx;
  350. /**
  351. * Current offset within the current buffer
  352. */
  353. size_t off;
  354. /**
  355. * Array of buffers
  356. */
  357. struct fuse_buf buf[1];
  358. };
  359. /* Initialize bufvec with a single buffer of given size */
  360. #define FUSE_BUFVEC_INIT(size__) \
  361. ((struct fuse_bufvec) { \
  362. /* .count= */ 1, \
  363. /* .idx = */ 0, \
  364. /* .off = */ 0, \
  365. /* .buf = */ { /* [0] = */ { \
  366. /* .size = */ (size__), \
  367. /* .flags = */ 0, \
  368. /* .mem = */ NULL, \
  369. /* .fd = */ -1, \
  370. /* .pos = */ 0, \
  371. } } \
  372. } )
  373. /**
  374. * Get total size of data in a fuse buffer vector
  375. *
  376. * @param bufv buffer vector
  377. * @return size of data
  378. */
  379. size_t fuse_buf_size(const struct fuse_bufvec *bufv);
  380. /**
  381. * Copy data from one buffer vector to another
  382. *
  383. * @param dst destination buffer vector
  384. * @param src source buffer vector
  385. * @param flags flags controlling the copy
  386. * @return actual number of bytes copied or -errno on error
  387. */
  388. ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src, int flags);
  389. /* ----------------------------------------------------------- *
  390. * Signal handling *
  391. * ----------------------------------------------------------- */
  392. /**
  393. * Exit session on HUP, TERM and INT signals and ignore PIPE signal
  394. *
  395. * Stores session in a global variable. May only be called once per
  396. * process until fuse_remove_signal_handlers() is called.
  397. *
  398. * @param se the session to exit
  399. * @return 0 on success, -1 on failure
  400. */
  401. int fuse_set_signal_handlers(struct fuse_session *se);
  402. /**
  403. * Restore default signal handlers
  404. *
  405. * Resets global session. After this fuse_set_signal_handlers() may
  406. * be called again.
  407. *
  408. * @param se the same session as given in fuse_set_signal_handlers()
  409. */
  410. void fuse_remove_signal_handlers(struct fuse_session *se);
  411. EXTERN_C_END
  412. #endif /* _FUSE_COMMON_H_ */