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