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.

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