hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/fs/ramfs/inode.c
....@@ -36,6 +36,8 @@
3636 #include <linux/magic.h>
3737 #include <linux/slab.h>
3838 #include <linux/uaccess.h>
39
+#include <linux/fs_context.h>
40
+#include <linux/fs_parser.h>
3941 #include "internal.h"
4042
4143 struct ramfs_mount_opts {
....@@ -175,62 +177,47 @@
175177 .show_options = ramfs_show_options,
176178 };
177179
178
-enum {
180
+enum ramfs_param {
179181 Opt_mode,
180
- Opt_err
181182 };
182183
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
+ {}
186187 };
187188
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)
189190 {
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;
194194
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) {
208197 /*
209198 * We might like to report bad mount options here;
210199 * but traditionally ramfs has ignored all mount options,
211200 * and as it is used as a !CONFIG_SHMEM simple substitute
212201 * for tmpfs, better continue to ignore other mount options.
213202 */
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;
215212 }
216213
217214 return 0;
218215 }
219216
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)
221218 {
222
- struct ramfs_fs_info *fsi;
219
+ struct ramfs_fs_info *fsi = sb->s_fs_info;
223220 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;
234221
235222 sb->s_maxbytes = MAX_LFS_FILESIZE;
236223 sb->s_blocksize = PAGE_SIZE;
....@@ -247,13 +234,37 @@
247234 return 0;
248235 }
249236
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)
252238 {
253
- return mount_nodev(fs_type, flags, data, ramfs_fill_super);
239
+ return get_tree_nodev(fc, ramfs_fill_super);
254240 }
255241
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)
257268 {
258269 kfree(sb->s_fs_info);
259270 kill_litter_super(sb);
....@@ -261,17 +272,14 @@
261272
262273 static struct file_system_type ramfs_fs_type = {
263274 .name = "ramfs",
264
- .mount = ramfs_mount,
275
+ .init_fs_context = ramfs_init_fs_context,
276
+ .parameters = ramfs_fs_parameters,
265277 .kill_sb = ramfs_kill_sb,
266278 .fs_flags = FS_USERNS_MOUNT,
267279 };
268280
269
-int __init init_ramfs_fs(void)
281
+static int __init init_ramfs_fs(void)
270282 {
271
- static unsigned long once;
272
-
273
- if (test_and_set_bit(0, &once))
274
- return 0;
275283 return register_filesystem(&ramfs_fs_type);
276284 }
277285 fs_initcall(init_ramfs_fs);