blob: bafa1827dbbc269f96dbd8eb2180696734ad601b [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
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
25/** Handle for a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000026typedef struct fuse_dirhandle *fuse_dirh_t;
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000027
Miklos Szeredi2df1c042001-11-06 15:07:17 +000028/** Function to add an entry in a getdir() operation */
Miklos Szeredia181e612001-11-06 12:03:23 +000029typedef int (*fuse_dirfil_t) (fuse_dirh_t, const char *, int type);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +000030
Miklos Szeredi2df1c042001-11-06 15:07:17 +000031/**
32 * The file system operations:
33 *
34 * Most of these should work very similarly to the well known UNIX
35 * file system operations. Exceptions are:
36 *
Miklos Szeredi2df1c042001-11-06 15:07:17 +000037 * - All operations should return the negated error value (-errno) on
38 * error.
39 *
Miklos Szeredi05033042001-11-13 16:11:35 +000040 * - Getattr() doesn't need to fill in the following fields:
41 * st_ino
42 * st_dev
43 * st_blksize
44 *
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000045 * - readlink() should fill the buffer with a null terminated string. The
46 * buffer size argument includes the space for the terminating null
47 * character. If the linkname is too long to fit in the buffer, it should
48 * be truncated. The return value should be 0 for success.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000049 *
50 * - getdir() is the opendir(), readdir(), ..., closedir() sequence
51 * in one call. For each directory entry the filldir parameter should
52 * be called.
53 *
54 * - There is no create() operation, mknod() will be called for
55 * creation of all non directory, non symlink nodes.
56 *
57 * - open() should not return a filehandle, but 0 on success. No
58 * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be
59 * passed to open(). Open should only check if the operation is
60 * permitted for the given flags.
61 *
62 * - read(), write() are not passed a filehandle, but rather a
63 * pathname. The offset of the read and write is passed as the last
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000064 * argument, like the pread() and pwrite() system calls.
65 */
Miklos Szeredia181e612001-11-06 12:03:23 +000066struct fuse_operations {
Miklos Szeredi0a7077f2001-11-11 18:20:17 +000067 int (*getattr) (const char *, struct stat *);
68 int (*readlink) (const char *, char *, size_t);
69 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
70 int (*mknod) (const char *, mode_t, dev_t);
71 int (*mkdir) (const char *, mode_t);
72 int (*unlink) (const char *);
73 int (*rmdir) (const char *);
74 int (*symlink) (const char *, const char *);
75 int (*rename) (const char *, const char *);
76 int (*link) (const char *, const char *);
77 int (*chmod) (const char *, mode_t);
78 int (*chown) (const char *, uid_t, gid_t);
79 int (*truncate) (const char *, off_t);
80 int (*utime) (const char *, struct utimbuf *);
81 int (*open) (const char *, int);
82 int (*read) (const char *, char *, size_t, off_t);
83 int (*write) (const char *, const char *, size_t, off_t);
Miklos Szeredia181e612001-11-06 12:03:23 +000084};
85
Miklos Szeredi2e50d432001-12-20 12:17:25 +000086/** Extra context that may be needed by some filesystems */
87struct fuse_context {
88 uid_t uid;
89 gid_t gid;
90};
91
Miklos Szeredi2df1c042001-11-06 15:07:17 +000092/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +000093
Miklos Szeredic0938ea2001-11-07 12:35:06 +000094/** Enable debuging output */
95#define FUSE_DEBUG (1 << 1)
96
Miklos Szerediacd4e062001-12-08 20:29:20 +000097#ifdef __cplusplus
98extern "C" {
99#endif
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000100
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000101/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000102 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000103 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000104 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000105 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000106 * @param op the operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000107 * @return the created FUSE handle
108 */
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000109struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000110
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000111/**
112 * FUSE event loop.
113 *
114 * Requests from the kernel are processed, and the apropriate
115 * operations are called.
116 *
117 * @param f the FUSE handle
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000118 * @prarm op the file system operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000119 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000120void fuse_loop(struct fuse *f);
121
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000122/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000123 * FUSE event loop with multiple threads
124 *
125 * Requests from the kernel are processed, and the apropriate
126 * operations are called. Request are processed in parallel by
127 * distributing them between multiple threads.
128 *
129 * Calling this function requires the pthreads library to be linked to
130 * the application.
131 *
132 * @param f the FUSE handle
133 */
134void fuse_loop_mt(struct fuse *f);
135
136/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000137 * Destroy the FUSE handle.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000138 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000139 * The filesystem is not unmounted.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000140 *
141 * @param f the FUSE handle
142 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000143void fuse_destroy(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000144
Miklos Szeredi2e50d432001-12-20 12:17:25 +0000145/**
146 * Get the current context
147 *
148 * The context is only valid for the duration of a filesystem
149 * operation, and thus must not be stored and used later.
150 *
151 * @param f the FUSE handle
152 * @return the context
153 */
154struct fuse_context *fuse_get_context(struct fuse *f);
155
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000156/* ----------------------------------------------------------- *
157 * Miscellaneous helper fuctions *
158 * ----------------------------------------------------------- */
159
160/*
161 * Main function of FUSE.
162 *
163 * This is for the lazy. This is all that has to be called from the
164 * main() function.
165 *
166 * This function does the following:
167 * - mounts the filesystem
168 * - installs signal handlers for INT, HUP, TERM and PIPE
169 * - registers an exit handler to unmount the filesystem on program exit
170 * - parses command line options (-d -s and -h)
171 * - creates a fuse handle
172 * - registers the operations
173 * - calls either the single-threaded or the multi-threaded event loop
174 *
175 * @param argc the argument counter passed to the main() function
176 * @param argv the argument vector passed to the main() function
177 * @prarm op the file system operation
178 */
179void fuse_main(int argc, char *argv[], const struct fuse_operations *op);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000180
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000181/* ----------------------------------------------------------- *
182 * Advanced API for event handling, don't worry about this... *
183 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000184
185struct fuse_cmd;
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000186typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000187struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000188void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000189void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
190
Miklos Szerediacd4e062001-12-08 20:29:20 +0000191#ifdef __cplusplus
192}
193#endif
194
195#endif /* _FUSE_H_ */