Home | History | Annotate | Line # | Download | only in librefuse
fuse.h revision 1.25
      1 /* $NetBSD: fuse.h,v 1.25 2022/01/22 07:53:06 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 <refuse/session.h>
     34 #include <sys/cdefs.h>
     35 #include <sys/stat.h>
     36 #include <sys/statvfs.h>
     37 #include <sys/types.h>
     38 #include <utime.h>
     39 
     40 /* The latest version of FUSE API currently provided by refuse. */
     41 #define FUSE_MAJOR_VERSION	2
     42 #define FUSE_MINOR_VERSION	6
     43 
     44 #define FUSE_MAKE_VERSION(maj, min)	((maj) * 10 + (min))
     45 #define FUSE_VERSION	FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
     46 
     47 /* FUSE_USE_VERSION is expected to be defined by user code to
     48  * determine the API to be used. Although defining this macro is
     49  * mandatory in the original FUSE implementation, refuse hasn't
     50  * required this so we only emit a warning if it's undefined. */
     51 #if defined(FUSE_USE_VERSION)
     52 #	if FUSE_USE_VERSION > FUSE_VERSION
     53 #		warning "The requested API version is higher than the latest one supported by refuse."
     54 #	endif
     55 #else
     56 #	warning "User code including <fuse.h> should define FUSE_USE_VERSION before including this header. Defaulting to the latest version."
     57 #	define FUSE_USE_VERSION	FUSE_VERSION
     58 #endif
     59 
     60 #ifdef __cplusplus
     61 extern "C" {
     62 #endif
     63 
     64 struct fuse;
     65 struct fuse_args; /* XXXsupportme */
     66 
     67 struct fuse_file_info {
     68 	int32_t		flags;
     69 	uint32_t	fh_old;
     70 	int32_t		writepage;
     71 	uint32_t	direct_io:1;
     72 	uint32_t	keep_cache:1;
     73 	uint32_t	flush:1;
     74 	uint32_t	padding:29;
     75 	uint64_t	fh;
     76 	uint64_t	lock_owner;
     77 };
     78 
     79 struct fuse_conn_info {
     80 	uint32_t proto_major;
     81 	uint32_t proto_minor;
     82 	uint32_t async_read;
     83 	uint32_t max_write;
     84 	uint32_t max_readahead;
     85 	uint32_t reserved[27];
     86 };
     87 
     88 /* equivalent'ish of puffs_cc */
     89 struct fuse_context {
     90 	struct fuse	*fuse;
     91 	uid_t		uid;
     92 	gid_t		gid;
     93 	pid_t		pid;
     94 	void		*private_data;
     95 };
     96 
     97 /**
     98  * Argument list
     99  */
    100 struct fuse_args {
    101 	int	argc;
    102 	char	**argv;
    103 	int	allocated;
    104 };
    105 
    106 /**
    107  * Initializer for 'struct fuse_args'
    108  */
    109 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
    110 
    111 typedef struct puffs_fuse_dirh *fuse_dirh_t;
    112 
    113 typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
    114 typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
    115 
    116 /*
    117  * These operations shadow those in puffs_usermount, and are used
    118  * as a table of callbacks to make when file system requests come
    119  * in.
    120  *
    121  * NOTE: keep same order as fuse
    122  */
    123 struct fuse_operations {
    124 	int	(*getattr)(const char *, struct stat *);
    125 	int	(*readlink)(const char *, char *, size_t);
    126 	int	(*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
    127 	int	(*mknod)(const char *, mode_t, dev_t);
    128 	int	(*mkdir)(const char *, mode_t);
    129 	int	(*unlink)(const char *);
    130 	int	(*rmdir)(const char *);
    131 	int	(*symlink)(const char *, const char *);
    132 	int	(*rename)(const char *, const char *);
    133 	int	(*link)(const char *, const char *);
    134 	int	(*chmod)(const char *, mode_t);
    135 	int	(*chown)(const char *, uid_t, gid_t);
    136 	int	(*truncate)(const char *, off_t);
    137 	int	(*utime)(const char *, struct utimbuf *);
    138 	int	(*open)(const char *, struct fuse_file_info *);
    139 	int	(*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
    140 	int	(*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
    141 	int	(*statfs)(const char *, struct statvfs *);
    142 	int	(*flush)(const char *, struct fuse_file_info *);
    143 	int	(*release)(const char *, struct fuse_file_info *);
    144 	int	(*fsync)(const char *, int, struct fuse_file_info *);
    145 	int	(*setxattr)(const char *, const char *, const char *, size_t, int);
    146 	int	(*getxattr)(const char *, const char *, char *, size_t);
    147 	int	(*listxattr)(const char *, char *, size_t);
    148 	int	(*removexattr)(const char *, const char *);
    149 	int	(*opendir)(const char *, struct fuse_file_info *);
    150 	int	(*readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
    151 	int	(*releasedir)(const char *, struct fuse_file_info *);
    152 	int	(*fsyncdir)(const char *, int, struct fuse_file_info *);
    153 	void	*(*init)(struct fuse_conn_info *);
    154 	void	(*destroy)(void *);
    155 	int	(*access)(const char *, int);
    156 	int	(*create)(const char *, mode_t, struct fuse_file_info *);
    157 	int	(*ftruncate)(const char *, off_t, struct fuse_file_info *);
    158 	int	(*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
    159 	int	(*lock)(const char *, struct fuse_file_info *, int, struct flock *);
    160 	int	(*utimens)(const char *, const struct timespec *);
    161 	int	(*bmap)(const char *, size_t , uint64_t *);
    162 };
    163 
    164 
    165 struct fuse *fuse_new(struct fuse_args *,
    166 	const struct fuse_operations *, size_t, void *);
    167 
    168 int fuse_mount(struct fuse *, const char *);
    169 void fuse_unmount(struct fuse *);
    170 
    171 int fuse_daemonize(struct fuse *);
    172 
    173 int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
    174 int fuse_loop(struct fuse *);
    175 struct fuse_context *fuse_get_context(void);
    176 void fuse_exit(struct fuse *);
    177 void fuse_destroy(struct fuse *);
    178 int fuse_version(void);
    179 
    180 #if FUSE_USE_VERSION == 22
    181 #define fuse_unmount fuse_unmount_compat22
    182 #endif
    183 
    184 void fuse_unmount_compat22(const char *);
    185 
    186 #if FUSE_USE_VERSION >= 26
    187 #define fuse_main(argc, argv, op, user_data) \
    188             fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
    189 #else
    190 #define fuse_main(argc, argv, op) \
    191             fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
    192 #endif
    193 
    194 #ifdef __cplusplus
    195 }
    196 #endif
    197 
    198 #include <fuse_opt.h>
    199 
    200 #endif
    201