blob: 5e5cd4583defaf09e2302090d6f9082e3684dfa3 [file] [log] [blame]
Miklos Szeredi85c74fc2001-10-28 19:44:14 +00001/*
2 FUSE: Filesystem in Userspace
Miklos Szeredi149f6072005-01-10 12:29:28 +00003 Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +00004
Miklos Szeredi8b39a9f2002-10-25 12:41:16 +00005 This program can be distributed under the terms of the GNU LGPL.
6 See the file COPYING.LIB.
Miklos Szeredi85c74fc2001-10-28 19:44:14 +00007*/
8
Miklos Szerediacd4e062001-12-08 20:29:20 +00009#ifndef _FUSE_H_
10#define _FUSE_H_
11
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000012/* This file defines the library interface of FUSE */
13
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +000014/* IMPORTANT: you should define FUSE_USE_VERSION before including this
15 header. To use the new API define it to 22 (recommended for any
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000016 new application), to use the old API define it to 21 (this is the
17 default), to use the even older 1.X API define it to 11. */
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +000018
19#ifndef FUSE_USE_VERSION
20#define FUSE_USE_VERSION 21
21#endif
22
Miklos Szeredi2f3d9402003-12-15 12:11:33 +000023/** Major version of FUSE library interface */
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +000024#define FUSE_MAJOR_VERSION 2
Miklos Szeredi2f3d9402003-12-15 12:11:33 +000025
26/** Minor version of FUSE library interface */
Miklos Szeredif43f0632005-02-28 11:46:56 +000027#define FUSE_MINOR_VERSION 3
Miklos Szeredi2f3d9402003-12-15 12:11:33 +000028
Miklos Szeredi87f30a92004-04-13 10:49:54 +000029/* This interface uses 64 bit off_t */
30#if _FILE_OFFSET_BITS != 64
31#error Please add -D_FILE_OFFSET_BITS=64 to your compile flags!
32#endif
Miklos Szeredi5f054812002-12-03 18:45:21 +000033
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000034#include <sys/types.h>
35#include <sys/stat.h>
Miklos Szeredi18e75e42004-02-19 14:23:27 +000036#include <sys/statfs.h>
Miklos Szeredi5e183482001-10-31 14:52:35 +000037#include <utime.h>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000038
Miklos Szeredi8fb48fe2004-11-08 14:48:52 +000039#ifdef __cplusplus
40extern "C" {
41#endif
42
Miklos Szeredicc8c9752001-11-21 10:03:39 +000043/* ----------------------------------------------------------- *
44 * Basic FUSE API *
45 * ----------------------------------------------------------- */
46
Miklos Szeredi2df1c042001-11-06 15:07:17 +000047/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000048struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000049
50/** Handle for a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000051typedef struct fuse_dirhandle *fuse_dirh_t;
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000052
Miklos Szeredif08ace02003-10-22 11:11:57 +000053/** Function to add an entry in a getdir() operation
Miklos Szeredie5183742005-02-02 11:14:04 +000054 *
Miklos Szeredif08ace02003-10-22 11:11:57 +000055 * @param h the handle passed to the getdir() operation
56 * @param name the file name of the directory entry
57 * @param type the file type (0 if unknown) see <dirent.h>
Miklos Szeredi8fb48fe2004-11-08 14:48:52 +000058 * @param ino the inode number, ignored if "use_ino" mount option is
59 * not specified
Miklos Szeredif08ace02003-10-22 11:11:57 +000060 * @return 0 on success, -errno on error
61 */
Miklos Szeredid507c732004-11-08 17:32:25 +000062typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type,
63 ino_t ino);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000064
Miklos Szeredifb28c5e2004-11-26 12:15:06 +000065/** Information about open files */
66struct fuse_file_info {
67 /** Open flags. Available in open() and release() */
68 int flags;
69
70 /** File handle. May be filled in by filesystem in open().
71 Available in all other file operations */
72 unsigned long fh;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000073
74 /** In case of a write operation indicates if this was caused by a
75 writepage */
76 int writepage;
Miklos Szeredifb28c5e2004-11-26 12:15:06 +000077};
78
Miklos Szeredi2df1c042001-11-06 15:07:17 +000079/**
80 * The file system operations:
81 *
82 * Most of these should work very similarly to the well known UNIX
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000083 * file system operations. A major exception is that instead of
84 * returning an error in 'errno', the operation should return the
Miklos Szeredie5183742005-02-02 11:14:04 +000085 * negated error value (-errno) directly.
Miklos Szeredie56818b2004-12-12 11:45:24 +000086 *
87 * All methods are optional, but some are essential for a useful
Miklos Szeredi159bd7e2005-02-28 17:32:16 +000088 * filesystem (e.g. getattr). Flush, release, fsync, init and destroy
89 * are special purpose methods, without which a full featured
90 * filesystem can still be implemented.
Miklos Szeredie2e4ac22004-05-18 08:45:28 +000091 */
Miklos Szeredia181e612001-11-06 12:03:23 +000092struct fuse_operations {
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000093 /** Get file attributes.
94 *
95 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are
96 * ignored. The 'st_ino' field is ignored except if the 'use_ino'
97 * mount option is given.
98 */
99 int (*getattr) (const char *, struct stat *);
100
101 /** Read the target of a symbolic link
Miklos Szeredie5183742005-02-02 11:14:04 +0000102 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000103 * The buffer should be filled with a null terminated string. The
104 * buffer size argument includes the space for the terminating
105 * null character. If the linkname is too long to fit in the
106 * buffer, it should be truncated. The return value should be 0
107 * for success.
108 */
109 int (*readlink) (const char *, char *, size_t);
110
111 /** Read the contents of a directory
112 *
113 * This operation is the opendir(), readdir(), ..., closedir()
114 * sequence in one call. For each directory entry the filldir
115 * function should be called.
116 */
117 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
118
119 /** Create a file node
120 *
121 * There is no create() operation, mknod() will be called for
122 * creation of all non-directory, non-symlink nodes.
123 */
124 int (*mknod) (const char *, mode_t, dev_t);
125
126 /** Create a directory */
127 int (*mkdir) (const char *, mode_t);
128
129 /** Remove a file */
130 int (*unlink) (const char *);
131
132 /** Remove a directory */
133 int (*rmdir) (const char *);
134
135 /** Create a symbolic link */
136 int (*symlink) (const char *, const char *);
137
138 /** Rename a file */
139 int (*rename) (const char *, const char *);
140
141 /** Create a hard link to a file */
142 int (*link) (const char *, const char *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000143
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000144 /** Change the permission bits of a file */
145 int (*chmod) (const char *, mode_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000146
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000147 /** Change the owner and group of a file */
148 int (*chown) (const char *, uid_t, gid_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000149
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000150 /** Change the size of a file */
151 int (*truncate) (const char *, off_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000152
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000153 /** Change the access and/or modification times of a file */
154 int (*utime) (const char *, struct utimbuf *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000155
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000156 /** File open operation
157 *
158 * No creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC)
159 * will be passed to open(). Open should check if the operation
160 * is permitted for the given flags. Optionally open may also
161 * return an arbitary filehandle in the fuse_file_info structure,
162 * which will be passed to all file operations.
163 */
164 int (*open) (const char *, struct fuse_file_info *);
165
166 /** Read data from an open file
167 *
168 * Read should return exactly the number of bytes requested except
169 * on EOF or error, otherwise the rest of the data will be
170 * substituted with zeroes. An exception to this is when the
171 * 'direct_io' mount option is specified, in which case the return
172 * value of the read system call will reflect the return value of
173 * this operation.
174 */
175 int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *);
176
Miklos Szeredie5183742005-02-02 11:14:04 +0000177 /** Write data to an open file
178 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000179 * Write should return exactly the number of bytes requested
180 * except on error. An exception to this is when the 'direct_io'
181 * mount option is specified (see read operation).
182 */
183 int (*write) (const char *, const char *, size_t, off_t,
184 struct fuse_file_info *);
185
186 /** Get file system statistics
Miklos Szeredie5183742005-02-02 11:14:04 +0000187 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000188 * The 'f_type' and 'f_fsid' fields are ignored
189 */
190 int (*statfs) (const char *, struct statfs *);
191
Miklos Szeredie5183742005-02-02 11:14:04 +0000192 /** Possibly flush cached data
193 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000194 * BIG NOTE: This is not equivalent to fsync(). It's not a
Miklos Szeredie56818b2004-12-12 11:45:24 +0000195 * request to sync dirty data.
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000196 *
197 * Flush is called on each close() of a file descriptor. So if a
198 * filesystem wants to return write errors in close() and the file
199 * has cached dirty data, this is a good place to write back data
Miklos Szeredie56818b2004-12-12 11:45:24 +0000200 * and return any errors. Since many applications ignore close()
201 * errors this is not always useful.
Miklos Szeredie5183742005-02-02 11:14:04 +0000202 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000203 * NOTE: The flush() method may be called more than once for each
204 * open(). This happens if more than one file descriptor refers
205 * to an opened file due to dup(), dup2() or fork() calls. It is
206 * not possible to determine if a flush is final, so each flush
207 * should be treated equally. Multiple write-flush sequences are
208 * relatively rare, so this shouldn't be a problem.
209 */
210 int (*flush) (const char *, struct fuse_file_info *);
211
212 /** Release an open file
Miklos Szeredie5183742005-02-02 11:14:04 +0000213 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000214 * Release is called when there are no more references to an open
215 * file: all file descriptors are closed and all memory mappings
216 * are unmapped.
217 *
218 * For every open() call there will be exactly one release() call
Miklos Szeredie56818b2004-12-12 11:45:24 +0000219 * with the same flags and file descriptor. It is possible to
220 * have a file opened more than once, in which case only the last
221 * release will mean, that no more reads/writes will happen on the
222 * file. The return value of release is ignored.
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000223 */
224 int (*release) (const char *, struct fuse_file_info *);
225
226 /** Synchronize file contents
227 *
228 * If the datasync parameter is non-zero, then only the user data
229 * should be flushed, not the meta data.
230 */
231 int (*fsync) (const char *, int, struct fuse_file_info *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000232
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000233 /** Set extended attributes */
234 int (*setxattr) (const char *, const char *, const char *, size_t, int);
Miklos Szeredie5183742005-02-02 11:14:04 +0000235
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000236 /** Get extended attributes */
237 int (*getxattr) (const char *, const char *, char *, size_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000238
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000239 /** List extended attributes */
240 int (*listxattr) (const char *, char *, size_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000241
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000242 /** Remove extended attributes */
Miklos Szeredi3ed84232004-03-30 15:17:26 +0000243 int (*removexattr) (const char *, const char *);
Miklos Szeredif43f0632005-02-28 11:46:56 +0000244
245 /** Open direcory
246 *
247 * This method should check if the open operation is permitted for
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000248 * this directory. The fuse_file_info parameter is currently
249 * unused.
Miklos Szeredif43f0632005-02-28 11:46:56 +0000250 */
251 int (*opendir) (const char *, struct fuse_file_info *);
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000252
Miklos Szeredi4283ee72005-03-21 12:09:04 +0000253 /** Synchronize directory contents
254 *
255 * If the datasync parameter is non-zero, then only the user data
256 * should be flushed, not the meta data. The fuse_file_info
257 * parameter is currently unused
258 */
259 int (*fsyncdir) (const char *, int, struct fuse_file_info *);
260
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000261 /**
262 * Initialize filesystem
263 *
264 * The return value will passed in the private_data field of
265 * fuse_context to all file operations and as a parameter to the
266 * destroy() method.
267 */
268 void *(*init) (void);
269
270 /**
271 * Clean up filesystem
272 *
273 * Called on filesystem exit.
274 */
275 void (*destroy) (void *);
Miklos Szeredia181e612001-11-06 12:03:23 +0000276};
277
Miklos Szeredie5183742005-02-02 11:14:04 +0000278/** Extra context that may be needed by some filesystems
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000279 *
280 * The uid, gid and pid fields are not filled in case of a writepage
281 * operation.
282 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000283struct fuse_context {
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000284 /** Pointer to the fuse object */
Miklos Szeredid169f312004-09-22 08:48:26 +0000285 struct fuse *fuse;
Miklos Szeredie5183742005-02-02 11:14:04 +0000286
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000287 /** User ID of the calling process */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000288 uid_t uid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000289
290 /** Group ID of the calling process */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000291 gid_t gid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000292
293 /** Thread ID of the calling process */
Miklos Szeredi1f18db52004-09-27 06:54:49 +0000294 pid_t pid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000295
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000296 /** Private filesystem data */
Miklos Szeredi8fb48fe2004-11-08 14:48:52 +0000297 void *private_data;
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000298};
299
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000300/*
Miklos Szeredi0e535082003-10-13 10:08:06 +0000301 * Main function of FUSE.
302 *
303 * This is for the lazy. This is all that has to be called from the
304 * main() function.
Miklos Szeredie5183742005-02-02 11:14:04 +0000305 *
Miklos Szeredi0e535082003-10-13 10:08:06 +0000306 * This function does the following:
Miklos Szeredi307242f2004-01-26 11:28:44 +0000307 * - parses command line options (-d -s and -h)
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000308 * - passes relevant mount options to the fuse_mount()
Miklos Szeredi0e535082003-10-13 10:08:06 +0000309 * - installs signal handlers for INT, HUP, TERM and PIPE
310 * - registers an exit handler to unmount the filesystem on program exit
Miklos Szeredi0e535082003-10-13 10:08:06 +0000311 * - creates a fuse handle
312 * - registers the operations
313 * - calls either the single-threaded or the multi-threaded event loop
314 *
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000315 * Note: this is currently implemented as a macro.
316 *
Miklos Szeredi0e535082003-10-13 10:08:06 +0000317 * @param argc the argument counter passed to the main() function
318 * @param argv the argument vector passed to the main() function
Miklos Szeredie5183742005-02-02 11:14:04 +0000319 * @param op the file system operation
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000320 * @return 0 on success, nonzero on failure
Miklos Szeredi0e535082003-10-13 10:08:06 +0000321 */
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000322/*
323int fuse_main(int argc, char *argv[], const struct fuse_operations *op);
324*/
325#define fuse_main(argc, argv, op) \
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000326 fuse_main_real(argc, argv, op, sizeof(*(op)))
Miklos Szeredi891b8742004-07-29 09:27:49 +0000327
Miklos Szeredi0e535082003-10-13 10:08:06 +0000328/* ----------------------------------------------------------- *
329 * More detailed API *
330 * ----------------------------------------------------------- */
331
332/*
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000333 * Create a FUSE mountpoint
334 *
335 * Returns a control file descriptor suitable for passing to
336 * fuse_new()
337 *
338 * @param mountpoint the mount point path
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000339 * @param opts a comma separated list of mount options. Can be NULL.
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000340 * @return the control file descriptor on success, -1 on failure
341 */
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000342int fuse_mount(const char *mountpoint, const char *opts);
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000343
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000344/*
345 * Umount a FUSE mountpoint
346 *
347 * @param mountpoint the mount point path
348 */
349void fuse_unmount(const char *mountpoint);
350
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000351/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000352 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000353 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000354 * @param fd the control file descriptor
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000355 * @param opts mount options to be used by the library
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000356 * @param op the operations
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000357 * @param op_size the size of the fuse_operations structure
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000358 * @return the created FUSE handle
359 */
Miklos Szeredie5183742005-02-02 11:14:04 +0000360struct fuse *fuse_new(int fd, const char *opts,
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000361 const struct fuse_operations *op, size_t op_size);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000362
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000363/**
Miklos Szeredie5183742005-02-02 11:14:04 +0000364 * Destroy the FUSE handle.
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000365 *
366 * The filesystem is not unmounted.
367 *
368 * @param f the FUSE handle
369 */
370void fuse_destroy(struct fuse *f);
371
372/**
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000373 * FUSE event loop.
374 *
375 * Requests from the kernel are processed, and the apropriate
Miklos Szeredie5183742005-02-02 11:14:04 +0000376 * operations are called.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000377 *
378 * @param f the FUSE handle
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000379 * @return 0 if no error occured, -1 otherwise
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000380 */
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000381int fuse_loop(struct fuse *f);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000382
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000383/**
384 * Exit from event loop
385 *
386 * @param f the FUSE handle
387 */
388void fuse_exit(struct fuse *f);
389
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000390/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000391 * FUSE event loop with multiple threads
392 *
393 * Requests from the kernel are processed, and the apropriate
394 * operations are called. Request are processed in parallel by
395 * distributing them between multiple threads.
396 *
397 * Calling this function requires the pthreads library to be linked to
398 * the application.
399 *
400 * @param f the FUSE handle
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000401 * @return 0 if no error occured, -1 otherwise
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000402 */
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000403int fuse_loop_mt(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000404
405/**
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000406 * Get the current context
Miklos Szeredie5183742005-02-02 11:14:04 +0000407 *
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000408 * The context is only valid for the duration of a filesystem
409 * operation, and thus must not be stored and used later.
410 *
411 * @param f the FUSE handle
Miklos Szeredie5183742005-02-02 11:14:04 +0000412 * @return the context
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000413 */
Miklos Szeredid169f312004-09-22 08:48:26 +0000414struct fuse_context *fuse_get_context(void);
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000415
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000416/**
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000417 * Invalidate cached data of a file.
418 *
419 * Useful if the 'kernel_cache' mount option is given, since in that
420 * case the cache is not invalidated on file open.
421 *
422 * @return 0 on success or -errno on failure
423 */
424int fuse_invalidate(struct fuse *f, const char *path);
425
426/**
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000427 * Check whether a mount option should be passed to the kernel or the
428 * library
429 *
430 * @param opt the option to check
431 * @return 1 if it is a library option, 0 otherwise
432 */
433int fuse_is_lib_option(const char *opt);
434
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000435/**
436 * The real main function
Miklos Szeredie5183742005-02-02 11:14:04 +0000437 *
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000438 * Do not call this directly, use fuse_main()
439 */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000440int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
441 size_t op_size);
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000442
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000443/* ----------------------------------------------------------- *
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000444 * Advanced API for event handling, don't worry about this... *
445 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000446
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000447/** Structure containing a raw command */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000448struct fuse_cmd;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000449
450/** Function type used to process commands */
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000451typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000452
453/** This is the part of fuse_main() before the event loop */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000454struct fuse *fuse_setup(int argc, char *argv[],
455 const struct fuse_operations *op, size_t op_size,
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000456 char **mountpoint, int *multithreaded, int *fd);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000457
458/** This is the part of fuse_main() after the event loop */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000459void fuse_teardown(struct fuse *fuse, int fd, char *mountpoint);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000460
461/** Read a single command. If none are read, return NULL */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000462struct fuse_cmd *fuse_read_cmd(struct fuse *f);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000463
464/** Process a single command */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000465void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000466
467/** Multi threaded event loop, which calls the custom command
468 processor function */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000469int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000470
471/** Return the exited flag, which indicates if fuse_exit() has been
472 called */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000473int fuse_exited(struct fuse* f);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000474
475/** Set function which can be used to get the current context */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000476void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000477
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000478/* ----------------------------------------------------------- *
479 * Compatibility stuff *
480 * ----------------------------------------------------------- */
481
482#if FUSE_USE_VERSION == 21 || FUSE_USE_VERSION == 11
Miklos Szeredie56818b2004-12-12 11:45:24 +0000483# include "fuse_compat.h"
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000484# define fuse_dirfil_t fuse_dirfil_t_compat
485# define __fuse_read_cmd fuse_read_cmd
486# define __fuse_process_cmd fuse_process_cmd
487# define __fuse_loop_mt fuse_loop_mt_proc
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000488# undef fuse_main
489# undef FUSE_MINOR_VERSION
490# undef FUSE_MAJOR_VERSION
491# if FUSE_USE_VERSION == 21
492# define FUSE_MAJOR_VERSION 2
493# define FUSE_MINOR_VERSION 1
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000494# define fuse_operations fuse_operations_compat2
495# define fuse_main fuse_main_compat2
496# define fuse_new fuse_new_compat2
497# define __fuse_setup fuse_setup_compat2
498# define __fuse_teardown fuse_teardown
499# define __fuse_exited fuse_exited
500# define __fuse_set_getcontext_func fuse_set_getcontext_func
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000501# else
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000502# define FUSE_MAJOR_VERSION 1
503# define FUSE_MINOR_VERSION 1
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000504# define fuse_statfs fuse_statfs_compat1
505# define fuse_operations fuse_operations_compat1
506# define fuse_main fuse_main_compat1
507# define fuse_new fuse_new_compat1
508# define fuse_mount fuse_mount_compat1
509# define FUSE_DEBUG FUSE_DEBUG_COMPAT1
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000510# endif
Miklos Szeredi799993c2004-12-04 21:20:05 +0000511#elif FUSE_USE_VERSION < 22
512# error Compatibility with API version other than 21 and 11 not supported
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000513#endif
514
Miklos Szerediacd4e062001-12-08 20:29:20 +0000515#ifdef __cplusplus
516}
517#endif
518
519#endif /* _FUSE_H_ */