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.

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