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