fs.c revision 1.1 1 1.1 pho /* $NetBSD: fs.c,v 1.1 2022/01/22 08:09:40 pho Exp $ */
2 1.1 pho
3 1.1 pho /*
4 1.1 pho * Copyright (c) 2021 The NetBSD Foundation, Inc.
5 1.1 pho * All rights reserved.
6 1.1 pho *
7 1.1 pho * Redistribution and use in source and binary forms, with or without
8 1.1 pho * modification, are permitted provided that the following conditions
9 1.1 pho * are met:
10 1.1 pho * 1. Redistributions of source code must retain the above copyright
11 1.1 pho * notice, this list of conditions and the following disclaimer.
12 1.1 pho * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 pho * notice, this list of conditions and the following disclaimer in the
14 1.1 pho * documentation and/or other materials provided with the distribution.
15 1.1 pho * 3. The name of the author may not be used to endorse or promote
16 1.1 pho * products derived from this software without specific prior written
17 1.1 pho * permission.
18 1.1 pho *
19 1.1 pho * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 1.1 pho * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 1.1 pho * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 pho * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 1.1 pho * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 pho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 1.1 pho * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 1.1 pho * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 1.1 pho * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 1.1 pho * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 pho */
31 1.1 pho
32 1.1 pho #include <sys/cdefs.h>
33 1.1 pho #if !defined(lint)
34 1.1 pho __RCSID("$NetBSD: fs.c,v 1.1 2022/01/22 08:09:40 pho Exp $");
35 1.1 pho #endif /* !lint */
36 1.1 pho
37 1.1 pho /*
38 1.1 pho * Filesystem Stacking API, appeared on FUSE 2.7.
39 1.1 pho *
40 1.1 pho * So many callback functions in struct fuse_operations have different
41 1.1 pho * prototypes between versions. We use the stacking API to abstract
42 1.1 pho * that away to implement puffs operations in a manageable way.
43 1.1 pho */
44 1.1 pho
45 1.1 pho #include <err.h>
46 1.1 pho #include <fuse_internal.h>
47 1.1 pho #include <stdlib.h>
48 1.1 pho #include <string.h>
49 1.1 pho #include <sys/dirent.h>
50 1.1 pho #include <sys/errno.h>
51 1.1 pho
52 1.1 pho struct fuse_fs {
53 1.1 pho void* op;
54 1.1 pho int op_version;
55 1.1 pho void* user_data;
56 1.1 pho };
57 1.1 pho
58 1.1 pho #define UNKNOWN_VERSION(op_version) \
59 1.1 pho errc(EXIT_FAILURE, ENOSYS, "%s: unknown fuse_operations version: %d", \
60 1.1 pho __func__, op_version)
61 1.1 pho
62 1.1 pho static void*
63 1.1 pho clone_op(const void* op, int op_version) {
64 1.1 pho void* cloned;
65 1.1 pho
66 1.1 pho switch (op_version) {
67 1.1 pho #define CLONE_OP(VER) \
68 1.1 pho case VER: \
69 1.1 pho cloned = malloc(sizeof(struct __CONCAT(fuse_operations_v,VER))); \
70 1.1 pho if (!cloned) \
71 1.1 pho return NULL; \
72 1.1 pho memcpy(cloned, op, sizeof(struct __CONCAT(fuse_operations_v,VER))); \
73 1.1 pho return cloned
74 1.1 pho
75 1.1 pho CLONE_OP(11);
76 1.1 pho CLONE_OP(21);
77 1.1 pho CLONE_OP(22);
78 1.1 pho CLONE_OP(23);
79 1.1 pho CLONE_OP(25);
80 1.1 pho CLONE_OP(26);
81 1.1 pho CLONE_OP(28);
82 1.1 pho CLONE_OP(29);
83 1.1 pho CLONE_OP(30);
84 1.1 pho CLONE_OP(34);
85 1.1 pho CLONE_OP(35);
86 1.1 pho CLONE_OP(38);
87 1.1 pho #undef CLONE_OP
88 1.1 pho default:
89 1.1 pho UNKNOWN_VERSION(op_version);
90 1.1 pho }
91 1.1 pho }
92 1.1 pho
93 1.1 pho struct fuse_fs*
94 1.1 pho __fuse_fs_new(const void* op, int op_version, void* user_data) {
95 1.1 pho struct fuse_fs* fs;
96 1.1 pho
97 1.1 pho fs = malloc(sizeof(struct fuse_fs));
98 1.1 pho if (!fs)
99 1.1 pho err(EXIT_FAILURE, __func__);
100 1.1 pho
101 1.1 pho /* Callers aren't obliged to keep "op" valid during the lifetime
102 1.1 pho * of struct fuse_fs*. We must clone it now, even though it's
103 1.1 pho * non-trivial. */
104 1.1 pho fs->op = clone_op(op, op_version);
105 1.1 pho if (!fs->op)
106 1.1 pho err(EXIT_FAILURE, __func__);
107 1.1 pho
108 1.1 pho fs->op_version = op_version;
109 1.1 pho fs->user_data = user_data;
110 1.1 pho
111 1.1 pho return fs;
112 1.1 pho }
113 1.1 pho
114 1.1 pho /* Clobber the context private_data with that of this filesystem
115 1.1 pho * layer. This function needs to be called before invoking any of
116 1.1 pho * operation callbacks. */
117 1.1 pho static void
118 1.1 pho clobber_context_user_data(struct fuse_fs* fs) {
119 1.1 pho fuse_get_context()->private_data = fs->user_data;
120 1.1 pho }
121 1.1 pho
122 1.1 pho /* Ugly... These are like hand-written vtables... */
123 1.1 pho int
124 1.1 pho fuse_fs_getattr_v27(struct fuse_fs *fs, const char *path, struct stat *buf) {
125 1.1 pho return fuse_fs_getattr_v30(fs, path, buf, NULL);
126 1.1 pho }
127 1.1 pho
128 1.1 pho int
129 1.1 pho fuse_fs_getattr_v30(struct fuse_fs* fs, const char* path,
130 1.1 pho struct stat* buf, struct fuse_file_info* fi) {
131 1.1 pho clobber_context_user_data(fs);
132 1.1 pho switch (fs->op_version) {
133 1.1 pho #define CALL_OLD_GETATTR(VER) \
134 1.1 pho case VER: \
135 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr) \
136 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr(path, buf); \
137 1.1 pho else \
138 1.1 pho return -ENOSYS
139 1.1 pho CALL_OLD_GETATTR(11);
140 1.1 pho CALL_OLD_GETATTR(21);
141 1.1 pho CALL_OLD_GETATTR(22);
142 1.1 pho CALL_OLD_GETATTR(23);
143 1.1 pho CALL_OLD_GETATTR(25);
144 1.1 pho CALL_OLD_GETATTR(26);
145 1.1 pho CALL_OLD_GETATTR(28);
146 1.1 pho CALL_OLD_GETATTR(29);
147 1.1 pho #undef CALL_OLD_GETATTR
148 1.1 pho
149 1.1 pho #define CALL_GETATTR(VER) \
150 1.1 pho case VER: \
151 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr) \
152 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr(path, buf, fi); \
153 1.1 pho else \
154 1.1 pho return -ENOSYS
155 1.1 pho CALL_GETATTR(30);
156 1.1 pho CALL_GETATTR(34);
157 1.1 pho CALL_GETATTR(38);
158 1.1 pho #undef CALL_GETATTR
159 1.1 pho default:
160 1.1 pho UNKNOWN_VERSION(fs->op_version);
161 1.1 pho }
162 1.1 pho }
163 1.1 pho
164 1.1 pho int
165 1.1 pho fuse_fs_fgetattr(struct fuse_fs* fs, const char* path, struct stat* buf,
166 1.1 pho struct fuse_file_info* fi) {
167 1.1 pho clobber_context_user_data(fs);
168 1.1 pho /* fgetattr() was introduced on FUSE 2.5 then disappeared on FUSE
169 1.1 pho * 3.0. Fall back to getattr() if it's missing. */
170 1.1 pho switch (fs->op_version) {
171 1.1 pho case 11:
172 1.1 pho case 21:
173 1.1 pho case 22:
174 1.1 pho case 23:
175 1.1 pho return fuse_fs_getattr_v30(fs, path, buf, fi);
176 1.1 pho
177 1.1 pho #define CALL_FGETATTR_OR_OLD_GETATTR(VER) \
178 1.1 pho case VER: \
179 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fgetattr) \
180 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fgetattr(path, buf, fi); \
181 1.1 pho else if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr) \
182 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getattr(path, buf); \
183 1.1 pho else \
184 1.1 pho return -ENOSYS
185 1.1 pho CALL_FGETATTR_OR_OLD_GETATTR(25);
186 1.1 pho CALL_FGETATTR_OR_OLD_GETATTR(26);
187 1.1 pho CALL_FGETATTR_OR_OLD_GETATTR(28);
188 1.1 pho CALL_FGETATTR_OR_OLD_GETATTR(29);
189 1.1 pho #undef CALL_FGETATTR_OR_OLD_GETATTR
190 1.1 pho
191 1.1 pho case 30:
192 1.1 pho case 34:
193 1.1 pho case 38:
194 1.1 pho return fuse_fs_getattr_v30(fs, path, buf, fi);
195 1.1 pho default:
196 1.1 pho UNKNOWN_VERSION(fs->op_version);
197 1.1 pho }
198 1.1 pho }
199 1.1 pho
200 1.1 pho int
201 1.1 pho fuse_fs_rename_v27(struct fuse_fs* fs, const char* oldpath, const char* newpath) {
202 1.1 pho return fuse_fs_rename_v30(fs, oldpath, newpath, 0);
203 1.1 pho }
204 1.1 pho
205 1.1 pho int
206 1.1 pho fuse_fs_rename_v30(struct fuse_fs* fs, const char* oldpath,
207 1.1 pho const char* newpath, unsigned int flags) {
208 1.1 pho clobber_context_user_data(fs);
209 1.1 pho switch (fs->op_version) {
210 1.1 pho #define CALL_OLD_RENAME(VER) \
211 1.1 pho case VER: \
212 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rename) \
213 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rename(oldpath, newpath); \
214 1.1 pho else \
215 1.1 pho return -ENOSYS
216 1.1 pho CALL_OLD_RENAME(11);
217 1.1 pho CALL_OLD_RENAME(21);
218 1.1 pho CALL_OLD_RENAME(22);
219 1.1 pho CALL_OLD_RENAME(23);
220 1.1 pho CALL_OLD_RENAME(25);
221 1.1 pho CALL_OLD_RENAME(26);
222 1.1 pho CALL_OLD_RENAME(28);
223 1.1 pho CALL_OLD_RENAME(29);
224 1.1 pho #undef CALL_OLD_RENAME
225 1.1 pho
226 1.1 pho #define CALL_RENAME(VER) \
227 1.1 pho case VER: \
228 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rename) \
229 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rename(oldpath, newpath, flags); \
230 1.1 pho else \
231 1.1 pho return -ENOSYS
232 1.1 pho CALL_RENAME(30);
233 1.1 pho CALL_RENAME(34);
234 1.1 pho CALL_RENAME(38);
235 1.1 pho #undef CALL_RENAME
236 1.1 pho default:
237 1.1 pho UNKNOWN_VERSION(fs->op_version);
238 1.1 pho }
239 1.1 pho }
240 1.1 pho
241 1.1 pho int
242 1.1 pho fuse_fs_unlink(struct fuse_fs* fs, const char* path) {
243 1.1 pho clobber_context_user_data(fs);
244 1.1 pho switch (fs->op_version) {
245 1.1 pho #define CALL_UNLINK(VER) \
246 1.1 pho case VER: \
247 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->unlink) \
248 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->unlink(path); \
249 1.1 pho else \
250 1.1 pho return -ENOSYS
251 1.1 pho CALL_UNLINK(11);
252 1.1 pho CALL_UNLINK(21);
253 1.1 pho CALL_UNLINK(22);
254 1.1 pho CALL_UNLINK(23);
255 1.1 pho CALL_UNLINK(25);
256 1.1 pho CALL_UNLINK(26);
257 1.1 pho CALL_UNLINK(28);
258 1.1 pho CALL_UNLINK(29);
259 1.1 pho CALL_UNLINK(30);
260 1.1 pho CALL_UNLINK(34);
261 1.1 pho CALL_UNLINK(38);
262 1.1 pho #undef CALL_UNLINK
263 1.1 pho default:
264 1.1 pho UNKNOWN_VERSION(fs->op_version);
265 1.1 pho }
266 1.1 pho }
267 1.1 pho
268 1.1 pho int
269 1.1 pho fuse_fs_rmdir(struct fuse_fs* fs, const char* path) {
270 1.1 pho clobber_context_user_data(fs);
271 1.1 pho switch (fs->op_version) {
272 1.1 pho #define CALL_RMDIR(VER) \
273 1.1 pho case VER: \
274 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rmdir) \
275 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->rmdir(path); \
276 1.1 pho else \
277 1.1 pho return -ENOSYS
278 1.1 pho CALL_RMDIR(11);
279 1.1 pho CALL_RMDIR(21);
280 1.1 pho CALL_RMDIR(22);
281 1.1 pho CALL_RMDIR(23);
282 1.1 pho CALL_RMDIR(25);
283 1.1 pho CALL_RMDIR(26);
284 1.1 pho CALL_RMDIR(28);
285 1.1 pho CALL_RMDIR(29);
286 1.1 pho CALL_RMDIR(30);
287 1.1 pho CALL_RMDIR(34);
288 1.1 pho CALL_RMDIR(38);
289 1.1 pho #undef CALL_RMDIR
290 1.1 pho default:
291 1.1 pho UNKNOWN_VERSION(fs->op_version);
292 1.1 pho }
293 1.1 pho }
294 1.1 pho
295 1.1 pho int
296 1.1 pho fuse_fs_symlink(struct fuse_fs* fs, const char* linkname, const char* path) {
297 1.1 pho clobber_context_user_data(fs);
298 1.1 pho switch (fs->op_version) {
299 1.1 pho #define CALL_SYMLINK(VER) \
300 1.1 pho case VER: \
301 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->symlink) \
302 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->symlink(linkname, path); \
303 1.1 pho else \
304 1.1 pho return -ENOSYS
305 1.1 pho CALL_SYMLINK(11);
306 1.1 pho CALL_SYMLINK(21);
307 1.1 pho CALL_SYMLINK(22);
308 1.1 pho CALL_SYMLINK(23);
309 1.1 pho CALL_SYMLINK(25);
310 1.1 pho CALL_SYMLINK(26);
311 1.1 pho CALL_SYMLINK(28);
312 1.1 pho CALL_SYMLINK(29);
313 1.1 pho CALL_SYMLINK(30);
314 1.1 pho CALL_SYMLINK(34);
315 1.1 pho CALL_SYMLINK(38);
316 1.1 pho #undef CALL_SYMLINK
317 1.1 pho default:
318 1.1 pho UNKNOWN_VERSION(fs->op_version);
319 1.1 pho }
320 1.1 pho }
321 1.1 pho
322 1.1 pho int
323 1.1 pho fuse_fs_link(struct fuse_fs* fs, const char* oldpath, const char* newpath) {
324 1.1 pho clobber_context_user_data(fs);
325 1.1 pho switch (fs->op_version) {
326 1.1 pho #define CALL_LINK(VER) \
327 1.1 pho case VER: \
328 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->link) \
329 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->link(oldpath, newpath); \
330 1.1 pho else \
331 1.1 pho return -ENOSYS
332 1.1 pho CALL_LINK(11);
333 1.1 pho CALL_LINK(21);
334 1.1 pho CALL_LINK(22);
335 1.1 pho CALL_LINK(23);
336 1.1 pho CALL_LINK(25);
337 1.1 pho CALL_LINK(26);
338 1.1 pho CALL_LINK(28);
339 1.1 pho CALL_LINK(29);
340 1.1 pho CALL_LINK(30);
341 1.1 pho CALL_LINK(34);
342 1.1 pho CALL_LINK(38);
343 1.1 pho #undef CALL_LINK
344 1.1 pho default:
345 1.1 pho UNKNOWN_VERSION(fs->op_version);
346 1.1 pho }
347 1.1 pho }
348 1.1 pho
349 1.1 pho int
350 1.1 pho fuse_fs_release(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
351 1.1 pho clobber_context_user_data(fs);
352 1.1 pho switch (fs->op_version) {
353 1.1 pho #define CALL_OLD_RELEASE(VER) \
354 1.1 pho case VER: \
355 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->release) \
356 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->release(path, fi->flags); \
357 1.1 pho else \
358 1.1 pho return 0 /* Special case */
359 1.1 pho CALL_OLD_RELEASE(11);
360 1.1 pho CALL_OLD_RELEASE(21);
361 1.1 pho #undef CALL_OLD_RELEASE
362 1.1 pho
363 1.1 pho #define CALL_RELEASE(VER) \
364 1.1 pho case VER: \
365 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->release) \
366 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->release(path, fi); \
367 1.1 pho else \
368 1.1 pho return 0 /* Special case */
369 1.1 pho CALL_RELEASE(22);
370 1.1 pho CALL_RELEASE(23);
371 1.1 pho CALL_RELEASE(25);
372 1.1 pho CALL_RELEASE(26);
373 1.1 pho CALL_RELEASE(28);
374 1.1 pho CALL_RELEASE(29);
375 1.1 pho CALL_RELEASE(30);
376 1.1 pho CALL_RELEASE(34);
377 1.1 pho CALL_RELEASE(38);
378 1.1 pho #undef CALL_RELEASE
379 1.1 pho default:
380 1.1 pho UNKNOWN_VERSION(fs->op_version);
381 1.1 pho }
382 1.1 pho }
383 1.1 pho
384 1.1 pho int
385 1.1 pho fuse_fs_open(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
386 1.1 pho clobber_context_user_data(fs);
387 1.1 pho switch (fs->op_version) {
388 1.1 pho #define CALL_OLD_OPEN(VER) \
389 1.1 pho case VER: \
390 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->open) \
391 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->open(path, fi->flags); \
392 1.1 pho else \
393 1.1 pho return 0 /* Special case */
394 1.1 pho CALL_OLD_OPEN(11);
395 1.1 pho CALL_OLD_OPEN(21);
396 1.1 pho #undef CALL_OLD_OPEN
397 1.1 pho
398 1.1 pho #define CALL_OPEN(VER) \
399 1.1 pho case VER: \
400 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->open) \
401 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->open(path, fi); \
402 1.1 pho else \
403 1.1 pho return 0 /* Special case */
404 1.1 pho CALL_OPEN(22);
405 1.1 pho CALL_OPEN(23);
406 1.1 pho CALL_OPEN(25);
407 1.1 pho CALL_OPEN(26);
408 1.1 pho CALL_OPEN(28);
409 1.1 pho CALL_OPEN(29);
410 1.1 pho CALL_OPEN(30);
411 1.1 pho CALL_OPEN(34);
412 1.1 pho CALL_OPEN(38);
413 1.1 pho #undef CALL_OPEN
414 1.1 pho default:
415 1.1 pho UNKNOWN_VERSION(fs->op_version);
416 1.1 pho }
417 1.1 pho }
418 1.1 pho
419 1.1 pho int
420 1.1 pho fuse_fs_read(struct fuse_fs* fs, const char* path, char* buf,
421 1.1 pho size_t size, off_t off, struct fuse_file_info* fi) {
422 1.1 pho clobber_context_user_data(fs);
423 1.1 pho switch (fs->op_version) {
424 1.1 pho #define CALL_OLD_READ(VER) \
425 1.1 pho case VER: \
426 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read) \
427 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read(path, buf, size, off); \
428 1.1 pho else \
429 1.1 pho return -ENOSYS
430 1.1 pho CALL_OLD_READ(11);
431 1.1 pho CALL_OLD_READ(21);
432 1.1 pho #undef CALL_OLD_READ
433 1.1 pho
434 1.1 pho #define CALL_READ(VER) \
435 1.1 pho case VER: \
436 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read) \
437 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read(path, buf, size, off, fi); \
438 1.1 pho else \
439 1.1 pho return -ENOSYS
440 1.1 pho CALL_READ(22);
441 1.1 pho CALL_READ(23);
442 1.1 pho CALL_READ(25);
443 1.1 pho CALL_READ(26);
444 1.1 pho CALL_READ(28);
445 1.1 pho CALL_READ(29);
446 1.1 pho CALL_READ(30);
447 1.1 pho CALL_READ(34);
448 1.1 pho CALL_READ(38);
449 1.1 pho #undef CALL_READ
450 1.1 pho default:
451 1.1 pho UNKNOWN_VERSION(fs->op_version);
452 1.1 pho }
453 1.1 pho }
454 1.1 pho
455 1.1 pho int
456 1.1 pho fuse_fs_read_buf(struct fuse_fs* fs, const char* path,
457 1.1 pho struct fuse_bufvec** bufp, size_t size, off_t off,
458 1.1 pho struct fuse_file_info* fi) {
459 1.1 pho clobber_context_user_data(fs);
460 1.1 pho switch (fs->op_version) {
461 1.1 pho /* FUSE < 2.9 didn't have read_buf(). */
462 1.1 pho case 11:
463 1.1 pho case 21:
464 1.1 pho case 22:
465 1.1 pho case 23:
466 1.1 pho case 25:
467 1.1 pho case 26:
468 1.1 pho case 28:
469 1.1 pho return -ENOSYS;
470 1.1 pho #define CALL_READ_BUF(VER) \
471 1.1 pho case VER: \
472 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read_buf) \
473 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->read_buf(path, bufp, size, off, fi); \
474 1.1 pho else \
475 1.1 pho return -ENOSYS
476 1.1 pho CALL_READ_BUF(29);
477 1.1 pho CALL_READ_BUF(30);
478 1.1 pho CALL_READ_BUF(34);
479 1.1 pho CALL_READ_BUF(38);
480 1.1 pho #undef CALL_READ_BUF
481 1.1 pho default:
482 1.1 pho UNKNOWN_VERSION(fs->op_version);
483 1.1 pho }
484 1.1 pho }
485 1.1 pho
486 1.1 pho int
487 1.1 pho fuse_fs_write(struct fuse_fs* fs, const char* path, const char* buf,
488 1.1 pho size_t size, off_t off, struct fuse_file_info* fi) {
489 1.1 pho clobber_context_user_data(fs);
490 1.1 pho switch (fs->op_version) {
491 1.1 pho #define CALL_OLD_WRITE(VER) \
492 1.1 pho case VER: \
493 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write) \
494 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write(path, buf, size, off); \
495 1.1 pho else \
496 1.1 pho return -ENOSYS
497 1.1 pho CALL_OLD_WRITE(11);
498 1.1 pho CALL_OLD_WRITE(21);
499 1.1 pho #undef CALL_OLD_WRITE
500 1.1 pho
501 1.1 pho #define CALL_WRITE(VER) \
502 1.1 pho case VER: \
503 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write) \
504 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write(path, buf, size, off, fi); \
505 1.1 pho else \
506 1.1 pho return -ENOSYS
507 1.1 pho CALL_WRITE(22);
508 1.1 pho CALL_WRITE(23);
509 1.1 pho CALL_WRITE(25);
510 1.1 pho CALL_WRITE(26);
511 1.1 pho CALL_WRITE(28);
512 1.1 pho CALL_WRITE(29);
513 1.1 pho CALL_WRITE(30);
514 1.1 pho CALL_WRITE(34);
515 1.1 pho CALL_WRITE(38);
516 1.1 pho #undef CALL_WRITE
517 1.1 pho default:
518 1.1 pho UNKNOWN_VERSION(fs->op_version);
519 1.1 pho }
520 1.1 pho }
521 1.1 pho
522 1.1 pho int
523 1.1 pho fuse_fs_write_buf(struct fuse_fs* fs, const char* path,
524 1.1 pho struct fuse_bufvec* bufp, off_t off,
525 1.1 pho struct fuse_file_info* fi) {
526 1.1 pho clobber_context_user_data(fs);
527 1.1 pho switch (fs->op_version) {
528 1.1 pho /* FUSE < 2.9 didn't have write_buf(). */
529 1.1 pho case 11:
530 1.1 pho case 21:
531 1.1 pho case 22:
532 1.1 pho case 23:
533 1.1 pho case 25:
534 1.1 pho case 26:
535 1.1 pho case 28:
536 1.1 pho return -ENOSYS;
537 1.1 pho #define CALL_WRITE_BUF(VER) \
538 1.1 pho case VER: \
539 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write_buf) \
540 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->write_buf(path, bufp, off, fi); \
541 1.1 pho else \
542 1.1 pho return -ENOSYS
543 1.1 pho CALL_WRITE_BUF(29);
544 1.1 pho CALL_WRITE_BUF(30);
545 1.1 pho CALL_WRITE_BUF(34);
546 1.1 pho CALL_WRITE_BUF(38);
547 1.1 pho #undef CALL_WRITE_BUF
548 1.1 pho default:
549 1.1 pho UNKNOWN_VERSION(fs->op_version);
550 1.1 pho }
551 1.1 pho }
552 1.1 pho
553 1.1 pho int
554 1.1 pho fuse_fs_fsync(struct fuse_fs* fs, const char* path, int datasync, struct fuse_file_info* fi) {
555 1.1 pho clobber_context_user_data(fs);
556 1.1 pho switch (fs->op_version) {
557 1.1 pho #define CALL_OLD_FSYNC(VER) \
558 1.1 pho case VER: \
559 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsync) \
560 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsync(path, datasync); \
561 1.1 pho else \
562 1.1 pho return -ENOSYS
563 1.1 pho CALL_OLD_FSYNC(11);
564 1.1 pho CALL_OLD_FSYNC(21);
565 1.1 pho #undef CALL_OLD_FSYNC
566 1.1 pho
567 1.1 pho #define CALL_FSYNC(VER) \
568 1.1 pho case VER: \
569 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsync) \
570 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsync(path, datasync, fi); \
571 1.1 pho else \
572 1.1 pho return -ENOSYS
573 1.1 pho CALL_FSYNC(22);
574 1.1 pho CALL_FSYNC(23);
575 1.1 pho CALL_FSYNC(25);
576 1.1 pho CALL_FSYNC(26);
577 1.1 pho CALL_FSYNC(28);
578 1.1 pho CALL_FSYNC(29);
579 1.1 pho CALL_FSYNC(30);
580 1.1 pho CALL_FSYNC(34);
581 1.1 pho CALL_FSYNC(38);
582 1.1 pho #undef CALL_FSYNC
583 1.1 pho default:
584 1.1 pho UNKNOWN_VERSION(fs->op_version);
585 1.1 pho }
586 1.1 pho }
587 1.1 pho
588 1.1 pho int
589 1.1 pho fuse_fs_flush(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
590 1.1 pho clobber_context_user_data(fs);
591 1.1 pho /* flush() appeared on FUSE 2.1 and its prototype was changed on
592 1.1 pho * 2.2. */
593 1.1 pho switch (fs->op_version) {
594 1.1 pho case 11:
595 1.1 pho return -ENOSYS;
596 1.1 pho case 21:
597 1.1 pho if (((const struct fuse_operations_v21 *)fs->op)->flush)
598 1.1 pho return ((const struct fuse_operations_v21 *)fs->op)->flush(path);
599 1.1 pho else
600 1.1 pho return -ENOSYS;
601 1.1 pho
602 1.1 pho #define CALL_FLUSH(VER) \
603 1.1 pho case VER: \
604 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->flush) \
605 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->flush(path, fi); \
606 1.1 pho else \
607 1.1 pho return -ENOSYS
608 1.1 pho CALL_FLUSH(22);
609 1.1 pho CALL_FLUSH(23);
610 1.1 pho CALL_FLUSH(25);
611 1.1 pho CALL_FLUSH(26);
612 1.1 pho CALL_FLUSH(28);
613 1.1 pho CALL_FLUSH(29);
614 1.1 pho CALL_FLUSH(30);
615 1.1 pho CALL_FLUSH(34);
616 1.1 pho CALL_FLUSH(38);
617 1.1 pho #undef CALL_FLUSH
618 1.1 pho default:
619 1.1 pho UNKNOWN_VERSION(fs->op_version);
620 1.1 pho }
621 1.1 pho }
622 1.1 pho
623 1.1 pho static void
624 1.1 pho zero_statvfs(struct statvfs* dst) {
625 1.1 pho dst->f_bsize = 0;
626 1.1 pho dst->f_frsize = 0;
627 1.1 pho dst->f_blocks = 0;
628 1.1 pho dst->f_bfree = 0;
629 1.1 pho dst->f_bavail = 0;
630 1.1 pho dst->f_files = 0;
631 1.1 pho dst->f_ffree = 0;
632 1.1 pho dst->f_fresvd = 0;
633 1.1 pho }
634 1.1 pho static void
635 1.1 pho fuse_statfs_to_statvfs(struct statvfs* dst, const struct fuse_statfs* src) {
636 1.1 pho dst->f_bsize = (unsigned long)src->block_size;
637 1.1 pho dst->f_frsize = (unsigned long)src->block_size; /* Dunno if this is correct. */
638 1.1 pho dst->f_blocks = (fsblkcnt_t)src->blocks;
639 1.1 pho dst->f_bfree = (fsblkcnt_t)src->blocks_free;
640 1.1 pho dst->f_bavail = (fsblkcnt_t)src->blocks_free;
641 1.1 pho dst->f_files = (fsfilcnt_t)src->files;
642 1.1 pho dst->f_ffree = (fsfilcnt_t)src->files_free;
643 1.1 pho }
644 1.1 pho static void
645 1.1 pho linux_statfs_to_statvfs(struct statvfs* dst, const struct statfs* src) {
646 1.1 pho dst->f_bsize = (unsigned long)src->f_bsize;
647 1.1 pho dst->f_frsize = (unsigned long)src->f_bsize; /* Dunno if this is correct. */
648 1.1 pho dst->f_blocks = src->f_blocks;
649 1.1 pho dst->f_bfree = src->f_bfree;
650 1.1 pho dst->f_bavail = src->f_bavail;
651 1.1 pho dst->f_files = src->f_files;
652 1.1 pho dst->f_ffree = src->f_ffree;
653 1.1 pho }
654 1.1 pho int
655 1.1 pho fuse_fs_statfs(struct fuse_fs* fs, const char* path, struct statvfs* buf) {
656 1.1 pho clobber_context_user_data(fs);
657 1.1 pho
658 1.1 pho zero_statvfs(buf);
659 1.1 pho
660 1.1 pho switch (fs->op_version) {
661 1.1 pho /* FUSE < 2.1 used "struct fuse_statfs". */
662 1.1 pho case 11:
663 1.1 pho if (((const struct fuse_operations_v11*)fs->op)->statfs) {
664 1.1 pho struct fuse_statfs statfs_v11;
665 1.1 pho int ret;
666 1.1 pho
667 1.1 pho ret = ((const struct fuse_operations_v11*)fs->op)->statfs(path, &statfs_v11);
668 1.1 pho if (ret == 0)
669 1.1 pho fuse_statfs_to_statvfs(buf, &statfs_v11);
670 1.1 pho
671 1.1 pho return ret;
672 1.1 pho }
673 1.1 pho else
674 1.1 pho return 0; /* Special case */
675 1.1 pho
676 1.1 pho /* FUSE >= 2.2 && < 2.5 used Linux-specific "struct
677 1.1 pho * statfs". */
678 1.1 pho #define CALL_LINUX_STATFS(VER) \
679 1.1 pho case VER: \
680 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->statfs) { \
681 1.1 pho struct statfs statfs_v22; \
682 1.1 pho int ret; \
683 1.1 pho \
684 1.1 pho ret = ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->statfs(path, &statfs_v22); \
685 1.1 pho if (ret == 0) \
686 1.1 pho linux_statfs_to_statvfs(buf, &statfs_v22); \
687 1.1 pho \
688 1.1 pho return ret; \
689 1.1 pho } \
690 1.1 pho else \
691 1.1 pho return 0; /* Special case */
692 1.1 pho CALL_LINUX_STATFS(22);
693 1.1 pho CALL_LINUX_STATFS(23);
694 1.1 pho #undef CALL_STATFS
695 1.1 pho
696 1.1 pho /* FUSE >= 2.5 use struct statvfs. */
697 1.1 pho #define CALL_STATFS(VER) \
698 1.1 pho case VER: \
699 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->statfs) \
700 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->statfs(path, buf); \
701 1.1 pho else \
702 1.1 pho return 0; /* Special case */
703 1.1 pho CALL_STATFS(25);
704 1.1 pho CALL_STATFS(26);
705 1.1 pho CALL_STATFS(28);
706 1.1 pho CALL_STATFS(29);
707 1.1 pho CALL_STATFS(30);
708 1.1 pho CALL_STATFS(34);
709 1.1 pho CALL_STATFS(38);
710 1.1 pho #undef CALL_STATFS
711 1.1 pho default:
712 1.1 pho UNKNOWN_VERSION(fs->op_version);
713 1.1 pho }
714 1.1 pho }
715 1.1 pho
716 1.1 pho int
717 1.1 pho fuse_fs_opendir(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
718 1.1 pho clobber_context_user_data(fs);
719 1.1 pho switch (fs->op_version) {
720 1.1 pho /* FUSE < 2.3 didn't have opendir() and used to read
721 1.1 pho * directories without opening them. */
722 1.1 pho case 11:
723 1.1 pho case 21:
724 1.1 pho case 22:
725 1.1 pho return 0; /* Special case */
726 1.1 pho
727 1.1 pho #define CALL_OPENDIR(VER) \
728 1.1 pho case VER: \
729 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->opendir) \
730 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->opendir(path, fi); \
731 1.1 pho else \
732 1.1 pho return 0 /* Special case */
733 1.1 pho CALL_OPENDIR(23);
734 1.1 pho CALL_OPENDIR(25);
735 1.1 pho CALL_OPENDIR(26);
736 1.1 pho CALL_OPENDIR(28);
737 1.1 pho CALL_OPENDIR(29);
738 1.1 pho CALL_OPENDIR(30);
739 1.1 pho CALL_OPENDIR(34);
740 1.1 pho CALL_OPENDIR(38);
741 1.1 pho #undef CALL_OPENDIR
742 1.1 pho default:
743 1.1 pho UNKNOWN_VERSION(fs->op_version);
744 1.1 pho }
745 1.1 pho }
746 1.1 pho
747 1.1 pho /* ===================================
748 1.1 pho * -=- The readdir Madness -=-
749 1.1 pho * Juggling with Nested Shims
750 1.1 pho * =================================== */
751 1.1 pho
752 1.1 pho struct fuse_fill_dir_v23_shim {
753 1.1 pho void* dirh;
754 1.1 pho fuse_fill_dir_t_v23 fill_dir_v23;
755 1.1 pho };
756 1.1 pho
757 1.1 pho /* Translate dirent DT_* to mode_t. Needed by shim functions. */
758 1.1 pho static mode_t
759 1.1 pho dt_to_mode(int dt) {
760 1.1 pho switch (dt) {
761 1.1 pho case DT_UNKNOWN: return 0;
762 1.1 pho case DT_FIFO: return S_IFIFO;
763 1.1 pho case DT_CHR: return S_IFCHR;
764 1.1 pho case DT_DIR: return S_IFCHR;
765 1.1 pho case DT_BLK: return S_IFBLK;
766 1.1 pho case DT_REG: return S_IFREG;
767 1.1 pho case DT_LNK: return S_IFLNK;
768 1.1 pho case DT_SOCK: return S_IFSOCK;
769 1.1 pho case DT_WHT: return S_IFWHT;
770 1.1 pho default:
771 1.1 pho errx(EXIT_FAILURE, "%s: unknown dirent type: %d",
772 1.1 pho __func__, dt);
773 1.1 pho }
774 1.1 pho }
775 1.1 pho
776 1.1 pho /* This is a shim function that satisfies the type of
777 1.1 pho * fuse_dirfil_t_v11 but calls fuse_fill_dir_v23. */
778 1.1 pho static int
779 1.1 pho fuse_dirfil_v11_to_fill_dir_v23(fuse_dirh_t handle, const char* name, int type) {
780 1.1 pho struct fuse_fill_dir_v23_shim* shim = handle;
781 1.1 pho struct stat stbuf;
782 1.1 pho int res; /* 1 or 0 */
783 1.1 pho
784 1.1 pho memset(&stbuf, 0, sizeof(stbuf));
785 1.1 pho stbuf.st_mode = dt_to_mode(type);
786 1.1 pho
787 1.1 pho res = shim->fill_dir_v23(shim->dirh, name, &stbuf, 0);
788 1.1 pho return res ? -ENOMEM : 0;
789 1.1 pho }
790 1.1 pho
791 1.1 pho /* This is a shim function that satisfies the type of
792 1.1 pho * fuse_dirfil_t_v22 but calls fuse_fill_dir_v23. */
793 1.1 pho static int
794 1.1 pho fuse_dirfil_v22_to_fill_dir_v23(fuse_dirh_t handle, const char* name, int type, ino_t ino) {
795 1.1 pho struct fuse_fill_dir_v23_shim* shim = handle;
796 1.1 pho struct stat stbuf;
797 1.1 pho int res; /* 1 or 0 */
798 1.1 pho
799 1.1 pho memset(&stbuf, 0, sizeof(stbuf));
800 1.1 pho stbuf.st_mode = dt_to_mode(type);
801 1.1 pho stbuf.st_ino = ino;
802 1.1 pho
803 1.1 pho res = shim->fill_dir_v23(shim->dirh, name, &stbuf, 0);
804 1.1 pho return res ? -ENOMEM : 0;
805 1.1 pho }
806 1.1 pho
807 1.1 pho struct fuse_fill_dir_v30_shim {
808 1.1 pho void* dirh;
809 1.1 pho fuse_fill_dir_t_v30 fill_dir_v30;
810 1.1 pho };
811 1.1 pho
812 1.1 pho /* This is a shim function that satisfies the type of
813 1.1 pho * fuse_fill_dir_v23 but calls fuse_fill_dir_v30. */
814 1.1 pho static int
815 1.1 pho fuse_fill_dir_v23_to_v30(void* buf, const char* name,
816 1.1 pho const struct stat* stat, off_t off) {
817 1.1 pho
818 1.1 pho struct fuse_fill_dir_v30_shim* shim = buf;
819 1.1 pho
820 1.1 pho return shim->fill_dir_v30(shim->dirh, name, stat, off, (enum fuse_fill_dir_flags)0);
821 1.1 pho }
822 1.1 pho
823 1.1 pho int
824 1.1 pho fuse_fs_readdir_v27(struct fuse_fs* fs, const char* path, void* buf,
825 1.1 pho fuse_fill_dir_t_v23 filler, off_t off,
826 1.1 pho struct fuse_file_info* fi) {
827 1.1 pho
828 1.1 pho struct fuse_fill_dir_v23_shim v23_shim;
829 1.1 pho
830 1.1 pho v23_shim.dirh = buf;
831 1.1 pho v23_shim.fill_dir_v23 = filler;
832 1.1 pho
833 1.1 pho clobber_context_user_data(fs);
834 1.1 pho
835 1.1 pho switch (fs->op_version) {
836 1.1 pho /* FUSE < 2.2 had getdir() that used fuse_dirfil_t_v11. */
837 1.1 pho #define CALL_GETDIR_V11(VER) \
838 1.1 pho case VER: \
839 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getdir) \
840 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getdir(path, &v23_shim, fuse_dirfil_v11_to_fill_dir_v23); \
841 1.1 pho else \
842 1.1 pho return -ENOSYS
843 1.1 pho CALL_GETDIR_V11(11);
844 1.1 pho CALL_GETDIR_V11(21);
845 1.1 pho #undef CALL_GETDIR_V11
846 1.1 pho
847 1.1 pho /* FUSE 2.2 had getdir() that used fuse_dirfil_t_v22 but
848 1.1 pho * didn't have readdir(). */
849 1.1 pho case 22:
850 1.1 pho if (((const struct fuse_operations_v22*)fs->op)->getdir)
851 1.1 pho return ((const struct fuse_operations_v22*)fs->op)->getdir(path, &v23_shim, fuse_dirfil_v22_to_fill_dir_v23);
852 1.1 pho else
853 1.1 pho return -ENOSYS;
854 1.1 pho
855 1.1 pho /* FUSE 2.3 introduced readdir() but still had getdir() as
856 1.1 pho * a deprecated operation. It had been this way until FUSE 3.0
857 1.1 pho * finally removed getdir() and also changed the prototype of
858 1.1 pho * readdir(). */
859 1.1 pho #define CALL_READDIR_OR_GETDIR(VER) \
860 1.1 pho case VER: \
861 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readdir) \
862 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readdir(path, buf, filler, off, fi); \
863 1.1 pho else if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getdir) \
864 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getdir(path, &v23_shim, fuse_dirfil_v22_to_fill_dir_v23); \
865 1.1 pho else \
866 1.1 pho return -ENOSYS
867 1.1 pho CALL_READDIR_OR_GETDIR(23);
868 1.1 pho CALL_READDIR_OR_GETDIR(25);
869 1.1 pho CALL_READDIR_OR_GETDIR(26);
870 1.1 pho CALL_READDIR_OR_GETDIR(28);
871 1.1 pho CALL_READDIR_OR_GETDIR(29);
872 1.1 pho #undef CALL_READDIR_OR_GETDIR
873 1.1 pho
874 1.1 pho default:
875 1.1 pho /* FUSE >= 3.0 filesystems will never call this function. We
876 1.1 pho * can safely ignore them here. */
877 1.1 pho UNKNOWN_VERSION(fs->op_version);
878 1.1 pho }
879 1.1 pho }
880 1.1 pho
881 1.1 pho int
882 1.1 pho fuse_fs_readdir_v30(struct fuse_fs* fs, const char* path, void* buf,
883 1.1 pho fuse_fill_dir_t_v30 filler, off_t off,
884 1.1 pho struct fuse_file_info* fi, enum fuse_readdir_flags flags) {
885 1.1 pho clobber_context_user_data(fs);
886 1.1 pho
887 1.1 pho if (fs->op_version < 30) {
888 1.1 pho struct fuse_fill_dir_v30_shim v30_shim;
889 1.1 pho
890 1.1 pho v30_shim.dirh = buf;
891 1.1 pho v30_shim.fill_dir_v30 = filler;
892 1.1 pho
893 1.1 pho return fuse_fs_readdir_v27(fs, path, &v30_shim, fuse_fill_dir_v23_to_v30, off, fi);
894 1.1 pho }
895 1.1 pho else {
896 1.1 pho switch (fs->op_version) {
897 1.1 pho #define CALL_READDIR(VER) \
898 1.1 pho case VER: \
899 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readdir) \
900 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readdir(path, buf, filler, off, fi, flags); \
901 1.1 pho else \
902 1.1 pho return -ENOSYS
903 1.1 pho CALL_READDIR(30);
904 1.1 pho CALL_READDIR(34);
905 1.1 pho CALL_READDIR(38);
906 1.1 pho #undef CALL_READDIR
907 1.1 pho default:
908 1.1 pho UNKNOWN_VERSION(fs->op_version);
909 1.1 pho }
910 1.1 pho }
911 1.1 pho }
912 1.1 pho
913 1.1 pho /* ==============================
914 1.1 pho * The End of readdir Madness
915 1.1 pho * ============================== */
916 1.1 pho
917 1.1 pho int
918 1.1 pho fuse_fs_fsyncdir(struct fuse_fs* fs, const char* path, int datasync, struct fuse_file_info* fi) {
919 1.1 pho clobber_context_user_data(fs);
920 1.1 pho /* fsyncdir() appeared on FUSE 2.3. */
921 1.1 pho switch (fs->op_version) {
922 1.1 pho case 11:
923 1.1 pho case 21:
924 1.1 pho case 22:
925 1.1 pho return -ENOSYS;
926 1.1 pho
927 1.1 pho #define CALL_FSYNCDIR(VER) \
928 1.1 pho case VER: \
929 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsyncdir) \
930 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fsyncdir(path, datasync, fi); \
931 1.1 pho else \
932 1.1 pho return -ENOSYS
933 1.1 pho CALL_FSYNCDIR(23);
934 1.1 pho CALL_FSYNCDIR(25);
935 1.1 pho CALL_FSYNCDIR(26);
936 1.1 pho CALL_FSYNCDIR(28);
937 1.1 pho CALL_FSYNCDIR(29);
938 1.1 pho CALL_FSYNCDIR(30);
939 1.1 pho CALL_FSYNCDIR(34);
940 1.1 pho CALL_FSYNCDIR(38);
941 1.1 pho #undef CALL_FSYNCDIR
942 1.1 pho default:
943 1.1 pho UNKNOWN_VERSION(fs->op_version);
944 1.1 pho }
945 1.1 pho }
946 1.1 pho
947 1.1 pho int
948 1.1 pho fuse_fs_releasedir(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi) {
949 1.1 pho clobber_context_user_data(fs);
950 1.1 pho switch (fs->op_version) {
951 1.1 pho /* FUSE < 2.3 didn't have releasedir() and was reading
952 1.1 pho * directories without opening them. */
953 1.1 pho case 11:
954 1.1 pho case 21:
955 1.1 pho case 22:
956 1.1 pho return 0; /* Special case */
957 1.1 pho
958 1.1 pho #define CALL_RELEASEDIR(VER) \
959 1.1 pho case VER: \
960 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->releasedir) \
961 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->releasedir(path, fi); \
962 1.1 pho else \
963 1.1 pho return 0 /* Special case */
964 1.1 pho CALL_RELEASEDIR(23);
965 1.1 pho CALL_RELEASEDIR(25);
966 1.1 pho CALL_RELEASEDIR(26);
967 1.1 pho CALL_RELEASEDIR(28);
968 1.1 pho CALL_RELEASEDIR(29);
969 1.1 pho CALL_RELEASEDIR(30);
970 1.1 pho CALL_RELEASEDIR(34);
971 1.1 pho CALL_RELEASEDIR(38);
972 1.1 pho #undef CALL_RELEASEDIR
973 1.1 pho default:
974 1.1 pho UNKNOWN_VERSION(fs->op_version);
975 1.1 pho }
976 1.1 pho }
977 1.1 pho
978 1.1 pho int
979 1.1 pho fuse_fs_create(struct fuse_fs* fs, const char* path, mode_t mode, struct fuse_file_info* fi) {
980 1.1 pho clobber_context_user_data(fs);
981 1.1 pho switch (fs->op_version) {
982 1.1 pho /* FUSE < 2.5 didn't have create(). */
983 1.1 pho case 11:
984 1.1 pho case 21:
985 1.1 pho case 22:
986 1.1 pho case 23:
987 1.1 pho return -ENOSYS;
988 1.1 pho
989 1.1 pho #define CALL_CREATE(VER) \
990 1.1 pho case VER: \
991 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->create) \
992 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->create(path, mode, fi); \
993 1.1 pho else \
994 1.1 pho return -ENOSYS
995 1.1 pho CALL_CREATE(25);
996 1.1 pho CALL_CREATE(26);
997 1.1 pho CALL_CREATE(28);
998 1.1 pho CALL_CREATE(29);
999 1.1 pho CALL_CREATE(30);
1000 1.1 pho CALL_CREATE(34);
1001 1.1 pho CALL_CREATE(38);
1002 1.1 pho #undef CALL_CREATE
1003 1.1 pho default:
1004 1.1 pho UNKNOWN_VERSION(fs->op_version);
1005 1.1 pho }
1006 1.1 pho }
1007 1.1 pho
1008 1.1 pho int
1009 1.1 pho fuse_fs_lock(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi,
1010 1.1 pho int cmd, struct flock* lock) {
1011 1.1 pho clobber_context_user_data(fs);
1012 1.1 pho /* locK() appeared on FUSE 2.6. */
1013 1.1 pho switch (fs->op_version) {
1014 1.1 pho case 11:
1015 1.1 pho case 21:
1016 1.1 pho case 22:
1017 1.1 pho case 23:
1018 1.1 pho case 25:
1019 1.1 pho return -ENOSYS;
1020 1.1 pho
1021 1.1 pho #define CALL_LOCK(VER) \
1022 1.1 pho case VER: \
1023 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->lock) \
1024 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->lock(path, fi, cmd, lock); \
1025 1.1 pho else \
1026 1.1 pho return -ENOSYS
1027 1.1 pho CALL_LOCK(26);
1028 1.1 pho CALL_LOCK(28);
1029 1.1 pho CALL_LOCK(29);
1030 1.1 pho CALL_LOCK(30);
1031 1.1 pho CALL_LOCK(34);
1032 1.1 pho CALL_LOCK(38);
1033 1.1 pho #undef CALL_LOCK
1034 1.1 pho default:
1035 1.1 pho UNKNOWN_VERSION(fs->op_version);
1036 1.1 pho }
1037 1.1 pho }
1038 1.1 pho
1039 1.1 pho int
1040 1.1 pho fuse_fs_flock(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi, int op) {
1041 1.1 pho clobber_context_user_data(fs);
1042 1.1 pho /* flocK() appeared on FUSE 2.9. */
1043 1.1 pho switch (fs->op_version) {
1044 1.1 pho case 11:
1045 1.1 pho case 21:
1046 1.1 pho case 22:
1047 1.1 pho case 23:
1048 1.1 pho case 25:
1049 1.1 pho case 26:
1050 1.1 pho case 28:
1051 1.1 pho return -ENOSYS;
1052 1.1 pho
1053 1.1 pho #define CALL_FLOCK(VER) \
1054 1.1 pho case VER: \
1055 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->flock) \
1056 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->flock(path, fi, op); \
1057 1.1 pho else \
1058 1.1 pho return -ENOSYS
1059 1.1 pho CALL_FLOCK(29);
1060 1.1 pho CALL_FLOCK(30);
1061 1.1 pho CALL_FLOCK(34);
1062 1.1 pho CALL_FLOCK(38);
1063 1.1 pho #undef CALL_FLOCK
1064 1.1 pho default:
1065 1.1 pho UNKNOWN_VERSION(fs->op_version);
1066 1.1 pho }
1067 1.1 pho }
1068 1.1 pho
1069 1.1 pho int
1070 1.1 pho fuse_fs_chmod_v27(struct fuse_fs *fs, const char *path, mode_t mode) {
1071 1.1 pho return fuse_fs_chmod_v30(fs, path, mode, NULL);
1072 1.1 pho }
1073 1.1 pho
1074 1.1 pho int
1075 1.1 pho fuse_fs_chmod_v30(struct fuse_fs* fs, const char* path,
1076 1.1 pho mode_t mode, struct fuse_file_info* fi) {
1077 1.1 pho clobber_context_user_data(fs);
1078 1.1 pho switch (fs->op_version) {
1079 1.1 pho #define CALL_OLD_CHMOD(VER) \
1080 1.1 pho case VER: \
1081 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chmod) \
1082 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chmod(path, mode); \
1083 1.1 pho else \
1084 1.1 pho return -ENOSYS
1085 1.1 pho CALL_OLD_CHMOD(11);
1086 1.1 pho CALL_OLD_CHMOD(21);
1087 1.1 pho CALL_OLD_CHMOD(22);
1088 1.1 pho CALL_OLD_CHMOD(23);
1089 1.1 pho CALL_OLD_CHMOD(25);
1090 1.1 pho CALL_OLD_CHMOD(26);
1091 1.1 pho CALL_OLD_CHMOD(28);
1092 1.1 pho CALL_OLD_CHMOD(29);
1093 1.1 pho #undef CALL_OLD_CHMOD
1094 1.1 pho
1095 1.1 pho #define CALL_CHMOD(VER) \
1096 1.1 pho case VER: \
1097 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chmod) \
1098 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chmod(path, mode, fi); \
1099 1.1 pho else \
1100 1.1 pho return -ENOSYS
1101 1.1 pho CALL_CHMOD(30);
1102 1.1 pho CALL_CHMOD(34);
1103 1.1 pho CALL_CHMOD(38);
1104 1.1 pho #undef CALL_CHMOD
1105 1.1 pho default:
1106 1.1 pho UNKNOWN_VERSION(fs->op_version);
1107 1.1 pho }
1108 1.1 pho }
1109 1.1 pho
1110 1.1 pho int fuse_fs_chown_v27(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid) {
1111 1.1 pho return fuse_fs_chown_v30(fs, path, uid, gid, NULL);
1112 1.1 pho }
1113 1.1 pho
1114 1.1 pho int
1115 1.1 pho fuse_fs_chown_v30(struct fuse_fs* fs, const char* path,
1116 1.1 pho uid_t uid, gid_t gid, struct fuse_file_info* fi) {
1117 1.1 pho clobber_context_user_data(fs);
1118 1.1 pho switch (fs->op_version) {
1119 1.1 pho #define CALL_OLD_CHOWN(VER) \
1120 1.1 pho case VER: \
1121 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chown) \
1122 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chown(path, uid, gid); \
1123 1.1 pho else \
1124 1.1 pho return -ENOSYS
1125 1.1 pho CALL_OLD_CHOWN(11);
1126 1.1 pho CALL_OLD_CHOWN(21);
1127 1.1 pho CALL_OLD_CHOWN(22);
1128 1.1 pho CALL_OLD_CHOWN(23);
1129 1.1 pho CALL_OLD_CHOWN(25);
1130 1.1 pho CALL_OLD_CHOWN(26);
1131 1.1 pho CALL_OLD_CHOWN(28);
1132 1.1 pho CALL_OLD_CHOWN(29);
1133 1.1 pho #undef CALL_OLD_CHOWN
1134 1.1 pho
1135 1.1 pho #define CALL_CHOWN(VER) \
1136 1.1 pho case VER: \
1137 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chown) \
1138 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->chown(path, uid, gid, fi); \
1139 1.1 pho else \
1140 1.1 pho return -ENOSYS
1141 1.1 pho CALL_CHOWN(30);
1142 1.1 pho CALL_CHOWN(34);
1143 1.1 pho CALL_CHOWN(38);
1144 1.1 pho #undef CALL_CHOWN
1145 1.1 pho default:
1146 1.1 pho UNKNOWN_VERSION(fs->op_version);
1147 1.1 pho }
1148 1.1 pho }
1149 1.1 pho
1150 1.1 pho int fuse_fs_truncate_v27(struct fuse_fs *fs, const char *path, off_t size) {
1151 1.1 pho return fuse_fs_truncate_v30(fs, path, size, NULL);
1152 1.1 pho }
1153 1.1 pho
1154 1.1 pho int
1155 1.1 pho fuse_fs_truncate_v30(struct fuse_fs* fs, const char* path, off_t size, struct fuse_file_info* fi) {
1156 1.1 pho clobber_context_user_data(fs);
1157 1.1 pho switch (fs->op_version) {
1158 1.1 pho #define CALL_OLD_TRUNCATE(VER) \
1159 1.1 pho case VER: \
1160 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
1161 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size); \
1162 1.1 pho else \
1163 1.1 pho return -ENOSYS
1164 1.1 pho CALL_OLD_TRUNCATE(11);
1165 1.1 pho CALL_OLD_TRUNCATE(21);
1166 1.1 pho CALL_OLD_TRUNCATE(22);
1167 1.1 pho CALL_OLD_TRUNCATE(23);
1168 1.1 pho CALL_OLD_TRUNCATE(25);
1169 1.1 pho CALL_OLD_TRUNCATE(26);
1170 1.1 pho CALL_OLD_TRUNCATE(28);
1171 1.1 pho CALL_OLD_TRUNCATE(29);
1172 1.1 pho #undef CALL_OLD_TRUNCATE
1173 1.1 pho
1174 1.1 pho #define CALL_TRUNCATE(VER) \
1175 1.1 pho case VER: \
1176 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
1177 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size, fi); \
1178 1.1 pho else \
1179 1.1 pho return -ENOSYS
1180 1.1 pho CALL_TRUNCATE(30);
1181 1.1 pho CALL_TRUNCATE(34);
1182 1.1 pho CALL_TRUNCATE(38);
1183 1.1 pho #undef CALL_TRUNCATE
1184 1.1 pho default:
1185 1.1 pho UNKNOWN_VERSION(fs->op_version);
1186 1.1 pho }
1187 1.1 pho }
1188 1.1 pho
1189 1.1 pho int
1190 1.1 pho fuse_fs_ftruncate(struct fuse_fs* fs, const char* path, off_t size, struct fuse_file_info* fi) {
1191 1.1 pho clobber_context_user_data(fs);
1192 1.1 pho switch (fs->op_version) {
1193 1.1 pho /* FUSE < 2.5 didn't have ftruncate(). Always fall back to
1194 1.1 pho * truncate(). */
1195 1.1 pho #define CALL_OLD_TRUNCATE(VER) \
1196 1.1 pho case VER: \
1197 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
1198 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size); \
1199 1.1 pho else \
1200 1.1 pho return -ENOSYS
1201 1.1 pho CALL_OLD_TRUNCATE(11);
1202 1.1 pho CALL_OLD_TRUNCATE(21);
1203 1.1 pho CALL_OLD_TRUNCATE(22);
1204 1.1 pho CALL_OLD_TRUNCATE(23);
1205 1.1 pho #undef CALL_OLD_TRUNCATE
1206 1.1 pho
1207 1.1 pho /* ftruncate() appeared on FUSE 2.5 and then disappeared on
1208 1.1 pho * FUSE 3.0. Call it if it exists, or fall back to truncate()
1209 1.1 pho * otherwise. */
1210 1.1 pho #define CALL_FTRUNCATE_OR_TRUNCATE(VER) \
1211 1.1 pho case VER: \
1212 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ftruncate) \
1213 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ftruncate(path, size, fi); \
1214 1.1 pho else if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
1215 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size); \
1216 1.1 pho else \
1217 1.1 pho return -ENOSYS
1218 1.1 pho CALL_FTRUNCATE_OR_TRUNCATE(25);
1219 1.1 pho CALL_FTRUNCATE_OR_TRUNCATE(26);
1220 1.1 pho CALL_FTRUNCATE_OR_TRUNCATE(28);
1221 1.1 pho CALL_FTRUNCATE_OR_TRUNCATE(29);
1222 1.1 pho #undef CALL_FTRUNCATE_OR_TRUNCATE
1223 1.1 pho
1224 1.1 pho /* FUSE >= 3.0 have truncate() but with a different function
1225 1.1 pho * type. */
1226 1.1 pho #define CALL_TRUNCATE(VER) \
1227 1.1 pho case VER: \
1228 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate) \
1229 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->truncate(path, size, fi); \
1230 1.1 pho else \
1231 1.1 pho return -ENOSYS
1232 1.1 pho CALL_TRUNCATE(30);
1233 1.1 pho CALL_TRUNCATE(34);
1234 1.1 pho CALL_TRUNCATE(38);
1235 1.1 pho #undef CALL_TRUNCATE
1236 1.1 pho default:
1237 1.1 pho UNKNOWN_VERSION(fs->op_version);
1238 1.1 pho }
1239 1.1 pho }
1240 1.1 pho
1241 1.1 pho int
1242 1.1 pho fuse_fs_utimens_v27(struct fuse_fs *fs, const char *path, const struct timespec tv[2]) {
1243 1.1 pho return fuse_fs_utimens_v30(fs, path, tv, NULL);
1244 1.1 pho }
1245 1.1 pho
1246 1.1 pho int
1247 1.1 pho fuse_fs_utimens_v30(struct fuse_fs* fs, const char* path,
1248 1.1 pho const struct timespec tv[2], struct fuse_file_info* fi) {
1249 1.1 pho struct utimbuf timbuf;
1250 1.1 pho
1251 1.1 pho timbuf.actime = tv[0].tv_sec;
1252 1.1 pho timbuf.modtime = tv[1].tv_sec;
1253 1.1 pho
1254 1.1 pho clobber_context_user_data(fs);
1255 1.1 pho
1256 1.1 pho switch (fs->op_version) {
1257 1.1 pho /* FUSE < 2.6 didn't have utimens() but had utime()
1258 1.1 pho * instead. */
1259 1.1 pho #define CALL_UTIME(VER) \
1260 1.1 pho case VER: \
1261 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utime) \
1262 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utime(path, &timbuf); \
1263 1.1 pho else \
1264 1.1 pho return -ENOSYS
1265 1.1 pho CALL_UTIME(11);
1266 1.1 pho CALL_UTIME(21);
1267 1.1 pho CALL_UTIME(22);
1268 1.1 pho CALL_UTIME(23);
1269 1.1 pho CALL_UTIME(25);
1270 1.1 pho #undef CALL_UTIME
1271 1.1 pho
1272 1.1 pho /* utimens() appeared on FUSE 2.6. Call it if it exists, or fall back to
1273 1.1 pho * utime() otherwise. */
1274 1.1 pho #define CALL_UTIMENS_OR_UTIME(VER) \
1275 1.1 pho case VER: \
1276 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utimens) \
1277 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utimens(path, tv); \
1278 1.1 pho else if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utime) \
1279 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utime(path, &timbuf); \
1280 1.1 pho else \
1281 1.1 pho return -ENOSYS
1282 1.1 pho CALL_UTIMENS_OR_UTIME(26);
1283 1.1 pho CALL_UTIMENS_OR_UTIME(28);
1284 1.1 pho CALL_UTIMENS_OR_UTIME(29);
1285 1.1 pho #undef CALL_UTIMENS_OR_UTIME
1286 1.1 pho
1287 1.1 pho /* utime() disappeared on FUSE 3.0. */
1288 1.1 pho #define CALL_UTIMENS(VER) \
1289 1.1 pho case VER: \
1290 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utimens) \
1291 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->utimens(path, tv, fi); \
1292 1.1 pho else \
1293 1.1 pho return -ENOSYS
1294 1.1 pho CALL_UTIMENS(30);
1295 1.1 pho CALL_UTIMENS(34);
1296 1.1 pho CALL_UTIMENS(38);
1297 1.1 pho #undef CALL_UTIMENS
1298 1.1 pho default:
1299 1.1 pho UNKNOWN_VERSION(fs->op_version);
1300 1.1 pho }
1301 1.1 pho }
1302 1.1 pho
1303 1.1 pho int
1304 1.1 pho fuse_fs_access(struct fuse_fs* fs, const char* path, int mask) {
1305 1.1 pho clobber_context_user_data(fs);
1306 1.1 pho /* access() appeared on FUSE 2.5. */
1307 1.1 pho switch (fs->op_version) {
1308 1.1 pho case 11:
1309 1.1 pho case 21:
1310 1.1 pho case 22:
1311 1.1 pho case 23:
1312 1.1 pho return -ENOSYS;
1313 1.1 pho #define CALL_ACCESS(VER) \
1314 1.1 pho case VER: \
1315 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->access) \
1316 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->access(path, mask); \
1317 1.1 pho else \
1318 1.1 pho return -ENOSYS
1319 1.1 pho CALL_ACCESS(25);
1320 1.1 pho CALL_ACCESS(26);
1321 1.1 pho CALL_ACCESS(28);
1322 1.1 pho CALL_ACCESS(29);
1323 1.1 pho CALL_ACCESS(30);
1324 1.1 pho CALL_ACCESS(34);
1325 1.1 pho CALL_ACCESS(38);
1326 1.1 pho #undef CALL_ACCESS
1327 1.1 pho default:
1328 1.1 pho UNKNOWN_VERSION(fs->op_version);
1329 1.1 pho }
1330 1.1 pho }
1331 1.1 pho
1332 1.1 pho int
1333 1.1 pho fuse_fs_readlink(struct fuse_fs* fs, const char* path, char* buf, size_t len) {
1334 1.1 pho clobber_context_user_data(fs);
1335 1.1 pho switch (fs->op_version) {
1336 1.1 pho #define CALL_READLINK(VER) \
1337 1.1 pho case VER: \
1338 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readlink) \
1339 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->readlink(path, buf, len); \
1340 1.1 pho else \
1341 1.1 pho return -ENOSYS
1342 1.1 pho CALL_READLINK(11);
1343 1.1 pho CALL_READLINK(21);
1344 1.1 pho CALL_READLINK(22);
1345 1.1 pho CALL_READLINK(23);
1346 1.1 pho CALL_READLINK(25);
1347 1.1 pho CALL_READLINK(26);
1348 1.1 pho CALL_READLINK(28);
1349 1.1 pho CALL_READLINK(29);
1350 1.1 pho CALL_READLINK(30);
1351 1.1 pho CALL_READLINK(34);
1352 1.1 pho CALL_READLINK(38);
1353 1.1 pho #undef CALL_READLINK
1354 1.1 pho default:
1355 1.1 pho UNKNOWN_VERSION(fs->op_version);
1356 1.1 pho }
1357 1.1 pho }
1358 1.1 pho
1359 1.1 pho int
1360 1.1 pho fuse_fs_mknod(struct fuse_fs* fs, const char* path, mode_t mode, dev_t rdev) {
1361 1.1 pho clobber_context_user_data(fs);
1362 1.1 pho switch (fs->op_version) {
1363 1.1 pho #define CALL_MKNOD(VER) \
1364 1.1 pho case VER: \
1365 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->mknod) \
1366 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->mknod(path, mode, rdev); \
1367 1.1 pho else \
1368 1.1 pho return -ENOSYS
1369 1.1 pho CALL_MKNOD(11);
1370 1.1 pho CALL_MKNOD(21);
1371 1.1 pho CALL_MKNOD(22);
1372 1.1 pho CALL_MKNOD(23);
1373 1.1 pho CALL_MKNOD(25);
1374 1.1 pho CALL_MKNOD(26);
1375 1.1 pho CALL_MKNOD(28);
1376 1.1 pho CALL_MKNOD(29);
1377 1.1 pho CALL_MKNOD(30);
1378 1.1 pho CALL_MKNOD(34);
1379 1.1 pho CALL_MKNOD(38);
1380 1.1 pho #undef CALL_MKNOD
1381 1.1 pho default:
1382 1.1 pho UNKNOWN_VERSION(fs->op_version);
1383 1.1 pho }
1384 1.1 pho }
1385 1.1 pho
1386 1.1 pho int
1387 1.1 pho fuse_fs_mkdir(struct fuse_fs* fs, const char* path, mode_t mode) {
1388 1.1 pho clobber_context_user_data(fs);
1389 1.1 pho switch (fs->op_version) {
1390 1.1 pho #define CALL_MKDIR(VER) \
1391 1.1 pho case VER: \
1392 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->mkdir) \
1393 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->mkdir(path, mode); \
1394 1.1 pho else \
1395 1.1 pho return -ENOSYS
1396 1.1 pho CALL_MKDIR(11);
1397 1.1 pho CALL_MKDIR(21);
1398 1.1 pho CALL_MKDIR(22);
1399 1.1 pho CALL_MKDIR(23);
1400 1.1 pho CALL_MKDIR(25);
1401 1.1 pho CALL_MKDIR(26);
1402 1.1 pho CALL_MKDIR(28);
1403 1.1 pho CALL_MKDIR(29);
1404 1.1 pho CALL_MKDIR(30);
1405 1.1 pho CALL_MKDIR(34);
1406 1.1 pho CALL_MKDIR(38);
1407 1.1 pho #undef CALL_MKDIR
1408 1.1 pho default:
1409 1.1 pho UNKNOWN_VERSION(fs->op_version);
1410 1.1 pho }
1411 1.1 pho }
1412 1.1 pho
1413 1.1 pho int fuse_fs_setxattr(struct fuse_fs* fs, const char* path, const char* name,
1414 1.1 pho const char* value, size_t size, int flags) {
1415 1.1 pho clobber_context_user_data(fs);
1416 1.1 pho /* setxattr() appeared on FUSE 2.1. */
1417 1.1 pho switch (fs->op_version) {
1418 1.1 pho case 11:
1419 1.1 pho return -ENOSYS;
1420 1.1 pho #define CALL_SETXATTR(VER) \
1421 1.1 pho case VER: \
1422 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->setxattr) \
1423 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->setxattr(path, name, value, size, flags); \
1424 1.1 pho else \
1425 1.1 pho return -ENOSYS
1426 1.1 pho CALL_SETXATTR(21);
1427 1.1 pho CALL_SETXATTR(22);
1428 1.1 pho CALL_SETXATTR(23);
1429 1.1 pho CALL_SETXATTR(25);
1430 1.1 pho CALL_SETXATTR(26);
1431 1.1 pho CALL_SETXATTR(28);
1432 1.1 pho CALL_SETXATTR(29);
1433 1.1 pho CALL_SETXATTR(30);
1434 1.1 pho CALL_SETXATTR(34);
1435 1.1 pho CALL_SETXATTR(38);
1436 1.1 pho #undef CALL_SETXATTR
1437 1.1 pho default:
1438 1.1 pho UNKNOWN_VERSION(fs->op_version);
1439 1.1 pho }
1440 1.1 pho }
1441 1.1 pho
1442 1.1 pho int
1443 1.1 pho fuse_fs_getxattr(struct fuse_fs* fs, const char* path, const char* name,
1444 1.1 pho char* value, size_t size) {
1445 1.1 pho clobber_context_user_data(fs);
1446 1.1 pho /* getxattr() appeared on FUSE 2.1. */
1447 1.1 pho switch (fs->op_version) {
1448 1.1 pho case 11:
1449 1.1 pho return -ENOSYS;
1450 1.1 pho #define CALL_GETXATTR(VER) \
1451 1.1 pho case VER: \
1452 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getxattr) \
1453 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->getxattr(path, name, value, size); \
1454 1.1 pho else \
1455 1.1 pho return -ENOSYS
1456 1.1 pho CALL_GETXATTR(21);
1457 1.1 pho CALL_GETXATTR(22);
1458 1.1 pho CALL_GETXATTR(23);
1459 1.1 pho CALL_GETXATTR(25);
1460 1.1 pho CALL_GETXATTR(26);
1461 1.1 pho CALL_GETXATTR(28);
1462 1.1 pho CALL_GETXATTR(29);
1463 1.1 pho CALL_GETXATTR(30);
1464 1.1 pho CALL_GETXATTR(34);
1465 1.1 pho CALL_GETXATTR(38);
1466 1.1 pho #undef CALL_GETXATTR
1467 1.1 pho default:
1468 1.1 pho UNKNOWN_VERSION(fs->op_version);
1469 1.1 pho }
1470 1.1 pho }
1471 1.1 pho
1472 1.1 pho int fuse_fs_listxattr(struct fuse_fs* fs, const char* path, char* list, size_t size) {
1473 1.1 pho clobber_context_user_data(fs);
1474 1.1 pho /* listxattr() appeared on FUSE 2.1. */
1475 1.1 pho switch (fs->op_version) {
1476 1.1 pho case 11:
1477 1.1 pho return -ENOSYS;
1478 1.1 pho #define CALL_LISTXATTR(VER) \
1479 1.1 pho case VER: \
1480 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->listxattr) \
1481 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->listxattr(path, list, size); \
1482 1.1 pho else \
1483 1.1 pho return -ENOSYS
1484 1.1 pho CALL_LISTXATTR(21);
1485 1.1 pho CALL_LISTXATTR(22);
1486 1.1 pho CALL_LISTXATTR(23);
1487 1.1 pho CALL_LISTXATTR(25);
1488 1.1 pho CALL_LISTXATTR(26);
1489 1.1 pho CALL_LISTXATTR(28);
1490 1.1 pho CALL_LISTXATTR(29);
1491 1.1 pho CALL_LISTXATTR(30);
1492 1.1 pho CALL_LISTXATTR(34);
1493 1.1 pho CALL_LISTXATTR(38);
1494 1.1 pho #undef CALL_LISTXATTR
1495 1.1 pho default:
1496 1.1 pho UNKNOWN_VERSION(fs->op_version);
1497 1.1 pho }
1498 1.1 pho }
1499 1.1 pho
1500 1.1 pho int
1501 1.1 pho fuse_fs_removexattr(struct fuse_fs* fs, const char* path, const char* name) {
1502 1.1 pho clobber_context_user_data(fs);
1503 1.1 pho /* removexattr() appeared on FUSE 2.1. */
1504 1.1 pho switch (fs->op_version) {
1505 1.1 pho case 11:
1506 1.1 pho return -ENOSYS;
1507 1.1 pho #define CALL_REMOVEXATTR(VER) \
1508 1.1 pho case VER: \
1509 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->removexattr) \
1510 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->removexattr(path, name); \
1511 1.1 pho else \
1512 1.1 pho return -ENOSYS
1513 1.1 pho CALL_REMOVEXATTR(21);
1514 1.1 pho CALL_REMOVEXATTR(22);
1515 1.1 pho CALL_REMOVEXATTR(23);
1516 1.1 pho CALL_REMOVEXATTR(25);
1517 1.1 pho CALL_REMOVEXATTR(26);
1518 1.1 pho CALL_REMOVEXATTR(28);
1519 1.1 pho CALL_REMOVEXATTR(29);
1520 1.1 pho CALL_REMOVEXATTR(30);
1521 1.1 pho CALL_REMOVEXATTR(34);
1522 1.1 pho CALL_REMOVEXATTR(38);
1523 1.1 pho #undef CALL_REMOVEXATTR
1524 1.1 pho default:
1525 1.1 pho UNKNOWN_VERSION(fs->op_version);
1526 1.1 pho }
1527 1.1 pho }
1528 1.1 pho
1529 1.1 pho int
1530 1.1 pho fuse_fs_bmap(struct fuse_fs* fs, const char* path, size_t blocksize, uint64_t *idx) {
1531 1.1 pho clobber_context_user_data(fs);
1532 1.1 pho /* bmap() appeared on FUSE 2.6. */
1533 1.1 pho switch (fs->op_version) {
1534 1.1 pho case 11:
1535 1.1 pho case 22:
1536 1.1 pho case 23:
1537 1.1 pho case 25:
1538 1.1 pho return -ENOSYS;
1539 1.1 pho #define CALL_BMAP(VER) \
1540 1.1 pho case VER: \
1541 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->bmap) \
1542 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->bmap(path, blocksize, idx); \
1543 1.1 pho else \
1544 1.1 pho return -ENOSYS
1545 1.1 pho CALL_BMAP(26);
1546 1.1 pho CALL_BMAP(28);
1547 1.1 pho CALL_BMAP(29);
1548 1.1 pho CALL_BMAP(30);
1549 1.1 pho CALL_BMAP(34);
1550 1.1 pho CALL_BMAP(38);
1551 1.1 pho #undef CALL_BMAP
1552 1.1 pho default:
1553 1.1 pho UNKNOWN_VERSION(fs->op_version);
1554 1.1 pho }
1555 1.1 pho }
1556 1.1 pho
1557 1.1 pho int fuse_fs_ioctl_v28(struct fuse_fs* fs, const char* path, int cmd, void* arg,
1558 1.1 pho struct fuse_file_info* fi, unsigned int flags, void* data) {
1559 1.1 pho return fuse_fs_ioctl_v35(fs, path, (unsigned int)cmd, arg, fi, flags, data);
1560 1.1 pho }
1561 1.1 pho
1562 1.1 pho int fuse_fs_ioctl_v35(struct fuse_fs* fs, const char* path, unsigned int cmd, void* arg,
1563 1.1 pho struct fuse_file_info* fi, unsigned int flags, void* data) {
1564 1.1 pho clobber_context_user_data(fs);
1565 1.1 pho switch (fs->op_version) {
1566 1.1 pho /* ioctl() appeared on FUSE 2.8 but with (int)cmd. */
1567 1.1 pho case 11:
1568 1.1 pho case 22:
1569 1.1 pho case 23:
1570 1.1 pho case 25:
1571 1.1 pho case 26:
1572 1.1 pho return -ENOSYS;
1573 1.1 pho #define CALL_OLD_IOCTL(VER) \
1574 1.1 pho case VER: \
1575 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ioctl) \
1576 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ioctl(path, (int)cmd, arg, fi, flags, data); \
1577 1.1 pho else \
1578 1.1 pho return -ENOSYS
1579 1.1 pho CALL_OLD_IOCTL(28);
1580 1.1 pho CALL_OLD_IOCTL(29);
1581 1.1 pho CALL_OLD_IOCTL(30);
1582 1.1 pho CALL_OLD_IOCTL(34);
1583 1.1 pho #undef CALL_OLD_IOCTL
1584 1.1 pho
1585 1.1 pho /* It was then changed to (unsigned int)cmd on FUSE 3.5. */
1586 1.1 pho #define CALL_IOCTL(VER) \
1587 1.1 pho case VER: \
1588 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ioctl) \
1589 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->ioctl(path, cmd, arg, fi, flags, data); \
1590 1.1 pho else \
1591 1.1 pho return -ENOSYS
1592 1.1 pho CALL_IOCTL(35);
1593 1.1 pho CALL_IOCTL(38);
1594 1.1 pho #undef CALL_IOCTL
1595 1.1 pho default:
1596 1.1 pho UNKNOWN_VERSION(fs->op_version);
1597 1.1 pho }
1598 1.1 pho }
1599 1.1 pho
1600 1.1 pho int
1601 1.1 pho fuse_fs_poll(struct fuse_fs* fs, const char* path, struct fuse_file_info* fi,
1602 1.1 pho struct fuse_pollhandle* ph, unsigned* reventsp) {
1603 1.1 pho clobber_context_user_data(fs);
1604 1.1 pho /* poll() appeared on FUSE 2.8. */
1605 1.1 pho switch (fs->op_version) {
1606 1.1 pho case 11:
1607 1.1 pho case 22:
1608 1.1 pho case 23:
1609 1.1 pho case 25:
1610 1.1 pho case 26:
1611 1.1 pho return -ENOSYS;
1612 1.1 pho #define CALL_POLL(VER) \
1613 1.1 pho case VER: \
1614 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->poll) \
1615 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->poll(path, fi, ph, reventsp); \
1616 1.1 pho else \
1617 1.1 pho return -ENOSYS
1618 1.1 pho CALL_POLL(28);
1619 1.1 pho CALL_POLL(29);
1620 1.1 pho CALL_POLL(30);
1621 1.1 pho CALL_POLL(34);
1622 1.1 pho CALL_POLL(38);
1623 1.1 pho #undef CALL_POLL
1624 1.1 pho default:
1625 1.1 pho UNKNOWN_VERSION(fs->op_version);
1626 1.1 pho }
1627 1.1 pho }
1628 1.1 pho
1629 1.1 pho int
1630 1.1 pho fuse_fs_fallocate(struct fuse_fs* fs, const char* path, int mode, off_t offset,
1631 1.1 pho off_t length, struct fuse_file_info* fi) {
1632 1.1 pho clobber_context_user_data(fs);
1633 1.1 pho /* fallocate() appeared on FUSE 2.9. */
1634 1.1 pho switch (fs->op_version) {
1635 1.1 pho case 11:
1636 1.1 pho case 22:
1637 1.1 pho case 23:
1638 1.1 pho case 25:
1639 1.1 pho case 26:
1640 1.1 pho case 28:
1641 1.1 pho return -ENOSYS;
1642 1.1 pho #define CALL_FALLOCATE(VER) \
1643 1.1 pho case VER: \
1644 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fallocate) \
1645 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->fallocate(path, mode, offset, length, fi); \
1646 1.1 pho else \
1647 1.1 pho return -ENOSYS
1648 1.1 pho CALL_FALLOCATE(29);
1649 1.1 pho CALL_FALLOCATE(30);
1650 1.1 pho CALL_FALLOCATE(34);
1651 1.1 pho CALL_FALLOCATE(38);
1652 1.1 pho #undef CALL_FALLOCATE
1653 1.1 pho default:
1654 1.1 pho UNKNOWN_VERSION(fs->op_version);
1655 1.1 pho }
1656 1.1 pho }
1657 1.1 pho
1658 1.1 pho ssize_t
1659 1.1 pho fuse_fs_copy_file_range(struct fuse_fs *fs,
1660 1.1 pho const char *path_in, struct fuse_file_info *fi_in, off_t off_in,
1661 1.1 pho const char *path_out, struct fuse_file_info *fi_out, off_t off_out,
1662 1.1 pho size_t len, int flags) {
1663 1.1 pho clobber_context_user_data(fs);
1664 1.1 pho /* copy_file_range() appeared on FUSE 3.4. */
1665 1.1 pho switch (fs->op_version) {
1666 1.1 pho case 11:
1667 1.1 pho case 22:
1668 1.1 pho case 23:
1669 1.1 pho case 25:
1670 1.1 pho case 26:
1671 1.1 pho case 28:
1672 1.1 pho case 29:
1673 1.1 pho case 30:
1674 1.1 pho return -ENOSYS;
1675 1.1 pho #define CALL_COPY_FILE_RANGE(VER) \
1676 1.1 pho case VER: \
1677 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->copy_file_range) \
1678 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->copy_file_range(path_in, fi_in, off_in, path_out, fi_out, off_out, len, flags); \
1679 1.1 pho else \
1680 1.1 pho return -ENOSYS
1681 1.1 pho CALL_COPY_FILE_RANGE(34);
1682 1.1 pho CALL_COPY_FILE_RANGE(38);
1683 1.1 pho #undef CALL_COPY_FILE_RANGE
1684 1.1 pho default:
1685 1.1 pho UNKNOWN_VERSION(fs->op_version);
1686 1.1 pho }
1687 1.1 pho }
1688 1.1 pho
1689 1.1 pho off_t
1690 1.1 pho fuse_fs_lseek(struct fuse_fs* fs, const char* path, off_t off, int whence,
1691 1.1 pho struct fuse_file_info* fi) {
1692 1.1 pho clobber_context_user_data(fs);
1693 1.1 pho /* lseek() appeared on FUSE 3.8. */
1694 1.1 pho switch (fs->op_version) {
1695 1.1 pho case 11:
1696 1.1 pho case 22:
1697 1.1 pho case 23:
1698 1.1 pho case 25:
1699 1.1 pho case 26:
1700 1.1 pho case 28:
1701 1.1 pho case 29:
1702 1.1 pho case 30:
1703 1.1 pho case 34:
1704 1.1 pho return -ENOSYS;
1705 1.1 pho #define CALL_LSEEK(VER) \
1706 1.1 pho case VER: \
1707 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->lseek) \
1708 1.1 pho return ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->lseek(path, off, whence, fi); \
1709 1.1 pho else \
1710 1.1 pho return -ENOSYS
1711 1.1 pho CALL_LSEEK(38);
1712 1.1 pho #undef CALL_LSEEK
1713 1.1 pho default:
1714 1.1 pho UNKNOWN_VERSION(fs->op_version);
1715 1.1 pho }
1716 1.1 pho }
1717 1.1 pho
1718 1.1 pho void
1719 1.1 pho fuse_fs_init_v27(struct fuse_fs *fs, struct fuse_conn_info *conn) {
1720 1.1 pho fuse_fs_init_v30(fs, conn, NULL);
1721 1.1 pho }
1722 1.1 pho
1723 1.1 pho void
1724 1.1 pho fuse_fs_init_v30(struct fuse_fs* fs, struct fuse_conn_info* conn,
1725 1.1 pho struct fuse_config* cfg) {
1726 1.1 pho clobber_context_user_data(fs);
1727 1.1 pho switch (fs->op_version) {
1728 1.1 pho case 11:
1729 1.1 pho case 21:
1730 1.1 pho case 22:
1731 1.1 pho break;
1732 1.1 pho
1733 1.1 pho /* init() appeared on FUSE 2.3 as init(void). */
1734 1.1 pho #define CALL_NULLARY_INIT(VER) \
1735 1.1 pho case VER: \
1736 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init) \
1737 1.1 pho fs->user_data = ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init(); \
1738 1.1 pho break
1739 1.1 pho CALL_NULLARY_INIT(23);
1740 1.1 pho CALL_NULLARY_INIT(25);
1741 1.1 pho #undef CALL_NULLARY_INIT
1742 1.1 pho
1743 1.1 pho /* It was changed to init(struct fuse_conn_info*) on FUSE
1744 1.1 pho * 2.6. */
1745 1.1 pho #define CALL_UNARY_INIT(VER) \
1746 1.1 pho case VER: \
1747 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init) \
1748 1.1 pho fs->user_data = ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init(conn); \
1749 1.1 pho break
1750 1.1 pho CALL_UNARY_INIT(26);
1751 1.1 pho CALL_UNARY_INIT(28);
1752 1.1 pho CALL_UNARY_INIT(29);
1753 1.1 pho #undef CALL_INIT
1754 1.1 pho
1755 1.1 pho /* It was again changed to init(struct fuse_conn_info*, struct
1756 1.1 pho * fuse_config*) on FUSE 3.0. */
1757 1.1 pho #define CALL_BINARY_INIT(VER) \
1758 1.1 pho case VER: \
1759 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init) \
1760 1.1 pho fs->user_data = ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->init(conn, cfg); \
1761 1.1 pho break
1762 1.1 pho CALL_BINARY_INIT(30);
1763 1.1 pho CALL_BINARY_INIT(34);
1764 1.1 pho CALL_BINARY_INIT(38);
1765 1.1 pho #undef CALL_BINARY_INIT
1766 1.1 pho default:
1767 1.1 pho UNKNOWN_VERSION(fs->op_version);
1768 1.1 pho }
1769 1.1 pho }
1770 1.1 pho
1771 1.1 pho void
1772 1.1 pho fuse_fs_destroy(struct fuse_fs *fs) {
1773 1.1 pho clobber_context_user_data(fs);
1774 1.1 pho switch (fs->op_version) {
1775 1.1 pho /* destroy() appeared on FUSE 2.3. */
1776 1.1 pho case 11:
1777 1.1 pho case 21:
1778 1.1 pho case 22:
1779 1.1 pho break;
1780 1.1 pho
1781 1.1 pho #define CALL_DESTROY(VER) \
1782 1.1 pho case VER: \
1783 1.1 pho if (((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->destroy) \
1784 1.1 pho ((const struct __CONCAT(fuse_operations_v,VER)*)fs->op)->destroy(fs->user_data); \
1785 1.1 pho break
1786 1.1 pho CALL_DESTROY(23);
1787 1.1 pho CALL_DESTROY(25);
1788 1.1 pho CALL_DESTROY(26);
1789 1.1 pho CALL_DESTROY(28);
1790 1.1 pho CALL_DESTROY(29);
1791 1.1 pho CALL_DESTROY(30);
1792 1.1 pho CALL_DESTROY(34);
1793 1.1 pho CALL_DESTROY(38);
1794 1.1 pho #undef CALL_DESTROY
1795 1.1 pho default:
1796 1.1 pho UNKNOWN_VERSION(fs->op_version);
1797 1.1 pho }
1798 1.1 pho
1799 1.1 pho /* fuse_fs_destroy(3) also deallocates struct fuse_fs itself. */
1800 1.1 pho free(fs->op);
1801 1.1 pho free(fs);
1802 1.1 pho }
1803