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.

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