blob: c4cfbc4083cfbe877e2c19e37541354cdafa483e [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
14#include <sys/types.h>
15#include <sys/stat.h>
Miklos Szeredi5e183482001-10-31 14:52:35 +000016#include <utime.h>
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000017
Miklos Szeredicc8c9752001-11-21 10:03:39 +000018/* ----------------------------------------------------------- *
19 * Basic FUSE API *
20 * ----------------------------------------------------------- */
21
Miklos Szeredi2df1c042001-11-06 15:07:17 +000022/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000023struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000024
Miklos Szeredi24ed9452002-10-07 10:24:26 +000025/* Statfs structure used by FUSE */
26struct fuse_statfs {
27 long block_size;
28 long blocks;
29 long blocks_free;
30 long files;
31 long files_free;
32 long namelen;
33};
34
Miklos Szeredi2df1c042001-11-06 15:07:17 +000035/** 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 Szeredi2df1c042001-11-06 15:07:17 +000038/** Function to add an entry in a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000039typedef int (*fuse_dirfil_t) (fuse_dirh_t, const char *, int type);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000040
Miklos Szeredi2df1c042001-11-06 15:07:17 +000041/**
42 * The file system operations:
43 *
44 * Most of these should work very similarly to the well known UNIX
45 * file system operations. Exceptions are:
46 *
Miklos Szeredi2df1c042001-11-06 15:07:17 +000047 * - All operations should return the negated error value (-errno) on
48 * error.
49 *
Miklos Szeredi05033042001-11-13 16:11:35 +000050 * - Getattr() doesn't need to fill in the following fields:
51 * st_ino
52 * st_dev
53 * st_blksize
54 *
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000055 * - readlink() should fill the buffer with a null terminated string. The
56 * buffer size argument includes the space for the terminating null
57 * character. If the linkname is too long to fit in the buffer, it should
58 * be truncated. The return value should be 0 for success.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000059 *
60 * - getdir() is the opendir(), readdir(), ..., closedir() sequence
61 * in one call. For each directory entry the filldir parameter should
62 * be called.
63 *
64 * - There is no create() operation, mknod() will be called for
65 * creation of all non directory, non symlink nodes.
66 *
67 * - open() should not return a filehandle, but 0 on success. No
68 * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
69 * passed to open(). Open should only check if the operation is
70 * permitted for the given flags.
71 *
72 * - read(), write() are not passed a filehandle, but rather a
73 * pathname. The offset of the read and write is passed as the last
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000074 * argument, like the pread() and pwrite() system calls.
75 */
Miklos Szeredia181e612001-11-06 12:03:23 +000076struct fuse_operations {
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000077 int (*getattr) (const char *, struct stat *);
78 int (*readlink) (const char *, char *, size_t);
79 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
80 int (*mknod) (const char *, mode_t, dev_t);
81 int (*mkdir) (const char *, mode_t);
82 int (*unlink) (const char *);
83 int (*rmdir) (const char *);
84 int (*symlink) (const char *, const char *);
85 int (*rename) (const char *, const char *);
86 int (*link) (const char *, const char *);
87 int (*chmod) (const char *, mode_t);
88 int (*chown) (const char *, uid_t, gid_t);
89 int (*truncate) (const char *, off_t);
90 int (*utime) (const char *, struct utimbuf *);
91 int (*open) (const char *, int);
92 int (*read) (const char *, char *, size_t, off_t);
93 int (*write) (const char *, const char *, size_t, off_t);
Mark Glines85801bb2002-03-17 06:58:33 +000094 int (*statfs) (struct fuse_statfs *);
Miklos Szeredia181e612001-11-06 12:03:23 +000095};
96
Miklos Szeredi2e50d432001-12-20 12:17:25 +000097/** Extra context that may be needed by some filesystems */
98struct fuse_context {
99 uid_t uid;
100 gid_t gid;
101};
102
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000103/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +0000104
Miklos Szeredic0938ea2001-11-07 12:35:06 +0000105/** Enable debuging output */
106#define FUSE_DEBUG (1 << 1)
107
Miklos Szerediacd4e062001-12-08 20:29:20 +0000108#ifdef __cplusplus
109extern "C" {
110#endif
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000111
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000112/*
113 * Create a FUSE mountpoint
114 *
115 * Returns a control file descriptor suitable for passing to
116 * fuse_new()
117 *
118 * @param mountpoint the mount point path
Miklos Szeredid6e9f882002-10-25 11:40:14 +0000119 * @param args array of arguments to be passed to fusermount (NULL
120 * terminated). Can be NULL if no arguments are needed.
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000121 * @return the control file descriptor on success, -1 on failure
122 */
Miklos Szeredid6e9f882002-10-25 11:40:14 +0000123int fuse_mount(const char *mountpoint, const char *args[]);
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000124
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000125/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000126 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000127 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000128 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000129 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000130 * @param op the operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000131 * @return the created FUSE handle
132 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000133struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000134
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000135/**
136 * FUSE event loop.
137 *
138 * Requests from the kernel are processed, and the apropriate
139 * operations are called.
140 *
141 * @param f the FUSE handle
142 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000143void fuse_loop(struct fuse *f);
144
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000145/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000146 * FUSE event loop with multiple threads
147 *
148 * Requests from the kernel are processed, and the apropriate
149 * operations are called. Request are processed in parallel by
150 * distributing them between multiple threads.
151 *
152 * Calling this function requires the pthreads library to be linked to
153 * the application.
154 *
155 * @param f the FUSE handle
156 */
157void fuse_loop_mt(struct fuse *f);
158
159/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000160 * Destroy the FUSE handle.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000161 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000162 * The filesystem is not unmounted.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000163 *
164 * @param f the FUSE handle
165 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000166void fuse_destroy(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000167
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000168/**
169 * Get the current context
170 *
171 * The context is only valid for the duration of a filesystem
172 * operation, and thus must not be stored and used later.
173 *
174 * @param f the FUSE handle
175 * @return the context
176 */
177struct fuse_context *fuse_get_context(struct fuse *f);
178
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000179/* ----------------------------------------------------------- *
180 * Miscellaneous helper fuctions *
181 * ----------------------------------------------------------- */
182
183/*
184 * Main function of FUSE.
185 *
186 * This is for the lazy. This is all that has to be called from the
187 * main() function.
188 *
189 * This function does the following:
190 * - mounts the filesystem
191 * - installs signal handlers for INT, HUP, TERM and PIPE
192 * - registers an exit handler to unmount the filesystem on program exit
193 * - parses command line options (-d -s and -h)
194 * - creates a fuse handle
195 * - registers the operations
196 * - calls either the single-threaded or the multi-threaded event loop
197 *
198 * @param argc the argument counter passed to the main() function
199 * @param argv the argument vector passed to the main() function
Miklos Szeredif4736e72002-05-29 07:06:09 +0000200 * @param op the file system operation
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000201 */
202void fuse_main(int argc, char *argv[], const struct fuse_operations *op);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000203
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000204/* ----------------------------------------------------------- *
205 * Advanced API for event handling, don't worry about this... *
206 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000207
208struct fuse_cmd;
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000209typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000210struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000211void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000212void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
213
Miklos Szerediacd4e062001-12-08 20:29:20 +0000214#ifdef __cplusplus
215}
216#endif
217
218#endif /* _FUSE_H_ */