/src/libfuse/include/fuse.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | FUSE: Filesystem in Userspace |
3 | | Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu> |
4 | | |
5 | | This program can be distributed under the terms of the GNU LGPLv2. |
6 | | See the file LGPL2.txt. |
7 | | */ |
8 | | |
9 | | #ifndef FUSE_H_ |
10 | | #define FUSE_H_ |
11 | | |
12 | | /** @file |
13 | | * |
14 | | * This file defines the library interface of FUSE |
15 | | * |
16 | | * IMPORTANT: you should define FUSE_USE_VERSION before including this header. |
17 | | */ |
18 | | |
19 | | #include "fuse_common.h" |
20 | | |
21 | | #include <fcntl.h> |
22 | | #include <time.h> |
23 | | #include <sys/types.h> |
24 | | #include <sys/stat.h> |
25 | | #include <sys/statvfs.h> |
26 | | #include <sys/uio.h> |
27 | | |
28 | | #ifdef __cplusplus |
29 | | extern "C" { |
30 | | #endif |
31 | | |
32 | | /* ----------------------------------------------------------- * |
33 | | * Basic FUSE API * |
34 | | * ----------------------------------------------------------- */ |
35 | | |
36 | | /** Handle for a FUSE filesystem */ |
37 | | struct fuse; |
38 | | |
39 | | /** |
40 | | * Readdir flags, passed to ->readdir() |
41 | | */ |
42 | | enum fuse_readdir_flags { |
43 | | /** |
44 | | * "Plus" mode. |
45 | | * |
46 | | * The kernel wants to prefill the inode cache during readdir. The |
47 | | * filesystem may honour this by filling in the attributes and setting |
48 | | * FUSE_FILL_DIR_FLAGS for the filler function. The filesystem may also |
49 | | * just ignore this flag completely. |
50 | | */ |
51 | | FUSE_READDIR_DEFAULTS = 0, |
52 | | FUSE_READDIR_PLUS = (1 << 0) |
53 | | }; |
54 | | |
55 | | /** |
56 | | * Readdir flags, passed to fuse_fill_dir_t callback. |
57 | | */ |
58 | | enum fuse_fill_dir_flags { |
59 | | /** |
60 | | * "Plus" mode: all file attributes are valid |
61 | | * |
62 | | * The attributes are used by the kernel to prefill the inode cache |
63 | | * during a readdir. |
64 | | * |
65 | | * It is okay to set FUSE_FILL_DIR_PLUS if FUSE_READDIR_PLUS is not set |
66 | | * and vice versa. |
67 | | */ |
68 | | FUSE_FILL_DIR_DEFAULTS = 0, |
69 | | FUSE_FILL_DIR_PLUS = (1 << 1) |
70 | | }; |
71 | | |
72 | | /** Function to add an entry in a readdir() operation |
73 | | * |
74 | | * The *off* parameter can be any non-zero value that enables the |
75 | | * filesystem to identify the current point in the directory |
76 | | * stream. It does not need to be the actual physical position. A |
77 | | * value of zero is reserved to indicate that seeking in directories |
78 | | * is not supported. |
79 | | * |
80 | | * @param buf the buffer passed to the readdir() operation |
81 | | * @param name the file name of the directory entry |
82 | | * @param stbuf file attributes, can be NULL |
83 | | * @param off offset of the next entry or zero |
84 | | * @param flags fill flags |
85 | | * @return 1 if buffer is full, zero otherwise |
86 | | */ |
87 | | typedef int (*fuse_fill_dir_t) (void *buf, const char *name, |
88 | | const struct stat *stbuf, off_t off, |
89 | | enum fuse_fill_dir_flags flags); |
90 | | /** |
91 | | * Configuration of the high-level API |
92 | | * |
93 | | * This structure is initialized from the arguments passed to |
94 | | * fuse_new(), and then passed to the file system's init() handler |
95 | | * which should ensure that the configuration is compatible with the |
96 | | * file system implementation. |
97 | | * |
98 | | * Note: this data structure is ABI sensitive, new options have to be |
99 | | * appended at the end of the structure |
100 | | */ |
101 | | struct fuse_config { |
102 | | /** |
103 | | * If `set_gid` is non-zero, the st_gid attribute of each file |
104 | | * is overwritten with the value of `gid`. |
105 | | */ |
106 | | int32_t set_gid; |
107 | | uint32_t gid; |
108 | | |
109 | | /** |
110 | | * If `set_uid` is non-zero, the st_uid attribute of each file |
111 | | * is overwritten with the value of `uid`. |
112 | | */ |
113 | | int32_t set_uid; |
114 | | uint32_t uid; |
115 | | |
116 | | /** |
117 | | * If `set_mode` is non-zero, the any permissions bits set in |
118 | | * `umask` are unset in the st_mode attribute of each file. |
119 | | */ |
120 | | int32_t set_mode; |
121 | | uint32_t umask; |
122 | | |
123 | | /** |
124 | | * The timeout in seconds for which name lookups will be |
125 | | * cached. |
126 | | */ |
127 | | double entry_timeout; |
128 | | |
129 | | /** |
130 | | * The timeout in seconds for which a negative lookup will be |
131 | | * cached. This means, that if file did not exist (lookup |
132 | | * returned ENOENT), the lookup will only be redone after the |
133 | | * timeout, and the file/directory will be assumed to not |
134 | | * exist until then. A value of zero means that negative |
135 | | * lookups are not cached. |
136 | | */ |
137 | | double negative_timeout; |
138 | | |
139 | | /** |
140 | | * The timeout in seconds for which file/directory attributes |
141 | | * (as returned by e.g. the `getattr` handler) are cached. |
142 | | */ |
143 | | double attr_timeout; |
144 | | |
145 | | /** |
146 | | * Allow requests to be interrupted |
147 | | */ |
148 | | int32_t intr; |
149 | | |
150 | | /** |
151 | | * Specify which signal number to send to the filesystem when |
152 | | * a request is interrupted. The default is hardcoded to |
153 | | * USR1. |
154 | | */ |
155 | | int32_t intr_signal; |
156 | | |
157 | | /** |
158 | | * Normally, FUSE assigns inodes to paths only for as long as |
159 | | * the kernel is aware of them. With this option inodes are |
160 | | * instead remembered for at least this many seconds. This |
161 | | * will require more memory, but may be necessary when using |
162 | | * applications that make use of inode numbers. |
163 | | * |
164 | | * A number of -1 means that inodes will be remembered for the |
165 | | * entire life-time of the file-system process. |
166 | | */ |
167 | | int32_t remember; |
168 | | |
169 | | /** |
170 | | * The default behavior is that if an open file is deleted, |
171 | | * the file is renamed to a hidden file (.fuse_hiddenXXX), and |
172 | | * only removed when the file is finally released. This |
173 | | * relieves the filesystem implementation of having to deal |
174 | | * with this problem. This option disables the hiding |
175 | | * behavior, and files are removed immediately in an unlink |
176 | | * operation (or in a rename operation which overwrites an |
177 | | * existing file). |
178 | | * |
179 | | * It is recommended that you not use the hard_remove |
180 | | * option. When hard_remove is set, the following libc |
181 | | * functions fail on unlinked files (returning errno of |
182 | | * ENOENT): read(2), write(2), fsync(2), close(2), f*xattr(2), |
183 | | * ftruncate(2), fstat(2), fchmod(2), fchown(2) |
184 | | */ |
185 | | int32_t hard_remove; |
186 | | |
187 | | /** |
188 | | * Honor the st_ino field in the functions getattr() and |
189 | | * fill_dir(). This value is used to fill in the st_ino field |
190 | | * in the stat(2), lstat(2), fstat(2) functions and the d_ino |
191 | | * field in the readdir(2) function. The filesystem does not |
192 | | * have to guarantee uniqueness, however some applications |
193 | | * rely on this value being unique for the whole filesystem. |
194 | | * |
195 | | * Note that this does *not* affect the inode that libfuse |
196 | | * and the kernel use internally (also called the "nodeid"). |
197 | | */ |
198 | | int32_t use_ino; |
199 | | |
200 | | /** |
201 | | * If use_ino option is not given, still try to fill in the |
202 | | * d_ino field in readdir(2). If the name was previously |
203 | | * looked up, and is still in the cache, the inode number |
204 | | * found there will be used. Otherwise it will be set to -1. |
205 | | * If use_ino option is given, this option is ignored. |
206 | | */ |
207 | | int32_t readdir_ino; |
208 | | |
209 | | /** |
210 | | * This option disables the use of page cache (file content cache) |
211 | | * in the kernel for this filesystem. This has several affects: |
212 | | * |
213 | | * 1. Each read(2) or write(2) system call will initiate one |
214 | | * or more read or write operations, data will not be |
215 | | * cached in the kernel. |
216 | | * |
217 | | * 2. The return value of the read() and write() system calls |
218 | | * will correspond to the return values of the read and |
219 | | * write operations. This is useful for example if the |
220 | | * file size is not known in advance (before reading it). |
221 | | * |
222 | | * Internally, enabling this option causes fuse to set the |
223 | | * `direct_io` field of `struct fuse_file_info` - overwriting |
224 | | * any value that was put there by the file system. |
225 | | */ |
226 | | int32_t direct_io; |
227 | | |
228 | | /** |
229 | | * This option disables flushing the cache of the file |
230 | | * contents on every open(2). This should only be enabled on |
231 | | * filesystems where the file data is never changed |
232 | | * externally (not through the mounted FUSE filesystem). Thus |
233 | | * it is not suitable for network filesystems and other |
234 | | * intermediate filesystems. |
235 | | * |
236 | | * NOTE: if this option is not specified (and neither |
237 | | * direct_io) data is still cached after the open(2), so a |
238 | | * read(2) system call will not always initiate a read |
239 | | * operation. |
240 | | * |
241 | | * Internally, enabling this option causes fuse to set the |
242 | | * `keep_cache` field of `struct fuse_file_info` - overwriting |
243 | | * any value that was put there by the file system. |
244 | | */ |
245 | | int32_t kernel_cache; |
246 | | |
247 | | /** |
248 | | * This option is an alternative to `kernel_cache`. Instead of |
249 | | * unconditionally keeping cached data, the cached data is |
250 | | * invalidated on open(2) if if the modification time or the |
251 | | * size of the file has changed since it was last opened. |
252 | | */ |
253 | | int32_t auto_cache; |
254 | | |
255 | | /* |
256 | | * The timeout in seconds for which file attributes are cached |
257 | | * for the purpose of checking if auto_cache should flush the |
258 | | * file data on open. |
259 | | */ |
260 | | int32_t ac_attr_timeout_set; |
261 | | double ac_attr_timeout; |
262 | | |
263 | | /** |
264 | | * If this option is given the file-system handlers for the |
265 | | * following operations will not receive path information: |
266 | | * read, write, flush, release, fallocate, fsync, readdir, |
267 | | * releasedir, fsyncdir, lock, ioctl and poll. |
268 | | * |
269 | | * For the truncate, getattr, chmod, chown and utimens |
270 | | * operations the path will be provided only if the struct |
271 | | * fuse_file_info argument is NULL. |
272 | | */ |
273 | | int32_t nullpath_ok; |
274 | | |
275 | | /** |
276 | | * These 3 options are used by libfuse internally and |
277 | | * should not be touched. |
278 | | */ |
279 | | int32_t show_help; |
280 | | char *modules; |
281 | | int32_t debug; |
282 | | |
283 | | /** |
284 | | * `fmask` and `dmask` function the same way as `umask`, but apply |
285 | | * to files and directories separately. If non-zero, `fmask` and |
286 | | * `dmask` take precedence over the `umask` setting. |
287 | | */ |
288 | | uint32_t fmask; |
289 | | uint32_t dmask; |
290 | | |
291 | | /** |
292 | | * By default, fuse waits for all pending writes to complete |
293 | | * and calls the FLUSH operation on close(2) of every fuse fd. |
294 | | * With this option, wait and FLUSH are not done for read-only |
295 | | * fuse fd, similar to the behavior of NFS/SMB clients. |
296 | | */ |
297 | | int32_t no_rofd_flush; |
298 | | |
299 | | /** |
300 | | * Allow parallel direct-io writes to operate on the same file. |
301 | | * |
302 | | * FUSE implementations which do not handle parallel writes on |
303 | | * same file/region should NOT enable this option at all as it |
304 | | * might lead to data inconsistencies. |
305 | | * |
306 | | * For the FUSE implementations which have their own mechanism |
307 | | * of cache/data integrity are beneficiaries of this setting as |
308 | | * it now open doors to parallel writes on the same file (without |
309 | | * enabling this setting, all direct writes on the same file are |
310 | | * serialized, resulting in huge data bandwidth loss). |
311 | | */ |
312 | | int32_t parallel_direct_writes; |
313 | | |
314 | | |
315 | | /** |
316 | | * Reserved for future use. |
317 | | */ |
318 | | uint32_t flags; |
319 | | |
320 | | /** |
321 | | * Reserved for future use. |
322 | | */ |
323 | | uint64_t reserved[48]; |
324 | | }; |
325 | | |
326 | | |
327 | | /** |
328 | | * The file system operations: |
329 | | * |
330 | | * Most of these should work very similarly to the well known UNIX |
331 | | * file system operations. A major exception is that instead of |
332 | | * returning an error in 'errno', the operation should return the |
333 | | * negated error value (-errno) directly. |
334 | | * |
335 | | * All methods are optional, but some are essential for a useful |
336 | | * filesystem (e.g. getattr). Open, flush, release, fsync, opendir, |
337 | | * releasedir, fsyncdir, access, create, truncate, lock, init and |
338 | | * destroy are special purpose methods, without which a full featured |
339 | | * filesystem can still be implemented. |
340 | | * |
341 | | * In general, all methods are expected to perform any necessary |
342 | | * permission checking. However, a filesystem may delegate this task |
343 | | * to the kernel by passing the `default_permissions` mount option to |
344 | | * `fuse_new()`. In this case, methods will only be called if |
345 | | * the kernel's permission check has succeeded. |
346 | | * |
347 | | * Almost all operations take a path which can be of any length. |
348 | | */ |
349 | | struct fuse_operations { |
350 | | /** Get file attributes. |
351 | | * |
352 | | * Similar to stat(). The 'st_dev' and 'st_blksize' fields are |
353 | | * ignored. The 'st_ino' field is ignored except if the 'use_ino' |
354 | | * mount option is given. In that case it is passed to userspace, |
355 | | * but libfuse and the kernel will still assign a different |
356 | | * inode for internal use (called the "nodeid"). |
357 | | * |
358 | | * `fi` will always be NULL if the file is not currently open, but |
359 | | * may also be NULL if the file is open. |
360 | | */ |
361 | | int (*getattr) (const char *, struct stat *, struct fuse_file_info *fi); |
362 | | |
363 | | /** Read the target of a symbolic link |
364 | | * |
365 | | * The buffer should be filled with a null terminated string. The |
366 | | * buffer size argument includes the space for the terminating |
367 | | * null character. If the linkname is too long to fit in the |
368 | | * buffer, it should be truncated. The return value should be 0 |
369 | | * for success. |
370 | | */ |
371 | | int (*readlink) (const char *, char *, size_t); |
372 | | |
373 | | /** Create a file node |
374 | | * |
375 | | * This is called for creation of all non-directory, non-symlink |
376 | | * nodes. If the filesystem defines a create() method, then for |
377 | | * regular files that will be called instead. |
378 | | */ |
379 | | int (*mknod) (const char *, mode_t, dev_t); |
380 | | |
381 | | /** Create a directory |
382 | | * |
383 | | * Note that the mode argument may not have the type specification |
384 | | * bits set, i.e. S_ISDIR(mode) can be false. To obtain the |
385 | | * correct directory type bits use mode|S_IFDIR |
386 | | * */ |
387 | | int (*mkdir) (const char *, mode_t); |
388 | | |
389 | | /** Remove a file */ |
390 | | int (*unlink) (const char *); |
391 | | |
392 | | /** Remove a directory */ |
393 | | int (*rmdir) (const char *); |
394 | | |
395 | | /** Create a symbolic link */ |
396 | | int (*symlink) (const char *, const char *); |
397 | | |
398 | | /** Rename a file |
399 | | * |
400 | | * *flags* may be `RENAME_EXCHANGE` or `RENAME_NOREPLACE`. If |
401 | | * RENAME_NOREPLACE is specified, the filesystem must not |
402 | | * overwrite *newname* if it exists and return an error |
403 | | * instead. If `RENAME_EXCHANGE` is specified, the filesystem |
404 | | * must atomically exchange the two files, i.e. both must |
405 | | * exist and neither may be deleted. |
406 | | */ |
407 | | int (*rename) (const char *, const char *, unsigned int flags); |
408 | | |
409 | | /** Create a hard link to a file */ |
410 | | int (*link) (const char *, const char *); |
411 | | |
412 | | /** Change the permission bits of a file |
413 | | * |
414 | | * `fi` will always be NULL if the file is not currently open, but |
415 | | * may also be NULL if the file is open. |
416 | | */ |
417 | | int (*chmod) (const char *, mode_t, struct fuse_file_info *fi); |
418 | | |
419 | | /** Change the owner and group of a file |
420 | | * |
421 | | * `fi` will always be NULL if the file is not currently open, but |
422 | | * may also be NULL if the file is open. |
423 | | * |
424 | | * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is |
425 | | * expected to reset the setuid and setgid bits. |
426 | | */ |
427 | | int (*chown) (const char *, uid_t, gid_t, struct fuse_file_info *fi); |
428 | | |
429 | | /** Change the size of a file |
430 | | * |
431 | | * `fi` will always be NULL if the file is not currently open, but |
432 | | * may also be NULL if the file is open. |
433 | | * |
434 | | * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is |
435 | | * expected to reset the setuid and setgid bits. |
436 | | */ |
437 | | int (*truncate) (const char *, off_t, struct fuse_file_info *fi); |
438 | | |
439 | | /** Open a file |
440 | | * |
441 | | * Open flags are available in fi->flags. The following rules |
442 | | * apply. |
443 | | * |
444 | | * - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be |
445 | | * filtered out / handled by the kernel. |
446 | | * |
447 | | * - Access modes (O_RDONLY, O_WRONLY, O_RDWR, O_EXEC, O_SEARCH) |
448 | | * should be used by the filesystem to check if the operation is |
449 | | * permitted. If the ``-o default_permissions`` mount option is |
450 | | * given, this check is already done by the kernel before calling |
451 | | * open() and may thus be omitted by the filesystem. |
452 | | * |
453 | | * - When writeback caching is enabled, the kernel may send |
454 | | * read requests even for files opened with O_WRONLY. The |
455 | | * filesystem should be prepared to handle this. |
456 | | * |
457 | | * - When writeback caching is disabled, the filesystem is |
458 | | * expected to properly handle the O_APPEND flag and ensure |
459 | | * that each write is appending to the end of the file. |
460 | | * |
461 | | * - When writeback caching is enabled, the kernel will |
462 | | * handle O_APPEND. However, unless all changes to the file |
463 | | * come through the kernel this will not work reliably. The |
464 | | * filesystem should thus either ignore the O_APPEND flag |
465 | | * (and let the kernel handle it), or return an error |
466 | | * (indicating that reliably O_APPEND is not available). |
467 | | * |
468 | | * Filesystem may store an arbitrary file handle (pointer, |
469 | | * index, etc) in fi->fh, and use this in other all other file |
470 | | * operations (read, write, flush, release, fsync). |
471 | | * |
472 | | * Filesystem may also implement stateless file I/O and not store |
473 | | * anything in fi->fh. |
474 | | * |
475 | | * There are also some flags (direct_io, keep_cache) which the |
476 | | * filesystem may set in fi, to change the way the file is opened. |
477 | | * See fuse_file_info structure in <fuse_common.h> for more details. |
478 | | * |
479 | | * If this request is answered with an error code of ENOSYS |
480 | | * and FUSE_CAP_NO_OPEN_SUPPORT is set in |
481 | | * `fuse_conn_info.capable`, this is treated as success and |
482 | | * future calls to open will also succeed without being sent |
483 | | * to the filesystem process. |
484 | | * |
485 | | */ |
486 | | int (*open) (const char *, struct fuse_file_info *); |
487 | | |
488 | | /** Read data from an open file |
489 | | * |
490 | | * Read should return exactly the number of bytes requested except |
491 | | * on EOF or error, otherwise the rest of the data will be |
492 | | * substituted with zeroes. An exception to this is when the |
493 | | * 'direct_io' mount option is specified, in which case the return |
494 | | * value of the read system call will reflect the return value of |
495 | | * this operation. |
496 | | */ |
497 | | int (*read) (const char *, char *, size_t, off_t, |
498 | | struct fuse_file_info *); |
499 | | |
500 | | /** Write data to an open file |
501 | | * |
502 | | * Write should return exactly the number of bytes requested |
503 | | * except on error. An exception to this is when the 'direct_io' |
504 | | * mount option is specified (see read operation). |
505 | | * |
506 | | * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is |
507 | | * expected to reset the setuid and setgid bits. |
508 | | */ |
509 | | int (*write) (const char *, const char *, size_t, off_t, |
510 | | struct fuse_file_info *); |
511 | | |
512 | | /** Get file system statistics |
513 | | * |
514 | | * The 'f_favail', 'f_fsid' and 'f_flag' fields are ignored |
515 | | */ |
516 | | int (*statfs) (const char *, struct statvfs *); |
517 | | |
518 | | /** Possibly flush cached data |
519 | | * |
520 | | * BIG NOTE: This is not equivalent to fsync(). It's not a |
521 | | * request to sync dirty data. |
522 | | * |
523 | | * Flush is called on each close() of a file descriptor, as opposed to |
524 | | * release which is called on the close of the last file descriptor for |
525 | | * a file. Under Linux, errors returned by flush() will be passed to |
526 | | * userspace as errors from close(), so flush() is a good place to write |
527 | | * back any cached dirty data. However, many applications ignore errors |
528 | | * on close(), and on non-Linux systems, close() may succeed even if flush() |
529 | | * returns an error. For these reasons, filesystems should not assume |
530 | | * that errors returned by flush will ever be noticed or even |
531 | | * delivered. |
532 | | * |
533 | | * NOTE: The flush() method may be called more than once for each |
534 | | * open(). This happens if more than one file descriptor refers to an |
535 | | * open file handle, e.g. due to dup(), dup2() or fork() calls. It is |
536 | | * not possible to determine if a flush is final, so each flush should |
537 | | * be treated equally. Multiple write-flush sequences are relatively |
538 | | * rare, so this shouldn't be a problem. |
539 | | * |
540 | | * Filesystems shouldn't assume that flush will be called at any |
541 | | * particular point. It may be called more times than expected, or not |
542 | | * at all. |
543 | | * |
544 | | * [close]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html |
545 | | */ |
546 | | int (*flush) (const char *, struct fuse_file_info *); |
547 | | |
548 | | /** Release an open file |
549 | | * |
550 | | * Release is called when there are no more references to an open |
551 | | * file: all file descriptors are closed and all memory mappings |
552 | | * are unmapped. |
553 | | * |
554 | | * For every open() call there will be exactly one release() call |
555 | | * with the same flags and file handle. It is possible to |
556 | | * have a file opened more than once, in which case only the last |
557 | | * release will mean, that no more reads/writes will happen on the |
558 | | * file. The return value of release is ignored. |
559 | | */ |
560 | | int (*release) (const char *, struct fuse_file_info *); |
561 | | |
562 | | /** Synchronize file contents |
563 | | * |
564 | | * If the datasync parameter is non-zero, then only the user data |
565 | | * should be flushed, not the meta data. |
566 | | */ |
567 | | int (*fsync) (const char *, int, struct fuse_file_info *); |
568 | | |
569 | | /** Set extended attributes */ |
570 | | int (*setxattr) (const char *, const char *, const char *, size_t, int); |
571 | | |
572 | | /** Get extended attributes */ |
573 | | int (*getxattr) (const char *, const char *, char *, size_t); |
574 | | |
575 | | /** List extended attributes */ |
576 | | int (*listxattr) (const char *, char *, size_t); |
577 | | |
578 | | /** Remove extended attributes */ |
579 | | int (*removexattr) (const char *, const char *); |
580 | | |
581 | | /** Open directory |
582 | | * |
583 | | * Unless the 'default_permissions' mount option is given, |
584 | | * this method should check if opendir is permitted for this |
585 | | * directory. Optionally opendir may also return an arbitrary |
586 | | * filehandle in the fuse_file_info structure, which will be |
587 | | * passed to readdir, releasedir and fsyncdir. |
588 | | */ |
589 | | int (*opendir) (const char *, struct fuse_file_info *); |
590 | | |
591 | | /** Read directory |
592 | | * |
593 | | * The filesystem may choose between two modes of operation: |
594 | | * |
595 | | * 1) The readdir implementation ignores the offset parameter, and |
596 | | * passes zero to the filler function's offset. The filler |
597 | | * function will not return '1' (unless an error happens), so the |
598 | | * whole directory is read in a single readdir operation. |
599 | | * |
600 | | * 2) The readdir implementation keeps track of the offsets of the |
601 | | * directory entries. It uses the offset parameter and always |
602 | | * passes non-zero offset to the filler function. When the buffer |
603 | | * is full (or an error happens) the filler function will return |
604 | | * '1'. |
605 | | * |
606 | | * When FUSE_READDIR_PLUS is not set, only some parameters of the |
607 | | * fill function (the fuse_fill_dir_t parameter) are actually used: |
608 | | * The file type (which is part of stat::st_mode) is used. And if |
609 | | * fuse_config::use_ino is set, the inode (stat::st_ino) is also |
610 | | * used. The other fields are ignored when FUSE_READDIR_PLUS is not |
611 | | * set. |
612 | | */ |
613 | | int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t, |
614 | | struct fuse_file_info *, enum fuse_readdir_flags); |
615 | | |
616 | | /** Release directory |
617 | | * |
618 | | * If the directory has been removed after the call to opendir, the |
619 | | * path parameter will be NULL. |
620 | | */ |
621 | | int (*releasedir) (const char *, struct fuse_file_info *); |
622 | | |
623 | | /** Synchronize directory contents |
624 | | * |
625 | | * If the directory has been removed after the call to opendir, the |
626 | | * path parameter will be NULL. |
627 | | * |
628 | | * If the datasync parameter is non-zero, then only the user data |
629 | | * should be flushed, not the meta data |
630 | | */ |
631 | | int (*fsyncdir) (const char *, int, struct fuse_file_info *); |
632 | | |
633 | | /** |
634 | | * Initialize filesystem |
635 | | * |
636 | | * The return value will passed in the `private_data` field of |
637 | | * `struct fuse_context` to all file operations, and as a |
638 | | * parameter to the destroy() method. It overrides the initial |
639 | | * value provided to fuse_main() / fuse_new(). |
640 | | */ |
641 | | void *(*init) (struct fuse_conn_info *conn, |
642 | | struct fuse_config *cfg); |
643 | | |
644 | | /** |
645 | | * Clean up filesystem |
646 | | * |
647 | | * Called on filesystem exit. |
648 | | */ |
649 | | void (*destroy) (void *private_data); |
650 | | |
651 | | /** |
652 | | * Check file access permissions |
653 | | * |
654 | | * This will be called for the access() system call. If the |
655 | | * 'default_permissions' mount option is given, this method is not |
656 | | * called. |
657 | | * |
658 | | * This method is not called under Linux kernel versions 2.4.x |
659 | | */ |
660 | | int (*access) (const char *, int); |
661 | | |
662 | | /** |
663 | | * Create and open a file |
664 | | * |
665 | | * If the file does not exist, first create it with the specified |
666 | | * mode, and then open it. |
667 | | * |
668 | | * If this method is not implemented or under Linux kernel |
669 | | * versions earlier than 2.6.15, the mknod() and open() methods |
670 | | * will be called instead. |
671 | | */ |
672 | | int (*create) (const char *, mode_t, struct fuse_file_info *); |
673 | | |
674 | | /** |
675 | | * Perform POSIX file locking operation |
676 | | * |
677 | | * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW. |
678 | | * |
679 | | * For the meaning of fields in 'struct flock' see the man page |
680 | | * for fcntl(2). The l_whence field will always be set to |
681 | | * SEEK_SET. |
682 | | * |
683 | | * For checking lock ownership, the 'fuse_file_info->owner' |
684 | | * argument must be used. |
685 | | * |
686 | | * For F_GETLK operation, the library will first check currently |
687 | | * held locks, and if a conflicting lock is found it will return |
688 | | * information without calling this method. This ensures, that |
689 | | * for local locks the l_pid field is correctly filled in. The |
690 | | * results may not be accurate in case of race conditions and in |
691 | | * the presence of hard links, but it's unlikely that an |
692 | | * application would rely on accurate GETLK results in these |
693 | | * cases. If a conflicting lock is not found, this method will be |
694 | | * called, and the filesystem may fill out l_pid by a meaningful |
695 | | * value, or it may leave this field zero. |
696 | | * |
697 | | * For F_SETLK and F_SETLKW the l_pid field will be set to the pid |
698 | | * of the process performing the locking operation. |
699 | | * |
700 | | * Note: if this method is not implemented, the kernel will still |
701 | | * allow file locking to work locally. Hence it is only |
702 | | * interesting for network filesystems and similar. |
703 | | */ |
704 | | int (*lock) (const char *, struct fuse_file_info *, int cmd, |
705 | | struct flock *); |
706 | | |
707 | | /** |
708 | | * Change the access and modification times of a file with |
709 | | * nanosecond resolution |
710 | | * |
711 | | * This supersedes the old utime() interface. New applications |
712 | | * should use this. |
713 | | * |
714 | | * `fi` will always be NULL if the file is not currently open, but |
715 | | * may also be NULL if the file is open. |
716 | | * |
717 | | * See the utimensat(2) man page for details. |
718 | | */ |
719 | | int (*utimens) (const char *, const struct timespec tv[2], |
720 | | struct fuse_file_info *fi); |
721 | | |
722 | | /** |
723 | | * Map block index within file to block index within device |
724 | | * |
725 | | * Note: This makes sense only for block device backed filesystems |
726 | | * mounted with the 'blkdev' option |
727 | | */ |
728 | | int (*bmap) (const char *, size_t blocksize, uint64_t *idx); |
729 | | |
730 | | #if FUSE_USE_VERSION < 35 |
731 | | int (*ioctl) (const char *, int cmd, void *arg, |
732 | | struct fuse_file_info *, unsigned int flags, void *data); |
733 | | #else |
734 | | /** |
735 | | * Ioctl |
736 | | * |
737 | | * flags will have FUSE_IOCTL_COMPAT set for 32bit ioctls in |
738 | | * 64bit environment. The size and direction of data is |
739 | | * determined by _IOC_*() decoding of cmd. For _IOC_NONE, |
740 | | * data will be NULL, for _IOC_WRITE data is out area, for |
741 | | * _IOC_READ in area and if both are set in/out area. In all |
742 | | * non-NULL cases, the area is of _IOC_SIZE(cmd) bytes. |
743 | | * |
744 | | * If flags has FUSE_IOCTL_DIR then the fuse_file_info refers to a |
745 | | * directory file handle. |
746 | | * |
747 | | * Note : the unsigned long request submitted by the application |
748 | | * is truncated to 32 bits. |
749 | | */ |
750 | | int (*ioctl) (const char *, unsigned int cmd, void *arg, |
751 | | struct fuse_file_info *, unsigned int flags, void *data); |
752 | | #endif |
753 | | |
754 | | /** |
755 | | * Poll for IO readiness events |
756 | | * |
757 | | * Note: If ph is non-NULL, the client should notify |
758 | | * when IO readiness events occur by calling |
759 | | * fuse_notify_poll() with the specified ph. |
760 | | * |
761 | | * Regardless of the number of times poll with a non-NULL ph |
762 | | * is received, single notification is enough to clear all. |
763 | | * Notifying more times incurs overhead but doesn't harm |
764 | | * correctness. |
765 | | * |
766 | | * The callee is responsible for destroying ph with |
767 | | * fuse_pollhandle_destroy() when no longer in use. |
768 | | */ |
769 | | int (*poll) (const char *, struct fuse_file_info *, |
770 | | struct fuse_pollhandle *ph, unsigned *reventsp); |
771 | | |
772 | | /** Write contents of buffer to an open file |
773 | | * |
774 | | * Similar to the write() method, but data is supplied in a |
775 | | * generic buffer. Use fuse_buf_copy() to transfer data to |
776 | | * the destination. |
777 | | * |
778 | | * Unless FUSE_CAP_HANDLE_KILLPRIV is disabled, this method is |
779 | | * expected to reset the setuid and setgid bits. |
780 | | */ |
781 | | int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off, |
782 | | struct fuse_file_info *); |
783 | | |
784 | | /** Store data from an open file in a buffer |
785 | | * |
786 | | * Similar to the read() method, but data is stored and |
787 | | * returned in a generic buffer. |
788 | | * |
789 | | * No actual copying of data has to take place, the source |
790 | | * file descriptor may simply be stored in the buffer for |
791 | | * later data transfer. |
792 | | * |
793 | | * The buffer must be allocated dynamically and stored at the |
794 | | * location pointed to by bufp. If the buffer contains memory |
795 | | * regions, they too must be allocated using malloc(). The |
796 | | * allocated memory will be freed by the caller. |
797 | | */ |
798 | | int (*read_buf) (const char *, struct fuse_bufvec **bufp, |
799 | | size_t size, off_t off, struct fuse_file_info *); |
800 | | /** |
801 | | * Perform BSD file locking operation |
802 | | * |
803 | | * The op argument will be either LOCK_SH, LOCK_EX or LOCK_UN |
804 | | * |
805 | | * Nonblocking requests will be indicated by ORing LOCK_NB to |
806 | | * the above operations |
807 | | * |
808 | | * For more information see the flock(2) manual page. |
809 | | * |
810 | | * Additionally fi->owner will be set to a value unique to |
811 | | * this open file. This same value will be supplied to |
812 | | * ->release() when the file is released. |
813 | | * |
814 | | * Note: if this method is not implemented, the kernel will still |
815 | | * allow file locking to work locally. Hence it is only |
816 | | * interesting for network filesystems and similar. |
817 | | */ |
818 | | int (*flock) (const char *, struct fuse_file_info *, int op); |
819 | | |
820 | | /** |
821 | | * Allocates space for an open file |
822 | | * |
823 | | * This function ensures that required space is allocated for specified |
824 | | * file. If this function returns success then any subsequent write |
825 | | * request to specified range is guaranteed not to fail because of lack |
826 | | * of space on the file system media. |
827 | | */ |
828 | | int (*fallocate) (const char *, int, off_t, off_t, |
829 | | struct fuse_file_info *); |
830 | | |
831 | | /** |
832 | | * Copy a range of data from one file to another |
833 | | * |
834 | | * Performs an optimized copy between two file descriptors without the |
835 | | * additional cost of transferring data through the FUSE kernel module |
836 | | * to user space (glibc) and then back into the FUSE filesystem again. |
837 | | * |
838 | | * In case this method is not implemented, applications are expected to |
839 | | * fall back to a regular file copy. (Some glibc versions did this |
840 | | * emulation automatically, but the emulation has been removed from all |
841 | | * glibc release branches.) |
842 | | */ |
843 | | ssize_t (*copy_file_range) (const char *path_in, |
844 | | struct fuse_file_info *fi_in, |
845 | | off_t offset_in, const char *path_out, |
846 | | struct fuse_file_info *fi_out, |
847 | | off_t offset_out, size_t size, int flags); |
848 | | |
849 | | /** |
850 | | * Find next data or hole after the specified offset |
851 | | */ |
852 | | off_t (*lseek) (const char *, off_t off, int whence, struct fuse_file_info *); |
853 | | }; |
854 | | |
855 | | /** Extra context that may be needed by some filesystems |
856 | | * |
857 | | * The uid, gid and pid fields are not filled in case of a writepage |
858 | | * operation. |
859 | | */ |
860 | | struct fuse_context { |
861 | | /** Pointer to the fuse object */ |
862 | | struct fuse *fuse; |
863 | | |
864 | | /** User ID of the calling process */ |
865 | | uid_t uid; |
866 | | |
867 | | /** Group ID of the calling process */ |
868 | | gid_t gid; |
869 | | |
870 | | /** Process ID of the calling thread */ |
871 | | pid_t pid; |
872 | | |
873 | | /** Private filesystem data */ |
874 | | void *private_data; |
875 | | |
876 | | /** Umask of the calling process */ |
877 | | mode_t umask; |
878 | | }; |
879 | | |
880 | | /** |
881 | | * The real main function |
882 | | * |
883 | | * Do not call this directly, use fuse_main() |
884 | | */ |
885 | | int fuse_main_real_versioned(int argc, char *argv[], |
886 | | const struct fuse_operations *op, size_t op_size, |
887 | | struct libfuse_version *version, void *user_data); |
888 | | static inline int fuse_main_real(int argc, char *argv[], |
889 | | const struct fuse_operations *op, |
890 | | size_t op_size, void *user_data) |
891 | 0 | { |
892 | 0 | struct libfuse_version version = { .major = FUSE_MAJOR_VERSION, |
893 | 0 | .minor = FUSE_MINOR_VERSION, |
894 | 0 | .hotfix = FUSE_HOTFIX_VERSION, |
895 | 0 | .padding = 0 }; |
896 | 0 |
|
897 | 0 | fuse_log(FUSE_LOG_ERR, |
898 | 0 | "%s is a libfuse internal function, please use fuse_main()\n", |
899 | 0 | __func__); |
900 | 0 |
|
901 | 0 | return fuse_main_real_versioned(argc, argv, op, op_size, &version, |
902 | 0 | user_data); |
903 | 0 | } Unexecuted instantiation: fuzz_optparse.c:fuse_main_real Unexecuted instantiation: fuse_opt.c:fuse_main_real |
904 | | |
905 | | /** |
906 | | * Main function of FUSE. |
907 | | * |
908 | | * This is for the lazy. This is all that has to be called from the |
909 | | * main() function. |
910 | | * |
911 | | * This function does the following: |
912 | | * - parses command line options, and handles --help and |
913 | | * --version |
914 | | * - installs signal handlers for INT, HUP, TERM and PIPE |
915 | | * - registers an exit handler to unmount the filesystem on program exit |
916 | | * - creates a fuse handle |
917 | | * - registers the operations |
918 | | * - calls either the single-threaded or the multi-threaded event loop |
919 | | * |
920 | | * Most file systems will have to parse some file-system specific |
921 | | * arguments before calling this function. It is recommended to do |
922 | | * this with fuse_opt_parse() and a processing function that passes |
923 | | * through any unknown options (this can also be achieved by just |
924 | | * passing NULL as the processing function). That way, the remaining |
925 | | * options can be passed directly to fuse_main(). |
926 | | * |
927 | | * fuse_main() accepts all options that can be passed to |
928 | | * fuse_parse_cmdline(), fuse_new(), or fuse_session_new(). |
929 | | * |
930 | | * Option parsing skips argv[0], which is assumed to contain the |
931 | | * program name. This element must always be present and is used to |
932 | | * construct a basic ``usage: `` message for the --help |
933 | | * output. argv[0] may also be set to the empty string. In this case |
934 | | * the usage message is suppressed. This can be used by file systems |
935 | | * to print their own usage line first. See hello.c for an example of |
936 | | * how to do this. |
937 | | * |
938 | | * Note: this is currently implemented as a macro. |
939 | | * |
940 | | * The following error codes may be returned from fuse_main(): |
941 | | * 1: Invalid option arguments |
942 | | * 2: No mount point specified |
943 | | * 3: FUSE setup failed |
944 | | * 4: Mounting failed |
945 | | * 5: Failed to daemonize (detach from session) |
946 | | * 6: Failed to set up signal handlers |
947 | | * 7: An error occurred during the life of the file system |
948 | | * |
949 | | * @param argc the argument counter passed to the main() function |
950 | | * @param argv the argument vector passed to the main() function |
951 | | * @param op the file system operation |
952 | | * @param private_data Initial value for the `private_data` |
953 | | * field of `struct fuse_context`. May be overridden by the |
954 | | * `struct fuse_operations.init` handler. |
955 | | * @return 0 on success, nonzero on failure |
956 | | * |
957 | | * Example usage, see hello.c |
958 | | */ |
959 | | static inline int fuse_main_fn(int argc, char *argv[], |
960 | | const struct fuse_operations *op, |
961 | | void *user_data) |
962 | 0 | { |
963 | 0 | struct libfuse_version version = { |
964 | 0 | .major = FUSE_MAJOR_VERSION, |
965 | 0 | .minor = FUSE_MINOR_VERSION, |
966 | 0 | .hotfix = FUSE_HOTFIX_VERSION, |
967 | 0 | .padding = 0 |
968 | 0 | }; |
969 | 0 |
|
970 | 0 | return fuse_main_real_versioned(argc, argv, op, sizeof(*(op)), &version, |
971 | 0 | user_data); |
972 | 0 | } Unexecuted instantiation: fuzz_optparse.c:fuse_main_fn Unexecuted instantiation: fuse_opt.c:fuse_main_fn |
973 | | #define fuse_main(argc, argv, op, user_data) \ |
974 | | fuse_main_fn(argc, argv, op, user_data) |
975 | | |
976 | | /* ----------------------------------------------------------- * |
977 | | * More detailed API * |
978 | | * ----------------------------------------------------------- */ |
979 | | |
980 | | /** |
981 | | * Print available options (high- and low-level) to stdout. This is |
982 | | * not an exhaustive list, but includes only those options that may be |
983 | | * of interest to an end-user of a file system. |
984 | | * |
985 | | * The function looks at the argument vector only to determine if |
986 | | * there are additional modules to be loaded (module=foo option), |
987 | | * and attempts to call their help functions as well. |
988 | | * |
989 | | * @param args the argument vector. |
990 | | */ |
991 | | void fuse_lib_help(struct fuse_args *args); |
992 | | |
993 | | /* Do not call this directly, use fuse_new() instead */ |
994 | | struct fuse *_fuse_new_30(struct fuse_args *args, |
995 | | const struct fuse_operations *op, size_t op_size, |
996 | | struct libfuse_version *version, void *user_data); |
997 | | struct fuse *_fuse_new_31(struct fuse_args *args, |
998 | | const struct fuse_operations *op, size_t op_size, |
999 | | struct libfuse_version *version, void *user_data); |
1000 | | |
1001 | | /** |
1002 | | * Create a new FUSE filesystem. |
1003 | | * |
1004 | | * This function accepts most file-system independent mount options |
1005 | | * (like context, nodev, ro - see mount(8)), as well as the |
1006 | | * FUSE-specific mount options from mount.fuse(8). |
1007 | | * |
1008 | | * If the --help option is specified, the function writes a help text |
1009 | | * to stdout and returns NULL. |
1010 | | * |
1011 | | * Option parsing skips argv[0], which is assumed to contain the |
1012 | | * program name. This element must always be present and is used to |
1013 | | * construct a basic ``usage: `` message for the --help output. If |
1014 | | * argv[0] is set to the empty string, no usage message is included in |
1015 | | * the --help output. |
1016 | | * |
1017 | | * If an unknown option is passed in, an error message is written to |
1018 | | * stderr and the function returns NULL. |
1019 | | * |
1020 | | * @param args argument vector |
1021 | | * @param op the filesystem operations |
1022 | | * @param op_size the size of the fuse_operations structure |
1023 | | * @param private_data Initial value for the `private_data` |
1024 | | * field of `struct fuse_context`. May be overridden by the |
1025 | | * `struct fuse_operations.init` handler. |
1026 | | * @return the created FUSE handle |
1027 | | */ |
1028 | | #if FUSE_USE_VERSION == 30 |
1029 | | static inline struct fuse *fuse_new_fn(struct fuse_args *args, |
1030 | | const struct fuse_operations *op, |
1031 | | size_t op_size, void *user_data) |
1032 | | { |
1033 | | struct libfuse_version version = { |
1034 | | .major = FUSE_MAJOR_VERSION, |
1035 | | .minor = FUSE_MINOR_VERSION, |
1036 | | .hotfix = FUSE_HOTFIX_VERSION, |
1037 | | .padding = 0 |
1038 | | }; |
1039 | | |
1040 | | return _fuse_new_30(args, op, op_size, &version, user_data); |
1041 | | } |
1042 | | #else /* FUSE_USE_VERSION */ |
1043 | | static inline struct fuse *fuse_new_fn(struct fuse_args *args, |
1044 | | const struct fuse_operations *op, |
1045 | | size_t op_size, void *user_data) |
1046 | 0 | { |
1047 | 0 | struct libfuse_version version = { |
1048 | 0 | .major = FUSE_MAJOR_VERSION, |
1049 | 0 | .minor = FUSE_MINOR_VERSION, |
1050 | 0 | .hotfix = FUSE_HOTFIX_VERSION, |
1051 | 0 | .padding = 0 |
1052 | 0 | }; |
1053 | 0 |
|
1054 | 0 | return _fuse_new_31(args, op, op_size, &version, user_data); |
1055 | 0 | } Unexecuted instantiation: fuzz_optparse.c:fuse_new_fn Unexecuted instantiation: fuse_opt.c:fuse_new_fn |
1056 | | #endif |
1057 | | #define fuse_new(args, op, size, data) fuse_new_fn(args, op, size, data) |
1058 | | |
1059 | | /** |
1060 | | * Mount a FUSE file system. |
1061 | | * |
1062 | | * @param mountpoint the mount point path |
1063 | | * @param f the FUSE handle |
1064 | | * |
1065 | | * @return 0 on success, -1 on failure. |
1066 | | **/ |
1067 | | int fuse_mount(struct fuse *f, const char *mountpoint); |
1068 | | |
1069 | | /** |
1070 | | * Unmount a FUSE file system. |
1071 | | * |
1072 | | * See fuse_session_unmount() for additional information. |
1073 | | * |
1074 | | * @param f the FUSE handle |
1075 | | **/ |
1076 | | void fuse_unmount(struct fuse *f); |
1077 | | |
1078 | | /** |
1079 | | * Destroy the FUSE handle. |
1080 | | * |
1081 | | * NOTE: This function does not unmount the filesystem. If this is |
1082 | | * needed, call fuse_unmount() before calling this function. |
1083 | | * |
1084 | | * @param f the FUSE handle |
1085 | | */ |
1086 | | void fuse_destroy(struct fuse *f); |
1087 | | |
1088 | | /** |
1089 | | * FUSE event loop. |
1090 | | * |
1091 | | * Requests from the kernel are processed, and the appropriate |
1092 | | * operations are called. |
1093 | | * |
1094 | | * For a description of the return value and the conditions when the |
1095 | | * event loop exits, refer to the documentation of |
1096 | | * fuse_session_loop(). |
1097 | | * |
1098 | | * @param f the FUSE handle |
1099 | | * @return see fuse_session_loop() |
1100 | | * |
1101 | | * See also: fuse_loop_mt() |
1102 | | */ |
1103 | | int fuse_loop(struct fuse *f); |
1104 | | |
1105 | | /** |
1106 | | * Flag session as terminated |
1107 | | * |
1108 | | * This function will cause any running event loops to exit on |
1109 | | * the next opportunity. |
1110 | | * |
1111 | | * @param f the FUSE handle |
1112 | | */ |
1113 | | void fuse_exit(struct fuse *f); |
1114 | | |
1115 | | #if FUSE_USE_VERSION < 32 |
1116 | | int fuse_loop_mt_31(struct fuse *f, int clone_fd); |
1117 | | #define fuse_loop_mt(f, clone_fd) fuse_loop_mt_31(f, clone_fd) |
1118 | | #elif FUSE_USE_VERSION < FUSE_MAKE_VERSION(3, 12) |
1119 | | int fuse_loop_mt_32(struct fuse *f, struct fuse_loop_config *config); |
1120 | | #define fuse_loop_mt(f, config) fuse_loop_mt_32(f, config) |
1121 | | #else |
1122 | | /** |
1123 | | * FUSE event loop with multiple threads |
1124 | | * |
1125 | | * Requests from the kernel are processed, and the appropriate |
1126 | | * operations are called. Request are processed in parallel by |
1127 | | * distributing them between multiple threads. |
1128 | | * |
1129 | | * For a description of the return value and the conditions when the |
1130 | | * event loop exits, refer to the documentation of |
1131 | | * fuse_session_loop(). |
1132 | | * |
1133 | | * Note: using fuse_loop() instead of fuse_loop_mt() means you are running in |
1134 | | * single-threaded mode, and that you will not have to worry about reentrancy, |
1135 | | * though you will have to worry about recursive lookups. In single-threaded |
1136 | | * mode, FUSE will wait for one callback to return before calling another. |
1137 | | * |
1138 | | * Enabling multiple threads, by using fuse_loop_mt(), will cause FUSE to make |
1139 | | * multiple simultaneous calls into the various callback functions given by your |
1140 | | * fuse_operations record. |
1141 | | * |
1142 | | * If you are using multiple threads, you can enjoy all the parallel execution |
1143 | | * and interactive response benefits of threads, and you get to enjoy all the |
1144 | | * benefits of race conditions and locking bugs, too. Ensure that any code used |
1145 | | * in the callback function of fuse_operations is also thread-safe. |
1146 | | * |
1147 | | * @param f the FUSE handle |
1148 | | * @param config loop configuration, may be NULL and defaults will be used then |
1149 | | * @return see fuse_session_loop() |
1150 | | * |
1151 | | * See also: fuse_loop() |
1152 | | */ |
1153 | | #if (defined(LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS)) |
1154 | | int fuse_loop_mt(struct fuse *f, struct fuse_loop_config *config); |
1155 | | #else |
1156 | | #define fuse_loop_mt(f, config) fuse_loop_mt_312(f, config) |
1157 | | #endif /* LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS */ |
1158 | | #endif |
1159 | | |
1160 | | |
1161 | | /** |
1162 | | * Get the current context |
1163 | | * |
1164 | | * The context is only valid for the duration of a filesystem |
1165 | | * operation, and thus must not be stored and used later. |
1166 | | * |
1167 | | * @return the context |
1168 | | */ |
1169 | | struct fuse_context *fuse_get_context(void); |
1170 | | |
1171 | | /** |
1172 | | * Get the current supplementary group IDs for the current request |
1173 | | * |
1174 | | * Similar to the getgroups(2) system call, except the return value is |
1175 | | * always the total number of group IDs, even if it is larger than the |
1176 | | * specified size. |
1177 | | * |
1178 | | * The current fuse kernel module in linux (as of 2.6.30) doesn't pass |
1179 | | * the group list to userspace, hence this function needs to parse |
1180 | | * "/proc/$TID/task/$TID/status" to get the group IDs. |
1181 | | * |
1182 | | * This feature may not be supported on all operating systems. In |
1183 | | * such a case this function will return -ENOSYS. |
1184 | | * |
1185 | | * @param size size of given array |
1186 | | * @param list array of group IDs to be filled in |
1187 | | * @return the total number of supplementary group IDs or -errno on failure |
1188 | | */ |
1189 | | int fuse_getgroups(int size, gid_t list[]); |
1190 | | |
1191 | | /** |
1192 | | * Check if the current request has already been interrupted |
1193 | | * |
1194 | | * @return 1 if the request has been interrupted, 0 otherwise |
1195 | | */ |
1196 | | int fuse_interrupted(void); |
1197 | | |
1198 | | /** |
1199 | | * Invalidates cache for the given path. |
1200 | | * |
1201 | | * This calls fuse_lowlevel_notify_inval_inode internally. |
1202 | | * |
1203 | | * @return 0 on successful invalidation, negative error value otherwise. |
1204 | | * This routine may return -ENOENT to indicate that there was |
1205 | | * no entry to be invalidated, e.g., because the path has not |
1206 | | * been seen before or has been forgotten; this should not be |
1207 | | * considered to be an error. |
1208 | | */ |
1209 | | int fuse_invalidate_path(struct fuse *f, const char *path); |
1210 | | |
1211 | | /** |
1212 | | * Start the cleanup thread when using option "remember". |
1213 | | * |
1214 | | * This is done automatically by fuse_loop_mt() |
1215 | | * @param fuse struct fuse pointer for fuse instance |
1216 | | * @return 0 on success and -1 on error |
1217 | | */ |
1218 | | int fuse_start_cleanup_thread(struct fuse *fuse); |
1219 | | |
1220 | | /** |
1221 | | * Stop the cleanup thread when using option "remember". |
1222 | | * |
1223 | | * This is done automatically by fuse_loop_mt() |
1224 | | * @param fuse struct fuse pointer for fuse instance |
1225 | | */ |
1226 | | void fuse_stop_cleanup_thread(struct fuse *fuse); |
1227 | | |
1228 | | /** |
1229 | | * Iterate over cache removing stale entries |
1230 | | * use in conjunction with "-oremember" |
1231 | | * |
1232 | | * NOTE: This is already done for the standard sessions |
1233 | | * |
1234 | | * @param fuse struct fuse pointer for fuse instance |
1235 | | * @return the number of seconds until the next cleanup |
1236 | | */ |
1237 | | int fuse_clean_cache(struct fuse *fuse); |
1238 | | |
1239 | | /* |
1240 | | * Stacking API |
1241 | | */ |
1242 | | |
1243 | | /** |
1244 | | * Fuse filesystem object |
1245 | | * |
1246 | | * This is opaque object represents a filesystem layer |
1247 | | */ |
1248 | | struct fuse_fs; |
1249 | | |
1250 | | /* |
1251 | | * These functions call the relevant filesystem operation, and return |
1252 | | * the result. |
1253 | | * |
1254 | | * If the operation is not defined, they return -ENOSYS, with the |
1255 | | * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir, |
1256 | | * fuse_fs_releasedir and fuse_fs_statfs, which return 0. |
1257 | | */ |
1258 | | |
1259 | | int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf, |
1260 | | struct fuse_file_info *fi); |
1261 | | int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath, |
1262 | | const char *newpath, unsigned int flags); |
1263 | | int fuse_fs_unlink(struct fuse_fs *fs, const char *path); |
1264 | | int fuse_fs_rmdir(struct fuse_fs *fs, const char *path); |
1265 | | int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname, |
1266 | | const char *path); |
1267 | | int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath); |
1268 | | int fuse_fs_release(struct fuse_fs *fs, const char *path, |
1269 | | struct fuse_file_info *fi); |
1270 | | int fuse_fs_open(struct fuse_fs *fs, const char *path, |
1271 | | struct fuse_file_info *fi); |
1272 | | int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size, |
1273 | | off_t off, struct fuse_file_info *fi); |
1274 | | int fuse_fs_read_buf(struct fuse_fs *fs, const char *path, |
1275 | | struct fuse_bufvec **bufp, size_t size, off_t off, |
1276 | | struct fuse_file_info *fi); |
1277 | | int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf, |
1278 | | size_t size, off_t off, struct fuse_file_info *fi); |
1279 | | int fuse_fs_write_buf(struct fuse_fs *fs, const char *path, |
1280 | | struct fuse_bufvec *buf, off_t off, |
1281 | | struct fuse_file_info *fi); |
1282 | | int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync, |
1283 | | struct fuse_file_info *fi); |
1284 | | int fuse_fs_flush(struct fuse_fs *fs, const char *path, |
1285 | | struct fuse_file_info *fi); |
1286 | | int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf); |
1287 | | int fuse_fs_opendir(struct fuse_fs *fs, const char *path, |
1288 | | struct fuse_file_info *fi); |
1289 | | int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf, |
1290 | | fuse_fill_dir_t filler, off_t off, |
1291 | | struct fuse_file_info *fi, enum fuse_readdir_flags flags); |
1292 | | int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync, |
1293 | | struct fuse_file_info *fi); |
1294 | | int fuse_fs_releasedir(struct fuse_fs *fs, const char *path, |
1295 | | struct fuse_file_info *fi); |
1296 | | int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode, |
1297 | | struct fuse_file_info *fi); |
1298 | | int fuse_fs_lock(struct fuse_fs *fs, const char *path, |
1299 | | struct fuse_file_info *fi, int cmd, struct flock *lock); |
1300 | | int fuse_fs_flock(struct fuse_fs *fs, const char *path, |
1301 | | struct fuse_file_info *fi, int op); |
1302 | | int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode, |
1303 | | struct fuse_file_info *fi); |
1304 | | int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid, |
1305 | | struct fuse_file_info *fi); |
1306 | | int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size, |
1307 | | struct fuse_file_info *fi); |
1308 | | int fuse_fs_utimens(struct fuse_fs *fs, const char *path, |
1309 | | const struct timespec tv[2], struct fuse_file_info *fi); |
1310 | | int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask); |
1311 | | int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf, |
1312 | | size_t len); |
1313 | | int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode, |
1314 | | dev_t rdev); |
1315 | | int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode); |
1316 | | int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name, |
1317 | | const char *value, size_t size, int flags); |
1318 | | int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name, |
1319 | | char *value, size_t size); |
1320 | | int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list, |
1321 | | size_t size); |
1322 | | int fuse_fs_removexattr(struct fuse_fs *fs, const char *path, |
1323 | | const char *name); |
1324 | | int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize, |
1325 | | uint64_t *idx); |
1326 | | #if FUSE_USE_VERSION < 35 |
1327 | | int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, int cmd, |
1328 | | void *arg, struct fuse_file_info *fi, unsigned int flags, |
1329 | | void *data); |
1330 | | #else |
1331 | | int fuse_fs_ioctl(struct fuse_fs *fs, const char *path, unsigned int cmd, |
1332 | | void *arg, struct fuse_file_info *fi, unsigned int flags, |
1333 | | void *data); |
1334 | | #endif |
1335 | | int fuse_fs_poll(struct fuse_fs *fs, const char *path, |
1336 | | struct fuse_file_info *fi, struct fuse_pollhandle *ph, |
1337 | | unsigned *reventsp); |
1338 | | int fuse_fs_fallocate(struct fuse_fs *fs, const char *path, int mode, |
1339 | | off_t offset, off_t length, struct fuse_file_info *fi); |
1340 | | ssize_t fuse_fs_copy_file_range(struct fuse_fs *fs, const char *path_in, |
1341 | | struct fuse_file_info *fi_in, off_t off_in, |
1342 | | const char *path_out, |
1343 | | struct fuse_file_info *fi_out, off_t off_out, |
1344 | | size_t len, int flags); |
1345 | | off_t fuse_fs_lseek(struct fuse_fs *fs, const char *path, off_t off, int whence, |
1346 | | struct fuse_file_info *fi); |
1347 | | void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn, |
1348 | | struct fuse_config *cfg); |
1349 | | void fuse_fs_destroy(struct fuse_fs *fs); |
1350 | | |
1351 | | int fuse_notify_poll(struct fuse_pollhandle *ph); |
1352 | | |
1353 | | /** |
1354 | | * Create a new fuse filesystem object |
1355 | | * |
1356 | | * This is usually called from the factory of a fuse module to create |
1357 | | * a new instance of a filesystem. |
1358 | | * |
1359 | | * @param op the filesystem operations |
1360 | | * @param op_size the size of the fuse_operations structure |
1361 | | * @param private_data Initial value for the `private_data` |
1362 | | * field of `struct fuse_context`. May be overridden by the |
1363 | | * `struct fuse_operations.init` handler. |
1364 | | * @return a new filesystem object |
1365 | | */ |
1366 | | struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size, |
1367 | | void *private_data); |
1368 | | |
1369 | | /** |
1370 | | * Factory for creating filesystem objects |
1371 | | * |
1372 | | * The function may use and remove options from 'args' that belong |
1373 | | * to this module. |
1374 | | * |
1375 | | * For now the 'fs' vector always contains exactly one filesystem. |
1376 | | * This is the filesystem which will be below the newly created |
1377 | | * filesystem in the stack. |
1378 | | * |
1379 | | * @param args the command line arguments |
1380 | | * @param fs NULL terminated filesystem object vector |
1381 | | * @return the new filesystem object |
1382 | | */ |
1383 | | typedef struct fuse_fs *(*fuse_module_factory_t)(struct fuse_args *args, |
1384 | | struct fuse_fs *fs[]); |
1385 | | /** |
1386 | | * Register filesystem module |
1387 | | * |
1388 | | * If the "-omodules=*name*_:..." option is present, filesystem |
1389 | | * objects are created and pushed onto the stack with the *factory_* |
1390 | | * function. |
1391 | | * |
1392 | | * @param name_ the name of this filesystem module |
1393 | | * @param factory_ the factory function for this filesystem module |
1394 | | */ |
1395 | | #define FUSE_REGISTER_MODULE(name_, factory_) \ |
1396 | | fuse_module_factory_t fuse_module_ ## name_ ## _factory = factory_ |
1397 | | |
1398 | | /** Get session from fuse object */ |
1399 | | struct fuse_session *fuse_get_session(struct fuse *f); |
1400 | | |
1401 | | /** |
1402 | | * Open a FUSE file descriptor and set up the mount for the given |
1403 | | * mountpoint and flags. |
1404 | | * |
1405 | | * @param mountpoint reference to the mount in the file system |
1406 | | * @param options mount options |
1407 | | * @return the FUSE file descriptor or -1 upon error |
1408 | | */ |
1409 | | int fuse_open_channel(const char *mountpoint, const char *options); |
1410 | | |
1411 | | #ifdef __cplusplus |
1412 | | } |
1413 | | #endif |
1414 | | |
1415 | | #endif /* FUSE_H_ */ |