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.

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