Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 1 | /* |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 2 | FUSE: Filesystem in Userspace |
Miklos Szeredi | 149f607 | 2005-01-10 12:29:28 +0000 | [diff] [blame] | 3 | Copyright (C) 2001-2005 Miklos Szeredi <miklos@szeredi.hu> |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 4 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 9 | #include "fuse_i.h" |
| 10 | |
Miklos Szeredi | 0503304 | 2001-11-13 16:11:35 +0000 | [diff] [blame] | 11 | #include <linux/pagemap.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 12 | #include <linux/slab.h> |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 13 | #include <linux/file.h> |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 14 | #include <linux/mount.h> |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 15 | #include <linux/seq_file.h> |
Miklos Szeredi | c6ee9fd | 2005-01-10 09:53:04 +0000 | [diff] [blame] | 16 | #include <linux/init.h> |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 17 | #include <linux/module.h> |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 18 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 8ec48ec | 2004-04-19 10:24:41 +0000 | [diff] [blame] | 19 | #include <linux/parser.h> |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 20 | #include <linux/statfs.h> |
Miklos Szeredi | 8ec48ec | 2004-04-19 10:24:41 +0000 | [diff] [blame] | 21 | #else |
| 22 | #include "compat/parser.h" |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 23 | #endif |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 24 | |
Miklos Szeredi | c6ee9fd | 2005-01-10 09:53:04 +0000 | [diff] [blame] | 25 | MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>"); |
| 26 | MODULE_DESCRIPTION("Filesystem in Userspace"); |
| 27 | #ifdef MODULE_LICENSE |
| 28 | MODULE_LICENSE("GPL"); |
| 29 | #endif |
| 30 | |
| 31 | spinlock_t fuse_lock; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 32 | static kmem_cache_t *fuse_inode_cachep; |
Miklos Szeredi | acb4d36 | 2004-07-02 16:20:45 +0000 | [diff] [blame] | 33 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 34 | #define FUSE_SUPER_MAGIC 0x65735546 |
| 35 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 36 | #ifndef KERNEL_2_6 |
| 37 | #define kstatfs statfs |
| 38 | #endif |
Miklos Szeredi | b1ab8b5 | 2004-11-01 10:57:41 +0000 | [diff] [blame] | 39 | #ifndef MAX_LFS_FILESIZE |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 40 | #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) |
Miklos Szeredi | b1ab8b5 | 2004-11-01 10:57:41 +0000 | [diff] [blame] | 41 | #endif |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 42 | struct fuse_mount_data { |
| 43 | int fd; |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 44 | unsigned rootmode; |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 45 | unsigned user_id; |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 46 | unsigned flags; |
| 47 | unsigned max_read; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 48 | }; |
Miklos Szeredi | 69cc79a | 2004-02-17 08:57:29 +0000 | [diff] [blame] | 49 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 50 | static struct inode *fuse_alloc_inode(struct super_block *sb) |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 51 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 52 | struct inode *inode; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 53 | struct fuse_inode *fi; |
| 54 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 55 | inode = kmem_cache_alloc(fuse_inode_cachep, SLAB_KERNEL); |
| 56 | if (!inode) |
| 57 | return NULL; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 58 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 59 | #ifndef KERNEL_2_6 |
| 60 | inode->u.generic_ip = NULL; |
| 61 | #endif |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 62 | fi = get_fuse_inode(inode); |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 63 | fi->i_time = jiffies - 1; |
| 64 | fi->nodeid = 0; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 65 | fi->forget_req = fuse_request_alloc(); |
| 66 | if (!fi->forget_req) { |
| 67 | kmem_cache_free(fuse_inode_cachep, inode); |
| 68 | return NULL; |
| 69 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 70 | |
| 71 | return inode; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 74 | static void fuse_destroy_inode(struct inode *inode) |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 75 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 76 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 77 | if (fi->forget_req) |
| 78 | fuse_request_free(fi->forget_req); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 79 | kmem_cache_free(fuse_inode_cachep, inode); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 82 | static void fuse_read_inode(struct inode *inode) |
| 83 | { |
Miklos Szeredi | 90d8bef | 2001-10-26 14:55:42 +0000 | [diff] [blame] | 84 | /* No op */ |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 87 | void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, |
| 88 | unsigned long nodeid, int version) |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 89 | { |
| 90 | struct fuse_forget_in *inarg = &req->misc.forget_in; |
| 91 | inarg->version = version; |
| 92 | req->in.h.opcode = FUSE_FORGET; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 93 | req->in.h.nodeid = nodeid; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 94 | req->in.numargs = 1; |
| 95 | req->in.args[0].size = sizeof(struct fuse_forget_in); |
| 96 | req->in.args[0].value = inarg; |
| 97 | request_send_noreply(fc, req); |
| 98 | } |
| 99 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 100 | static void fuse_clear_inode(struct inode *inode) |
| 101 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 102 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 103 | if (fc) { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 104 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 105 | fuse_send_forget(fc, fi->forget_req, fi->nodeid, inode->i_version); |
| 106 | fi->forget_req = NULL; |
Miklos Szeredi | d3dd2d5 | 2004-06-22 18:46:02 +0000 | [diff] [blame] | 107 | } |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 110 | void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr) |
| 111 | { |
| 112 | if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size) |
| 113 | #ifdef KERNEL_2_6 |
| 114 | invalidate_inode_pages(inode->i_mapping); |
| 115 | #else |
| 116 | invalidate_inode_pages(inode); |
| 117 | #endif |
| 118 | |
| 119 | inode->i_ino = attr->ino; |
| 120 | inode->i_mode = (inode->i_mode & S_IFMT) + (attr->mode & 07777); |
| 121 | inode->i_nlink = attr->nlink; |
| 122 | inode->i_uid = attr->uid; |
| 123 | inode->i_gid = attr->gid; |
| 124 | i_size_write(inode, attr->size); |
| 125 | inode->i_blksize = PAGE_CACHE_SIZE; |
| 126 | inode->i_blocks = attr->blocks; |
| 127 | #ifdef KERNEL_2_6 |
| 128 | inode->i_atime.tv_sec = attr->atime; |
| 129 | inode->i_atime.tv_nsec = attr->atimensec; |
| 130 | inode->i_mtime.tv_sec = attr->mtime; |
| 131 | inode->i_mtime.tv_nsec = attr->mtimensec; |
| 132 | inode->i_ctime.tv_sec = attr->ctime; |
| 133 | inode->i_ctime.tv_nsec = attr->ctimensec; |
| 134 | #else |
| 135 | inode->i_atime = attr->atime; |
| 136 | inode->i_mtime = attr->mtime; |
| 137 | inode->i_ctime = attr->ctime; |
| 138 | #endif |
| 139 | } |
| 140 | |
| 141 | static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr) |
| 142 | { |
| 143 | inode->i_mode = attr->mode & S_IFMT; |
| 144 | i_size_write(inode, attr->size); |
| 145 | if (S_ISREG(inode->i_mode)) { |
| 146 | fuse_init_common(inode); |
| 147 | fuse_init_file_inode(inode); |
| 148 | } else if (S_ISDIR(inode->i_mode)) |
| 149 | fuse_init_dir(inode); |
| 150 | else if (S_ISLNK(inode->i_mode)) |
| 151 | fuse_init_symlink(inode); |
| 152 | else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || |
| 153 | S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { |
| 154 | fuse_init_common(inode); |
| 155 | init_special_inode(inode, inode->i_mode, |
| 156 | new_decode_dev(attr->rdev)); |
| 157 | } else { |
| 158 | /* Don't let user create weird files */ |
| 159 | inode->i_mode = S_IFREG; |
| 160 | fuse_init_common(inode); |
| 161 | fuse_init_file_inode(inode); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | #ifdef KERNEL_2_6 |
| 166 | static int fuse_inode_eq(struct inode *inode, void *_nodeidp) |
| 167 | { |
| 168 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
| 169 | if (get_node_id(inode) == nodeid) |
| 170 | return 1; |
| 171 | else |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static int fuse_inode_set(struct inode *inode, void *_nodeidp) |
| 176 | { |
| 177 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
| 178 | get_fuse_inode(inode)->nodeid = nodeid; |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, |
| 183 | int generation, struct fuse_attr *attr, int version) |
| 184 | { |
| 185 | struct inode *inode; |
| 186 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
| 187 | int retried = 0; |
| 188 | |
| 189 | retry: |
| 190 | inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid); |
| 191 | if (!inode) |
| 192 | return NULL; |
| 193 | |
| 194 | if ((inode->i_state & I_NEW)) { |
| 195 | inode->i_generation = generation; |
| 196 | inode->i_data.backing_dev_info = &fc->bdi; |
| 197 | fuse_init_inode(inode, attr); |
| 198 | unlock_new_inode(inode); |
| 199 | } else if ((inode->i_mode ^ attr->mode) & S_IFMT) { |
| 200 | BUG_ON(retried); |
| 201 | /* Inode has changed type, any I/O on the old should fail */ |
| 202 | make_bad_inode(inode); |
| 203 | iput(inode); |
| 204 | retried = 1; |
| 205 | goto retry; |
| 206 | } |
| 207 | |
| 208 | fuse_change_attributes(inode, attr); |
| 209 | inode->i_version = version; |
| 210 | return inode; |
| 211 | } |
| 212 | #else |
| 213 | static int fuse_inode_eq(struct inode *inode, unsigned long ino, void *_nodeidp){ |
| 214 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
| 215 | if (inode->u.generic_ip && get_node_id(inode) == nodeid) |
| 216 | return 1; |
| 217 | else |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, |
| 222 | int generation, struct fuse_attr *attr, int version) |
| 223 | { |
| 224 | struct inode *inode; |
| 225 | int retried = 0; |
| 226 | |
| 227 | retry: |
| 228 | inode = iget4(sb, attr->ino, fuse_inode_eq, &nodeid); |
| 229 | if (!inode) |
| 230 | return NULL; |
| 231 | |
| 232 | if (!inode->u.generic_ip) { |
| 233 | get_fuse_inode(inode)->nodeid = nodeid; |
| 234 | inode->u.generic_ip = inode; |
| 235 | inode->i_generation = generation; |
| 236 | fuse_init_inode(inode, attr); |
| 237 | } else if ((inode->i_mode ^ attr->mode) & S_IFMT) { |
| 238 | BUG_ON(retried); |
| 239 | /* Inode has changed type, any I/O on the old should fail */ |
| 240 | remove_inode_hash(inode); |
| 241 | make_bad_inode(inode); |
| 242 | iput(inode); |
| 243 | retried = 1; |
| 244 | goto retry; |
| 245 | } |
| 246 | |
| 247 | fuse_change_attributes(inode, attr); |
| 248 | inode->i_version = version; |
| 249 | return inode; |
| 250 | } |
| 251 | #endif |
| 252 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 253 | static void fuse_put_super(struct super_block *sb) |
| 254 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 255 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 256 | |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 257 | spin_lock(&fuse_lock); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 258 | fc->sb = NULL; |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 259 | fc->user_id = 0; |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 260 | fc->flags = 0; |
Miklos Szeredi | 9624998 | 2001-11-21 12:21:19 +0000 | [diff] [blame] | 261 | /* Flush all readers on this fs */ |
| 262 | wake_up_all(&fc->waitq); |
Miklos Szeredi | 79b461a | 2003-03-10 09:35:34 +0000 | [diff] [blame] | 263 | fuse_release_conn(fc); |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 264 | *get_fuse_conn_super_p(sb) = NULL; |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 265 | spin_unlock(&fuse_lock); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 268 | static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr) |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 269 | { |
| 270 | stbuf->f_type = FUSE_SUPER_MAGIC; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 271 | stbuf->f_bsize = attr->bsize; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 272 | stbuf->f_blocks = attr->blocks; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 273 | stbuf->f_bfree = attr->bfree; |
| 274 | stbuf->f_bavail = attr->bavail; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 275 | stbuf->f_files = attr->files; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 276 | stbuf->f_ffree = attr->ffree; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 277 | stbuf->f_namelen = attr->namelen; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 278 | /* fsid is left zero */ |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 281 | static int fuse_statfs(struct super_block *sb, struct kstatfs *buf) |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 282 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 283 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 284 | struct fuse_req *req; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 285 | struct fuse_statfs_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 286 | int err; |
| 287 | |
| 288 | req = fuse_get_request(fc); |
| 289 | if (!req) |
| 290 | return -ERESTARTSYS; |
| 291 | |
| 292 | req->in.numargs = 0; |
| 293 | req->in.h.opcode = FUSE_STATFS; |
| 294 | req->out.numargs = 1; |
| 295 | req->out.args[0].size = sizeof(outarg); |
| 296 | req->out.args[0].value = &outarg; |
| 297 | request_send(fc, req); |
| 298 | err = req->out.h.error; |
| 299 | if (!err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 300 | convert_fuse_statfs(buf, &outarg.st); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 301 | fuse_put_request(fc, req); |
| 302 | return err; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 305 | enum { |
| 306 | OPT_FD, |
| 307 | OPT_ROOTMODE, |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 308 | OPT_USER_ID, |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 309 | OPT_DEFAULT_PERMISSIONS, |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 310 | OPT_ALLOW_OTHER, |
| 311 | OPT_ALLOW_ROOT, |
| 312 | OPT_KERNEL_CACHE, |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 313 | #ifndef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 314 | OPT_LARGE_READ, |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 315 | #endif |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 316 | OPT_DIRECT_IO, |
| 317 | OPT_MAX_READ, |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 318 | OPT_ERR |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 319 | }; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 320 | |
| 321 | static match_table_t tokens = { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 322 | {OPT_FD, "fd=%u"}, |
| 323 | {OPT_ROOTMODE, "rootmode=%o"}, |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 324 | {OPT_USER_ID, "user_id=%u"}, |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 325 | {OPT_DEFAULT_PERMISSIONS, "default_permissions"}, |
| 326 | {OPT_ALLOW_OTHER, "allow_other"}, |
| 327 | {OPT_ALLOW_ROOT, "allow_root"}, |
| 328 | {OPT_KERNEL_CACHE, "kernel_cache"}, |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 329 | #ifndef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 330 | {OPT_LARGE_READ, "large_read"}, |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 331 | #endif |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 332 | {OPT_DIRECT_IO, "direct_io"}, |
| 333 | {OPT_MAX_READ, "max_read=%u"}, |
| 334 | {OPT_ERR, NULL} |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
| 337 | static int parse_fuse_opt(char *opt, struct fuse_mount_data *d) |
| 338 | { |
| 339 | char *p; |
| 340 | memset(d, 0, sizeof(struct fuse_mount_data)); |
| 341 | d->fd = -1; |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 342 | d->max_read = ~0; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 343 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 344 | while ((p = strsep(&opt, ",")) != NULL) { |
| 345 | int token; |
| 346 | int value; |
| 347 | substring_t args[MAX_OPT_ARGS]; |
| 348 | if (!*p) |
| 349 | continue; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 350 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 351 | token = match_token(p, tokens, args); |
| 352 | switch (token) { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 353 | case OPT_FD: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 354 | if (match_int(&args[0], &value)) |
| 355 | return 0; |
| 356 | d->fd = value; |
| 357 | break; |
| 358 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 359 | case OPT_ROOTMODE: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 360 | if (match_octal(&args[0], &value)) |
| 361 | return 0; |
| 362 | d->rootmode = value; |
| 363 | break; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 364 | |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 365 | case OPT_USER_ID: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 366 | if (match_int(&args[0], &value)) |
| 367 | return 0; |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 368 | d->user_id = value; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 369 | break; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 370 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 371 | case OPT_DEFAULT_PERMISSIONS: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 372 | d->flags |= FUSE_DEFAULT_PERMISSIONS; |
| 373 | break; |
| 374 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 375 | case OPT_ALLOW_OTHER: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 376 | d->flags |= FUSE_ALLOW_OTHER; |
| 377 | break; |
| 378 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 379 | case OPT_ALLOW_ROOT: |
Miklos Szeredi | 180ff69 | 2004-11-01 16:01:05 +0000 | [diff] [blame] | 380 | d->flags |= FUSE_ALLOW_ROOT; |
| 381 | break; |
| 382 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 383 | case OPT_KERNEL_CACHE: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 384 | d->flags |= FUSE_KERNEL_CACHE; |
| 385 | break; |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 386 | |
Miklos Szeredi | 1bf53ee | 2004-09-13 11:47:59 +0000 | [diff] [blame] | 387 | #ifndef KERNEL_2_6 |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 388 | case OPT_LARGE_READ: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 389 | d->flags |= FUSE_LARGE_READ; |
Miklos Szeredi | 1bf53ee | 2004-09-13 11:47:59 +0000 | [diff] [blame] | 390 | break; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 391 | #endif |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 392 | case OPT_DIRECT_IO: |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 393 | d->flags |= FUSE_DIRECT_IO; |
| 394 | break; |
| 395 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 396 | case OPT_MAX_READ: |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 397 | if (match_int(&args[0], &value)) |
| 398 | return 0; |
| 399 | d->max_read = value; |
| 400 | break; |
| 401 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 402 | default: |
| 403 | return 0; |
| 404 | } |
| 405 | } |
| 406 | if (d->fd == -1) |
| 407 | return 0; |
| 408 | |
| 409 | return 1; |
| 410 | } |
| 411 | |
| 412 | static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 413 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 414 | struct fuse_conn *fc = get_fuse_conn_super(mnt->mnt_sb); |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 415 | |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 416 | seq_printf(m, ",user_id=%u", fc->user_id); |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 417 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) |
| 418 | seq_puts(m, ",default_permissions"); |
| 419 | if (fc->flags & FUSE_ALLOW_OTHER) |
| 420 | seq_puts(m, ",allow_other"); |
Miklos Szeredi | 180ff69 | 2004-11-01 16:01:05 +0000 | [diff] [blame] | 421 | if (fc->flags & FUSE_ALLOW_ROOT) |
| 422 | seq_puts(m, ",allow_root"); |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 423 | if (fc->flags & FUSE_KERNEL_CACHE) |
| 424 | seq_puts(m, ",kernel_cache"); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 425 | #ifndef KERNEL_2_6 |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 426 | if (fc->flags & FUSE_LARGE_READ) |
| 427 | seq_puts(m, ",large_read"); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 428 | #endif |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 429 | if (fc->flags & FUSE_DIRECT_IO) |
| 430 | seq_puts(m, ",direct_io"); |
| 431 | if (fc->max_read != ~0) |
| 432 | seq_printf(m, ",max_read=%u", fc->max_read); |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 433 | return 0; |
| 434 | } |
| 435 | |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 436 | static void free_conn(struct fuse_conn *fc) |
| 437 | { |
| 438 | while (!list_empty(&fc->unused_list)) { |
| 439 | struct fuse_req *req; |
| 440 | req = list_entry(fc->unused_list.next, struct fuse_req, list); |
| 441 | list_del(&req->list); |
| 442 | fuse_request_free(req); |
| 443 | } |
| 444 | kfree(fc); |
| 445 | } |
| 446 | |
| 447 | /* Must be called with the fuse lock held */ |
| 448 | void fuse_release_conn(struct fuse_conn *fc) |
| 449 | { |
| 450 | if (!fc->sb && !fc->file) |
| 451 | free_conn(fc); |
| 452 | } |
| 453 | |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 454 | static struct fuse_conn *new_conn(void) |
| 455 | { |
| 456 | struct fuse_conn *fc; |
| 457 | |
| 458 | fc = kmalloc(sizeof(*fc), GFP_KERNEL); |
| 459 | if (fc != NULL) { |
| 460 | int i; |
| 461 | memset(fc, 0, sizeof(*fc)); |
| 462 | fc->sb = NULL; |
| 463 | fc->file = NULL; |
| 464 | fc->flags = 0; |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 465 | fc->user_id = 0; |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 466 | init_waitqueue_head(&fc->waitq); |
| 467 | INIT_LIST_HEAD(&fc->pending); |
| 468 | INIT_LIST_HEAD(&fc->processing); |
| 469 | INIT_LIST_HEAD(&fc->unused_list); |
Miklos Szeredi | 3f0005f | 2005-01-04 19:24:31 +0000 | [diff] [blame] | 470 | sema_init(&fc->outstanding_sem, 0); |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 471 | for (i = 0; i < FUSE_MAX_OUTSTANDING; i++) { |
| 472 | struct fuse_req *req = fuse_request_alloc(); |
| 473 | if (!req) { |
| 474 | free_conn(fc); |
| 475 | return NULL; |
| 476 | } |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 477 | list_add(&req->list, &fc->unused_list); |
| 478 | } |
Miklos Szeredi | b622019 | 2005-01-05 16:19:10 +0000 | [diff] [blame] | 479 | #ifdef KERNEL_2_6_6_PLUS |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 480 | fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; |
| 481 | fc->bdi.unplug_io_fn = default_unplug_io_fn; |
| 482 | #endif |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 483 | fc->reqctr = 1; |
| 484 | } |
| 485 | return fc; |
| 486 | } |
| 487 | |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 488 | static struct fuse_conn *get_conn(struct file *file, struct super_block *sb) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 489 | { |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 490 | struct fuse_conn *fc; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 491 | |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 492 | if (file->f_op != &fuse_dev_operations) |
Miklos Szeredi | ee80838 | 2005-01-21 22:05:37 +0000 | [diff] [blame] | 493 | return ERR_PTR(-EINVAL); |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 494 | fc = new_conn(); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 495 | if (fc == NULL) |
Miklos Szeredi | ee80838 | 2005-01-21 22:05:37 +0000 | [diff] [blame] | 496 | return ERR_PTR(-ENOMEM); |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 497 | spin_lock(&fuse_lock); |
| 498 | if (file->private_data) { |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 499 | free_conn(fc); |
Miklos Szeredi | ee80838 | 2005-01-21 22:05:37 +0000 | [diff] [blame] | 500 | fc = ERR_PTR(-EINVAL); |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 501 | } else { |
| 502 | file->private_data = fc; |
| 503 | fc->sb = sb; |
| 504 | fc->file = file; |
| 505 | } |
| 506 | spin_unlock(&fuse_lock); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 507 | return fc; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 510 | static struct inode *get_root_inode(struct super_block *sb, unsigned mode) |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 511 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 512 | struct fuse_attr attr; |
| 513 | memset(&attr, 0, sizeof(attr)); |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 514 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 515 | attr.mode = mode; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 516 | attr.ino = FUSE_ROOT_ID; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 517 | return fuse_iget(sb, 1, 0, &attr, 0); |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 520 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 521 | static struct dentry *fuse_get_dentry(struct super_block *sb, void *vobjp) |
| 522 | { |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 523 | int err; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 524 | __u32 *objp = vobjp; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 525 | unsigned long nodeid = objp[0]; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 526 | __u32 generation = objp[1]; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 527 | struct inode *inode; |
| 528 | struct dentry *entry; |
| 529 | |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 530 | err = -ESTALE; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 531 | if (nodeid == 0) |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 532 | goto error; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 533 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 534 | inode = ilookup5(sb, nodeid, fuse_inode_eq, &nodeid); |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 535 | if (!inode) |
| 536 | goto error; |
| 537 | if (inode->i_generation != generation) |
| 538 | goto error_iput; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 539 | |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 540 | err = -ENOMEM; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 541 | entry = d_alloc_anon(inode); |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 542 | if (!entry) |
| 543 | goto error_iput; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 544 | |
| 545 | return entry; |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 546 | |
| 547 | error_iput: |
| 548 | iput(inode); |
| 549 | error: |
| 550 | return ERR_PTR(err); |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 553 | static int fuse_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, |
| 554 | int connectable) |
| 555 | { |
| 556 | struct inode *inode = dentry->d_inode; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 557 | int len = *max_len; |
| 558 | int type = 1; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 559 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 560 | if (len < 2 || (connectable && len < 4)) |
| 561 | return 255; |
| 562 | |
| 563 | len = 2; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 564 | fh[0] = get_fuse_inode(inode)->nodeid; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 565 | fh[1] = inode->i_generation; |
| 566 | if (connectable && !S_ISDIR(inode->i_mode)) { |
| 567 | struct inode *parent; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 568 | |
| 569 | spin_lock(&dentry->d_lock); |
| 570 | parent = dentry->d_parent->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 571 | fh[2] = get_fuse_inode(parent)->nodeid; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 572 | fh[3] = parent->i_generation; |
| 573 | spin_unlock(&dentry->d_lock); |
| 574 | len = 4; |
| 575 | type = 2; |
| 576 | } |
| 577 | *max_len = len; |
| 578 | return type; |
| 579 | } |
| 580 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 581 | static struct export_operations fuse_export_operations = { |
| 582 | .get_dentry = fuse_get_dentry, |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 583 | .encode_fh = fuse_encode_fh, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 584 | }; |
| 585 | #endif |
| 586 | |
| 587 | static struct super_operations fuse_super_operations = { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 588 | .alloc_inode = fuse_alloc_inode, |
| 589 | .destroy_inode = fuse_destroy_inode, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 590 | .read_inode = fuse_read_inode, |
| 591 | .clear_inode = fuse_clear_inode, |
| 592 | .put_super = fuse_put_super, |
| 593 | .statfs = fuse_statfs, |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 594 | .show_options = fuse_show_options, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 595 | }; |
| 596 | |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 597 | static int fuse_fill_super(struct super_block *sb, void *data, int silent) |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 598 | { |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 599 | struct fuse_conn *fc; |
| 600 | struct inode *root; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 601 | struct fuse_mount_data d; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 602 | struct file *file; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 603 | int err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 604 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 605 | if (!parse_fuse_opt((char *) data, &d)) |
| 606 | return -EINVAL; |
| 607 | |
Miklos Szeredi | 377b2ea | 2004-02-06 09:48:51 +0000 | [diff] [blame] | 608 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 609 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 610 | sb->s_magic = FUSE_SUPER_MAGIC; |
| 611 | sb->s_op = &fuse_super_operations; |
| 612 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 613 | #ifdef KERNEL_2_6 |
| 614 | sb->s_export_op = &fuse_export_operations; |
| 615 | #endif |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 616 | |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 617 | file = fget(d.fd); |
| 618 | if (!file) |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 619 | return -EINVAL; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 620 | |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 621 | fc = get_conn(file, sb); |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 622 | fput(file); |
Miklos Szeredi | ee80838 | 2005-01-21 22:05:37 +0000 | [diff] [blame] | 623 | if (IS_ERR(fc)) |
| 624 | return PTR_ERR(fc); |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 625 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 626 | fc->flags = d.flags; |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 627 | fc->user_id = d.user_id; |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 628 | fc->max_read = d.max_read; |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 629 | #ifdef KERNEL_2_6 |
| 630 | if (fc->max_read / PAGE_CACHE_SIZE < fc->bdi.ra_pages) |
| 631 | fc->bdi.ra_pages = fc->max_read / PAGE_CACHE_SIZE; |
| 632 | #endif |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 633 | fc->max_write = FUSE_MAX_IN / 2; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 634 | |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 635 | *get_fuse_conn_super_p(sb) = fc; |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 636 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 637 | err = -ENOMEM; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 638 | root = get_root_inode(sb, d.rootmode); |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 639 | if (root == NULL) |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 640 | goto err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 641 | |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 642 | sb->s_root = d_alloc_root(root); |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 643 | if (!sb->s_root) { |
| 644 | iput(root); |
| 645 | goto err; |
| 646 | } |
Miklos Szeredi | 3f0005f | 2005-01-04 19:24:31 +0000 | [diff] [blame] | 647 | fuse_send_init(fc); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 648 | return 0; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 649 | |
| 650 | err: |
| 651 | spin_lock(&fuse_lock); |
| 652 | fc->sb = NULL; |
| 653 | fuse_release_conn(fc); |
| 654 | spin_unlock(&fuse_lock); |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 655 | *get_fuse_conn_super_p(sb) = NULL; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 656 | return err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 659 | #ifdef KERNEL_2_6 |
| 660 | static struct super_block *fuse_get_sb(struct file_system_type *fs_type, |
Miklos Szeredi | e8663f3 | 2004-01-13 15:33:12 +0000 | [diff] [blame] | 661 | int flags, const char *dev_name, |
| 662 | void *raw_data) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 663 | { |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 664 | return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 665 | } |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 666 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 667 | static struct file_system_type fuse_fs_type = { |
Miklos Szeredi | 377b2ea | 2004-02-06 09:48:51 +0000 | [diff] [blame] | 668 | .owner = THIS_MODULE, |
| 669 | .name = "fuse", |
| 670 | .get_sb = fuse_get_sb, |
| 671 | .kill_sb = kill_anon_super, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 672 | }; |
| 673 | #else |
| 674 | static struct super_block *fuse_read_super_compat(struct super_block *sb, |
| 675 | void *data, int silent) |
| 676 | { |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 677 | int err = fuse_fill_super(sb, data, silent); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 678 | if (err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 679 | return NULL; |
| 680 | else |
| 681 | return sb; |
| 682 | } |
| 683 | |
| 684 | static DECLARE_FSTYPE(fuse_fs_type, "fuse", fuse_read_super_compat, 0); |
| 685 | #endif |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 686 | |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 687 | static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep, |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 688 | unsigned long flags) |
| 689 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 690 | struct inode * inode = foo; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 691 | |
| 692 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == |
| 693 | SLAB_CTOR_CONSTRUCTOR) |
| 694 | inode_init_once(inode); |
| 695 | } |
| 696 | |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 697 | static int __init fuse_fs_init(void) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 698 | { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 699 | int err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 700 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 701 | err = register_filesystem(&fuse_fs_type); |
| 702 | if (err) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 703 | printk("fuse: failed to register filesystem\n"); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 704 | else { |
| 705 | fuse_inode_cachep = kmem_cache_create("fuse_inode", |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 706 | sizeof(struct fuse_inode), |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 707 | 0, SLAB_HWCACHE_ALIGN, |
| 708 | fuse_inode_init_once, NULL); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 709 | if (!fuse_inode_cachep) { |
| 710 | unregister_filesystem(&fuse_fs_type); |
| 711 | err = -ENOMEM; |
| 712 | } |
| 713 | } |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 714 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 715 | return err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 718 | static void fuse_fs_cleanup(void) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 719 | { |
| 720 | unregister_filesystem(&fuse_fs_type); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 721 | kmem_cache_destroy(fuse_inode_cachep); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 722 | } |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 723 | |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 724 | static int __init fuse_init(void) |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 725 | { |
| 726 | int res; |
| 727 | |
| 728 | printk("fuse init (API version %i.%i)\n", |
| 729 | FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); |
| 730 | #ifndef FUSE_MAINLINE |
| 731 | printk("fuse distribution version: %s\n", FUSE_VERSION); |
| 732 | #endif |
| 733 | |
| 734 | spin_lock_init(&fuse_lock); |
| 735 | res = fuse_fs_init(); |
| 736 | if (res) |
| 737 | goto err; |
| 738 | |
| 739 | res = fuse_dev_init(); |
| 740 | if (res) |
| 741 | goto err_fs_cleanup; |
| 742 | |
| 743 | return 0; |
| 744 | |
| 745 | err_fs_cleanup: |
| 746 | fuse_fs_cleanup(); |
| 747 | err: |
| 748 | return res; |
| 749 | } |
| 750 | |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 751 | static void __exit fuse_exit(void) |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 752 | { |
| 753 | printk(KERN_DEBUG "fuse exit\n"); |
| 754 | |
| 755 | fuse_fs_cleanup(); |
| 756 | fuse_dev_cleanup(); |
| 757 | } |
| 758 | |
| 759 | module_init(fuse_init); |
| 760 | module_exit(fuse_exit); |