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 | 95da860 | 2006-01-06 18:29:40 +0000 | [diff] [blame] | 3 | Copyright (C) 2001-2006 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/seq_file.h> |
Miklos Szeredi | c6ee9fd | 2005-01-10 09:53:04 +0000 | [diff] [blame] | 15 | #include <linux/init.h> |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 16 | #include <linux/module.h> |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 17 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 8ec48ec | 2004-04-19 10:24:41 +0000 | [diff] [blame] | 18 | #include <linux/parser.h> |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 19 | #include <linux/statfs.h> |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 20 | #include <linux/random.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 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 31 | static kmem_cache_t *fuse_inode_cachep; |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 32 | struct list_head fuse_conn_list; |
| 33 | DEFINE_MUTEX(fuse_mutex); |
Miklos Szeredi | acb4d36 | 2004-07-02 16:20:45 +0000 | [diff] [blame] | 34 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 35 | #define FUSE_SUPER_MAGIC 0x65735546 |
| 36 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 37 | #ifndef KERNEL_2_6 |
| 38 | #define kstatfs statfs |
| 39 | #endif |
Miklos Szeredi | b1ab8b5 | 2004-11-01 10:57:41 +0000 | [diff] [blame] | 40 | #ifndef MAX_LFS_FILESIZE |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 41 | #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] | 42 | #endif |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 43 | struct fuse_mount_data { |
| 44 | int fd; |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 45 | unsigned rootmode; |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 46 | unsigned user_id; |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame] | 47 | unsigned group_id; |
Miklos Szeredi | 437d811 | 2005-07-06 09:14:20 +0000 | [diff] [blame] | 48 | unsigned fd_present : 1; |
| 49 | unsigned rootmode_present : 1; |
| 50 | unsigned user_id_present : 1; |
| 51 | unsigned group_id_present : 1; |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 52 | unsigned flags; |
| 53 | unsigned max_read; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 54 | }; |
Miklos Szeredi | 69cc79a | 2004-02-17 08:57:29 +0000 | [diff] [blame] | 55 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 56 | static struct inode *fuse_alloc_inode(struct super_block *sb) |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 57 | { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 58 | struct inode *inode; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 59 | struct fuse_inode *fi; |
| 60 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 61 | inode = kmem_cache_alloc(fuse_inode_cachep, SLAB_KERNEL); |
| 62 | if (!inode) |
| 63 | return NULL; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 64 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 65 | #ifndef KERNEL_2_6 |
| 66 | inode->u.generic_ip = NULL; |
| 67 | #endif |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 68 | fi = get_fuse_inode(inode); |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 69 | fi->i_time = 0; |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 70 | fi->nodeid = 0; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 71 | fi->nlookup = 0; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 72 | fi->forget_req = fuse_request_alloc(); |
| 73 | if (!fi->forget_req) { |
| 74 | kmem_cache_free(fuse_inode_cachep, inode); |
| 75 | return NULL; |
| 76 | } |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 77 | |
| 78 | return inode; |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 81 | static void fuse_destroy_inode(struct inode *inode) |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 82 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 83 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 84 | if (fi->forget_req) |
| 85 | fuse_request_free(fi->forget_req); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 86 | kmem_cache_free(fuse_inode_cachep, inode); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 89 | static void fuse_read_inode(struct inode *inode) |
| 90 | { |
Miklos Szeredi | 90d8bef | 2001-10-26 14:55:42 +0000 | [diff] [blame] | 91 | /* No op */ |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 94 | void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 95 | unsigned long nodeid, u64 nlookup) |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 96 | { |
| 97 | struct fuse_forget_in *inarg = &req->misc.forget_in; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 98 | inarg->nlookup = nlookup; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 99 | req->in.h.opcode = FUSE_FORGET; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 100 | req->in.h.nodeid = nodeid; |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 101 | req->in.numargs = 1; |
| 102 | req->in.args[0].size = sizeof(struct fuse_forget_in); |
| 103 | req->in.args[0].value = inarg; |
| 104 | request_send_noreply(fc, req); |
| 105 | } |
| 106 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 107 | static void fuse_clear_inode(struct inode *inode) |
| 108 | { |
Miklos Szeredi | 0111f9d | 2005-04-22 12:04:55 +0000 | [diff] [blame] | 109 | if (inode->i_sb->s_flags & MS_ACTIVE) { |
| 110 | struct fuse_conn *fc = get_fuse_conn(inode); |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 111 | struct fuse_inode *fi = get_fuse_inode(inode); |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 112 | fuse_send_forget(fc, fi->forget_req, fi->nodeid, fi->nlookup); |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 113 | fi->forget_req = NULL; |
Miklos Szeredi | d3dd2d5 | 2004-06-22 18:46:02 +0000 | [diff] [blame] | 114 | } |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 117 | static int fuse_remount_fs(struct super_block *sb, int *flags, char *data) |
| 118 | { |
| 119 | if (*flags & MS_MANDLOCK) |
| 120 | return -EINVAL; |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 125 | void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr) |
| 126 | { |
| 127 | if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size) |
| 128 | #ifdef KERNEL_2_6 |
| 129 | invalidate_inode_pages(inode->i_mapping); |
| 130 | #else |
| 131 | invalidate_inode_pages(inode); |
| 132 | #endif |
| 133 | |
| 134 | inode->i_ino = attr->ino; |
| 135 | inode->i_mode = (inode->i_mode & S_IFMT) + (attr->mode & 07777); |
| 136 | inode->i_nlink = attr->nlink; |
| 137 | inode->i_uid = attr->uid; |
| 138 | inode->i_gid = attr->gid; |
| 139 | i_size_write(inode, attr->size); |
| 140 | inode->i_blksize = PAGE_CACHE_SIZE; |
| 141 | inode->i_blocks = attr->blocks; |
| 142 | #ifdef KERNEL_2_6 |
| 143 | inode->i_atime.tv_sec = attr->atime; |
| 144 | inode->i_atime.tv_nsec = attr->atimensec; |
| 145 | inode->i_mtime.tv_sec = attr->mtime; |
| 146 | inode->i_mtime.tv_nsec = attr->mtimensec; |
| 147 | inode->i_ctime.tv_sec = attr->ctime; |
| 148 | inode->i_ctime.tv_nsec = attr->ctimensec; |
| 149 | #else |
| 150 | inode->i_atime = attr->atime; |
| 151 | inode->i_mtime = attr->mtime; |
| 152 | inode->i_ctime = attr->ctime; |
| 153 | #endif |
| 154 | } |
| 155 | |
| 156 | static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr) |
| 157 | { |
| 158 | inode->i_mode = attr->mode & S_IFMT; |
| 159 | i_size_write(inode, attr->size); |
| 160 | if (S_ISREG(inode->i_mode)) { |
| 161 | fuse_init_common(inode); |
| 162 | fuse_init_file_inode(inode); |
| 163 | } else if (S_ISDIR(inode->i_mode)) |
| 164 | fuse_init_dir(inode); |
| 165 | else if (S_ISLNK(inode->i_mode)) |
| 166 | fuse_init_symlink(inode); |
| 167 | else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || |
| 168 | S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { |
| 169 | fuse_init_common(inode); |
| 170 | init_special_inode(inode, inode->i_mode, |
| 171 | new_decode_dev(attr->rdev)); |
Miklos Szeredi | 6470957 | 2005-12-14 22:16:28 +0000 | [diff] [blame] | 172 | } else |
| 173 | BUG(); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | #ifdef KERNEL_2_6 |
| 177 | static int fuse_inode_eq(struct inode *inode, void *_nodeidp) |
| 178 | { |
| 179 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
| 180 | if (get_node_id(inode) == nodeid) |
| 181 | return 1; |
| 182 | else |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int fuse_inode_set(struct inode *inode, void *_nodeidp) |
| 187 | { |
| 188 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
| 189 | get_fuse_inode(inode)->nodeid = nodeid; |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 194 | int generation, struct fuse_attr *attr) |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 195 | { |
| 196 | struct inode *inode; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 197 | struct fuse_inode *fi; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 198 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
| 199 | int retried = 0; |
| 200 | |
| 201 | retry: |
| 202 | inode = iget5_locked(sb, nodeid, fuse_inode_eq, fuse_inode_set, &nodeid); |
| 203 | if (!inode) |
| 204 | return NULL; |
| 205 | |
| 206 | if ((inode->i_state & I_NEW)) { |
Miklos Szeredi | 3b9e53f | 2005-09-02 16:04:48 +0000 | [diff] [blame] | 207 | #ifdef KERNEL_2_6_8_PLUS |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 208 | inode->i_flags |= S_NOATIME|S_NOCMTIME; |
Miklos Szeredi | 3b9e53f | 2005-09-02 16:04:48 +0000 | [diff] [blame] | 209 | #else |
| 210 | inode->i_flags |= S_NOATIME; |
| 211 | #endif |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 212 | inode->i_generation = generation; |
| 213 | inode->i_data.backing_dev_info = &fc->bdi; |
| 214 | fuse_init_inode(inode, attr); |
| 215 | unlock_new_inode(inode); |
| 216 | } else if ((inode->i_mode ^ attr->mode) & S_IFMT) { |
| 217 | BUG_ON(retried); |
| 218 | /* Inode has changed type, any I/O on the old should fail */ |
| 219 | make_bad_inode(inode); |
| 220 | iput(inode); |
| 221 | retried = 1; |
| 222 | goto retry; |
| 223 | } |
| 224 | |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 225 | fi = get_fuse_inode(inode); |
| 226 | fi->nlookup ++; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 227 | fuse_change_attributes(inode, attr); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 228 | return inode; |
| 229 | } |
| 230 | #else |
| 231 | static int fuse_inode_eq(struct inode *inode, unsigned long ino, void *_nodeidp){ |
| 232 | unsigned long nodeid = *(unsigned long *) _nodeidp; |
| 233 | if (inode->u.generic_ip && get_node_id(inode) == nodeid) |
| 234 | return 1; |
| 235 | else |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid, |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 240 | int generation, struct fuse_attr *attr) |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 241 | { |
| 242 | struct inode *inode; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 243 | struct fuse_inode *fi; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 244 | int retried = 0; |
| 245 | |
| 246 | retry: |
| 247 | inode = iget4(sb, attr->ino, fuse_inode_eq, &nodeid); |
| 248 | if (!inode) |
| 249 | return NULL; |
| 250 | |
| 251 | if (!inode->u.generic_ip) { |
| 252 | get_fuse_inode(inode)->nodeid = nodeid; |
| 253 | inode->u.generic_ip = inode; |
| 254 | inode->i_generation = generation; |
| 255 | fuse_init_inode(inode, attr); |
| 256 | } else if ((inode->i_mode ^ attr->mode) & S_IFMT) { |
| 257 | BUG_ON(retried); |
| 258 | /* Inode has changed type, any I/O on the old should fail */ |
| 259 | remove_inode_hash(inode); |
| 260 | make_bad_inode(inode); |
| 261 | iput(inode); |
| 262 | retried = 1; |
| 263 | goto retry; |
| 264 | } |
| 265 | |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 266 | fi = get_fuse_inode(inode); |
| 267 | fi->nlookup ++; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 268 | fuse_change_attributes(inode, attr); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 269 | return inode; |
| 270 | } |
| 271 | #endif |
| 272 | |
Miklos Szeredi | ec3f6e4 | 2006-06-29 15:13:35 +0000 | [diff] [blame] | 273 | #ifdef KERNEL_2_6_18_PLUS |
| 274 | static void fuse_umount_begin(struct vfsmount *vfsmnt, int flags) |
| 275 | { |
| 276 | if (flags & MNT_FORCE) |
| 277 | fuse_abort_conn(get_fuse_conn_super(vfsmnt->mnt_sb)); |
| 278 | } |
| 279 | #else |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 280 | static void fuse_umount_begin(struct super_block *sb) |
| 281 | { |
| 282 | fuse_abort_conn(get_fuse_conn_super(sb)); |
| 283 | } |
Miklos Szeredi | ec3f6e4 | 2006-06-29 15:13:35 +0000 | [diff] [blame] | 284 | #endif |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 285 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 286 | static void fuse_put_super(struct super_block *sb) |
| 287 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 288 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 289 | |
Miklos Szeredi | 67d26d4 | 2006-03-13 17:39:56 +0000 | [diff] [blame] | 290 | spin_lock(&fc->lock); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 291 | fc->connected = 0; |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 292 | fc->blocked = 0; |
Miklos Szeredi | 67d26d4 | 2006-03-13 17:39:56 +0000 | [diff] [blame] | 293 | spin_unlock(&fc->lock); |
Miklos Szeredi | 9624998 | 2001-11-21 12:21:19 +0000 | [diff] [blame] | 294 | /* Flush all readers on this fs */ |
Miklos Szeredi | 5d9ce36 | 2006-03-01 12:10:13 +0000 | [diff] [blame] | 295 | kill_fasync(&fc->fasync, SIGIO, POLL_IN); |
Miklos Szeredi | 9624998 | 2001-11-21 12:21:19 +0000 | [diff] [blame] | 296 | wake_up_all(&fc->waitq); |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 297 | wake_up_all(&fc->blocked_waitq); |
| 298 | mutex_lock(&fuse_mutex); |
| 299 | list_del(&fc->entry); |
| 300 | fuse_ctl_remove_conn(fc); |
| 301 | mutex_unlock(&fuse_mutex); |
| 302 | fuse_conn_put(fc); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 305 | static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr) |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 306 | { |
| 307 | stbuf->f_type = FUSE_SUPER_MAGIC; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 308 | stbuf->f_bsize = attr->bsize; |
Miklos Szeredi | bb4b974 | 2005-11-29 11:29:44 +0000 | [diff] [blame] | 309 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 310 | stbuf->f_frsize = attr->frsize; |
Miklos Szeredi | bb4b974 | 2005-11-29 11:29:44 +0000 | [diff] [blame] | 311 | #endif |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 312 | stbuf->f_blocks = attr->blocks; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 313 | stbuf->f_bfree = attr->bfree; |
| 314 | stbuf->f_bavail = attr->bavail; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 315 | stbuf->f_files = attr->files; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 316 | stbuf->f_ffree = attr->ffree; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 317 | stbuf->f_namelen = attr->namelen; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 318 | /* fsid is left zero */ |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 321 | #ifdef KERNEL_2_6_18_PLUS |
| 322 | static int fuse_statfs(struct dentry *dentry, struct kstatfs *buf) |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 323 | #else |
| 324 | static int fuse_statfs(struct super_block *sb, struct kstatfs *buf) |
| 325 | #endif |
| 326 | { |
| 327 | #ifdef KERNEL_2_6_18_PLUS |
| 328 | struct super_block *sb = dentry->d_sb; |
| 329 | #endif |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 330 | struct fuse_conn *fc = get_fuse_conn_super(sb); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 331 | struct fuse_req *req; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 332 | struct fuse_statfs_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 333 | int err; |
| 334 | |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 335 | req = fuse_get_req(fc); |
| 336 | if (IS_ERR(req)) |
| 337 | return PTR_ERR(req); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 338 | |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 339 | memset(&outarg, 0, sizeof(outarg)); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 340 | req->in.numargs = 0; |
| 341 | req->in.h.opcode = FUSE_STATFS; |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 342 | #ifdef KERNEL_2_6_18_PLUS |
| 343 | req->in.h.nodeid = get_node_id(dentry->d_inode); |
| 344 | #endif |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 345 | req->out.numargs = 1; |
Miklos Szeredi | ead7f10 | 2005-11-28 16:02:27 +0000 | [diff] [blame] | 346 | req->out.args[0].size = |
Miklos Szeredi | 2b47811 | 2005-11-28 13:27:10 +0000 | [diff] [blame] | 347 | fc->minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(outarg); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 348 | req->out.args[0].value = &outarg; |
| 349 | request_send(fc, req); |
| 350 | err = req->out.h.error; |
| 351 | if (!err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 352 | convert_fuse_statfs(buf, &outarg.st); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 353 | fuse_put_request(fc, req); |
| 354 | return err; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 357 | enum { |
| 358 | OPT_FD, |
| 359 | OPT_ROOTMODE, |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 360 | OPT_USER_ID, |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame] | 361 | OPT_GROUP_ID, |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 362 | OPT_DEFAULT_PERMISSIONS, |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 363 | OPT_ALLOW_OTHER, |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 364 | #ifndef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 365 | OPT_LARGE_READ, |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 366 | #endif |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 367 | OPT_MAX_READ, |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 368 | OPT_ERR |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 369 | }; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 370 | |
| 371 | static match_table_t tokens = { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 372 | {OPT_FD, "fd=%u"}, |
| 373 | {OPT_ROOTMODE, "rootmode=%o"}, |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 374 | {OPT_USER_ID, "user_id=%u"}, |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame] | 375 | {OPT_GROUP_ID, "group_id=%u"}, |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 376 | {OPT_DEFAULT_PERMISSIONS, "default_permissions"}, |
| 377 | {OPT_ALLOW_OTHER, "allow_other"}, |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 378 | #ifndef KERNEL_2_6 |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 379 | {OPT_LARGE_READ, "large_read"}, |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 380 | #endif |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 381 | {OPT_MAX_READ, "max_read=%u"}, |
| 382 | {OPT_ERR, NULL} |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | static int parse_fuse_opt(char *opt, struct fuse_mount_data *d) |
| 386 | { |
| 387 | char *p; |
| 388 | memset(d, 0, sizeof(struct fuse_mount_data)); |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 389 | d->max_read = ~0; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 390 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 391 | while ((p = strsep(&opt, ",")) != NULL) { |
| 392 | int token; |
| 393 | int value; |
| 394 | substring_t args[MAX_OPT_ARGS]; |
| 395 | if (!*p) |
| 396 | continue; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 397 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 398 | token = match_token(p, tokens, args); |
| 399 | switch (token) { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 400 | case OPT_FD: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 401 | if (match_int(&args[0], &value)) |
| 402 | return 0; |
| 403 | d->fd = value; |
Miklos Szeredi | 437d811 | 2005-07-06 09:14:20 +0000 | [diff] [blame] | 404 | d->fd_present = 1; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 405 | break; |
| 406 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 407 | case OPT_ROOTMODE: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 408 | if (match_octal(&args[0], &value)) |
| 409 | return 0; |
| 410 | d->rootmode = value; |
Miklos Szeredi | 437d811 | 2005-07-06 09:14:20 +0000 | [diff] [blame] | 411 | d->rootmode_present = 1; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 412 | break; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 413 | |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 414 | case OPT_USER_ID: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 415 | if (match_int(&args[0], &value)) |
| 416 | return 0; |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 417 | d->user_id = value; |
Miklos Szeredi | 437d811 | 2005-07-06 09:14:20 +0000 | [diff] [blame] | 418 | d->user_id_present = 1; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 419 | break; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 420 | |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame] | 421 | case OPT_GROUP_ID: |
| 422 | if (match_int(&args[0], &value)) |
| 423 | return 0; |
| 424 | d->group_id = value; |
Miklos Szeredi | 437d811 | 2005-07-06 09:14:20 +0000 | [diff] [blame] | 425 | d->group_id_present = 1; |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame] | 426 | break; |
| 427 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 428 | case OPT_DEFAULT_PERMISSIONS: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 429 | d->flags |= FUSE_DEFAULT_PERMISSIONS; |
| 430 | break; |
| 431 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 432 | case OPT_ALLOW_OTHER: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 433 | d->flags |= FUSE_ALLOW_OTHER; |
| 434 | break; |
| 435 | |
Miklos Szeredi | 1bf53ee | 2004-09-13 11:47:59 +0000 | [diff] [blame] | 436 | #ifndef KERNEL_2_6 |
Miklos Szeredi | e56818b | 2004-12-12 11:45:24 +0000 | [diff] [blame] | 437 | case OPT_LARGE_READ: |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 438 | d->flags |= FUSE_LARGE_READ; |
Miklos Szeredi | 1bf53ee | 2004-09-13 11:47:59 +0000 | [diff] [blame] | 439 | break; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 440 | #endif |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 441 | case OPT_MAX_READ: |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 442 | if (match_int(&args[0], &value)) |
| 443 | return 0; |
| 444 | d->max_read = value; |
| 445 | break; |
| 446 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 447 | default: |
| 448 | return 0; |
| 449 | } |
| 450 | } |
Miklos Szeredi | 9b813af | 2005-07-21 07:59:37 +0000 | [diff] [blame] | 451 | |
Miklos Szeredi | 437d811 | 2005-07-06 09:14:20 +0000 | [diff] [blame] | 452 | if (!d->fd_present || !d->rootmode_present || |
| 453 | !d->user_id_present || !d->group_id_present) |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 454 | return 0; |
| 455 | |
| 456 | return 1; |
| 457 | } |
| 458 | |
| 459 | static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 460 | { |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 461 | struct fuse_conn *fc = get_fuse_conn_super(mnt->mnt_sb); |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 462 | |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 463 | seq_printf(m, ",user_id=%u", fc->user_id); |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame] | 464 | seq_printf(m, ",group_id=%u", fc->group_id); |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 465 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) |
| 466 | seq_puts(m, ",default_permissions"); |
| 467 | if (fc->flags & FUSE_ALLOW_OTHER) |
| 468 | seq_puts(m, ",allow_other"); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 469 | #ifndef KERNEL_2_6 |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 470 | if (fc->flags & FUSE_LARGE_READ) |
| 471 | seq_puts(m, ",large_read"); |
Miklos Szeredi | 209f5d0 | 2004-07-24 19:56:16 +0000 | [diff] [blame] | 472 | #endif |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 473 | if (fc->max_read != ~0) |
| 474 | seq_printf(m, ",max_read=%u", fc->max_read); |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 475 | return 0; |
| 476 | } |
| 477 | |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 478 | #ifndef HAVE_KZALLOC |
| 479 | static void *kzalloc(size_t size, int flags) |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 480 | { |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 481 | void *ret = kmalloc(size, flags); |
| 482 | if (ret) |
| 483 | memset(ret, 0, size); |
| 484 | return ret; |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 485 | } |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 486 | #endif |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 487 | static struct fuse_conn *new_conn(void) |
| 488 | { |
| 489 | struct fuse_conn *fc; |
| 490 | |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 491 | fc = kzalloc(sizeof(*fc), GFP_KERNEL); |
| 492 | if (fc) { |
Miklos Szeredi | 67d26d4 | 2006-03-13 17:39:56 +0000 | [diff] [blame] | 493 | spin_lock_init(&fc->lock); |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 494 | atomic_set(&fc->count, 1); |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 495 | init_waitqueue_head(&fc->waitq); |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 496 | init_waitqueue_head(&fc->blocked_waitq); |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 497 | INIT_LIST_HEAD(&fc->pending); |
| 498 | INIT_LIST_HEAD(&fc->processing); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 499 | INIT_LIST_HEAD(&fc->io); |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 500 | INIT_LIST_HEAD(&fc->interrupts); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 501 | atomic_set(&fc->num_waiting, 0); |
Miklos Szeredi | b622019 | 2005-01-05 16:19:10 +0000 | [diff] [blame] | 502 | #ifdef KERNEL_2_6_6_PLUS |
Miklos Szeredi | a25d4c2 | 2004-11-23 22:32:16 +0000 | [diff] [blame] | 503 | fc->bdi.ra_pages = (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE; |
| 504 | fc->bdi.unplug_io_fn = default_unplug_io_fn; |
| 505 | #endif |
Miklos Szeredi | e3b8309 | 2005-07-22 17:24:30 +0000 | [diff] [blame] | 506 | fc->reqctr = 0; |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 507 | fc->blocked = 1; |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 508 | get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); |
Miklos Szeredi | 3d60e76 | 2004-11-11 14:44:04 +0000 | [diff] [blame] | 509 | } |
| 510 | return fc; |
| 511 | } |
| 512 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 513 | void fuse_conn_put(struct fuse_conn *fc) |
| 514 | { |
| 515 | if (atomic_dec_and_test(&fc->count)) |
| 516 | kfree(fc); |
| 517 | } |
| 518 | |
| 519 | struct fuse_conn *fuse_conn_get(struct fuse_conn *fc) |
| 520 | { |
| 521 | atomic_inc(&fc->count); |
| 522 | return fc; |
| 523 | } |
| 524 | |
Miklos Szeredi | 83a0744 | 2004-11-30 18:25:20 +0000 | [diff] [blame] | 525 | static struct inode *get_root_inode(struct super_block *sb, unsigned mode) |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 526 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 527 | struct fuse_attr attr; |
| 528 | memset(&attr, 0, sizeof(attr)); |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 529 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 530 | attr.mode = mode; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 531 | attr.ino = FUSE_ROOT_ID; |
Miklos Szeredi | 3800902 | 2005-05-08 19:47:22 +0000 | [diff] [blame] | 532 | return fuse_iget(sb, 1, 0, &attr); |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 533 | } |
Miklos Szeredi | 1b18802 | 2005-07-28 11:07:29 +0000 | [diff] [blame] | 534 | #ifndef FUSE_MAINLINE |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 535 | #ifdef KERNEL_2_6 |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 536 | static struct dentry *fuse_get_dentry(struct super_block *sb, void *vobjp) |
| 537 | { |
| 538 | __u32 *objp = vobjp; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 539 | unsigned long nodeid = objp[0]; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 540 | __u32 generation = objp[1]; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 541 | struct inode *inode; |
| 542 | struct dentry *entry; |
| 543 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 544 | if (nodeid == 0) |
Miklos Szeredi | a528879 | 2005-03-05 16:46:52 +0000 | [diff] [blame] | 545 | return ERR_PTR(-ESTALE); |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 546 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 547 | inode = ilookup5(sb, nodeid, fuse_inode_eq, &nodeid); |
Miklos Szeredi | f43f063 | 2005-02-28 11:46:56 +0000 | [diff] [blame] | 548 | if (!inode) |
Miklos Szeredi | a528879 | 2005-03-05 16:46:52 +0000 | [diff] [blame] | 549 | return ERR_PTR(-ESTALE); |
| 550 | if (inode->i_generation != generation) { |
| 551 | iput(inode); |
| 552 | return ERR_PTR(-ESTALE); |
| 553 | } |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 554 | |
| 555 | entry = d_alloc_anon(inode); |
Miklos Szeredi | a528879 | 2005-03-05 16:46:52 +0000 | [diff] [blame] | 556 | if (!entry) { |
| 557 | iput(inode); |
| 558 | return ERR_PTR(-ENOMEM); |
| 559 | } |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 560 | |
| 561 | return entry; |
| 562 | } |
| 563 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 564 | static int fuse_encode_fh(struct dentry *dentry, __u32 *fh, int *max_len, |
| 565 | int connectable) |
| 566 | { |
| 567 | struct inode *inode = dentry->d_inode; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 568 | int len = *max_len; |
| 569 | int type = 1; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 570 | |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 571 | if (len < 2 || (connectable && len < 4)) |
| 572 | return 255; |
| 573 | |
| 574 | len = 2; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 575 | fh[0] = get_fuse_inode(inode)->nodeid; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 576 | fh[1] = inode->i_generation; |
| 577 | if (connectable && !S_ISDIR(inode->i_mode)) { |
| 578 | struct inode *parent; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 579 | |
| 580 | spin_lock(&dentry->d_lock); |
| 581 | parent = dentry->d_parent->d_inode; |
Miklos Szeredi | 039322d | 2004-12-01 18:39:12 +0000 | [diff] [blame] | 582 | fh[2] = get_fuse_inode(parent)->nodeid; |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 583 | fh[3] = parent->i_generation; |
| 584 | spin_unlock(&dentry->d_lock); |
| 585 | len = 4; |
| 586 | type = 2; |
| 587 | } |
| 588 | *max_len = len; |
| 589 | return type; |
| 590 | } |
| 591 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 592 | static struct export_operations fuse_export_operations = { |
| 593 | .get_dentry = fuse_get_dentry, |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 594 | .encode_fh = fuse_encode_fh, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 595 | }; |
| 596 | #endif |
Miklos Szeredi | 1b18802 | 2005-07-28 11:07:29 +0000 | [diff] [blame] | 597 | #endif |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 598 | |
| 599 | static struct super_operations fuse_super_operations = { |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 600 | .alloc_inode = fuse_alloc_inode, |
| 601 | .destroy_inode = fuse_destroy_inode, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 602 | .read_inode = fuse_read_inode, |
| 603 | .clear_inode = fuse_clear_inode, |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 604 | .remount_fs = fuse_remount_fs, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 605 | .put_super = fuse_put_super, |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 606 | .umount_begin = fuse_umount_begin, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 607 | .statfs = fuse_statfs, |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 608 | .show_options = fuse_show_options, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 609 | }; |
| 610 | |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 611 | static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req) |
| 612 | { |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 613 | struct fuse_init_out *arg = &req->misc.init_out; |
| 614 | |
| 615 | if (req->out.h.error || arg->major != FUSE_KERNEL_VERSION) |
| 616 | fc->conn_error = 1; |
| 617 | else { |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 618 | #ifdef KERNEL_2_6 |
| 619 | unsigned long ra_pages; |
| 620 | |
| 621 | if (arg->minor >= 6) { |
| 622 | ra_pages = arg->max_readahead / PAGE_CACHE_SIZE; |
Miklos Szeredi | f827750 | 2006-01-20 17:16:27 +0000 | [diff] [blame] | 623 | if (arg->flags & FUSE_ASYNC_READ) |
| 624 | fc->async_read = 1; |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 625 | if (!(arg->flags & FUSE_POSIX_LOCKS)) |
| 626 | fc->no_lock = 1; |
| 627 | } else { |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 628 | ra_pages = fc->max_read / PAGE_CACHE_SIZE; |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 629 | fc->no_lock = 1; |
| 630 | } |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 631 | |
| 632 | fc->bdi.ra_pages = min(fc->bdi.ra_pages, ra_pages); |
| 633 | #endif |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 634 | fc->minor = arg->minor; |
| 635 | fc->max_write = arg->minor < 5 ? 4096 : arg->max_write; |
| 636 | } |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 637 | fuse_put_request(fc, req); |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 638 | fc->blocked = 0; |
| 639 | wake_up_all(&fc->blocked_waitq); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 642 | static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req) |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 643 | { |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 644 | struct fuse_init_in *arg = &req->misc.init_in; |
| 645 | |
| 646 | arg->major = FUSE_KERNEL_VERSION; |
| 647 | arg->minor = FUSE_KERNEL_MINOR_VERSION; |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 648 | #ifdef KERNEL_2_6 |
| 649 | arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE; |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 650 | arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS; |
Miklos Szeredi | 065f222 | 2006-01-20 15:15:21 +0000 | [diff] [blame] | 651 | #endif |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 652 | req->in.h.opcode = FUSE_INIT; |
| 653 | req->in.numargs = 1; |
| 654 | req->in.args[0].size = sizeof(*arg); |
| 655 | req->in.args[0].value = arg; |
| 656 | req->out.numargs = 1; |
| 657 | /* Variable length arguement used for backward compatibility |
| 658 | with interface version < 7.5. Rest of init_out is zeroed |
| 659 | by do_get_request(), so a short reply is not a problem */ |
| 660 | req->out.argvar = 1; |
| 661 | req->out.args[0].size = sizeof(struct fuse_init_out); |
| 662 | req->out.args[0].value = &req->misc.init_out; |
| 663 | req->end = process_init_reply; |
| 664 | request_send_background(fc, req); |
| 665 | } |
| 666 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 667 | static u64 conn_id(void) |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 668 | { |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 669 | static u64 ctr = 1; |
Miklos Szeredi | 67d26d4 | 2006-03-13 17:39:56 +0000 | [diff] [blame] | 670 | return ctr++; |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 671 | } |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 672 | |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 673 | 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] | 674 | { |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 675 | struct fuse_conn *fc; |
| 676 | struct inode *root; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 677 | struct fuse_mount_data d; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 678 | struct file *file; |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 679 | struct dentry *root_dentry; |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 680 | struct fuse_req *init_req; |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 681 | int err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 682 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 683 | if (sb->s_flags & MS_MANDLOCK) |
| 684 | return -EINVAL; |
| 685 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 686 | if (!parse_fuse_opt((char *) data, &d)) |
| 687 | return -EINVAL; |
| 688 | |
Miklos Szeredi | 377b2ea | 2004-02-06 09:48:51 +0000 | [diff] [blame] | 689 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 690 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 691 | sb->s_magic = FUSE_SUPER_MAGIC; |
| 692 | sb->s_op = &fuse_super_operations; |
| 693 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Miklos Szeredi | 1b18802 | 2005-07-28 11:07:29 +0000 | [diff] [blame] | 694 | #ifndef FUSE_MAINLINE |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 695 | #ifdef KERNEL_2_6 |
| 696 | sb->s_export_op = &fuse_export_operations; |
| 697 | #endif |
Miklos Szeredi | 1b18802 | 2005-07-28 11:07:29 +0000 | [diff] [blame] | 698 | #endif |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 699 | |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 700 | file = fget(d.fd); |
| 701 | if (!file) |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 702 | return -EINVAL; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 703 | |
Miklos Szeredi | 67d26d4 | 2006-03-13 17:39:56 +0000 | [diff] [blame] | 704 | if (file->f_op != &fuse_dev_operations) |
| 705 | return -EINVAL; |
| 706 | |
Miklos Szeredi | 67d26d4 | 2006-03-13 17:39:56 +0000 | [diff] [blame] | 707 | fc = new_conn(); |
| 708 | if (!fc) |
| 709 | return -ENOMEM; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 710 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 711 | fc->flags = d.flags; |
Miklos Szeredi | 3c7d41b | 2005-01-09 20:05:27 +0000 | [diff] [blame] | 712 | fc->user_id = d.user_id; |
Miklos Szeredi | 9c1b68d | 2005-04-28 09:55:09 +0000 | [diff] [blame] | 713 | fc->group_id = d.group_id; |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame] | 714 | fc->max_read = d.max_read; |
Miklos Szeredi | aa63b6b | 2004-12-03 13:24:35 +0000 | [diff] [blame] | 715 | |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 716 | /* Used by get_root_inode() */ |
| 717 | sb->s_fs_info = fc; |
| 718 | |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 719 | err = -ENOMEM; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 720 | root = get_root_inode(sb, d.rootmode); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 721 | if (!root) |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 722 | goto err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 723 | |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 724 | root_dentry = d_alloc_root(root); |
| 725 | if (!root_dentry) { |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 726 | iput(root); |
| 727 | goto err; |
| 728 | } |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 729 | |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 730 | init_req = fuse_request_alloc(); |
| 731 | if (!init_req) |
| 732 | goto err_put_root; |
| 733 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 734 | mutex_lock(&fuse_mutex); |
Miklos Szeredi | 5fe07d6 | 2006-04-21 14:09:28 +0000 | [diff] [blame] | 735 | err = -EINVAL; |
| 736 | if (file->private_data) |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 737 | goto err_unlock; |
Miklos Szeredi | 5fe07d6 | 2006-04-21 14:09:28 +0000 | [diff] [blame] | 738 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 739 | fc->id = conn_id(); |
| 740 | err = fuse_ctl_add_conn(fc); |
| 741 | if (err) |
| 742 | goto err_unlock; |
| 743 | |
| 744 | list_add_tail(&fc->entry, &fuse_conn_list); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 745 | sb->s_root = root_dentry; |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 746 | fc->connected = 1; |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 747 | file->private_data = fuse_conn_get(fc); |
| 748 | mutex_unlock(&fuse_mutex); |
Miklos Szeredi | 67d26d4 | 2006-03-13 17:39:56 +0000 | [diff] [blame] | 749 | /* |
| 750 | * atomic_dec_and_test() in fput() provides the necessary |
| 751 | * memory barrier for file->private_data to be visible on all |
| 752 | * CPUs after this |
| 753 | */ |
| 754 | fput(file); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 755 | |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 756 | fuse_send_init(fc, init_req); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 757 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 758 | return 0; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 759 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 760 | err_unlock: |
| 761 | mutex_unlock(&fuse_mutex); |
Miklos Szeredi | 7a2814c | 2006-04-12 10:41:50 +0000 | [diff] [blame] | 762 | fuse_request_free(init_req); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 763 | err_put_root: |
| 764 | dput(root_dentry); |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 765 | err: |
Miklos Szeredi | 67d26d4 | 2006-03-13 17:39:56 +0000 | [diff] [blame] | 766 | fput(file); |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 767 | fuse_conn_put(fc); |
Miklos Szeredi | 0f62d72 | 2005-01-04 12:45:54 +0000 | [diff] [blame] | 768 | return err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 771 | #ifdef KERNEL_2_6 |
Miklos Szeredi | ec3f6e4 | 2006-06-29 15:13:35 +0000 | [diff] [blame] | 772 | #ifdef KERNEL_2_6_18_PLUS |
| 773 | static int fuse_get_sb(struct file_system_type *fs_type, |
| 774 | int flags, const char *dev_name, |
| 775 | void *raw_data, struct vfsmount *mnt) |
| 776 | { |
| 777 | return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super, mnt); |
| 778 | } |
| 779 | #else |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 780 | 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] | 781 | int flags, const char *dev_name, |
| 782 | void *raw_data) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 783 | { |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 784 | return get_sb_nodev(fs_type, flags, raw_data, fuse_fill_super); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 785 | } |
Miklos Szeredi | ec3f6e4 | 2006-06-29 15:13:35 +0000 | [diff] [blame] | 786 | #endif |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 787 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 788 | static struct file_system_type fuse_fs_type = { |
Miklos Szeredi | 377b2ea | 2004-02-06 09:48:51 +0000 | [diff] [blame] | 789 | .owner = THIS_MODULE, |
| 790 | .name = "fuse", |
| 791 | .get_sb = fuse_get_sb, |
| 792 | .kill_sb = kill_anon_super, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 793 | }; |
| 794 | #else |
| 795 | static struct super_block *fuse_read_super_compat(struct super_block *sb, |
| 796 | void *data, int silent) |
| 797 | { |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 798 | int err = fuse_fill_super(sb, data, silent); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 799 | if (err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 800 | return NULL; |
| 801 | else |
| 802 | return sb; |
| 803 | } |
| 804 | |
| 805 | static DECLARE_FSTYPE(fuse_fs_type, "fuse", fuse_read_super_compat, 0); |
| 806 | #endif |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 807 | |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 808 | #ifdef KERNEL_2_6 |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 809 | #ifndef HAVE_FS_SUBSYS |
| 810 | static decl_subsys(fs, NULL, NULL); |
| 811 | #endif |
| 812 | static decl_subsys(fuse, NULL, NULL); |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 813 | static decl_subsys(connections, NULL, NULL); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 814 | #endif /* KERNEL_2_6 */ |
| 815 | |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 816 | static void fuse_inode_init_once(void *foo, kmem_cache_t *cachep, |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 817 | unsigned long flags) |
| 818 | { |
Miklos Szeredi | 13ed482 | 2004-11-20 11:12:21 +0000 | [diff] [blame] | 819 | struct inode * inode = foo; |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 820 | |
| 821 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == |
| 822 | SLAB_CTOR_CONSTRUCTOR) |
| 823 | inode_init_once(inode); |
| 824 | } |
| 825 | |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 826 | static int __init fuse_fs_init(void) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 827 | { |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 828 | int err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 829 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 830 | err = register_filesystem(&fuse_fs_type); |
| 831 | if (err) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 832 | printk("fuse: failed to register filesystem\n"); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 833 | else { |
| 834 | fuse_inode_cachep = kmem_cache_create("fuse_inode", |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 835 | sizeof(struct fuse_inode), |
Miklos Szeredi | a13d900 | 2004-11-02 17:32:03 +0000 | [diff] [blame] | 836 | 0, SLAB_HWCACHE_ALIGN, |
| 837 | fuse_inode_init_once, NULL); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 838 | if (!fuse_inode_cachep) { |
| 839 | unregister_filesystem(&fuse_fs_type); |
| 840 | err = -ENOMEM; |
| 841 | } |
| 842 | } |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 843 | |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 844 | return err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 847 | static void fuse_fs_cleanup(void) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 848 | { |
| 849 | unregister_filesystem(&fuse_fs_type); |
Miklos Szeredi | 069c950 | 2004-07-16 16:17:02 +0000 | [diff] [blame] | 850 | kmem_cache_destroy(fuse_inode_cachep); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 851 | } |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 852 | |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 853 | #ifdef KERNEL_2_6 |
| 854 | static int fuse_sysfs_init(void) |
| 855 | { |
| 856 | int err; |
| 857 | |
| 858 | #ifndef HAVE_FS_SUBSYS |
| 859 | err = subsystem_register(&fs_subsys); |
| 860 | if (err) |
| 861 | return err; |
| 862 | #endif |
| 863 | kset_set_kset_s(&fuse_subsys, fs_subsys); |
| 864 | err = subsystem_register(&fuse_subsys); |
| 865 | if (err) |
| 866 | goto out_err; |
| 867 | |
| 868 | kset_set_kset_s(&connections_subsys, fuse_subsys); |
| 869 | err = subsystem_register(&connections_subsys); |
| 870 | if (err) |
| 871 | goto out_fuse_unregister; |
| 872 | |
| 873 | return 0; |
| 874 | |
| 875 | out_fuse_unregister: |
| 876 | subsystem_unregister(&fuse_subsys); |
| 877 | out_err: |
| 878 | #ifndef HAVE_FS_SUBSYS |
| 879 | subsystem_unregister(&fs_subsys); |
| 880 | #endif |
| 881 | return err; |
| 882 | } |
| 883 | |
| 884 | static void fuse_sysfs_cleanup(void) |
| 885 | { |
| 886 | subsystem_unregister(&connections_subsys); |
| 887 | subsystem_unregister(&fuse_subsys); |
| 888 | #ifndef HAVE_FS_SUBSYS |
| 889 | subsystem_unregister(&fs_subsys); |
| 890 | #endif |
| 891 | } |
| 892 | #else /* KERNEL_2_6 */ |
| 893 | static int fuse_sysfs_init(void) |
| 894 | { |
| 895 | return 0; |
| 896 | } |
| 897 | static void fuse_sysfs_cleanup(void) |
| 898 | { |
| 899 | } |
| 900 | #endif /* KERNEL_2_6 */ |
| 901 | |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 902 | static int __init fuse_init(void) |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 903 | { |
| 904 | int res; |
| 905 | |
| 906 | printk("fuse init (API version %i.%i)\n", |
| 907 | FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION); |
| 908 | #ifndef FUSE_MAINLINE |
| 909 | printk("fuse distribution version: %s\n", FUSE_VERSION); |
| 910 | #endif |
| 911 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 912 | INIT_LIST_HEAD(&fuse_conn_list); |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 913 | res = fuse_fs_init(); |
| 914 | if (res) |
| 915 | goto err; |
| 916 | |
| 917 | res = fuse_dev_init(); |
| 918 | if (res) |
| 919 | goto err_fs_cleanup; |
| 920 | |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 921 | res = fuse_sysfs_init(); |
| 922 | if (res) |
| 923 | goto err_dev_cleanup; |
| 924 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 925 | res = fuse_ctl_init(); |
| 926 | if (res) |
| 927 | goto err_sysfs_cleanup; |
| 928 | |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 929 | return 0; |
| 930 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 931 | err_sysfs_cleanup: |
| 932 | fuse_sysfs_cleanup(); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 933 | err_dev_cleanup: |
| 934 | fuse_dev_cleanup(); |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 935 | err_fs_cleanup: |
| 936 | fuse_fs_cleanup(); |
| 937 | err: |
| 938 | return res; |
| 939 | } |
| 940 | |
Miklos Szeredi | 8139452 | 2005-01-11 14:24:18 +0000 | [diff] [blame] | 941 | static void __exit fuse_exit(void) |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 942 | { |
| 943 | printk(KERN_DEBUG "fuse exit\n"); |
| 944 | |
Miklos Szeredi | 91762cd | 2006-06-29 14:38:35 +0000 | [diff] [blame] | 945 | fuse_ctl_cleanup(); |
Miklos Szeredi | 15af1b8 | 2006-01-16 17:52:24 +0000 | [diff] [blame] | 946 | fuse_sysfs_cleanup(); |
Miklos Szeredi | 9080c79 | 2005-01-08 11:50:08 +0000 | [diff] [blame] | 947 | fuse_fs_cleanup(); |
| 948 | fuse_dev_cleanup(); |
| 949 | } |
| 950 | |
| 951 | module_init(fuse_init); |
| 952 | module_exit(fuse_exit); |