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.

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