libfuse
fuse_kernel.h
1 /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) */
2 /*
3  This file defines the kernel interface of FUSE
4  Copyright (C) 2001-2008 Miklos Szeredi <miklos@szeredi.hu>
5 
6  This program can be distributed under the terms of the GNU GPL.
7  See the file COPYING.
8 
9  This -- and only this -- header file may also be distributed under
10  the terms of the BSD Licence as follows:
11 
12  Copyright (C) 2001-2007 Miklos Szeredi. All rights reserved.
13 
14  Redistribution and use in source and binary forms, with or without
15  modification, are permitted provided that the following conditions
16  are met:
17  1. Redistributions of source code must retain the above copyright
18  notice, this list of conditions and the following disclaimer.
19  2. Redistributions in binary form must reproduce the above copyright
20  notice, this list of conditions and the following disclaimer in the
21  documentation and/or other materials provided with the distribution.
22 
23  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
27  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  SUCH DAMAGE.
34 */
35 
36 /*
37  * This file defines the kernel interface of FUSE
38  *
39  * Protocol changelog:
40  *
41  * 7.9:
42  * - new fuse_getattr_in input argument of GETATTR
43  * - add lk_flags in fuse_lk_in
44  * - add lock_owner field to fuse_setattr_in, fuse_read_in and fuse_write_in
45  * - add blksize field to fuse_attr
46  * - add file flags field to fuse_read_in and fuse_write_in
47  *
48  * 7.10
49  * - add nonseekable open flag
50  *
51  * 7.11
52  * - add IOCTL message
53  * - add unsolicited notification support
54  * - add POLL message and NOTIFY_POLL notification
55  *
56  * 7.12
57  * - add umask flag to input argument of create, mknod and mkdir
58  * - add notification messages for invalidation of inodes and
59  * directory entries
60  *
61  * 7.13
62  * - make max number of background requests and congestion threshold
63  * tunables
64  *
65  * 7.14
66  * - add splice support to fuse device
67  *
68  * 7.15
69  * - add store notify
70  * - add retrieve notify
71  *
72  * 7.16
73  * - add BATCH_FORGET request
74  * - FUSE_IOCTL_UNRESTRICTED shall now return with array of 'struct
75  * fuse_ioctl_iovec' instead of ambiguous 'struct iovec'
76  * - add FUSE_IOCTL_32BIT flag
77  *
78  * 7.17
79  * - add FUSE_FLOCK_LOCKS and FUSE_RELEASE_FLOCK_UNLOCK
80  *
81  * 7.18
82  * - add FUSE_IOCTL_DIR flag
83  * - add FUSE_NOTIFY_DELETE
84  *
85  * 7.19
86  * - add FUSE_FALLOCATE
87  *
88  * 7.20
89  * - add FUSE_AUTO_INVAL_DATA
90  *
91  * 7.21
92  * - add FUSE_READDIRPLUS
93  * - send the requested events in POLL request
94  *
95  * 7.22
96  * - add FUSE_ASYNC_DIO
97  *
98  * 7.23
99  * - add FUSE_WRITEBACK_CACHE
100  * - add time_gran to fuse_init_out
101  * - add reserved space to fuse_init_out
102  * - add FATTR_CTIME
103  * - add ctime and ctimensec to fuse_setattr_in
104  * - add FUSE_RENAME2 request
105  * - add FUSE_NO_OPEN_SUPPORT flag
106  *
107  * 7.24
108  * - add FUSE_LSEEK for SEEK_HOLE and SEEK_DATA support
109  *
110  * 7.25
111  * - add FUSE_PARALLEL_DIROPS
112  *
113  * 7.26
114  * - add FUSE_HANDLE_KILLPRIV
115  * - add FUSE_POSIX_ACL
116  *
117  * 7.27
118  * - add FUSE_ABORT_ERROR
119  *
120  * 7.28
121  * - add FUSE_COPY_FILE_RANGE
122  */
123 
124 #ifndef _LINUX_FUSE_H
125 #define _LINUX_FUSE_H
126 
127 #ifdef __KERNEL__
128 #include <linux/types.h>
129 #else
130 #include <stdint.h>
131 #endif
132 
133 /*
134  * Version negotiation:
135  *
136  * Both the kernel and userspace send the version they support in the
137  * INIT request and reply respectively.
138  *
139  * If the major versions match then both shall use the smallest
140  * of the two minor versions for communication.
141  *
142  * If the kernel supports a larger major version, then userspace shall
143  * reply with the major version it supports, ignore the rest of the
144  * INIT message and expect a new INIT message from the kernel with a
145  * matching major version.
146  *
147  * If the library supports a larger major version, then it shall fall
148  * back to the major protocol version sent by the kernel for
149  * communication and reply with that major version (and an arbitrary
150  * supported minor version).
151  */
152 
154 #define FUSE_KERNEL_VERSION 7
155 
157 #define FUSE_KERNEL_MINOR_VERSION 27
158 
160 #define FUSE_ROOT_ID 1
161 
162 /* Make sure all structures are padded to 64bit boundary, so 32bit
163  userspace works under 64bit kernels */
164 
165 struct fuse_attr {
166  uint64_t ino;
167  uint64_t size;
168  uint64_t blocks;
169  uint64_t atime;
170  uint64_t mtime;
171  uint64_t ctime;
172  uint32_t atimensec;
173  uint32_t mtimensec;
174  uint32_t ctimensec;
175  uint32_t mode;
176  uint32_t nlink;
177  uint32_t uid;
178  uint32_t gid;
179  uint32_t rdev;
180  uint32_t blksize;
181  uint32_t padding;
182 };
183 
184 struct fuse_kstatfs {
185  uint64_t blocks;
186  uint64_t bfree;
187  uint64_t bavail;
188  uint64_t files;
189  uint64_t ffree;
190  uint32_t bsize;
191  uint32_t namelen;
192  uint32_t frsize;
193  uint32_t padding;
194  uint32_t spare[6];
195 };
196 
197 struct fuse_file_lock {
198  uint64_t start;
199  uint64_t end;
200  uint32_t type;
201  uint32_t pid; /* tgid */
202 };
203 
207 #define FATTR_MODE (1 << 0)
208 #define FATTR_UID (1 << 1)
209 #define FATTR_GID (1 << 2)
210 #define FATTR_SIZE (1 << 3)
211 #define FATTR_ATIME (1 << 4)
212 #define FATTR_MTIME (1 << 5)
213 #define FATTR_FH (1 << 6)
214 #define FATTR_ATIME_NOW (1 << 7)
215 #define FATTR_MTIME_NOW (1 << 8)
216 #define FATTR_LOCKOWNER (1 << 9)
217 #define FATTR_CTIME (1 << 10)
218 
226 #define FOPEN_DIRECT_IO (1 << 0)
227 #define FOPEN_KEEP_CACHE (1 << 1)
228 #define FOPEN_NONSEEKABLE (1 << 2)
229 
256 #define FUSE_ASYNC_READ (1 << 0)
257 #define FUSE_POSIX_LOCKS (1 << 1)
258 #define FUSE_FILE_OPS (1 << 2)
259 #define FUSE_ATOMIC_O_TRUNC (1 << 3)
260 #define FUSE_EXPORT_SUPPORT (1 << 4)
261 #define FUSE_BIG_WRITES (1 << 5)
262 #define FUSE_DONT_MASK (1 << 6)
263 #define FUSE_SPLICE_WRITE (1 << 7)
264 #define FUSE_SPLICE_MOVE (1 << 8)
265 #define FUSE_SPLICE_READ (1 << 9)
266 #define FUSE_FLOCK_LOCKS (1 << 10)
267 #define FUSE_HAS_IOCTL_DIR (1 << 11)
268 #define FUSE_AUTO_INVAL_DATA (1 << 12)
269 #define FUSE_DO_READDIRPLUS (1 << 13)
270 #define FUSE_READDIRPLUS_AUTO (1 << 14)
271 #define FUSE_ASYNC_DIO (1 << 15)
272 #define FUSE_WRITEBACK_CACHE (1 << 16)
273 #define FUSE_NO_OPEN_SUPPORT (1 << 17)
274 #define FUSE_PARALLEL_DIROPS (1 << 18)
275 #define FUSE_HANDLE_KILLPRIV (1 << 19)
276 #define FUSE_POSIX_ACL (1 << 20)
277 #define FUSE_ABORT_ERROR (1 << 21)
278 
284 #define CUSE_UNRESTRICTED_IOCTL (1 << 0)
285 
289 #define FUSE_RELEASE_FLUSH (1 << 0)
290 #define FUSE_RELEASE_FLOCK_UNLOCK (1 << 1)
291 
295 #define FUSE_GETATTR_FH (1 << 0)
296 
300 #define FUSE_LK_FLOCK (1 << 0)
301 
308 #define FUSE_WRITE_CACHE (1 << 0)
309 #define FUSE_WRITE_LOCKOWNER (1 << 1)
310 
314 #define FUSE_READ_LOCKOWNER (1 << 1)
315 
327 #define FUSE_IOCTL_COMPAT (1 << 0)
328 #define FUSE_IOCTL_UNRESTRICTED (1 << 1)
329 #define FUSE_IOCTL_RETRY (1 << 2)
330 #define FUSE_IOCTL_32BIT (1 << 3)
331 #define FUSE_IOCTL_DIR (1 << 4)
332 
333 #define FUSE_IOCTL_MAX_IOV 256
334 
340 #define FUSE_POLL_SCHEDULE_NOTIFY (1 << 0)
341 
347 #define FUSE_FSYNC_FDATASYNC (1 << 0)
348 
349 enum fuse_opcode {
350  FUSE_LOOKUP = 1,
351  FUSE_FORGET = 2, /* no reply */
352  FUSE_GETATTR = 3,
353  FUSE_SETATTR = 4,
354  FUSE_READLINK = 5,
355  FUSE_SYMLINK = 6,
356  FUSE_MKNOD = 8,
357  FUSE_MKDIR = 9,
358  FUSE_UNLINK = 10,
359  FUSE_RMDIR = 11,
360  FUSE_RENAME = 12,
361  FUSE_LINK = 13,
362  FUSE_OPEN = 14,
363  FUSE_READ = 15,
364  FUSE_WRITE = 16,
365  FUSE_STATFS = 17,
366  FUSE_RELEASE = 18,
367  FUSE_FSYNC = 20,
368  FUSE_SETXATTR = 21,
369  FUSE_GETXATTR = 22,
370  FUSE_LISTXATTR = 23,
371  FUSE_REMOVEXATTR = 24,
372  FUSE_FLUSH = 25,
373  FUSE_INIT = 26,
374  FUSE_OPENDIR = 27,
375  FUSE_READDIR = 28,
376  FUSE_RELEASEDIR = 29,
377  FUSE_FSYNCDIR = 30,
378  FUSE_GETLK = 31,
379  FUSE_SETLK = 32,
380  FUSE_SETLKW = 33,
381  FUSE_ACCESS = 34,
382  FUSE_CREATE = 35,
383  FUSE_INTERRUPT = 36,
384  FUSE_BMAP = 37,
385  FUSE_DESTROY = 38,
386  FUSE_IOCTL = 39,
387  FUSE_POLL = 40,
388  FUSE_NOTIFY_REPLY = 41,
389  FUSE_BATCH_FORGET = 42,
390  FUSE_FALLOCATE = 43,
391  FUSE_READDIRPLUS = 44,
392  FUSE_RENAME2 = 45,
393  FUSE_LSEEK = 46,
394  FUSE_COPY_FILE_RANGE = 47,
395 
396  /* CUSE specific operations */
397  CUSE_INIT = 4096,
398 };
399 
400 enum fuse_notify_code {
401  FUSE_NOTIFY_POLL = 1,
402  FUSE_NOTIFY_INVAL_INODE = 2,
403  FUSE_NOTIFY_INVAL_ENTRY = 3,
404  FUSE_NOTIFY_STORE = 4,
405  FUSE_NOTIFY_RETRIEVE = 5,
406  FUSE_NOTIFY_DELETE = 6,
407  FUSE_NOTIFY_CODE_MAX,
408 };
409 
410 /* The read buffer is required to be at least 8k, but may be much larger */
411 #define FUSE_MIN_READ_BUFFER 8192
412 
413 #define FUSE_COMPAT_ENTRY_OUT_SIZE 120
414 
415 struct fuse_entry_out {
416  uint64_t nodeid; /* Inode ID */
417  uint64_t generation; /* Inode generation: nodeid:gen must
418  be unique for the fs's lifetime */
419  uint64_t entry_valid; /* Cache timeout for the name */
420  uint64_t attr_valid; /* Cache timeout for the attributes */
421  uint32_t entry_valid_nsec;
422  uint32_t attr_valid_nsec;
423  struct fuse_attr attr;
424 };
425 
426 struct fuse_forget_in {
427  uint64_t nlookup;
428 };
429 
430 struct fuse_forget_one {
431  uint64_t nodeid;
432  uint64_t nlookup;
433 };
434 
435 struct fuse_batch_forget_in {
436  uint32_t count;
437  uint32_t dummy;
438 };
439 
440 struct fuse_getattr_in {
441  uint32_t getattr_flags;
442  uint32_t dummy;
443  uint64_t fh;
444 };
445 
446 #define FUSE_COMPAT_ATTR_OUT_SIZE 96
447 
448 struct fuse_attr_out {
449  uint64_t attr_valid; /* Cache timeout for the attributes */
450  uint32_t attr_valid_nsec;
451  uint32_t dummy;
452  struct fuse_attr attr;
453 };
454 
455 #define FUSE_COMPAT_MKNOD_IN_SIZE 8
456 
457 struct fuse_mknod_in {
458  uint32_t mode;
459  uint32_t rdev;
460  uint32_t umask;
461  uint32_t padding;
462 };
463 
464 struct fuse_mkdir_in {
465  uint32_t mode;
466  uint32_t umask;
467 };
468 
469 struct fuse_rename_in {
470  uint64_t newdir;
471 };
472 
473 struct fuse_rename2_in {
474  uint64_t newdir;
475  uint32_t flags;
476  uint32_t padding;
477 };
478 
479 struct fuse_link_in {
480  uint64_t oldnodeid;
481 };
482 
483 struct fuse_setattr_in {
484  uint32_t valid;
485  uint32_t padding;
486  uint64_t fh;
487  uint64_t size;
488  uint64_t lock_owner;
489  uint64_t atime;
490  uint64_t mtime;
491  uint64_t ctime;
492  uint32_t atimensec;
493  uint32_t mtimensec;
494  uint32_t ctimensec;
495  uint32_t mode;
496  uint32_t unused4;
497  uint32_t uid;
498  uint32_t gid;
499  uint32_t unused5;
500 };
501 
502 struct fuse_open_in {
503  uint32_t flags;
504  uint32_t unused;
505 };
506 
507 struct fuse_create_in {
508  uint32_t flags;
509  uint32_t mode;
510  uint32_t umask;
511  uint32_t padding;
512 };
513 
514 struct fuse_open_out {
515  uint64_t fh;
516  uint32_t open_flags;
517  uint32_t padding;
518 };
519 
520 struct fuse_release_in {
521  uint64_t fh;
522  uint32_t flags;
523  uint32_t release_flags;
524  uint64_t lock_owner;
525 };
526 
527 struct fuse_flush_in {
528  uint64_t fh;
529  uint32_t unused;
530  uint32_t padding;
531  uint64_t lock_owner;
532 };
533 
534 struct fuse_read_in {
535  uint64_t fh;
536  uint64_t offset;
537  uint32_t size;
538  uint32_t read_flags;
539  uint64_t lock_owner;
540  uint32_t flags;
541  uint32_t padding;
542 };
543 
544 #define FUSE_COMPAT_WRITE_IN_SIZE 24
545 
546 struct fuse_write_in {
547  uint64_t fh;
548  uint64_t offset;
549  uint32_t size;
550  uint32_t write_flags;
551  uint64_t lock_owner;
552  uint32_t flags;
553  uint32_t padding;
554 };
555 
556 struct fuse_write_out {
557  uint32_t size;
558  uint32_t padding;
559 };
560 
561 #define FUSE_COMPAT_STATFS_SIZE 48
562 
563 struct fuse_statfs_out {
564  struct fuse_kstatfs st;
565 };
566 
567 struct fuse_fsync_in {
568  uint64_t fh;
569  uint32_t fsync_flags;
570  uint32_t padding;
571 };
572 
573 struct fuse_setxattr_in {
574  uint32_t size;
575  uint32_t flags;
576 };
577 
578 struct fuse_getxattr_in {
579  uint32_t size;
580  uint32_t padding;
581 };
582 
583 struct fuse_getxattr_out {
584  uint32_t size;
585  uint32_t padding;
586 };
587 
588 struct fuse_lk_in {
589  uint64_t fh;
590  uint64_t owner;
591  struct fuse_file_lock lk;
592  uint32_t lk_flags;
593  uint32_t padding;
594 };
595 
596 struct fuse_lk_out {
597  struct fuse_file_lock lk;
598 };
599 
600 struct fuse_access_in {
601  uint32_t mask;
602  uint32_t padding;
603 };
604 
605 struct fuse_init_in {
606  uint32_t major;
607  uint32_t minor;
608  uint32_t max_readahead;
609  uint32_t flags;
610 };
611 
612 #define FUSE_COMPAT_INIT_OUT_SIZE 8
613 #define FUSE_COMPAT_22_INIT_OUT_SIZE 24
614 
615 struct fuse_init_out {
616  uint32_t major;
617  uint32_t minor;
618  uint32_t max_readahead;
619  uint32_t flags;
620  uint16_t max_background;
621  uint16_t congestion_threshold;
622  uint32_t max_write;
623  uint32_t time_gran;
624  uint32_t unused[9];
625 };
626 
627 #define CUSE_INIT_INFO_MAX 4096
628 
629 struct cuse_init_in {
630  uint32_t major;
631  uint32_t minor;
632  uint32_t unused;
633  uint32_t flags;
634 };
635 
636 struct cuse_init_out {
637  uint32_t major;
638  uint32_t minor;
639  uint32_t unused;
640  uint32_t flags;
641  uint32_t max_read;
642  uint32_t max_write;
643  uint32_t dev_major; /* chardev major */
644  uint32_t dev_minor; /* chardev minor */
645  uint32_t spare[10];
646 };
647 
648 struct fuse_interrupt_in {
649  uint64_t unique;
650 };
651 
652 struct fuse_bmap_in {
653  uint64_t block;
654  uint32_t blocksize;
655  uint32_t padding;
656 };
657 
658 struct fuse_bmap_out {
659  uint64_t block;
660 };
661 
662 struct fuse_ioctl_in {
663  uint64_t fh;
664  uint32_t flags;
665  uint32_t cmd;
666  uint64_t arg;
667  uint32_t in_size;
668  uint32_t out_size;
669 };
670 
671 struct fuse_ioctl_iovec {
672  uint64_t base;
673  uint64_t len;
674 };
675 
676 struct fuse_ioctl_out {
677  int32_t result;
678  uint32_t flags;
679  uint32_t in_iovs;
680  uint32_t out_iovs;
681 };
682 
683 struct fuse_poll_in {
684  uint64_t fh;
685  uint64_t kh;
686  uint32_t flags;
687  uint32_t events;
688 };
689 
690 struct fuse_poll_out {
691  uint32_t revents;
692  uint32_t padding;
693 };
694 
695 struct fuse_notify_poll_wakeup_out {
696  uint64_t kh;
697 };
698 
699 struct fuse_fallocate_in {
700  uint64_t fh;
701  uint64_t offset;
702  uint64_t length;
703  uint32_t mode;
704  uint32_t padding;
705 };
706 
707 struct fuse_in_header {
708  uint32_t len;
709  uint32_t opcode;
710  uint64_t unique;
711  uint64_t nodeid;
712  uint32_t uid;
713  uint32_t gid;
714  uint32_t pid;
715  uint32_t padding;
716 };
717 
718 struct fuse_out_header {
719  uint32_t len;
720  int32_t error;
721  uint64_t unique;
722 };
723 
724 struct fuse_dirent {
725  uint64_t ino;
726  uint64_t off;
727  uint32_t namelen;
728  uint32_t type;
729  char name[];
730 };
731 
732 #define FUSE_NAME_OFFSET offsetof(struct fuse_dirent, name)
733 #define FUSE_DIRENT_ALIGN(x) \
734  (((x) + sizeof(uint64_t) - 1) & ~(sizeof(uint64_t) - 1))
735 #define FUSE_DIRENT_SIZE(d) \
736  FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
737 
738 struct fuse_direntplus {
739  struct fuse_entry_out entry_out;
740  struct fuse_dirent dirent;
741 };
742 
743 #define FUSE_NAME_OFFSET_DIRENTPLUS \
744  offsetof(struct fuse_direntplus, dirent.name)
745 #define FUSE_DIRENTPLUS_SIZE(d) \
746  FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET_DIRENTPLUS + (d)->dirent.namelen)
747 
748 struct fuse_notify_inval_inode_out {
749  uint64_t ino;
750  int64_t off;
751  int64_t len;
752 };
753 
754 struct fuse_notify_inval_entry_out {
755  uint64_t parent;
756  uint32_t namelen;
757  uint32_t padding;
758 };
759 
760 struct fuse_notify_delete_out {
761  uint64_t parent;
762  uint64_t child;
763  uint32_t namelen;
764  uint32_t padding;
765 };
766 
767 struct fuse_notify_store_out {
768  uint64_t nodeid;
769  uint64_t offset;
770  uint32_t size;
771  uint32_t padding;
772 };
773 
774 struct fuse_notify_retrieve_out {
775  uint64_t notify_unique;
776  uint64_t nodeid;
777  uint64_t offset;
778  uint32_t size;
779  uint32_t padding;
780 };
781 
782 /* Matches the size of fuse_write_in */
783 struct fuse_notify_retrieve_in {
784  uint64_t dummy1;
785  uint64_t offset;
786  uint32_t size;
787  uint32_t dummy2;
788  uint64_t dummy3;
789  uint64_t dummy4;
790 };
791 
792 /* Device ioctls: */
793 #define FUSE_DEV_IOC_CLONE _IOR(229, 0, uint32_t)
794 
795 struct fuse_lseek_in {
796  uint64_t fh;
797  uint64_t offset;
798  uint32_t whence;
799  uint32_t padding;
800 };
801 
802 struct fuse_lseek_out {
803  uint64_t offset;
804 };
805 
806 struct fuse_copy_file_range_in {
807  uint64_t fh_in;
808  uint64_t off_in;
809  uint64_t nodeid_out;
810  uint64_t fh_out;
811  uint64_t off_out;
812  uint64_t len;
813  uint64_t flags;
814 };
815 
816 #endif /* _LINUX_FUSE_H */