]> git.proxmox.com Git - mirror_qemu.git/blob - tools/virtiofsd/fuse_common.h
virtiofsd: Trim down imported files
[mirror_qemu.git] / tools / virtiofsd / fuse_common.h
1 /* FUSE: Filesystem in Userspace
2 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
3
4 This program can be distributed under the terms of the GNU LGPLv2.
5 See the file COPYING.LIB.
6 */
7
8 /** @file */
9
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."
12 #endif
13
14 #ifndef FUSE_COMMON_H_
15 #define FUSE_COMMON_H_
16
17 #include "fuse_opt.h"
18 #include "fuse_log.h"
19 #include <stdint.h>
20 #include <sys/types.h>
21
22 /** Major version of FUSE library interface */
23 #define FUSE_MAJOR_VERSION 3
24
25 /** Minor version of FUSE library interface */
26 #define FUSE_MINOR_VERSION 2
27
28 #define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
29 #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
30
31 /**
32 * Information about an open file.
33 *
34 * File Handles are created by the open, opendir, and create methods and closed
35 * by the release and releasedir methods. Multiple file handles may be
36 * concurrently open for the same file. Generally, a client will create one
37 * file handle per file descriptor, though in some cases multiple file
38 * descriptors can share a single file handle.
39 */
40 struct fuse_file_info {
41 /** Open flags. Available in open() and release() */
42 int flags;
43
44 /** In case of a write operation indicates if this was caused
45 by a delayed write from the page cache. If so, then the
46 context's pid, uid, and gid fields will not be valid, and
47 the *fh* value may not match the *fh* value that would
48 have been sent with the corresponding individual write
49 requests if write caching had been disabled. */
50 unsigned int writepage : 1;
51
52 /** Can be filled in by open, to use direct I/O on this file. */
53 unsigned int direct_io : 1;
54
55 /** Can be filled in by open. It signals the kernel that any
56 currently cached file data (ie., data that the filesystem
57 provided the last time the file was open) need not be
58 invalidated. Has no effect when set in other contexts (in
59 particular it does nothing when set by opendir()). */
60 unsigned int keep_cache : 1;
61
62 /** Indicates a flush operation. Set in flush operation, also
63 maybe set in highlevel lock operation and lowlevel release
64 operation. */
65 unsigned int flush : 1;
66
67 /** Can be filled in by open, to indicate that the file is not
68 seekable. */
69 unsigned int nonseekable : 1;
70
71 /* Indicates that flock locks for this file should be
72 released. If set, lock_owner shall contain a valid value.
73 May only be set in ->release(). */
74 unsigned int flock_release : 1;
75
76 /** Can be filled in by opendir. It signals the kernel to
77 enable caching of entries returned by readdir(). Has no
78 effect when set in other contexts (in particular it does
79 nothing when set by open()). */
80 unsigned int cache_readdir : 1;
81
82 /** Padding. Reserved for future use*/
83 unsigned int padding : 25;
84 unsigned int padding2 : 32;
85
86 /** File handle id. May be filled in by filesystem in create,
87 * open, and opendir(). Available in most other file operations on the
88 * same file handle. */
89 uint64_t fh;
90
91 /** Lock owner id. Available in locking operations and flush */
92 uint64_t lock_owner;
93
94 /** Requested poll events. Available in ->poll. Only set on kernels
95 which support it. If unsupported, this field is set to zero. */
96 uint32_t poll_events;
97 };
98
99 /**************************************************************************
100 * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want' *
101 **************************************************************************/
102
103 /**
104 * Indicates that the filesystem supports asynchronous read requests.
105 *
106 * If this capability is not requested/available, the kernel will
107 * ensure that there is at most one pending read request per
108 * file-handle at any time, and will attempt to order read requests by
109 * increasing offset.
110 *
111 * This feature is enabled by default when supported by the kernel.
112 */
113 #define FUSE_CAP_ASYNC_READ (1 << 0)
114
115 /**
116 * Indicates that the filesystem supports "remote" locking.
117 *
118 * This feature is enabled by default when supported by the kernel,
119 * and if getlk() and setlk() handlers are implemented.
120 */
121 #define FUSE_CAP_POSIX_LOCKS (1 << 1)
122
123 /**
124 * Indicates that the filesystem supports the O_TRUNC open flag. If
125 * disabled, and an application specifies O_TRUNC, fuse first calls
126 * truncate() and then open() with O_TRUNC filtered out.
127 *
128 * This feature is enabled by default when supported by the kernel.
129 */
130 #define FUSE_CAP_ATOMIC_O_TRUNC (1 << 3)
131
132 /**
133 * Indicates that the filesystem supports lookups of "." and "..".
134 *
135 * This feature is disabled by default.
136 */
137 #define FUSE_CAP_EXPORT_SUPPORT (1 << 4)
138
139 /**
140 * Indicates that the kernel should not apply the umask to the
141 * file mode on create operations.
142 *
143 * This feature is disabled by default.
144 */
145 #define FUSE_CAP_DONT_MASK (1 << 6)
146
147 /**
148 * Indicates that libfuse should try to use splice() when writing to
149 * the fuse device. This may improve performance.
150 *
151 * This feature is disabled by default.
152 */
153 #define FUSE_CAP_SPLICE_WRITE (1 << 7)
154
155 /**
156 * Indicates that libfuse should try to move pages instead of copying when
157 * writing to / reading from the fuse device. This may improve performance.
158 *
159 * This feature is disabled by default.
160 */
161 #define FUSE_CAP_SPLICE_MOVE (1 << 8)
162
163 /**
164 * Indicates that libfuse should try to use splice() when reading from
165 * the fuse device. This may improve performance.
166 *
167 * This feature is enabled by default when supported by the kernel and
168 * if the filesystem implements a write_buf() handler.
169 */
170 #define FUSE_CAP_SPLICE_READ (1 << 9)
171
172 /**
173 * If set, the calls to flock(2) will be emulated using POSIX locks and must
174 * then be handled by the filesystem's setlock() handler.
175 *
176 * If not set, flock(2) calls will be handled by the FUSE kernel module
177 * internally (so any access that does not go through the kernel cannot be taken
178 * into account).
179 *
180 * This feature is enabled by default when supported by the kernel and
181 * if the filesystem implements a flock() handler.
182 */
183 #define FUSE_CAP_FLOCK_LOCKS (1 << 10)
184
185 /**
186 * Indicates that the filesystem supports ioctl's on directories.
187 *
188 * This feature is enabled by default when supported by the kernel.
189 */
190 #define FUSE_CAP_IOCTL_DIR (1 << 11)
191
192 /**
193 * Traditionally, while a file is open the FUSE kernel module only
194 * asks the filesystem for an update of the file's attributes when a
195 * client attempts to read beyond EOF. This is unsuitable for
196 * e.g. network filesystems, where the file contents may change
197 * without the kernel knowing about it.
198 *
199 * If this flag is set, FUSE will check the validity of the attributes
200 * on every read. If the attributes are no longer valid (i.e., if the
201 * *attr_timeout* passed to fuse_reply_attr() or set in `struct
202 * fuse_entry_param` has passed), it will first issue a `getattr`
203 * request. If the new mtime differs from the previous value, any
204 * cached file *contents* will be invalidated as well.
205 *
206 * This flag should always be set when available. If all file changes
207 * go through the kernel, *attr_timeout* should be set to a very large
208 * number to avoid unnecessary getattr() calls.
209 *
210 * This feature is enabled by default when supported by the kernel.
211 */
212 #define FUSE_CAP_AUTO_INVAL_DATA (1 << 12)
213
214 /**
215 * Indicates that the filesystem supports readdirplus.
216 *
217 * This feature is enabled by default when supported by the kernel and if the
218 * filesystem implements a readdirplus() handler.
219 */
220 #define FUSE_CAP_READDIRPLUS (1 << 13)
221
222 /**
223 * Indicates that the filesystem supports adaptive readdirplus.
224 *
225 * If FUSE_CAP_READDIRPLUS is not set, this flag has no effect.
226 *
227 * If FUSE_CAP_READDIRPLUS is set and this flag is not set, the kernel
228 * will always issue readdirplus() requests to retrieve directory
229 * contents.
230 *
231 * If FUSE_CAP_READDIRPLUS is set and this flag is set, the kernel
232 * will issue both readdir() and readdirplus() requests, depending on
233 * how much information is expected to be required.
234 *
235 * As of Linux 4.20, the algorithm is as follows: when userspace
236 * starts to read directory entries, issue a READDIRPLUS request to
237 * the filesystem. If any entry attributes have been looked up by the
238 * time userspace requests the next batch of entries continue with
239 * READDIRPLUS, otherwise switch to plain READDIR. This will reasult
240 * in eg plain "ls" triggering READDIRPLUS first then READDIR after
241 * that because it doesn't do lookups. "ls -l" should result in all
242 * READDIRPLUS, except if dentries are already cached.
243 *
244 * This feature is enabled by default when supported by the kernel and
245 * if the filesystem implements both a readdirplus() and a readdir()
246 * handler.
247 */
248 #define FUSE_CAP_READDIRPLUS_AUTO (1 << 14)
249
250 /**
251 * Indicates that the filesystem supports asynchronous direct I/O submission.
252 *
253 * If this capability is not requested/available, the kernel will ensure that
254 * there is at most one pending read and one pending write request per direct
255 * I/O file-handle at any time.
256 *
257 * This feature is enabled by default when supported by the kernel.
258 */
259 #define FUSE_CAP_ASYNC_DIO (1 << 15)
260
261 /**
262 * Indicates that writeback caching should be enabled. This means that
263 * individual write request may be buffered and merged in the kernel
264 * before they are send to the filesystem.
265 *
266 * This feature is disabled by default.
267 */
268 #define FUSE_CAP_WRITEBACK_CACHE (1 << 16)
269
270 /**
271 * Indicates support for zero-message opens. If this flag is set in
272 * the `capable` field of the `fuse_conn_info` structure, then the
273 * filesystem may return `ENOSYS` from the open() handler to indicate
274 * success. Further attempts to open files will be handled in the
275 * kernel. (If this flag is not set, returning ENOSYS will be treated
276 * as an error and signaled to the caller).
277 *
278 * Setting (or unsetting) this flag in the `want` field has *no
279 * effect*.
280 */
281 #define FUSE_CAP_NO_OPEN_SUPPORT (1 << 17)
282
283 /**
284 * Indicates support for parallel directory operations. If this flag
285 * is unset, the FUSE kernel module will ensure that lookup() and
286 * readdir() requests are never issued concurrently for the same
287 * directory.
288 *
289 * This feature is enabled by default when supported by the kernel.
290 */
291 #define FUSE_CAP_PARALLEL_DIROPS (1 << 18)
292
293 /**
294 * Indicates support for POSIX ACLs.
295 *
296 * If this feature is enabled, the kernel will cache and have
297 * responsibility for enforcing ACLs. ACL will be stored as xattrs and
298 * passed to userspace, which is responsible for updating the ACLs in
299 * the filesystem, keeping the file mode in sync with the ACL, and
300 * ensuring inheritance of default ACLs when new filesystem nodes are
301 * created. Note that this requires that the file system is able to
302 * parse and interpret the xattr representation of ACLs.
303 *
304 * Enabling this feature implicitly turns on the
305 * ``default_permissions`` mount option (even if it was not passed to
306 * mount(2)).
307 *
308 * This feature is disabled by default.
309 */
310 #define FUSE_CAP_POSIX_ACL (1 << 19)
311
312 /**
313 * Indicates that the filesystem is responsible for unsetting
314 * setuid and setgid bits when a file is written, truncated, or
315 * its owner is changed.
316 *
317 * This feature is enabled by default when supported by the kernel.
318 */
319 #define FUSE_CAP_HANDLE_KILLPRIV (1 << 20)
320
321 /**
322 * Indicates support for zero-message opendirs. If this flag is set in
323 * the `capable` field of the `fuse_conn_info` structure, then the filesystem
324 * may return `ENOSYS` from the opendir() handler to indicate success. Further
325 * opendir and releasedir messages will be handled in the kernel. (If this
326 * flag is not set, returning ENOSYS will be treated as an error and signalled
327 * to the caller.)
328 *
329 * Setting (or unsetting) this flag in the `want` field has *no effect*.
330 */
331 #define FUSE_CAP_NO_OPENDIR_SUPPORT (1 << 24)
332
333 /**
334 * Ioctl flags
335 *
336 * FUSE_IOCTL_COMPAT: 32bit compat ioctl on 64bit machine
337 * FUSE_IOCTL_UNRESTRICTED: not restricted to well-formed ioctls, retry allowed
338 * FUSE_IOCTL_RETRY: retry with new iovecs
339 * FUSE_IOCTL_DIR: is a directory
340 *
341 * FUSE_IOCTL_MAX_IOV: maximum of in_iovecs + out_iovecs
342 */
343 #define FUSE_IOCTL_COMPAT (1 << 0)
344 #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
345 #define FUSE_IOCTL_RETRY (1 << 2)
346 #define FUSE_IOCTL_DIR (1 << 4)
347
348 #define FUSE_IOCTL_MAX_IOV 256
349
350 /**
351 * Connection information, passed to the ->init() method
352 *
353 * Some of the elements are read-write, these can be changed to
354 * indicate the value requested by the filesystem. The requested
355 * value must usually be smaller than the indicated value.
356 */
357 struct fuse_conn_info {
358 /**
359 * Major version of the protocol (read-only)
360 */
361 unsigned proto_major;
362
363 /**
364 * Minor version of the protocol (read-only)
365 */
366 unsigned proto_minor;
367
368 /**
369 * Maximum size of the write buffer
370 */
371 unsigned max_write;
372
373 /**
374 * Maximum size of read requests. A value of zero indicates no
375 * limit. However, even if the filesystem does not specify a
376 * limit, the maximum size of read requests will still be
377 * limited by the kernel.
378 *
379 * NOTE: For the time being, the maximum size of read requests
380 * must be set both here *and* passed to fuse_session_new()
381 * using the ``-o max_read=<n>`` mount option. At some point
382 * in the future, specifying the mount option will no longer
383 * be necessary.
384 */
385 unsigned max_read;
386
387 /**
388 * Maximum readahead
389 */
390 unsigned max_readahead;
391
392 /**
393 * Capability flags that the kernel supports (read-only)
394 */
395 unsigned capable;
396
397 /**
398 * Capability flags that the filesystem wants to enable.
399 *
400 * libfuse attempts to initialize this field with
401 * reasonable default values before calling the init() handler.
402 */
403 unsigned want;
404
405 /**
406 * Maximum number of pending "background" requests. A
407 * background request is any type of request for which the
408 * total number is not limited by other means. As of kernel
409 * 4.8, only two types of requests fall into this category:
410 *
411 * 1. Read-ahead requests
412 * 2. Asynchronous direct I/O requests
413 *
414 * Read-ahead requests are generated (if max_readahead is
415 * non-zero) by the kernel to preemptively fill its caches
416 * when it anticipates that userspace will soon read more
417 * data.
418 *
419 * Asynchronous direct I/O requests are generated if
420 * FUSE_CAP_ASYNC_DIO is enabled and userspace submits a large
421 * direct I/O request. In this case the kernel will internally
422 * split it up into multiple smaller requests and submit them
423 * to the filesystem concurrently.
424 *
425 * Note that the following requests are *not* background
426 * requests: writeback requests (limited by the kernel's
427 * flusher algorithm), regular (i.e., synchronous and
428 * buffered) userspace read/write requests (limited to one per
429 * thread), asynchronous read requests (Linux's io_submit(2)
430 * call actually blocks, so these are also limited to one per
431 * thread).
432 */
433 unsigned max_background;
434
435 /**
436 * Kernel congestion threshold parameter. If the number of pending
437 * background requests exceeds this number, the FUSE kernel module will
438 * mark the filesystem as "congested". This instructs the kernel to
439 * expect that queued requests will take some time to complete, and to
440 * adjust its algorithms accordingly (e.g. by putting a waiting thread
441 * to sleep instead of using a busy-loop).
442 */
443 unsigned congestion_threshold;
444
445 /**
446 * When FUSE_CAP_WRITEBACK_CACHE is enabled, the kernel is responsible
447 * for updating mtime and ctime when write requests are received. The
448 * updated values are passed to the filesystem with setattr() requests.
449 * However, if the filesystem does not support the full resolution of
450 * the kernel timestamps (nanoseconds), the mtime and ctime values used
451 * by kernel and filesystem will differ (and result in an apparent
452 * change of times after a cache flush).
453 *
454 * To prevent this problem, this variable can be used to inform the
455 * kernel about the timestamp granularity supported by the file-system.
456 * The value should be power of 10. The default is 1, i.e. full
457 * nano-second resolution. Filesystems supporting only second resolution
458 * should set this to 1000000000.
459 */
460 unsigned time_gran;
461
462 /**
463 * For future use.
464 */
465 unsigned reserved[22];
466 };
467
468 struct fuse_session;
469 struct fuse_pollhandle;
470 struct fuse_conn_info_opts;
471
472 /**
473 * This function parses several command-line options that can be used
474 * to override elements of struct fuse_conn_info. The pointer returned
475 * by this function should be passed to the
476 * fuse_apply_conn_info_opts() method by the file system's init()
477 * handler.
478 *
479 * Before using this function, think twice if you really want these
480 * parameters to be adjustable from the command line. In most cases,
481 * they should be determined by the file system internally.
482 *
483 * The following options are recognized:
484 *
485 * -o max_write=N sets conn->max_write
486 * -o max_readahead=N sets conn->max_readahead
487 * -o max_background=N sets conn->max_background
488 * -o congestion_threshold=N sets conn->congestion_threshold
489 * -o async_read sets FUSE_CAP_ASYNC_READ in conn->want
490 * -o sync_read unsets FUSE_CAP_ASYNC_READ in conn->want
491 * -o atomic_o_trunc sets FUSE_CAP_ATOMIC_O_TRUNC in conn->want
492 * -o no_remote_lock Equivalent to -o no_remote_flock,no_remote_posix_lock
493 * -o no_remote_flock Unsets FUSE_CAP_FLOCK_LOCKS in conn->want
494 * -o no_remote_posix_lock Unsets FUSE_CAP_POSIX_LOCKS in conn->want
495 * -o [no_]splice_write (un-)sets FUSE_CAP_SPLICE_WRITE in conn->want
496 * -o [no_]splice_move (un-)sets FUSE_CAP_SPLICE_MOVE in conn->want
497 * -o [no_]splice_read (un-)sets FUSE_CAP_SPLICE_READ in conn->want
498 * -o [no_]auto_inval_data (un-)sets FUSE_CAP_AUTO_INVAL_DATA in conn->want
499 * -o readdirplus=no unsets FUSE_CAP_READDIRPLUS in conn->want
500 * -o readdirplus=yes sets FUSE_CAP_READDIRPLUS and unsets
501 * FUSE_CAP_READDIRPLUS_AUTO in conn->want
502 * -o readdirplus=auto sets FUSE_CAP_READDIRPLUS and
503 * FUSE_CAP_READDIRPLUS_AUTO in conn->want
504 * -o [no_]async_dio (un-)sets FUSE_CAP_ASYNC_DIO in conn->want
505 * -o [no_]writeback_cache (un-)sets FUSE_CAP_WRITEBACK_CACHE in conn->want
506 * -o time_gran=N sets conn->time_gran
507 *
508 * Known options will be removed from *args*, unknown options will be
509 * passed through unchanged.
510 *
511 * @param args argument vector (input+output)
512 * @return parsed options
513 **/
514 struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args);
515
516 /**
517 * This function applies the (parsed) parameters in *opts* to the
518 * *conn* pointer. It may modify the following fields: wants,
519 * max_write, max_readahead, congestion_threshold, max_background,
520 * time_gran. A field is only set (or unset) if the corresponding
521 * option has been explicitly set.
522 */
523 void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
524 struct fuse_conn_info *conn);
525
526 /**
527 * Go into the background
528 *
529 * @param foreground if true, stay in the foreground
530 * @return 0 on success, -1 on failure
531 */
532 int fuse_daemonize(int foreground);
533
534 /**
535 * Get the version of the library
536 *
537 * @return the version
538 */
539 int fuse_version(void);
540
541 /**
542 * Get the full package version string of the library
543 *
544 * @return the package version
545 */
546 const char *fuse_pkgversion(void);
547
548 /**
549 * Destroy poll handle
550 *
551 * @param ph the poll handle
552 */
553 void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
554
555 /* ----------------------------------------------------------- *
556 * Data buffer *
557 * ----------------------------------------------------------- */
558
559 /**
560 * Buffer flags
561 */
562 enum fuse_buf_flags {
563 /**
564 * Buffer contains a file descriptor
565 *
566 * If this flag is set, the .fd field is valid, otherwise the
567 * .mem fields is valid.
568 */
569 FUSE_BUF_IS_FD = (1 << 1),
570
571 /**
572 * Seek on the file descriptor
573 *
574 * If this flag is set then the .pos field is valid and is
575 * used to seek to the given offset before performing
576 * operation on file descriptor.
577 */
578 FUSE_BUF_FD_SEEK = (1 << 2),
579
580 /**
581 * Retry operation on file descriptor
582 *
583 * If this flag is set then retry operation on file descriptor
584 * until .size bytes have been copied or an error or EOF is
585 * detected.
586 */
587 FUSE_BUF_FD_RETRY = (1 << 3),
588 };
589
590 /**
591 * Buffer copy flags
592 */
593 enum fuse_buf_copy_flags {
594 /**
595 * Don't use splice(2)
596 *
597 * Always fall back to using read and write instead of
598 * splice(2) to copy data from one file descriptor to another.
599 *
600 * If this flag is not set, then only fall back if splice is
601 * unavailable.
602 */
603 FUSE_BUF_NO_SPLICE = (1 << 1),
604
605 /**
606 * Force splice
607 *
608 * Always use splice(2) to copy data from one file descriptor
609 * to another. If splice is not available, return -EINVAL.
610 */
611 FUSE_BUF_FORCE_SPLICE = (1 << 2),
612
613 /**
614 * Try to move data with splice.
615 *
616 * If splice is used, try to move pages from the source to the
617 * destination instead of copying. See documentation of
618 * SPLICE_F_MOVE in splice(2) man page.
619 */
620 FUSE_BUF_SPLICE_MOVE = (1 << 3),
621
622 /**
623 * Don't block on the pipe when copying data with splice
624 *
625 * Makes the operations on the pipe non-blocking (if the pipe
626 * is full or empty). See SPLICE_F_NONBLOCK in the splice(2)
627 * man page.
628 */
629 FUSE_BUF_SPLICE_NONBLOCK= (1 << 4),
630 };
631
632 /**
633 * Single data buffer
634 *
635 * Generic data buffer for I/O, extended attributes, etc... Data may
636 * be supplied as a memory pointer or as a file descriptor
637 */
638 struct fuse_buf {
639 /**
640 * Size of data in bytes
641 */
642 size_t size;
643
644 /**
645 * Buffer flags
646 */
647 enum fuse_buf_flags flags;
648
649 /**
650 * Memory pointer
651 *
652 * Used unless FUSE_BUF_IS_FD flag is set.
653 */
654 void *mem;
655
656 /**
657 * File descriptor
658 *
659 * Used if FUSE_BUF_IS_FD flag is set.
660 */
661 int fd;
662
663 /**
664 * File position
665 *
666 * Used if FUSE_BUF_FD_SEEK flag is set.
667 */
668 off_t pos;
669 };
670
671 /**
672 * Data buffer vector
673 *
674 * An array of data buffers, each containing a memory pointer or a
675 * file descriptor.
676 *
677 * Allocate dynamically to add more than one buffer.
678 */
679 struct fuse_bufvec {
680 /**
681 * Number of buffers in the array
682 */
683 size_t count;
684
685 /**
686 * Index of current buffer within the array
687 */
688 size_t idx;
689
690 /**
691 * Current offset within the current buffer
692 */
693 size_t off;
694
695 /**
696 * Array of buffers
697 */
698 struct fuse_buf buf[1];
699 };
700
701 /* Initialize bufvec with a single buffer of given size */
702 #define FUSE_BUFVEC_INIT(size__) \
703 ((struct fuse_bufvec) { \
704 /* .count= */ 1, \
705 /* .idx = */ 0, \
706 /* .off = */ 0, \
707 /* .buf = */ { /* [0] = */ { \
708 /* .size = */ (size__), \
709 /* .flags = */ (enum fuse_buf_flags) 0, \
710 /* .mem = */ NULL, \
711 /* .fd = */ -1, \
712 /* .pos = */ 0, \
713 } } \
714 } )
715
716 /**
717 * Get total size of data in a fuse buffer vector
718 *
719 * @param bufv buffer vector
720 * @return size of data
721 */
722 size_t fuse_buf_size(const struct fuse_bufvec *bufv);
723
724 /**
725 * Copy data from one buffer vector to another
726 *
727 * @param dst destination buffer vector
728 * @param src source buffer vector
729 * @param flags flags controlling the copy
730 * @return actual number of bytes copied or -errno on error
731 */
732 ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src,
733 enum fuse_buf_copy_flags flags);
734
735 /* ----------------------------------------------------------- *
736 * Signal handling *
737 * ----------------------------------------------------------- */
738
739 /**
740 * Exit session on HUP, TERM and INT signals and ignore PIPE signal
741 *
742 * Stores session in a global variable. May only be called once per
743 * process until fuse_remove_signal_handlers() is called.
744 *
745 * Once either of the POSIX signals arrives, the signal handler calls
746 * fuse_session_exit().
747 *
748 * @param se the session to exit
749 * @return 0 on success, -1 on failure
750 *
751 * See also:
752 * fuse_remove_signal_handlers()
753 */
754 int fuse_set_signal_handlers(struct fuse_session *se);
755
756 /**
757 * Restore default signal handlers
758 *
759 * Resets global session. After this fuse_set_signal_handlers() may
760 * be called again.
761 *
762 * @param se the same session as given in fuse_set_signal_handlers()
763 *
764 * See also:
765 * fuse_set_signal_handlers()
766 */
767 void fuse_remove_signal_handlers(struct fuse_session *se);
768
769 /* ----------------------------------------------------------- *
770 * Compatibility stuff *
771 * ----------------------------------------------------------- */
772
773 #if !defined(FUSE_USE_VERSION) || FUSE_USE_VERSION < 30
774 # error only API version 30 or greater is supported
775 #endif
776
777
778 /*
779 * This interface uses 64 bit off_t.
780 *
781 * On 32bit systems please add -D_FILE_OFFSET_BITS=64 to your compile flags!
782 */
783
784 #if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 6) && !defined __cplusplus
785 _Static_assert(sizeof(off_t) == 8, "fuse: off_t must be 64bit");
786 #else
787 struct _fuse_off_t_must_be_64bit_dummy_struct \
788 { unsigned _fuse_off_t_must_be_64bit:((sizeof(off_t) == 8) ? 1 : -1); };
789 #endif
790
791 #endif /* FUSE_COMMON_H_ */