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.

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