blob: ade49f57c2579b72c83084e08bdfd1cb100a96e8 [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 Szeredi31066bb2005-08-01 14:49:31 +000027#define FUSE_MINOR_VERSION 4
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,
Miklos Szeredif6e0ec62005-08-03 09:11:06 +000061 const struct stat *stbuf, off_t off);
Miklos Szerediab974562005-04-07 15:40:21 +000062
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 Szeredi31066bb2005-08-01 14:49:31 +000077 * filesystem (e.g. getattr). Open, flush, release, fsync, opendir,
78 * releasedir, fsyncdir, init and destroy are special purpose methods,
79 * without which a full featured filesystem can still be implemented.
Miklos Szeredie2e4ac22004-05-18 08:45:28 +000080 */
Miklos Szeredia181e612001-11-06 12:03:23 +000081struct fuse_operations {
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000082 /** Get file attributes.
83 *
84 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are
85 * ignored. The 'st_ino' field is ignored except if the 'use_ino'
86 * mount option is given.
87 */
88 int (*getattr) (const char *, struct stat *);
89
90 /** Read the target of a symbolic link
Miklos Szeredie5183742005-02-02 11:14:04 +000091 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000092 * The buffer should be filled with a null terminated string. The
93 * buffer size argument includes the space for the terminating
94 * null character. If the linkname is too long to fit in the
95 * buffer, it should be truncated. The return value should be 0
96 * for success.
97 */
98 int (*readlink) (const char *, char *, size_t);
99
Miklos Szerediab974562005-04-07 15:40:21 +0000100 /* Deprecated, use readdir() instead */
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000101 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
102
103 /** Create a file node
104 *
105 * There is no create() operation, mknod() will be called for
106 * creation of all non-directory, non-symlink nodes.
107 */
108 int (*mknod) (const char *, mode_t, dev_t);
109
110 /** Create a directory */
111 int (*mkdir) (const char *, mode_t);
112
113 /** Remove a file */
114 int (*unlink) (const char *);
115
116 /** Remove a directory */
117 int (*rmdir) (const char *);
118
119 /** Create a symbolic link */
120 int (*symlink) (const char *, const char *);
121
122 /** Rename a file */
123 int (*rename) (const char *, const char *);
124
125 /** Create a hard link to a file */
126 int (*link) (const char *, const char *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000127
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000128 /** Change the permission bits of a file */
129 int (*chmod) (const char *, mode_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000130
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000131 /** Change the owner and group of a file */
132 int (*chown) (const char *, uid_t, gid_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000133
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000134 /** Change the size of a file */
135 int (*truncate) (const char *, off_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000136
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000137 /** Change the access and/or modification times of a file */
138 int (*utime) (const char *, struct utimbuf *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000139
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000140 /** File open operation
141 *
142 * No creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC)
Miklos Szeredi009b8782005-08-01 13:36:53 +0000143 * will be passed to open(). Optionally open may return an
144 * arbitary filehandle in the fuse_file_info structure, which will
145 * be passed to all file operations.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000146 *
Miklos Szeredi31066bb2005-08-01 14:49:31 +0000147 * Open does not need to check the permission to open the file
148 * with the given flags. In fact it cannot correctly do that
149 * since it doesn't have a way to determine if the file was just
150 * created (and hence the permission need not be checked).
Miklos Szeredif6e0ec62005-08-03 09:11:06 +0000151 *
Miklos Szeredi31066bb2005-08-01 14:49:31 +0000152 * If permission needs to be checked, implement the access()
153 * method, and do the check there.
154 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000155 * Changed in version 2.2
Miklos Szeredi31066bb2005-08-01 14:49:31 +0000156 * Optional from version 2.4
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000157 */
158 int (*open) (const char *, struct fuse_file_info *);
159
160 /** Read data from an open file
161 *
162 * Read should return exactly the number of bytes requested except
163 * on EOF or error, otherwise the rest of the data will be
164 * substituted with zeroes. An exception to this is when the
165 * 'direct_io' mount option is specified, in which case the return
166 * value of the read system call will reflect the return value of
167 * this operation.
Miklos Szeredi437d8112005-07-06 09:14:20 +0000168 *
169 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000170 */
171 int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *);
172
Miklos Szeredie5183742005-02-02 11:14:04 +0000173 /** Write data to an open file
174 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000175 * 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).
Miklos Szeredi437d8112005-07-06 09:14:20 +0000178 *
179 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000180 */
181 int (*write) (const char *, const char *, size_t, off_t,
182 struct fuse_file_info *);
183
184 /** Get file system statistics
Miklos Szeredie5183742005-02-02 11:14:04 +0000185 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000186 * The 'f_type' and 'f_fsid' fields are ignored
187 */
188 int (*statfs) (const char *, struct statfs *);
189
Miklos Szeredie5183742005-02-02 11:14:04 +0000190 /** Possibly flush cached data
191 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000192 * BIG NOTE: This is not equivalent to fsync(). It's not a
Miklos Szeredie56818b2004-12-12 11:45:24 +0000193 * request to sync dirty data.
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000194 *
195 * Flush is called on each close() of a file descriptor. So if a
196 * filesystem wants to return write errors in close() and the file
197 * has cached dirty data, this is a good place to write back data
Miklos Szeredie56818b2004-12-12 11:45:24 +0000198 * and return any errors. Since many applications ignore close()
199 * errors this is not always useful.
Miklos Szeredie5183742005-02-02 11:14:04 +0000200 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000201 * NOTE: The flush() method may be called more than once for each
202 * open(). This happens if more than one file descriptor refers
203 * to an opened file due to dup(), dup2() or fork() calls. It is
204 * not possible to determine if a flush is final, so each flush
205 * should be treated equally. Multiple write-flush sequences are
206 * relatively rare, so this shouldn't be a problem.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000207 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000208 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000209 */
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 Szeredi437d8112005-07-06 09:14:20 +0000223 *
224 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000225 */
226 int (*release) (const char *, struct fuse_file_info *);
227
228 /** Synchronize file contents
229 *
230 * If the datasync parameter is non-zero, then only the user data
231 * should be flushed, not the meta data.
Miklos Szeredi437d8112005-07-06 09:14:20 +0000232 *
233 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000234 */
235 int (*fsync) (const char *, int, struct fuse_file_info *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000236
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000237 /** Set extended attributes */
238 int (*setxattr) (const char *, const char *, const char *, size_t, int);
Miklos Szeredie5183742005-02-02 11:14:04 +0000239
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000240 /** Get extended attributes */
241 int (*getxattr) (const char *, const char *, char *, size_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000242
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000243 /** List extended attributes */
244 int (*listxattr) (const char *, char *, size_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000245
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000246 /** Remove extended attributes */
Miklos Szeredi3ed84232004-03-30 15:17:26 +0000247 int (*removexattr) (const char *, const char *);
Miklos Szeredif43f0632005-02-28 11:46:56 +0000248
Miklos Szeredi009b8782005-08-01 13:36:53 +0000249 /** Open directory
Miklos Szeredi437d8112005-07-06 09:14:20 +0000250 *
251 * Introduced in version 2.3
Miklos Szeredif43f0632005-02-28 11:46:56 +0000252 */
253 int (*opendir) (const char *, struct fuse_file_info *);
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000254
Miklos Szeredi18fce982005-04-01 21:07:35 +0000255 /** Read directory
256 *
Miklos Szerediab974562005-04-07 15:40:21 +0000257 * This supersedes the old getdir() interface. New applications
258 * should use this.
259 *
260 * The filesystem may choose between two modes of operation:
Miklos Szeredi21019c92005-05-09 11:22:41 +0000261 *
Miklos Szerediab974562005-04-07 15:40:21 +0000262 * 1) The readdir implementation ignores the offset parameter, and
263 * passes zero to the filler function's offset. The filler
264 * function will not return '1' (unless an error happens), so the
265 * whole directory is read in a single readdir operation. This
266 * works just like the old getdir() method.
267 *
268 * 2) The readdir implementation keeps track of the offsets of the
269 * directory entries. It uses the offset parameter and always
270 * passes non-zero offset to the filler function. When the buffer
271 * is full (or an error happens) the filler function will return
272 * '1'.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000273 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000274 * Introduced in version 2.3
Miklos Szeredi18fce982005-04-01 21:07:35 +0000275 */
Miklos Szerediab974562005-04-07 15:40:21 +0000276 int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t,
Miklos Szeredi18fce982005-04-01 21:07:35 +0000277 struct fuse_file_info *);
278
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000279 /** Release directory
Miklos Szeredi437d8112005-07-06 09:14:20 +0000280 *
281 * Introduced in version 2.3
282 */
Miklos Szeredi18fce982005-04-01 21:07:35 +0000283 int (*releasedir) (const char *, struct fuse_file_info *);
284
Miklos Szeredi4283ee72005-03-21 12:09:04 +0000285 /** Synchronize directory contents
286 *
287 * If the datasync parameter is non-zero, then only the user data
Miklos Szeredi18fce982005-04-01 21:07:35 +0000288 * should be flushed, not the meta data
Miklos Szeredi437d8112005-07-06 09:14:20 +0000289 *
290 * Introduced in version 2.3
Miklos Szeredi4283ee72005-03-21 12:09:04 +0000291 */
292 int (*fsyncdir) (const char *, int, struct fuse_file_info *);
293
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000294 /**
295 * Initialize filesystem
296 *
297 * The return value will passed in the private_data field of
298 * fuse_context to all file operations and as a parameter to the
299 * destroy() method.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000300 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000301 * Introduced in version 2.3
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000302 */
303 void *(*init) (void);
304
305 /**
306 * Clean up filesystem
Miklos Szeredi18fce982005-04-01 21:07:35 +0000307 *
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000308 * Called on filesystem exit.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000309 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000310 * Introduced in version 2.3
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000311 */
312 void (*destroy) (void *);
Miklos Szeredi7b28eae2005-08-01 12:48:30 +0000313
314 /**
315 * Check file access permissions
Miklos Szeredif6e0ec62005-08-03 09:11:06 +0000316 *
Miklos Szeredi7b28eae2005-08-01 12:48:30 +0000317 * Need not be implemented. Will only be called for the access()
Miklos Szeredi009b8782005-08-01 13:36:53 +0000318 * system call, and for the open() system call, unless a new file
319 * is created (file didn't exist and O_CREAT was given). If the
320 * 'default_permissions' mount option is given, this method is
321 * never called.
Miklos Szeredi7b28eae2005-08-01 12:48:30 +0000322 *
323 * Introduced in version 2.4
324 */
325 int (*access) (const char *, int);
Miklos Szeredia181e612001-11-06 12:03:23 +0000326};
327
Miklos Szeredie5183742005-02-02 11:14:04 +0000328/** Extra context that may be needed by some filesystems
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000329 *
330 * The uid, gid and pid fields are not filled in case of a writepage
331 * operation.
332 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000333struct fuse_context {
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000334 /** Pointer to the fuse object */
Miklos Szeredid169f312004-09-22 08:48:26 +0000335 struct fuse *fuse;
Miklos Szeredie5183742005-02-02 11:14:04 +0000336
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000337 /** User ID of the calling process */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000338 uid_t uid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000339
340 /** Group ID of the calling process */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000341 gid_t gid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000342
343 /** Thread ID of the calling process */
Miklos Szeredi1f18db52004-09-27 06:54:49 +0000344 pid_t pid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000345
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000346 /** Private filesystem data */
Miklos Szeredi8fb48fe2004-11-08 14:48:52 +0000347 void *private_data;
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000348};
349
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000350/*
Miklos Szeredi0e535082003-10-13 10:08:06 +0000351 * Main function of FUSE.
352 *
353 * This is for the lazy. This is all that has to be called from the
354 * main() function.
Miklos Szeredie5183742005-02-02 11:14:04 +0000355 *
Miklos Szeredi0e535082003-10-13 10:08:06 +0000356 * This function does the following:
Miklos Szeredi307242f2004-01-26 11:28:44 +0000357 * - parses command line options (-d -s and -h)
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000358 * - passes relevant mount options to the fuse_mount()
Miklos Szeredi0e535082003-10-13 10:08:06 +0000359 * - installs signal handlers for INT, HUP, TERM and PIPE
360 * - registers an exit handler to unmount the filesystem on program exit
Miklos Szeredi0e535082003-10-13 10:08:06 +0000361 * - creates a fuse handle
362 * - registers the operations
363 * - calls either the single-threaded or the multi-threaded event loop
364 *
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000365 * Note: this is currently implemented as a macro.
366 *
Miklos Szeredi0e535082003-10-13 10:08:06 +0000367 * @param argc the argument counter passed to the main() function
368 * @param argv the argument vector passed to the main() function
Miklos Szeredie5183742005-02-02 11:14:04 +0000369 * @param op the file system operation
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000370 * @return 0 on success, nonzero on failure
Miklos Szeredi0e535082003-10-13 10:08:06 +0000371 */
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000372/*
373int fuse_main(int argc, char *argv[], const struct fuse_operations *op);
374*/
375#define fuse_main(argc, argv, op) \
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000376 fuse_main_real(argc, argv, op, sizeof(*(op)))
Miklos Szeredi891b8742004-07-29 09:27:49 +0000377
Miklos Szeredi0e535082003-10-13 10:08:06 +0000378/* ----------------------------------------------------------- *
379 * More detailed API *
380 * ----------------------------------------------------------- */
381
382/*
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000383 * Create a FUSE mountpoint
384 *
385 * Returns a control file descriptor suitable for passing to
386 * fuse_new()
387 *
388 * @param mountpoint the mount point path
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000389 * @param opts a comma separated list of mount options. Can be NULL.
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000390 * @return the control file descriptor on success, -1 on failure
391 */
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000392int fuse_mount(const char *mountpoint, const char *opts);
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000393
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000394/*
395 * Umount a FUSE mountpoint
396 *
397 * @param mountpoint the mount point path
398 */
399void fuse_unmount(const char *mountpoint);
400
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000401/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000402 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000403 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000404 * @param fd the control file descriptor
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000405 * @param opts mount options to be used by the library
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000406 * @param op the operations
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000407 * @param op_size the size of the fuse_operations structure
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000408 * @return the created FUSE handle
409 */
Miklos Szeredie5183742005-02-02 11:14:04 +0000410struct fuse *fuse_new(int fd, const char *opts,
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000411 const struct fuse_operations *op, size_t op_size);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000412
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000413/**
Miklos Szeredie5183742005-02-02 11:14:04 +0000414 * Destroy the FUSE handle.
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000415 *
416 * The filesystem is not unmounted.
417 *
418 * @param f the FUSE handle
419 */
420void fuse_destroy(struct fuse *f);
421
422/**
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000423 * FUSE event loop.
424 *
425 * Requests from the kernel are processed, and the apropriate
Miklos Szeredie5183742005-02-02 11:14:04 +0000426 * operations are called.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000427 *
428 * @param f the FUSE handle
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000429 * @return 0 if no error occured, -1 otherwise
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000430 */
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000431int fuse_loop(struct fuse *f);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000432
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000433/**
434 * Exit from event loop
435 *
436 * @param f the FUSE handle
437 */
438void fuse_exit(struct fuse *f);
439
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000440/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000441 * FUSE event loop with multiple threads
442 *
443 * Requests from the kernel are processed, and the apropriate
444 * operations are called. Request are processed in parallel by
445 * distributing them between multiple threads.
446 *
447 * Calling this function requires the pthreads library to be linked to
448 * the application.
449 *
450 * @param f the FUSE handle
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000451 * @return 0 if no error occured, -1 otherwise
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000452 */
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000453int fuse_loop_mt(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000454
455/**
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000456 * Get the current context
Miklos Szeredie5183742005-02-02 11:14:04 +0000457 *
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000458 * The context is only valid for the duration of a filesystem
459 * operation, and thus must not be stored and used later.
460 *
461 * @param f the FUSE handle
Miklos Szeredie5183742005-02-02 11:14:04 +0000462 * @return the context
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000463 */
Miklos Szeredid169f312004-09-22 08:48:26 +0000464struct fuse_context *fuse_get_context(void);
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000465
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000466/**
Miklos Szeredi76c17522005-07-13 14:08:19 +0000467 * Obsolete, doesn't do anything
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000468 *
Miklos Szeredibd10a7b2005-07-15 09:59:59 +0000469 * @return -EINVAL
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000470 */
471int fuse_invalidate(struct fuse *f, const char *path);
472
473/**
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000474 * Check whether a mount option should be passed to the kernel or the
475 * library
476 *
477 * @param opt the option to check
478 * @return 1 if it is a library option, 0 otherwise
479 */
480int fuse_is_lib_option(const char *opt);
481
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000482/**
483 * The real main function
Miklos Szeredie5183742005-02-02 11:14:04 +0000484 *
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000485 * Do not call this directly, use fuse_main()
486 */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000487int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
488 size_t op_size);
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000489
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000490/* ----------------------------------------------------------- *
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000491 * Advanced API for event handling, don't worry about this... *
492 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000493
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000494/** Function type used to process commands */
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000495typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000496
497/** This is the part of fuse_main() before the event loop */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000498struct fuse *fuse_setup(int argc, char *argv[],
499 const struct fuse_operations *op, size_t op_size,
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000500 char **mountpoint, int *multithreaded, int *fd);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000501
502/** This is the part of fuse_main() after the event loop */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000503void fuse_teardown(struct fuse *fuse, int fd, char *mountpoint);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000504
505/** Read a single command. If none are read, return NULL */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000506struct fuse_cmd *fuse_read_cmd(struct fuse *f);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000507
508/** Process a single command */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000509void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000510
511/** Multi threaded event loop, which calls the custom command
512 processor function */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000513int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000514
515/** Return the exited flag, which indicates if fuse_exit() has been
516 called */
Miklos Szeredie2aa2e22005-07-15 13:31:36 +0000517int fuse_exited(struct fuse *f);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000518
519/** Set function which can be used to get the current context */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000520void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000521
Miklos Szeredie2aa2e22005-07-15 13:31:36 +0000522/** Returns the lowlevel FUSE object */
523struct fuse_ll *fuse_get_lowlevel(struct fuse *f);
524
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000525/* ----------------------------------------------------------- *
526 * Compatibility stuff *
527 * ----------------------------------------------------------- */
528
529#if FUSE_USE_VERSION == 21 || FUSE_USE_VERSION == 11
Miklos Szeredie56818b2004-12-12 11:45:24 +0000530# include "fuse_compat.h"
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000531# define fuse_dirfil_t fuse_dirfil_t_compat
532# define __fuse_read_cmd fuse_read_cmd
533# define __fuse_process_cmd fuse_process_cmd
534# define __fuse_loop_mt fuse_loop_mt_proc
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000535# undef fuse_main
536# undef FUSE_MINOR_VERSION
537# undef FUSE_MAJOR_VERSION
538# if FUSE_USE_VERSION == 21
539# define FUSE_MAJOR_VERSION 2
540# define FUSE_MINOR_VERSION 1
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000541# define fuse_operations fuse_operations_compat2
542# define fuse_main fuse_main_compat2
543# define fuse_new fuse_new_compat2
544# define __fuse_setup fuse_setup_compat2
545# define __fuse_teardown fuse_teardown
546# define __fuse_exited fuse_exited
547# define __fuse_set_getcontext_func fuse_set_getcontext_func
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000548# else
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000549# define FUSE_MAJOR_VERSION 1
550# define FUSE_MINOR_VERSION 1
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000551# define fuse_statfs fuse_statfs_compat1
552# define fuse_operations fuse_operations_compat1
553# define fuse_main fuse_main_compat1
554# define fuse_new fuse_new_compat1
555# define fuse_mount fuse_mount_compat1
556# define FUSE_DEBUG FUSE_DEBUG_COMPAT1
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000557# endif
Miklos Szeredi799993c2004-12-04 21:20:05 +0000558#elif FUSE_USE_VERSION < 22
559# error Compatibility with API version other than 21 and 11 not supported
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000560#endif
561
Miklos Szerediacd4e062001-12-08 20:29:20 +0000562#ifdef __cplusplus
563}
564#endif
565
566#endif /* _FUSE_H_ */