Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | FUSE: Filesystem in Userspace |
| 3 | Copyright (C) 2001 Miklos Szeredi (mszeredi@inf.bme.hu) |
| 4 | |
| 5 | This program can be distributed under the terms of the GNU GPL. |
| 6 | See the file COPYING. |
| 7 | */ |
| 8 | |
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 | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 12 | #include <linux/sched.h> |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 13 | #include <linux/slab.h> |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 14 | #include <linux/file.h> |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 15 | #include <linux/mount.h> |
Miklos Szeredi | 60c2352 | 2002-10-24 09:19:43 +0000 | [diff] [blame] | 16 | #include <linux/proc_fs.h> |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 17 | #include <linux/seq_file.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 | |
| 25 | #define FUSE_SUPER_MAGIC 0x65735546 |
| 26 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 27 | #ifndef KERNEL_2_6 |
| 28 | #define kstatfs statfs |
| 29 | #endif |
| 30 | |
Miklos Szeredi | 69cc79a | 2004-02-17 08:57:29 +0000 | [diff] [blame] | 31 | #ifndef FS_SAFE |
| 32 | #define FS_SAFE 0 |
| 33 | #endif |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 34 | |
| 35 | struct fuse_mount_data { |
| 36 | int fd; |
| 37 | unsigned int rootmode; |
| 38 | unsigned int uid; |
| 39 | unsigned int flags; |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame^] | 40 | unsigned int max_read; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 41 | }; |
Miklos Szeredi | 69cc79a | 2004-02-17 08:57:29 +0000 | [diff] [blame] | 42 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 43 | static void fuse_read_inode(struct inode *inode) |
| 44 | { |
Miklos Szeredi | 90d8bef | 2001-10-26 14:55:42 +0000 | [diff] [blame] | 45 | /* No op */ |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Miklos Szeredi | 2778f6c | 2004-06-21 09:45:30 +0000 | [diff] [blame] | 48 | void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req, ino_t ino, |
| 49 | int version) |
| 50 | { |
| 51 | struct fuse_forget_in *inarg = &req->misc.forget_in; |
| 52 | inarg->version = version; |
| 53 | req->in.h.opcode = FUSE_FORGET; |
| 54 | req->in.h.ino = ino; |
| 55 | req->in.numargs = 1; |
| 56 | req->in.args[0].size = sizeof(struct fuse_forget_in); |
| 57 | req->in.args[0].value = inarg; |
| 58 | request_send_noreply(fc, req); |
| 59 | } |
| 60 | |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 61 | static void fuse_clear_inode(struct inode *inode) |
| 62 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 63 | struct fuse_conn *fc = INO_FC(inode); |
Miklos Szeredi | d3dd2d5 | 2004-06-22 18:46:02 +0000 | [diff] [blame] | 64 | struct fuse_req *req = inode->u.generic_ip; |
Miklos Szeredi | a181e61 | 2001-11-06 12:03:23 +0000 | [diff] [blame] | 65 | |
Miklos Szeredi | d3dd2d5 | 2004-06-22 18:46:02 +0000 | [diff] [blame] | 66 | if (fc == NULL) { |
| 67 | if (req) |
| 68 | fuse_request_free(req); |
Miklos Szeredi | 4369643 | 2001-11-18 19:15:05 +0000 | [diff] [blame] | 69 | return; |
Miklos Szeredi | d3dd2d5 | 2004-06-22 18:46:02 +0000 | [diff] [blame] | 70 | } |
| 71 | if (req != NULL) |
| 72 | fuse_send_forget(fc, req, inode->i_ino, inode->i_version); |
Miklos Szeredi | 85c74fc | 2001-10-28 19:44:14 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 75 | static void fuse_put_super(struct super_block *sb) |
| 76 | { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 77 | struct fuse_conn *fc = SB_FC(sb); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 78 | |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 79 | spin_lock(&fuse_lock); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 80 | fc->sb = NULL; |
Miklos Szeredi | 8cffdb9 | 2001-11-09 14:49:18 +0000 | [diff] [blame] | 81 | fc->uid = 0; |
| 82 | fc->flags = 0; |
Miklos Szeredi | 9624998 | 2001-11-21 12:21:19 +0000 | [diff] [blame] | 83 | /* Flush all readers on this fs */ |
| 84 | wake_up_all(&fc->waitq); |
Miklos Szeredi | 79b461a | 2003-03-10 09:35:34 +0000 | [diff] [blame] | 85 | fuse_release_conn(fc); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 86 | SB_FC(sb) = NULL; |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 87 | spin_unlock(&fuse_lock); |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 90 | static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr) |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 91 | { |
| 92 | stbuf->f_type = FUSE_SUPER_MAGIC; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 93 | stbuf->f_bsize = attr->bsize; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 94 | stbuf->f_blocks = attr->blocks; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 95 | stbuf->f_bfree = attr->bfree; |
| 96 | stbuf->f_bavail = attr->bavail; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 97 | stbuf->f_files = attr->files; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 98 | stbuf->f_ffree = attr->ffree; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 99 | stbuf->f_namelen = attr->namelen; |
Miklos Szeredi | 18e75e4 | 2004-02-19 14:23:27 +0000 | [diff] [blame] | 100 | /* fsid is left zero */ |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 103 | static int fuse_statfs(struct super_block *sb, struct kstatfs *buf) |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 104 | { |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 105 | struct fuse_conn *fc = SB_FC(sb); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 106 | struct fuse_req *req; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 107 | struct fuse_statfs_out outarg; |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 108 | int err; |
| 109 | |
| 110 | req = fuse_get_request(fc); |
| 111 | if (!req) |
| 112 | return -ERESTARTSYS; |
| 113 | |
| 114 | req->in.numargs = 0; |
| 115 | req->in.h.opcode = FUSE_STATFS; |
| 116 | req->out.numargs = 1; |
| 117 | req->out.args[0].size = sizeof(outarg); |
| 118 | req->out.args[0].value = &outarg; |
| 119 | request_send(fc, req); |
| 120 | err = req->out.h.error; |
| 121 | if (!err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 122 | convert_fuse_statfs(buf, &outarg.st); |
Miklos Szeredi | 7eafcce | 2004-06-19 22:42:38 +0000 | [diff] [blame] | 123 | fuse_put_request(fc, req); |
| 124 | return err; |
Mark Glines | d84b39a | 2002-01-07 16:32:02 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 127 | enum { opt_fd, opt_rootmode, opt_uid, opt_default_permissions, |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame^] | 128 | opt_allow_other, opt_kernel_cache, opt_large_read, opt_direct_io, |
| 129 | opt_max_read, opt_err }; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 130 | |
| 131 | static match_table_t tokens = { |
| 132 | {opt_fd, "fd=%u"}, |
| 133 | {opt_rootmode, "rootmode=%o"}, |
| 134 | {opt_uid, "uid=%u"}, |
| 135 | {opt_default_permissions, "default_permissions"}, |
| 136 | {opt_allow_other, "allow_other"}, |
| 137 | {opt_kernel_cache, "kernel_cache"}, |
| 138 | {opt_large_read, "large_read"}, |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame^] | 139 | {opt_direct_io, "direct_io"}, |
| 140 | {opt_max_read, "max_read" }, |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 141 | {opt_err, NULL} |
| 142 | }; |
| 143 | |
| 144 | static int parse_fuse_opt(char *opt, struct fuse_mount_data *d) |
| 145 | { |
| 146 | char *p; |
| 147 | memset(d, 0, sizeof(struct fuse_mount_data)); |
| 148 | d->fd = -1; |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame^] | 149 | d->max_read = ~0; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 150 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 151 | while ((p = strsep(&opt, ",")) != NULL) { |
| 152 | int token; |
| 153 | int value; |
| 154 | substring_t args[MAX_OPT_ARGS]; |
| 155 | if (!*p) |
| 156 | continue; |
| 157 | |
| 158 | token = match_token(p, tokens, args); |
| 159 | switch (token) { |
| 160 | case opt_fd: |
| 161 | if (match_int(&args[0], &value)) |
| 162 | return 0; |
| 163 | d->fd = value; |
| 164 | break; |
| 165 | |
| 166 | case opt_rootmode: |
| 167 | if (match_octal(&args[0], &value)) |
| 168 | return 0; |
| 169 | d->rootmode = value; |
| 170 | break; |
| 171 | |
| 172 | case opt_uid: |
| 173 | if (match_int(&args[0], &value)) |
| 174 | return 0; |
| 175 | d->uid = value; |
| 176 | break; |
| 177 | |
| 178 | case opt_default_permissions: |
| 179 | d->flags |= FUSE_DEFAULT_PERMISSIONS; |
| 180 | break; |
| 181 | |
| 182 | case opt_allow_other: |
| 183 | d->flags |= FUSE_ALLOW_OTHER; |
| 184 | break; |
| 185 | |
| 186 | case opt_kernel_cache: |
| 187 | d->flags |= FUSE_KERNEL_CACHE; |
| 188 | break; |
| 189 | |
| 190 | case opt_large_read: |
| 191 | d->flags |= FUSE_LARGE_READ; |
| 192 | break; |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame^] | 193 | |
| 194 | case opt_direct_io: |
| 195 | d->flags |= FUSE_DIRECT_IO; |
| 196 | break; |
| 197 | |
| 198 | case opt_max_read: |
| 199 | if (match_int(&args[0], &value)) |
| 200 | return 0; |
| 201 | d->max_read = value; |
| 202 | break; |
| 203 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 204 | default: |
| 205 | return 0; |
| 206 | } |
| 207 | } |
| 208 | if (d->fd == -1) |
| 209 | return 0; |
| 210 | |
| 211 | return 1; |
| 212 | } |
| 213 | |
| 214 | static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 215 | { |
| 216 | struct fuse_conn *fc = SB_FC(mnt->mnt_sb); |
| 217 | |
| 218 | seq_printf(m, ",uid=%u", fc->uid); |
| 219 | if (fc->flags & FUSE_DEFAULT_PERMISSIONS) |
| 220 | seq_puts(m, ",default_permissions"); |
| 221 | if (fc->flags & FUSE_ALLOW_OTHER) |
| 222 | seq_puts(m, ",allow_other"); |
| 223 | if (fc->flags & FUSE_KERNEL_CACHE) |
| 224 | seq_puts(m, ",kernel_cache"); |
| 225 | if (fc->flags & FUSE_LARGE_READ) |
| 226 | seq_puts(m, ",large_read"); |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame^] | 227 | if (fc->flags & FUSE_DIRECT_IO) |
| 228 | seq_puts(m, ",direct_io"); |
| 229 | if (fc->max_read != ~0) |
| 230 | seq_printf(m, ",max_read=%u", fc->max_read); |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 234 | 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] | 235 | { |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 236 | struct fuse_conn *fc; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 237 | struct inode *ino; |
| 238 | |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 239 | ino = file->f_dentry->d_inode; |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 240 | if (!ino || !proc_fuse_dev || proc_fuse_dev->low_ino != ino->i_ino) { |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 241 | printk("FUSE: bad communication file descriptor\n"); |
| 242 | return NULL; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 243 | } |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 244 | fc = file->private_data; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 245 | if (fc->sb != NULL) { |
| 246 | printk("fuse_read_super: connection already mounted\n"); |
| 247 | return NULL; |
| 248 | } |
| 249 | fc->sb = sb; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 250 | return fc; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 253 | static struct inode *get_root_inode(struct super_block *sb, unsigned int mode) |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 254 | { |
Miklos Szeredi | 5e18348 | 2001-10-31 14:52:35 +0000 | [diff] [blame] | 255 | struct fuse_attr attr; |
| 256 | memset(&attr, 0, sizeof(attr)); |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 257 | |
Miklos Szeredi | 2df1c04 | 2001-11-06 15:07:17 +0000 | [diff] [blame] | 258 | attr.mode = mode; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 259 | return fuse_iget(sb, 1, 0, &attr, 0); |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 262 | |
| 263 | #ifdef KERNEL_2_6 |
| 264 | |
| 265 | static struct dentry *fuse_get_dentry(struct super_block *sb, void *vobjp) |
| 266 | { |
| 267 | __u32 *objp = vobjp; |
| 268 | unsigned long ino = objp[0]; |
Miklos Szeredi | 76f6578 | 2004-02-19 16:55:40 +0000 | [diff] [blame] | 269 | __u32 generation = objp[1]; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 270 | struct inode *inode; |
| 271 | struct dentry *entry; |
| 272 | |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 273 | if (ino == 0) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 274 | return ERR_PTR(-ESTALE); |
| 275 | |
| 276 | inode = ilookup(sb, ino); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 277 | if (!inode || inode->i_generation != generation) |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 278 | return ERR_PTR(-ESTALE); |
| 279 | |
| 280 | entry = d_alloc_anon(inode); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 281 | if (!entry) { |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 282 | iput(inode); |
| 283 | return ERR_PTR(-ENOMEM); |
| 284 | } |
| 285 | |
| 286 | return entry; |
| 287 | } |
| 288 | |
| 289 | static struct export_operations fuse_export_operations = { |
| 290 | .get_dentry = fuse_get_dentry, |
| 291 | }; |
| 292 | #endif |
| 293 | |
| 294 | static struct super_operations fuse_super_operations = { |
| 295 | .read_inode = fuse_read_inode, |
| 296 | .clear_inode = fuse_clear_inode, |
| 297 | .put_super = fuse_put_super, |
| 298 | .statfs = fuse_statfs, |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 299 | .show_options = fuse_show_options, |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 300 | }; |
| 301 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 302 | static int fuse_read_super(struct super_block *sb, void *data, int silent) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 303 | { |
| 304 | struct fuse_conn *fc; |
| 305 | struct inode *root; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 306 | struct fuse_mount_data d; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 307 | struct file *file; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 308 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 309 | if (!parse_fuse_opt((char *) data, &d)) |
| 310 | return -EINVAL; |
| 311 | |
| 312 | if ((d.flags & FUSE_ALLOW_OTHER) && !capable(CAP_SYS_ADMIN)) |
| 313 | return -EPERM; |
Miklos Szeredi | 69cc79a | 2004-02-17 08:57:29 +0000 | [diff] [blame] | 314 | |
Miklos Szeredi | 377b2ea | 2004-02-06 09:48:51 +0000 | [diff] [blame] | 315 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 316 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 317 | sb->s_magic = FUSE_SUPER_MAGIC; |
| 318 | sb->s_op = &fuse_super_operations; |
| 319 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
Miklos Szeredi | e815c03 | 2004-01-19 18:20:49 +0000 | [diff] [blame] | 320 | #ifdef KERNEL_2_6 |
| 321 | sb->s_export_op = &fuse_export_operations; |
| 322 | #endif |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 323 | |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 324 | file = fget(d.fd); |
| 325 | if (!file) |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 326 | return -EINVAL; |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 327 | |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 328 | spin_lock(&fuse_lock); |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 329 | fc = get_conn(file, sb); |
| 330 | spin_unlock(&fuse_lock); |
| 331 | fput(file); |
| 332 | if (fc == NULL) |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 333 | return -EINVAL; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 334 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 335 | fc->flags = d.flags; |
| 336 | fc->uid = d.uid; |
Miklos Szeredi | ad051c3 | 2004-07-02 09:22:50 +0000 | [diff] [blame^] | 337 | fc->max_read = d.max_read; |
| 338 | fc->max_write = FUSE_MAX_IN / 2; |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 339 | |
| 340 | /* fc is needed in fuse_init_file_inode which could be called |
Miklos Szeredi | 377b2ea | 2004-02-06 09:48:51 +0000 | [diff] [blame] | 341 | from get_root_inode */ |
Miklos Szeredi | 307242f | 2004-01-26 11:28:44 +0000 | [diff] [blame] | 342 | SB_FC(sb) = fc; |
| 343 | |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 344 | root = get_root_inode(sb, d.rootmode); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 345 | if (root == NULL) { |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 346 | printk("fuse_read_super: failed to get root inode\n"); |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 347 | goto err; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Miklos Szeredi | 79b52f6 | 2001-10-24 14:37:13 +0000 | [diff] [blame] | 350 | sb->s_root = d_alloc_root(root); |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 351 | if (!sb->s_root) { |
| 352 | iput(root); |
| 353 | goto err; |
| 354 | } |
Miklos Szeredi | 19dff1b | 2001-10-30 15:06:52 +0000 | [diff] [blame] | 355 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 356 | return 0; |
Miklos Szeredi | ed62d86 | 2004-06-20 08:57:39 +0000 | [diff] [blame] | 357 | |
| 358 | err: |
| 359 | spin_lock(&fuse_lock); |
| 360 | fc->sb = NULL; |
| 361 | fuse_release_conn(fc); |
| 362 | spin_unlock(&fuse_lock); |
| 363 | SB_FC(sb) = NULL; |
| 364 | return -EINVAL; |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 367 | #ifdef KERNEL_2_6 |
| 368 | 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] | 369 | int flags, const char *dev_name, |
| 370 | void *raw_data) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 371 | { |
Miklos Szeredi | 377b2ea | 2004-02-06 09:48:51 +0000 | [diff] [blame] | 372 | return get_sb_nodev(fs_type, flags, raw_data, fuse_read_super); |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 373 | } |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 374 | |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 375 | static struct file_system_type fuse_fs_type = { |
Miklos Szeredi | 377b2ea | 2004-02-06 09:48:51 +0000 | [diff] [blame] | 376 | .owner = THIS_MODULE, |
| 377 | .name = "fuse", |
| 378 | .get_sb = fuse_get_sb, |
| 379 | .kill_sb = kill_anon_super, |
Miklos Szeredi | 7f6bc89 | 2004-04-13 10:49:14 +0000 | [diff] [blame] | 380 | .fs_flags = FS_SAFE, |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 381 | }; |
| 382 | #else |
| 383 | static struct super_block *fuse_read_super_compat(struct super_block *sb, |
| 384 | void *data, int silent) |
| 385 | { |
| 386 | int err = fuse_read_super(sb, data, silent); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 387 | if (err) |
Miklos Szeredi | f85ab24 | 2004-01-07 12:16:45 +0000 | [diff] [blame] | 388 | return NULL; |
| 389 | else |
| 390 | return sb; |
| 391 | } |
| 392 | |
| 393 | static DECLARE_FSTYPE(fuse_fs_type, "fuse", fuse_read_super_compat, 0); |
| 394 | #endif |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 395 | |
| 396 | int fuse_fs_init() |
| 397 | { |
| 398 | int res; |
| 399 | |
| 400 | res = register_filesystem(&fuse_fs_type); |
Miklos Szeredi | c26c14d | 2004-04-09 17:48:32 +0000 | [diff] [blame] | 401 | if (res) |
Miklos Szeredi | bc22e7b | 2001-10-23 19:26:04 +0000 | [diff] [blame] | 402 | printk("fuse: failed to register filesystem\n"); |
| 403 | |
| 404 | return res; |
| 405 | } |
| 406 | |
| 407 | void fuse_fs_cleanup() |
| 408 | { |
| 409 | unregister_filesystem(&fuse_fs_type); |
| 410 | } |
| 411 | |
| 412 | /* |
| 413 | * Local Variables: |
| 414 | * indent-tabs-mode: t |
| 415 | * c-basic-offset: 8 |
Miklos Szeredi | 63a63bc | 2001-12-02 20:37:53 +0000 | [diff] [blame] | 416 | * End: |
| 417 | */ |