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.

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