Home | History | Annotate | Line # | Download | only in librefuse
fuse.h revision 1.1
      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_file_info {
     41 	int32_t		flags;
     42 	uint32_t	fh_old;
     43 	int32_t		writepage;
     44 	uint32_t	direct_io:1;
     45 	uint32_t	keep_cache:1;
     46 	uint32_t	flush:1;
     47 	uint32_t	padding:29;
     48 	uint64_t	fh;
     49 	uint64_t	lock_owner;
     50 };
     51 
     52 struct fuse_conn_info {
     53 	uint32_t proto_major;
     54 	uint32_t proto_minor;
     55 	uint32_t async_read;
     56 	uint32_t max_write;
     57 	uint32_t max_readahead;
     58 	uint32_t reserved[27];
     59 };
     60 
     61 struct fuse_opt {
     62 	const char	*templ;
     63 	uint32_t	offset;
     64 	int32_t		value;
     65 };
     66 
     67 #define FUSE_OPT_KEY(templ, key) { templ, -1U, key }
     68 
     69 #define FUSE_OPT_END { .templ = NULL }
     70 
     71 /**
     72  * Argument list
     73  */
     74 struct fuse_args {
     75 	int	argc;
     76 	char	**argv;
     77 	int	allocated;
     78 };
     79 
     80 /**
     81  * Initializer for 'struct fuse_args'
     82  */
     83 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
     84 
     85 enum {
     86 	FUSE_OPT_KEY_OPT = -1,
     87 	FUSE_OPT_KEY_NONOPT = -2,
     88 	FUSE_OPT_KEY_KEEP = -3,
     89 	FUSE_OPT_KEY_DISCARD = -4
     90 };
     91 
     92 typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
     93 
     94 #define FUSE_VERSION	26
     95 
     96 /*
     97  * These operations shadow those in puffs_usermount, and are used
     98  * as a table of callbacks to make when file system requests come
     99  * in.
    100  */
    101 struct fuse_operations {
    102 	int	(*getattr)(const char *, struct stat *);
    103 	int	(*readlink)(const char *, char *, size_t);
    104 	int	(*mknod)(const char *, mode_t, dev_t);
    105 	int	(*mkdir)(const char *, mode_t);
    106 	int	(*unlink)(const char *);
    107 	int	(*rmdir)(const char *);
    108 	int	(*symlink)(const char *, const char *);
    109 	int	(*rename)(const char *, const char *);
    110 	int	(*link)(const char *, const char *);
    111 	int	(*chmod)(const char *, mode_t);
    112 	int	(*chown)(const char *, uid_t, gid_t);
    113 	int	(*truncate)(const char *, off_t);
    114 	int	(*utime)(const char *, struct utimbuf *);
    115 	int	(*open)(const char *, struct fuse_file_info *);
    116 	int	(*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
    117 	int	(*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
    118 	int	(*statfs)(const char *, struct statvfs *);
    119 	int	(*flush)(const char *, struct fuse_file_info *);
    120 	int	(*release)(const char *, struct fuse_file_info *);
    121 	int	(*fsync)(const char *, int, struct fuse_file_info *);
    122 	int	(*setxattr)(const char *, const char *, const char *, size_t, int);
    123 	int	(*getxattr)(const char *, const char *, char *, size_t);
    124 	int	(*listxattr)(const char *, char *, size_t);
    125 	int	(*removexattr)(const char *, const char *);
    126 	int	(*opendir)(const char *, struct fuse_file_info *);
    127 	int	(*readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
    128 	int	(*releasedir)(const char *, struct fuse_file_info *);
    129 	int	(*fsyncdir)(const char *, int, struct fuse_file_info *);
    130 	void	*(*init)(struct fuse_conn_info *);
    131 	void	(*destroy)(void *);
    132 	int	(*access)(const char *, int);
    133 	int	(*create)(const char *, mode_t, struct fuse_file_info *);
    134 	int	(*ftruncate)(const char *, off_t, struct fuse_file_info *);
    135 	int	(*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
    136 	int	(*lock)(const char *, struct fuse_file_info *, int, struct flock *);
    137 	int	(*utimens)(const char *, const struct timespec *);
    138 	int	(*bmap)(const char *, size_t , uint64_t *);
    139 	struct puffs_ops	puffs_ops;	/* pointer to puffs operations */
    140 };
    141 
    142 
    143 typedef int (*fuse_opt_proc_t)(void *, const char *, int, struct fuse_args *);
    144 
    145 
    146 int fuse_opt_add_arg(struct fuse_args *, const char *);
    147 int fuse_opt_parse(struct fuse_args *, void *, const struct fuse_opt *, fuse_opt_proc_t);
    148 int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
    149 
    150 
    151 #define fuse_main(argc, argv, op) \
    152             fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
    153 
    154 
    155 #ifdef __cplusplus
    156 }
    157 #endif
    158 
    159 #endif
    160