Free request in fuse_reply_data()
[fuse.git] / include / fuse_common.h
bloba4d980d5a1ac40707daee440cd969fecdab5962a
1 /*
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.
7 */
9 /** @file */
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."
13 #endif
15 #ifndef _FUSE_COMMON_H_
16 #define _FUSE_COMMON_H_
18 #include "fuse_opt.h"
19 #include <stdint.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!
34 #endif
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
40 /**
41 * Information about open files
43 * Changed in version 2.5
45 struct fuse_file_info {
46 /** Open flags. Available in open() and release() */
47 int flags;
49 /** Old file handle, don't use */
50 unsigned long fh_old;
52 /** In case of a write operation indicates if this was caused by a
53 writepage */
54 int writepage;
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
76 2.9 */
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 */
84 uint64_t fh;
86 /** Lock owner id. Available in locking operations and flush */
87 uint64_t lock_owner;
90 /**
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
102 * FUSE_CAP_IOCTL_DIR: ioctl support on directories
104 #define FUSE_CAP_ASYNC_READ (1 << 0)
105 #define FUSE_CAP_POSIX_LOCKS (1 << 1)
106 #define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
107 #define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
108 #define FUSE_CAP_BIG_WRITES (1 << 5)
109 #define FUSE_CAP_DONT_MASK (1 << 6)
110 #define FUSE_CAP_SPLICE_WRITE (1 << 7)
111 #define FUSE_CAP_SPLICE_MOVE (1 << 8)
112 #define FUSE_CAP_SPLICE_READ (1 << 9)
113 #define FUSE_CAP_FLOCK_LOCKS (1 << 10)
114 #define FUSE_CAP_IOCTL_DIR (1 << 11)
117 * Ioctl flags
119 * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
120 * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
121 * FUSE_IOCTL_RETRY: retry with new iovecs
122 * FUSE_IOCTL_DIR: is a directory
124 * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
126 #define FUSE_IOCTL_COMPAT (1 << 0)
127 #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
128 #define FUSE_IOCTL_RETRY (1 << 2)
129 #define FUSE_IOCTL_DIR (1 << 4)
131 #define FUSE_IOCTL_MAX_IOV 256
134 * Connection information, passed to the ->init() method
136 * Some of the elements are read-write, these can be changed to
137 * indicate the value requested by the filesystem. The requested
138 * value must usually be smaller than the indicated value.
140 struct fuse_conn_info {
142 * Major version of the protocol (read-only)
144 unsigned proto_major;
147 * Minor version of the protocol (read-only)
149 unsigned proto_minor;
152 * Is asynchronous read supported (read-write)
154 unsigned async_read;
157 * Maximum size of the write buffer
159 unsigned max_write;
162 * Maximum readahead
164 unsigned max_readahead;
167 * Capability flags, that the kernel supports
169 unsigned capable;
172 * Capability flags, that the filesystem wants to enable
174 unsigned want;
177 * Maximum number of backgrounded requests
179 unsigned max_background;
182 * Kernel congestion threshold parameter
184 unsigned congestion_threshold;
187 * For future use.
189 unsigned reserved[23];
192 struct fuse_session;
193 struct fuse_chan;
194 struct fuse_pollhandle;
197 * Create a FUSE mountpoint
199 * Returns a control file descriptor suitable for passing to
200 * fuse_new()
202 * @param mountpoint the mount point path
203 * @param args argument vector
204 * @return the communication channel on success, NULL on failure
206 struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args);
209 * Umount a FUSE mountpoint
211 * @param mountpoint the mount point path
212 * @param ch the communication channel
214 void fuse_unmount(const char *mountpoint, struct fuse_chan *ch);
217 * Parse common options
219 * The following options are parsed:
221 * '-f' foreground
222 * '-d' '-odebug' foreground, but keep the debug option
223 * '-s' single threaded
224 * '-h' '--help' help
225 * '-ho' help without header
226 * '-ofsname=..' file system name, if not present, then set to the program
227 * name
229 * All parameters may be NULL
231 * @param args argument vector
232 * @param mountpoint the returned mountpoint, should be freed after use
233 * @param multithreaded set to 1 unless the '-s' option is present
234 * @param foreground set to 1 if one of the relevant options is present
235 * @return 0 on success, -1 on failure
237 int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
238 int *multithreaded, int *foreground);
241 * Go into the background
243 * @param foreground if true, stay in the foreground
244 * @return 0 on success, -1 on failure
246 int fuse_daemonize(int foreground);
249 * Get the version of the library
251 * @return the version
253 int fuse_version(void);
256 * Destroy poll handle
258 * @param ph the poll handle
260 void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
262 /* ----------------------------------------------------------- *
263 * Data buffer *
264 * ----------------------------------------------------------- */
267 * Buffer flags
269 enum fuse_buf_flags {
271 * Buffer contains a file descriptor
273 * If this flag is set, the .fd field is valid, otherwise the
274 * .mem fields is valid.
276 FUSE_BUF_IS_FD = (1 << 1),
279 * Seek on the file descriptor
281 * If this flag is set then the .pos field is valid and is
282 * used to seek to the given offset before performing
283 * operation on file descriptor.
285 FUSE_BUF_FD_SEEK = (1 << 2),
288 * Retry operation on file descriptor
290 * If this flag is set then retry operation on file descriptor
291 * until .size bytes have been copied or an error or EOF is
292 * detected.
294 FUSE_BUF_FD_RETRY = (1 << 3),
298 * Buffer copy flags
300 enum fuse_buf_copy_flags {
302 * Don't use splice(2)
304 * Always fall back to using read and write instead of
305 * splice(2) to copy data from one file descriptor to another.
307 * If this flag is not set, then only fall back if splice is
308 * unavailable.
310 FUSE_BUF_NO_SPLICE = (1 << 1),
313 * Force splice
315 * Always use splice(2) to copy data from one file descriptor
316 * to another. If splice is not available, return -EINVAL.
318 FUSE_BUF_FORCE_SPLICE = (1 << 2),
321 * Try to move data with splice.
323 * If splice is used, try to move pages from the source to the
324 * destination instead of copying. See documentation of
325 * SPLICE_F_MOVE in splice(2) man page.
327 FUSE_BUF_SPLICE_MOVE = (1 << 3),
330 * Don't block on the pipe when copying data with splice
332 * Makes the operations on the pipe non-blocking (if the pipe
333 * is full or empty). See SPLICE_F_NONBLOCK in the splice(2)
334 * man page.
336 FUSE_BUF_SPLICE_NONBLOCK= (1 << 4),
340 * Single data buffer
342 * Generic data buffer for I/O, extended attributes, etc... Data may
343 * be supplied as a memory pointer or as a file descriptor
345 struct fuse_buf {
347 * Size of data in bytes
349 size_t size;
352 * Buffer flags
354 enum fuse_buf_flags flags;
357 * Memory pointer
359 * Used unless FUSE_BUF_IS_FD flag is set.
361 void *mem;
364 * File descriptor
366 * Used if FUSE_BUF_IS_FD flag is set.
368 int fd;
371 * File position
373 * Used if FUSE_BUF_FD_SEEK flag is set.
375 off_t pos;
379 * Data buffer vector
381 * An array of data buffers, each containing a memory pointer or a
382 * file descriptor.
384 * Allocate dynamically to add more than one buffer.
386 struct fuse_bufvec {
388 * Number of buffers in the array
390 size_t count;
393 * Index of current buffer within the array
395 size_t idx;
398 * Current offset within the current buffer
400 size_t off;
403 * Array of buffers
405 struct fuse_buf buf[1];
408 /* Initialize bufvec with a single buffer of given size */
409 #define FUSE_BUFVEC_INIT(size__) \
410 ((struct fuse_bufvec) { \
411 /* .count= */ 1, \
412 /* .idx = */ 0, \
413 /* .off = */ 0, \
414 /* .buf = */ { /* [0] = */ { \
415 /* .size = */ (size__), \
416 /* .flags = */ (enum fuse_buf_flags) 0, \
417 /* .mem = */ NULL, \
418 /* .fd = */ -1, \
419 /* .pos = */ 0, \
420 } } \
424 * Get total size of data in a fuse buffer vector
426 * @param bufv buffer vector
427 * @return size of data
429 size_t fuse_buf_size(const struct fuse_bufvec *bufv);
432 * Copy data from one buffer vector to another
434 * @param dst destination buffer vector
435 * @param src source buffer vector
436 * @param flags flags controlling the copy
437 * @return actual number of bytes copied or -errno on error
439 ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src,
440 enum fuse_buf_copy_flags flags);
442 /* ----------------------------------------------------------- *
443 * Signal handling *
444 * ----------------------------------------------------------- */
447 * Exit session on HUP, TERM and INT signals and ignore PIPE signal
449 * Stores session in a global variable. May only be called once per
450 * process until fuse_remove_signal_handlers() is called.
452 * @param se the session to exit
453 * @return 0 on success, -1 on failure
455 int fuse_set_signal_handlers(struct fuse_session *se);
458 * Restore default signal handlers
460 * Resets global session. After this fuse_set_signal_handlers() may
461 * be called again.
463 * @param se the same session as given in fuse_set_signal_handlers()
465 void fuse_remove_signal_handlers(struct fuse_session *se);
467 /* ----------------------------------------------------------- *
468 * Compatibility stuff *
469 * ----------------------------------------------------------- */
471 #if FUSE_USE_VERSION < 26
472 # ifdef __FreeBSD__
473 # if FUSE_USE_VERSION < 25
474 # error On FreeBSD API version 25 or greater must be used
475 # endif
476 # endif
477 # include "fuse_common_compat.h"
478 # undef FUSE_MINOR_VERSION
479 # undef fuse_main
480 # define fuse_unmount fuse_unmount_compat22
481 # if FUSE_USE_VERSION == 25
482 # define FUSE_MINOR_VERSION 5
483 # define fuse_mount fuse_mount_compat25
484 # elif FUSE_USE_VERSION == 24 || FUSE_USE_VERSION == 22
485 # define FUSE_MINOR_VERSION 4
486 # define fuse_mount fuse_mount_compat22
487 # elif FUSE_USE_VERSION == 21
488 # define FUSE_MINOR_VERSION 1
489 # define fuse_mount fuse_mount_compat22
490 # elif FUSE_USE_VERSION == 11
491 # warning Compatibility with API version 11 is deprecated
492 # undef FUSE_MAJOR_VERSION
493 # define FUSE_MAJOR_VERSION 1
494 # define FUSE_MINOR_VERSION 1
495 # define fuse_mount fuse_mount_compat1
496 # else
497 # error Compatibility with API version other than 21, 22, 24, 25 and 11 not supported
498 # endif
499 #endif
501 #ifdef __cplusplus
503 #endif
505 #endif /* _FUSE_COMMON_H_ */