blob: c2f0be4b40847d4435fa2ffddc28a3017790bad6 [file] [log] [blame]
Miklos Szeredi85c74fc2001-10-28 19:44:14 +00001/*
2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001 Miklos Szeredi (mszeredi@inf.bme.hu)
4
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 Szeredi2f3d9402003-12-15 12:11:33 +000014/** Major version of FUSE library interface */
15#define FUSE_MAJOR_VERSION 1
16
17/** Minor version of FUSE library interface */
18#define FUSE_MINOR_VERSION 1
19
Miklos Szeredi5f054812002-12-03 18:45:21 +000020/* Now and forever: this interface uses 64 bit off_t */
21#define _FILE_OFFSET_BITS 64
22
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000023#include <sys/types.h>
24#include <sys/stat.h>
Miklos Szeredi5e183482001-10-31 14:52:35 +000025#include <utime.h>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000026
Miklos Szeredicc8c9752001-11-21 10:03:39 +000027/* ----------------------------------------------------------- *
28 * Basic FUSE API *
29 * ----------------------------------------------------------- */
30
Miklos Szeredi2df1c042001-11-06 15:07:17 +000031/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000032struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000033
Miklos Szeredi24ed9452002-10-07 10:24:26 +000034/* Statfs structure used by FUSE */
35struct fuse_statfs {
36 long block_size;
37 long blocks;
38 long blocks_free;
39 long files;
40 long files_free;
41 long namelen;
42};
43
Miklos Szeredi2df1c042001-11-06 15:07:17 +000044/** Handle for a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000045typedef struct fuse_dirhandle *fuse_dirh_t;
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000046
Miklos Szeredif08ace02003-10-22 11:11:57 +000047/** Function to add an entry in a getdir() operation
48 *
49 * @param h the handle passed to the getdir() operation
50 * @param name the file name of the directory entry
51 * @param type the file type (0 if unknown) see <dirent.h>
52 * @return 0 on success, -errno on error
53 */
54typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000055
Miklos Szeredi2df1c042001-11-06 15:07:17 +000056/**
57 * The file system operations:
58 *
59 * Most of these should work very similarly to the well known UNIX
60 * file system operations. Exceptions are:
61 *
Miklos Szeredi2df1c042001-11-06 15:07:17 +000062 * - All operations should return the negated error value (-errno) on
63 * error.
64 *
Miklos Szeredi05033042001-11-13 16:11:35 +000065 * - Getattr() doesn't need to fill in the following fields:
66 * st_ino
67 * st_dev
68 * st_blksize
69 *
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000070 * - readlink() should fill the buffer with a null terminated string. The
71 * buffer size argument includes the space for the terminating null
72 * character. If the linkname is too long to fit in the buffer, it should
73 * be truncated. The return value should be 0 for success.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000074 *
75 * - getdir() is the opendir(), readdir(), ..., closedir() sequence
76 * in one call. For each directory entry the filldir parameter should
77 * be called.
78 *
79 * - There is no create() operation, mknod() will be called for
80 * creation of all non directory, non symlink nodes.
81 *
82 * - open() should not return a filehandle, but 0 on success. No
83 * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
84 * passed to open(). Open should only check if the operation is
85 * permitted for the given flags.
86 *
87 * - read(), write() are not passed a filehandle, but rather a
88 * pathname. The offset of the read and write is passed as the last
Miklos Szeredi307242f2004-01-26 11:28:44 +000089 * argument, like the pread() and pwrite() system calls. (NOTE:
90 * read() should always return the number of bytes requested, except
91 * at end of file)
Miklos Szeredic8ba2372002-12-10 12:26:00 +000092 *
93 * - release() is called when an open file has:
94 * 1) all file descriptors closed
95 * 2) all memory mappings unmapped
96 * This call need only be implemented if this information is required,
97 * otherwise set this function to NULL.
Miklos Szeredi5e43f2c2003-12-12 14:06:41 +000098 *
99 * - fsync() has a boolean 'datasync' parameter which if TRUE then do
100 * an fdatasync() operation.
Miklos Szeredi0a7077f2001-11-11 18:20:17 +0000101 */
Miklos Szeredia181e612001-11-06 12:03:23 +0000102struct fuse_operations {
Miklos Szeredi0a7077f2001-11-11 18:20:17 +0000103 int (*getattr) (const char *, struct stat *);
104 int (*readlink) (const char *, char *, size_t);
105 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
106 int (*mknod) (const char *, mode_t, dev_t);
107 int (*mkdir) (const char *, mode_t);
108 int (*unlink) (const char *);
109 int (*rmdir) (const char *);
110 int (*symlink) (const char *, const char *);
111 int (*rename) (const char *, const char *);
112 int (*link) (const char *, const char *);
113 int (*chmod) (const char *, mode_t);
114 int (*chown) (const char *, uid_t, gid_t);
115 int (*truncate) (const char *, off_t);
116 int (*utime) (const char *, struct utimbuf *);
117 int (*open) (const char *, int);
118 int (*read) (const char *, char *, size_t, off_t);
119 int (*write) (const char *, const char *, size_t, off_t);
Mark Glines85801bb2002-03-17 06:58:33 +0000120 int (*statfs) (struct fuse_statfs *);
Miklos Szeredi9478e862002-12-11 09:50:26 +0000121 int (*release) (const char *, int);
Miklos Szeredi5e43f2c2003-12-12 14:06:41 +0000122 int (*fsync) (const char *, int);
Miklos Szeredia181e612001-11-06 12:03:23 +0000123};
124
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000125/** Extra context that may be needed by some filesystems */
126struct fuse_context {
127 uid_t uid;
128 gid_t gid;
129};
130
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000131/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +0000132
Miklos Szeredic0938ea2001-11-07 12:35:06 +0000133/** Enable debuging output */
134#define FUSE_DEBUG (1 << 1)
135
Miklos Szerediacd4e062001-12-08 20:29:20 +0000136#ifdef __cplusplus
137extern "C" {
138#endif
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000139
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000140/*
Miklos Szeredi0e535082003-10-13 10:08:06 +0000141 * Main function of FUSE.
142 *
143 * This is for the lazy. This is all that has to be called from the
144 * main() function.
145 *
146 * This function does the following:
Miklos Szeredi307242f2004-01-26 11:28:44 +0000147 * - parses command line options (-d -s and -h)
148 * - passes all options after '--' to the fusermount program
149 * - mounts the filesystem by calling fusermount
Miklos Szeredi0e535082003-10-13 10:08:06 +0000150 * - installs signal handlers for INT, HUP, TERM and PIPE
151 * - registers an exit handler to unmount the filesystem on program exit
Miklos Szeredi0e535082003-10-13 10:08:06 +0000152 * - creates a fuse handle
153 * - registers the operations
154 * - calls either the single-threaded or the multi-threaded event loop
155 *
156 * @param argc the argument counter passed to the main() function
157 * @param argv the argument vector passed to the main() function
158 * @param op the file system operation
159 */
160void fuse_main(int argc, char *argv[], const struct fuse_operations *op);
161
162/* ----------------------------------------------------------- *
163 * More detailed API *
164 * ----------------------------------------------------------- */
165
166/*
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000167 * Create a FUSE mountpoint
168 *
169 * Returns a control file descriptor suitable for passing to
170 * fuse_new()
171 *
172 * @param mountpoint the mount point path
Miklos Szeredid6e9f882002-10-25 11:40:14 +0000173 * @param args array of arguments to be passed to fusermount (NULL
174 * terminated). Can be NULL if no arguments are needed.
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000175 * @return the control file descriptor on success, -1 on failure
176 */
Miklos Szeredid6e9f882002-10-25 11:40:14 +0000177int fuse_mount(const char *mountpoint, const char *args[]);
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000178
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000179/*
180 * Umount a FUSE mountpoint
181 *
182 * @param mountpoint the mount point path
183 */
184void fuse_unmount(const char *mountpoint);
185
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000186/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000187 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000188 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000189 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000190 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000191 * @param op the operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000192 * @return the created FUSE handle
193 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000194struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000195
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000196/**
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000197 * Destroy the FUSE handle.
198 *
199 * The filesystem is not unmounted.
200 *
201 * @param f the FUSE handle
202 */
203void fuse_destroy(struct fuse *f);
204
205/**
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000206 * FUSE event loop.
207 *
208 * Requests from the kernel are processed, and the apropriate
209 * operations are called.
210 *
211 * @param f the FUSE handle
212 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000213void fuse_loop(struct fuse *f);
214
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000215/**
216 * Exit from event loop
217 *
218 * @param f the FUSE handle
219 */
220void fuse_exit(struct fuse *f);
221
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000222/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000223 * FUSE event loop with multiple threads
224 *
225 * Requests from the kernel are processed, and the apropriate
226 * operations are called. Request are processed in parallel by
227 * distributing them between multiple threads.
228 *
229 * Calling this function requires the pthreads library to be linked to
230 * the application.
231 *
232 * @param f the FUSE handle
233 */
234void fuse_loop_mt(struct fuse *f);
235
236/**
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000237 * Get the current context
238 *
239 * The context is only valid for the duration of a filesystem
240 * operation, and thus must not be stored and used later.
241 *
242 * @param f the FUSE handle
243 * @return the context
244 */
245struct fuse_context *fuse_get_context(struct fuse *f);
246
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000247/* ----------------------------------------------------------- *
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000248 * Advanced API for event handling, don't worry about this... *
249 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000250
251struct fuse_cmd;
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000252typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000253struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000254void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000255void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
256
Miklos Szerediacd4e062001-12-08 20:29:20 +0000257#ifdef __cplusplus
258}
259#endif
260
261#endif /* _FUSE_H_ */