blob: fe52531bbacf13e023689d67a6e67b31caadae07 [file] [log] [blame]
Miklos Szeredi85c74fc2001-10-28 19:44:14 +00001/*
2 FUSE: Filesystem in Userspace
Miklos Szeredi95da8602006-01-06 18:29:40 +00003 Copyright (C) 2001-2006 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
Miklos Szeredia039f8f2006-02-24 16:21:58 +000015 header. To use the newest API define it to 26 (recommended for any
16 new application), to use the old API define it to 21 (default) 22
17 or 25, to use the even older 1.X API define it to 11. */
Miklos Szeredic706ad92005-11-07 15:30:48 +000018
19#ifndef FUSE_USE_VERSION
20#define FUSE_USE_VERSION 21
21#endif
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +000022
Miklos Szeredi76c17522005-07-13 14:08:19 +000023#include "fuse_common.h"
24
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000025#include <sys/types.h>
26#include <sys/stat.h>
Miklos Szeredi52cb09d2005-11-07 11:59:00 +000027#include <sys/statvfs.h>
Miklos Szeredi5e183482001-10-31 14:52:35 +000028#include <utime.h>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000029
Miklos Szeredi8fb48fe2004-11-08 14:48:52 +000030#ifdef __cplusplus
31extern "C" {
32#endif
33
Miklos Szeredicc8c9752001-11-21 10:03:39 +000034/* ----------------------------------------------------------- *
35 * Basic FUSE API *
36 * ----------------------------------------------------------- */
37
Miklos Szeredi2df1c042001-11-06 15:07:17 +000038/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000039struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000040
Miklos Szeredia1482422005-08-14 23:00:27 +000041/** Structure containing a raw command */
42struct fuse_cmd;
43
Miklos Szeredi18fce982005-04-01 21:07:35 +000044/** Function to add an entry in a readdir() operation
45 *
46 * @param buf the buffer passed to the readdir() operation
47 * @param name the file name of the directory entry
Miklos Szerediab974562005-04-07 15:40:21 +000048 * @param stat file attributes, can be NULL
49 * @param off offset of the next entry or zero
50 * @return 1 if buffer is full, zero otherwise
Miklos Szeredi18fce982005-04-01 21:07:35 +000051 */
Miklos Szerediab974562005-04-07 15:40:21 +000052typedef int (*fuse_fill_dir_t) (void *buf, const char *name,
Miklos Szeredif6e0ec62005-08-03 09:11:06 +000053 const struct stat *stbuf, off_t off);
Miklos Szerediab974562005-04-07 15:40:21 +000054
55/* Used by deprecated getdir() method */
56typedef struct fuse_dirhandle *fuse_dirh_t;
57typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type,
58 ino_t ino);
Miklos Szeredi18fce982005-04-01 21:07:35 +000059
Miklos Szeredi2df1c042001-11-06 15:07:17 +000060/**
61 * The file system operations:
62 *
63 * Most of these should work very similarly to the well known UNIX
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000064 * file system operations. A major exception is that instead of
65 * returning an error in 'errno', the operation should return the
Miklos Szeredie5183742005-02-02 11:14:04 +000066 * negated error value (-errno) directly.
Miklos Szeredie56818b2004-12-12 11:45:24 +000067 *
68 * All methods are optional, but some are essential for a useful
Miklos Szeredi31066bb2005-08-01 14:49:31 +000069 * filesystem (e.g. getattr). Open, flush, release, fsync, opendir,
Miklos Szeredif7eec032005-10-28 13:09:50 +000070 * releasedir, fsyncdir, access, create, ftruncate, fgetattr, init and
71 * destroy are special purpose methods, without which a full featured
Miklos Szeredi11509ce2005-10-26 16:04:04 +000072 * filesystem can still be implemented.
Miklos Szeredie2e4ac22004-05-18 08:45:28 +000073 */
Miklos Szeredia181e612001-11-06 12:03:23 +000074struct fuse_operations {
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000075 /** Get file attributes.
76 *
77 * Similar to stat(). The 'st_dev' and 'st_blksize' fields are
78 * ignored. The 'st_ino' field is ignored except if the 'use_ino'
79 * mount option is given.
80 */
81 int (*getattr) (const char *, struct stat *);
82
83 /** Read the target of a symbolic link
Miklos Szeredie5183742005-02-02 11:14:04 +000084 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000085 * The buffer should be filled with a null terminated string. The
86 * buffer size argument includes the space for the terminating
87 * null character. If the linkname is too long to fit in the
88 * buffer, it should be truncated. The return value should be 0
89 * for success.
90 */
91 int (*readlink) (const char *, char *, size_t);
92
Miklos Szerediab974562005-04-07 15:40:21 +000093 /* Deprecated, use readdir() instead */
Miklos Szeredid59bb9d2004-12-07 10:04:24 +000094 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
95
96 /** Create a file node
97 *
Miklos Szeredib052a1a2006-06-28 14:51:20 +000098 * If the filesystem doesn't define a create() operation, mknod()
99 * will be called for creation of all non-directory, non-symlink
100 * nodes.
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000101 */
102 int (*mknod) (const char *, mode_t, dev_t);
103
104 /** Create a directory */
105 int (*mkdir) (const char *, mode_t);
106
107 /** Remove a file */
108 int (*unlink) (const char *);
109
110 /** Remove a directory */
111 int (*rmdir) (const char *);
112
113 /** Create a symbolic link */
114 int (*symlink) (const char *, const char *);
115
116 /** Rename a file */
117 int (*rename) (const char *, const char *);
118
119 /** Create a hard link to a file */
120 int (*link) (const char *, const char *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000121
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000122 /** Change the permission bits of a file */
123 int (*chmod) (const char *, mode_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000124
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000125 /** Change the owner and group of a file */
126 int (*chown) (const char *, uid_t, gid_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000127
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000128 /** Change the size of a file */
129 int (*truncate) (const char *, off_t);
Miklos Szeredie5183742005-02-02 11:14:04 +0000130
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000131 /** Change the access and/or modification times of a file */
132 int (*utime) (const char *, struct utimbuf *);
Miklos Szeredie5183742005-02-02 11:14:04 +0000133
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000134 /** File open operation
135 *
Miklos Szeredib75d4b92005-10-11 10:12:08 +0000136 * No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC)
Miklos Szeredifa848662005-09-08 15:16:14 +0000137 * will be passed to open(). Open should check if the operation
138 * is permitted for the given flags. Optionally open may also
Miklos Szeredib75d4b92005-10-11 10:12:08 +0000139 * return an arbitrary filehandle in the fuse_file_info structure,
Miklos Szeredifa848662005-09-08 15:16:14 +0000140 * which will be passed to all file operations.
Miklos Szeredi31066bb2005-08-01 14:49:31 +0000141 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000142 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000143 */
144 int (*open) (const char *, struct fuse_file_info *);
145
146 /** Read data from an open file
147 *
148 * Read should return exactly the number of bytes requested except
149 * on EOF or error, otherwise the rest of the data will be
150 * substituted with zeroes. An exception to this is when the
151 * 'direct_io' mount option is specified, in which case the return
152 * value of the read system call will reflect the return value of
153 * this operation.
Miklos Szeredi437d8112005-07-06 09:14:20 +0000154 *
155 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000156 */
157 int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *);
158
Miklos Szeredie5183742005-02-02 11:14:04 +0000159 /** Write data to an open file
160 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000161 * Write should return exactly the number of bytes requested
162 * except on error. An exception to this is when the 'direct_io'
163 * mount option is specified (see read operation).
Miklos Szeredi437d8112005-07-06 09:14:20 +0000164 *
165 * Changed in version 2.2
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000166 */
167 int (*write) (const char *, const char *, size_t, off_t,
168 struct fuse_file_info *);
169
Miklos Szeredic706ad92005-11-07 15:30:48 +0000170 /** Just a placeholder, don't set */
Miklos Szeredi3a770472005-11-11 21:32:42 +0000171 /** Get file system statistics
172 *
173 * The 'f_frsize', 'f_favail', 'f_fsid' and 'f_flag' fields are ignored
174 *
175 * Replaced 'struct statfs' parameter with 'struct statvfs' in
176 * version 2.5
177 */
178 int (*statfs) (const char *, struct statvfs *);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000179
Miklos Szeredie5183742005-02-02 11:14:04 +0000180 /** Possibly flush cached data
181 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000182 * BIG NOTE: This is not equivalent to fsync(). It's not a
Miklos Szeredie56818b2004-12-12 11:45:24 +0000183 * request to sync dirty data.
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000184 *
185 * Flush is called on each close() of a file descriptor. So if a
186 * filesystem wants to return write errors in close() and the file
187 * has cached dirty data, this is a good place to write back data
Miklos Szeredie56818b2004-12-12 11:45:24 +0000188 * and return any errors. Since many applications ignore close()
189 * errors this is not always useful.
Miklos Szeredie5183742005-02-02 11:14:04 +0000190 *
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000191 * NOTE: The flush() method may be called more than once for each
192 * open(). This happens if more than one file descriptor refers
193 * to an opened file due to dup(), dup2() or fork() calls. It is
194 * not possible to determine if a flush is final, so each flush
195 * should be treated equally. Multiple write-flush sequences are
196 * relatively rare, so this shouldn't be a problem.
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000197 *
Miklos Szeredib75d4b92005-10-11 10:12:08 +0000198 * Filesystems shouldn't assume that flush will always be called
Miklos Szeredi7f54fb42005-10-10 08:42:17 +0000199 * after some writes, or that if will be called at all.
200 *
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
Miklos Szeredi009b8782005-08-01 13:36:53 +0000242 /** Open directory
Miklos Szeredi437d8112005-07-06 09:14:20 +0000243 *
Miklos Szeredifa848662005-09-08 15:16:14 +0000244 * This method should check if the open operation is permitted for
245 * this directory
246 *
Miklos Szeredi437d8112005-07-06 09:14:20 +0000247 * 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 */
Miklos Szeredi065f2222006-01-20 15:15:21 +0000299 void *(*init) (struct fuse_conn_info *conn);
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000300
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 Szeredib0b13d12005-10-26 12:53:25 +0000309
310 /**
311 * Check file access permissions
312 *
Miklos Szeredid9079a72005-10-26 15:29:06 +0000313 * This will be called for the access() system call. If the
314 * 'default_permissions' mount option is given, this method is not
315 * called.
316 *
317 * This method is not called under Linux kernel versions 2.4.x
Miklos Szeredib0b13d12005-10-26 12:53:25 +0000318 *
319 * Introduced in version 2.5
320 */
321 int (*access) (const char *, int);
Miklos Szeredid9079a72005-10-26 15:29:06 +0000322
323 /**
324 * Create and open a file
325 *
326 * If the file does not exist, first create it with the specified
327 * mode, and then open it.
328 *
329 * If this method is not implemented or under Linux kernel
330 * versions earlier than 2.6.15, the mknod() and open() methods
331 * will be called instead.
332 *
333 * Introduced in version 2.5
334 */
335 int (*create) (const char *, mode_t, struct fuse_file_info *);
Miklos Szeredi11509ce2005-10-26 16:04:04 +0000336
337 /**
338 * Change the size of an open file
339 *
340 * This method is called instead of the truncate() method if the
341 * truncation was invoked from an ftruncate() system call.
342 *
343 * If this method is not implemented or under Linux kernel
344 * versions earlier than 2.6.15, the truncate() method will be
345 * called instead.
346 *
347 * Introduced in version 2.5
348 */
349 int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
Miklos Szeredif7eec032005-10-28 13:09:50 +0000350
351 /**
352 * Get attributes from an open file
353 *
354 * This method is called instead of the getattr() method if the
355 * file information is available.
356 *
357 * Currently this is only called after the create() method if that
358 * is implemented (see above). Later it may be called for
359 * invocations of fstat() too.
360 *
361 * Introduced in version 2.5
362 */
363 int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
Miklos Szeredia181e612001-11-06 12:03:23 +0000364};
365
Miklos Szeredie5183742005-02-02 11:14:04 +0000366/** Extra context that may be needed by some filesystems
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000367 *
368 * The uid, gid and pid fields are not filled in case of a writepage
369 * operation.
370 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000371struct fuse_context {
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000372 /** Pointer to the fuse object */
Miklos Szeredid169f312004-09-22 08:48:26 +0000373 struct fuse *fuse;
Miklos Szeredie5183742005-02-02 11:14:04 +0000374
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000375 /** User ID of the calling process */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000376 uid_t uid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000377
378 /** Group ID of the calling process */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000379 gid_t gid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000380
381 /** Thread ID of the calling process */
Miklos Szeredi1f18db52004-09-27 06:54:49 +0000382 pid_t pid;
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000383
Miklos Szeredi159bd7e2005-02-28 17:32:16 +0000384 /** Private filesystem data */
Miklos Szeredi8fb48fe2004-11-08 14:48:52 +0000385 void *private_data;
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000386};
387
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000388/*
Miklos Szeredi0e535082003-10-13 10:08:06 +0000389 * Main function of FUSE.
390 *
391 * This is for the lazy. This is all that has to be called from the
392 * main() function.
Miklos Szeredie5183742005-02-02 11:14:04 +0000393 *
Miklos Szeredi0e535082003-10-13 10:08:06 +0000394 * This function does the following:
Miklos Szeredi307242f2004-01-26 11:28:44 +0000395 * - parses command line options (-d -s and -h)
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000396 * - passes relevant mount options to the fuse_mount()
Miklos Szeredi0e535082003-10-13 10:08:06 +0000397 * - installs signal handlers for INT, HUP, TERM and PIPE
398 * - registers an exit handler to unmount the filesystem on program exit
Miklos Szeredi0e535082003-10-13 10:08:06 +0000399 * - creates a fuse handle
400 * - registers the operations
401 * - calls either the single-threaded or the multi-threaded event loop
402 *
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000403 * Note: this is currently implemented as a macro.
404 *
Miklos Szeredi0e535082003-10-13 10:08:06 +0000405 * @param argc the argument counter passed to the main() function
406 * @param argv the argument vector passed to the main() function
Miklos Szeredie5183742005-02-02 11:14:04 +0000407 * @param op the file system operation
Miklos Szeredi6f385412006-03-17 15:05:40 +0000408 * @param user_data user data set in context for init() method
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000409 * @return 0 on success, nonzero on failure
Miklos Szeredi0e535082003-10-13 10:08:06 +0000410 */
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000411/*
Miklos Szeredi6f385412006-03-17 15:05:40 +0000412int fuse_main(int argc, char *argv[], const struct fuse_operations *op,
413 void *user_data);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000414*/
Miklos Szeredi6f385412006-03-17 15:05:40 +0000415#define fuse_main(argc, argv, op, user_data) \
416 fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
Miklos Szeredi891b8742004-07-29 09:27:49 +0000417
Miklos Szeredi0e535082003-10-13 10:08:06 +0000418/* ----------------------------------------------------------- *
419 * More detailed API *
420 * ----------------------------------------------------------- */
421
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000422/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000423 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000424 *
Miklos Szeredi6f385412006-03-17 15:05:40 +0000425 * @param ch the communication channel
Miklos Szeredi95da8602006-01-06 18:29:40 +0000426 * @param args argument vector
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000427 * @param op the operations
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000428 * @param op_size the size of the fuse_operations structure
Miklos Szeredi6f385412006-03-17 15:05:40 +0000429 * @param user_data user data set in context for init() method
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000430 * @return the created FUSE handle
431 */
Miklos Szeredi6f385412006-03-17 15:05:40 +0000432struct fuse *fuse_new(struct fuse_chan *ch, struct fuse_args *args,
433 const struct fuse_operations *op, size_t op_size,
434 void *user_data);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000435
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000436/**
Miklos Szeredie5183742005-02-02 11:14:04 +0000437 * Destroy the FUSE handle.
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000438 *
439 * The filesystem is not unmounted.
440 *
441 * @param f the FUSE handle
442 */
443void fuse_destroy(struct fuse *f);
444
445/**
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000446 * FUSE event loop.
447 *
Miklos Szeredib75d4b92005-10-11 10:12:08 +0000448 * Requests from the kernel are processed, and the appropriate
Miklos Szeredie5183742005-02-02 11:14:04 +0000449 * operations are called.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000450 *
451 * @param f the FUSE handle
Miklos Szeredib75d4b92005-10-11 10:12:08 +0000452 * @return 0 if no error occurred, -1 otherwise
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000453 */
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000454int fuse_loop(struct fuse *f);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000455
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000456/**
457 * Exit from event loop
458 *
459 * @param f the FUSE handle
460 */
461void fuse_exit(struct fuse *f);
462
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000463/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000464 * FUSE event loop with multiple threads
465 *
Miklos Szeredib75d4b92005-10-11 10:12:08 +0000466 * Requests from the kernel are processed, and the appropriate
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000467 * operations are called. Request are processed in parallel by
468 * distributing them between multiple threads.
469 *
470 * Calling this function requires the pthreads library to be linked to
471 * the application.
472 *
473 * @param f the FUSE handle
Miklos Szeredib75d4b92005-10-11 10:12:08 +0000474 * @return 0 if no error occurred, -1 otherwise
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000475 */
Miklos Szeredib2cf9562004-09-16 08:42:40 +0000476int fuse_loop_mt(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000477
478/**
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000479 * Get the current context
Miklos Szeredie5183742005-02-02 11:14:04 +0000480 *
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000481 * The context is only valid for the duration of a filesystem
482 * operation, and thus must not be stored and used later.
483 *
484 * @param f the FUSE handle
Miklos Szeredie5183742005-02-02 11:14:04 +0000485 * @return the context
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000486 */
Miklos Szeredid169f312004-09-22 08:48:26 +0000487struct fuse_context *fuse_get_context(void);
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000488
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000489/**
Miklos Szeredi76c17522005-07-13 14:08:19 +0000490 * Obsolete, doesn't do anything
Miklos Szeredi9b813af2005-07-21 07:59:37 +0000491 *
Miklos Szeredibd10a7b2005-07-15 09:59:59 +0000492 * @return -EINVAL
Miklos Szeredi5dc8a802004-10-21 09:35:10 +0000493 */
494int fuse_invalidate(struct fuse *f, const char *path);
495
Miklos Szeredi95da8602006-01-06 18:29:40 +0000496/* Deprecated, don't use */
Miklos Szeredibd7661b2004-07-23 17:16:29 +0000497int fuse_is_lib_option(const char *opt);
498
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000499/**
500 * The real main function
Miklos Szeredie5183742005-02-02 11:14:04 +0000501 *
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000502 * Do not call this directly, use fuse_main()
503 */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000504int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
Miklos Szeredi6f385412006-03-17 15:05:40 +0000505 size_t op_size, void *user_data);
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000506
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000507/* ----------------------------------------------------------- *
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000508 * Advanced API for event handling, don't worry about this... *
509 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000510
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000511/** Function type used to process commands */
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000512typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000513
514/** This is the part of fuse_main() before the event loop */
Miklos Szeredi60c69a22006-01-07 08:51:19 +0000515struct fuse *fuse_setup(int argc, char *argv[],
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000516 const struct fuse_operations *op, size_t op_size,
Miklos Szeredi6f385412006-03-17 15:05:40 +0000517 char **mountpoint, int *multithreaded,
518 void *user_data);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000519
520/** This is the part of fuse_main() after the event loop */
Miklos Szeredi6f385412006-03-17 15:05:40 +0000521void fuse_teardown(struct fuse *fuse, char *mountpoint);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000522
523/** Read a single command. If none are read, return NULL */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000524struct fuse_cmd *fuse_read_cmd(struct fuse *f);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000525
526/** Process a single command */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000527void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000528
529/** Multi threaded event loop, which calls the custom command
530 processor function */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000531int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000532
533/** Return the exited flag, which indicates if fuse_exit() has been
534 called */
Miklos Szeredie2aa2e22005-07-15 13:31:36 +0000535int fuse_exited(struct fuse *f);
Miklos Szeredid59bb9d2004-12-07 10:04:24 +0000536
537/** Set function which can be used to get the current context */
Miklos Szeredif458b8c2004-12-07 16:46:42 +0000538void fuse_set_getcontext_func(struct fuse_context *(*func)(void));
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000539
Miklos Szeredi6f385412006-03-17 15:05:40 +0000540/** Get session from fuse object */
541struct fuse_session *fuse_get_session(struct fuse *f);
542
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000543/* ----------------------------------------------------------- *
544 * Compatibility stuff *
545 * ----------------------------------------------------------- */
546
Miklos Szeredi87c77932006-03-10 10:18:20 +0000547#if FUSE_USE_VERSION < 26
Miklos Szeredie56818b2004-12-12 11:45:24 +0000548# include "fuse_compat.h"
Miklos Szeredic706ad92005-11-07 15:30:48 +0000549# undef fuse_main
Miklos Szeredi065f2222006-01-20 15:15:21 +0000550# if FUSE_USE_VERSION == 25
Miklos Szeredi065f2222006-01-20 15:15:21 +0000551# define fuse_main(argc, argv, op) \
552 fuse_main_real_compat25(argc, argv, op, sizeof(*(op)))
553# define fuse_new fuse_new_compat25
554# define fuse_setup fuse_setup_compat25
Miklos Szeredi6f385412006-03-17 15:05:40 +0000555# define fuse_teardown fuse_teardown_compat25
Miklos Szeredi065f2222006-01-20 15:15:21 +0000556# define fuse_operations fuse_operations_compat25
557# elif FUSE_USE_VERSION == 22
Miklos Szeredi3a770472005-11-11 21:32:42 +0000558# define fuse_main(argc, argv, op) \
559 fuse_main_real_compat22(argc, argv, op, sizeof(*(op)))
560# define fuse_new fuse_new_compat22
561# define fuse_setup fuse_setup_compat22
Miklos Szeredic706ad92005-11-07 15:30:48 +0000562# define fuse_operations fuse_operations_compat22
Miklos Szeredi3a770472005-11-11 21:32:42 +0000563# define fuse_file_info fuse_file_info_compat22
Miklos Szeredi87c77932006-03-10 10:18:20 +0000564# elif FUSE_USE_VERSION == 24
565# error Compatibility with high-level API version 24 not supported
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000566# else
Miklos Szeredic706ad92005-11-07 15:30:48 +0000567# define fuse_dirfil_t fuse_dirfil_t_compat
568# define __fuse_read_cmd fuse_read_cmd
569# define __fuse_process_cmd fuse_process_cmd
570# define __fuse_loop_mt fuse_loop_mt_proc
571# if FUSE_USE_VERSION == 21
Miklos Szeredic706ad92005-11-07 15:30:48 +0000572# define fuse_operations fuse_operations_compat2
573# define fuse_main fuse_main_compat2
574# define fuse_new fuse_new_compat2
575# define __fuse_setup fuse_setup_compat2
576# define __fuse_teardown fuse_teardown
577# define __fuse_exited fuse_exited
578# define __fuse_set_getcontext_func fuse_set_getcontext_func
579# else
Miklos Szeredic706ad92005-11-07 15:30:48 +0000580# define fuse_statfs fuse_statfs_compat1
581# define fuse_operations fuse_operations_compat1
582# define fuse_main fuse_main_compat1
583# define fuse_new fuse_new_compat1
Miklos Szeredic706ad92005-11-07 15:30:48 +0000584# define FUSE_DEBUG FUSE_DEBUG_COMPAT1
585# endif
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000586# endif
Miklos Szeredi0b6a0ad2004-12-04 00:40:50 +0000587#endif
588
Miklos Szerediacd4e062001-12-08 20:29:20 +0000589#ifdef __cplusplus
590}
591#endif
592
593#endif /* _FUSE_H_ */