blob: 79c62a6e750ccbe48e42f40faf11262b9a0fabb0 [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 */
Miklos Szeredi18e75e42004-02-19 14:23:27 +000015#define FUSE_MAJOR_VERSION 2
Miklos Szeredi2f3d9402003-12-15 12:11:33 +000016
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 Szeredi18e75e42004-02-19 14:23:27 +000025#include <sys/statfs.h>
Miklos Szeredi5e183482001-10-31 14:52:35 +000026#include <utime.h>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000027
Miklos Szeredicc8c9752001-11-21 10:03:39 +000028/* ----------------------------------------------------------- *
29 * Basic FUSE API *
30 * ----------------------------------------------------------- */
31
Miklos Szeredi2df1c042001-11-06 15:07:17 +000032/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000033struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000034
35/** Handle for a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000036typedef struct fuse_dirhandle *fuse_dirh_t;
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000037
Miklos Szeredif08ace02003-10-22 11:11:57 +000038/** Function to add an entry in a getdir() operation
39 *
40 * @param h the handle passed to the getdir() operation
41 * @param name the file name of the directory entry
42 * @param type the file type (0 if unknown) see <dirent.h>
43 * @return 0 on success, -errno on error
44 */
45typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000046
Miklos Szeredi2df1c042001-11-06 15:07:17 +000047/**
48 * The file system operations:
49 *
50 * Most of these should work very similarly to the well known UNIX
51 * file system operations. Exceptions are:
52 *
Miklos Szeredi2df1c042001-11-06 15:07:17 +000053 * - All operations should return the negated error value (-errno) on
54 * error.
55 *
Miklos Szeredi05033042001-11-13 16:11:35 +000056 * - Getattr() doesn't need to fill in the following fields:
57 * st_ino
58 * st_dev
59 * st_blksize
60 *
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000061 * - readlink() should fill the buffer with a null terminated string. The
62 * buffer size argument includes the space for the terminating null
63 * character. If the linkname is too long to fit in the buffer, it should
64 * be truncated. The return value should be 0 for success.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000065 *
66 * - getdir() is the opendir(), readdir(), ..., closedir() sequence
67 * in one call. For each directory entry the filldir parameter should
68 * be called.
69 *
70 * - There is no create() operation, mknod() will be called for
71 * creation of all non directory, non symlink nodes.
72 *
73 * - open() should not return a filehandle, but 0 on success. No
74 * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
75 * passed to open(). Open should only check if the operation is
76 * permitted for the given flags.
77 *
78 * - read(), write() are not passed a filehandle, but rather a
79 * pathname. The offset of the read and write is passed as the last
Miklos Szeredi307242f2004-01-26 11:28:44 +000080 * argument, like the pread() and pwrite() system calls. (NOTE:
81 * read() should always return the number of bytes requested, except
82 * at end of file)
Miklos Szeredic8ba2372002-12-10 12:26:00 +000083 *
84 * - release() is called when an open file has:
85 * 1) all file descriptors closed
86 * 2) all memory mappings unmapped
87 * This call need only be implemented if this information is required,
88 * otherwise set this function to NULL.
Miklos Szeredi5e43f2c2003-12-12 14:06:41 +000089 *
90 * - fsync() has a boolean 'datasync' parameter which if TRUE then do
91 * an fdatasync() operation.
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000092 */
Miklos Szeredia181e612001-11-06 12:03:23 +000093struct fuse_operations {
Miklos Szeredi3ed84232004-03-30 15:17:26 +000094 int (*getattr) (const char *, struct stat *);
95 int (*readlink) (const char *, char *, size_t);
96 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
97 int (*mknod) (const char *, mode_t, dev_t);
98 int (*mkdir) (const char *, mode_t);
99 int (*unlink) (const char *);
100 int (*rmdir) (const char *);
101 int (*symlink) (const char *, const char *);
102 int (*rename) (const char *, const char *);
103 int (*link) (const char *, const char *);
104 int (*chmod) (const char *, mode_t);
105 int (*chown) (const char *, uid_t, gid_t);
106 int (*truncate) (const char *, off_t);
107 int (*utime) (const char *, struct utimbuf *);
108 int (*open) (const char *, int);
109 int (*read) (const char *, char *, size_t, off_t);
110 int (*write) (const char *, const char *, size_t, off_t);
111 int (*statfs) (const char *, struct statfs *);
112 int (*release) (const char *, int);
113 int (*fsync) (const char *, int);
114 int (*setxattr) (const char *, const char *, const char *, size_t, int);
115 int (*getxattr) (const char *, const char *, char *, size_t);
116 int (*listxattr) (const char *, char *, size_t);
117 int (*removexattr) (const char *, const char *);
Miklos Szeredia181e612001-11-06 12:03:23 +0000118};
119
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000120/** Extra context that may be needed by some filesystems */
121struct fuse_context {
122 uid_t uid;
123 gid_t gid;
124};
125
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000126/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +0000127
Miklos Szeredic0938ea2001-11-07 12:35:06 +0000128/** Enable debuging output */
129#define FUSE_DEBUG (1 << 1)
130
Miklos Szerediacd4e062001-12-08 20:29:20 +0000131#ifdef __cplusplus
132extern "C" {
133#endif
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000134
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000135/*
Miklos Szeredi0e535082003-10-13 10:08:06 +0000136 * Main function of FUSE.
137 *
138 * This is for the lazy. This is all that has to be called from the
139 * main() function.
140 *
141 * This function does the following:
Miklos Szeredi307242f2004-01-26 11:28:44 +0000142 * - parses command line options (-d -s and -h)
143 * - passes all options after '--' to the fusermount program
144 * - mounts the filesystem by calling fusermount
Miklos Szeredi0e535082003-10-13 10:08:06 +0000145 * - installs signal handlers for INT, HUP, TERM and PIPE
146 * - registers an exit handler to unmount the filesystem on program exit
Miklos Szeredi0e535082003-10-13 10:08:06 +0000147 * - creates a fuse handle
148 * - registers the operations
149 * - calls either the single-threaded or the multi-threaded event loop
150 *
151 * @param argc the argument counter passed to the main() function
152 * @param argv the argument vector passed to the main() function
153 * @param op the file system operation
154 */
155void fuse_main(int argc, char *argv[], const struct fuse_operations *op);
156
Miklos Szeredi33c319c2004-02-25 09:19:29 +0000157/*
158 * Returns the fuse object created by fuse_main()
159 *
160 * This is useful when fuse_get_context() is used.
161 *
162 * @return the fuse object
163 */
164struct fuse *fuse_get(void);
165
Miklos Szeredi0e535082003-10-13 10:08:06 +0000166/* ----------------------------------------------------------- *
167 * More detailed API *
168 * ----------------------------------------------------------- */
169
170/*
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000171 * Create a FUSE mountpoint
172 *
173 * Returns a control file descriptor suitable for passing to
174 * fuse_new()
175 *
176 * @param mountpoint the mount point path
Miklos Szeredid6e9f882002-10-25 11:40:14 +0000177 * @param args array of arguments to be passed to fusermount (NULL
178 * terminated). Can be NULL if no arguments are needed.
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000179 * @return the control file descriptor on success, -1 on failure
180 */
Miklos Szeredid6e9f882002-10-25 11:40:14 +0000181int fuse_mount(const char *mountpoint, const char *args[]);
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000182
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000183/*
184 * Umount a FUSE mountpoint
185 *
186 * @param mountpoint the mount point path
187 */
188void fuse_unmount(const char *mountpoint);
189
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000190/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000191 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000192 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000193 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000194 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000195 * @param op the operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000196 * @return the created FUSE handle
197 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000198struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000199
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000200/**
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000201 * Destroy the FUSE handle.
202 *
203 * The filesystem is not unmounted.
204 *
205 * @param f the FUSE handle
206 */
207void fuse_destroy(struct fuse *f);
208
209/**
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000210 * FUSE event loop.
211 *
212 * Requests from the kernel are processed, and the apropriate
213 * operations are called.
214 *
215 * @param f the FUSE handle
216 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000217void fuse_loop(struct fuse *f);
218
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000219/**
220 * Exit from event loop
221 *
222 * @param f the FUSE handle
223 */
224void fuse_exit(struct fuse *f);
225
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000226/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000227 * FUSE event loop with multiple threads
228 *
229 * Requests from the kernel are processed, and the apropriate
230 * operations are called. Request are processed in parallel by
231 * distributing them between multiple threads.
232 *
233 * Calling this function requires the pthreads library to be linked to
234 * the application.
235 *
236 * @param f the FUSE handle
237 */
238void fuse_loop_mt(struct fuse *f);
239
240/**
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000241 * Get the current context
242 *
243 * The context is only valid for the duration of a filesystem
244 * operation, and thus must not be stored and used later.
245 *
246 * @param f the FUSE handle
247 * @return the context
248 */
249struct fuse_context *fuse_get_context(struct fuse *f);
250
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000251/* ----------------------------------------------------------- *
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000252 * Advanced API for event handling, don't worry about this... *
253 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000254
255struct fuse_cmd;
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000256typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000257struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000258void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000259void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
260
Miklos Szerediacd4e062001-12-08 20:29:20 +0000261#ifdef __cplusplus
262}
263#endif
264
265#endif /* _FUSE_H_ */