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.

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