fuse.h revision 1.3 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 /* equivalent'ish of puffs_cc */
68 struct fuse_context {
69 struct fuse *fuse;
70 uid_t uid;
71 gid_t gid;
72 pid_t pid;
73 void *private_data;
74 };
75
76 #define FUSE_OPT_KEY(templ, key) { templ, -1U, key }
77
78 #define FUSE_OPT_END { .templ = NULL }
79
80 /**
81 * Argument list
82 */
83 struct fuse_args {
84 int argc;
85 char **argv;
86 int allocated;
87 };
88
89 /**
90 * Initializer for 'struct fuse_args'
91 */
92 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
93
94 enum {
95 FUSE_OPT_KEY_OPT = -1,
96 FUSE_OPT_KEY_NONOPT = -2,
97 FUSE_OPT_KEY_KEEP = -3,
98 FUSE_OPT_KEY_DISCARD = -4
99 };
100
101 typedef struct fuse_dirh *fuse_dirh_t;
102
103 typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
104 typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
105
106 #define FUSE_VERSION 26
107
108 /*
109 * These operations shadow those in puffs_usermount, and are used
110 * as a table of callbacks to make when file system requests come
111 * in.
112 */
113 struct fuse_operations {
114 int (*getattr)(const char *, struct stat *);
115 int (*readlink)(const char *, char *, size_t);
116 int (*mknod)(const char *, mode_t, dev_t);
117 int (*mkdir)(const char *, mode_t);
118 int (*unlink)(const char *);
119 int (*rmdir)(const char *);
120 int (*symlink)(const char *, const char *);
121 int (*rename)(const char *, const char *);
122 int (*link)(const char *, const char *);
123 int (*chmod)(const char *, mode_t);
124 int (*chown)(const char *, uid_t, gid_t);
125 int (*truncate)(const char *, off_t);
126 int (*utime)(const char *, struct utimbuf *);
127 int (*open)(const char *, struct fuse_file_info *);
128 int (*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
129 int (*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
130 int (*statfs)(const char *, struct statvfs *);
131 int (*flush)(const char *, struct fuse_file_info *);
132 int (*release)(const char *, struct fuse_file_info *);
133 int (*fsync)(const char *, int, struct fuse_file_info *);
134 int (*setxattr)(const char *, const char *, const char *, size_t, int);
135 int (*getxattr)(const char *, const char *, char *, size_t);
136 int (*listxattr)(const char *, char *, size_t);
137 int (*removexattr)(const char *, const char *);
138 int (*opendir)(const char *, struct fuse_file_info *);
139 int (*readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
140 int (*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
141 int (*releasedir)(const char *, struct fuse_file_info *);
142 int (*fsyncdir)(const char *, int, struct fuse_file_info *);
143 void *(*init)(struct fuse_conn_info *);
144 void (*destroy)(void *);
145 int (*access)(const char *, int);
146 int (*create)(const char *, mode_t, struct fuse_file_info *);
147 int (*ftruncate)(const char *, off_t, struct fuse_file_info *);
148 int (*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
149 int (*lock)(const char *, struct fuse_file_info *, int, struct flock *);
150 int (*utimens)(const char *, const struct timespec *);
151 int (*bmap)(const char *, size_t , uint64_t *);
152 struct puffs_ops puffs_ops; /* pointer to puffs operations */
153 };
154
155
156 typedef int (*fuse_opt_proc_t)(void *, const char *, int, struct fuse_args *);
157
158
159 int fuse_opt_add_arg(struct fuse_args *, const char *);
160 int fuse_opt_parse(struct fuse_args *, void *, const struct fuse_opt *, fuse_opt_proc_t);
161 int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
162 struct fuse_context *fuse_get_context(void);
163
164
165 #define fuse_main(argc, argv, op) \
166 fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
167
168
169 #ifdef __cplusplus
170 }
171 #endif
172
173 #endif
174