blob: e285c07191c63cd07752fa242b2a3b7ed2f7c53d [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 Szeredi76c17522005-07-13 14:08:19 +000034#include "fuse_common.h"
35
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000036#include <sys/types.h>
37#include <sys/stat.h>
Miklos Szeredi18e75e42004-02-19 14:23:27 +000038#include <sys/statfs.h>
Miklos Szeredi5e183482001-10-31 14:52:35 +000039#include <utime.h>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000040
Miklos Szeredi8fb48fe2004-11-08 14:48:52 +000041#ifdef __cplusplus
42extern "C" {
43#endif
44
Miklos Szeredicc8c9752001-11-21 10:03:39 +000045/* ----------------------------------------------------------- *
46 * Basic FUSE API *
47 * ----------------------------------------------------------- */
48
Miklos Szeredi2df1c042001-11-06 15:07:17 +000049/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000050struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000051
Miklos Szeredi18fce982005-04-01 21:07:35 +000052/** Function to add an entry in a readdir() operation
53 *
54 * @param buf the buffer passed to the readdir() operation
55 * @param name the file name of the directory entry
Miklos Szerediab974562005-04-07 15:40:21 +000056 * @param stat file attributes, can be NULL
57 * @param off offset of the next entry or zero
58 * @return 1 if buffer is full, zero otherwise
Miklos Szeredi18fce982005-04-01 21:07:35 +000059 */
Miklos Szerediab974562005-04-07 15:40:21 +000060typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
61 const struct stat *stat, off_t off);
62
63/* Used by deprecated getdir() method */
64typedef struct fuse_dirhandle *fuse_dirh_t;
65typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type,
66 ino_t ino);
Miklos Szeredi18fce982005-04-01 21:07:35 +000067
Miklos Szeredi2df1c042001-11-06 15:07:17 +000068/**
69 * The file system operations:
70 *
71 * Most of these should work very similarly to the well known UNIX
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000072 * file system operations. A major exception is that instead of
73 * returning an error in 'errno', the operation should return the
Miklos Szeredie5183742005-02-02 11:14:04 +000074 * negated error value (-errno) directly.
Miklos Szeredie56818b2004-12-12 11:45:24 +000075 *
76 * All methods are optional, but some are essential for a useful
Miklos Szeredi18fce982005-04-01 21:07:35 +000077 * filesystem (e.g. getattr). Flush, release, fsync, opendir,
Miklos Szerediab974562005-04-07 15:40:21 +000078 * releasedir, fsyncdir, init and destroy are special purpose
Miklos Szeredi18fce982005-04-01 21:07:35 +000079 * methods, without which a full featured filesystem can still be
80 * implemented.
Miklos Szeredie2e4ac22004-05-18 08:45:28 +000081 */
Miklos Szeredia181e612001-11-06 12:03:23 +000082struct fuse_operations {
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000083 /** Get file attributes.
84 *
85 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are
86 * ignored. The 'st_ino' field is ignored except if the 'use_ino'
87 * mount option is given.
88 */
89 int (*getattr) (const char *, struct stat *);
90
91 /** Read the target of a symbolic link
Miklos Szeredie5183742005-02-02 11:14:04 +000092 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000093 * The buffer should be filled with a null terminated string. The
94 * buffer size argument includes the space for the terminating
95 * null character. If the linkname is too long to fit in the
96 * buffer, it should be truncated. The return value should be 0
97 * for success.
98 */
99 int (*readlink) (const char *, char *, size_t);
100
Miklos Szerediab974562005-04-07 15:40:21 +0000101 /* Deprecated, use readdir() instead */
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000102 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
103
104 /** Create a file node
105 *
106 * There is no create() operation, mknod() will be called for
107 * creation of all non-directory, non-symlink nodes.
108 */
109 int (*mknod) (const char *, mode_t, dev_t);
110
111 /** Create a directory */
112 int (*mkdir) (const char *, mode_t);
113
114 /** Remove a file */
115 int (*unlink) (const char *);
116
117 /** Remove a directory */
118 int (*rmdir) (const char *);
119
120 /** Create a symbolic link */
121 int (*symlink) (const char *, const char *);
122
123 /** Rename a file */
124 int (*rename) (const char *, const char *);
125
126 /** Create a hard link to a file */
127 int (*link) (const char *, const char *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000128
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000129 /** Change the permission bits of a file */
130 int (*chmod) (const char *, mode_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000131
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000132 /** Change the owner and group of a file */
133 int (*chown) (const char *, uid_t, gid_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000134
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000135 /** Change the size of a file */
136 int (*truncate) (const char *, off_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000137
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000138 /** Change the access and/or modification times of a file */
139 int (*utime) (const char *, struct utimbuf *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000140
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000141 /** File open operation
142 *
143 * No creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC)
144 * will be passed to open(). Open should check if the operation
145 * is permitted for the given flags. Optionally open may also
146 * return an arbitary filehandle in the fuse_file_info structure,
147 * which will be passed to all file operations.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000148 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000149 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000150 */
151 int (*open) (const char *, struct fuse_file_info *);
152
153 /** Read data from an open file
154 *
155 * Read should return exactly the number of bytes requested except
156 * on EOF or error, otherwise the rest of the data will be
157 * substituted with zeroes. An exception to this is when the
158 * 'direct_io' mount option is specified, in which case the return
159 * value of the read system call will reflect the return value of
160 * this operation.
Miklos Szeredi437d8112005-07-06 09:14:20 +0000161 *
162 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000163 */
164 int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *);
165
Miklos Szeredie5183742005-02-02 11:14:04 +0000166 /** Write data to an open file
167 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000168 * Write should return exactly the number of bytes requested
169 * except on error. An exception to this is when the 'direct_io'
170 * mount option is specified (see read operation).
Miklos Szeredi437d8112005-07-06 09:14:20 +0000171 *
172 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000173 */
174 int (*write) (const char *, const char *, size_t, off_t,
175 struct fuse_file_info *);
176
177 /** Get file system statistics
Miklos Szeredie5183742005-02-02 11:14:04 +0000178 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000179 * The 'f_type' and 'f_fsid' fields are ignored
180 */
181 int (*statfs) (const char *, struct statfs *);
182
Miklos Szeredie5183742005-02-02 11:14:04 +0000183 /** Possibly flush cached data
184 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000185 * BIG NOTE: This is not equivalent to fsync(). It's not a
Miklos Szeredie56818b2004-12-12 11:45:24 +0000186 * request to sync dirty data.
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000187 *
188 * Flush is called on each close() of a file descriptor. So if a
189 * filesystem wants to return write errors in close() and the file
190 * has cached dirty data, this is a good place to write back data
Miklos Szeredie56818b2004-12-12 11:45:24 +0000191 * and return any errors. Since many applications ignore close()
192 * errors this is not always useful.
Miklos Szeredie5183742005-02-02 11:14:04 +0000193 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000194 * NOTE: The flush() method may be called more than once for each
195 * open(). This happens if more than one file descriptor refers
196 * to an opened file due to dup(), dup2() or fork() calls. It is
197 * not possible to determine if a flush is final, so each flush
198 * should be treated equally. Multiple write-flush sequences are
199 * relatively rare, so this shouldn't be a problem.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000200 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000201 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000202 */
203 int (*flush) (const char *, struct fuse_file_info *);
204
205 /** Release an open file
Miklos Szeredie5183742005-02-02 11:14:04 +0000206 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000207 * Release is called when there are no more references to an open
208 * file: all file descriptors are closed and all memory mappings
209 * are unmapped.
210 *
211 * For every open() call there will be exactly one release() call
Miklos Szeredie56818b2004-12-12 11:45:24 +0000212 * with the same flags and file descriptor. It is possible to
213 * have a file opened more than once, in which case only the last
214 * release will mean, that no more reads/writes will happen on the
215 * file. The return value of release is ignored.
Miklos Szeredi437d8112005-07-06 09:14:20 +0000216 *
217 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000218 */
219 int (*release) (const char *, struct fuse_file_info *);
220
221 /** Synchronize file contents
222 *
223 * If the datasync parameter is non-zero, then only the user data
224 * should be flushed, not the meta data.
Miklos Szeredi437d8112005-07-06 09:14:20 +0000225 *
226 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000227 */
228 int (*fsync) (const char *, int, struct fuse_file_info *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000229
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000230 /** Set extended attributes */
231 int (*setxattr) (const char *, const char *, const char *, size_t, int);
Miklos Szeredie5183742005-02-02 11:14:04 +0000232
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000233 /** Get extended attributes */
234 int (*getxattr) (const char *, const char *, char *, size_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000235
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000236 /** List extended attributes */
237 int (*listxattr) (const char *, char *, size_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000238
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000239 /** Remove extended attributes */
Miklos Szeredi3ed84232004-03-30 15:17:26 +0000240 int (*removexattr) (const char *, const char *);
Miklos Szeredif43f0632005-02-28 11:46:56 +0000241
242 /** Open direcory
Miklos Szeredi18fce982005-04-01 21:07:35 +0000243 *
Miklos Szeredif43f0632005-02-28 11:46:56 +0000244 * This method should check if the open operation is permitted for
Miklos Szeredi18fce982005-04-01 21:07:35 +0000245 * this directory
Miklos Szeredi437d8112005-07-06 09:14:20 +0000246 *
247 * Introduced in version 2.3
Miklos Szeredif43f0632005-02-28 11:46:56 +0000248 */
249 int (*opendir) (const char *, struct fuse_file_info *);
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000250
Miklos Szeredi18fce982005-04-01 21:07:35 +0000251 /** Read directory
252 *
Miklos Szerediab974562005-04-07 15:40:21 +0000253 * This supersedes the old getdir() interface. New applications
254 * should use this.
255 *
256 * The filesystem may choose between two modes of operation:
Miklos Szeredi21019c92005-05-09 11:22:41 +0000257 *
Miklos Szerediab974562005-04-07 15:40:21 +0000258 * 1) The readdir implementation ignores the offset parameter, and
259 * passes zero to the filler function's offset. The filler
260 * function will not return '1' (unless an error happens), so the
261 * whole directory is read in a single readdir operation. This
262 * works just like the old getdir() method.
263 *
264 * 2) The readdir implementation keeps track of the offsets of the
265 * directory entries. It uses the offset parameter and always
266 * passes non-zero offset to the filler function. When the buffer
267 * is full (or an error happens) the filler function will return
268 * '1'.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000269 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000270 * Introduced in version 2.3
Miklos Szeredi18fce982005-04-01 21:07:35 +0000271 */
Miklos Szerediab974562005-04-07 15:40:21 +0000272 int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
Miklos Szeredi18fce982005-04-01 21:07:35 +0000273 struct fuse_file_info *);
274
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000275 /** Release directory
Miklos Szeredi437d8112005-07-06 09:14:20 +0000276 *
277 * Introduced in version 2.3
278 */
Miklos Szeredi18fce982005-04-01 21:07:35 +0000279 int (*releasedir) (const char *, struct fuse_file_info *);
280
Miklos Szeredi4283ee72005-03-21 12:09:04 +0000281 /** Synchronize directory contents
282 *
283 * If the datasync parameter is non-zero, then only the user data
Miklos Szeredi18fce982005-04-01 21:07:35 +0000284 * should be flushed, not the meta data
Miklos Szeredi437d8112005-07-06 09:14:20 +0000285 *
286 * Introduced in version 2.3
Miklos Szeredi4283ee72005-03-21 12:09:04 +0000287 */
288 int (*fsyncdir) (const char *, int, struct fuse_file_info *);
289
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000290 /**
291 * Initialize filesystem
292 *
293 * The return value will passed in the private_data field of
294 * fuse_context to all file operations and as a parameter to the
295 * destroy() method.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000296 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000297 * Introduced in version 2.3
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000298 */
299 void *(*init) (void);
300
301 /**
302 * Clean up filesystem
Miklos Szeredi18fce982005-04-01 21:07:35 +0000303 *
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000304 * Called on filesystem exit.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000305 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000306 * Introduced in version 2.3
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000307 */
308 void (*destroy) (void *);
Miklos Szeredia181e612001-11-06 12:03:23 +0000309};
310
Miklos Szeredie5183742005-02-02 11:14:04 +0000311/** Extra context that may be needed by some filesystems
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000312 *
313 * The uid, gid and pid fields are not filled in case of a writepage
314 * operation.
315 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000316struct fuse_context {
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000317 /** Pointer to the fuse object */
Miklos Szeredid169f312004-09-22 08:48:26 +0000318 struct fuse *fuse;
Miklos Szeredie5183742005-02-02 11:14:04 +0000319
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000320 /** User ID of the calling process */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000321 uid_t uid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000322
323 /** Group ID of the calling process */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000324 gid_t gid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000325
326 /** Thread ID of the calling process */
Miklos Szeredi1f18db52004-09-27 06:54:49 +0000327 pid_t pid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000328
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000329 /** Private filesystem data */
Miklos Szeredi8fb48fe2004-11-08 14:48:52 +0000330 void *private_data;
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000331};
332
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000333/*
Miklos Szeredi0e535082003-10-13 10:08:06 +0000334 * Main function of FUSE.
335 *
336 * This is for the lazy. This is all that has to be called from the
337 * main() function.
Miklos Szeredie5183742005-02-02 11:14:04 +0000338 *
Miklos Szeredi0e535082003-10-13 10:08:06 +0000339 * This function does the following:
Miklos Szeredi307242f2004-01-26 11:28:44 +0000340 * - parses command line options (-d -s and -h)
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000341 * - passes relevant mount options to the fuse_mount()
Miklos Szeredi0e535082003-10-13 10:08:06 +0000342 * - installs signal handlers for INT, HUP, TERM and PIPE
343 * - registers an exit handler to unmount the filesystem on program exit
Miklos Szeredi0e535082003-10-13 10:08:06 +0000344 * - creates a fuse handle
345 * - registers the operations
346 * - calls either the single-threaded or the multi-threaded event loop
347 *
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000348 * Note: this is currently implemented as a macro.
349 *
Miklos Szeredi0e535082003-10-13 10:08:06 +0000350 * @param argc the argument counter passed to the main() function
351 * @param argv the argument vector passed to the main() function
Miklos Szeredie5183742005-02-02 11:14:04 +0000352 * @param op the file system operation
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000353 * @return 0 on success, nonzero on failure
Miklos Szeredi0e535082003-10-13 10:08:06 +0000354 */
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000355/*
356int fuse_main(int argc, char *argv[], const struct fuse_operations *op);
357*/
358#define fuse_main(argc, argv, op) \
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000359 fuse_main_real(argc, argv, op, sizeof(*(op)))
Miklos Szeredi891b8742004-07-29 09:27:49 +0000360
Miklos Szeredi0e535082003-10-13 10:08:06 +0000361/* ----------------------------------------------------------- *
362 * More detailed API *
363 * ----------------------------------------------------------- */
364
365/*
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000366 * Create a FUSE mountpoint
367 *
368 * Returns a control file descriptor suitable for passing to
369 * fuse_new()
370 *
371 * @param mountpoint the mount point path
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000372 * @param opts a comma separated list of mount options. Can be NULL.
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000373 * @return the control file descriptor on success, -1 on failure
374 */
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000375int fuse_mount(const char *mountpoint, const char *opts);
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000376
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000377/*
378 * Umount a FUSE mountpoint
379 *
380 * @param mountpoint the mount point path
381 */
382void fuse_unmount(const char *mountpoint);
383
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000384/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000385 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000386 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000387 * @param fd the control file descriptor
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000388 * @param opts mount options to be used by the library
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000389 * @param op the operations
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000390 * @param op_size the size of the fuse_operations structure
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000391 * @return the created FUSE handle
392 */
Miklos Szeredie5183742005-02-02 11:14:04 +0000393struct fuse *fuse_new(int fd, const char *opts,
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000394 const struct fuse_operations *op, size_t op_size);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000395
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000396/**
Miklos Szeredie5183742005-02-02 11:14:04 +0000397 * Destroy the FUSE handle.
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000398 *
399 * The filesystem is not unmounted.
400 *
401 * @param f the FUSE handle
402 */
403void fuse_destroy(struct fuse *f);
404
405/**
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000406 * FUSE event loop.
407 *
408 * Requests from the kernel are processed, and the apropriate
Miklos Szeredie5183742005-02-02 11:14:04 +0000409 * operations are called.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000410 *
411 * @param f the FUSE handle
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000412 * @return 0 if no error occured, -1 otherwise
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000413 */
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000414int fuse_loop(struct fuse *f);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000415
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000416/**
417 * Exit from event loop
418 *
419 * @param f the FUSE handle
420 */
421void fuse_exit(struct fuse *f);
422
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000423/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000424 * FUSE event loop with multiple threads
425 *
426 * Requests from the kernel are processed, and the apropriate
427 * operations are called. Request are processed in parallel by
428 * distributing them between multiple threads.
429 *
430 * Calling this function requires the pthreads library to be linked to
431 * the application.
432 *
433 * @param f the FUSE handle
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000434 * @return 0 if no error occured, -1 otherwise
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000435 */
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000436int fuse_loop_mt(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000437
438/**
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000439 * Get the current context
Miklos Szeredie5183742005-02-02 11:14:04 +0000440 *
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000441 * The context is only valid for the duration of a filesystem
442 * operation, and thus must not be stored and used later.
443 *
444 * @param f the FUSE handle
Miklos Szeredie5183742005-02-02 11:14:04 +0000445 * @return the context
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000446 */
Miklos Szeredid169f312004-09-22 08:48:26 +0000447struct fuse_context *fuse_get_context(void);
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000448
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000449/**
Miklos Szeredi76c17522005-07-13 14:08:19 +0000450 * Obsolete, doesn't do anything
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000451 *
Miklos Szeredibd10a7b2005-07-15 09:59:59 +0000452 * @return -EINVAL
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000453 */
454int fuse_invalidate(struct fuse *f, const char *path);
455
456/**
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000457 * Check whether a mount option should be passed to the kernel or the
458 * library
459 *
460 * @param opt the option to check
461 * @return 1 if it is a library option, 0 otherwise
462 */
463int fuse_is_lib_option(const char *opt);
464
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000465/**
466 * The real main function
Miklos Szeredie5183742005-02-02 11:14:04 +0000467 *
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000468 * Do not call this directly, use fuse_main()
469 */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000470int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
471 size_t op_size);
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000472
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000473/* ----------------------------------------------------------- *
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000474 * Advanced API for event handling, don't worry about this... *
475 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000476
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000477/** Function type used to process commands */
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000478typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000479
480/** This is the part of fuse_main() before the event loop */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000481struct fuse *fuse_setup(int argc, char *argv[],
482 const struct fuse_operations *op, size_t op_size,
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000483 char **mountpoint, int *multithreaded, int *fd);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000484
485/** This is the part of fuse_main() after the event loop */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000486void fuse_teardown(struct fuse *fuse, int fd, char *mountpoint);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000487
488/** Read a single command. If none are read, return NULL */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000489struct fuse_cmd *fuse_read_cmd(struct fuse *f);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000490
491/** Process a single command */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000492void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000493
494/** Multi threaded event loop, which calls the custom command
495 processor function */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000496int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000497
498/** Return the exited flag, which indicates if fuse_exit() has been
499 called */
Miklos Szeredie2aa2e22005-07-15 13:31:36 +0000500int fuse_exited(struct fuse *f);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000501
502/** Set function which can be used to get the current context */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000503void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000504
Miklos Szeredie2aa2e22005-07-15 13:31:36 +0000505/** Returns the lowlevel FUSE object */
506struct fuse_ll *fuse_get_lowlevel(struct fuse *f);
507
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000508/* ----------------------------------------------------------- *
509 * Compatibility stuff *
510 * ----------------------------------------------------------- */
511
512#if FUSE_USE_VERSION == 21 || FUSE_USE_VERSION == 11
Miklos Szeredie56818b2004-12-12 11:45:24 +0000513# include "fuse_compat.h"
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000514# define fuse_dirfil_t fuse_dirfil_t_compat
515# define __fuse_read_cmd fuse_read_cmd
516# define __fuse_process_cmd fuse_process_cmd
517# define __fuse_loop_mt fuse_loop_mt_proc
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000518# undef fuse_main
519# undef FUSE_MINOR_VERSION
520# undef FUSE_MAJOR_VERSION
521# if FUSE_USE_VERSION == 21
522# define FUSE_MAJOR_VERSION 2
523# define FUSE_MINOR_VERSION 1
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000524# define fuse_operations fuse_operations_compat2
525# define fuse_main fuse_main_compat2
526# define fuse_new fuse_new_compat2
527# define __fuse_setup fuse_setup_compat2
528# define __fuse_teardown fuse_teardown
529# define __fuse_exited fuse_exited
530# define __fuse_set_getcontext_func fuse_set_getcontext_func
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000531# else
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000532# define FUSE_MAJOR_VERSION 1
533# define FUSE_MINOR_VERSION 1
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000534# define fuse_statfs fuse_statfs_compat1
535# define fuse_operations fuse_operations_compat1
536# define fuse_main fuse_main_compat1
537# define fuse_new fuse_new_compat1
538# define fuse_mount fuse_mount_compat1
539# define FUSE_DEBUG FUSE_DEBUG_COMPAT1
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000540# endif
Miklos Szeredi799993c2004-12-04 21:20:05 +0000541#elif FUSE_USE_VERSION < 22
542# error Compatibility with API version other than 21 and 11 not supported
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000543#endif
544
Miklos Szerediacd4e062001-12-08 20:29:20 +0000545#ifdef __cplusplus
546}
547#endif
548
549#endif /* _FUSE_H_ */