blob: 700569c7e353736fa21378e88db1ae052ed3fd26 [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 Szeredi2df1c042001-11-06 15:07:17 +000086/* FUSE flags: */
Miklos Szeredic0938ea2001-11-07 12:35:06 +000087
Miklos Szeredic0938ea2001-11-07 12:35:06 +000088/** Enable debuging output */
89#define FUSE_DEBUG (1 << 1)
90
Miklos Szerediacd4e062001-12-08 20:29:20 +000091#ifdef __cplusplus
92extern "C" {
93#endif
Miklos Szeredicc8c9752001-11-21 10:03:39 +000094
Miklos Szeredi2df1c042001-11-06 15:07:17 +000095/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +000096 * Create a new FUSE filesystem.
Miklos Szeredi2df1c042001-11-06 15:07:17 +000097 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +000098 * @param fd the control file descriptor
Miklos Szeredi2df1c042001-11-06 15:07:17 +000099 * @param flags any combination of the FUSE flags defined above, or 0
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000100 * @return the created FUSE handle
101 */
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000102struct fuse *fuse_new(int fd, int flags);
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000103
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000104/**
105 * Set the filesystem operations.
106 *
107 * Operations which are initialised to NULL will return ENOSYS to the
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000108 * calling process.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000109 *
110 * @param f the FUSE handle
111 * @param op the operations
112 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000113void fuse_set_operations(struct fuse *f, const struct fuse_operations *op);
114
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000115/**
116 * FUSE event loop.
117 *
118 * Requests from the kernel are processed, and the apropriate
119 * operations are called.
120 *
121 * @param f the FUSE handle
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000122 * @prarm op the file system operations
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000123 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000124void fuse_loop(struct fuse *f);
125
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000126/**
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000127 * FUSE event loop with multiple threads
128 *
129 * Requests from the kernel are processed, and the apropriate
130 * operations are called. Request are processed in parallel by
131 * distributing them between multiple threads.
132 *
133 * Calling this function requires the pthreads library to be linked to
134 * the application.
135 *
136 * @param f the FUSE handle
137 */
138void fuse_loop_mt(struct fuse *f);
139
140/**
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000141 * Destroy the FUSE handle.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000142 *
Miklos Szeredi8cffdb92001-11-09 14:49:18 +0000143 * The filesystem is not unmounted.
Miklos Szeredi2df1c042001-11-06 15:07:17 +0000144 *
145 * @param f the FUSE handle
146 */
Miklos Szeredi85c74fc2001-10-28 19:44:14 +0000147void fuse_destroy(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000148
Miklos Szeredicc8c9752001-11-21 10:03:39 +0000149/* ----------------------------------------------------------- *
150 * Miscellaneous helper fuctions *
151 * ----------------------------------------------------------- */
152
153/*
154 * Main function of FUSE.
155 *
156 * This is for the lazy. This is all that has to be called from the
157 * main() function.
158 *
159 * This function does the following:
160 * - mounts the filesystem
161 * - installs signal handlers for INT, HUP, TERM and PIPE
162 * - registers an exit handler to unmount the filesystem on program exit
163 * - parses command line options (-d -s and -h)
164 * - creates a fuse handle
165 * - registers the operations
166 * - calls either the single-threaded or the multi-threaded event loop
167 *
168 * @param argc the argument counter passed to the main() function
169 * @param argv the argument vector passed to the main() function
170 * @prarm op the file system operation
171 */
172void fuse_main(int argc, char *argv[], const struct fuse_operations *op);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000173
Miklos Szeredi680a69a2001-11-16 13:31:14 +0000174/* ----------------------------------------------------------- *
175 * Advanced API for event handling, don't worry about this... *
176 * ----------------------------------------------------------- */
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000177
178struct fuse_cmd;
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000179typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000180struct fuse_cmd *__fuse_read_cmd(struct fuse *f);
Miklos Szeredifff56ab2001-11-16 10:12:59 +0000181void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd);
Miklos Szeredif830a7f2001-11-16 17:46:45 +0000182void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data);
183
Miklos Szerediacd4e062001-12-08 20:29:20 +0000184#ifdef __cplusplus
185}
186#endif
187
188#endif /* _FUSE_H_ */