xref: /haiku/headers/private/userlandfs/fuse/fuse.h (revision 4bd0c1066b227cec4b79883bdef697c7a27f2e90)
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
17  * header.  To use the newest API define it to 26 (recommended for any
18  * new application), to use the old API define it to 21 (default) 22
19  * or 25, to use the even older 1.X API define it to 11.
20  */
21 
22 #ifndef FUSE_USE_VERSION
23 #define FUSE_USE_VERSION 21
24 #endif
25 
26 #include "fuse_common.h"
27 
28 #include <fcntl.h>
29 #include <time.h>
30 #include <utime.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <sys/statvfs.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #ifdef HAS_FUSE_HAIKU_EXTENSIONS
40 struct fs_info;
41 extern int gHasHaikuFuseExtensions;
42 #endif
43 
44 /* ----------------------------------------------------------- *
45  * Basic FUSE API					       *
46  * ----------------------------------------------------------- */
47 
48 /** Handle for a FUSE filesystem */
49 struct fuse;
50 
51 /** Structure containing a raw command */
52 struct fuse_cmd;
53 
54 /** Function to add an entry in a readdir() operation
55  *
56  * @param buf the buffer passed to the readdir() operation
57  * @param name the file name of the directory entry
58  * @param stat file attributes, can be NULL
59  * @param off offset of the next entry or zero
60  * @return 1 if buffer is full, zero otherwise
61  */
62 typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
63 				const struct stat *stbuf, off_t off);
64 
65 /* Used by deprecated getdir() method */
66 typedef struct fuse_dirhandle *fuse_dirh_t;
67 typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type,
68 			      ino_t ino);
69 
70 /**
71  * The file system operations:
72  *
73  * Most of these should work very similarly to the well known UNIX
74  * file system operations.  A major exception is that instead of
75  * returning an error in 'errno', the operation should return the
76  * negated error value (-errno) directly.
77  *
78  * All methods are optional, but some are essential for a useful
79  * filesystem (e.g. getattr).  Open, flush, release, fsync, opendir,
80  * releasedir, fsyncdir, access, create, ftruncate, fgetattr, lock,
81  * init and destroy are special purpose methods, without which a full
82  * featured filesystem can still be implemented.
83  */
84 struct fuse_operations {
85 	/** Get file attributes.
86 	 *
87 	 * Similar to stat().  The 'st_dev' and 'st_blksize' fields are
88 	 * ignored.	 The 'st_ino' field is ignored except if the 'use_ino'
89 	 * mount option is given.
90 	 */
91 	int (*getattr) (const char *, struct stat *);
92 
93 	/** Read the target of a symbolic link
94 	 *
95 	 * The buffer should be filled with a null terminated string.  The
96 	 * buffer size argument includes the space for the terminating
97 	 * null character.	If the linkname is too long to fit in the
98 	 * buffer, it should be truncated.	The return value should be 0
99 	 * for success.
100 	 */
101 	int (*readlink) (const char *, char *, size_t);
102 
103 	/* Deprecated, use readdir() instead */
104 	int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
105 
106 	/** Create a file node
107 	 *
108 	 * This is called for creation of all non-directory, non-symlink
109 	 * nodes.  If the filesystem defines a create() method, then for
110 	 * regular files that will be called instead.
111 	 */
112 	int (*mknod) (const char *, mode_t, dev_t);
113 
114 	/** Create a directory */
115 	int (*mkdir) (const char *, mode_t);
116 
117 	/** Remove a file */
118 	int (*unlink) (const char *);
119 
120 	/** Remove a directory */
121 	int (*rmdir) (const char *);
122 
123 	/** Create a symbolic link */
124 	int (*symlink) (const char *, const char *);
125 
126 	/** Rename a file */
127 	int (*rename) (const char *, const char *);
128 
129 	/** Create a hard link to a file */
130 	int (*link) (const char *, const char *);
131 
132 	/** Change the permission bits of a file */
133 	int (*chmod) (const char *, mode_t);
134 
135 	/** Change the owner and group of a file */
136 	int (*chown) (const char *, uid_t, gid_t);
137 
138 	/** Change the size of a file */
139 	int (*truncate) (const char *, off_t);
140 
141 	/** Change the access and/or modification times of a file
142 	 *
143 	 * Deprecated, use utimens() instead.
144 	 */
145 	int (*utime) (const char *, struct utimbuf *);
146 
147 	/** File open operation
148 	 *
149 	 * No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC)
150 	 * will be passed to open().  Open should check if the operation
151 	 * is permitted for the given flags.  Optionally open may also
152 	 * return an arbitrary filehandle in the fuse_file_info structure,
153 	 * which will be passed to all file operations.
154 	 *
155 	 * Changed in version 2.2
156 	 */
157 	int (*open) (const char *, struct fuse_file_info *);
158 
159 	/** Read data from an open file
160 	 *
161 	 * Read should return exactly the number of bytes requested except
162 	 * on EOF or error, otherwise the rest of the data will be
163 	 * substituted with zeroes.	 An exception to this is when the
164 	 * 'direct_io' mount option is specified, in which case the return
165 	 * value of the read system call will reflect the return value of
166 	 * this operation.
167 	 *
168 	 * Changed in version 2.2
169 	 */
170 	int (*read) (const char *, char *, size_t, off_t,
171 		     struct fuse_file_info *);
172 
173 	/** Write data to an open file
174 	 *
175 	 * Write should return exactly the number of bytes requested
176 	 * except on error.	 An exception to this is when the 'direct_io'
177 	 * mount option is specified (see read operation).
178 	 *
179 	 * Changed in version 2.2
180 	 */
181 	int (*write) (const char *, const char *, size_t, off_t,
182 		      struct fuse_file_info *);
183 
184 	/** Get file system statistics
185 	 *
186 	 * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
187 	 *
188 	 * Replaced 'struct statfs' parameter with 'struct statvfs' in
189 	 * version 2.5
190 	 */
191 	int (*statfs) (const char *, struct statvfs *);
192 
193 	/** Possibly flush cached data
194 	 *
195 	 * BIG NOTE: This is not equivalent to fsync().  It's not a
196 	 * request to sync dirty data.
197 	 *
198 	 * Flush is called on each close() of a file descriptor.  So if a
199 	 * filesystem wants to return write errors in close() and the file
200 	 * has cached dirty data, this is a good place to write back data
201 	 * and return any errors.  Since many applications ignore close()
202 	 * errors this is not always useful.
203 	 *
204 	 * NOTE: The flush() method may be called more than once for each
205 	 * open().	This happens if more than one file descriptor refers
206 	 * to an opened file due to dup(), dup2() or fork() calls.	It is
207 	 * not possible to determine if a flush is final, so each flush
208 	 * should be treated equally.  Multiple write-flush sequences are
209 	 * relatively rare, so this shouldn't be a problem.
210 	 *
211 	 * Filesystems shouldn't assume that flush will always be called
212 	 * after some writes, or that if will be called at all.
213 	 *
214 	 * Changed in version 2.2
215 	 */
216 	int (*flush) (const char *, struct fuse_file_info *);
217 
218 	/** Release an open file
219 	 *
220 	 * Release is called when there are no more references to an open
221 	 * file: all file descriptors are closed and all memory mappings
222 	 * are unmapped.
223 	 *
224 	 * For every open() call there will be exactly one release() call
225 	 * with the same flags and file descriptor.	 It is possible to
226 	 * have a file opened more than once, in which case only the last
227 	 * release will mean, that no more reads/writes will happen on the
228 	 * file.  The return value of release is ignored.
229 	 *
230 	 * Changed in version 2.2
231 	 */
232 	int (*release) (const char *, struct fuse_file_info *);
233 
234 	/** Synchronize file contents
235 	 *
236 	 * If the datasync parameter is non-zero, then only the user data
237 	 * should be flushed, not the meta data.
238 	 *
239 	 * Changed in version 2.2
240 	 */
241 	int (*fsync) (const char *, int, struct fuse_file_info *);
242 
243 	/** Set extended attributes */
244 	int (*setxattr) (const char *, const char *, const char *, size_t, int);
245 
246 	/** Get extended attributes */
247 	int (*getxattr) (const char *, const char *, char *, size_t);
248 
249 	/** List extended attributes */
250 	int (*listxattr) (const char *, char *, size_t);
251 
252 	/** Remove extended attributes */
253 	int (*removexattr) (const char *, const char *);
254 
255 	/** Open directory
256 	 *
257 	 * This method should check if the open operation is permitted for
258 	 * this  directory
259 	 *
260 	 * Introduced in version 2.3
261 	 */
262 	int (*opendir) (const char *, struct fuse_file_info *);
263 
264 	/** Read directory
265 	 *
266 	 * This supersedes the old getdir() interface.  New applications
267 	 * should use this.
268 	 *
269 	 * The filesystem may choose between two modes of operation:
270 	 *
271 	 * 1) The readdir implementation ignores the offset parameter, and
272 	 * passes zero to the filler function's offset.  The filler
273 	 * function will not return '1' (unless an error happens), so the
274 	 * whole directory is read in a single readdir operation.  This
275 	 * works just like the old getdir() method.
276 	 *
277 	 * 2) The readdir implementation keeps track of the offsets of the
278 	 * directory entries.  It uses the offset parameter and always
279 	 * passes non-zero offset to the filler function.  When the buffer
280 	 * is full (or an error happens) the filler function will return
281 	 * '1'.
282 	 *
283 	 * Introduced in version 2.3
284 	 */
285 	int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
286 			struct fuse_file_info *);
287 
288 	/** Release directory
289 	 *
290 	 * Introduced in version 2.3
291 	 */
292 	int (*releasedir) (const char *, struct fuse_file_info *);
293 
294 	/** Synchronize directory contents
295 	 *
296 	 * If the datasync parameter is non-zero, then only the user data
297 	 * should be flushed, not the meta data
298 	 *
299 	 * Introduced in version 2.3
300 	 */
301 	int (*fsyncdir) (const char *, int, struct fuse_file_info *);
302 
303 	/**
304 	 * Initialize filesystem
305 	 *
306 	 * The return value will passed in the private_data field of
307 	 * fuse_context to all file operations and as a parameter to the
308 	 * destroy() method.
309 	 *
310 	 * Introduced in version 2.3
311 	 * Changed in version 2.6
312 	 */
313 	void *(*init) (struct fuse_conn_info *conn);
314 
315 	/**
316 	 * Clean up filesystem
317 	 *
318 	 * Called on filesystem exit.
319 	 *
320 	 * Introduced in version 2.3
321 	 */
322 	void (*destroy) (void *);
323 
324 	/**
325 	 * Check file access permissions
326 	 *
327 	 * This will be called for the access() system call.  If the
328 	 * 'default_permissions' mount option is given, this method is not
329 	 * called.
330 	 *
331 	 * This method is not called under Linux kernel versions 2.4.x
332 	 *
333 	 * Introduced in version 2.5
334 	 */
335 	int (*access) (const char *, int);
336 
337 	/**
338 	 * Create and open a file
339 	 *
340 	 * If the file does not exist, first create it with the specified
341 	 * mode, and then open it.
342 	 *
343 	 * If this method is not implemented or under Linux kernel
344 	 * versions earlier than 2.6.15, the mknod() and open() methods
345 	 * will be called instead.
346 	 *
347 	 * Introduced in version 2.5
348 	 */
349 	int (*create) (const char *, mode_t, struct fuse_file_info *);
350 
351 	/**
352 	 * Change the size of an open file
353 	 *
354 	 * This method is called instead of the truncate() method if the
355 	 * truncation was invoked from an ftruncate() system call.
356 	 *
357 	 * If this method is not implemented or under Linux kernel
358 	 * versions earlier than 2.6.15, the truncate() method will be
359 	 * called instead.
360 	 *
361 	 * Introduced in version 2.5
362 	 */
363 	int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
364 
365 	/**
366 	 * Get attributes from an open file
367 	 *
368 	 * This method is called instead of the getattr() method if the
369 	 * file information is available.
370 	 *
371 	 * Currently this is only called after the create() method if that
372 	 * is implemented (see above).  Later it may be called for
373 	 * invocations of fstat() too.
374 	 *
375 	 * Introduced in version 2.5
376 	 */
377 	int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
378 
379 	/**
380 	 * Perform POSIX file locking operation
381 	 *
382 	 * The cmd argument will be either F_GETLK, F_SETLK or F_SETLKW.
383 	 *
384 	 * For the meaning of fields in 'struct flock' see the man page
385 	 * for fcntl(2).  The l_whence field will always be set to
386 	 * SEEK_SET.
387 	 *
388 	 * For checking lock ownership, the 'fuse_file_info->owner'
389 	 * argument must be used.
390 	 *
391 	 * For F_GETLK operation, the library will first check currently
392 	 * held locks, and if a conflicting lock is found it will return
393 	 * information without calling this method.	 This ensures, that
394 	 * for local locks the l_pid field is correctly filled in.	The
395 	 * results may not be accurate in case of race conditions and in
396 	 * the presence of hard links, but it's unlikly that an
397 	 * application would rely on accurate GETLK results in these
398 	 * cases.  If a conflicting lock is not found, this method will be
399 	 * called, and the filesystem may fill out l_pid by a meaningful
400 	 * value, or it may leave this field zero.
401 	 *
402 	 * For F_SETLK and F_SETLKW the l_pid field will be set to the pid
403 	 * of the process performing the locking operation.
404 	 *
405 	 * Note: if this method is not implemented, the kernel will still
406 	 * allow file locking to work locally.  Hence it is only
407 	 * interesting for network filesystems and similar.
408 	 *
409 	 * Introduced in version 2.6
410 	 */
411 	int (*lock) (const char *, struct fuse_file_info *, int cmd,
412 		     struct flock *);
413 
414 	/**
415 	 * Change the access and modification times of a file with
416 	 * nanosecond resolution
417 	 *
418 	 * Introduced in version 2.6
419 	 */
420 	int (*utimens) (const char *, const struct timespec tv[2]);
421 
422 	/**
423 	 * Map block index within file to block index within device
424 	 *
425 	 * Note: This makes sense only for block device backed filesystems
426 	 * mounted with the 'blkdev' option
427 	 *
428 	 * Introduced in version 2.6
429 	 */
430 	int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
431 
432 #ifdef HAS_FUSE_HAIKU_EXTENSIONS
433 	int (*get_fs_info) (struct fs_info*);
434 #endif
435 };
436 
437 /** Extra context that may be needed by some filesystems
438  *
439  * The uid, gid and pid fields are not filled in case of a writepage
440  * operation.
441  */
442 struct fuse_context {
443 	/** Pointer to the fuse object */
444 	struct fuse *fuse;
445 
446 	/** User ID of the calling process */
447 	uid_t uid;
448 
449 	/** Group ID of the calling process */
450 	gid_t gid;
451 
452 	/** Thread ID of the calling process */
453 	pid_t pid;
454 
455 	/** Private filesystem data */
456 	void *private_data;
457 };
458 
459 /**
460  * Main function of FUSE.
461  *
462  * This is for the lazy.  This is all that has to be called from the
463  * main() function.
464  *
465  * This function does the following:
466  *   - parses command line options (-d -s and -h)
467  *   - passes relevant mount options to the fuse_mount()
468  *   - installs signal handlers for INT, HUP, TERM and PIPE
469  *   - registers an exit handler to unmount the filesystem on program exit
470  *   - creates a fuse handle
471  *   - registers the operations
472  *   - calls either the single-threaded or the multi-threaded event loop
473  *
474  * Note: this is currently implemented as a macro.
475  *
476  * @param argc the argument counter passed to the main() function
477  * @param argv the argument vector passed to the main() function
478  * @param op the file system operation
479  * @param user_data user data supplied in the context during the init() method
480  * @return 0 on success, nonzero on failure
481  */
482 /*
483   int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
484   void *user_data);
485 */
486 #define fuse_main(argc, argv, op, user_data)				\
487 	fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
488 
489 /* ----------------------------------------------------------- *
490  * More detailed API					       *
491  * ----------------------------------------------------------- */
492 
493 /**
494  * Create a new FUSE filesystem.
495  *
496  * @param ch the communication channel
497  * @param args argument vector
498  * @param op the filesystem operations
499  * @param op_size the size of the fuse_operations structure
500  * @param user_data user data supplied in the context during the init() method
501  * @return the created FUSE handle
502  */
503 struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
504 		      const struct fuse_operations *op, size_t op_size,
505 		      void *user_data);
506 
507 /**
508  * Destroy the FUSE handle.
509  *
510  * The communication channel attached to the handle is also destroyed.
511  *
512  * NOTE: This function does not unmount the filesystem.	 If this is
513  * needed, call fuse_unmount() before calling this function.
514  *
515  * @param f the FUSE handle
516  */
517 void fuse_destroy(struct fuse *f);
518 
519 /**
520  * FUSE event loop.
521  *
522  * Requests from the kernel are processed, and the appropriate
523  * operations are called.
524  *
525  * @param f the FUSE handle
526  * @return 0 if no error occurred, -1 otherwise
527  */
528 int fuse_loop(struct fuse *f);
529 
530 /**
531  * Exit from event loop
532  *
533  * @param f the FUSE handle
534  */
535 void fuse_exit(struct fuse *f);
536 
537 /**
538  * FUSE event loop with multiple threads
539  *
540  * Requests from the kernel are processed, and the appropriate
541  * operations are called.  Request are processed in parallel by
542  * distributing them between multiple threads.
543  *
544  * Calling this function requires the pthreads library to be linked to
545  * the application.
546  *
547  * @param f the FUSE handle
548  * @return 0 if no error occurred, -1 otherwise
549  */
550 int fuse_loop_mt(struct fuse *f);
551 
552 /**
553  * Get the current context
554  *
555  * The context is only valid for the duration of a filesystem
556  * operation, and thus must not be stored and used later.
557  *
558  * @return the context
559  */
560 struct fuse_context *fuse_get_context(void);
561 
562 /**
563  * Check if a request has already been interrupted
564  *
565  * @param req request handle
566  * @return 1 if the request has been interrupted, 0 otherwise
567  */
568 int fuse_interrupted(void);
569 
570 /**
571  * Obsolete, doesn't do anything
572  *
573  * @return -EINVAL
574  */
575 int fuse_invalidate(struct fuse *f, const char *path);
576 
577 /* Deprecated, don't use */
578 int fuse_is_lib_option(const char *opt);
579 
580 /**
581  * The real main function
582  *
583  * Do not call this directly, use fuse_main()
584  */
585 int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
586 		   size_t op_size, void *user_data);
587 
588 /*
589  * Stacking API
590  */
591 
592 /**
593  * Fuse filesystem object
594  *
595  * This is opaque object represents a filesystem layer
596  */
597 struct fuse_fs;
598 
599 /*
600  * These functions call the relevant filesystem operation, and return
601  * the result.
602  *
603  * If the operation is not defined, they return -ENOSYS, with the
604  * exception of fuse_fs_open, fuse_fs_release, fuse_fs_opendir,
605  * fuse_fs_releasedir and fuse_fs_statfs, which return 0.
606  */
607 
608 int fuse_fs_getattr(struct fuse_fs *fs, const char *path, struct stat *buf);
609 int fuse_fs_fgetattr(struct fuse_fs *fs, const char *path, struct stat *buf,
610 		     struct fuse_file_info *fi);
611 int fuse_fs_rename(struct fuse_fs *fs, const char *oldpath,
612 		   const char *newpath);
613 int fuse_fs_unlink(struct fuse_fs *fs, const char *path);
614 int fuse_fs_rmdir(struct fuse_fs *fs, const char *path);
615 int fuse_fs_symlink(struct fuse_fs *fs, const char *linkname,
616 		    const char *path);
617 int fuse_fs_link(struct fuse_fs *fs, const char *oldpath, const char *newpath);
618 int fuse_fs_release(struct fuse_fs *fs,	 const char *path,
619 		    struct fuse_file_info *fi);
620 int fuse_fs_open(struct fuse_fs *fs, const char *path,
621 		 struct fuse_file_info *fi);
622 int fuse_fs_read(struct fuse_fs *fs, const char *path, char *buf, size_t size,
623 		 off_t off, struct fuse_file_info *fi);
624 int fuse_fs_write(struct fuse_fs *fs, const char *path, const char *buf,
625 		  size_t size, off_t off, struct fuse_file_info *fi);
626 int fuse_fs_fsync(struct fuse_fs *fs, const char *path, int datasync,
627 		  struct fuse_file_info *fi);
628 int fuse_fs_flush(struct fuse_fs *fs, const char *path,
629 		  struct fuse_file_info *fi);
630 int fuse_fs_statfs(struct fuse_fs *fs, const char *path, struct statvfs *buf);
631 int fuse_fs_opendir(struct fuse_fs *fs, const char *path,
632 		    struct fuse_file_info *fi);
633 int fuse_fs_readdir(struct fuse_fs *fs, const char *path, void *buf,
634 		    fuse_fill_dir_t filler, off_t off,
635 		    struct fuse_file_info *fi);
636 int fuse_fs_fsyncdir(struct fuse_fs *fs, const char *path, int datasync,
637 		     struct fuse_file_info *fi);
638 int fuse_fs_releasedir(struct fuse_fs *fs, const char *path,
639 		       struct fuse_file_info *fi);
640 int fuse_fs_create(struct fuse_fs *fs, const char *path, mode_t mode,
641 		   struct fuse_file_info *fi);
642 int fuse_fs_lock(struct fuse_fs *fs, const char *path,
643 		 struct fuse_file_info *fi, int cmd, struct flock *lock);
644 int fuse_fs_chmod(struct fuse_fs *fs, const char *path, mode_t mode);
645 int fuse_fs_chown(struct fuse_fs *fs, const char *path, uid_t uid, gid_t gid);
646 int fuse_fs_truncate(struct fuse_fs *fs, const char *path, off_t size);
647 int fuse_fs_ftruncate(struct fuse_fs *fs, const char *path, off_t size,
648 		      struct fuse_file_info *fi);
649 int fuse_fs_utimens(struct fuse_fs *fs, const char *path,
650 		    const struct timespec tv[2]);
651 int fuse_fs_access(struct fuse_fs *fs, const char *path, int mask);
652 int fuse_fs_readlink(struct fuse_fs *fs, const char *path, char *buf,
653 		     size_t len);
654 int fuse_fs_mknod(struct fuse_fs *fs, const char *path, mode_t mode,
655 		  dev_t rdev);
656 int fuse_fs_mkdir(struct fuse_fs *fs, const char *path, mode_t mode);
657 int fuse_fs_setxattr(struct fuse_fs *fs, const char *path, const char *name,
658 		     const char *value, size_t size, int flags);
659 int fuse_fs_getxattr(struct fuse_fs *fs, const char *path, const char *name,
660 		     char *value, size_t size);
661 int fuse_fs_listxattr(struct fuse_fs *fs, const char *path, char *list,
662 		      size_t size);
663 int fuse_fs_removexattr(struct fuse_fs *fs, const char *path,
664 			const char *name);
665 int fuse_fs_bmap(struct fuse_fs *fs, const char *path, size_t blocksize,
666 		 uint64_t *idx);
667 void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn);
668 void fuse_fs_destroy(struct fuse_fs *fs);
669 
670 #ifdef HAS_FUSE_HAIKU_EXTENSIONS
671 int fuse_fs_get_fs_info(struct fuse_fs* fs, struct fs_info* info);
672 #endif
673 
674 /**
675  * Create a new fuse filesystem object
676  *
677  * This is usually called from the factory of a fuse module to create
678  * a new instance of a filesystem.
679  *
680  * @param op the filesystem operations
681  * @param op_size the size of the fuse_operations structure
682  * @param user_data user data supplied in the context during the init() method
683  * @return a new filesystem object
684  */
685 struct fuse_fs *fuse_fs_new(const struct fuse_operations *op, size_t op_size,
686 			    void *user_data);
687 
688 /**
689  * Filesystem module
690  *
691  * Filesystem modules are registered with the FUSE_REGISTER_MODULE()
692  * macro.
693  *
694  * If the "-omodules=modname:..." option is present, filesystem
695  * objects are created and pushed onto the stack with the 'factory'
696  * function.
697  */
698 struct fuse_module {
699 	/**
700 	 * Name of filesystem
701 	 */
702 	const char *name;
703 
704 	/**
705 	 * Factory for creating filesystem objects
706 	 *
707 	 * The function may use and remove options from 'args' that belong
708 	 * to this module.
709 	 *
710 	 * For now the 'fs' vector always contains exactly one filesystem.
711 	 * This is the filesystem which will be below the newly created
712 	 * filesystem in the stack.
713 	 *
714 	 * @param args the command line arguments
715 	 * @param fs NULL terminated filesystem object vector
716 	 * @return the new filesystem object
717 	 */
718 	struct fuse_fs *(*factory)(struct fuse_args *args,
719 				   struct fuse_fs *fs[]);
720 
721 	struct fuse_module *next;
722 	struct fusemod_so *so;
723 	int ctr;
724 };
725 
726 /**
727  * Register a filesystem module
728  *
729  * This function is used by FUSE_REGISTER_MODULE and there's usually
730  * no need to call it directly
731  */
732 void fuse_register_module(struct fuse_module *mod);
733 
734 /**
735  * Register filesystem module
736  *
737  * For the parameters, see description of the fields in 'struct
738  * fuse_module'
739  */
740 #define FUSE_REGISTER_MODULE(name_, factory_)				  \
741 	static __attribute__((constructor)) void name_ ## _register(void) \
742 	{								  \
743 		static struct fuse_module mod =				  \
744 			{ #name_, factory_, NULL, NULL, 0 };		  \
745 		fuse_register_module(&mod);				  \
746 	}
747 
748 
749 /* ----------------------------------------------------------- *
750  * Advanced API for event handling, don't worry about this...  *
751  * ----------------------------------------------------------- */
752 
753 /* NOTE: the following functions are deprecated, and will be removed
754    from the 3.0 API.  Use the lowlevel session functions instead */
755 
756 /** Function type used to process commands */
757 typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
758 
759 /** This is the part of fuse_main() before the event loop */
760 struct fuse *fuse_setup(int argc, char *argv[],
761 			const struct fuse_operations *op, size_t op_size,
762 			char **mountpoint, int *multithreaded,
763 			void *user_data);
764 
765 /** This is the part of fuse_main() after the event loop */
766 void fuse_teardown(struct fuse *fuse, char *mountpoint);
767 
768 /** Read a single command.  If none are read, return NULL */
769 struct fuse_cmd *fuse_read_cmd(struct fuse *f);
770 
771 /** Process a single command */
772 void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
773 
774 /** Multi threaded event loop, which calls the custom command
775     processor function */
776 int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data);
777 
778 /** Return the exited flag, which indicates if fuse_exit() has been
779     called */
780 int fuse_exited(struct fuse *f);
781 
782 /** This function is obsolete and implemented as a no-op */
783 void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
784 
785 /** Get session from fuse object */
786 struct fuse_session *fuse_get_session(struct fuse *f);
787 
788 /* ----------------------------------------------------------- *
789  * Compatibility stuff					       *
790  * ----------------------------------------------------------- */
791 
792 #if FUSE_USE_VERSION < 26
793 #  include "fuse_compat.h"
794 #  undef fuse_main
795 #  if FUSE_USE_VERSION == 25
796 #    define fuse_main(argc, argv, op)				\
797 	fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
798 #    define fuse_new fuse_new_compat25
799 #    define fuse_setup fuse_setup_compat25
800 #    define fuse_teardown fuse_teardown_compat22
801 #    define fuse_operations fuse_operations_compat25
802 #  elif FUSE_USE_VERSION == 22
803 #    define fuse_main(argc, argv, op)				\
804 	fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
805 #    define fuse_new fuse_new_compat22
806 #    define fuse_setup fuse_setup_compat22
807 #    define fuse_teardown fuse_teardown_compat22
808 #    define fuse_operations fuse_operations_compat22
809 #    define fuse_file_info fuse_file_info_compat
810 #  elif FUSE_USE_VERSION == 24
811 #    error Compatibility with high-level API version 24 not supported
812 #  else
813 #    define fuse_dirfil_t fuse_dirfil_t_compat
814 #    define __fuse_read_cmd fuse_read_cmd
815 #    define __fuse_process_cmd fuse_process_cmd
816 #    define __fuse_loop_mt fuse_loop_mt_proc
817 #    if FUSE_USE_VERSION == 21
818 #      define fuse_operations fuse_operations_compat2
819 #      define fuse_main fuse_main_compat2
820 #      define fuse_new fuse_new_compat2
821 #      define __fuse_setup fuse_setup_compat2
822 #      define __fuse_teardown fuse_teardown_compat22
823 #      define __fuse_exited fuse_exited
824 #      define __fuse_set_getcontext_func fuse_set_getcontext_func
825 #    else
826 #      define fuse_statfs fuse_statfs_compat1
827 #      define fuse_operations fuse_operations_compat1
828 #      define fuse_main fuse_main_compat1
829 #      define fuse_new fuse_new_compat1
830 #      define FUSE_DEBUG FUSE_DEBUG_COMPAT1
831 #    endif
832 #  endif
833 #endif
834 
835 #ifdef __cplusplus
836 }
837 #endif
838 
839 #endif /* _FUSE_H_ */
840