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 | /** Credentials for an operation, these are determined by the fsuid |
| 25 | and fsgid of the calling process */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 26 | struct fuse_cred { |
| 27 | uid_t uid; |
| 28 | gid_t gid; |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 29 | /* FIXME: supplementary groups should also be included */ |
Miklos Szeredi | 552c281 | 2001-11-08 14:56:53 +0000 | [diff] [blame] | 30 | /* (And capabilities???) */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 31 | }; |
| 32 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 33 | /** |
| 34 | * The file system operations: |
| 35 | * |
| 36 | * Most of these should work very similarly to the well known UNIX |
| 37 | * file system operations. Exceptions are: |
| 38 | * |
| 39 | * - All operations get a fuse_cred structure by which the filesystem |
| 40 | * implementation can check, whether the operation is permitted or |
| 41 | * not. |
| 42 | * |
| 43 | * - All operations should return the negated error value (-errno) on |
| 44 | * error. |
| 45 | * |
| 46 | * - readlink() should fill the buffer with a null terminated string. |
| 47 | * The buffer size argument includes the space for the terminating |
| 48 | * null character. If the linkname is too long to fit in the buffer, |
| 49 | * it should be truncated. The return value should be 0 for success. |
| 50 | * |
| 51 | * - getdir() is the opendir(), readdir(), ..., closedir() sequence |
| 52 | * in one call. For each directory entry the filldir parameter should |
| 53 | * be called. |
| 54 | * |
| 55 | * - There is no create() operation, mknod() will be called for |
| 56 | * creation of all non directory, non symlink nodes. |
| 57 | * |
| 58 | * - open() should not return a filehandle, but 0 on success. No |
| 59 | * creation, or trunctation flags (O_CREAT, O_EXCL, O_TRUNC) will be |
| 60 | * passed to open(). Open should only check if the operation is |
| 61 | * permitted for the given flags. |
| 62 | * |
| 63 | * - read(), write() are not passed a filehandle, but rather a |
| 64 | * pathname. The offset of the read and write is passed as the last |
| 65 | * argument, like the pread() and pwrite() system calls. */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 66 | struct fuse_operations { |
| 67 | int (*getattr) (struct fuse_cred *, const char *, struct stat *); |
| 68 | int (*readlink) (struct fuse_cred *, const char *, char *, size_t); |
| 69 | int (*getdir) (struct fuse_cred *, const char *, fuse_dirh_t, fuse_dirfil_t); |
| 70 | int (*mknod) (struct fuse_cred *, const char *, mode_t, dev_t); |
| 71 | int (*mkdir) (struct fuse_cred *, const char *, mode_t); |
| 72 | int (*unlink) (struct fuse_cred *, const char *); |
| 73 | int (*rmdir) (struct fuse_cred *, const char *); |
| 74 | int (*symlink) (struct fuse_cred *, const char *, const char *); |
| 75 | int (*rename) (struct fuse_cred *, const char *, const char *); |
| 76 | int (*link) (struct fuse_cred *, const char *, const char *); |
| 77 | int (*chmod) (struct fuse_cred *, const char *, mode_t); |
| 78 | int (*chown) (struct fuse_cred *, const char *, uid_t, gid_t); |
| 79 | int (*truncate) (struct fuse_cred *, const char *, off_t); |
| 80 | int (*utime) (struct fuse_cred *, const char *, struct utimbuf *); |
| 81 | int (*open) (struct fuse_cred *, const char *, int); |
| 82 | int (*read) (struct fuse_cred *, const char *, char *, size_t, off_t); |
| 83 | int (*write) (struct fuse_cred *, const char *, const char *, size_t, off_t); |
| 84 | }; |
| 85 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 86 | /* FUSE flags: */ |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 87 | |
| 88 | /** Process requests in multiple threads */ |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 89 | #define FUSE_MULTITHREAD (1 << 0) |
| 90 | |
Miklos Szeredi | c0938ea | 2001-11-07 12:35:06 +0000 | [diff] [blame] | 91 | /** Enable debuging output */ |
| 92 | #define FUSE_DEBUG (1 << 1) |
| 93 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 94 | /** |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame^] | 95 | * Create a new FUSE filesystem. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 96 | * |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame^] | 97 | * @param fd the control file descriptor |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 98 | * @param flags any combination of the FUSE flags defined above, or 0 |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 99 | * @return the created FUSE handle |
| 100 | */ |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame^] | 101 | struct fuse *fuse_new(int fd, int flags); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 102 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 103 | /** |
| 104 | * Set the filesystem operations. |
| 105 | * |
| 106 | * Operations which are initialised to NULL will return ENOSYS to the |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame^] | 107 | * calling process. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 108 | * |
| 109 | * @param f the FUSE handle |
| 110 | * @param op the operations |
| 111 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 112 | void fuse_set_operations(struct fuse *f, const struct fuse_operations *op); |
| 113 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 114 | /** |
| 115 | * FUSE event loop. |
| 116 | * |
| 117 | * Requests from the kernel are processed, and the apropriate |
| 118 | * operations are called. |
| 119 | * |
| 120 | * @param f the FUSE handle |
| 121 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 122 | void fuse_loop(struct fuse *f); |
| 123 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 124 | /** |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame^] | 125 | * Destroy the FUSE handle. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 126 | * |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame^] | 127 | * The filesystem is not unmounted. |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 128 | * |
| 129 | * @param f the FUSE handle |
| 130 | */ |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 131 | void fuse_destroy(struct fuse *f); |