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