Home | History | Annotate | Line # | Download | only in librefuse
fuse.h revision 1.33
      1  1.33      pho /* $NetBSD: fuse.h,v 1.33 2022/01/22 08:06:21 pho Exp $ */
      2  1.18  xtraeme 
      3   1.1      agc /*
      4   1.1      agc  * Copyright  2007 Alistair Crooks.  All rights reserved.
      5   1.1      agc  *
      6   1.1      agc  * Redistribution and use in source and binary forms, with or without
      7   1.1      agc  * modification, are permitted provided that the following conditions
      8   1.1      agc  * are met:
      9   1.1      agc  * 1. Redistributions of source code must retain the above copyright
     10   1.1      agc  *    notice, this list of conditions and the following disclaimer.
     11   1.1      agc  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1      agc  *    notice, this list of conditions and the following disclaimer in the
     13   1.1      agc  *    documentation and/or other materials provided with the distribution.
     14   1.1      agc  * 3. The name of the author may not be used to endorse or promote
     15   1.1      agc  *    products derived from this software without specific prior written
     16   1.1      agc  *    permission.
     17   1.1      agc  *
     18   1.1      agc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     19   1.1      agc  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20   1.1      agc  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21   1.1      agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     22   1.1      agc  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23   1.1      agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     24   1.1      agc  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25   1.1      agc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     26   1.1      agc  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     27   1.1      agc  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     28   1.1      agc  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29   1.1      agc  */
     30   1.1      agc #ifndef FUSE_H_
     31  1.24      pho #define FUSE_H_	20211204
     32  1.16      agc 
     33  1.33      pho #include <fcntl.h>
     34  1.30      pho #include <fuse_opt.h>
     35  1.26      pho #include <refuse/buf.h>
     36  1.28      pho #include <refuse/legacy.h>
     37  1.27      pho #include <refuse/poll.h>
     38  1.25      pho #include <refuse/session.h>
     39  1.25      pho #include <sys/cdefs.h>
     40  1.25      pho #include <sys/stat.h>
     41  1.25      pho #include <sys/statvfs.h>
     42   1.1      agc #include <sys/types.h>
     43   1.1      agc #include <utime.h>
     44   1.1      agc 
     45  1.29      pho /* This used to be (maj) * 10 + (min) until FUSE 3.10, and then
     46  1.29      pho  * changed to (maj) * 100 + (min). We can't just use the "newer"
     47  1.29      pho  * definition because filesystems in the wild still use the older one
     48  1.29      pho  * in their FUSE_USE_VERSION request. */
     49  1.29      pho #define FUSE_MAKE_VERSION(maj, min)					\
     50  1.29      pho 	(((maj) > 3 || ((maj) == 3 && (min) >= 10))			\
     51  1.29      pho 	? (maj) * 100 + (min)						\
     52  1.29      pho 	: (maj) *  10 + (min))
     53  1.29      pho 
     54  1.29      pho /* The latest version of FUSE API currently provided by ReFUSE. This
     55  1.29      pho  * is an implementation detail. User code should not rely on this
     56  1.29      pho  * constant. */
     57  1.29      pho #define _REFUSE_MAJOR_VERSION_	2
     58  1.29      pho #define _REFUSE_MINOR_VERSION_	6
     59  1.24      pho 
     60  1.29      pho #define _REFUSE_VERSION_	FUSE_MAKE_VERSION(_REFUSE_MAJOR_VERSION_, _REFUSE_MINOR_VERSION_)
     61  1.24      pho 
     62  1.24      pho /* FUSE_USE_VERSION is expected to be defined by user code to
     63  1.24      pho  * determine the API to be used. Although defining this macro is
     64  1.24      pho  * mandatory in the original FUSE implementation, refuse hasn't
     65  1.24      pho  * required this so we only emit a warning if it's undefined. */
     66  1.24      pho #if defined(FUSE_USE_VERSION)
     67  1.29      pho #	if FUSE_USE_VERSION > _REFUSE_VERSION_
     68  1.24      pho #		warning "The requested API version is higher than the latest one supported by refuse."
     69  1.29      pho #	elif FUSE_USE_VERSION < 11
     70  1.29      pho #		warning "The requested API version is lower than the oldest one supported by refuse."
     71  1.24      pho #	endif
     72  1.24      pho #else
     73  1.29      pho #	if !defined(_REFUSE_IMPLEMENTATION_)
     74  1.29      pho #		warning "User code including <fuse.h> should define FUSE_USE_VERSION before including this header. Defaulting to the latest version."
     75  1.29      pho #		define FUSE_USE_VERSION	_REFUSE_VERSION_
     76  1.29      pho #	endif
     77  1.29      pho #endif
     78  1.29      pho 
     79  1.29      pho /* FUSE_VERSION is supposed to be the latest version of FUSE API
     80  1.29      pho  * supported by the library. However, due to the way how original FUSE
     81  1.29      pho  * is implemented, some filesystems set FUSE_USE_VERSION to some old
     82  1.29      pho  * one and then expect the actual API version exposed by the library
     83  1.29      pho  * to be something newer if FUSE_VERSION is higher than that. ReFUSE
     84  1.29      pho  * doesn't work that way, so this has to be always identical to
     85  1.29      pho  * FUSE_USE_VERSION.
     86  1.29      pho  */
     87  1.29      pho #if defined(FUSE_USE_VERSION)
     88  1.29      pho #	define FUSE_VERSION		FUSE_USE_VERSION
     89  1.29      pho #	define FUSE_MAJOR_VERSION	(FUSE_VERSION / 10)
     90  1.29      pho #	define FUSE_MINOR_VERSION	(FUSE_VERSION % 10)
     91  1.24      pho #endif
     92  1.24      pho 
     93   1.1      agc #ifdef __cplusplus
     94   1.1      agc extern "C" {
     95   1.1      agc #endif
     96   1.1      agc 
     97   1.4      agc struct fuse;
     98   1.4      agc 
     99   1.1      agc struct fuse_file_info {
    100   1.1      agc 	int32_t		flags;
    101  1.33      pho 	uint32_t	fh_old;			/* Removed as of FUSE 3.0. */
    102  1.33      pho 	int32_t		writepage:1;
    103   1.1      agc 	uint32_t	direct_io:1;
    104   1.1      agc 	uint32_t	keep_cache:1;
    105   1.1      agc 	uint32_t	flush:1;
    106  1.33      pho 	uint32_t	nonseekable:1;		/* Added on FUSE 2.8. */
    107  1.33      pho 	uint32_t	flock_release:1;	/* Added on FUSE 2.9. */
    108  1.33      pho 	uint32_t	cache_readdir:1;	/* Added on FUSE 3.5. */
    109  1.33      pho 	uint32_t	padding:26;
    110   1.1      agc 	uint64_t	fh;
    111  1.33      pho 	uint64_t	lock_owner;		/* Added on FUSE 2.6. */
    112  1.33      pho 	uint32_t	poll_events;		/* Added on FUSE 3.0. */
    113   1.1      agc };
    114   1.1      agc 
    115   1.1      agc struct fuse_conn_info {
    116  1.33      pho 	uint32_t	proto_major;
    117  1.33      pho 	uint32_t	proto_minor;
    118  1.33      pho 	uint32_t	async_read;		/* Removed as of FUSE 3.0. */
    119  1.33      pho 	uint32_t	max_write;
    120  1.33      pho 	uint32_t	max_read;		/* Added on FUSE 3.0. */
    121  1.33      pho 	uint32_t	max_readahead;
    122  1.33      pho 	uint32_t	capable;		/* Added on FUSE 2.8. */
    123  1.33      pho 	uint32_t	want;			/* Added on FUSE 2.8. */
    124  1.33      pho 	uint32_t	max_background;		/* Added on FUSE 3.0. */
    125  1.33      pho 	uint32_t	congestion_threshold;	/* Added on FUSE 3.0. */
    126  1.33      pho 	uint32_t	time_gran;		/* Added on FUSE 3.0. */
    127  1.33      pho 	uint32_t	reserved[22];
    128   1.1      agc };
    129   1.1      agc 
    130   1.3    pooka /* equivalent'ish of puffs_cc */
    131   1.3    pooka struct fuse_context {
    132   1.3    pooka 	struct fuse	*fuse;
    133   1.3    pooka 	uid_t		uid;
    134   1.3    pooka 	gid_t		gid;
    135   1.3    pooka 	pid_t		pid;
    136   1.3    pooka 	void		*private_data;
    137  1.33      pho 	mode_t		umask;			/* Added on FUSE 2.8. */
    138  1.33      pho };
    139  1.33      pho 
    140  1.33      pho /* Capability bits for fuse_conn_info.capable and
    141  1.33      pho  * fuse_conn_info.want */
    142  1.33      pho #define FUSE_CAP_ASYNC_READ		(1 << 0)
    143  1.33      pho #define FUSE_CAP_POSIX_LOCKS		(1 << 1)
    144  1.33      pho #define FUSE_CAP_ATOMIC_O_TRUNC		(1 << 3)
    145  1.33      pho #define FUSE_CAP_EXPORT_SUPPORT		(1 << 4)
    146  1.33      pho #define FUSE_CAP_BIG_WRITES		(1 << 5)	/* Removed as of FUSE 3.0. */
    147  1.33      pho #define FUSE_CAP_DONT_MASK		(1 << 6)
    148  1.33      pho #define FUSE_CAP_SPLICE_WRITE		(1 << 7)	/* Added on FUSE 3.0. */
    149  1.33      pho #define FUSE_CAP_SPLICE_MOVE		(1 << 8)	/* Added on FUSE 3.0. */
    150  1.33      pho #define FUSE_CAP_SPLICE_READ		(1 << 9)	/* Added on FUSE 3.0. */
    151  1.33      pho #define FUSE_CAP_FLOCK_LOCKS		(1 << 10)	/* Added on FUSE 3.0. */
    152  1.33      pho #define FUSE_CAP_IOCTL_DIR		(1 << 11)	/* Added on FUSE 3.0. */
    153  1.33      pho #define FUSE_CAP_AUTO_INVAL_DATA	(1 << 12)	/* Added on FUSE 3.0. */
    154  1.33      pho #define FUSE_CAP_READDIRPLUS		(1 << 13)	/* Added on FUSE 3.0. */
    155  1.33      pho #define FUSE_CAP_READDIRPLUS_AUTO	(1 << 14)	/* Added on FUSE 3.0. */
    156  1.33      pho #define FUSE_CAP_ASYNC_DIO		(1 << 15)	/* Added on FUSE 3.0. */
    157  1.33      pho #define FUSE_CAP_WRITEBACK_CACHE	(1 << 16)	/* Added on FUSE 3.0. */
    158  1.33      pho #define FUSE_CAP_NO_OPEN_SUPPORT	(1 << 17)	/* Added on FUSE 3.0. */
    159  1.33      pho #define FUSE_CAP_PARALLEL_DIROPS	(1 << 18)	/* Added on FUSE 3.0. */
    160  1.33      pho #define FUSE_CAP_POSIX_ACL		(1 << 19)	/* Added on FUSE 3.0. */
    161  1.33      pho #define FUSE_CAP_HANDLE_KILLPRIV	(1 << 20)	/* Added on FUSE 3.0. */
    162  1.33      pho #define FUSE_CAP_CACHE_SYMLINKS		(1 << 23)	/* Added on FUSE 3.10. */
    163  1.33      pho #define FUSE_CAP_NO_OPENDIR_SUPPORT	(1 << 24)	/* Added on FUSE 3.5. */
    164  1.33      pho 
    165  1.33      pho /* ioctl flags */
    166  1.33      pho #define FUSE_IOCTL_COMPAT	(1 << 0)
    167  1.33      pho #define FUSE_IOCTL_UNRESTRICTED	(1 << 1)
    168  1.33      pho #define FUSE_IOCTL_RETRY	(1 << 2)
    169  1.33      pho #define FUSE_IOCTL_DIR		(1 << 4)	/* Added on FUSE 2.9. */
    170  1.33      pho #define FUSE_IOCTL_MAX_IOV	256
    171  1.33      pho 
    172  1.33      pho /* readdir() flags, appeared on FUSE 3.0. */
    173  1.33      pho enum fuse_readdir_flags {
    174  1.33      pho 	FUSE_READDIR_PLUS	= (1 << 0),
    175  1.33      pho };
    176  1.33      pho enum fuse_fill_dir_flags {
    177  1.33      pho 	FUSE_FILL_DIR_PLUS	= (1 << 1),
    178  1.33      pho };
    179  1.33      pho 
    180  1.33      pho /* Configuration of the high-level API, appeared on FUSE 3.0. */
    181  1.33      pho struct fuse_config {
    182  1.33      pho 	int		set_gid;
    183  1.33      pho 	unsigned int	gid;
    184  1.33      pho 	int		set_uid;
    185  1.33      pho 	unsigned int	uid;
    186  1.33      pho 	int		set_mode;
    187  1.33      pho 	unsigned int	umask;
    188  1.33      pho 	double		entry_timeout;
    189  1.33      pho 	double		negative_timeout;
    190  1.33      pho 	double		attr_timeout;
    191  1.33      pho 	int		intr;
    192  1.33      pho 	int		intr_signal;
    193  1.33      pho 	int		remember;
    194  1.33      pho 	int		hard_remove;
    195  1.33      pho 	int		use_ino;
    196  1.33      pho 	int		readdir_ino;
    197  1.33      pho 	int		direct_io;
    198  1.33      pho 	int		kernel_cache;
    199  1.33      pho 	int		auto_cache;
    200  1.33      pho 	int		ac_attr_timeout_set;
    201  1.33      pho 	double		ac_attr_timeout;
    202  1.33      pho 	int		nullpath_ok;
    203  1.33      pho };
    204  1.33      pho 
    205  1.33      pho /* Configuration of fuse_loop_mt(), appeared on FUSE 3.2. */
    206  1.33      pho struct fuse_loop_config {
    207  1.33      pho 	int		clone_fd;
    208  1.33      pho 	unsigned int	max_idle_threads;
    209   1.3    pooka };
    210   1.3    pooka 
    211   1.1      agc /**
    212   1.1      agc  * Argument list
    213   1.1      agc  */
    214   1.1      agc struct fuse_args {
    215   1.1      agc 	int	argc;
    216   1.1      agc 	char	**argv;
    217   1.1      agc 	int	allocated;
    218   1.1      agc };
    219   1.1      agc 
    220   1.1      agc /**
    221   1.1      agc  * Initializer for 'struct fuse_args'
    222   1.1      agc  */
    223   1.1      agc #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
    224   1.1      agc 
    225   1.2    pooka 
    226   1.1      agc typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
    227   1.2    pooka typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
    228   1.1      agc 
    229   1.1      agc /*
    230   1.1      agc  * These operations shadow those in puffs_usermount, and are used
    231   1.1      agc  * as a table of callbacks to make when file system requests come
    232   1.1      agc  * in.
    233   1.5    pooka  *
    234   1.5    pooka  * NOTE: keep same order as fuse
    235   1.1      agc  */
    236   1.1      agc struct fuse_operations {
    237   1.1      agc 	int	(*getattr)(const char *, struct stat *);
    238   1.1      agc 	int	(*readlink)(const char *, char *, size_t);
    239   1.5    pooka 	int	(*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
    240   1.1      agc 	int	(*mknod)(const char *, mode_t, dev_t);
    241   1.1      agc 	int	(*mkdir)(const char *, mode_t);
    242   1.1      agc 	int	(*unlink)(const char *);
    243   1.1      agc 	int	(*rmdir)(const char *);
    244   1.1      agc 	int	(*symlink)(const char *, const char *);
    245   1.1      agc 	int	(*rename)(const char *, const char *);
    246   1.1      agc 	int	(*link)(const char *, const char *);
    247   1.1      agc 	int	(*chmod)(const char *, mode_t);
    248   1.1      agc 	int	(*chown)(const char *, uid_t, gid_t);
    249   1.1      agc 	int	(*truncate)(const char *, off_t);
    250   1.1      agc 	int	(*utime)(const char *, struct utimbuf *);
    251   1.1      agc 	int	(*open)(const char *, struct fuse_file_info *);
    252   1.1      agc 	int	(*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
    253   1.1      agc 	int	(*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
    254   1.1      agc 	int	(*statfs)(const char *, struct statvfs *);
    255   1.1      agc 	int	(*flush)(const char *, struct fuse_file_info *);
    256   1.1      agc 	int	(*release)(const char *, struct fuse_file_info *);
    257   1.1      agc 	int	(*fsync)(const char *, int, struct fuse_file_info *);
    258   1.1      agc 	int	(*setxattr)(const char *, const char *, const char *, size_t, int);
    259   1.1      agc 	int	(*getxattr)(const char *, const char *, char *, size_t);
    260   1.1      agc 	int	(*listxattr)(const char *, char *, size_t);
    261   1.1      agc 	int	(*removexattr)(const char *, const char *);
    262   1.1      agc 	int	(*opendir)(const char *, struct fuse_file_info *);
    263   1.1      agc 	int	(*readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
    264   1.1      agc 	int	(*releasedir)(const char *, struct fuse_file_info *);
    265   1.1      agc 	int	(*fsyncdir)(const char *, int, struct fuse_file_info *);
    266   1.1      agc 	void	*(*init)(struct fuse_conn_info *);
    267   1.1      agc 	void	(*destroy)(void *);
    268   1.1      agc 	int	(*access)(const char *, int);
    269   1.1      agc 	int	(*create)(const char *, mode_t, struct fuse_file_info *);
    270   1.1      agc 	int	(*ftruncate)(const char *, off_t, struct fuse_file_info *);
    271   1.1      agc 	int	(*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
    272   1.1      agc 	int	(*lock)(const char *, struct fuse_file_info *, int, struct flock *);
    273   1.1      agc 	int	(*utimens)(const char *, const struct timespec *);
    274   1.1      agc 	int	(*bmap)(const char *, size_t , uint64_t *);
    275   1.1      agc };
    276   1.1      agc 
    277   1.1      agc 
    278  1.22      pho struct fuse *fuse_new(struct fuse_args *,
    279   1.8    pooka 	const struct fuse_operations *, size_t, void *);
    280   1.8    pooka 
    281  1.22      pho int fuse_mount(struct fuse *, const char *);
    282  1.22      pho void fuse_unmount(struct fuse *);
    283  1.22      pho 
    284   1.1      agc int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
    285  1.31      pho /* Functions that have existed since the beginning and have never
    286  1.31      pho  * changed between API versions. */
    287   1.8    pooka int fuse_loop(struct fuse *);
    288   1.4      agc void fuse_exit(struct fuse *);
    289   1.8    pooka void fuse_destroy(struct fuse *);
    290  1.32      pho struct fuse_context *fuse_get_context(void);
    291  1.32      pho 
    292  1.32      pho /* Print available library options. Appeared on FUSE 3.1. */
    293  1.32      pho void fuse_lib_help(struct fuse_args *args);
    294  1.31      pho 
    295  1.31      pho /* Daemonize the calling process. Appeared on FUSE 2.6.
    296  1.31      pho  *
    297  1.31      pho  * NOTE: This function used to have a wrong prototype in librefuse at
    298  1.31      pho  * the time when FUSE_H_ < 20211204. */
    299  1.31      pho int fuse_daemonize(int foreground) __RENAME(fuse_daemonize_rev1);
    300  1.31      pho 
    301  1.32      pho /* Check if a request has been interrupted. Appeared on FUSE 2.6. */
    302  1.32      pho int fuse_interrupted(void);
    303  1.32      pho 
    304  1.32      pho /* Invalidate cache for a given path. Appeared on FUSE 3.2. */
    305  1.32      pho int fuse_invalidate_path(struct fuse *fuse, const char *path);
    306  1.32      pho 
    307  1.32      pho /* Get the version number of the library. Appeared on FUSE 2.7. */
    308  1.23     maya int fuse_version(void);
    309   1.8    pooka 
    310   1.8    pooka #if FUSE_USE_VERSION == 22
    311   1.8    pooka #define fuse_unmount fuse_unmount_compat22
    312   1.8    pooka #endif
    313   1.8    pooka 
    314   1.8    pooka void fuse_unmount_compat22(const char *);
    315   1.1      agc 
    316  1.16      agc #if FUSE_USE_VERSION >= 26
    317  1.22      pho #define fuse_main(argc, argv, op, user_data) \
    318  1.22      pho             fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
    319  1.15      agc #else
    320   1.1      agc #define fuse_main(argc, argv, op) \
    321   1.1      agc             fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
    322  1.15      agc #endif
    323  1.32      pho /* Get the version string of the library. Appeared on FUSE 3.0. */
    324  1.32      pho const char *fuse_pkgversion(void);
    325  1.32      pho 
    326  1.32      pho /* Get the current supplementary group IDs for the current request, or
    327  1.32      pho  * return -errno on failure. Appeared on FUSE 2.8. */
    328  1.32      pho int fuse_getgroups(int size, gid_t list[]);
    329  1.32      pho 
    330  1.32      pho /* Start the cleanup thread when using option "-oremember". Appeared
    331  1.32      pho  * on FUSE 2.9. */
    332  1.32      pho int fuse_start_cleanup_thread(struct fuse *fuse);
    333  1.32      pho 
    334  1.32      pho /* Stop the cleanup thread when using "-oremember". Appeared on FUSE
    335  1.32      pho  * 2.9. */
    336  1.32      pho void fuse_stop_cleanup_thread(struct fuse *fuse);
    337  1.32      pho 
    338  1.32      pho /* Iterate over cache removing stale entries, used in conjunction with
    339  1.32      pho  * "-oremember". Return the number of seconds until the next
    340  1.32      pho  * cleanup. Appeared on FUSE 2.9. */
    341  1.32      pho int fuse_clean_cache(struct fuse *fuse);
    342   1.1      agc 
    343   1.1      agc #ifdef __cplusplus
    344   1.1      agc }
    345   1.1      agc #endif
    346   1.1      agc 
    347   1.1      agc #endif
    348