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