1 /* 2 FUSE: Filesystem in Userspace 3 Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu> 4 5 This program can be distributed under the terms of the GNU GPL. 6 See the file COPYING. 7 */ 8 9 #ifndef _FS_FUSE_I_H 10 #define _FS_FUSE_I_H 11 12 #ifndef pr_fmt 13 # define pr_fmt(fmt) "fuse: " fmt 14 #endif 15 16 #include <linux/fuse.h> 17 #include <linux/fs.h> 18 #include <linux/mount.h> 19 #include <linux/wait.h> 20 #include <linux/list.h> 21 #include <linux/spinlock.h> 22 #include <linux/mm.h> 23 #include <linux/backing-dev.h> 24 #include <linux/mutex.h> 25 #include <linux/rwsem.h> 26 #include <linux/rbtree.h> 27 #include <linux/poll.h> 28 #include <linux/workqueue.h> 29 #include <linux/kref.h> 30 #include <linux/xattr.h> 31 #include <linux/pid_namespace.h> 32 #include <linux/refcount.h> 33 #include <linux/user_namespace.h> 34 35 /** Default max number of pages that can be used in a single read request */ 36 #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32 37 38 /** Maximum of max_pages received in init_out */ 39 #define FUSE_MAX_MAX_PAGES 256 40 41 /** Bias for fi->writectr, meaning new writepages must not be sent */ 42 #define FUSE_NOWRITE INT_MIN 43 44 /** It could be as large as PATH_MAX, but would that have any uses? */ 45 #define FUSE_NAME_MAX 1024 46 47 /** Number of dentries for each connection in the control filesystem */ 48 #define FUSE_CTL_NUM_DENTRIES 5 49 50 /** Number of page pointers embedded in fuse_req */ 51 #define FUSE_REQ_INLINE_PAGES 1 52 53 /** List of active connections */ 54 extern struct list_head fuse_conn_list; 55 56 /** Global mutex protecting fuse_conn_list and the control filesystem */ 57 extern struct mutex fuse_mutex; 58 59 /** Module parameters */ 60 extern unsigned max_user_bgreq; 61 extern unsigned max_user_congthresh; 62 63 /* One forget request */ 64 struct fuse_forget_link { 65 struct fuse_forget_one forget_one; 66 struct fuse_forget_link *next; 67 }; 68 69 /** FUSE inode */ 70 struct fuse_inode { 71 /** Inode data */ 72 struct inode inode; 73 74 /** Unique ID, which identifies the inode between userspace 75 * and kernel */ 76 u64 nodeid; 77 78 /** Number of lookups on this inode */ 79 u64 nlookup; 80 81 /** The request used for sending the FORGET message */ 82 struct fuse_forget_link *forget; 83 84 /** Time in jiffies until the file attributes are valid */ 85 u64 i_time; 86 87 /* Which attributes are invalid */ 88 u32 inval_mask; 89 90 /** The sticky bit in inode->i_mode may have been removed, so 91 preserve the original mode */ 92 umode_t orig_i_mode; 93 94 /** 64 bit inode number */ 95 u64 orig_ino; 96 97 /** Version of last attribute change */ 98 u64 attr_version; 99 100 union { 101 /* Write related fields (regular file only) */ 102 struct { 103 /* Files usable in writepage. Protected by fi->lock */ 104 struct list_head write_files; 105 106 /* Writepages pending on truncate or fsync */ 107 struct list_head queued_writes; 108 109 /* Number of sent writes, a negative bias 110 * (FUSE_NOWRITE) means more writes are blocked */ 111 int writectr; 112 113 /* Waitq for writepage completion */ 114 wait_queue_head_t page_waitq; 115 116 /* List of writepage requestst (pending or sent) */ 117 struct list_head writepages; 118 }; 119 120 /* readdir cache (directory only) */ 121 struct { 122 /* true if fully cached */ 123 bool cached; 124 125 /* size of cache */ 126 loff_t size; 127 128 /* position at end of cache (position of next entry) */ 129 loff_t pos; 130 131 /* version of the cache */ 132 u64 version; 133 134 /* modification time of directory when cache was 135 * started */ 136 struct timespec64 mtime; 137 138 /* iversion of directory when cache was started */ 139 u64 iversion; 140 141 /* protects above fields */ 142 spinlock_t lock; 143 } rdc; 144 }; 145 146 /** Miscellaneous bits describing inode state */ 147 unsigned long state; 148 149 /** Lock for serializing lookup and readdir for back compatibility*/ 150 struct mutex mutex; 151 152 /** Lock to protect write related fields */ 153 spinlock_t lock; 154 }; 155 156 /** FUSE inode state bits */ 157 enum { 158 /** Advise readdirplus */ 159 FUSE_I_ADVISE_RDPLUS, 160 /** Initialized with readdirplus */ 161 FUSE_I_INIT_RDPLUS, 162 /** An operation changing file size is in progress */ 163 FUSE_I_SIZE_UNSTABLE, 164 }; 165 166 struct fuse_conn; 167 168 /** FUSE specific file data */ 169 struct fuse_file { 170 /** Fuse connection for this file */ 171 struct fuse_conn *fc; 172 173 /* 174 * Request reserved for flush and release. 175 * Modified under relative fuse_inode::lock. 176 */ 177 struct fuse_req *reserved_req; 178 179 /** Kernel file handle guaranteed to be unique */ 180 u64 kh; 181 182 /** File handle used by userspace */ 183 u64 fh; 184 185 /** Node id of this file */ 186 u64 nodeid; 187 188 /** Refcount */ 189 refcount_t count; 190 191 /** FOPEN_* flags returned by open */ 192 u32 open_flags; 193 194 /** Entry on inode's write_files list */ 195 struct list_head write_entry; 196 197 /* Readdir related */ 198 struct { 199 /* 200 * Protects below fields against (crazy) parallel readdir on 201 * same open file. Uncontended in the normal case. 202 */ 203 struct mutex lock; 204 205 /* Dir stream position */ 206 loff_t pos; 207 208 /* Offset in cache */ 209 loff_t cache_off; 210 211 /* Version of cache we are reading */ 212 u64 version; 213 214 } readdir; 215 216 /** RB node to be linked on fuse_conn->polled_files */ 217 struct rb_node polled_node; 218 219 /** Wait queue head for poll */ 220 wait_queue_head_t poll_wait; 221 222 /** Has flock been performed on this file? */ 223 bool flock:1; 224 }; 225 226 /** One input argument of a request */ 227 struct fuse_in_arg { 228 unsigned size; 229 const void *value; 230 }; 231 232 /** The request input */ 233 struct fuse_in { 234 /** The request header */ 235 struct fuse_in_header h; 236 237 /** True if the data for the last argument is in req->pages */ 238 unsigned argpages:1; 239 240 /** Number of arguments */ 241 unsigned numargs; 242 243 /** Array of arguments */ 244 struct fuse_in_arg args[3]; 245 }; 246 247 /** One output argument of a request */ 248 struct fuse_arg { 249 unsigned size; 250 void *value; 251 }; 252 253 /** The request output */ 254 struct fuse_out { 255 /** Header returned from userspace */ 256 struct fuse_out_header h; 257 258 /* 259 * The following bitfields are not changed during the request 260 * processing 261 */ 262 263 /** Last argument is variable length (can be shorter than 264 arg->size) */ 265 unsigned argvar:1; 266 267 /** Last argument is a list of pages to copy data to */ 268 unsigned argpages:1; 269 270 /** Zero partially or not copied pages */ 271 unsigned page_zeroing:1; 272 273 /** Pages may be replaced with new ones */ 274 unsigned page_replace:1; 275 276 /** Number or arguments */ 277 unsigned numargs; 278 279 /** Array of arguments */ 280 struct fuse_arg args[2]; 281 }; 282 283 /** FUSE page descriptor */ 284 struct fuse_page_desc { 285 unsigned int length; 286 unsigned int offset; 287 }; 288 289 struct fuse_args { 290 struct { 291 struct { 292 uint32_t opcode; 293 uint64_t nodeid; 294 } h; 295 unsigned numargs; 296 struct fuse_in_arg args[3]; 297 298 } in; 299 struct { 300 unsigned argvar:1; 301 unsigned numargs; 302 struct fuse_arg args[2]; 303 } out; 304 }; 305 306 #define FUSE_ARGS(args) struct fuse_args args = {} 307 308 /** The request IO state (for asynchronous processing) */ 309 struct fuse_io_priv { 310 struct kref refcnt; 311 int async; 312 spinlock_t lock; 313 unsigned reqs; 314 ssize_t bytes; 315 size_t size; 316 __u64 offset; 317 bool write; 318 bool should_dirty; 319 int err; 320 struct kiocb *iocb; 321 struct completion *done; 322 bool blocking; 323 }; 324 325 #define FUSE_IO_PRIV_SYNC(i) \ 326 { \ 327 .refcnt = KREF_INIT(1), \ 328 .async = 0, \ 329 .iocb = i, \ 330 } 331 332 /** 333 * Request flags 334 * 335 * FR_ISREPLY: set if the request has reply 336 * FR_FORCE: force sending of the request even if interrupted 337 * FR_BACKGROUND: request is sent in the background 338 * FR_WAITING: request is counted as "waiting" 339 * FR_ABORTED: the request was aborted 340 * FR_INTERRUPTED: the request has been interrupted 341 * FR_LOCKED: data is being copied to/from the request 342 * FR_PENDING: request is not yet in userspace 343 * FR_SENT: request is in userspace, waiting for an answer 344 * FR_FINISHED: request is finished 345 * FR_PRIVATE: request is on private list 346 */ 347 enum fuse_req_flag { 348 FR_ISREPLY, 349 FR_FORCE, 350 FR_BACKGROUND, 351 FR_WAITING, 352 FR_ABORTED, 353 FR_INTERRUPTED, 354 FR_LOCKED, 355 FR_PENDING, 356 FR_SENT, 357 FR_FINISHED, 358 FR_PRIVATE, 359 }; 360 361 /** 362 * A request to the client 363 * 364 * .waitq.lock protects the following fields: 365 * - FR_ABORTED 366 * - FR_LOCKED (may also be modified under fc->lock, tested under both) 367 */ 368 struct fuse_req { 369 /** This can be on either pending processing or io lists in 370 fuse_conn */ 371 struct list_head list; 372 373 /** Entry on the interrupts list */ 374 struct list_head intr_entry; 375 376 /** refcount */ 377 refcount_t count; 378 379 /* Request flags, updated with test/set/clear_bit() */ 380 unsigned long flags; 381 382 /** The request input */ 383 struct fuse_in in; 384 385 /** The request output */ 386 struct fuse_out out; 387 388 /** Used to wake up the task waiting for completion of request*/ 389 wait_queue_head_t waitq; 390 391 /** Data for asynchronous requests */ 392 union { 393 struct { 394 struct fuse_release_in in; 395 struct inode *inode; 396 } release; 397 struct fuse_init_in init_in; 398 struct fuse_init_out init_out; 399 struct cuse_init_in cuse_init_in; 400 struct { 401 struct fuse_read_in in; 402 u64 attr_ver; 403 } read; 404 struct { 405 struct fuse_write_in in; 406 struct fuse_write_out out; 407 struct fuse_req *next; 408 } write; 409 struct fuse_notify_retrieve_in retrieve_in; 410 } misc; 411 412 /** page vector */ 413 struct page **pages; 414 415 /** page-descriptor vector */ 416 struct fuse_page_desc *page_descs; 417 418 /** size of the 'pages' array */ 419 unsigned max_pages; 420 421 /** inline page vector */ 422 struct page *inline_pages[FUSE_REQ_INLINE_PAGES]; 423 424 /** inline page-descriptor vector */ 425 struct fuse_page_desc inline_page_descs[FUSE_REQ_INLINE_PAGES]; 426 427 /** number of pages in vector */ 428 unsigned num_pages; 429 430 /** File used in the request (or NULL) */ 431 struct fuse_file *ff; 432 433 /** Inode used in the request or NULL */ 434 struct inode *inode; 435 436 /** AIO control block */ 437 struct fuse_io_priv *io; 438 439 /** Link on fi->writepages */ 440 struct list_head writepages_entry; 441 442 /** Request completion callback */ 443 void (*end)(struct fuse_conn *, struct fuse_req *); 444 445 /** Request is stolen from fuse_file->reserved_req */ 446 struct file *stolen_file; 447 }; 448 449 struct fuse_iqueue { 450 /** Connection established */ 451 unsigned connected; 452 453 /** Readers of the connection are waiting on this */ 454 wait_queue_head_t waitq; 455 456 /** The next unique request id */ 457 u64 reqctr; 458 459 /** The list of pending requests */ 460 struct list_head pending; 461 462 /** Pending interrupts */ 463 struct list_head interrupts; 464 465 /** Queue of pending forgets */ 466 struct fuse_forget_link forget_list_head; 467 struct fuse_forget_link *forget_list_tail; 468 469 /** Batching of FORGET requests (positive indicates FORGET batch) */ 470 int forget_batch; 471 472 /** O_ASYNC requests */ 473 struct fasync_struct *fasync; 474 }; 475 476 #define FUSE_PQ_HASH_BITS 8 477 #define FUSE_PQ_HASH_SIZE (1 << FUSE_PQ_HASH_BITS) 478 479 struct fuse_pqueue { 480 /** Connection established */ 481 unsigned connected; 482 483 /** Lock protecting accessess to members of this structure */ 484 spinlock_t lock; 485 486 /** Hash table of requests being processed */ 487 struct list_head *processing; 488 489 /** The list of requests under I/O */ 490 struct list_head io; 491 }; 492 493 /** 494 * Fuse device instance 495 */ 496 struct fuse_dev { 497 /** Fuse connection for this device */ 498 struct fuse_conn *fc; 499 500 /** Processing queue */ 501 struct fuse_pqueue pq; 502 503 /** list entry on fc->devices */ 504 struct list_head entry; 505 }; 506 507 /** 508 * A Fuse connection. 509 * 510 * This structure is created, when the filesystem is mounted, and is 511 * destroyed, when the client device is closed and the filesystem is 512 * unmounted. 513 */ 514 struct fuse_conn { 515 /** Lock protecting accessess to members of this structure */ 516 spinlock_t lock; 517 518 /** Refcount */ 519 refcount_t count; 520 521 /** Number of fuse_dev's */ 522 atomic_t dev_count; 523 524 struct rcu_head rcu; 525 526 /** The user id for this mount */ 527 kuid_t user_id; 528 529 /** The group id for this mount */ 530 kgid_t group_id; 531 532 /** The pid namespace for this mount */ 533 struct pid_namespace *pid_ns; 534 535 /** The user namespace for this mount */ 536 struct user_namespace *user_ns; 537 538 /** Maximum read size */ 539 unsigned max_read; 540 541 /** Maximum write size */ 542 unsigned max_write; 543 544 /** Maxmum number of pages that can be used in a single request */ 545 unsigned int max_pages; 546 547 /** Input queue */ 548 struct fuse_iqueue iq; 549 550 /** The next unique kernel file handle */ 551 atomic64_t khctr; 552 553 /** rbtree of fuse_files waiting for poll events indexed by ph */ 554 struct rb_root polled_files; 555 556 /** Maximum number of outstanding background requests */ 557 unsigned max_background; 558 559 /** Number of background requests at which congestion starts */ 560 unsigned congestion_threshold; 561 562 /** Number of requests currently in the background */ 563 unsigned num_background; 564 565 /** Number of background requests currently queued for userspace */ 566 unsigned active_background; 567 568 /** The list of background requests set aside for later queuing */ 569 struct list_head bg_queue; 570 571 /** Protects: max_background, congestion_threshold, num_background, 572 * active_background, bg_queue, blocked */ 573 spinlock_t bg_lock; 574 575 /** Flag indicating that INIT reply has been received. Allocating 576 * any fuse request will be suspended until the flag is set */ 577 int initialized; 578 579 /** Flag indicating if connection is blocked. This will be 580 the case before the INIT reply is received, and if there 581 are too many outstading backgrounds requests */ 582 int blocked; 583 584 /** waitq for blocked connection */ 585 wait_queue_head_t blocked_waitq; 586 587 /** waitq for reserved requests */ 588 wait_queue_head_t reserved_req_waitq; 589 590 /** Connection established, cleared on umount, connection 591 abort and device release */ 592 unsigned connected; 593 594 /** Connection aborted via sysfs */ 595 bool aborted; 596 597 /** Connection failed (version mismatch). Cannot race with 598 setting other bitfields since it is only set once in INIT 599 reply, before any other request, and never cleared */ 600 unsigned conn_error:1; 601 602 /** Connection successful. Only set in INIT */ 603 unsigned conn_init:1; 604 605 /** Do readpages asynchronously? Only set in INIT */ 606 unsigned async_read:1; 607 608 /** Return an unique read error after abort. Only set in INIT */ 609 unsigned abort_err:1; 610 611 /** Do not send separate SETATTR request before open(O_TRUNC) */ 612 unsigned atomic_o_trunc:1; 613 614 /** Filesystem supports NFS exporting. Only set in INIT */ 615 unsigned export_support:1; 616 617 /** write-back cache policy (default is write-through) */ 618 unsigned writeback_cache:1; 619 620 /** allow parallel lookups and readdir (default is serialized) */ 621 unsigned parallel_dirops:1; 622 623 /** handle fs handles killing suid/sgid/cap on write/chown/trunc */ 624 unsigned handle_killpriv:1; 625 626 /** cache READLINK responses in page cache */ 627 unsigned cache_symlinks:1; 628 629 /* 630 * The following bitfields are only for optimization purposes 631 * and hence races in setting them will not cause malfunction 632 */ 633 634 /** Is open/release not implemented by fs? */ 635 unsigned no_open:1; 636 637 /** Is opendir/releasedir not implemented by fs? */ 638 unsigned no_opendir:1; 639 640 /** Is fsync not implemented by fs? */ 641 unsigned no_fsync:1; 642 643 /** Is fsyncdir not implemented by fs? */ 644 unsigned no_fsyncdir:1; 645 646 /** Is flush not implemented by fs? */ 647 unsigned no_flush:1; 648 649 /** Is setxattr not implemented by fs? */ 650 unsigned no_setxattr:1; 651 652 /** Is getxattr not implemented by fs? */ 653 unsigned no_getxattr:1; 654 655 /** Is listxattr not implemented by fs? */ 656 unsigned no_listxattr:1; 657 658 /** Is removexattr not implemented by fs? */ 659 unsigned no_removexattr:1; 660 661 /** Are posix file locking primitives not implemented by fs? */ 662 unsigned no_lock:1; 663 664 /** Is access not implemented by fs? */ 665 unsigned no_access:1; 666 667 /** Is create not implemented by fs? */ 668 unsigned no_create:1; 669 670 /** Is interrupt not implemented by fs? */ 671 unsigned no_interrupt:1; 672 673 /** Is bmap not implemented by fs? */ 674 unsigned no_bmap:1; 675 676 /** Is poll not implemented by fs? */ 677 unsigned no_poll:1; 678 679 /** Do multi-page cached writes */ 680 unsigned big_writes:1; 681 682 /** Don't apply umask to creation modes */ 683 unsigned dont_mask:1; 684 685 /** Are BSD file locking primitives not implemented by fs? */ 686 unsigned no_flock:1; 687 688 /** Is fallocate not implemented by fs? */ 689 unsigned no_fallocate:1; 690 691 /** Is rename with flags implemented by fs? */ 692 unsigned no_rename2:1; 693 694 /** Use enhanced/automatic page cache invalidation. */ 695 unsigned auto_inval_data:1; 696 697 /** Filesystem is fully reponsible for page cache invalidation. */ 698 unsigned explicit_inval_data:1; 699 700 /** Does the filesystem support readdirplus? */ 701 unsigned do_readdirplus:1; 702 703 /** Does the filesystem want adaptive readdirplus? */ 704 unsigned readdirplus_auto:1; 705 706 /** Does the filesystem support asynchronous direct-IO submission? */ 707 unsigned async_dio:1; 708 709 /** Is lseek not implemented by fs? */ 710 unsigned no_lseek:1; 711 712 /** Does the filesystem support posix acls? */ 713 unsigned posix_acl:1; 714 715 /** Check permissions based on the file mode or not? */ 716 unsigned default_permissions:1; 717 718 /** Allow other than the mounter user to access the filesystem ? */ 719 unsigned allow_other:1; 720 721 /** Does the filesystem support copy_file_range? */ 722 unsigned no_copy_file_range:1; 723 724 /** The number of requests waiting for completion */ 725 atomic_t num_waiting; 726 727 /** Negotiated minor version */ 728 unsigned minor; 729 730 /** Entry on the fuse_conn_list */ 731 struct list_head entry; 732 733 /** Device ID from super block */ 734 dev_t dev; 735 736 /** Dentries in the control filesystem */ 737 struct dentry *ctl_dentry[FUSE_CTL_NUM_DENTRIES]; 738 739 /** number of dentries used in the above array */ 740 int ctl_ndents; 741 742 /** Key for lock owner ID scrambling */ 743 u32 scramble_key[4]; 744 745 /** Reserved request for the DESTROY message */ 746 struct fuse_req *destroy_req; 747 748 /** Version counter for attribute changes */ 749 atomic64_t attr_version; 750 751 /** Called on final put */ 752 void (*release)(struct fuse_conn *); 753 754 /** Super block for this connection. */ 755 struct super_block *sb; 756 757 /** Read/write semaphore to hold when accessing sb. */ 758 struct rw_semaphore killsb; 759 760 /** List of device instances belonging to this connection */ 761 struct list_head devices; 762 }; 763 764 static inline struct fuse_conn *get_fuse_conn_super(struct super_block *sb) 765 { 766 return sb->s_fs_info; 767 } 768 769 static inline struct fuse_conn *get_fuse_conn(struct inode *inode) 770 { 771 return get_fuse_conn_super(inode->i_sb); 772 } 773 774 static inline struct fuse_inode *get_fuse_inode(struct inode *inode) 775 { 776 return container_of(inode, struct fuse_inode, inode); 777 } 778 779 static inline u64 get_node_id(struct inode *inode) 780 { 781 return get_fuse_inode(inode)->nodeid; 782 } 783 784 static inline int invalid_nodeid(u64 nodeid) 785 { 786 return !nodeid || nodeid == FUSE_ROOT_ID; 787 } 788 789 static inline u64 fuse_get_attr_version(struct fuse_conn *fc) 790 { 791 return atomic64_read(&fc->attr_version); 792 } 793 794 /** Device operations */ 795 extern const struct file_operations fuse_dev_operations; 796 797 extern const struct dentry_operations fuse_dentry_operations; 798 extern const struct dentry_operations fuse_root_dentry_operations; 799 800 /** 801 * Inode to nodeid comparison. 802 */ 803 int fuse_inode_eq(struct inode *inode, void *_nodeidp); 804 805 /** 806 * Get a filled in inode 807 */ 808 struct inode *fuse_iget(struct super_block *sb, u64 nodeid, 809 int generation, struct fuse_attr *attr, 810 u64 attr_valid, u64 attr_version); 811 812 int fuse_lookup_name(struct super_block *sb, u64 nodeid, const struct qstr *name, 813 struct fuse_entry_out *outarg, struct inode **inode); 814 815 /** 816 * Send FORGET command 817 */ 818 void fuse_queue_forget(struct fuse_conn *fc, struct fuse_forget_link *forget, 819 u64 nodeid, u64 nlookup); 820 821 struct fuse_forget_link *fuse_alloc_forget(void); 822 823 /* Used by READDIRPLUS */ 824 void fuse_force_forget(struct file *file, u64 nodeid); 825 826 /** 827 * Initialize READ or READDIR request 828 */ 829 void fuse_read_fill(struct fuse_req *req, struct file *file, 830 loff_t pos, size_t count, int opcode); 831 832 /** 833 * Send OPEN or OPENDIR request 834 */ 835 int fuse_open_common(struct inode *inode, struct file *file, bool isdir); 836 837 struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); 838 void fuse_file_free(struct fuse_file *ff); 839 void fuse_finish_open(struct inode *inode, struct file *file); 840 841 void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags); 842 843 /** 844 * Send RELEASE or RELEASEDIR request 845 */ 846 void fuse_release_common(struct file *file, bool isdir); 847 848 /** 849 * Send FSYNC or FSYNCDIR request 850 */ 851 int fuse_fsync_common(struct file *file, loff_t start, loff_t end, 852 int datasync, int opcode); 853 854 /** 855 * Notify poll wakeup 856 */ 857 int fuse_notify_poll_wakeup(struct fuse_conn *fc, 858 struct fuse_notify_poll_wakeup_out *outarg); 859 860 /** 861 * Initialize file operations on a regular file 862 */ 863 void fuse_init_file_inode(struct inode *inode); 864 865 /** 866 * Initialize inode operations on regular files and special files 867 */ 868 void fuse_init_common(struct inode *inode); 869 870 /** 871 * Initialize inode and file operations on a directory 872 */ 873 void fuse_init_dir(struct inode *inode); 874 875 /** 876 * Initialize inode operations on a symlink 877 */ 878 void fuse_init_symlink(struct inode *inode); 879 880 /** 881 * Change attributes of an inode 882 */ 883 void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, 884 u64 attr_valid, u64 attr_version); 885 886 void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, 887 u64 attr_valid); 888 889 /** 890 * Initialize the client device 891 */ 892 int fuse_dev_init(void); 893 894 /** 895 * Cleanup the client device 896 */ 897 void fuse_dev_cleanup(void); 898 899 int fuse_ctl_init(void); 900 void __exit fuse_ctl_cleanup(void); 901 902 /** 903 * Allocate a request 904 */ 905 struct fuse_req *fuse_request_alloc(unsigned npages); 906 907 struct fuse_req *fuse_request_alloc_nofs(unsigned npages); 908 909 bool fuse_req_realloc_pages(struct fuse_conn *fc, struct fuse_req *req, 910 gfp_t flags); 911 912 913 /** 914 * Free a request 915 */ 916 void fuse_request_free(struct fuse_req *req); 917 918 /** 919 * Get a request, may fail with -ENOMEM, 920 * caller should specify # elements in req->pages[] explicitly 921 */ 922 struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages); 923 struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc, 924 unsigned npages); 925 926 /* 927 * Increment reference count on request 928 */ 929 void __fuse_get_request(struct fuse_req *req); 930 931 /** 932 * Gets a requests for a file operation, always succeeds 933 */ 934 struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc, 935 struct file *file); 936 937 /** 938 * Decrement reference count of a request. If count goes to zero free 939 * the request. 940 */ 941 void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req); 942 943 /** 944 * Send a request (synchronous) 945 */ 946 void fuse_request_send(struct fuse_conn *fc, struct fuse_req *req); 947 948 /** 949 * Simple request sending that does request allocation and freeing 950 */ 951 ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args); 952 953 /** 954 * Send a request in the background 955 */ 956 void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); 957 bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req); 958 959 /* Abort all requests */ 960 void fuse_abort_conn(struct fuse_conn *fc); 961 void fuse_wait_aborted(struct fuse_conn *fc); 962 963 /** 964 * Invalidate inode attributes 965 */ 966 void fuse_invalidate_attr(struct inode *inode); 967 968 void fuse_invalidate_entry_cache(struct dentry *entry); 969 970 void fuse_invalidate_atime(struct inode *inode); 971 972 u64 entry_attr_timeout(struct fuse_entry_out *o); 973 void fuse_change_entry_timeout(struct dentry *entry, struct fuse_entry_out *o); 974 975 /** 976 * Acquire reference to fuse_conn 977 */ 978 struct fuse_conn *fuse_conn_get(struct fuse_conn *fc); 979 980 /** 981 * Initialize fuse_conn 982 */ 983 void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns); 984 985 /** 986 * Release reference to fuse_conn 987 */ 988 void fuse_conn_put(struct fuse_conn *fc); 989 990 struct fuse_dev *fuse_dev_alloc(struct fuse_conn *fc); 991 void fuse_dev_free(struct fuse_dev *fud); 992 993 /** 994 * Add connection to control filesystem 995 */ 996 int fuse_ctl_add_conn(struct fuse_conn *fc); 997 998 /** 999 * Remove connection from control filesystem 1000 */ 1001 void fuse_ctl_remove_conn(struct fuse_conn *fc); 1002 1003 /** 1004 * Is file type valid? 1005 */ 1006 int fuse_valid_type(int m); 1007 1008 /** 1009 * Is current process allowed to perform filesystem operation? 1010 */ 1011 int fuse_allow_current_process(struct fuse_conn *fc); 1012 1013 u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id); 1014 1015 void fuse_update_ctime(struct inode *inode); 1016 1017 int fuse_update_attributes(struct inode *inode, struct file *file); 1018 1019 void fuse_flush_writepages(struct inode *inode); 1020 1021 void fuse_set_nowrite(struct inode *inode); 1022 void fuse_release_nowrite(struct inode *inode); 1023 1024 /** 1025 * File-system tells the kernel to invalidate cache for the given node id. 1026 */ 1027 int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, 1028 loff_t offset, loff_t len); 1029 1030 /** 1031 * File-system tells the kernel to invalidate parent attributes and 1032 * the dentry matching parent/name. 1033 * 1034 * If the child_nodeid is non-zero and: 1035 * - matches the inode number for the dentry matching parent/name, 1036 * - is not a mount point 1037 * - is a file or oan empty directory 1038 * then the dentry is unhashed (d_delete()). 1039 */ 1040 int fuse_reverse_inval_entry(struct super_block *sb, u64 parent_nodeid, 1041 u64 child_nodeid, struct qstr *name); 1042 1043 int fuse_do_open(struct fuse_conn *fc, u64 nodeid, struct file *file, 1044 bool isdir); 1045 1046 /** 1047 * fuse_direct_io() flags 1048 */ 1049 1050 /** If set, it is WRITE; otherwise - READ */ 1051 #define FUSE_DIO_WRITE (1 << 0) 1052 1053 /** CUSE pass fuse_direct_io() a file which f_mapping->host is not from FUSE */ 1054 #define FUSE_DIO_CUSE (1 << 1) 1055 1056 ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter, 1057 loff_t *ppos, int flags); 1058 long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, 1059 unsigned int flags); 1060 long fuse_ioctl_common(struct file *file, unsigned int cmd, 1061 unsigned long arg, unsigned int flags); 1062 __poll_t fuse_file_poll(struct file *file, poll_table *wait); 1063 int fuse_dev_release(struct inode *inode, struct file *file); 1064 1065 bool fuse_write_update_size(struct inode *inode, loff_t pos); 1066 1067 int fuse_flush_times(struct inode *inode, struct fuse_file *ff); 1068 int fuse_write_inode(struct inode *inode, struct writeback_control *wbc); 1069 1070 int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, 1071 struct file *file); 1072 1073 void fuse_set_initialized(struct fuse_conn *fc); 1074 1075 void fuse_unlock_inode(struct inode *inode, bool locked); 1076 bool fuse_lock_inode(struct inode *inode); 1077 1078 int fuse_setxattr(struct inode *inode, const char *name, const void *value, 1079 size_t size, int flags); 1080 ssize_t fuse_getxattr(struct inode *inode, const char *name, void *value, 1081 size_t size); 1082 ssize_t fuse_listxattr(struct dentry *entry, char *list, size_t size); 1083 int fuse_removexattr(struct inode *inode, const char *name); 1084 extern const struct xattr_handler *fuse_xattr_handlers[]; 1085 extern const struct xattr_handler *fuse_acl_xattr_handlers[]; 1086 extern const struct xattr_handler *fuse_no_acl_xattr_handlers[]; 1087 1088 struct posix_acl; 1089 struct posix_acl *fuse_get_acl(struct inode *inode, int type); 1090 int fuse_set_acl(struct inode *inode, struct posix_acl *acl, int type); 1091 1092 1093 /* readdir.c */ 1094 int fuse_readdir(struct file *file, struct dir_context *ctx); 1095 1096 #endif /* _FS_FUSE_I_H */ 1097