| .. | .. |
|---|
| 36 | 36 | #include <linux/magic.h> |
|---|
| 37 | 37 | #include <linux/slab.h> |
|---|
| 38 | 38 | #include <linux/uaccess.h> |
|---|
| 39 | +#include <linux/fs_context.h> |
|---|
| 40 | +#include <linux/fs_parser.h> |
|---|
| 39 | 41 | #include "internal.h" |
|---|
| 40 | 42 | |
|---|
| 41 | 43 | struct ramfs_mount_opts { |
|---|
| .. | .. |
|---|
| 175 | 177 | .show_options = ramfs_show_options, |
|---|
| 176 | 178 | }; |
|---|
| 177 | 179 | |
|---|
| 178 | | -enum { |
|---|
| 180 | +enum ramfs_param { |
|---|
| 179 | 181 | Opt_mode, |
|---|
| 180 | | - Opt_err |
|---|
| 181 | 182 | }; |
|---|
| 182 | 183 | |
|---|
| 183 | | -static const match_table_t tokens = { |
|---|
| 184 | | - {Opt_mode, "mode=%o"}, |
|---|
| 185 | | - {Opt_err, NULL} |
|---|
| 184 | +const struct fs_parameter_spec ramfs_fs_parameters[] = { |
|---|
| 185 | + fsparam_u32oct("mode", Opt_mode), |
|---|
| 186 | + {} |
|---|
| 186 | 187 | }; |
|---|
| 187 | 188 | |
|---|
| 188 | | -static int ramfs_parse_options(char *data, struct ramfs_mount_opts *opts) |
|---|
| 189 | +static int ramfs_parse_param(struct fs_context *fc, struct fs_parameter *param) |
|---|
| 189 | 190 | { |
|---|
| 190 | | - substring_t args[MAX_OPT_ARGS]; |
|---|
| 191 | | - int option; |
|---|
| 192 | | - int token; |
|---|
| 193 | | - char *p; |
|---|
| 191 | + struct fs_parse_result result; |
|---|
| 192 | + struct ramfs_fs_info *fsi = fc->s_fs_info; |
|---|
| 193 | + int opt; |
|---|
| 194 | 194 | |
|---|
| 195 | | - opts->mode = RAMFS_DEFAULT_MODE; |
|---|
| 196 | | - |
|---|
| 197 | | - while ((p = strsep(&data, ",")) != NULL) { |
|---|
| 198 | | - if (!*p) |
|---|
| 199 | | - continue; |
|---|
| 200 | | - |
|---|
| 201 | | - token = match_token(p, tokens, args); |
|---|
| 202 | | - switch (token) { |
|---|
| 203 | | - case Opt_mode: |
|---|
| 204 | | - if (match_octal(&args[0], &option)) |
|---|
| 205 | | - return -EINVAL; |
|---|
| 206 | | - opts->mode = option & S_IALLUGO; |
|---|
| 207 | | - break; |
|---|
| 195 | + opt = fs_parse(fc, ramfs_fs_parameters, param, &result); |
|---|
| 196 | + if (opt < 0) { |
|---|
| 208 | 197 | /* |
|---|
| 209 | 198 | * We might like to report bad mount options here; |
|---|
| 210 | 199 | * but traditionally ramfs has ignored all mount options, |
|---|
| 211 | 200 | * and as it is used as a !CONFIG_SHMEM simple substitute |
|---|
| 212 | 201 | * for tmpfs, better continue to ignore other mount options. |
|---|
| 213 | 202 | */ |
|---|
| 214 | | - } |
|---|
| 203 | + if (opt == -ENOPARAM) |
|---|
| 204 | + opt = 0; |
|---|
| 205 | + return opt; |
|---|
| 206 | + } |
|---|
| 207 | + |
|---|
| 208 | + switch (opt) { |
|---|
| 209 | + case Opt_mode: |
|---|
| 210 | + fsi->mount_opts.mode = result.uint_32 & S_IALLUGO; |
|---|
| 211 | + break; |
|---|
| 215 | 212 | } |
|---|
| 216 | 213 | |
|---|
| 217 | 214 | return 0; |
|---|
| 218 | 215 | } |
|---|
| 219 | 216 | |
|---|
| 220 | | -int ramfs_fill_super(struct super_block *sb, void *data, int silent) |
|---|
| 217 | +static int ramfs_fill_super(struct super_block *sb, struct fs_context *fc) |
|---|
| 221 | 218 | { |
|---|
| 222 | | - struct ramfs_fs_info *fsi; |
|---|
| 219 | + struct ramfs_fs_info *fsi = sb->s_fs_info; |
|---|
| 223 | 220 | struct inode *inode; |
|---|
| 224 | | - int err; |
|---|
| 225 | | - |
|---|
| 226 | | - fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL); |
|---|
| 227 | | - sb->s_fs_info = fsi; |
|---|
| 228 | | - if (!fsi) |
|---|
| 229 | | - return -ENOMEM; |
|---|
| 230 | | - |
|---|
| 231 | | - err = ramfs_parse_options(data, &fsi->mount_opts); |
|---|
| 232 | | - if (err) |
|---|
| 233 | | - return err; |
|---|
| 234 | 221 | |
|---|
| 235 | 222 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
|---|
| 236 | 223 | sb->s_blocksize = PAGE_SIZE; |
|---|
| .. | .. |
|---|
| 247 | 234 | return 0; |
|---|
| 248 | 235 | } |
|---|
| 249 | 236 | |
|---|
| 250 | | -struct dentry *ramfs_mount(struct file_system_type *fs_type, |
|---|
| 251 | | - int flags, const char *dev_name, void *data) |
|---|
| 237 | +static int ramfs_get_tree(struct fs_context *fc) |
|---|
| 252 | 238 | { |
|---|
| 253 | | - return mount_nodev(fs_type, flags, data, ramfs_fill_super); |
|---|
| 239 | + return get_tree_nodev(fc, ramfs_fill_super); |
|---|
| 254 | 240 | } |
|---|
| 255 | 241 | |
|---|
| 256 | | -static void ramfs_kill_sb(struct super_block *sb) |
|---|
| 242 | +static void ramfs_free_fc(struct fs_context *fc) |
|---|
| 243 | +{ |
|---|
| 244 | + kfree(fc->s_fs_info); |
|---|
| 245 | +} |
|---|
| 246 | + |
|---|
| 247 | +static const struct fs_context_operations ramfs_context_ops = { |
|---|
| 248 | + .free = ramfs_free_fc, |
|---|
| 249 | + .parse_param = ramfs_parse_param, |
|---|
| 250 | + .get_tree = ramfs_get_tree, |
|---|
| 251 | +}; |
|---|
| 252 | + |
|---|
| 253 | +int ramfs_init_fs_context(struct fs_context *fc) |
|---|
| 254 | +{ |
|---|
| 255 | + struct ramfs_fs_info *fsi; |
|---|
| 256 | + |
|---|
| 257 | + fsi = kzalloc(sizeof(*fsi), GFP_KERNEL); |
|---|
| 258 | + if (!fsi) |
|---|
| 259 | + return -ENOMEM; |
|---|
| 260 | + |
|---|
| 261 | + fsi->mount_opts.mode = RAMFS_DEFAULT_MODE; |
|---|
| 262 | + fc->s_fs_info = fsi; |
|---|
| 263 | + fc->ops = &ramfs_context_ops; |
|---|
| 264 | + return 0; |
|---|
| 265 | +} |
|---|
| 266 | + |
|---|
| 267 | +void ramfs_kill_sb(struct super_block *sb) |
|---|
| 257 | 268 | { |
|---|
| 258 | 269 | kfree(sb->s_fs_info); |
|---|
| 259 | 270 | kill_litter_super(sb); |
|---|
| .. | .. |
|---|
| 261 | 272 | |
|---|
| 262 | 273 | static struct file_system_type ramfs_fs_type = { |
|---|
| 263 | 274 | .name = "ramfs", |
|---|
| 264 | | - .mount = ramfs_mount, |
|---|
| 275 | + .init_fs_context = ramfs_init_fs_context, |
|---|
| 276 | + .parameters = ramfs_fs_parameters, |
|---|
| 265 | 277 | .kill_sb = ramfs_kill_sb, |
|---|
| 266 | 278 | .fs_flags = FS_USERNS_MOUNT, |
|---|
| 267 | 279 | }; |
|---|
| 268 | 280 | |
|---|
| 269 | | -int __init init_ramfs_fs(void) |
|---|
| 281 | +static int __init init_ramfs_fs(void) |
|---|
| 270 | 282 | { |
|---|
| 271 | | - static unsigned long once; |
|---|
| 272 | | - |
|---|
| 273 | | - if (test_and_set_bit(0, &once)) |
|---|
| 274 | | - return 0; |
|---|
| 275 | 283 | return register_filesystem(&ramfs_fs_type); |
|---|
| 276 | 284 | } |
|---|
| 277 | 285 | fs_initcall(init_ramfs_fs); |
|---|