blob: b9e7962fd22e7cfe738e786a8caecb0e049ad280 [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
5 This program can be distributed under the terms of the GNU GPL.
6 See the file COPYING.
7*/
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
Roland Bauerschmidtf0cd8e42002-04-12 14:32:43 +000018#include <fusestat.h>
Miklos Szeredicc8c9752001-11-21 10:03:39 +000019/* ----------------------------------------------------------- *
20 * Basic FUSE API *
21 * ----------------------------------------------------------- */
22
Miklos Szeredi2df1c042001-11-06 15:07:17 +000023/** Handle for a FUSE filesystem */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000024struct fuse;
Miklos Szeredi2df1c042001-11-06 15:07:17 +000025
26/** Handle for a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000027typedef struct fuse_dirhandle *fuse_dirh_t;
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000028
Miklos Szeredi2df1c042001-11-06 15:07:17 +000029/** Function to add an entry in a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000030typedef int (*fuse_dirfil_t) (fuse_dirh_t, const char *, int type);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000031
Miklos Szeredi2df1c042001-11-06 15:07:17 +000032/**
33 * The file system operations:
34 *
35 * Most of these should work very similarly to the well known UNIX
36 * file system operations. Exceptions are:
37 *
Miklos Szeredi2df1c042001-11-06 15:07:17 +000038 * - All operations should return the negated error value (-errno) on
39 * error.
40 *
Miklos Szeredi05033042001-11-13 16:11:35 +000041 * - Getattr() doesn't need to fill in the following fields:
42 * st_ino
43 * st_dev
44 * st_blksize
45 *
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000046 * - readlink() should fill the buffer with a null terminated string. The
47 * buffer size argument includes the space for the terminating null
48 * character. If the linkname is too long to fit in the buffer, it should
49 * be truncated. The return value should be 0 for success.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000050 *
51 * - getdir() is the opendir(), readdir(), ..., closedir() sequence
52 * in one call. For each directory entry the filldir parameter should
53 * be called.
54 *
55 * - There is no create() operation, mknod() will be called for
56 * creation of all non directory, non symlink nodes.
57 *
58 * - open() should not return a filehandle, but 0 on success. No
59 * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
60 * passed to open(). Open should only check if the operation is
61 * permitted for the given flags.
62 *
63 * - read(), write() are not passed a filehandle, but rather a
64 * pathname. The offset of the read and write is passed as the last
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000065 * argument, like the pread() and pwrite() system calls.
66 */
Miklos Szeredia181e612001-11-06 12:03:23 +000067struct fuse_operations {
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000068 int (*getattr) (const char *, struct stat *);
69 int (*readlink) (const char *, char *, size_t);
70 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
71 int (*mknod) (const char *, mode_t, dev_t);
72 int (*mkdir) (const char *, mode_t);
73 int (*unlink) (const char *);
74 int (*rmdir) (const char *);
75 int (*symlink) (const char *, const char *);
76 int (*rename) (const char *, const char *);
77 int (*link) (const char *, const char *);
78 int (*chmod) (const char *, mode_t);
79 int (*chown) (const char *, uid_t, gid_t);
80 int (*truncate) (const char *, off_t);
81 int (*utime) (const char *, struct utimbuf *);
82 int (*open) (const char *, int);
83 int (*read) (const char *, char *, size_t, off_t);
84 int (*write) (const char *, const char *, size_t, off_t);
Mark Glines85801bb2002-03-17 06:58:33 +000085 int (*statfs) (struct fuse_statfs *);
Miklos Szeredia181e612001-11-06 12:03:23 +000086};
87
Miklos Szeredi2e50d432001-12-20 12:17:25 +000088/** Extra context that may be needed by some filesystems */
89struct fuse_context {
90 uid_t uid;
91 gid_t gid;
92};
93
Miklos Szeredi2df1c042001-11-06 15:07:17 +000094/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +000095
Miklos Szeredic0938ea2001-11-07 12:35:06 +000096/** Enable debuging output */
97#define FUSE_DEBUG (1 << 1)
98
Miklos Szerediacd4e062001-12-08 20:29:20 +000099#ifdef __cplusplus
100extern "C" {
101#endif
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000102
Miklos Szeredia4b0c772002-04-19 15:57:02 +0000103/*
104 * Create a FUSE mountpoint
105 *
106 * Returns a control file descriptor suitable for passing to
107 * fuse_new()
108 *
109 * @param mountpoint the mount point path
110 * @param mount arguments (passed to the fusermount program)
111 * @return the control file descriptor on success, -1 on failure
112 */
113int fuse_mount(const char *mountpoint, const char *mount_args);
114
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000115/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000116 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000117 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000118 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000119 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000120 * @param op the operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000121 * @return the created FUSE handle
122 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000123struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000124
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000125/**
126 * FUSE event loop.
127 *
128 * Requests from the kernel are processed, and the apropriate
129 * operations are called.
130 *
131 * @param f the FUSE handle
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000132 * @prarm op the file system operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000133 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000134void fuse_loop(struct fuse *f);
135
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000136/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000137 * FUSE event loop with multiple threads
138 *
139 * Requests from the kernel are processed, and the apropriate
140 * operations are called. Request are processed in parallel by
141 * distributing them between multiple threads.
142 *
143 * Calling this function requires the pthreads library to be linked to
144 * the application.
145 *
146 * @param f the FUSE handle
147 */
148void fuse_loop_mt(struct fuse *f);
149
150/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000151 * Destroy the FUSE handle.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000152 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000153 * The filesystem is not unmounted.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000154 *
155 * @param f the FUSE handle
156 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000157void fuse_destroy(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000158
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000159/**
160 * Get the current context
161 *
162 * The context is only valid for the duration of a filesystem
163 * operation, and thus must not be stored and used later.
164 *
165 * @param f the FUSE handle
166 * @return the context
167 */
168struct fuse_context *fuse_get_context(struct fuse *f);
169
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000170/* ----------------------------------------------------------- *
171 * Miscellaneous helper fuctions *
172 * ----------------------------------------------------------- */
173
174/*
175 * Main function of FUSE.
176 *
177 * This is for the lazy. This is all that has to be called from the
178 * main() function.
179 *
180 * This function does the following:
181 * - mounts the filesystem
182 * - installs signal handlers for INT, HUP, TERM and PIPE
183 * - registers an exit handler to unmount the filesystem on program exit
184 * - parses command line options (-d -s and -h)
185 * - creates a fuse handle
186 * - registers the operations
187 * - calls either the single-threaded or the multi-threaded event loop
188 *
189 * @param argc the argument counter passed to the main() function
190 * @param argv the argument vector passed to the main() function
191 * @prarm op the file system operation
192 */
193void fuse_main(int argc, char *argv[], const struct fuse_operations *op);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000194
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000195/* ----------------------------------------------------------- *
196 * Advanced API for event handling, don't worry about this... *
197 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000198
199struct fuse_cmd;
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000200typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000201struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000202void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000203void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
204
Miklos Szerediacd4e062001-12-08 20:29:20 +0000205#ifdef __cplusplus
206}
207#endif
208
209#endif /* _FUSE_H_ */