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 | |
Miklos Szeredi | 8b39a9f | 2002-10-25 12:41:16 +0000 | [diff] [blame] | 5 | This program can be distributed under the terms of the GNU LGPL. |
| 6 | See the file COPYING.LIB. |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 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 | |
Miklos Szeredi | 2f3d940 | 2003-12-15 12:11:33 +0000 | [diff] [blame] | 14 | /** Major version of FUSE library interface */ |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 15 | #define FUSE_MAJOR_VERSION 2 |
Miklos Szeredi | 2f3d940 | 2003-12-15 12:11:33 +0000 | [diff] [blame] | 16 | |
| 17 | /** Minor version of FUSE library interface */ |
| 18 | #define FUSE_MINOR_VERSION 1 |
| 19 | |
Miklos Szeredi | 5f05481 | 2002-12-03 18:45:21 +0000 | [diff] [blame] | 20 | /* Now and forever: this interface uses 64 bit off_t */ |
| 21 | #define _FILE_OFFSET_BITS 64 |
| 22 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 23 | #include <sys/types.h> |
| 24 | #include <sys/stat.h> |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 25 | #include <sys/statfs.h> |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 26 | #include <utime.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 27 | |
Miklos Szeredi | cc8c975 | 2001-11-21 10:03:39 +0000 | [diff] [blame] | 28 | /* ----------------------------------------------------------- * |
| 29 | * Basic FUSE API * |
| 30 | * ----------------------------------------------------------- */ |
| 31 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 32 | /** Handle for a FUSE filesystem */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 33 | struct fuse; |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 34 | |
| 35 | /** Handle for a getdir() operation */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 36 | typedef struct fuse_dirhandle *fuse_dirh_t; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 37 | |
Miklos Szeredi | f08ace0 | 2003-10-22 11:11:57 +0000 | [diff] [blame] | 38 | /** Function to add an entry in a getdir() operation |
| 39 | * |
| 40 | * @param h the handle passed to the getdir() operation |
| 41 | * @param name the file name of the directory entry |
| 42 | * @param type the file type (0 if unknown) see <dirent.h> |
| 43 | * @return 0 on success, -errno on error |
| 44 | */ |
| 45 | typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 46 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 47 | /** |
| 48 | * The file system operations: |
| 49 | * |
| 50 | * Most of these should work very similarly to the well known UNIX |
| 51 | * file system operations. Exceptions are: |
| 52 | * |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 53 | * - All operations should return the negated error value (-errno) on |
| 54 | * error. |
| 55 | * |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 56 | * - Getattr() doesn't need to fill in the following fields: |
| 57 | * st_ino |
| 58 | * st_dev |
| 59 | * st_blksize |
| 60 | * |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 61 | * - readlink() should fill the buffer with a null terminated string. The |
| 62 | * buffer size argument includes the space for the terminating null |
| 63 | * character. If the linkname is too long to fit in the buffer, it should |
| 64 | * be truncated. The return value should be 0 for success. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 65 | * |
| 66 | * - getdir() is the opendir(), readdir(), ..., closedir() sequence |
| 67 | * in one call. For each directory entry the filldir parameter should |
| 68 | * be called. |
| 69 | * |
| 70 | * - There is no create() operation, mknod() will be called for |
| 71 | * creation of all non directory, non symlink nodes. |
| 72 | * |
| 73 | * - open() should not return a filehandle, but 0 on success. No |
| 74 | * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be |
| 75 | * passed to open(). Open should only check if the operation is |
| 76 | * permitted for the given flags. |
| 77 | * |
| 78 | * - read(), write() are not passed a filehandle, but rather a |
| 79 | * pathname. The offset of the read and write is passed as the last |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 80 | * argument, like the pread() and pwrite() system calls. (NOTE: |
| 81 | * read() should always return the number of bytes requested, except |
| 82 | * at end of file) |
Miklos Szeredi | c8ba237 | 2002-12-10 12:26:00 +0000 | [diff] [blame] | 83 | * |
| 84 | * - release() is called when an open file has: |
| 85 | * 1) all file descriptors closed |
| 86 | * 2) all memory mappings unmapped |
| 87 | * This call need only be implemented if this information is required, |
| 88 | * otherwise set this function to NULL. |
Miklos Szeredi | 5e43f2c | 2003-12-12 14:06:41 +0000 | [diff] [blame] | 89 | * |
| 90 | * - fsync() has a boolean 'datasync' parameter which if TRUE then do |
| 91 | * an fdatasync() operation. |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 92 | */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 93 | struct fuse_operations { |
Miklos Szeredi | 3ed8423 | 2004-03-30 15:17:26 +0000 | [diff] [blame^] | 94 | int (*getattr) (const char *, struct stat *); |
| 95 | int (*readlink) (const char *, char *, size_t); |
| 96 | int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t); |
| 97 | int (*mknod) (const char *, mode_t, dev_t); |
| 98 | int (*mkdir) (const char *, mode_t); |
| 99 | int (*unlink) (const char *); |
| 100 | int (*rmdir) (const char *); |
| 101 | int (*symlink) (const char *, const char *); |
| 102 | int (*rename) (const char *, const char *); |
| 103 | int (*link) (const char *, const char *); |
| 104 | int (*chmod) (const char *, mode_t); |
| 105 | int (*chown) (const char *, uid_t, gid_t); |
| 106 | int (*truncate) (const char *, off_t); |
| 107 | int (*utime) (const char *, struct utimbuf *); |
| 108 | int (*open) (const char *, int); |
| 109 | int (*read) (const char *, char *, size_t, off_t); |
| 110 | int (*write) (const char *, const char *, size_t, off_t); |
| 111 | int (*statfs) (const char *, struct statfs *); |
| 112 | int (*release) (const char *, int); |
| 113 | int (*fsync) (const char *, int); |
| 114 | int (*setxattr) (const char *, const char *, const char *, size_t, int); |
| 115 | int (*getxattr) (const char *, const char *, char *, size_t); |
| 116 | int (*listxattr) (const char *, char *, size_t); |
| 117 | int (*removexattr) (const char *, const char *); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 120 | /** Extra context that may be needed by some filesystems */ |
| 121 | struct fuse_context { |
| 122 | uid_t uid; |
| 123 | gid_t gid; |
| 124 | }; |
| 125 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 126 | /* FUSE flags: */ |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 127 | |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 128 | /** Enable debuging output */ |
| 129 | #define FUSE_DEBUG (1 << 1) |
| 130 | |
Miklos Szeredi | acd4e06 | 2001-12-08 20:29:20 +0000 | [diff] [blame] | 131 | #ifdef __cplusplus |
| 132 | extern "C" { |
| 133 | #endif |
Miklos Szeredi | cc8c975 | 2001-11-21 10:03:39 +0000 | [diff] [blame] | 134 | |
Miklos Szeredi | a4b0c77 | 2002-04-19 15:57:02 +0000 | [diff] [blame] | 135 | /* |
Miklos Szeredi | 0e53508 | 2003-10-13 10:08:06 +0000 | [diff] [blame] | 136 | * Main function of FUSE. |
| 137 | * |
| 138 | * This is for the lazy. This is all that has to be called from the |
| 139 | * main() function. |
| 140 | * |
| 141 | * This function does the following: |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 142 | * - parses command line options (-d -s and -h) |
| 143 | * - passes all options after '--' to the fusermount program |
| 144 | * - mounts the filesystem by calling fusermount |
Miklos Szeredi | 0e53508 | 2003-10-13 10:08:06 +0000 | [diff] [blame] | 145 | * - installs signal handlers for INT, HUP, TERM and PIPE |
| 146 | * - registers an exit handler to unmount the filesystem on program exit |
Miklos Szeredi | 0e53508 | 2003-10-13 10:08:06 +0000 | [diff] [blame] | 147 | * - creates a fuse handle |
| 148 | * - registers the operations |
| 149 | * - calls either the single-threaded or the multi-threaded event loop |
| 150 | * |
| 151 | * @param argc the argument counter passed to the main() function |
| 152 | * @param argv the argument vector passed to the main() function |
| 153 | * @param op the file system operation |
| 154 | */ |
| 155 | void fuse_main(int argc, char *argv[], const struct fuse_operations *op); |
| 156 | |
Miklos Szeredi | 33c319c | 2004-02-25 09:19:29 +0000 | [diff] [blame] | 157 | /* |
| 158 | * Returns the fuse object created by fuse_main() |
| 159 | * |
| 160 | * This is useful when fuse_get_context() is used. |
| 161 | * |
| 162 | * @return the fuse object |
| 163 | */ |
| 164 | struct fuse *fuse_get(void); |
| 165 | |
Miklos Szeredi | 0e53508 | 2003-10-13 10:08:06 +0000 | [diff] [blame] | 166 | /* ----------------------------------------------------------- * |
| 167 | * More detailed API * |
| 168 | * ----------------------------------------------------------- */ |
| 169 | |
| 170 | /* |
Miklos Szeredi | a4b0c77 | 2002-04-19 15:57:02 +0000 | [diff] [blame] | 171 | * Create a FUSE mountpoint |
| 172 | * |
| 173 | * Returns a control file descriptor suitable for passing to |
| 174 | * fuse_new() |
| 175 | * |
| 176 | * @param mountpoint the mount point path |
Miklos Szeredi | d6e9f88 | 2002-10-25 11:40:14 +0000 | [diff] [blame] | 177 | * @param args array of arguments to be passed to fusermount (NULL |
| 178 | * terminated). Can be NULL if no arguments are needed. |
Miklos Szeredi | a4b0c77 | 2002-04-19 15:57:02 +0000 | [diff] [blame] | 179 | * @return the control file descriptor on success, -1 on failure |
| 180 | */ |
Miklos Szeredi | d6e9f88 | 2002-10-25 11:40:14 +0000 | [diff] [blame] | 181 | int fuse_mount(const char *mountpoint, const char *args[]); |
Miklos Szeredi | a4b0c77 | 2002-04-19 15:57:02 +0000 | [diff] [blame] | 182 | |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 183 | /* |
| 184 | * Umount a FUSE mountpoint |
| 185 | * |
| 186 | * @param mountpoint the mount point path |
| 187 | */ |
| 188 | void fuse_unmount(const char *mountpoint); |
| 189 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 190 | /** |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 191 | * Create a new FUSE filesystem. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 192 | * |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 193 | * @param fd the control file descriptor |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 194 | * @param flags any combination of the FUSE flags defined above, or 0 |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 195 | * @param op the operations |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 196 | * @return the created FUSE handle |
| 197 | */ |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 198 | 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] | 199 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 200 | /** |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 201 | * Destroy the FUSE handle. |
| 202 | * |
| 203 | * The filesystem is not unmounted. |
| 204 | * |
| 205 | * @param f the FUSE handle |
| 206 | */ |
| 207 | void fuse_destroy(struct fuse *f); |
| 208 | |
| 209 | /** |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 210 | * FUSE event loop. |
| 211 | * |
| 212 | * Requests from the kernel are processed, and the apropriate |
| 213 | * operations are called. |
| 214 | * |
| 215 | * @param f the FUSE handle |
| 216 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 217 | void fuse_loop(struct fuse *f); |
| 218 | |
Miklos Szeredi | 0f48a26 | 2002-12-05 14:23:01 +0000 | [diff] [blame] | 219 | /** |
| 220 | * Exit from event loop |
| 221 | * |
| 222 | * @param f the FUSE handle |
| 223 | */ |
| 224 | void fuse_exit(struct fuse *f); |
| 225 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 226 | /** |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 227 | * FUSE event loop with multiple threads |
| 228 | * |
| 229 | * Requests from the kernel are processed, and the apropriate |
| 230 | * operations are called. Request are processed in parallel by |
| 231 | * distributing them between multiple threads. |
| 232 | * |
| 233 | * Calling this function requires the pthreads library to be linked to |
| 234 | * the application. |
| 235 | * |
| 236 | * @param f the FUSE handle |
| 237 | */ |
| 238 | void fuse_loop_mt(struct fuse *f); |
| 239 | |
| 240 | /** |
Miklos Szeredi | 2e50d43 | 2001-12-20 12:17:25 +0000 | [diff] [blame] | 241 | * Get the current context |
| 242 | * |
| 243 | * The context is only valid for the duration of a filesystem |
| 244 | * operation, and thus must not be stored and used later. |
| 245 | * |
| 246 | * @param f the FUSE handle |
| 247 | * @return the context |
| 248 | */ |
| 249 | struct fuse_context *fuse_get_context(struct fuse *f); |
| 250 | |
Miklos Szeredi | cc8c975 | 2001-11-21 10:03:39 +0000 | [diff] [blame] | 251 | /* ----------------------------------------------------------- * |
Miklos Szeredi | 680a69a | 2001-11-16 13:31:14 +0000 | [diff] [blame] | 252 | * Advanced API for event handling, don't worry about this... * |
| 253 | * ----------------------------------------------------------- */ |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 254 | |
| 255 | struct fuse_cmd; |
Miklos Szeredi | f830a7f | 2001-11-16 17:46:45 +0000 | [diff] [blame] | 256 | typedef void (*fuse_processor_t)(struct fuse *, struct fuse_cmd *, void *); |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 257 | struct fuse_cmd *__fuse_read_cmd(struct fuse *f); |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame] | 258 | void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd); |
Miklos Szeredi | f830a7f | 2001-11-16 17:46:45 +0000 | [diff] [blame] | 259 | void __fuse_loop_mt(struct fuse *f, fuse_processor_t proc, void *data); |
| 260 | |
Miklos Szeredi | acd4e06 | 2001-12-08 20:29:20 +0000 | [diff] [blame] | 261 | #ifdef __cplusplus |
| 262 | } |
| 263 | #endif |
| 264 | |
| 265 | #endif /* _FUSE_H_ */ |