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.

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