|
6 | 6 | */
|
7 | 7 | #include <linux/module.h>
|
8 | 8 | #include <linux/init.h>
|
9 |
| -#include <linux/parser.h> |
| 9 | +#include <linux/fs_parser.h> |
| 10 | +#include <linux/fs_context.h> |
10 | 11 | #include <linux/mount.h>
|
11 | 12 | #include <linux/seq_file.h>
|
12 | 13 | #include <linux/slab.h>
|
@@ -115,87 +116,61 @@ static int adfs_show_options(struct seq_file *seq, struct dentry *root)
|
115 | 116 | return 0;
|
116 | 117 | }
|
117 | 118 |
|
118 |
| -enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_ftsuffix, Opt_err}; |
| 119 | +enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_ftsuffix}; |
119 | 120 |
|
120 |
| -static const match_table_t tokens = { |
121 |
| - {Opt_uid, "uid=%u"}, |
122 |
| - {Opt_gid, "gid=%u"}, |
123 |
| - {Opt_ownmask, "ownmask=%o"}, |
124 |
| - {Opt_othmask, "othmask=%o"}, |
125 |
| - {Opt_ftsuffix, "ftsuffix=%u"}, |
126 |
| - {Opt_err, NULL} |
| 121 | +static const struct fs_parameter_spec adfs_param_spec[] = { |
| 122 | + fsparam_uid ("uid", Opt_uid), |
| 123 | + fsparam_gid ("gid", Opt_gid), |
| 124 | + fsparam_u32oct ("ownmask", Opt_ownmask), |
| 125 | + fsparam_u32oct ("othmask", Opt_othmask), |
| 126 | + fsparam_u32 ("ftsuffix", Opt_ftsuffix), |
| 127 | + {} |
127 | 128 | };
|
128 | 129 |
|
129 |
| -static int parse_options(struct super_block *sb, struct adfs_sb_info *asb, |
130 |
| - char *options) |
| 130 | +static int adfs_parse_param(struct fs_context *fc, struct fs_parameter *param) |
131 | 131 | {
|
132 |
| - char *p; |
133 |
| - int option; |
134 |
| - |
135 |
| - if (!options) |
136 |
| - return 0; |
137 |
| - |
138 |
| - while ((p = strsep(&options, ",")) != NULL) { |
139 |
| - substring_t args[MAX_OPT_ARGS]; |
140 |
| - int token; |
141 |
| - if (!*p) |
142 |
| - continue; |
143 |
| - |
144 |
| - token = match_token(p, tokens, args); |
145 |
| - switch (token) { |
146 |
| - case Opt_uid: |
147 |
| - if (match_int(args, &option)) |
148 |
| - return -EINVAL; |
149 |
| - asb->s_uid = make_kuid(current_user_ns(), option); |
150 |
| - if (!uid_valid(asb->s_uid)) |
151 |
| - return -EINVAL; |
152 |
| - break; |
153 |
| - case Opt_gid: |
154 |
| - if (match_int(args, &option)) |
155 |
| - return -EINVAL; |
156 |
| - asb->s_gid = make_kgid(current_user_ns(), option); |
157 |
| - if (!gid_valid(asb->s_gid)) |
158 |
| - return -EINVAL; |
159 |
| - break; |
160 |
| - case Opt_ownmask: |
161 |
| - if (match_octal(args, &option)) |
162 |
| - return -EINVAL; |
163 |
| - asb->s_owner_mask = option; |
164 |
| - break; |
165 |
| - case Opt_othmask: |
166 |
| - if (match_octal(args, &option)) |
167 |
| - return -EINVAL; |
168 |
| - asb->s_other_mask = option; |
169 |
| - break; |
170 |
| - case Opt_ftsuffix: |
171 |
| - if (match_int(args, &option)) |
172 |
| - return -EINVAL; |
173 |
| - asb->s_ftsuffix = option; |
174 |
| - break; |
175 |
| - default: |
176 |
| - adfs_msg(sb, KERN_ERR, |
177 |
| - "unrecognised mount option \"%s\" or missing value", |
178 |
| - p); |
179 |
| - return -EINVAL; |
180 |
| - } |
| 132 | + struct adfs_sb_info *asb = fc->s_fs_info; |
| 133 | + struct fs_parse_result result; |
| 134 | + int opt; |
| 135 | + |
| 136 | + opt = fs_parse(fc, adfs_param_spec, param, &result); |
| 137 | + if (opt < 0) |
| 138 | + return opt; |
| 139 | + |
| 140 | + switch (opt) { |
| 141 | + case Opt_uid: |
| 142 | + asb->s_uid = result.uid; |
| 143 | + break; |
| 144 | + case Opt_gid: |
| 145 | + asb->s_gid = result.gid; |
| 146 | + break; |
| 147 | + case Opt_ownmask: |
| 148 | + asb->s_owner_mask = result.uint_32; |
| 149 | + break; |
| 150 | + case Opt_othmask: |
| 151 | + asb->s_other_mask = result.uint_32; |
| 152 | + break; |
| 153 | + case Opt_ftsuffix: |
| 154 | + asb->s_ftsuffix = result.uint_32; |
| 155 | + break; |
| 156 | + default: |
| 157 | + return -EINVAL; |
181 | 158 | }
|
182 | 159 | return 0;
|
183 | 160 | }
|
184 | 161 |
|
185 |
| -static int adfs_remount(struct super_block *sb, int *flags, char *data) |
| 162 | +static int adfs_reconfigure(struct fs_context *fc) |
186 | 163 | {
|
187 |
| - struct adfs_sb_info temp_asb; |
188 |
| - int ret; |
| 164 | + struct adfs_sb_info *new_asb = fc->s_fs_info; |
| 165 | + struct adfs_sb_info *asb = ADFS_SB(fc->root->d_sb); |
189 | 166 |
|
190 |
| - sync_filesystem(sb); |
191 |
| - *flags |= ADFS_SB_FLAGS; |
| 167 | + sync_filesystem(fc->root->d_sb); |
| 168 | + fc->sb_flags |= ADFS_SB_FLAGS; |
192 | 169 |
|
193 |
| - temp_asb = *ADFS_SB(sb); |
194 |
| - ret = parse_options(sb, &temp_asb, data); |
195 |
| - if (ret == 0) |
196 |
| - *ADFS_SB(sb) = temp_asb; |
| 170 | + /* Structure copy newly parsed options */ |
| 171 | + *asb = *new_asb; |
197 | 172 |
|
198 |
| - return ret; |
| 173 | + return 0; |
199 | 174 | }
|
200 | 175 |
|
201 | 176 | static int adfs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
@@ -273,7 +248,6 @@ static const struct super_operations adfs_sops = {
|
273 | 248 | .write_inode = adfs_write_inode,
|
274 | 249 | .put_super = adfs_put_super,
|
275 | 250 | .statfs = adfs_statfs,
|
276 |
| - .remount_fs = adfs_remount, |
277 | 251 | .show_options = adfs_show_options,
|
278 | 252 | };
|
279 | 253 |
|
@@ -361,34 +335,21 @@ static int adfs_validate_dr0(struct super_block *sb, struct buffer_head *bh,
|
361 | 335 | return 0;
|
362 | 336 | }
|
363 | 337 |
|
364 |
| -static int adfs_fill_super(struct super_block *sb, void *data, int silent) |
| 338 | +static int adfs_fill_super(struct super_block *sb, struct fs_context *fc) |
365 | 339 | {
|
366 | 340 | struct adfs_discrecord *dr;
|
367 | 341 | struct object_info root_obj;
|
368 |
| - struct adfs_sb_info *asb; |
| 342 | + struct adfs_sb_info *asb = sb->s_fs_info; |
369 | 343 | struct inode *root;
|
370 | 344 | int ret = -EINVAL;
|
| 345 | + int silent = fc->sb_flags & SB_SILENT; |
371 | 346 |
|
372 | 347 | sb->s_flags |= ADFS_SB_FLAGS;
|
373 | 348 |
|
374 |
| - asb = kzalloc(sizeof(*asb), GFP_KERNEL); |
375 |
| - if (!asb) |
376 |
| - return -ENOMEM; |
377 |
| - |
378 | 349 | sb->s_fs_info = asb;
|
379 | 350 | sb->s_magic = ADFS_SUPER_MAGIC;
|
380 | 351 | sb->s_time_gran = 10000000;
|
381 | 352 |
|
382 |
| - /* set default options */ |
383 |
| - asb->s_uid = GLOBAL_ROOT_UID; |
384 |
| - asb->s_gid = GLOBAL_ROOT_GID; |
385 |
| - asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK; |
386 |
| - asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK; |
387 |
| - asb->s_ftsuffix = 0; |
388 |
| - |
389 |
| - if (parse_options(sb, asb, data)) |
390 |
| - goto error; |
391 |
| - |
392 | 353 | /* Try to probe the filesystem boot block */
|
393 | 354 | ret = adfs_probe(sb, ADFS_DISCRECORD, 1, adfs_validate_bblk);
|
394 | 355 | if (ret == -EILSEQ)
|
@@ -453,18 +414,61 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
|
453 | 414 | return ret;
|
454 | 415 | }
|
455 | 416 |
|
456 |
| -static struct dentry *adfs_mount(struct file_system_type *fs_type, |
457 |
| - int flags, const char *dev_name, void *data) |
| 417 | +static int adfs_get_tree(struct fs_context *fc) |
| 418 | +{ |
| 419 | + return get_tree_bdev(fc, adfs_fill_super); |
| 420 | +} |
| 421 | + |
| 422 | +static void adfs_free_fc(struct fs_context *fc) |
458 | 423 | {
|
459 |
| - return mount_bdev(fs_type, flags, dev_name, data, adfs_fill_super); |
| 424 | + struct adfs_context *asb = fc->s_fs_info; |
| 425 | + |
| 426 | + kfree(asb); |
| 427 | +} |
| 428 | + |
| 429 | +static const struct fs_context_operations adfs_context_ops = { |
| 430 | + .parse_param = adfs_parse_param, |
| 431 | + .get_tree = adfs_get_tree, |
| 432 | + .reconfigure = adfs_reconfigure, |
| 433 | + .free = adfs_free_fc, |
| 434 | +}; |
| 435 | + |
| 436 | +static int adfs_init_fs_context(struct fs_context *fc) |
| 437 | +{ |
| 438 | + struct adfs_sb_info *asb; |
| 439 | + |
| 440 | + asb = kzalloc(sizeof(struct adfs_sb_info), GFP_KERNEL); |
| 441 | + if (!asb) |
| 442 | + return -ENOMEM; |
| 443 | + |
| 444 | + if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE) { |
| 445 | + struct super_block *sb = fc->root->d_sb; |
| 446 | + struct adfs_sb_info *old_asb = ADFS_SB(sb); |
| 447 | + |
| 448 | + /* structure copy existing options before parsing */ |
| 449 | + *asb = *old_asb; |
| 450 | + } else { |
| 451 | + /* set default options */ |
| 452 | + asb->s_uid = GLOBAL_ROOT_UID; |
| 453 | + asb->s_gid = GLOBAL_ROOT_GID; |
| 454 | + asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK; |
| 455 | + asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK; |
| 456 | + asb->s_ftsuffix = 0; |
| 457 | + } |
| 458 | + |
| 459 | + fc->ops = &adfs_context_ops; |
| 460 | + fc->s_fs_info = asb; |
| 461 | + |
| 462 | + return 0; |
460 | 463 | }
|
461 | 464 |
|
462 | 465 | static struct file_system_type adfs_fs_type = {
|
463 | 466 | .owner = THIS_MODULE,
|
464 | 467 | .name = "adfs",
|
465 |
| - .mount = adfs_mount, |
466 | 468 | .kill_sb = kill_block_super,
|
467 | 469 | .fs_flags = FS_REQUIRES_DEV,
|
| 470 | + .init_fs_context = adfs_init_fs_context, |
| 471 | + .parameters = adfs_param_spec, |
468 | 472 | };
|
469 | 473 | MODULE_ALIAS_FS("adfs");
|
470 | 474 |
|
|
0 commit comments