2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB.
11 #if !defined(_FUSE_H_) && !defined(_FUSE_LOWLEVEL_H_)
12 #error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h> instead."
15 #ifndef _FUSE_COMMON_H_
16 #define _FUSE_COMMON_H_
20 #include <sys/types.h>
22 /** Major version of FUSE library interface */
23 #define FUSE_MAJOR_VERSION 2
25 /** Minor version of FUSE library interface */
26 #define FUSE_MINOR_VERSION 9
28 #define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
29 #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
31 /* This interface uses 64 bit off_t */
32 #if _FILE_OFFSET_BITS != 64
33 #error Please add -D_FILE_OFFSET_BITS=64 to your compile flags!
41 * Information about open files
43 * Changed in version 2.5
45 struct fuse_file_info
{
46 /** Open flags. Available in open() and release() */
49 /** Old file handle, don't use */
52 /** In case of a write operation indicates if this was caused by a
56 /** Can be filled in by open, to use direct I/O on this file.
57 Introduced in version 2.4 */
58 unsigned int direct_io
: 1;
60 /** Can be filled in by open, to indicate, that cached file data
61 need not be invalidated. Introduced in version 2.4 */
62 unsigned int keep_cache
: 1;
64 /** Indicates a flush operation. Set in flush operation, also
65 maybe set in highlevel lock operation and lowlevel release
66 operation. Introduced in version 2.6 */
67 unsigned int flush
: 1;
69 /** Can be filled in by open, to indicate that the file is not
70 seekable. Introduced in version 2.8 */
71 unsigned int nonseekable
: 1;
73 /* Indicates that flock locks for this file should be
74 released. If set, lock_owner shall contain a valid value.
75 May only be set in ->release(). Introduced in version
77 unsigned int flock_release
: 1;
79 /** Padding. Do not use*/
80 unsigned int padding
: 27;
82 /** File handle. May be filled in by filesystem in open().
83 Available in all other file operations */
86 /** Lock owner id. Available in locking operations and flush */
91 * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want'
93 * FUSE_CAP_ASYNC_READ: filesystem supports asynchronous read requests
94 * FUSE_CAP_POSIX_LOCKS: filesystem supports "remote" locking
95 * FUSE_CAP_ATOMIC_O_TRUNC: filesystem handles the O_TRUNC open flag
96 * FUSE_CAP_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
97 * FUSE_CAP_BIG_WRITES: filesystem can handle write size larger than 4kB
98 * FUSE_CAP_DONT_MASK: don't apply umask to file mode on create operations
99 * FUSE_CAP_SPLICE_WRITE: ability to use splice() to write to the fuse device
100 * FUSE_CAP_SPLICE_MOVE: ability to move data to the fuse device with splice()
101 * FUSE_CAP_SPLICE_READ: ability to use splice() to read from the fuse device
103 #define FUSE_CAP_ASYNC_READ (1 << 0)
104 #define FUSE_CAP_POSIX_LOCKS (1 << 1)
105 #define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
106 #define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
107 #define FUSE_CAP_BIG_WRITES (1 << 5)
108 #define FUSE_CAP_DONT_MASK (1 << 6)
109 #define FUSE_CAP_SPLICE_WRITE (1 << 7)
110 #define FUSE_CAP_SPLICE_MOVE (1 << 8)
111 #define FUSE_CAP_SPLICE_READ (1 << 9)
112 #define FUSE_CAP_FLOCK_LOCKS (1 << 10)
117 * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
118 * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
119 * FUSE_IOCTL_RETRY: retry with new iovecs
121 * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
123 #define FUSE_IOCTL_COMPAT (1 << 0)
124 #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
125 #define FUSE_IOCTL_RETRY (1 << 2)
127 #define FUSE_IOCTL_MAX_IOV 256
130 * Connection information, passed to the ->init() method
132 * Some of the elements are read-write, these can be changed to
133 * indicate the value requested by the filesystem. The requested
134 * value must usually be smaller than the indicated value.
136 struct fuse_conn_info
{
138 * Major version of the protocol (read-only)
140 unsigned proto_major
;
143 * Minor version of the protocol (read-only)
145 unsigned proto_minor
;
148 * Is asynchronous read supported (read-write)
153 * Maximum size of the write buffer
160 unsigned max_readahead
;
163 * Capability flags, that the kernel supports
168 * Capability flags, that the filesystem wants to enable
173 * Maximum number of backgrounded requests
175 unsigned max_background
;
178 * Kernel congestion threshold parameter
180 unsigned congestion_threshold
;
185 unsigned reserved
[23];
190 struct fuse_pollhandle
;
193 * Create a FUSE mountpoint
195 * Returns a control file descriptor suitable for passing to
198 * @param mountpoint the mount point path
199 * @param args argument vector
200 * @return the communication channel on success, NULL on failure
202 struct fuse_chan
*fuse_mount(const char *mountpoint
, struct fuse_args
*args
);
205 * Umount a FUSE mountpoint
207 * @param mountpoint the mount point path
208 * @param ch the communication channel
210 void fuse_unmount(const char *mountpoint
, struct fuse_chan
*ch
);
213 * Parse common options
215 * The following options are parsed:
218 * '-d' '-odebug' foreground, but keep the debug option
219 * '-s' single threaded
221 * '-ho' help without header
222 * '-ofsname=..' file system name, if not present, then set to the program
225 * All parameters may be NULL
227 * @param args argument vector
228 * @param mountpoint the returned mountpoint, should be freed after use
229 * @param multithreaded set to 1 unless the '-s' option is present
230 * @param foreground set to 1 if one of the relevant options is present
231 * @return 0 on success, -1 on failure
233 int fuse_parse_cmdline(struct fuse_args
*args
, char **mountpoint
,
234 int *multithreaded
, int *foreground
);
237 * Go into the background
239 * @param foreground if true, stay in the foreground
240 * @return 0 on success, -1 on failure
242 int fuse_daemonize(int foreground
);
245 * Get the version of the library
247 * @return the version
249 int fuse_version(void);
252 * Destroy poll handle
254 * @param ph the poll handle
256 void fuse_pollhandle_destroy(struct fuse_pollhandle
*ph
);
258 /* ----------------------------------------------------------- *
260 * ----------------------------------------------------------- */
265 enum fuse_buf_flags
{
267 * Buffer contains a file descriptor
269 * If this flag is set, the .fd field is valid, otherwise the
270 * .mem fields is valid.
272 FUSE_BUF_IS_FD
= (1 << 1),
275 * Seek on the file descriptor
277 * If this flag is set then the .pos field is valid and is
278 * used to seek to the given offset before performing
279 * operation on file descriptor.
281 FUSE_BUF_FD_SEEK
= (1 << 2),
284 * Retry operation on file descriptor
286 * If this flag is set then retry operation on file descriptor
287 * until .size bytes have been copied or an error or EOF is
290 FUSE_BUF_FD_RETRY
= (1 << 3),
296 enum fuse_buf_copy_flags
{
298 * Don't use splice(2)
300 * Always fall back to using read and write instead of
301 * splice(2) to copy data from one file descriptor to another.
303 * If this flag is not set, then only fall back if splice is
306 FUSE_BUF_NO_SPLICE
= (1 << 1),
311 * Always use splice(2) to copy data from one file descriptor
312 * to another. If splice is not available, return -EINVAL.
314 FUSE_BUF_FORCE_SPLICE
= (1 << 2),
317 * Try to move data with splice.
319 * If splice is used, try to move pages from the source to the
320 * destination instead of copying. See documentation of
321 * SPLICE_F_MOVE in splice(2) man page.
323 FUSE_BUF_SPLICE_MOVE
= (1 << 3),
326 * Don't block on the pipe when copying data with splice
328 * Makes the operations on the pipe non-blocking (if the pipe
329 * is full or empty). See SPLICE_F_NONBLOCK in the splice(2)
332 FUSE_BUF_SPLICE_NONBLOCK
= (1 << 4),
338 * Generic data buffer for I/O, extended attributes, etc... Data may
339 * be supplied as a memory pointer or as a file descriptor
343 * Size of data in bytes
350 enum fuse_buf_flags flags
;
355 * Used unless FUSE_BUF_IS_FD flag is set.
362 * Used if FUSE_BUF_IS_FD flag is set.
369 * Used if FUSE_BUF_FD_SEEK flag is set.
377 * An array of data buffers, each containing a memory pointer or a
380 * Allocate dynamically to add more than one buffer.
384 * Number of buffers in the array
389 * Index of current buffer within the array
394 * Current offset within the current buffer
401 struct fuse_buf buf
[1];
404 /* Initialize bufvec with a single buffer of given size */
405 #define FUSE_BUFVEC_INIT(size__) \
406 ((struct fuse_bufvec) { \
410 /* .buf = */ { /* [0] = */ { \
411 /* .size = */ (size__), \
412 /* .flags = */ (enum fuse_buf_flags) 0, \
420 * Get total size of data in a fuse buffer vector
422 * @param bufv buffer vector
423 * @return size of data
425 size_t fuse_buf_size(const struct fuse_bufvec
*bufv
);
428 * Copy data from one buffer vector to another
430 * @param dst destination buffer vector
431 * @param src source buffer vector
432 * @param flags flags controlling the copy
433 * @return actual number of bytes copied or -errno on error
435 ssize_t
fuse_buf_copy(struct fuse_bufvec
*dst
, struct fuse_bufvec
*src
,
436 enum fuse_buf_copy_flags flags
);
438 /* ----------------------------------------------------------- *
440 * ----------------------------------------------------------- */
443 * Exit session on HUP, TERM and INT signals and ignore PIPE signal
445 * Stores session in a global variable. May only be called once per
446 * process until fuse_remove_signal_handlers() is called.
448 * @param se the session to exit
449 * @return 0 on success, -1 on failure
451 int fuse_set_signal_handlers(struct fuse_session
*se
);
454 * Restore default signal handlers
456 * Resets global session. After this fuse_set_signal_handlers() may
459 * @param se the same session as given in fuse_set_signal_handlers()
461 void fuse_remove_signal_handlers(struct fuse_session
*se
);
463 /* ----------------------------------------------------------- *
464 * Compatibility stuff *
465 * ----------------------------------------------------------- */
467 #if FUSE_USE_VERSION < 26
469 # if FUSE_USE_VERSION < 25
470 # error On FreeBSD API version 25 or greater must be used
473 # include "fuse_common_compat.h"
474 # undef FUSE_MINOR_VERSION
476 # define fuse_unmount fuse_unmount_compat22
477 # if FUSE_USE_VERSION == 25
478 # define FUSE_MINOR_VERSION 5
479 # define fuse_mount fuse_mount_compat25
480 # elif FUSE_USE_VERSION == 24 || FUSE_USE_VERSION == 22
481 # define FUSE_MINOR_VERSION 4
482 # define fuse_mount fuse_mount_compat22
483 # elif FUSE_USE_VERSION == 21
484 # define FUSE_MINOR_VERSION 1
485 # define fuse_mount fuse_mount_compat22
486 # elif FUSE_USE_VERSION == 11
487 # warning Compatibility with API version 11 is deprecated
488 # undef FUSE_MAJOR_VERSION
489 # define FUSE_MAJOR_VERSION 1
490 # define FUSE_MINOR_VERSION 1
491 # define fuse_mount fuse_mount_compat1
493 # error Compatibility with API version other than 21, 22, 24, 25 and 11 not supported
501 #endif /* _FUSE_COMMON_H_ */