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.

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