Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 1 | /* |
| 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 Szeredi | acd4e06 | 2001-12-08 20:29:20 +0000 | [diff] [blame] | 9 | #ifndef _FUSE_H_ |
| 10 | #define _FUSE_H_ |
| 11 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 12 | /* This file defines the library interface of FUSE */ |
| 13 | |
| 14 | #include <sys/types.h> |
| 15 | #include <sys/stat.h> |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 16 | #include <utime.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 17 | |
Miklos Szeredi | cc8c975 | 2001-11-21 10:03:39 +0000 | [diff] [blame] | 18 | /* ----------------------------------------------------------- * |
| 19 | * Basic FUSE API * |
| 20 | * ----------------------------------------------------------- */ |
| 21 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 22 | /** Handle for a FUSE filesystem */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 23 | struct fuse; |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 24 | |
| 25 | /** Handle for a getdir() operation */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 26 | typedef struct fuse_dirhandle *fuse_dirh_t; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 27 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 28 | /** Function to add an entry in a getdir() operation */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 29 | typedef int (*fuse_dirfil_t) (fuse_dirh_t, const char *, int type); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 30 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 31 | /** |
| 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 Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 37 | * - All operations should return the negated error value (-errno) on |
| 38 | * error. |
| 39 | * |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 40 | * - Getattr() doesn't need to fill in the following fields: |
| 41 | * st_ino |
| 42 | * st_dev |
| 43 | * st_blksize |
| 44 | * |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 45 | * - 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 Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 49 | * |
| 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 Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 64 | * argument, like the pread() and pwrite() system calls. |
| 65 | */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 66 | struct fuse_operations { |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 67 | 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 Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame^] | 86 | /** Extra context that may be needed by some filesystems */ |
| 87 | struct fuse_context { |
| 88 | uid_t uid; |
| 89 | gid_t gid; |
| 90 | }; |
| 91 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 92 | /* FUSE flags: */ |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 93 | |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 94 | /** Enable debuging output */ |
| 95 | #define FUSE_DEBUG (1 << 1) |
| 96 | |
Miklos Szeredi | acd4e06 | 2001-12-08 20:29:20 +0000 | [diff] [blame] | 97 | #ifdef __cplusplus |
| 98 | extern "C" { |
| 99 | #endif |
Miklos Szeredi | cc8c975 | 2001-11-21 10:03:39 +0000 | [diff] [blame] | 100 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 101 | /** |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 102 | * Create a new FUSE filesystem. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 103 | * |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 104 | * @param fd the control file descriptor |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 105 | * @param flags any combination of the FUSE flags defined above, or 0 |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame^] | 106 | * @param op the operations |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 107 | * @return the created FUSE handle |
| 108 | */ |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame^] | 109 | struct fuse *fuse_new(int fd, int flags, const struct fuse_operations *op); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 110 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 111 | /** |
| 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 Szeredi | cc8c975 | 2001-11-21 10:03:39 +0000 | [diff] [blame] | 118 | * @prarm op the file system operations |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 119 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 120 | void fuse_loop(struct fuse *f); |
| 121 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 122 | /** |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 123 | * 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 | */ |
| 134 | void fuse_loop_mt(struct fuse *f); |
| 135 | |
| 136 | /** |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 137 | * Destroy the FUSE handle. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 138 | * |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 139 | * The filesystem is not unmounted. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 140 | * |
| 141 | * @param f the FUSE handle |
| 142 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 143 | void fuse_destroy(struct fuse *f); |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 144 | |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame^] | 145 | /** |
| 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 | */ |
| 154 | struct fuse_context *fuse_get_context(struct fuse *f); |
| 155 | |
Miklos Szeredi | cc8c975 | 2001-11-21 10:03:39 +0000 | [diff] [blame] | 156 | /* ----------------------------------------------------------- * |
| 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 | */ |
| 179 | void fuse_main(int argc, char *argv[], const struct fuse_operations *op); |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 180 | |
Miklos Szeredi | 680a69a | 2001-11-16 13:31:14 +0000 | [diff] [blame] | 181 | /* ----------------------------------------------------------- * |
| 182 | * Advanced API for event handling, don't worry about this... * |
| 183 | * ----------------------------------------------------------- */ |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 184 | |
| 185 | struct fuse_cmd; |
Miklos Szeredi | f830a7f | 2001-11-16 17:46:45 +0000 | [diff] [blame] | 186 | typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *); |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 187 | struct fuse_cmd *__fuse_read_cmd(struct fuse *f); |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 188 | void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd); |
Miklos Szeredi | f830a7f | 2001-11-16 17:46:45 +0000 | [diff] [blame] | 189 | void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data); |
| 190 | |
Miklos Szeredi | acd4e06 | 2001-12-08 20:29:20 +0000 | [diff] [blame] | 191 | #ifdef __cplusplus |
| 192 | } |
| 193 | #endif |
| 194 | |
| 195 | #endif /* _FUSE_H_ */ |