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 | |
| 9 | /* This file defines the library interface of FUSE */ |
| 10 | |
| 11 | #include <sys/types.h> |
| 12 | #include <sys/stat.h> |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 13 | #include <utime.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 14 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 15 | /** Handle for a FUSE filesystem */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 16 | struct fuse; |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 17 | |
| 18 | /** Handle for a getdir() operation */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 19 | typedef struct fuse_dirhandle *fuse_dirh_t; |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 20 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 21 | /** Function to add an entry in a getdir() operation */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 22 | typedef int (*fuse_dirfil_t) (fuse_dirh_t, const char *, int type); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 23 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 24 | /** |
| 25 | * The file system operations: |
| 26 | * |
| 27 | * Most of these should work very similarly to the well known UNIX |
| 28 | * file system operations. Exceptions are: |
| 29 | * |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 30 | * - All operations should return the negated error value (-errno) on |
| 31 | * error. |
| 32 | * |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 33 | * - Getattr() doesn't need to fill in the following fields: |
| 34 | * st_ino |
| 35 | * st_dev |
| 36 | * st_blksize |
| 37 | * |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 38 | * - readlink() should fill the buffer with a null terminated string. The |
| 39 | * buffer size argument includes the space for the terminating null |
| 40 | * character. If the linkname is too long to fit in the buffer, it should |
| 41 | * be truncated. The return value should be 0 for success. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 42 | * |
| 43 | * - getdir() is the opendir(), readdir(), ..., closedir() sequence |
| 44 | * in one call. For each directory entry the filldir parameter should |
| 45 | * be called. |
| 46 | * |
| 47 | * - There is no create() operation, mknod() will be called for |
| 48 | * creation of all non directory, non symlink nodes. |
| 49 | * |
| 50 | * - open() should not return a filehandle, but 0 on success. No |
| 51 | * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be |
| 52 | * passed to open(). Open should only check if the operation is |
| 53 | * permitted for the given flags. |
| 54 | * |
| 55 | * - read(), write() are not passed a filehandle, but rather a |
| 56 | * 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] | 57 | * argument, like the pread() and pwrite() system calls. |
| 58 | */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 59 | struct fuse_operations { |
Miklos Szeredi | 0a7077f | 2001-11-11 18:20:17 +0000 | [diff] [blame] | 60 | int (*getattr) (const char *, struct stat *); |
| 61 | int (*readlink) (const char *, char *, size_t); |
| 62 | int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t); |
| 63 | int (*mknod) (const char *, mode_t, dev_t); |
| 64 | int (*mkdir) (const char *, mode_t); |
| 65 | int (*unlink) (const char *); |
| 66 | int (*rmdir) (const char *); |
| 67 | int (*symlink) (const char *, const char *); |
| 68 | int (*rename) (const char *, const char *); |
| 69 | int (*link) (const char *, const char *); |
| 70 | int (*chmod) (const char *, mode_t); |
| 71 | int (*chown) (const char *, uid_t, gid_t); |
| 72 | int (*truncate) (const char *, off_t); |
| 73 | int (*utime) (const char *, struct utimbuf *); |
| 74 | int (*open) (const char *, int); |
| 75 | int (*read) (const char *, char *, size_t, off_t); |
| 76 | int (*write) (const char *, const char *, size_t, off_t); |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 79 | /* FUSE flags: */ |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 80 | |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 81 | /** Enable debuging output */ |
| 82 | #define FUSE_DEBUG (1 << 1) |
| 83 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 84 | /** |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 85 | * Create a new FUSE filesystem. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 86 | * |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 87 | * @param fd the control file descriptor |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 88 | * @param flags any combination of the FUSE flags defined above, or 0 |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 89 | * @return the created FUSE handle |
| 90 | */ |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 91 | struct fuse *fuse_new(int fd, int flags); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 92 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 93 | /** |
| 94 | * Set the filesystem operations. |
| 95 | * |
| 96 | * Operations which are initialised to NULL will return ENOSYS to the |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 97 | * calling process. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 98 | * |
| 99 | * @param f the FUSE handle |
| 100 | * @param op the operations |
| 101 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 102 | void fuse_set_operations(struct fuse *f, const struct fuse_operations *op); |
| 103 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 104 | /** |
| 105 | * FUSE event loop. |
| 106 | * |
| 107 | * Requests from the kernel are processed, and the apropriate |
| 108 | * operations are called. |
| 109 | * |
| 110 | * @param f the FUSE handle |
| 111 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 112 | void fuse_loop(struct fuse *f); |
| 113 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 114 | /** |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame^] | 115 | * FUSE event loop with multiple threads |
| 116 | * |
| 117 | * Requests from the kernel are processed, and the apropriate |
| 118 | * operations are called. Request are processed in parallel by |
| 119 | * distributing them between multiple threads. |
| 120 | * |
| 121 | * Calling this function requires the pthreads library to be linked to |
| 122 | * the application. |
| 123 | * |
| 124 | * @param f the FUSE handle |
| 125 | */ |
| 126 | void fuse_loop_mt(struct fuse *f); |
| 127 | |
| 128 | /** |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 129 | * Destroy the FUSE handle. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 130 | * |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 131 | * The filesystem is not unmounted. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 132 | * |
| 133 | * @param f the FUSE handle |
| 134 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 135 | void fuse_destroy(struct fuse *f); |
Miklos Szeredi | fff56ab | 2001-11-16 10:12:59 +0000 | [diff] [blame^] | 136 | |
| 137 | |
| 138 | /* --------------------------------------------------- * |
| 139 | * Advanced API, usually you need not bother with this * |
| 140 | * --------------------------------------------------- */ |
| 141 | |
| 142 | struct fuse_cmd; |
| 143 | |
| 144 | struct fuse_cmd *__fuse_read_cmd(struct fuse *f); |
| 145 | |
| 146 | void __fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd); |