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_H_ 10 #define _FUSE_H_ 11 12 /** @file 13 * 14 * This file defines the library interface of FUSE 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 21 (default) 22 19 * or 25, to use the even older 1.X API define it to 11. 20 */ 21 22 #ifndef FUSE_USE_VERSION 23 #define FUSE_USE_VERSION 21 24 #endif 25 26 #include "fuse_common.h" 27 28 #include <fcntl.h> 29 #include <time.h> 30 #include <utime.h> 31 #include <sys/types.h> 32 #include <sys/stat.h> 33 #include <sys/statvfs.h> 34 #include <sys/uio.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 41 /* ----------------------------------------------------------- * 42 * Basic FUSE API * 43 * ----------------------------------------------------------- */ 44 45 /** Handle for a FUSE filesystem */ 46 struct fuse; 47 48 /** Structure containing a raw command */ 49 struct fuse_cmd; 50 51 /** Function to add an entry in a readdir() operation 52 * 53 * @param buf the buffer passed to the readdir() operation 54 * @param name the file name of the directory entry 55 * @param stat file attributes, can be NULL 56 * @param off offset of the next entry or zero 57 * @return 1 if buffer is full, zero otherwise 58 */ 59 typedef int (*fuse_fill_dir_t) (void *buf, const char *name, 60 const struct stat *stbuf, off_t off); 61 62 /* Used by deprecated getdir() method */ 63 typedef struct fuse_dirhandle *fuse_dirh_t; 64 typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type, 65 ino_t ino); 66 67 /** 68 * The file system operations: 69 * 70 * Most of these should work very similarly to the well known UNIX 71 * file system operations. A major exception is that instead of 72 * returning an error in 'errno', the operation should return the 73 * negated error value (-errno) directly. 74 * 75 * All methods are optional, but some are essential for a useful 76 * filesystem (e.g. getattr). Open, flush, release, fsync, opendir, 77 * releasedir, fsyncdir, access, create, ftruncate, fgetattr, lock, 78 * init and destroy are special purpose methods, without which a full 79 * featured filesystem can still be implemented. 80 * 81 * Almost all operations take a path which can be of any length. 82 * 83 * Changed in fuse 2.8.0 (regardless of API version) 84 * Previously, paths were limited to a length of PATH_MAX. 85 * 86 * See http://fuse.sourceforge.net/wiki/ for more information. There 87 * is also a snapshot of the relevant wiki pages in the doc/ folder. 88 */ 89 struct fuse_operations { 90 /** Get file attributes. 91 * 92 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are 93 * ignored. The 'st_ino' field is ignored except if the 'use_ino' 94 * mount option is given. 95 */ 96 int (*getattr) (const char *, struct stat *); 97 98 /** Read the target of a symbolic link 99 * 100 * The buffer should be filled with a null terminated string. The 101 * buffer size argument includes the space for the terminating 102 * null character. If the linkname is too long to fit in the 103 * buffer, it should be truncated. The return value should be 0 104 * for success. 105 */ 106 int (*readlink) (const char *, char *, size_t); 107 108 /* Deprecated, use readdir() instead */ 109 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t); 110 111 /** Create a file node 112 * 113 * This is called for creation of all non-directory, non-symlink 114 * nodes. If the filesystem defines a create() method, then for 115 * regular files that will be called instead. 116 */ 117 int (*mknod) (const char *, mode_t, dev_t); 118 119 /** Create a directory 120 * 121 * Note that the mode argument may not have the type specification 122 * bits set, i.e. S_ISDIR(mode) can be false. To obtain the 123 * correct directory type bits use mode|S_IFDIR 124 * */ 125 int (*mkdir) (const char *, mode_t); 126 127 /** Remove a file */ 128 int (*unlink) (const char *); 129 130 /** Remove a directory */ 131 int (*rmdir) (const char *); 132 133 /** Create a symbolic link */ 134 int (*symlink) (const char *, const char *); 135 136 /** Rename a file */ 137 int (*rename) (const char *, const char *); 138 139 /** Create a hard link to a file */ 140 int (*link) (const char *, const char *); 141 142 /** Change the permission bits of a file */ 143 int (*chmod) (const char *, mode_t); 144 145 /** Change the owner and group of a file */ 146 int (*chown) (const char *, uid_t, gid_t); 147 148 /** Change the size of a file */ 149 int (*truncate) (const char *, off_t); 150 151 /** Change the access and/or modification times of a file 152 * 153 * Deprecated, use utimens() instead. 154 */ 155 int (*utime) (const char *, struct utimbuf *); 156 157 /** File open operation 158 * 159 * No creation (O_CREAT, O_EXCL) and by default also no 160 * truncation (O_TRUNC) flags will be passed to open(). If an 161 * application specifies O_TRUNC, fuse first calls truncate() 162 * and then open(). Only if 'atomic_o_trunc' has been 163 * specified and kernel version is 2.6.24 or later, O_TRUNC is 164 * passed on to open. 165 * 166 * Unless the 'default_permissions' mount option is given, 167 * open should check if the operation is permitted for the 168 * given flags. Optionally open may also return an arbitrary 169 * filehandle in the fuse_file_info structure, which will be 170 * passed to all file operations. 171 * 172 * Changed in version 2.2 173 */ 174 int (*open) (const char *, struct fuse_file_info *); 175 176 /** Read data from an open file 177 * 178 * Read should return exactly the number of bytes requested except 179 * on EOF or error, otherwise the rest of the data will be 180 * substituted with zeroes. An exception to this is when the 181 * 'direct_io' mount option is specified, in which case the return 182 * value of the read system call will reflect the return value of 183 * this operation. 184 * 185 * Changed in version 2.2 186 */ 187 int (*read) (const char *, char *, size_t, off_t, 188 struct fuse_file_info *); 189 190 /** Write data to an open file 191 * 192 * Write should return exactly the number of bytes requested 193 * except on error. An exception to this is when the 'direct_io' 194 * mount option is specified (see read operation). 195 * 196 * Changed in version 2.2 197 */ 198 int (*write) (const char *, const char *, size_t, off_t, 199 struct fuse_file_info *); 200 201 /** Get file system statistics 202 * 203 * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored 204 * 205 * Replaced 'struct statfs' parameter with 'struct statvfs' in 206 * version 2.5 207 */ 208 int (*statfs) (const char *, struct statvfs *); 209 210 /** Possibly flush cached data 211 * 212 * BIG NOTE: This is not equivalent to fsync(). It's not a 213 * request to sync dirty data. 214 * 215 * Flush is called on each close() of a file descriptor. So if a 216 * filesystem wants to return write errors in close() and the file 217 * has cached dirty data, this is a good place to write back data 218 * and return any errors. Since many applications ignore close() 219 * errors this is not always useful. 220 * 221 * NOTE: The flush() method may be called more than once for each 222 * open(). This happens if more than one file descriptor refers 223 * to an opened file due to dup(), dup2() or fork() calls. It is 224 * not possible to determine if a flush is final, so each flush 225 * should be treated equally. Multiple write-flush sequences are 226 * relatively rare, so this shouldn't be a problem. 227 * 228 * Filesystems shouldn't assume that flush will always be called 229 * after some writes, or that if will be called at all. 230 * 231 * Changed in version 2.2 232 */ 233 int (*flush) (const char *, struct fuse_file_info *); 234 235 /** Release an open file 236 * 237 * Release is called when there are no more references to an open 238 * file: all file descriptors are closed and all memory mappings 239 * are unmapped. 240 * 241 * For every open() call there will be exactly one release() call 242 * with the same flags and file descriptor. It is possible to 243 * have a file opened more than once, in which case only the last 244 * release will mean, that no more reads/writes will happen on the 245 * file. The return value of release is ignored. 246 * 247 * Changed in version 2.2 248 */ 249 int (*release) (const char *, struct fuse_file_info *); 250 251 /** Synchronize file contents 252 * 253 * If the datasync parameter is non-zero, then only the user data 254 * should be flushed, not the meta data. 255 * 256 * Changed in version 2.2 257 */ 258 int (*fsync) (const char *, int, struct fuse_file_info *); 259 260 /** Set extended attributes */ 261 int (*setxattr) (const char *, const char *, const char *, size_t, int); 262 263 /** Get extended attributes */ 264 int (*getxattr) (const char *, const char *, char *, size_t); 265 266 /** List extended attributes */ 267 int (*listxattr) (const char *, char *, size_t); 268 269 /** Remove extended attributes */ 270 int (*removexattr) (const char *, const char *); 271 272 /** Open directory 273 * 274 * Unless the 'default_permissions' mount option is given, 275 * this method should check if opendir is permitted for this 276 * directory. Optionally opendir may also return an arbitrary 277 * filehandle in the fuse_file_info structure, which will be 278 * passed to readdir, releasedir and fsyncdir. 279 * 280 * Introduced in version 2.3 281 */ 282 int (*opendir) (const char *, struct fuse_file_info *); 283 284 /** Read directory 285 * 286 * This supersedes the old getdir() interface. New applications 287 * should use this. 288 * 289 * The filesystem may choose between two modes of operation: 290 * 291 * 1) The readdir implementation ignores the offset parameter, and 292 * passes zero to the filler function's offset. The filler 293 * function will not return '1' (unless an error happens), so the 294 * whole directory is read in a single readdir operation. This 295 * works just like the old getdir() method. 296 * 297 * 2) The readdir implementation keeps track of the offsets of the 298 * directory entries. It uses the offset parameter and always 299 * passes non-zero offset to the filler function. When the buffer 300 * is full (or an error happens) the filler function will return 301 * '1'. 302 * 303 * Introduced in version 2.3 304 */ 305 int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t, 306 struct fuse_file_info *); 307 308 /** Release directory 309 * 310 * Introduced in version 2.3 311 */ 312 int (*releasedir) (const char *, struct fuse_file_info *); 313 314 /** Synchronize directory contents 315 * 316 * If the datasync parameter is non-zero, then only the user data 317 * should be flushed, not the meta data 318 * 319 * Introduced in version 2.3 320 */ 321 int (*fsyncdir) (const char *, int, struct fuse_file_info *); 322 323 /** 324 * Initialize filesystem 325 * 326 * The return value will passed in the private_data field of 327 * fuse_context to all file operations and as a parameter to the 328 * destroy() method. 329 * 330 * Introduced in version 2.3 331 * Changed in version 2.6 332 */ 333 void *(*init) (struct fuse_conn_info *conn); 334 335 /** 336 * Clean up filesystem 337 * 338 * Called on filesystem exit. 339 * 340 * Introduced in version 2.3 341 */ 342 void (*destroy) (void *); 343 344 /** 345 * Check file access permissions 346 * 347 * This will be called for the access() system call. If the 348 * 'default_permissions' mount option is given, this method is not 349 * called. 350 * 351 * This method is not called under Linux kernel versions 2.4.x 352 * 353 * Introduced in version 2.5 354 */ 355 int (*access) (const char *, int); 356 357 /** 358 * Create and open a file 359 * 360 * If the file does not exist, first create it with the specified 361 * mode, and then open it. 362 * 363 * If this method is not implemented or under Linux kernel 364 * versions earlier than 2.6.15, the mknod() and open() methods 365 * will be called instead. 366 * 367 * Introduced in version 2.5 368 */ 369 int (*create) (const char *, mode_t, struct fuse_file_info *); 370 371 /** 372 * Change the size of an open file 373 * 374 * This method is called instead of the truncate() method if the 375 * truncation was invoked from an ftruncate() system call. 376 * 377 * If this method is not implemented or under Linux kernel 378 * versions earlier than 2.6.15, the truncate() method will be 379 * called instead. 380 * 381 * Introduced in version 2.5 382 */ 383 int (*ftruncate) (const char *, off_t, struct fuse_file_info *); 384 385 /** 386 * Get attributes from an open file 387 * 388 * This method is called instead of the getattr() method if the 389 * file information is available. 390 * 391 * Currently this is only called after the create() method if that 392 * is implemented (see above). Later it may be called for 393 * invocations of fstat() too. 394 * 395 * Introduced in version 2.5 396 */ 397 int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *); 398 399 /** 400 * Perform POSIX file locking operation 401 * 402 * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW. 403 * 404 * For the meaning of fields in 'struct flock' see the man page 405 * for fcntl(2). The l_whence field will always be set to 406 * SEEK_SET. 407 * 408 * For checking lock ownership, the 'fuse_file_info->owner' 409 * argument must be used. 410 * 411 * For F_GETLK operation, the library will first check currently 412 * held locks, and if a conflicting lock is found it will return 413 * information without calling this method. This ensures, that 414 * for local locks the l_pid field is correctly filled in. The 415 * results may not be accurate in case of race conditions and in 416 * the presence of hard links, but it's unlikely that an 417 * application would rely on accurate GETLK results in these 418 * cases. If a conflicting lock is not found, this method will be 419 * called, and the filesystem may fill out l_pid by a meaningful 420 * value, or it may leave this field zero. 421 * 422 * For F_SETLK and F_SETLKW the l_pid field will be set to the pid 423 * of the process performing the locking operation. 424 * 425 * Note: if this method is not implemented, the kernel will still 426 * allow file locking to work locally. Hence it is only 427 * interesting for network filesystems and similar. 428 * 429 * Introduced in version 2.6 430 */ 431 int (*lock) (const char *, struct fuse_file_info *, int cmd, 432 struct flock *); 433 434 /** 435 * Change the access and modification times of a file with 436 * nanosecond resolution 437 * 438 * This supersedes the old utime() interface. New applications 439 * should use this. 440 * 441 * See the utimensat(2) man page for details. 442 * 443 * Introduced in version 2.6 444 */ 445 int (*utimens) (const char *, const struct timespec tv[2]); 446 447 /** 448 * Map block index within file to block index within device 449 * 450 * Note: This makes sense only for block device backed filesystems 451 * mounted with the 'blkdev' option 452 * 453 * Introduced in version 2.6 454 */ 455 int (*bmap) (const char *, size_t blocksize, uint64_t *idx); 456 457 /** 458 * Flag indicating that the filesystem can accept a NULL path 459 * as the first argument for the following operations: 460 * 461 * read, write, flush, release, fsync, readdir, releasedir, 462 * fsyncdir, ftruncate, fgetattr, lock, ioctl and poll 463 * 464 * If this flag is set these operations continue to work on 465 * unlinked files even if "-ohard_remove" option was specified. 466 */ 467 unsigned int flag_nullpath_ok:1; 468 469 /** 470 * Flag indicating that the path need not be calculated for 471 * the following operations: 472 * 473 * read, write, flush, release, fsync, readdir, releasedir, 474 * fsyncdir, ftruncate, fgetattr, lock, ioctl and poll 475 * 476 * Closely related to flag_nullpath_ok, but if this flag is 477 * set then the path will not be calculaged even if the file 478 * wasn't unlinked. However the path can still be non-NULL if 479 * it needs to be calculated for some other reason. 480 */ 481 unsigned int flag_nopath:1; 482 483 /** 484 * Flag indicating that the filesystem accepts special 485 * UTIME_NOW and UTIME_OMIT values in its utimens operation. 486 */ 487 unsigned int flag_utime_omit_ok:1; 488 489 /** 490 * Reserved flags, don't set 491 */ 492 unsigned int flag_reserved:29; 493 494 /** 495 * Ioctl 496 * 497 * flags will have FUSE_IOCTL_COMPAT set for 32bit ioctls in 498 * 64bit environment. The size and direction of data is 499 * determined by _IOC_*() decoding of cmd. For _IOC_NONE, 500 * data will be NULL, for _IOC_WRITE data is out area, for 501 * _IOC_READ in area and if both are set in/out area. In all 502 * non-NULL cases, the area is of _IOC_SIZE(cmd) bytes. 503 * 504 * If flags has FUSE_IOCTL_DIR then the fuse_file_info refers to a 505 * directory file handle. 506 * 507 * Introduced in version 2.8 508 */ 509 int (*ioctl) (const char *, int cmd, void *arg, 510 struct fuse_file_info *, unsigned int flags, void *data); 511 512 /** 513 * Poll for IO readiness events 514 * 515 * Note: If ph is non-NULL, the client should notify 516 * when IO readiness events occur by calling 517 * fuse_notify_poll() with the specified ph. 518 * 519 * Regardless of the number of times poll with a non-NULL ph 520 * is received, single notification is enough to clear all. 521 * Notifying more times incurs overhead but doesn't harm 522 * correctness. 523 * 524 * The callee is responsible for destroying ph with 525 * fuse_pollhandle_destroy() when no longer in use. 526 * 527 * Introduced in version 2.8 528 */ 529 int (*poll) (const char *, struct fuse_file_info *, 530 struct fuse_pollhandle *ph, unsigned *reventsp); 531 532 /** Write contents of buffer to an open file 533 * 534 * Similar to the write() method, but data is supplied in a 535 * generic buffer. Use fuse_buf_copy() to transfer data to 536 * the destination. 537 * 538 * Introduced in version 2.9 539 */ 540 int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off, 541 struct fuse_file_info *); 542 543 /** Store data from an open file in a buffer 544 * 545 * Similar to the read() method, but data is stored and 546 * returned in a generic buffer. 547 * 548 * No actual copying of data has to take place, the source 549 * file descriptor may simply be stored in the buffer for 550 * later data transfer. 551 * 552 * The buffer must be allocated dynamically and stored at the 553 * location pointed to by bufp. If the buffer contains memory 554 * regions, they too must be allocated using malloc(). The 555 * allocated memory will be freed by the caller. 556 * 557 * Introduced in version 2.9 558 */ 559 int (*read_buf) (const char *, struct fuse_bufvec **bufp, 560 size_t size, off_t off, struct fuse_file_info *); 561 /** 562 * Perform BSD file locking operation 563 * 564 * The op argument will be either LOCK_SH, LOCK_EX or LOCK_UN 565 * 566 * Nonblocking requests will be indicated by ORing LOCK_NB to 567 * the above operations 568 * 569 * For more information see the flock(2) manual page. 570 * 571 * Additionally fi->owner will be set to a value unique to 572 * this open file. This same value will be supplied to 573 * ->release() when the file is released. 574 * 575 * Note: if this method is not implemented, the kernel will still 576 * allow file locking to work locally. Hence it is only 577 * interesting for network filesystems and similar. 578 * 579 * Introduced in version 2.9 580 */ 581 int (*flock) (const char *, struct fuse_file_info *, int op); 582 583 /** 584 * Allocates space for an open file 585 * 586 * This function ensures that required space is allocated for specified 587 * file. If this function returns success then any subsequent write 588 * request to specified range is guaranteed not to fail because of lack 589 * of space on the file system media. 590 * 591 * Introduced in version 2.9.1 592 */ 593 int (*fallocate) (const char *, int, off_t, off_t, 594 struct fuse_file_info *); 595 }; 596 597 /** Extra context that may be needed by some filesystems 598 * 599 * The uid, gid and pid fields are not filled in case of a writepage 600 * operation. 601 */ 602 struct fuse_context { 603 /** Pointer to the fuse object */ 604 struct fuse *fuse; 605 606 /** User ID of the calling process */ 607 uid_t uid; 608 609 /** Group ID of the calling process */ 610 gid_t gid; 611 612 /** Thread ID of the calling process */ 613 pid_t pid; 614 615 /** Private filesystem data */ 616 void *private_data; 617 618 /** Umask of the calling process (introduced in version 2.8) */ 619 mode_t umask; 620 }; 621 622 /** 623 * Main function of FUSE. 624 * 625 * This is for the lazy. This is all that has to be called from the 626 * main() function. 627 * 628 * This function does the following: 629 * - parses command line options (-d -s and -h) 630 * - passes relevant mount options to the fuse_mount() 631 * - installs signal handlers for INT, HUP, TERM and PIPE 632 * - registers an exit handler to unmount the filesystem on program exit 633 * - creates a fuse handle 634 * - registers the operations 635 * - calls either the single-threaded or the multi-threaded event loop 636 * 637 * Note: this is currently implemented as a macro. 638 * 639 * @param argc the argument counter passed to the main() function 640 * @param argv the argument vector passed to the main() function 641 * @param op the file system operation 642 * @param user_data user data supplied in the context during the init() method 643 * @return 0 on success, nonzero on failure 644 */ 645 /* 646 int fuse_main(int argc, char *argv[], const struct fuse_operations *op, 647 void *user_data); 648 */ 649 #define fuse_main(argc, argv, op, user_data) \ 650 fuse_main_real(argc, argv, op, sizeof(*(op)), user_data) 651 652 /* ----------------------------------------------------------- * 653 * More detailed API * 654 * ----------------------------------------------------------- */ 655 656 /** 657 * Create a new FUSE filesystem. 658 * 659 * @param ch the communication channel 660 * @param args argument vector 661 * @param op the filesystem operations 662 * @param op_size the size of the fuse_operations structure 663 * @param user_data user data supplied in the context during the init() method 664 * @return the created FUSE handle 665 */ 666 struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args, 667 const struct fuse_operations *op, size_t op_size, 668 void *user_data); 669 670 /** 671 * Destroy the FUSE handle. 672 * 673 * The communication channel attached to the handle is also destroyed. 674 * 675 * NOTE: This function does not unmount the filesystem. If this is 676 * needed, call fuse_unmount() before calling this function. 677 * 678 * @param f the FUSE handle 679 */ 680 void fuse_destroy(struct fuse *f); 681 682 /** 683 * FUSE event loop. 684 * 685 * Requests from the kernel are processed, and the appropriate 686 * operations are called. 687 * 688 * @param f the FUSE handle 689 * @return 0 if no error occurred, -1 otherwise 690 */ 691 int fuse_loop(struct fuse *f); 692 693 /** 694 * Exit from event loop 695 * 696 * @param f the FUSE handle 697 */ 698 void fuse_exit(struct fuse *f); 699 700 /** 701 * FUSE event loop with multiple threads 702 * 703 * Requests from the kernel are processed, and the appropriate 704 * operations are called. Request are processed in parallel by 705 * distributing them between multiple threads. 706 * 707 * Calling this function requires the pthreads library to be linked to 708 * the application. 709 * 710 * @param f the FUSE handle 711 * @return 0 if no error occurred, -1 otherwise 712 */ 713 int fuse_loop_mt(struct fuse *f); 714 715 /** 716 * Get the current context 717 * 718 * The context is only valid for the duration of a filesystem 719 * operation, and thus must not be stored and used later. 720 * 721 * @return the context 722 */ 723 struct fuse_context *fuse_get_context(void); 724 725 /** 726 * Get the current supplementary group IDs for the current request 727 * 728 * Similar to the getgroups(2) system call, except the return value is 729 * always the total number of group IDs, even if it is larger than the 730 * specified size. 731 * 732 * The current fuse kernel module in linux (as of 2.6.30) doesn't pass 733 * the group list to userspace, hence this function needs to parse 734 * "/proc/$TID/task/$TID/status" to get the group IDs. 735 * 736 * This feature may not be supported on all operating systems. In 737 * such a case this function will return -ENOSYS. 738 * 739 * @param size size of given array 740 * @param list array of group IDs to be filled in 741 * @return the total number of supplementary group IDs or -errno on failure 742 */ 743 int fuse_getgroups(int size, gid_t list[]); 744 745 /** 746 * Check if the current request has already been interrupted 747 * 748 * @return 1 if the request has been interrupted, 0 otherwise 749 */ 750 int fuse_interrupted(void); 751 752 /** 753 * Obsolete, doesn't do anything 754 * 755 * @return -EINVAL 756 */ 757 int fuse_invalidate(struct fuse *f, const char *path); 758 759 /* Deprecated, don't use */ 760 int fuse_is_lib_option(const char *opt); 761 762 /** 763 * The real main function 764 * 765 * Do not call this directly, use fuse_main() 766 */ 767 int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, 768 size_t op_size, void *user_data); 769 770 /** 771 * Start the cleanup thread when using option "remember". 772 * 773 * This is done automatically by fuse_loop_mt() 774 * @param fuse struct fuse pointer for fuse instance 775 * @return 0 on success and -1 on error 776 */ 777 int fuse_start_cleanup_thread(struct fuse *fuse); 778 779 /** 780 * Stop the cleanup thread when using option "remember". 781 * 782 * This is done automatically by fuse_loop_mt() 783 * @param fuse struct fuse pointer for fuse instance 784 */ 785 void fuse_stop_cleanup_thread(struct fuse *fuse); 786 787 /** 788 * Iterate over cache removing stale entries 789 * use in conjunction with "-oremember" 790 * 791 * NOTE: This is already done for the standard sessions 792 * 793 * @param fuse struct fuse pointer for fuse instance 794 * @return the number of seconds until the next cleanup 795 */ 796 int fuse_clean_cache(struct fuse *fuse); 797 798 /* 799 * Stacking API 800 */ 801 802 /** 803 * Fuse filesystem object 804 * 805 * This is opaque object represents a filesystem layer 806 */ 807 struct fuse_fs; 808 809 /* 810 * These functions call the relevant filesystem operation, and return 811 * the result. 812 * 813 * If the operation is not defined, they return -ENOSYS, with the 814 * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir, 815 * fuse_fs_releasedir and fuse_fs_statfs, which return 0. 816 */ 817 818 int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf); 819 int fuse_fs_fgetattr(struct fuse_fs *fs, const char *path, struct stat *buf, 820 struct fuse_file_info *fi); 821 int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath, 822 const char *newpath); 823 int fuse_fs_unlink(struct fuse_fs *fs, const char *path); 824 int fuse_fs_rmdir(struct fuse_fs *fs, const char *path); 825 int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname, 826 const char *path); 827 int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath); 828 int fuse_fs_release(struct fuse_fs *fs, const char *path, 829 struct fuse_file_info *fi); 830 int fuse_fs_open(struct fuse_fs *fs, const char *path, 831 struct fuse_file_info *fi); 832 int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size, 833 off_t off, struct fuse_file_info *fi); 834 int fuse_fs_read_buf(struct fuse_fs *fs, const char *path, 835 struct fuse_bufvec **bufp, size_t size, off_t off, 836 struct fuse_file_info *fi); 837 int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf, 838 size_t size, off_t off, struct fuse_file_info *fi); 839 int fuse_fs_write_buf(struct fuse_fs *fs, const char *path, 840 struct fuse_bufvec *buf, off_t off, 841 struct fuse_file_info *fi); 842 int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync, 843 struct fuse_file_info *fi); 844 int fuse_fs_flush(struct fuse_fs *fs, const char *path, 845 struct fuse_file_info *fi); 846 int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf); 847 int fuse_fs_opendir(struct fuse_fs *fs, const char *path, 848 struct fuse_file_info *fi); 849 int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf, 850 fuse_fill_dir_t filler, off_t off, 851 struct fuse_file_info *fi); 852 int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync, 853 struct fuse_file_info *fi); 854 int fuse_fs_releasedir(struct fuse_fs *fs, const char *path, 855 struct fuse_file_info *fi); 856 int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode, 857 struct fuse_file_info *fi); 858 int fuse_fs_lock(struct fuse_fs *fs, const char *path, 859 struct fuse_file_info *fi, int cmd, struct flock *lock); 860 int fuse_fs_flock(struct fuse_fs *fs, const char *path, 861 struct fuse_file_info *fi, int op); 862 int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode); 863 int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid); 864 int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size); 865 int fuse_fs_ftruncate(struct fuse_fs *fs, const char *path, off_t size, 866 struct fuse_file_info *fi); 867 int fuse_fs_utimens(struct fuse_fs *fs, const char *path, 868 const struct timespec tv[2]); 869 int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask); 870 int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf, 871 size_t len); 872 int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode, 873 dev_t rdev); 874 int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode); 875 int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name, 876 const char *value, size_t size, int flags); 877 int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name, 878 char *value, size_t size); 879 int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list, 880 size_t size); 881 int fuse_fs_removexattr(struct fuse_fs *fs, const char *path, 882 const char *name); 883 int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize, 884 uint64_t *idx); 885 int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd, void *arg, 886 struct fuse_file_info *fi, unsigned int flags, void *data); 887 int fuse_fs_poll(struct fuse_fs *fs, const char *path, 888 struct fuse_file_info *fi, struct fuse_pollhandle *ph, 889 unsigned *reventsp); 890 int fuse_fs_fallocate(struct fuse_fs *fs, const char *path, int mode, 891 off_t offset, off_t length, struct fuse_file_info *fi); 892 void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn); 893 void fuse_fs_destroy(struct fuse_fs *fs); 894 895 int fuse_notify_poll(struct fuse_pollhandle *ph); 896 897 /** 898 * Create a new fuse filesystem object 899 * 900 * This is usually called from the factory of a fuse module to create 901 * a new instance of a filesystem. 902 * 903 * @param op the filesystem operations 904 * @param op_size the size of the fuse_operations structure 905 * @param user_data user data supplied in the context during the init() method 906 * @return a new filesystem object 907 */ 908 struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size, 909 void *user_data); 910 911 /** 912 * Filesystem module 913 * 914 * Filesystem modules are registered with the FUSE_REGISTER_MODULE() 915 * macro. 916 * 917 * If the "-omodules=modname:..." option is present, filesystem 918 * objects are created and pushed onto the stack with the 'factory' 919 * function. 920 */ 921 struct fuse_module { 922 /** 923 * Name of filesystem 924 */ 925 const char *name; 926 927 /** 928 * Factory for creating filesystem objects 929 * 930 * The function may use and remove options from 'args' that belong 931 * to this module. 932 * 933 * For now the 'fs' vector always contains exactly one filesystem. 934 * This is the filesystem which will be below the newly created 935 * filesystem in the stack. 936 * 937 * @param args the command line arguments 938 * @param fs NULL terminated filesystem object vector 939 * @return the new filesystem object 940 */ 941 struct fuse_fs *(*factory)(struct fuse_args *args, 942 struct fuse_fs *fs[]); 943 944 struct fuse_module *next; 945 struct fusemod_so *so; 946 int ctr; 947 }; 948 949 /** 950 * Register a filesystem module 951 * 952 * This function is used by FUSE_REGISTER_MODULE and there's usually 953 * no need to call it directly 954 */ 955 void fuse_register_module(struct fuse_module *mod); 956 957 /** 958 * Register filesystem module 959 * 960 * For the parameters, see description of the fields in 'struct 961 * fuse_module' 962 */ 963 #define FUSE_REGISTER_MODULE(name_, factory_) \ 964 static __attribute__((constructor)) void name_ ## _register(void) \ 965 { \ 966 static struct fuse_module mod = \ 967 { #name_, factory_, NULL, NULL, 0 }; \ 968 fuse_register_module(&mod); \ 969 } 970 971 972 /* ----------------------------------------------------------- * 973 * Advanced API for event handling, don't worry about this... * 974 * ----------------------------------------------------------- */ 975 976 /* NOTE: the following functions are deprecated, and will be removed 977 from the 3.0 API. Use the lowlevel session functions instead */ 978 979 /** Function type used to process commands */ 980 typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *); 981 982 /** This is the part of fuse_main() before the event loop */ 983 struct fuse *fuse_setup(int argc, char *argv[], 984 const struct fuse_operations *op, size_t op_size, 985 char **mountpoint, int *multithreaded, 986 void *user_data); 987 988 /** This is the part of fuse_main() after the event loop */ 989 void fuse_teardown(struct fuse *fuse, char *mountpoint); 990 991 /** Read a single command. If none are read, return NULL */ 992 struct fuse_cmd *fuse_read_cmd(struct fuse *f); 993 994 /** Process a single command */ 995 void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd); 996 997 /** Multi threaded event loop, which calls the custom command 998 processor function */ 999 int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data); 1000 1001 /** Return the exited flag, which indicates if fuse_exit() has been 1002 called */ 1003 int fuse_exited(struct fuse *f); 1004 1005 /** This function is obsolete and implemented as a no-op */ 1006 void fuse_set_getcontext_func(struct fuse_context *(*func)(void)); 1007 1008 /** Get session from fuse object */ 1009 struct fuse_session *fuse_get_session(struct fuse *f); 1010 1011 /* ----------------------------------------------------------- * 1012 * Compatibility stuff * 1013 * ----------------------------------------------------------- */ 1014 1015 #if FUSE_USE_VERSION < 26 1016 # include "fuse_compat.h" 1017 # undef fuse_main 1018 # if FUSE_USE_VERSION == 25 1019 # define fuse_main(argc, argv, op) \ 1020 fuse_main_real_compat25(argc, argv, op, sizeof(*(op))) 1021 # define fuse_new fuse_new_compat25 1022 # define fuse_setup fuse_setup_compat25 1023 # define fuse_teardown fuse_teardown_compat22 1024 # define fuse_operations fuse_operations_compat25 1025 # elif FUSE_USE_VERSION == 22 1026 # define fuse_main(argc, argv, op) \ 1027 fuse_main_real_compat22(argc, argv, op, sizeof(*(op))) 1028 # define fuse_new fuse_new_compat22 1029 # define fuse_setup fuse_setup_compat22 1030 # define fuse_teardown fuse_teardown_compat22 1031 # define fuse_operations fuse_operations_compat22 1032 # define fuse_file_info fuse_file_info_compat 1033 # elif FUSE_USE_VERSION == 24 1034 # error Compatibility with high-level API version 24 not supported 1035 # else 1036 # define fuse_dirfil_t fuse_dirfil_t_compat 1037 # define __fuse_read_cmd fuse_read_cmd 1038 # define __fuse_process_cmd fuse_process_cmd 1039 # define __fuse_loop_mt fuse_loop_mt_proc 1040 # if FUSE_USE_VERSION == 21 1041 # define fuse_operations fuse_operations_compat2 1042 # define fuse_main fuse_main_compat2 1043 # define fuse_new fuse_new_compat2 1044 # define __fuse_setup fuse_setup_compat2 1045 # define __fuse_teardown fuse_teardown_compat22 1046 # define __fuse_exited fuse_exited 1047 # define __fuse_set_getcontext_func fuse_set_getcontext_func 1048 # else 1049 # define fuse_statfs fuse_statfs_compat1 1050 # define fuse_operations fuse_operations_compat1 1051 # define fuse_main fuse_main_compat1 1052 # define fuse_new fuse_new_compat1 1053 # define FUSE_DEBUG FUSE_DEBUG_COMPAT1 1054 # endif 1055 # endif 1056 #endif 1057 1058 #ifdef __cplusplus 1059 } 1060 #endif 1061 1062 #endif /* _FUSE_H_ */ 1063