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