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