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