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.

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