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