Home | History | Annotate | Line # | Download | only in librefuse
fuse.h revision 1.32
      1  1.32      pho /* $NetBSD: fuse.h,v 1.32 2022/01/22 08:03:32 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.30      pho #include <fuse_opt.h>
     34  1.26      pho #include <refuse/buf.h>
     35  1.28      pho #include <refuse/legacy.h>
     36  1.27      pho #include <refuse/poll.h>
     37  1.25      pho #include <refuse/session.h>
     38  1.25      pho #include <sys/cdefs.h>
     39  1.25      pho #include <sys/stat.h>
     40  1.25      pho #include <sys/statvfs.h>
     41   1.1      agc #include <sys/types.h>
     42   1.1      agc #include <utime.h>
     43   1.1      agc 
     44  1.29      pho /* This used to be (maj) * 10 + (min) until FUSE 3.10, and then
     45  1.29      pho  * changed to (maj) * 100 + (min). We can't just use the "newer"
     46  1.29      pho  * definition because filesystems in the wild still use the older one
     47  1.29      pho  * in their FUSE_USE_VERSION request. */
     48  1.29      pho #define FUSE_MAKE_VERSION(maj, min)					\
     49  1.29      pho 	(((maj) > 3 || ((maj) == 3 && (min) >= 10))			\
     50  1.29      pho 	? (maj) * 100 + (min)						\
     51  1.29      pho 	: (maj) *  10 + (min))
     52  1.29      pho 
     53  1.29      pho /* The latest version of FUSE API currently provided by ReFUSE. This
     54  1.29      pho  * is an implementation detail. User code should not rely on this
     55  1.29      pho  * constant. */
     56  1.29      pho #define _REFUSE_MAJOR_VERSION_	2
     57  1.29      pho #define _REFUSE_MINOR_VERSION_	6
     58  1.24      pho 
     59  1.29      pho #define _REFUSE_VERSION_	FUSE_MAKE_VERSION(_REFUSE_MAJOR_VERSION_, _REFUSE_MINOR_VERSION_)
     60  1.24      pho 
     61  1.24      pho /* FUSE_USE_VERSION is expected to be defined by user code to
     62  1.24      pho  * determine the API to be used. Although defining this macro is
     63  1.24      pho  * mandatory in the original FUSE implementation, refuse hasn't
     64  1.24      pho  * required this so we only emit a warning if it's undefined. */
     65  1.24      pho #if defined(FUSE_USE_VERSION)
     66  1.29      pho #	if FUSE_USE_VERSION > _REFUSE_VERSION_
     67  1.24      pho #		warning "The requested API version is higher than the latest one supported by refuse."
     68  1.29      pho #	elif FUSE_USE_VERSION < 11
     69  1.29      pho #		warning "The requested API version is lower than the oldest one supported by refuse."
     70  1.24      pho #	endif
     71  1.24      pho #else
     72  1.29      pho #	if !defined(_REFUSE_IMPLEMENTATION_)
     73  1.29      pho #		warning "User code including <fuse.h> should define FUSE_USE_VERSION before including this header. Defaulting to the latest version."
     74  1.29      pho #		define FUSE_USE_VERSION	_REFUSE_VERSION_
     75  1.29      pho #	endif
     76  1.29      pho #endif
     77  1.29      pho 
     78  1.29      pho /* FUSE_VERSION is supposed to be the latest version of FUSE API
     79  1.29      pho  * supported by the library. However, due to the way how original FUSE
     80  1.29      pho  * is implemented, some filesystems set FUSE_USE_VERSION to some old
     81  1.29      pho  * one and then expect the actual API version exposed by the library
     82  1.29      pho  * to be something newer if FUSE_VERSION is higher than that. ReFUSE
     83  1.29      pho  * doesn't work that way, so this has to be always identical to
     84  1.29      pho  * FUSE_USE_VERSION.
     85  1.29      pho  */
     86  1.29      pho #if defined(FUSE_USE_VERSION)
     87  1.29      pho #	define FUSE_VERSION		FUSE_USE_VERSION
     88  1.29      pho #	define FUSE_MAJOR_VERSION	(FUSE_VERSION / 10)
     89  1.29      pho #	define FUSE_MINOR_VERSION	(FUSE_VERSION % 10)
     90  1.24      pho #endif
     91  1.24      pho 
     92   1.1      agc #ifdef __cplusplus
     93   1.1      agc extern "C" {
     94   1.1      agc #endif
     95   1.1      agc 
     96   1.4      agc struct fuse;
     97  1.11      agc struct fuse_args; /* XXXsupportme */
     98   1.4      agc 
     99   1.1      agc struct fuse_file_info {
    100   1.1      agc 	int32_t		flags;
    101   1.1      agc 	uint32_t	fh_old;
    102   1.1      agc 	int32_t		writepage;
    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.1      agc 	uint32_t	padding:29;
    107   1.1      agc 	uint64_t	fh;
    108   1.1      agc 	uint64_t	lock_owner;
    109   1.1      agc };
    110   1.1      agc 
    111   1.1      agc struct fuse_conn_info {
    112   1.1      agc 	uint32_t proto_major;
    113   1.1      agc 	uint32_t proto_minor;
    114   1.1      agc 	uint32_t async_read;
    115   1.1      agc 	uint32_t max_write;
    116   1.1      agc 	uint32_t max_readahead;
    117   1.1      agc 	uint32_t reserved[27];
    118   1.1      agc };
    119   1.1      agc 
    120   1.3    pooka /* equivalent'ish of puffs_cc */
    121   1.3    pooka struct fuse_context {
    122   1.3    pooka 	struct fuse	*fuse;
    123   1.3    pooka 	uid_t		uid;
    124   1.3    pooka 	gid_t		gid;
    125   1.3    pooka 	pid_t		pid;
    126   1.3    pooka 	void		*private_data;
    127   1.3    pooka };
    128   1.3    pooka 
    129   1.1      agc /**
    130   1.1      agc  * Argument list
    131   1.1      agc  */
    132   1.1      agc struct fuse_args {
    133   1.1      agc 	int	argc;
    134   1.1      agc 	char	**argv;
    135   1.1      agc 	int	allocated;
    136   1.1      agc };
    137   1.1      agc 
    138   1.1      agc /**
    139   1.1      agc  * Initializer for 'struct fuse_args'
    140   1.1      agc  */
    141   1.1      agc #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
    142   1.1      agc 
    143   1.2    pooka 
    144   1.1      agc typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
    145   1.2    pooka typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
    146   1.1      agc 
    147   1.1      agc /*
    148   1.1      agc  * These operations shadow those in puffs_usermount, and are used
    149   1.1      agc  * as a table of callbacks to make when file system requests come
    150   1.1      agc  * in.
    151   1.5    pooka  *
    152   1.5    pooka  * NOTE: keep same order as fuse
    153   1.1      agc  */
    154   1.1      agc struct fuse_operations {
    155   1.1      agc 	int	(*getattr)(const char *, struct stat *);
    156   1.1      agc 	int	(*readlink)(const char *, char *, size_t);
    157   1.5    pooka 	int	(*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
    158   1.1      agc 	int	(*mknod)(const char *, mode_t, dev_t);
    159   1.1      agc 	int	(*mkdir)(const char *, mode_t);
    160   1.1      agc 	int	(*unlink)(const char *);
    161   1.1      agc 	int	(*rmdir)(const char *);
    162   1.1      agc 	int	(*symlink)(const char *, const char *);
    163   1.1      agc 	int	(*rename)(const char *, const char *);
    164   1.1      agc 	int	(*link)(const char *, const char *);
    165   1.1      agc 	int	(*chmod)(const char *, mode_t);
    166   1.1      agc 	int	(*chown)(const char *, uid_t, gid_t);
    167   1.1      agc 	int	(*truncate)(const char *, off_t);
    168   1.1      agc 	int	(*utime)(const char *, struct utimbuf *);
    169   1.1      agc 	int	(*open)(const char *, struct fuse_file_info *);
    170   1.1      agc 	int	(*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
    171   1.1      agc 	int	(*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
    172   1.1      agc 	int	(*statfs)(const char *, struct statvfs *);
    173   1.1      agc 	int	(*flush)(const char *, struct fuse_file_info *);
    174   1.1      agc 	int	(*release)(const char *, struct fuse_file_info *);
    175   1.1      agc 	int	(*fsync)(const char *, int, struct fuse_file_info *);
    176   1.1      agc 	int	(*setxattr)(const char *, const char *, const char *, size_t, int);
    177   1.1      agc 	int	(*getxattr)(const char *, const char *, char *, size_t);
    178   1.1      agc 	int	(*listxattr)(const char *, char *, size_t);
    179   1.1      agc 	int	(*removexattr)(const char *, const char *);
    180   1.1      agc 	int	(*opendir)(const char *, struct fuse_file_info *);
    181   1.1      agc 	int	(*readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
    182   1.1      agc 	int	(*releasedir)(const char *, struct fuse_file_info *);
    183   1.1      agc 	int	(*fsyncdir)(const char *, int, struct fuse_file_info *);
    184   1.1      agc 	void	*(*init)(struct fuse_conn_info *);
    185   1.1      agc 	void	(*destroy)(void *);
    186   1.1      agc 	int	(*access)(const char *, int);
    187   1.1      agc 	int	(*create)(const char *, mode_t, struct fuse_file_info *);
    188   1.1      agc 	int	(*ftruncate)(const char *, off_t, struct fuse_file_info *);
    189   1.1      agc 	int	(*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
    190   1.1      agc 	int	(*lock)(const char *, struct fuse_file_info *, int, struct flock *);
    191   1.1      agc 	int	(*utimens)(const char *, const struct timespec *);
    192   1.1      agc 	int	(*bmap)(const char *, size_t , uint64_t *);
    193   1.1      agc };
    194   1.1      agc 
    195   1.1      agc 
    196  1.22      pho struct fuse *fuse_new(struct fuse_args *,
    197   1.8    pooka 	const struct fuse_operations *, size_t, void *);
    198   1.8    pooka 
    199  1.22      pho int fuse_mount(struct fuse *, const char *);
    200  1.22      pho void fuse_unmount(struct fuse *);
    201  1.22      pho 
    202   1.1      agc int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
    203  1.31      pho /* Functions that have existed since the beginning and have never
    204  1.31      pho  * changed between API versions. */
    205   1.8    pooka int fuse_loop(struct fuse *);
    206   1.4      agc void fuse_exit(struct fuse *);
    207   1.8    pooka void fuse_destroy(struct fuse *);
    208  1.32      pho struct fuse_context *fuse_get_context(void);
    209  1.32      pho 
    210  1.32      pho /* Print available library options. Appeared on FUSE 3.1. */
    211  1.32      pho void fuse_lib_help(struct fuse_args *args);
    212  1.31      pho 
    213  1.31      pho /* Daemonize the calling process. Appeared on FUSE 2.6.
    214  1.31      pho  *
    215  1.31      pho  * NOTE: This function used to have a wrong prototype in librefuse at
    216  1.31      pho  * the time when FUSE_H_ < 20211204. */
    217  1.31      pho int fuse_daemonize(int foreground) __RENAME(fuse_daemonize_rev1);
    218  1.31      pho 
    219  1.32      pho /* Check if a request has been interrupted. Appeared on FUSE 2.6. */
    220  1.32      pho int fuse_interrupted(void);
    221  1.32      pho 
    222  1.32      pho /* Invalidate cache for a given path. Appeared on FUSE 3.2. */
    223  1.32      pho int fuse_invalidate_path(struct fuse *fuse, const char *path);
    224  1.32      pho 
    225  1.32      pho /* Get the version number of the library. Appeared on FUSE 2.7. */
    226  1.23     maya int fuse_version(void);
    227   1.8    pooka 
    228   1.8    pooka #if FUSE_USE_VERSION == 22
    229   1.8    pooka #define fuse_unmount fuse_unmount_compat22
    230   1.8    pooka #endif
    231   1.8    pooka 
    232   1.8    pooka void fuse_unmount_compat22(const char *);
    233   1.1      agc 
    234  1.16      agc #if FUSE_USE_VERSION >= 26
    235  1.22      pho #define fuse_main(argc, argv, op, user_data) \
    236  1.22      pho             fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
    237  1.15      agc #else
    238   1.1      agc #define fuse_main(argc, argv, op) \
    239   1.1      agc             fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
    240  1.15      agc #endif
    241  1.32      pho /* Get the version string of the library. Appeared on FUSE 3.0. */
    242  1.32      pho const char *fuse_pkgversion(void);
    243  1.32      pho 
    244  1.32      pho /* Get the current supplementary group IDs for the current request, or
    245  1.32      pho  * return -errno on failure. Appeared on FUSE 2.8. */
    246  1.32      pho int fuse_getgroups(int size, gid_t list[]);
    247  1.32      pho 
    248  1.32      pho /* Start the cleanup thread when using option "-oremember". Appeared
    249  1.32      pho  * on FUSE 2.9. */
    250  1.32      pho int fuse_start_cleanup_thread(struct fuse *fuse);
    251  1.32      pho 
    252  1.32      pho /* Stop the cleanup thread when using "-oremember". Appeared on FUSE
    253  1.32      pho  * 2.9. */
    254  1.32      pho void fuse_stop_cleanup_thread(struct fuse *fuse);
    255  1.32      pho 
    256  1.32      pho /* Iterate over cache removing stale entries, used in conjunction with
    257  1.32      pho  * "-oremember". Return the number of seconds until the next
    258  1.32      pho  * cleanup. Appeared on FUSE 2.9. */
    259  1.32      pho int fuse_clean_cache(struct fuse *fuse);
    260   1.1      agc 
    261   1.1      agc #ifdef __cplusplus
    262   1.1      agc }
    263   1.1      agc #endif
    264   1.1      agc 
    265   1.1      agc #endif
    266