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.

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