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.

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