fuse.h revision 1.32 1 /* $NetBSD: fuse.h,v 1.32 2022/01/22 08:03:32 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 <fuse_opt.h>
34 #include <refuse/buf.h>
35 #include <refuse/legacy.h>
36 #include <refuse/poll.h>
37 #include <refuse/session.h>
38 #include <sys/cdefs.h>
39 #include <sys/stat.h>
40 #include <sys/statvfs.h>
41 #include <sys/types.h>
42 #include <utime.h>
43
44 /* This used to be (maj) * 10 + (min) until FUSE 3.10, and then
45 * changed to (maj) * 100 + (min). We can't just use the "newer"
46 * definition because filesystems in the wild still use the older one
47 * in their FUSE_USE_VERSION request. */
48 #define FUSE_MAKE_VERSION(maj, min) \
49 (((maj) > 3 || ((maj) == 3 && (min) >= 10)) \
50 ? (maj) * 100 + (min) \
51 : (maj) * 10 + (min))
52
53 /* The latest version of FUSE API currently provided by ReFUSE. This
54 * is an implementation detail. User code should not rely on this
55 * constant. */
56 #define _REFUSE_MAJOR_VERSION_ 2
57 #define _REFUSE_MINOR_VERSION_ 6
58
59 #define _REFUSE_VERSION_ FUSE_MAKE_VERSION(_REFUSE_MAJOR_VERSION_, _REFUSE_MINOR_VERSION_)
60
61 /* FUSE_USE_VERSION is expected to be defined by user code to
62 * determine the API to be used. Although defining this macro is
63 * mandatory in the original FUSE implementation, refuse hasn't
64 * required this so we only emit a warning if it's undefined. */
65 #if defined(FUSE_USE_VERSION)
66 # if FUSE_USE_VERSION > _REFUSE_VERSION_
67 # warning "The requested API version is higher than the latest one supported by refuse."
68 # elif FUSE_USE_VERSION < 11
69 # warning "The requested API version is lower than the oldest one supported by refuse."
70 # endif
71 #else
72 # if !defined(_REFUSE_IMPLEMENTATION_)
73 # warning "User code including <fuse.h> should define FUSE_USE_VERSION before including this header. Defaulting to the latest version."
74 # define FUSE_USE_VERSION _REFUSE_VERSION_
75 # endif
76 #endif
77
78 /* FUSE_VERSION is supposed to be the latest version of FUSE API
79 * supported by the library. However, due to the way how original FUSE
80 * is implemented, some filesystems set FUSE_USE_VERSION to some old
81 * one and then expect the actual API version exposed by the library
82 * to be something newer if FUSE_VERSION is higher than that. ReFUSE
83 * doesn't work that way, so this has to be always identical to
84 * FUSE_USE_VERSION.
85 */
86 #if defined(FUSE_USE_VERSION)
87 # define FUSE_VERSION FUSE_USE_VERSION
88 # define FUSE_MAJOR_VERSION (FUSE_VERSION / 10)
89 # define FUSE_MINOR_VERSION (FUSE_VERSION % 10)
90 #endif
91
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
95
96 struct fuse;
97 struct fuse_args; /* XXXsupportme */
98
99 struct fuse_file_info {
100 int32_t flags;
101 uint32_t fh_old;
102 int32_t writepage;
103 uint32_t direct_io:1;
104 uint32_t keep_cache:1;
105 uint32_t flush:1;
106 uint32_t padding:29;
107 uint64_t fh;
108 uint64_t lock_owner;
109 };
110
111 struct fuse_conn_info {
112 uint32_t proto_major;
113 uint32_t proto_minor;
114 uint32_t async_read;
115 uint32_t max_write;
116 uint32_t max_readahead;
117 uint32_t reserved[27];
118 };
119
120 /* equivalent'ish of puffs_cc */
121 struct fuse_context {
122 struct fuse *fuse;
123 uid_t uid;
124 gid_t gid;
125 pid_t pid;
126 void *private_data;
127 };
128
129 /**
130 * Argument list
131 */
132 struct fuse_args {
133 int argc;
134 char **argv;
135 int allocated;
136 };
137
138 /**
139 * Initializer for 'struct fuse_args'
140 */
141 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
142
143
144 typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
145 typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
146
147 /*
148 * These operations shadow those in puffs_usermount, and are used
149 * as a table of callbacks to make when file system requests come
150 * in.
151 *
152 * NOTE: keep same order as fuse
153 */
154 struct fuse_operations {
155 int (*getattr)(const char *, struct stat *);
156 int (*readlink)(const char *, char *, size_t);
157 int (*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
158 int (*mknod)(const char *, mode_t, dev_t);
159 int (*mkdir)(const char *, mode_t);
160 int (*unlink)(const char *);
161 int (*rmdir)(const char *);
162 int (*symlink)(const char *, const char *);
163 int (*rename)(const char *, const char *);
164 int (*link)(const char *, const char *);
165 int (*chmod)(const char *, mode_t);
166 int (*chown)(const char *, uid_t, gid_t);
167 int (*truncate)(const char *, off_t);
168 int (*utime)(const char *, struct utimbuf *);
169 int (*open)(const char *, struct fuse_file_info *);
170 int (*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
171 int (*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
172 int (*statfs)(const char *, struct statvfs *);
173 int (*flush)(const char *, struct fuse_file_info *);
174 int (*release)(const char *, struct fuse_file_info *);
175 int (*fsync)(const char *, int, struct fuse_file_info *);
176 int (*setxattr)(const char *, const char *, const char *, size_t, int);
177 int (*getxattr)(const char *, const char *, char *, size_t);
178 int (*listxattr)(const char *, char *, size_t);
179 int (*removexattr)(const char *, const char *);
180 int (*opendir)(const char *, struct fuse_file_info *);
181 int (*readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
182 int (*releasedir)(const char *, struct fuse_file_info *);
183 int (*fsyncdir)(const char *, int, struct fuse_file_info *);
184 void *(*init)(struct fuse_conn_info *);
185 void (*destroy)(void *);
186 int (*access)(const char *, int);
187 int (*create)(const char *, mode_t, struct fuse_file_info *);
188 int (*ftruncate)(const char *, off_t, struct fuse_file_info *);
189 int (*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
190 int (*lock)(const char *, struct fuse_file_info *, int, struct flock *);
191 int (*utimens)(const char *, const struct timespec *);
192 int (*bmap)(const char *, size_t , uint64_t *);
193 };
194
195
196 struct fuse *fuse_new(struct fuse_args *,
197 const struct fuse_operations *, size_t, void *);
198
199 int fuse_mount(struct fuse *, const char *);
200 void fuse_unmount(struct fuse *);
201
202 int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
203 /* Functions that have existed since the beginning and have never
204 * changed between API versions. */
205 int fuse_loop(struct fuse *);
206 void fuse_exit(struct fuse *);
207 void fuse_destroy(struct fuse *);
208 struct fuse_context *fuse_get_context(void);
209
210 /* Print available library options. Appeared on FUSE 3.1. */
211 void fuse_lib_help(struct fuse_args *args);
212
213 /* Daemonize the calling process. Appeared on FUSE 2.6.
214 *
215 * NOTE: This function used to have a wrong prototype in librefuse at
216 * the time when FUSE_H_ < 20211204. */
217 int fuse_daemonize(int foreground) __RENAME(fuse_daemonize_rev1);
218
219 /* Check if a request has been interrupted. Appeared on FUSE 2.6. */
220 int fuse_interrupted(void);
221
222 /* Invalidate cache for a given path. Appeared on FUSE 3.2. */
223 int fuse_invalidate_path(struct fuse *fuse, const char *path);
224
225 /* Get the version number of the library. Appeared on FUSE 2.7. */
226 int fuse_version(void);
227
228 #if FUSE_USE_VERSION == 22
229 #define fuse_unmount fuse_unmount_compat22
230 #endif
231
232 void fuse_unmount_compat22(const char *);
233
234 #if FUSE_USE_VERSION >= 26
235 #define fuse_main(argc, argv, op, user_data) \
236 fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
237 #else
238 #define fuse_main(argc, argv, op) \
239 fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
240 #endif
241 /* Get the version string of the library. Appeared on FUSE 3.0. */
242 const char *fuse_pkgversion(void);
243
244 /* Get the current supplementary group IDs for the current request, or
245 * return -errno on failure. Appeared on FUSE 2.8. */
246 int fuse_getgroups(int size, gid_t list[]);
247
248 /* Start the cleanup thread when using option "-oremember". Appeared
249 * on FUSE 2.9. */
250 int fuse_start_cleanup_thread(struct fuse *fuse);
251
252 /* Stop the cleanup thread when using "-oremember". Appeared on FUSE
253 * 2.9. */
254 void fuse_stop_cleanup_thread(struct fuse *fuse);
255
256 /* Iterate over cache removing stale entries, used in conjunction with
257 * "-oremember". Return the number of seconds until the next
258 * cleanup. Appeared on FUSE 2.9. */
259 int fuse_clean_cache(struct fuse *fuse);
260
261 #ifdef __cplusplus
262 }
263 #endif
264
265 #endif
266