blob: b54cb47b5b697fb03a4be003cf5c4b226420de3b [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 Szeredi5f054812002-12-03 18:45:21 +000014/* Now and forever: this interface uses 64 bit off_t */
15#define _FILE_OFFSET_BITS 64
16
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000017#include <sys/types.h>
18#include <sys/stat.h>
Miklos Szeredi5e183482001-10-31 14:52:35 +000019#include <utime.h>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000020
Miklos Szeredicc8c9752001-11-21 10:03:39 +000021/* ----------------------------------------------------------- *
22 * Basic FUSE API *
23 * ----------------------------------------------------------- */
24
Miklos Szeredi2df1c042001-11-06 15:07:17 +000025/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000026struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000027
Miklos Szeredi24ed9452002-10-07 10:24:26 +000028/* Statfs structure used by FUSE */
29struct fuse_statfs {
30 long block_size;
31 long blocks;
32 long blocks_free;
33 long files;
34 long files_free;
35 long namelen;
36};
37
Miklos Szeredi2df1c042001-11-06 15:07:17 +000038/** Handle for a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000039typedef struct fuse_dirhandle *fuse_dirh_t;
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000040
Miklos Szeredi2df1c042001-11-06 15:07:17 +000041/** Function to add an entry in a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000042typedef int (*fuse_dirfil_t) (fuse_dirh_t, const char *, int type);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000043
Miklos Szeredi2df1c042001-11-06 15:07:17 +000044/**
45 * The file system operations:
46 *
47 * Most of these should work very similarly to the well known UNIX
48 * file system operations. Exceptions are:
49 *
Miklos Szeredi2df1c042001-11-06 15:07:17 +000050 * - All operations should return the negated error value (-errno) on
51 * error.
52 *
Miklos Szeredi05033042001-11-13 16:11:35 +000053 * - Getattr() doesn't need to fill in the following fields:
54 * st_ino
55 * st_dev
56 * st_blksize
57 *
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000058 * - readlink() should fill the buffer with a null terminated string. The
59 * buffer size argument includes the space for the terminating null
60 * character. If the linkname is too long to fit in the buffer, it should
61 * be truncated. The return value should be 0 for success.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000062 *
63 * - getdir() is the opendir(), readdir(), ..., closedir() sequence
64 * in one call. For each directory entry the filldir parameter should
65 * be called.
66 *
67 * - There is no create() operation, mknod() will be called for
68 * creation of all non directory, non symlink nodes.
69 *
70 * - open() should not return a filehandle, but 0 on success. No
71 * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
72 * passed to open(). Open should only check if the operation is
73 * permitted for the given flags.
74 *
75 * - read(), write() are not passed a filehandle, but rather a
76 * pathname. The offset of the read and write is passed as the last
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000077 * argument, like the pread() and pwrite() system calls.
Miklos Szeredic8ba2372002-12-10 12:26:00 +000078 *
79 * - release() is called when an open file has:
80 * 1) all file descriptors closed
81 * 2) all memory mappings unmapped
82 * This call need only be implemented if this information is required,
83 * otherwise set this function to NULL.
84 *
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000085 */
Miklos Szeredia181e612001-11-06 12:03:23 +000086struct fuse_operations {
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000087 int (*getattr) (const char *, struct stat *);
88 int (*readlink) (const char *, char *, size_t);
89 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
90 int (*mknod) (const char *, mode_t, dev_t);
91 int (*mkdir) (const char *, mode_t);
92 int (*unlink) (const char *);
93 int (*rmdir) (const char *);
94 int (*symlink) (const char *, const char *);
95 int (*rename) (const char *, const char *);
96 int (*link) (const char *, const char *);
97 int (*chmod) (const char *, mode_t);
98 int (*chown) (const char *, uid_t, gid_t);
99 int (*truncate) (const char *, off_t);
100 int (*utime) (const char *, struct utimbuf *);
101 int (*open) (const char *, int);
102 int (*read) (const char *, char *, size_t, off_t);
103 int (*write) (const char *, const char *, size_t, off_t);
Mark Glines85801bb2002-03-17 06:58:33 +0000104 int (*statfs) (struct fuse_statfs *);
Miklos Szeredi9478e862002-12-11 09:50:26 +0000105 int (*release) (const char *, int);
Miklos Szeredia181e612001-11-06 12:03:23 +0000106};
107
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000108/** Extra context that may be needed by some filesystems */
109struct fuse_context {
110 uid_t uid;
111 gid_t gid;
112};
113
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000114/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +0000115
Miklos Szeredic0938ea2001-11-07 12:35:06 +0000116/** Enable debuging output */
117#define FUSE_DEBUG (1 << 1)
118
Miklos Szerediacd4e062001-12-08 20:29:20 +0000119#ifdef __cplusplus
120extern "C" {
121#endif
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000122
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000123/*
Miklos Szeredi0e535082003-10-13 10:08:06 +0000124 * Main function of FUSE.
125 *
126 * This is for the lazy. This is all that has to be called from the
127 * main() function.
128 *
129 * This function does the following:
130 * - mounts the filesystem
131 * - installs signal handlers for INT, HUP, TERM and PIPE
132 * - registers an exit handler to unmount the filesystem on program exit
133 * - parses command line options (-d -s and -h)
134 * - creates a fuse handle
135 * - registers the operations
136 * - calls either the single-threaded or the multi-threaded event loop
137 *
138 * @param argc the argument counter passed to the main() function
139 * @param argv the argument vector passed to the main() function
140 * @param op the file system operation
141 */
142void fuse_main(int argc, char *argv[], const struct fuse_operations *op);
143
144/* ----------------------------------------------------------- *
145 * More detailed API *
146 * ----------------------------------------------------------- */
147
148/*
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000149 * Create a FUSE mountpoint
150 *
151 * Returns a control file descriptor suitable for passing to
152 * fuse_new()
153 *
154 * @param mountpoint the mount point path
Miklos Szeredid6e9f882002-10-25 11:40:14 +0000155 * @param args array of arguments to be passed to fusermount (NULL
156 * terminated). Can be NULL if no arguments are needed.
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000157 * @return the control file descriptor on success, -1 on failure
158 */
Miklos Szeredid6e9f882002-10-25 11:40:14 +0000159int fuse_mount(const char *mountpoint, const char *args[]);
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000160
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000161/*
162 * Umount a FUSE mountpoint
163 *
164 * @param mountpoint the mount point path
165 */
166void fuse_unmount(const char *mountpoint);
167
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000168/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000169 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000170 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000171 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000172 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000173 * @param op the operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000174 * @return the created FUSE handle
175 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000176struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000177
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000178/**
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000179 * Destroy the FUSE handle.
180 *
181 * The filesystem is not unmounted.
182 *
183 * @param f the FUSE handle
184 */
185void fuse_destroy(struct fuse *f);
186
187/**
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000188 * FUSE event loop.
189 *
190 * Requests from the kernel are processed, and the apropriate
191 * operations are called.
192 *
193 * @param f the FUSE handle
194 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000195void fuse_loop(struct fuse *f);
196
Miklos Szeredi0f48a262002-12-05 14:23:01 +0000197/**
198 * Exit from event loop
199 *
200 * @param f the FUSE handle
201 */
202void fuse_exit(struct fuse *f);
203
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000204/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000205 * FUSE event loop with multiple threads
206 *
207 * Requests from the kernel are processed, and the apropriate
208 * operations are called. Request are processed in parallel by
209 * distributing them between multiple threads.
210 *
211 * Calling this function requires the pthreads library to be linked to
212 * the application.
213 *
214 * @param f the FUSE handle
215 */
216void fuse_loop_mt(struct fuse *f);
217
218/**
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000219 * Get the current context
220 *
221 * The context is only valid for the duration of a filesystem
222 * operation, and thus must not be stored and used later.
223 *
224 * @param f the FUSE handle
225 * @return the context
226 */
227struct fuse_context *fuse_get_context(struct fuse *f);
228
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000229/* ----------------------------------------------------------- *
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000230 * Advanced API for event handling, don't worry about this... *
231 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000232
233struct fuse_cmd;
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000234typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000235struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000236void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000237void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
238
Miklos Szerediacd4e062001-12-08 20:29:20 +0000239#ifdef __cplusplus
240}
241#endif
242
243#endif /* _FUSE_H_ */