1 /* FUSE: Filesystem in Userspace
2 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.
10 #if !defined(_FUSE_H_) && !defined(_FUSE_LOWLEVEL_H_)
11 #error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h> instead."
14 #ifndef _FUSE_COMMON_H_
15 #define _FUSE_COMMON_H_
19 #include <sys/types.h>
21 /** Major version of FUSE library interface */
22 #define FUSE_MAJOR_VERSION 3
24 /** Minor version of FUSE library interface */
25 #define FUSE_MINOR_VERSION 0
27 #define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
28 #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
30 /* This interface uses 64 bit off_t */
31 #if _FILE_OFFSET_BITS != 64
32 #error Please add -D_FILE_OFFSET_BITS=64 to your compile flags!
40 * Information about open files
42 * Changed in version 2.5
44 struct fuse_file_info
{
45 /** Open flags. Available in open() and release() */
48 /** Old file handle, don't use */
51 /** In case of a write operation indicates if this was caused by a
55 /** Can be filled in by open, to use direct I/O on this file.
56 Introduced in version 2.4 */
57 unsigned int direct_io
: 1;
59 /** Can be filled in by open, to indicate, that cached file data
60 need not be invalidated. Introduced in version 2.4 */
61 unsigned int keep_cache
: 1;
63 /** Indicates a flush operation. Set in flush operation, also
64 maybe set in highlevel lock operation and lowlevel release
65 operation. Introduced in version 2.6 */
66 unsigned int flush
: 1;
68 /** Can be filled in by open, to indicate that the file is not
69 seekable. Introduced in version 2.8 */
70 unsigned int nonseekable
: 1;
72 /* Indicates that flock locks for this file should be
73 released. If set, lock_owner shall contain a valid value.
74 May only be set in ->release(). Introduced in version
76 unsigned int flock_release
: 1;
78 /** Padding. Do not use*/
79 unsigned int padding
: 27;
81 /** File handle. May be filled in by filesystem in open().
82 Available in all other file operations */
85 /** Lock owner id. Available in locking operations and flush */
88 /** Requested poll events. Available in ->poll. Only set on kernels
89 which support it. If unsupported, this field is set to zero.
90 Introduced in version 3.0 */
95 * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want'
97 * FUSE_CAP_ASYNC_READ: filesystem supports asynchronous read requests
98 * FUSE_CAP_POSIX_LOCKS: filesystem supports "remote" locking
99 * FUSE_CAP_ATOMIC_O_TRUNC: filesystem handles the O_TRUNC open flag
100 * FUSE_CAP_EXPORT_SUPPORT: filesystem handles lookups of "." and ".."
101 * FUSE_CAP_BIG_WRITES: filesystem can handle write size larger than 4kB
102 * FUSE_CAP_DONT_MASK: don't apply umask to file mode on create operations
103 * FUSE_CAP_SPLICE_WRITE: ability to use splice() to write to the fuse device
104 * FUSE_CAP_SPLICE_MOVE: ability to move data to the fuse device with splice()
105 * FUSE_CAP_SPLICE_READ: ability to use splice() to read from the fuse device
106 * FUSE_CAP_IOCTL_DIR: ioctl support on directories
108 #define FUSE_CAP_ASYNC_READ (1 << 0)
109 #define FUSE_CAP_POSIX_LOCKS (1 << 1)
110 #define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
111 #define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
112 #define FUSE_CAP_BIG_WRITES (1 << 5)
113 #define FUSE_CAP_DONT_MASK (1 << 6)
114 #define FUSE_CAP_SPLICE_WRITE (1 << 7)
115 #define FUSE_CAP_SPLICE_MOVE (1 << 8)
116 #define FUSE_CAP_SPLICE_READ (1 << 9)
117 #define FUSE_CAP_FLOCK_LOCKS (1 << 10)
118 #define FUSE_CAP_IOCTL_DIR (1 << 11)
119 #define FUSE_CAP_AUTO_INVAL_DATA (1 << 12)
120 #define FUSE_CAP_READDIRPLUS (1 << 13)
121 #define FUSE_CAP_READDIRPLUS_AUTO (1 << 14)
126 * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
127 * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
128 * FUSE_IOCTL_RETRY: retry with new iovecs
129 * FUSE_IOCTL_DIR: is a directory
131 * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
133 #define FUSE_IOCTL_COMPAT (1 << 0)
134 #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
135 #define FUSE_IOCTL_RETRY (1 << 2)
136 #define FUSE_IOCTL_DIR (1 << 4)
138 #define FUSE_IOCTL_MAX_IOV 256
141 * Connection information, passed to the ->init() method
143 * Some of the elements are read-write, these can be changed to
144 * indicate the value requested by the filesystem. The requested
145 * value must usually be smaller than the indicated value.
147 struct fuse_conn_info
{
149 * Major version of the protocol (read-only)
151 unsigned proto_major
;
154 * Minor version of the protocol (read-only)
156 unsigned proto_minor
;
159 * Is asynchronous read supported (read-write)
164 * Maximum size of the write buffer
171 unsigned max_readahead
;
174 * Capability flags, that the kernel supports
179 * Capability flags, that the filesystem wants to enable
184 * Maximum number of backgrounded requests
186 unsigned max_background
;
189 * Kernel congestion threshold parameter
191 unsigned congestion_threshold
;
196 unsigned reserved
[23];
201 struct fuse_pollhandle
;
204 * Create a FUSE mountpoint
206 * Returns a control file descriptor suitable for passing to
209 * @param mountpoint the mount point path
210 * @param args argument vector
211 * @return the communication channel on success, NULL on failure
213 struct fuse_chan
*fuse_mount(const char *mountpoint
, struct fuse_args
*args
);
216 * Umount a FUSE mountpoint
218 * @param mountpoint the mount point path
219 * @param ch the communication channel
221 void fuse_unmount(const char *mountpoint
, struct fuse_chan
*ch
);
224 * Parse common options
226 * The following options are parsed:
229 * '-d' '-odebug' foreground, but keep the debug option
230 * '-s' single threaded
232 * '-ho' help without header
233 * '-ofsname=..' file system name, if not present, then set to the program
236 * All parameters may be NULL
238 * @param args argument vector
239 * @param mountpoint the returned mountpoint, should be freed after use
240 * @param multithreaded set to 1 unless the '-s' option is present
241 * @param foreground set to 1 if one of the relevant options is present
242 * @return 0 on success, -1 on failure
244 int fuse_parse_cmdline(struct fuse_args
*args
, char **mountpoint
,
245 int *multithreaded
, int *foreground
);
248 * Go into the background
250 * @param foreground if true, stay in the foreground
251 * @return 0 on success, -1 on failure
253 int fuse_daemonize(int foreground
);
256 * Get the version of the library
258 * @return the version
260 int fuse_version(void);
263 * Destroy poll handle
265 * @param ph the poll handle
267 void fuse_pollhandle_destroy(struct fuse_pollhandle
*ph
);
269 /* ----------------------------------------------------------- *
271 * ----------------------------------------------------------- */
276 enum fuse_buf_flags
{
278 * Buffer contains a file descriptor
280 * If this flag is set, the .fd field is valid, otherwise the
281 * .mem fields is valid.
283 FUSE_BUF_IS_FD
= (1 << 1),
286 * Seek on the file descriptor
288 * If this flag is set then the .pos field is valid and is
289 * used to seek to the given offset before performing
290 * operation on file descriptor.
292 FUSE_BUF_FD_SEEK
= (1 << 2),
295 * Retry operation on file descriptor
297 * If this flag is set then retry operation on file descriptor
298 * until .size bytes have been copied or an error or EOF is
301 FUSE_BUF_FD_RETRY
= (1 << 3),
307 enum fuse_buf_copy_flags
{
309 * Don't use splice(2)
311 * Always fall back to using read and write instead of
312 * splice(2) to copy data from one file descriptor to another.
314 * If this flag is not set, then only fall back if splice is
317 FUSE_BUF_NO_SPLICE
= (1 << 1),
322 * Always use splice(2) to copy data from one file descriptor
323 * to another. If splice is not available, return -EINVAL.
325 FUSE_BUF_FORCE_SPLICE
= (1 << 2),
328 * Try to move data with splice.
330 * If splice is used, try to move pages from the source to the
331 * destination instead of copying. See documentation of
332 * SPLICE_F_MOVE in splice(2) man page.
334 FUSE_BUF_SPLICE_MOVE
= (1 << 3),
337 * Don't block on the pipe when copying data with splice
339 * Makes the operations on the pipe non-blocking (if the pipe
340 * is full or empty). See SPLICE_F_NONBLOCK in the splice(2)
343 FUSE_BUF_SPLICE_NONBLOCK
= (1 << 4),
349 * Generic data buffer for I/O, extended attributes, etc... Data may
350 * be supplied as a memory pointer or as a file descriptor
354 * Size of data in bytes
361 enum fuse_buf_flags flags
;
366 * Used unless FUSE_BUF_IS_FD flag is set.
373 * Used if FUSE_BUF_IS_FD flag is set.
380 * Used if FUSE_BUF_FD_SEEK flag is set.
388 * An array of data buffers, each containing a memory pointer or a
391 * Allocate dynamically to add more than one buffer.
395 * Number of buffers in the array
400 * Index of current buffer within the array
405 * Current offset within the current buffer
412 struct fuse_buf buf
[1];
415 /* Initialize bufvec with a single buffer of given size */
416 #define FUSE_BUFVEC_INIT(size__) \
417 ((struct fuse_bufvec) { \
421 /* .buf = */ { /* [0] = */ { \
422 /* .size = */ (size__), \
423 /* .flags = */ (enum fuse_buf_flags) 0, \
431 * Get total size of data in a fuse buffer vector
433 * @param bufv buffer vector
434 * @return size of data
436 size_t fuse_buf_size(const struct fuse_bufvec
*bufv
);
439 * Copy data from one buffer vector to another
441 * @param dst destination buffer vector
442 * @param src source buffer vector
443 * @param flags flags controlling the copy
444 * @return actual number of bytes copied or -errno on error
446 ssize_t
fuse_buf_copy(struct fuse_bufvec
*dst
, struct fuse_bufvec
*src
,
447 enum fuse_buf_copy_flags flags
);
449 /* ----------------------------------------------------------- *
451 * ----------------------------------------------------------- */
454 * Exit session on HUP, TERM and INT signals and ignore PIPE signal
456 * Stores session in a global variable. May only be called once per
457 * process until fuse_remove_signal_handlers() is called.
459 * @param se the session to exit
460 * @return 0 on success, -1 on failure
462 int fuse_set_signal_handlers(struct fuse_session
*se
);
465 * Restore default signal handlers
467 * Resets global session. After this fuse_set_signal_handlers() may
470 * @param se the same session as given in fuse_set_signal_handlers()
472 void fuse_remove_signal_handlers(struct fuse_session
*se
);
474 /* ----------------------------------------------------------- *
475 * Compatibility stuff *
476 * ----------------------------------------------------------- */
478 #if !defined(FUSE_USE_VERSION) || FUSE_USE_VERSION < 30
479 # error only API version 30 or greater is supported
486 #endif /* _FUSE_COMMON_H_ */