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 #ifndef _FUSE_LOWLEVEL_H_ 10 #define _FUSE_LOWLEVEL_H_ 11 12 /** @file 13 * 14 * Low level API 15 * 16 * IMPORTANT: you should define FUSE_USE_VERSION before including this 17 * header. To use the newest API define it to 26 (recommended for any 18 * new application), to use the old API define it to 24 (default) or 19 * 25 20 */ 21 22 #ifndef FUSE_USE_VERSION 23 #define FUSE_USE_VERSION 24 24 #endif 25 26 #include "fuse_common.h" 27 28 #include <utime.h> 29 #include <fcntl.h> 30 #include <sys/types.h> 31 #include <sys/stat.h> 32 #include <sys/statvfs.h> 33 #include <sys/uio.h> 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 /* ----------------------------------------------------------- * 40 * Miscellaneous definitions * 41 * ----------------------------------------------------------- */ 42 43 /** The node ID of the root inode */ 44 #define FUSE_ROOT_ID 1 45 46 /** Inode number type */ 47 typedef unsigned long fuse_ino_t; 48 49 /** Request pointer type */ 50 typedef struct fuse_req *fuse_req_t; 51 52 /** 53 * Session 54 * 55 * This provides hooks for processing requests, and exiting 56 */ 57 struct fuse_session; 58 59 /** 60 * Channel 61 * 62 * A communication channel, providing hooks for sending and receiving 63 * messages 64 */ 65 struct fuse_chan; 66 67 /** Directory entry parameters supplied to fuse_reply_entry() */ 68 struct fuse_entry_param { 69 /** Unique inode number 70 * 71 * In lookup, zero means negative entry (from version 2.5) 72 * Returning ENOENT also means negative entry, but by setting zero 73 * ino the kernel may cache negative entries for entry_timeout 74 * seconds. 75 */ 76 fuse_ino_t ino; 77 78 /** Generation number for this entry. 79 * 80 * If the file system will be exported over NFS, the 81 * ino/generation pairs need to be unique over the file 82 * system's lifetime (rather than just the mount time). So if 83 * the file system reuses an inode after it has been deleted, 84 * it must assign a new, previously unused generation number 85 * to the inode at the same time. 86 * 87 * The generation must be non-zero, otherwise FUSE will treat 88 * it as an error. 89 * 90 */ 91 unsigned long generation; 92 93 /** Inode attributes. 94 * 95 * Even if attr_timeout == 0, attr must be correct. For example, 96 * for open(), FUSE uses attr.st_size from lookup() to determine 97 * how many bytes to request. If this value is not correct, 98 * incorrect data will be returned. 99 */ 100 struct stat attr; 101 102 /** Validity timeout (in seconds) for the attributes */ 103 double attr_timeout; 104 105 /** Validity timeout (in seconds) for the name */ 106 double entry_timeout; 107 }; 108 109 /** 110 * Additional context associated with requests. 111 * 112 * Note that the reported client uid, gid and pid may be zero in some 113 * situations. For example, if the FUSE file system is running in a 114 * PID or user namespace but then accessed from outside the namespace, 115 * there is no valid uid/pid/gid that could be reported. 116 */ 117 struct fuse_ctx { 118 /** User ID of the calling process */ 119 uid_t uid; 120 121 /** Group ID of the calling process */ 122 gid_t gid; 123 124 /** Thread ID of the calling process */ 125 pid_t pid; 126 127 /** Umask of the calling process (introduced in version 2.8) */ 128 mode_t umask; 129 }; 130 131 struct fuse_forget_data { 132 uint64_t ino; 133 uint64_t nlookup; 134 }; 135 136 /* 'to_set' flags in setattr */ 137 #define FUSE_SET_ATTR_MODE (1 << 0) 138 #define FUSE_SET_ATTR_UID (1 << 1) 139 #define FUSE_SET_ATTR_GID (1 << 2) 140 #define FUSE_SET_ATTR_SIZE (1 << 3) 141 #define FUSE_SET_ATTR_ATIME (1 << 4) 142 #define FUSE_SET_ATTR_MTIME (1 << 5) 143 #define FUSE_SET_ATTR_ATIME_NOW (1 << 7) 144 #define FUSE_SET_ATTR_MTIME_NOW (1 << 8) 145 146 /* ----------------------------------------------------------- * 147 * Request methods and replies * 148 * ----------------------------------------------------------- */ 149 150 /** 151 * Low level filesystem operations 152 * 153 * Most of the methods (with the exception of init and destroy) 154 * receive a request handle (fuse_req_t) as their first argument. 155 * This handle must be passed to one of the specified reply functions. 156 * 157 * This may be done inside the method invocation, or after the call 158 * has returned. The request handle is valid until one of the reply 159 * functions is called. 160 * 161 * Other pointer arguments (name, fuse_file_info, etc) are not valid 162 * after the call has returned, so if they are needed later, their 163 * contents have to be copied. 164 * 165 * The filesystem sometimes needs to handle a return value of -ENOENT 166 * from the reply function, which means, that the request was 167 * interrupted, and the reply discarded. For example if 168 * fuse_reply_open() return -ENOENT means, that the release method for 169 * this file will not be called. 170 */ 171 struct fuse_lowlevel_ops { 172 /** 173 * Initialize filesystem 174 * 175 * Called before any other filesystem method 176 * 177 * There's no reply to this function 178 * 179 * @param userdata the user data passed to fuse_lowlevel_new() 180 */ 181 void (*init) (void *userdata, struct fuse_conn_info *conn); 182 183 /** 184 * Clean up filesystem 185 * 186 * Called on filesystem exit 187 * 188 * There's no reply to this function 189 * 190 * @param userdata the user data passed to fuse_lowlevel_new() 191 */ 192 void (*destroy) (void *userdata); 193 194 /** 195 * Look up a directory entry by name and get its attributes. 196 * 197 * Valid replies: 198 * fuse_reply_entry 199 * fuse_reply_err 200 * 201 * @param req request handle 202 * @param parent inode number of the parent directory 203 * @param name the name to look up 204 */ 205 void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name); 206 207 /** 208 * Forget about an inode 209 * 210 * This function is called when the kernel removes an inode 211 * from its internal caches. 212 * 213 * The inode's lookup count increases by one for every call to 214 * fuse_reply_entry and fuse_reply_create. The nlookup parameter 215 * indicates by how much the lookup count should be decreased. 216 * 217 * Inodes with a non-zero lookup count may receive request from 218 * the kernel even after calls to unlink, rmdir or (when 219 * overwriting an existing file) rename. Filesystems must handle 220 * such requests properly and it is recommended to defer removal 221 * of the inode until the lookup count reaches zero. Calls to 222 * unlink, remdir or rename will be followed closely by forget 223 * unless the file or directory is open, in which case the 224 * kernel issues forget only after the release or releasedir 225 * calls. 226 * 227 * Note that if a file system will be exported over NFS the 228 * inodes lifetime must extend even beyond forget. See the 229 * generation field in struct fuse_entry_param above. 230 * 231 * On unmount the lookup count for all inodes implicitly drops 232 * to zero. It is not guaranteed that the file system will 233 * receive corresponding forget messages for the affected 234 * inodes. 235 * 236 * Valid replies: 237 * fuse_reply_none 238 * 239 * @param req request handle 240 * @param ino the inode number 241 * @param nlookup the number of lookups to forget 242 */ 243 void (*forget) (fuse_req_t req, fuse_ino_t ino, unsigned long nlookup); 244 245 /** 246 * Get file attributes 247 * 248 * Valid replies: 249 * fuse_reply_attr 250 * fuse_reply_err 251 * 252 * @param req request handle 253 * @param ino the inode number 254 * @param fi for future use, currently always NULL 255 */ 256 void (*getattr) (fuse_req_t req, fuse_ino_t ino, 257 struct fuse_file_info *fi); 258 259 /** 260 * Set file attributes 261 * 262 * In the 'attr' argument only members indicated by the 'to_set' 263 * bitmask contain valid values. Other members contain undefined 264 * values. 265 * 266 * If the setattr was invoked from the ftruncate() system call 267 * under Linux kernel versions 2.6.15 or later, the fi->fh will 268 * contain the value set by the open method or will be undefined 269 * if the open method didn't set any value. Otherwise (not 270 * ftruncate call, or kernel version earlier than 2.6.15) the fi 271 * parameter will be NULL. 272 * 273 * Valid replies: 274 * fuse_reply_attr 275 * fuse_reply_err 276 * 277 * @param req request handle 278 * @param ino the inode number 279 * @param attr the attributes 280 * @param to_set bit mask of attributes which should be set 281 * @param fi file information, or NULL 282 * 283 * Changed in version 2.5: 284 * file information filled in for ftruncate 285 */ 286 void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr, 287 int to_set, struct fuse_file_info *fi); 288 289 /** 290 * Read symbolic link 291 * 292 * Valid replies: 293 * fuse_reply_readlink 294 * fuse_reply_err 295 * 296 * @param req request handle 297 * @param ino the inode number 298 */ 299 void (*readlink) (fuse_req_t req, fuse_ino_t ino); 300 301 /** 302 * Create file node 303 * 304 * Create a regular file, character device, block device, fifo or 305 * socket node. 306 * 307 * Valid replies: 308 * fuse_reply_entry 309 * fuse_reply_err 310 * 311 * @param req request handle 312 * @param parent inode number of the parent directory 313 * @param name to create 314 * @param mode file type and mode with which to create the new file 315 * @param rdev the device number (only valid if created file is a device) 316 */ 317 void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name, 318 mode_t mode, dev_t rdev); 319 320 /** 321 * Create a directory 322 * 323 * Valid replies: 324 * fuse_reply_entry 325 * fuse_reply_err 326 * 327 * @param req request handle 328 * @param parent inode number of the parent directory 329 * @param name to create 330 * @param mode with which to create the new file 331 */ 332 void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name, 333 mode_t mode); 334 335 /** 336 * Remove a file 337 * 338 * If the file's inode's lookup count is non-zero, the file 339 * system is expected to postpone any removal of the inode 340 * until the lookup count reaches zero (see description of the 341 * forget function). 342 * 343 * Valid replies: 344 * fuse_reply_err 345 * 346 * @param req request handle 347 * @param parent inode number of the parent directory 348 * @param name to remove 349 */ 350 void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name); 351 352 /** 353 * Remove a directory 354 * 355 * If the directory's inode's lookup count is non-zero, the 356 * file system is expected to postpone any removal of the 357 * inode until the lookup count reaches zero (see description 358 * of the forget function). 359 * 360 * Valid replies: 361 * fuse_reply_err 362 * 363 * @param req request handle 364 * @param parent inode number of the parent directory 365 * @param name to remove 366 */ 367 void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name); 368 369 /** 370 * Create a symbolic link 371 * 372 * Valid replies: 373 * fuse_reply_entry 374 * fuse_reply_err 375 * 376 * @param req request handle 377 * @param link the contents of the symbolic link 378 * @param parent inode number of the parent directory 379 * @param name to create 380 */ 381 void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent, 382 const char *name); 383 384 /** Rename a file 385 * 386 * If the target exists it should be atomically replaced. If 387 * the target's inode's lookup count is non-zero, the file 388 * system is expected to postpone any removal of the inode 389 * until the lookup count reaches zero (see description of the 390 * forget function). 391 * 392 * Valid replies: 393 * fuse_reply_err 394 * 395 * @param req request handle 396 * @param parent inode number of the old parent directory 397 * @param name old name 398 * @param newparent inode number of the new parent directory 399 * @param newname new name 400 */ 401 void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name, 402 fuse_ino_t newparent, const char *newname); 403 404 /** 405 * Create a hard link 406 * 407 * Valid replies: 408 * fuse_reply_entry 409 * fuse_reply_err 410 * 411 * @param req request handle 412 * @param ino the old inode number 413 * @param newparent inode number of the new parent directory 414 * @param newname new name to create 415 */ 416 void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, 417 const char *newname); 418 419 /** 420 * Open a file 421 * 422 * Open flags (with the exception of O_CREAT, O_EXCL, O_NOCTTY and 423 * O_TRUNC) are available in fi->flags. 424 * 425 * Filesystem may store an arbitrary file handle (pointer, index, 426 * etc) in fi->fh, and use this in other all other file operations 427 * (read, write, flush, release, fsync). 428 * 429 * Filesystem may also implement stateless file I/O and not store 430 * anything in fi->fh. 431 * 432 * There are also some flags (direct_io, keep_cache) which the 433 * filesystem may set in fi, to change the way the file is opened. 434 * See fuse_file_info structure in <fuse_common.h> for more details. 435 * 436 * Valid replies: 437 * fuse_reply_open 438 * fuse_reply_err 439 * 440 * @param req request handle 441 * @param ino the inode number 442 * @param fi file information 443 */ 444 void (*open) (fuse_req_t req, fuse_ino_t ino, 445 struct fuse_file_info *fi); 446 447 /** 448 * Read data 449 * 450 * Read should send exactly the number of bytes requested except 451 * on EOF or error, otherwise the rest of the data will be 452 * substituted with zeroes. An exception to this is when the file 453 * has been opened in 'direct_io' mode, in which case the return 454 * value of the read system call will reflect the return value of 455 * this operation. 456 * 457 * fi->fh will contain the value set by the open method, or will 458 * be undefined if the open method didn't set any value. 459 * 460 * Valid replies: 461 * fuse_reply_buf 462 * fuse_reply_iov 463 * fuse_reply_data 464 * fuse_reply_err 465 * 466 * @param req request handle 467 * @param ino the inode number 468 * @param size number of bytes to read 469 * @param off offset to read from 470 * @param fi file information 471 */ 472 void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, 473 struct fuse_file_info *fi); 474 475 /** 476 * Write data 477 * 478 * Write should return exactly the number of bytes requested 479 * except on error. An exception to this is when the file has 480 * been opened in 'direct_io' mode, in which case the return value 481 * of the write system call will reflect the return value of this 482 * operation. 483 * 484 * fi->fh will contain the value set by the open method, or will 485 * be undefined if the open method didn't set any value. 486 * 487 * Valid replies: 488 * fuse_reply_write 489 * fuse_reply_err 490 * 491 * @param req request handle 492 * @param ino the inode number 493 * @param buf data to write 494 * @param size number of bytes to write 495 * @param off offset to write to 496 * @param fi file information 497 */ 498 void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf, 499 size_t size, off_t off, struct fuse_file_info *fi); 500 501 /** 502 * Flush method 503 * 504 * This is called on each close() of the opened file. 505 * 506 * Since file descriptors can be duplicated (dup, dup2, fork), for 507 * one open call there may be many flush calls. 508 * 509 * Filesystems shouldn't assume that flush will always be called 510 * after some writes, or that if will be called at all. 511 * 512 * fi->fh will contain the value set by the open method, or will 513 * be undefined if the open method didn't set any value. 514 * 515 * NOTE: the name of the method is misleading, since (unlike 516 * fsync) the filesystem is not forced to flush pending writes. 517 * One reason to flush data, is if the filesystem wants to return 518 * write errors. 519 * 520 * If the filesystem supports file locking operations (setlk, 521 * getlk) it should remove all locks belonging to 'fi->owner'. 522 * 523 * Valid replies: 524 * fuse_reply_err 525 * 526 * @param req request handle 527 * @param ino the inode number 528 * @param fi file information 529 */ 530 void (*flush) (fuse_req_t req, fuse_ino_t ino, 531 struct fuse_file_info *fi); 532 533 /** 534 * Release an open file 535 * 536 * Release is called when there are no more references to an open 537 * file: all file descriptors are closed and all memory mappings 538 * are unmapped. 539 * 540 * For every open call there will be exactly one release call. 541 * 542 * The filesystem may reply with an error, but error values are 543 * not returned to close() or munmap() which triggered the 544 * release. 545 * 546 * fi->fh will contain the value set by the open method, or will 547 * be undefined if the open method didn't set any value. 548 * fi->flags will contain the same flags as for open. 549 * 550 * Valid replies: 551 * fuse_reply_err 552 * 553 * @param req request handle 554 * @param ino the inode number 555 * @param fi file information 556 */ 557 void (*release) (fuse_req_t req, fuse_ino_t ino, 558 struct fuse_file_info *fi); 559 560 /** 561 * Synchronize file contents 562 * 563 * If the datasync parameter is non-zero, then only the user data 564 * should be flushed, not the meta data. 565 * 566 * Valid replies: 567 * fuse_reply_err 568 * 569 * @param req request handle 570 * @param ino the inode number 571 * @param datasync flag indicating if only data should be flushed 572 * @param fi file information 573 */ 574 void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync, 575 struct fuse_file_info *fi); 576 577 /** 578 * Open a directory 579 * 580 * Filesystem may store an arbitrary file handle (pointer, index, 581 * etc) in fi->fh, and use this in other all other directory 582 * stream operations (readdir, releasedir, fsyncdir). 583 * 584 * Filesystem may also implement stateless directory I/O and not 585 * store anything in fi->fh, though that makes it impossible to 586 * implement standard conforming directory stream operations in 587 * case the contents of the directory can change between opendir 588 * and releasedir. 589 * 590 * Valid replies: 591 * fuse_reply_open 592 * fuse_reply_err 593 * 594 * @param req request handle 595 * @param ino the inode number 596 * @param fi file information 597 */ 598 void (*opendir) (fuse_req_t req, fuse_ino_t ino, 599 struct fuse_file_info *fi); 600 601 /** 602 * Read directory 603 * 604 * Send a buffer filled using fuse_add_direntry(), with size not 605 * exceeding the requested size. Send an empty buffer on end of 606 * stream. 607 * 608 * fi->fh will contain the value set by the opendir method, or 609 * will be undefined if the opendir method didn't set any value. 610 * 611 * Valid replies: 612 * fuse_reply_buf 613 * fuse_reply_data 614 * fuse_reply_err 615 * 616 * @param req request handle 617 * @param ino the inode number 618 * @param size maximum number of bytes to send 619 * @param off offset to continue reading the directory stream 620 * @param fi file information 621 */ 622 void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, 623 struct fuse_file_info *fi); 624 625 /** 626 * Release an open directory 627 * 628 * For every opendir call there will be exactly one releasedir 629 * call. 630 * 631 * fi->fh will contain the value set by the opendir method, or 632 * will be undefined if the opendir method didn't set any value. 633 * 634 * Valid replies: 635 * fuse_reply_err 636 * 637 * @param req request handle 638 * @param ino the inode number 639 * @param fi file information 640 */ 641 void (*releasedir) (fuse_req_t req, fuse_ino_t ino, 642 struct fuse_file_info *fi); 643 644 /** 645 * Synchronize directory contents 646 * 647 * If the datasync parameter is non-zero, then only the directory 648 * contents should be flushed, not the meta data. 649 * 650 * fi->fh will contain the value set by the opendir method, or 651 * will be undefined if the opendir method didn't set any value. 652 * 653 * Valid replies: 654 * fuse_reply_err 655 * 656 * @param req request handle 657 * @param ino the inode number 658 * @param datasync flag indicating if only data should be flushed 659 * @param fi file information 660 */ 661 void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync, 662 struct fuse_file_info *fi); 663 664 /** 665 * Get file system statistics 666 * 667 * Valid replies: 668 * fuse_reply_statfs 669 * fuse_reply_err 670 * 671 * @param req request handle 672 * @param ino the inode number, zero means "undefined" 673 */ 674 void (*statfs) (fuse_req_t req, fuse_ino_t ino); 675 676 /** 677 * Set an extended attribute 678 * 679 * Valid replies: 680 * fuse_reply_err 681 */ 682 void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name, 683 const char *value, size_t size, int flags); 684 685 /** 686 * Get an extended attribute 687 * 688 * If size is zero, the size of the value should be sent with 689 * fuse_reply_xattr. 690 * 691 * If the size is non-zero, and the value fits in the buffer, the 692 * value should be sent with fuse_reply_buf. 693 * 694 * If the size is too small for the value, the ERANGE error should 695 * be sent. 696 * 697 * Valid replies: 698 * fuse_reply_buf 699 * fuse_reply_data 700 * fuse_reply_xattr 701 * fuse_reply_err 702 * 703 * @param req request handle 704 * @param ino the inode number 705 * @param name of the extended attribute 706 * @param size maximum size of the value to send 707 */ 708 void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name, 709 size_t size); 710 711 /** 712 * List extended attribute names 713 * 714 * If size is zero, the total size of the attribute list should be 715 * sent with fuse_reply_xattr. 716 * 717 * If the size is non-zero, and the null character separated 718 * attribute list fits in the buffer, the list should be sent with 719 * fuse_reply_buf. 720 * 721 * If the size is too small for the list, the ERANGE error should 722 * be sent. 723 * 724 * Valid replies: 725 * fuse_reply_buf 726 * fuse_reply_data 727 * fuse_reply_xattr 728 * fuse_reply_err 729 * 730 * @param req request handle 731 * @param ino the inode number 732 * @param size maximum size of the list to send 733 */ 734 void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size); 735 736 /** 737 * Remove an extended attribute 738 * 739 * Valid replies: 740 * fuse_reply_err 741 * 742 * @param req request handle 743 * @param ino the inode number 744 * @param name of the extended attribute 745 */ 746 void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name); 747 748 /** 749 * Check file access permissions 750 * 751 * This will be called for the access() system call. If the 752 * 'default_permissions' mount option is given, this method is not 753 * called. 754 * 755 * This method is not called under Linux kernel versions 2.4.x 756 * 757 * Introduced in version 2.5 758 * 759 * Valid replies: 760 * fuse_reply_err 761 * 762 * @param req request handle 763 * @param ino the inode number 764 * @param mask requested access mode 765 */ 766 void (*access) (fuse_req_t req, fuse_ino_t ino, int mask); 767 768 /** 769 * Create and open a file 770 * 771 * If the file does not exist, first create it with the specified 772 * mode, and then open it. 773 * 774 * Open flags (with the exception of O_NOCTTY) are available in 775 * fi->flags. 776 * 777 * Filesystem may store an arbitrary file handle (pointer, index, 778 * etc) in fi->fh, and use this in other all other file operations 779 * (read, write, flush, release, fsync). 780 * 781 * There are also some flags (direct_io, keep_cache) which the 782 * filesystem may set in fi, to change the way the file is opened. 783 * See fuse_file_info structure in <fuse_common.h> for more details. 784 * 785 * If this method is not implemented or under Linux kernel 786 * versions earlier than 2.6.15, the mknod() and open() methods 787 * will be called instead. 788 * 789 * Introduced in version 2.5 790 * 791 * Valid replies: 792 * fuse_reply_create 793 * fuse_reply_err 794 * 795 * @param req request handle 796 * @param parent inode number of the parent directory 797 * @param name to create 798 * @param mode file type and mode with which to create the new file 799 * @param fi file information 800 */ 801 void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name, 802 mode_t mode, struct fuse_file_info *fi); 803 804 /** 805 * Test for a POSIX file lock 806 * 807 * Introduced in version 2.6 808 * 809 * Valid replies: 810 * fuse_reply_lock 811 * fuse_reply_err 812 * 813 * @param req request handle 814 * @param ino the inode number 815 * @param fi file information 816 * @param lock the region/type to test 817 */ 818 void (*getlk) (fuse_req_t req, fuse_ino_t ino, 819 struct fuse_file_info *fi, struct flock *lock); 820 821 /** 822 * Acquire, modify or release a POSIX file lock 823 * 824 * For POSIX threads (NPTL) there's a 1-1 relation between pid and 825 * owner, but otherwise this is not always the case. For checking 826 * lock ownership, 'fi->owner' must be used. The l_pid field in 827 * 'struct flock' should only be used to fill in this field in 828 * getlk(). 829 * 830 * Note: if the locking methods are not implemented, the kernel 831 * will still allow file locking to work locally. Hence these are 832 * only interesting for network filesystems and similar. 833 * 834 * Introduced in version 2.6 835 * 836 * Valid replies: 837 * fuse_reply_err 838 * 839 * @param req request handle 840 * @param ino the inode number 841 * @param fi file information 842 * @param lock the region/type to set 843 * @param sleep locking operation may sleep 844 */ 845 void (*setlk) (fuse_req_t req, fuse_ino_t ino, 846 struct fuse_file_info *fi, 847 struct flock *lock, int sleep); 848 849 /** 850 * Map block index within file to block index within device 851 * 852 * Note: This makes sense only for block device backed filesystems 853 * mounted with the 'blkdev' option 854 * 855 * Introduced in version 2.6 856 * 857 * Valid replies: 858 * fuse_reply_bmap 859 * fuse_reply_err 860 * 861 * @param req request handle 862 * @param ino the inode number 863 * @param blocksize unit of block index 864 * @param idx block index within file 865 */ 866 void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize, 867 uint64_t idx); 868 869 /** 870 * Ioctl 871 * 872 * Note: For unrestricted ioctls (not allowed for FUSE 873 * servers), data in and out areas can be discovered by giving 874 * iovs and setting FUSE_IOCTL_RETRY in @flags. For 875 * restricted ioctls, kernel prepares in/out data area 876 * according to the information encoded in cmd. 877 * 878 * Introduced in version 2.8 879 * 880 * Valid replies: 881 * fuse_reply_ioctl_retry 882 * fuse_reply_ioctl 883 * fuse_reply_ioctl_iov 884 * fuse_reply_err 885 * 886 * @param req request handle 887 * @param ino the inode number 888 * @param cmd ioctl command 889 * @param arg ioctl argument 890 * @param fi file information 891 * @param flags for FUSE_IOCTL_* flags 892 * @param in_buf data fetched from the caller 893 * @param in_bufsz number of fetched bytes 894 * @param out_bufsz maximum size of output data 895 */ 896 void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg, 897 struct fuse_file_info *fi, unsigned flags, 898 const void *in_buf, size_t in_bufsz, size_t out_bufsz); 899 900 /** 901 * Poll for IO readiness 902 * 903 * Introduced in version 2.8 904 * 905 * Note: If ph is non-NULL, the client should notify 906 * when IO readiness events occur by calling 907 * fuse_lowelevel_notify_poll() with the specified ph. 908 * 909 * Regardless of the number of times poll with a non-NULL ph 910 * is received, single notification is enough to clear all. 911 * Notifying more times incurs overhead but doesn't harm 912 * correctness. 913 * 914 * The callee is responsible for destroying ph with 915 * fuse_pollhandle_destroy() when no longer in use. 916 * 917 * Valid replies: 918 * fuse_reply_poll 919 * fuse_reply_err 920 * 921 * @param req request handle 922 * @param ino the inode number 923 * @param fi file information 924 * @param ph poll handle to be used for notification 925 */ 926 void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, 927 struct fuse_pollhandle *ph); 928 929 /** 930 * Write data made available in a buffer 931 * 932 * This is a more generic version of the ->write() method. If 933 * FUSE_CAP_SPLICE_READ is set in fuse_conn_info.want and the 934 * kernel supports splicing from the fuse device, then the 935 * data will be made available in pipe for supporting zero 936 * copy data transfer. 937 * 938 * buf->count is guaranteed to be one (and thus buf->idx is 939 * always zero). The write_buf handler must ensure that 940 * bufv->off is correctly updated (reflecting the number of 941 * bytes read from bufv->buf[0]). 942 * 943 * Introduced in version 2.9 944 * 945 * Valid replies: 946 * fuse_reply_write 947 * fuse_reply_err 948 * 949 * @param req request handle 950 * @param ino the inode number 951 * @param bufv buffer containing the data 952 * @param off offset to write to 953 * @param fi file information 954 */ 955 void (*write_buf) (fuse_req_t req, fuse_ino_t ino, 956 struct fuse_bufvec *bufv, off_t off, 957 struct fuse_file_info *fi); 958 959 /** 960 * Callback function for the retrieve request 961 * 962 * Introduced in version 2.9 963 * 964 * Valid replies: 965 * fuse_reply_none 966 * 967 * @param req request handle 968 * @param cookie user data supplied to fuse_lowlevel_notify_retrieve() 969 * @param ino the inode number supplied to fuse_lowlevel_notify_retrieve() 970 * @param offset the offset supplied to fuse_lowlevel_notify_retrieve() 971 * @param bufv the buffer containing the returned data 972 */ 973 void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino, 974 off_t offset, struct fuse_bufvec *bufv); 975 976 /** 977 * Forget about multiple inodes 978 * 979 * See description of the forget function for more 980 * information. 981 * 982 * Introduced in version 2.9 983 * 984 * Valid replies: 985 * fuse_reply_none 986 * 987 * @param req request handle 988 */ 989 void (*forget_multi) (fuse_req_t req, size_t count, 990 struct fuse_forget_data *forgets); 991 992 /** 993 * Acquire, modify or release a BSD file lock 994 * 995 * Note: if the locking methods are not implemented, the kernel 996 * will still allow file locking to work locally. Hence these are 997 * only interesting for network filesystems and similar. 998 * 999 * Introduced in version 2.9 1000 * 1001 * Valid replies: 1002 * fuse_reply_err 1003 * 1004 * @param req request handle 1005 * @param ino the inode number 1006 * @param fi file information 1007 * @param op the locking operation, see flock(2) 1008 */ 1009 void (*flock) (fuse_req_t req, fuse_ino_t ino, 1010 struct fuse_file_info *fi, int op); 1011 1012 /** 1013 * Allocate requested space. If this function returns success then 1014 * subsequent writes to the specified range shall not fail due to the lack 1015 * of free space on the file system storage media. 1016 * 1017 * Introduced in version 2.9 1018 * 1019 * Valid replies: 1020 * fuse_reply_err 1021 * 1022 * @param req request handle 1023 * @param ino the inode number 1024 * @param offset starting point for allocated region 1025 * @param length size of allocated region 1026 * @param mode determines the operation to be performed on the given range, 1027 * see fallocate(2) 1028 */ 1029 void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode, 1030 off_t offset, off_t length, struct fuse_file_info *fi); 1031 }; 1032 1033 /** 1034 * Reply with an error code or success 1035 * 1036 * Possible requests: 1037 * all except forget 1038 * 1039 * unlink, rmdir, rename, flush, release, fsync, fsyncdir, setxattr, 1040 * removexattr and setlk may send a zero code 1041 * 1042 * @param req request handle 1043 * @param err the positive error value, or zero for success 1044 * @return zero for success, -errno for failure to send reply 1045 */ 1046 int fuse_reply_err(fuse_req_t req, int err); 1047 1048 /** 1049 * Don't send reply 1050 * 1051 * Possible requests: 1052 * forget 1053 * 1054 * @param req request handle 1055 */ 1056 void fuse_reply_none(fuse_req_t req); 1057 1058 /** 1059 * Reply with a directory entry 1060 * 1061 * Possible requests: 1062 * lookup, mknod, mkdir, symlink, link 1063 * 1064 * Side effects: 1065 * increments the lookup count on success 1066 * 1067 * @param req request handle 1068 * @param e the entry parameters 1069 * @return zero for success, -errno for failure to send reply 1070 */ 1071 int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e); 1072 1073 /** 1074 * Reply with a directory entry and open parameters 1075 * 1076 * currently the following members of 'fi' are used: 1077 * fh, direct_io, keep_cache 1078 * 1079 * Possible requests: 1080 * create 1081 * 1082 * Side effects: 1083 * increments the lookup count on success 1084 * 1085 * @param req request handle 1086 * @param e the entry parameters 1087 * @param fi file information 1088 * @return zero for success, -errno for failure to send reply 1089 */ 1090 int fuse_reply_create(fuse_req_t req, const struct fuse_entry_param *e, 1091 const struct fuse_file_info *fi); 1092 1093 /** 1094 * Reply with attributes 1095 * 1096 * Possible requests: 1097 * getattr, setattr 1098 * 1099 * @param req request handle 1100 * @param attr the attributes 1101 * @param attr_timeout validity timeout (in seconds) for the attributes 1102 * @return zero for success, -errno for failure to send reply 1103 */ 1104 int fuse_reply_attr(fuse_req_t req, const struct stat *attr, 1105 double attr_timeout); 1106 1107 /** 1108 * Reply with the contents of a symbolic link 1109 * 1110 * Possible requests: 1111 * readlink 1112 * 1113 * @param req request handle 1114 * @param link symbolic link contents 1115 * @return zero for success, -errno for failure to send reply 1116 */ 1117 int fuse_reply_readlink(fuse_req_t req, const char *link); 1118 1119 /** 1120 * Reply with open parameters 1121 * 1122 * currently the following members of 'fi' are used: 1123 * fh, direct_io, keep_cache 1124 * 1125 * Possible requests: 1126 * open, opendir 1127 * 1128 * @param req request handle 1129 * @param fi file information 1130 * @return zero for success, -errno for failure to send reply 1131 */ 1132 int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi); 1133 1134 /** 1135 * Reply with number of bytes written 1136 * 1137 * Possible requests: 1138 * write 1139 * 1140 * @param req request handle 1141 * @param count the number of bytes written 1142 * @return zero for success, -errno for failure to send reply 1143 */ 1144 int fuse_reply_write(fuse_req_t req, size_t count); 1145 1146 /** 1147 * Reply with data 1148 * 1149 * Possible requests: 1150 * read, readdir, getxattr, listxattr 1151 * 1152 * @param req request handle 1153 * @param buf buffer containing data 1154 * @param size the size of data in bytes 1155 * @return zero for success, -errno for failure to send reply 1156 */ 1157 int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size); 1158 1159 /** 1160 * Reply with data copied/moved from buffer(s) 1161 * 1162 * Possible requests: 1163 * read, readdir, getxattr, listxattr 1164 * 1165 * @param req request handle 1166 * @param bufv buffer vector 1167 * @param flags flags controlling the copy 1168 * @return zero for success, -errno for failure to send reply 1169 */ 1170 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv, 1171 enum fuse_buf_copy_flags flags); 1172 1173 /** 1174 * Reply with data vector 1175 * 1176 * Possible requests: 1177 * read, readdir, getxattr, listxattr 1178 * 1179 * @param req request handle 1180 * @param iov the vector containing the data 1181 * @param count the size of vector 1182 * @return zero for success, -errno for failure to send reply 1183 */ 1184 int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count); 1185 1186 /** 1187 * Reply with filesystem statistics 1188 * 1189 * Possible requests: 1190 * statfs 1191 * 1192 * @param req request handle 1193 * @param stbuf filesystem statistics 1194 * @return zero for success, -errno for failure to send reply 1195 */ 1196 int fuse_reply_statfs(fuse_req_t req, const struct statvfs *stbuf); 1197 1198 /** 1199 * Reply with needed buffer size 1200 * 1201 * Possible requests: 1202 * getxattr, listxattr 1203 * 1204 * @param req request handle 1205 * @param count the buffer size needed in bytes 1206 * @return zero for success, -errno for failure to send reply 1207 */ 1208 int fuse_reply_xattr(fuse_req_t req, size_t count); 1209 1210 /** 1211 * Reply with file lock information 1212 * 1213 * Possible requests: 1214 * getlk 1215 * 1216 * @param req request handle 1217 * @param lock the lock information 1218 * @return zero for success, -errno for failure to send reply 1219 */ 1220 int fuse_reply_lock(fuse_req_t req, const struct flock *lock); 1221 1222 /** 1223 * Reply with block index 1224 * 1225 * Possible requests: 1226 * bmap 1227 * 1228 * @param req request handle 1229 * @param idx block index within device 1230 * @return zero for success, -errno for failure to send reply 1231 */ 1232 int fuse_reply_bmap(fuse_req_t req, uint64_t idx); 1233 1234 /* ----------------------------------------------------------- * 1235 * Filling a buffer in readdir * 1236 * ----------------------------------------------------------- */ 1237 1238 /** 1239 * Add a directory entry to the buffer 1240 * 1241 * Buffer needs to be large enough to hold the entry. If it's not, 1242 * then the entry is not filled in but the size of the entry is still 1243 * returned. The caller can check this by comparing the bufsize 1244 * parameter with the returned entry size. If the entry size is 1245 * larger than the buffer size, the operation failed. 1246 * 1247 * From the 'stbuf' argument the st_ino field and bits 12-15 of the 1248 * st_mode field are used. The other fields are ignored. 1249 * 1250 * Note: offsets do not necessarily represent physical offsets, and 1251 * could be any marker, that enables the implementation to find a 1252 * specific point in the directory stream. 1253 * 1254 * @param req request handle 1255 * @param buf the point where the new entry will be added to the buffer 1256 * @param bufsize remaining size of the buffer 1257 * @param name the name of the entry 1258 * @param stbuf the file attributes 1259 * @param off the offset of the next entry 1260 * @return the space needed for the entry 1261 */ 1262 size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, 1263 const char *name, const struct stat *stbuf, 1264 off_t off); 1265 1266 /** 1267 * Reply to ask for data fetch and output buffer preparation. ioctl 1268 * will be retried with the specified input data fetched and output 1269 * buffer prepared. 1270 * 1271 * Possible requests: 1272 * ioctl 1273 * 1274 * @param req request handle 1275 * @param in_iov iovec specifying data to fetch from the caller 1276 * @param in_count number of entries in in_iov 1277 * @param out_iov iovec specifying addresses to write output to 1278 * @param out_count number of entries in out_iov 1279 * @return zero for success, -errno for failure to send reply 1280 */ 1281 int fuse_reply_ioctl_retry(fuse_req_t req, 1282 const struct iovec *in_iov, size_t in_count, 1283 const struct iovec *out_iov, size_t out_count); 1284 1285 /** 1286 * Reply to finish ioctl 1287 * 1288 * Possible requests: 1289 * ioctl 1290 * 1291 * @param req request handle 1292 * @param result result to be passed to the caller 1293 * @param buf buffer containing output data 1294 * @param size length of output data 1295 */ 1296 int fuse_reply_ioctl(fuse_req_t req, int result, const void *buf, size_t size); 1297 1298 /** 1299 * Reply to finish ioctl with iov buffer 1300 * 1301 * Possible requests: 1302 * ioctl 1303 * 1304 * @param req request handle 1305 * @param result result to be passed to the caller 1306 * @param iov the vector containing the data 1307 * @param count the size of vector 1308 */ 1309 int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, 1310 int count); 1311 1312 /** 1313 * Reply with poll result event mask 1314 * 1315 * @param req request handle 1316 * @param revents poll result event mask 1317 */ 1318 int fuse_reply_poll(fuse_req_t req, unsigned revents); 1319 1320 /* ----------------------------------------------------------- * 1321 * Notification * 1322 * ----------------------------------------------------------- */ 1323 1324 /** 1325 * Notify IO readiness event 1326 * 1327 * For more information, please read comment for poll operation. 1328 * 1329 * @param ph poll handle to notify IO readiness event for 1330 */ 1331 int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph); 1332 1333 /** 1334 * Notify to invalidate cache for an inode 1335 * 1336 * @param ch the channel through which to send the invalidation 1337 * @param ino the inode number 1338 * @param off the offset in the inode where to start invalidating 1339 * or negative to invalidate attributes only 1340 * @param len the amount of cache to invalidate or 0 for all 1341 * @return zero for success, -errno for failure 1342 */ 1343 int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino, 1344 off_t off, off_t len); 1345 1346 /** 1347 * Notify to invalidate parent attributes and the dentry matching 1348 * parent/name 1349 * 1350 * To avoid a deadlock don't call this function from a filesystem operation and 1351 * don't call it with a lock held that can also be held by a filesystem 1352 * operation. 1353 * 1354 * @param ch the channel through which to send the invalidation 1355 * @param parent inode number 1356 * @param name file name 1357 * @param namelen strlen() of file name 1358 * @return zero for success, -errno for failure 1359 */ 1360 int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent, 1361 const char *name, size_t namelen); 1362 1363 /** 1364 * Notify to invalidate parent attributes and delete the dentry matching 1365 * parent/name if the dentry's inode number matches child (otherwise it 1366 * will invalidate the matching dentry). 1367 * 1368 * To avoid a deadlock don't call this function from a filesystem operation and 1369 * don't call it with a lock held that can also be held by a filesystem 1370 * operation. 1371 * 1372 * @param ch the channel through which to send the notification 1373 * @param parent inode number 1374 * @param child inode number 1375 * @param name file name 1376 * @param namelen strlen() of file name 1377 * @return zero for success, -errno for failure 1378 */ 1379 int fuse_lowlevel_notify_delete(struct fuse_chan *ch, 1380 fuse_ino_t parent, fuse_ino_t child, 1381 const char *name, size_t namelen); 1382 1383 /** 1384 * Store data to the kernel buffers 1385 * 1386 * Synchronously store data in the kernel buffers belonging to the 1387 * given inode. The stored data is marked up-to-date (no read will be 1388 * performed against it, unless it's invalidated or evicted from the 1389 * cache). 1390 * 1391 * If the stored data overflows the current file size, then the size 1392 * is extended, similarly to a write(2) on the filesystem. 1393 * 1394 * If this function returns an error, then the store wasn't fully 1395 * completed, but it may have been partially completed. 1396 * 1397 * @param ch the channel through which to send the invalidation 1398 * @param ino the inode number 1399 * @param offset the starting offset into the file to store to 1400 * @param bufv buffer vector 1401 * @param flags flags controlling the copy 1402 * @return zero for success, -errno for failure 1403 */ 1404 int fuse_lowlevel_notify_store(struct fuse_chan *ch, fuse_ino_t ino, 1405 off_t offset, struct fuse_bufvec *bufv, 1406 enum fuse_buf_copy_flags flags); 1407 /** 1408 * Retrieve data from the kernel buffers 1409 * 1410 * Retrieve data in the kernel buffers belonging to the given inode. 1411 * If successful then the retrieve_reply() method will be called with 1412 * the returned data. 1413 * 1414 * Only present pages are returned in the retrieve reply. Retrieving 1415 * stops when it finds a non-present page and only data prior to that is 1416 * returned. 1417 * 1418 * If this function returns an error, then the retrieve will not be 1419 * completed and no reply will be sent. 1420 * 1421 * This function doesn't change the dirty state of pages in the kernel 1422 * buffer. For dirty pages the write() method will be called 1423 * regardless of having been retrieved previously. 1424 * 1425 * @param ch the channel through which to send the invalidation 1426 * @param ino the inode number 1427 * @param size the number of bytes to retrieve 1428 * @param offset the starting offset into the file to retrieve from 1429 * @param cookie user data to supply to the reply callback 1430 * @return zero for success, -errno for failure 1431 */ 1432 int fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, fuse_ino_t ino, 1433 size_t size, off_t offset, void *cookie); 1434 1435 1436 /* ----------------------------------------------------------- * 1437 * Utility functions * 1438 * ----------------------------------------------------------- */ 1439 1440 /** 1441 * Get the userdata from the request 1442 * 1443 * @param req request handle 1444 * @return the user data passed to fuse_lowlevel_new() 1445 */ 1446 void *fuse_req_userdata(fuse_req_t req); 1447 1448 /** 1449 * Get the context from the request 1450 * 1451 * The pointer returned by this function will only be valid for the 1452 * request's lifetime 1453 * 1454 * @param req request handle 1455 * @return the context structure 1456 */ 1457 const struct fuse_ctx *fuse_req_ctx(fuse_req_t req); 1458 1459 /** 1460 * Get the current supplementary group IDs for the specified request 1461 * 1462 * Similar to the getgroups(2) system call, except the return value is 1463 * always the total number of group IDs, even if it is larger than the 1464 * specified size. 1465 * 1466 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass 1467 * the group list to userspace, hence this function needs to parse 1468 * "/proc/$TID/task/$TID/status" to get the group IDs. 1469 * 1470 * This feature may not be supported on all operating systems. In 1471 * such a case this function will return -ENOSYS. 1472 * 1473 * @param req request handle 1474 * @param size size of given array 1475 * @param list array of group IDs to be filled in 1476 * @return the total number of supplementary group IDs or -errno on failure 1477 */ 1478 int fuse_req_getgroups(fuse_req_t req, int size, gid_t list[]); 1479 1480 /** 1481 * Callback function for an interrupt 1482 * 1483 * @param req interrupted request 1484 * @param data user data 1485 */ 1486 typedef void (*fuse_interrupt_func_t)(fuse_req_t req, void *data); 1487 1488 /** 1489 * Register/unregister callback for an interrupt 1490 * 1491 * If an interrupt has already happened, then the callback function is 1492 * called from within this function, hence it's not possible for 1493 * interrupts to be lost. 1494 * 1495 * @param req request handle 1496 * @param func the callback function or NULL for unregister 1497 * @param data user data passed to the callback function 1498 */ 1499 void fuse_req_interrupt_func(fuse_req_t req, fuse_interrupt_func_t func, 1500 void *data); 1501 1502 /** 1503 * Check if a request has already been interrupted 1504 * 1505 * @param req request handle 1506 * @return 1 if the request has been interrupted, 0 otherwise 1507 */ 1508 int fuse_req_interrupted(fuse_req_t req); 1509 1510 /* ----------------------------------------------------------- * 1511 * Filesystem setup * 1512 * ----------------------------------------------------------- */ 1513 1514 /* Deprecated, don't use */ 1515 int fuse_lowlevel_is_lib_option(const char *opt); 1516 1517 /** 1518 * Create a low level session 1519 * 1520 * @param args argument vector 1521 * @param op the low level filesystem operations 1522 * @param op_size sizeof(struct fuse_lowlevel_ops) 1523 * @param userdata user data 1524 * @return the created session object, or NULL on failure 1525 */ 1526 struct fuse_session *fuse_lowlevel_new(struct fuse_args *args, 1527 const struct fuse_lowlevel_ops *op, 1528 size_t op_size, void *userdata); 1529 1530 /* ----------------------------------------------------------- * 1531 * Session interface * 1532 * ----------------------------------------------------------- */ 1533 1534 /** 1535 * Session operations 1536 * 1537 * This is used in session creation 1538 */ 1539 struct fuse_session_ops { 1540 /** 1541 * Hook to process a request (mandatory) 1542 * 1543 * @param data user data passed to fuse_session_new() 1544 * @param buf buffer containing the raw request 1545 * @param len request length 1546 * @param ch channel on which the request was received 1547 */ 1548 void (*process) (void *data, const char *buf, size_t len, 1549 struct fuse_chan *ch); 1550 1551 /** 1552 * Hook for session exit and reset (optional) 1553 * 1554 * @param data user data passed to fuse_session_new() 1555 * @param val exited status (1 - exited, 0 - not exited) 1556 */ 1557 void (*exit) (void *data, int val); 1558 1559 /** 1560 * Hook for querying the current exited status (optional) 1561 * 1562 * @param data user data passed to fuse_session_new() 1563 * @return 1 if exited, 0 if not exited 1564 */ 1565 int (*exited) (void *data); 1566 1567 /** 1568 * Hook for cleaning up the channel on destroy (optional) 1569 * 1570 * @param data user data passed to fuse_session_new() 1571 */ 1572 void (*destroy) (void *data); 1573 }; 1574 1575 /** 1576 * Create a new session 1577 * 1578 * @param op session operations 1579 * @param data user data 1580 * @return new session object, or NULL on failure 1581 */ 1582 struct fuse_session *fuse_session_new(struct fuse_session_ops *op, void *data); 1583 1584 /** 1585 * Assign a channel to a session 1586 * 1587 * Note: currently only a single channel may be assigned. This may 1588 * change in the future 1589 * 1590 * If a session is destroyed, the assigned channel is also destroyed 1591 * 1592 * @param se the session 1593 * @param ch the channel 1594 */ 1595 void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch); 1596 1597 /** 1598 * Remove a channel from a session 1599 * 1600 * If the channel is not assigned to a session, then this is a no-op 1601 * 1602 * @param ch the channel to remove 1603 */ 1604 void fuse_session_remove_chan(struct fuse_chan *ch); 1605 1606 /** 1607 * Iterate over the channels assigned to a session 1608 * 1609 * The iterating function needs to start with a NULL channel, and 1610 * after that needs to pass the previously returned channel to the 1611 * function. 1612 * 1613 * @param se the session 1614 * @param ch the previous channel, or NULL 1615 * @return the next channel, or NULL if no more channels exist 1616 */ 1617 struct fuse_chan *fuse_session_next_chan(struct fuse_session *se, 1618 struct fuse_chan *ch); 1619 1620 /** 1621 * Process a raw request 1622 * 1623 * @param se the session 1624 * @param buf buffer containing the raw request 1625 * @param len request length 1626 * @param ch channel on which the request was received 1627 */ 1628 void fuse_session_process(struct fuse_session *se, const char *buf, size_t len, 1629 struct fuse_chan *ch); 1630 1631 /** 1632 * Process a raw request supplied in a generic buffer 1633 * 1634 * This is a more generic version of fuse_session_process(). The 1635 * fuse_buf may contain a memory buffer or a pipe file descriptor. 1636 * 1637 * @param se the session 1638 * @param buf the fuse_buf containing the request 1639 * @param ch channel on which the request was received 1640 */ 1641 void fuse_session_process_buf(struct fuse_session *se, 1642 const struct fuse_buf *buf, struct fuse_chan *ch); 1643 1644 /** 1645 * Receive a raw request supplied in a generic buffer 1646 * 1647 * This is a more generic version of fuse_chan_recv(). The fuse_buf 1648 * supplied to this function contains a suitably allocated memory 1649 * buffer. This may be overwritten with a file descriptor buffer. 1650 * 1651 * @param se the session 1652 * @param buf the fuse_buf to store the request in 1653 * @param chp pointer to the channel 1654 * @return the actual size of the raw request, or -errno on error 1655 */ 1656 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf, 1657 struct fuse_chan **chp); 1658 1659 /** 1660 * Destroy a session 1661 * 1662 * @param se the session 1663 */ 1664 void fuse_session_destroy(struct fuse_session *se); 1665 1666 /** 1667 * Exit a session 1668 * 1669 * @param se the session 1670 */ 1671 void fuse_session_exit(struct fuse_session *se); 1672 1673 /** 1674 * Reset the exited status of a session 1675 * 1676 * @param se the session 1677 */ 1678 void fuse_session_reset(struct fuse_session *se); 1679 1680 /** 1681 * Query the exited status of a session 1682 * 1683 * @param se the session 1684 * @return 1 if exited, 0 if not exited 1685 */ 1686 int fuse_session_exited(struct fuse_session *se); 1687 1688 /** 1689 * Get the user data provided to the session 1690 * 1691 * @param se the session 1692 * @return the user data 1693 */ 1694 void *fuse_session_data(struct fuse_session *se); 1695 1696 /** 1697 * Enter a single threaded event loop 1698 * 1699 * @param se the session 1700 * @return 0 on success, -1 on error 1701 */ 1702 int fuse_session_loop(struct fuse_session *se); 1703 1704 /** 1705 * Enter a multi-threaded event loop 1706 * 1707 * @param se the session 1708 * @return 0 on success, -1 on error 1709 */ 1710 int fuse_session_loop_mt(struct fuse_session *se); 1711 1712 /* ----------------------------------------------------------- * 1713 * Channel interface * 1714 * ----------------------------------------------------------- */ 1715 1716 /** 1717 * Channel operations 1718 * 1719 * This is used in channel creation 1720 */ 1721 struct fuse_chan_ops { 1722 /** 1723 * Hook for receiving a raw request 1724 * 1725 * @param ch pointer to the channel 1726 * @param buf the buffer to store the request in 1727 * @param size the size of the buffer 1728 * @return the actual size of the raw request, or -1 on error 1729 */ 1730 int (*receive)(struct fuse_chan **chp, char *buf, size_t size); 1731 1732 /** 1733 * Hook for sending a raw reply 1734 * 1735 * A return value of -ENOENT means, that the request was 1736 * interrupted, and the reply was discarded 1737 * 1738 * @param ch the channel 1739 * @param iov vector of blocks 1740 * @param count the number of blocks in vector 1741 * @return zero on success, -errno on failure 1742 */ 1743 int (*send)(struct fuse_chan *ch, const struct iovec iov[], 1744 size_t count); 1745 1746 /** 1747 * Destroy the channel 1748 * 1749 * @param ch the channel 1750 */ 1751 void (*destroy)(struct fuse_chan *ch); 1752 }; 1753 1754 /** 1755 * Create a new channel 1756 * 1757 * @param op channel operations 1758 * @param fd file descriptor of the channel 1759 * @param bufsize the minimal receive buffer size 1760 * @param data user data 1761 * @return the new channel object, or NULL on failure 1762 */ 1763 struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd, 1764 size_t bufsize, void *data); 1765 1766 /** 1767 * Query the file descriptor of the channel 1768 * 1769 * @param ch the channel 1770 * @return the file descriptor passed to fuse_chan_new() 1771 */ 1772 int fuse_chan_fd(struct fuse_chan *ch); 1773 1774 /** 1775 * Query the minimal receive buffer size 1776 * 1777 * @param ch the channel 1778 * @return the buffer size passed to fuse_chan_new() 1779 */ 1780 size_t fuse_chan_bufsize(struct fuse_chan *ch); 1781 1782 /** 1783 * Query the user data 1784 * 1785 * @param ch the channel 1786 * @return the user data passed to fuse_chan_new() 1787 */ 1788 void *fuse_chan_data(struct fuse_chan *ch); 1789 1790 /** 1791 * Query the session to which this channel is assigned 1792 * 1793 * @param ch the channel 1794 * @return the session, or NULL if the channel is not assigned 1795 */ 1796 struct fuse_session *fuse_chan_session(struct fuse_chan *ch); 1797 1798 /** 1799 * Receive a raw request 1800 * 1801 * A return value of -ENODEV means, that the filesystem was unmounted 1802 * 1803 * @param ch pointer to the channel 1804 * @param buf the buffer to store the request in 1805 * @param size the size of the buffer 1806 * @return the actual size of the raw request, or -errno on error 1807 */ 1808 int fuse_chan_recv(struct fuse_chan **ch, char *buf, size_t size); 1809 1810 /** 1811 * Send a raw reply 1812 * 1813 * A return value of -ENOENT means, that the request was 1814 * interrupted, and the reply was discarded 1815 * 1816 * @param ch the channel 1817 * @param iov vector of blocks 1818 * @param count the number of blocks in vector 1819 * @return zero on success, -errno on failure 1820 */ 1821 int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[], 1822 size_t count); 1823 1824 /** 1825 * Destroy a channel 1826 * 1827 * @param ch the channel 1828 */ 1829 void fuse_chan_destroy(struct fuse_chan *ch); 1830 1831 /* ----------------------------------------------------------- * 1832 * Compatibility stuff * 1833 * ----------------------------------------------------------- */ 1834 1835 #if FUSE_USE_VERSION < 26 1836 # include "fuse_lowlevel_compat.h" 1837 # define fuse_chan_ops fuse_chan_ops_compat24 1838 # define fuse_chan_new fuse_chan_new_compat24 1839 # if FUSE_USE_VERSION == 25 1840 # define fuse_lowlevel_ops fuse_lowlevel_ops_compat25 1841 # define fuse_lowlevel_new fuse_lowlevel_new_compat25 1842 # elif FUSE_USE_VERSION == 24 1843 # define fuse_lowlevel_ops fuse_lowlevel_ops_compat 1844 # define fuse_lowlevel_new fuse_lowlevel_new_compat 1845 # define fuse_file_info fuse_file_info_compat 1846 # define fuse_reply_statfs fuse_reply_statfs_compat 1847 # define fuse_reply_open fuse_reply_open_compat 1848 # else 1849 # error Compatibility with low-level API version < 24 not supported 1850 # endif 1851 #endif 1852 1853 #ifdef __cplusplus 1854 } 1855 #endif 1856 1857 #endif /* _FUSE_LOWLEVEL_H_ */ 1858