Home | History | Annotate | Line # | Download | only in librefuse
fuse.h revision 1.24
      1 /* $NetBSD: fuse.h,v 1.24 2021/12/04 06:42:39 pho Exp $ */
      2 
      3 /*
      4  * Copyright  2007 Alistair Crooks.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote
     15  *    products derived from this software without specific prior written
     16  *    permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
     22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 #ifndef FUSE_H_
     31 #define FUSE_H_	20211204
     32 
     33 #include <sys/types.h>
     34 
     35 #include <puffs.h>
     36 #include <utime.h>
     37 
     38 /* The latest version of FUSE API currently provided by refuse. */
     39 #define FUSE_MAJOR_VERSION	2
     40 #define FUSE_MINOR_VERSION	6
     41 
     42 #define FUSE_MAKE_VERSION(maj, min)	((maj) * 10 + (min))
     43 #define FUSE_VERSION	FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
     44 
     45 /* FUSE_USE_VERSION is expected to be defined by user code to
     46  * determine the API to be used. Although defining this macro is
     47  * mandatory in the original FUSE implementation, refuse hasn't
     48  * required this so we only emit a warning if it's undefined. */
     49 #if defined(FUSE_USE_VERSION)
     50 #	if FUSE_USE_VERSION > FUSE_VERSION
     51 #		warning "The requested API version is higher than the latest one supported by refuse."
     52 #	endif
     53 #else
     54 #	warning "User code including <fuse.h> should define FUSE_USE_VERSION before including this header. Defaulting to the latest version."
     55 #	define FUSE_USE_VERSION	FUSE_VERSION
     56 #endif
     57 
     58 #ifdef __cplusplus
     59 extern "C" {
     60 #endif
     61 
     62 struct fuse;
     63 struct fuse_args; /* XXXsupportme */
     64 
     65 struct fuse_file_info {
     66 	int32_t		flags;
     67 	uint32_t	fh_old;
     68 	int32_t		writepage;
     69 	uint32_t	direct_io:1;
     70 	uint32_t	keep_cache:1;
     71 	uint32_t	flush:1;
     72 	uint32_t	padding:29;
     73 	uint64_t	fh;
     74 	uint64_t	lock_owner;
     75 };
     76 
     77 struct fuse_conn_info {
     78 	uint32_t proto_major;
     79 	uint32_t proto_minor;
     80 	uint32_t async_read;
     81 	uint32_t max_write;
     82 	uint32_t max_readahead;
     83 	uint32_t reserved[27];
     84 };
     85 
     86 /* equivalent'ish of puffs_cc */
     87 struct fuse_context {
     88 	struct fuse	*fuse;
     89 	uid_t		uid;
     90 	gid_t		gid;
     91 	pid_t		pid;
     92 	void		*private_data;
     93 };
     94 
     95 /**
     96  * Argument list
     97  */
     98 struct fuse_args {
     99 	int	argc;
    100 	char	**argv;
    101 	int	allocated;
    102 };
    103 
    104 /**
    105  * Initializer for 'struct fuse_args'
    106  */
    107 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
    108 
    109 typedef struct puffs_fuse_dirh *fuse_dirh_t;
    110 
    111 typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
    112 typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
    113 
    114 /*
    115  * These operations shadow those in puffs_usermount, and are used
    116  * as a table of callbacks to make when file system requests come
    117  * in.
    118  *
    119  * NOTE: keep same order as fuse
    120  */
    121 struct fuse_operations {
    122 	int	(*getattr)(const char *, struct stat *);
    123 	int	(*readlink)(const char *, char *, size_t);
    124 	int	(*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
    125 	int	(*mknod)(const char *, mode_t, dev_t);
    126 	int	(*mkdir)(const char *, mode_t);
    127 	int	(*unlink)(const char *);
    128 	int	(*rmdir)(const char *);
    129 	int	(*symlink)(const char *, const char *);
    130 	int	(*rename)(const char *, const char *);
    131 	int	(*link)(const char *, const char *);
    132 	int	(*chmod)(const char *, mode_t);
    133 	int	(*chown)(const char *, uid_t, gid_t);
    134 	int	(*truncate)(const char *, off_t);
    135 	int	(*utime)(const char *, struct utimbuf *);
    136 	int	(*open)(const char *, struct fuse_file_info *);
    137 	int	(*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
    138 	int	(*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
    139 	int	(*statfs)(const char *, struct statvfs *);
    140 	int	(*flush)(const char *, struct fuse_file_info *);
    141 	int	(*release)(const char *, struct fuse_file_info *);
    142 	int	(*fsync)(const char *, int, struct fuse_file_info *);
    143 	int	(*setxattr)(const char *, const char *, const char *, size_t, int);
    144 	int	(*getxattr)(const char *, const char *, char *, size_t);
    145 	int	(*listxattr)(const char *, char *, size_t);
    146 	int	(*removexattr)(const char *, const char *);
    147 	int	(*opendir)(const char *, struct fuse_file_info *);
    148 	int	(*readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
    149 	int	(*releasedir)(const char *, struct fuse_file_info *);
    150 	int	(*fsyncdir)(const char *, int, struct fuse_file_info *);
    151 	void	*(*init)(struct fuse_conn_info *);
    152 	void	(*destroy)(void *);
    153 	int	(*access)(const char *, int);
    154 	int	(*create)(const char *, mode_t, struct fuse_file_info *);
    155 	int	(*ftruncate)(const char *, off_t, struct fuse_file_info *);
    156 	int	(*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
    157 	int	(*lock)(const char *, struct fuse_file_info *, int, struct flock *);
    158 	int	(*utimens)(const char *, const struct timespec *);
    159 	int	(*bmap)(const char *, size_t , uint64_t *);
    160 };
    161 
    162 
    163 struct fuse *fuse_new(struct fuse_args *,
    164 	const struct fuse_operations *, size_t, void *);
    165 
    166 int fuse_mount(struct fuse *, const char *);
    167 void fuse_unmount(struct fuse *);
    168 
    169 int fuse_daemonize(struct fuse *);
    170 
    171 int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
    172 int fuse_loop(struct fuse *);
    173 struct fuse_context *fuse_get_context(void);
    174 void fuse_exit(struct fuse *);
    175 void fuse_destroy(struct fuse *);
    176 int fuse_version(void);
    177 
    178 #if FUSE_USE_VERSION == 22
    179 #define fuse_unmount fuse_unmount_compat22
    180 #endif
    181 
    182 void fuse_unmount_compat22(const char *);
    183 
    184 #if FUSE_USE_VERSION >= 26
    185 #define fuse_main(argc, argv, op, user_data) \
    186             fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
    187 #else
    188 #define fuse_main(argc, argv, op) \
    189             fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
    190 #endif
    191 
    192 #ifdef __cplusplus
    193 }
    194 #endif
    195 
    196 #include <fuse_opt.h>
    197 
    198 #endif
    199