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.

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