fs_parser.c (96cafb9ccb153f6a82ff2c9bde68916d9d65501e) fs_parser.c (d7167b149943e38ad610191ecbb0800c78bbced9)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* Filesystem parameter parser.
3 *
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8#include <linux/export.h>

--- 33 unchanged lines hidden (view full) ---

42{
43 const struct constant_table *p = __lookup_constant(tbl, name);
44
45 return p ? p->value : not_found;
46}
47EXPORT_SYMBOL(lookup_constant);
48
49static const struct fs_parameter_spec *fs_lookup_key(
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* Filesystem parameter parser.
3 *
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8#include <linux/export.h>

--- 33 unchanged lines hidden (view full) ---

42{
43 const struct constant_table *p = __lookup_constant(tbl, name);
44
45 return p ? p->value : not_found;
46}
47EXPORT_SYMBOL(lookup_constant);
48
49static const struct fs_parameter_spec *fs_lookup_key(
50 const struct fs_parameter_description *desc,
50 const struct fs_parameter_spec *desc,
51 const char *name)
52{
53 const struct fs_parameter_spec *p;
51 const char *name)
52{
53 const struct fs_parameter_spec *p;
54
55 if (!desc->specs)
54 if (!desc)
56 return NULL;
57
55 return NULL;
56
58 for (p = desc->specs; p->name; p++)
57 for (p = desc; p->name; p++)
59 if (strcmp(p->name, name) == 0)
60 return p;
61
62 return NULL;
63}
64
65/*
66 * fs_parse - Parse a filesystem configuration parameter

--- 9 unchanged lines hidden (view full) ---

76 * the union in @result.
77 *
78 * The function returns the parameter number if the parameter was matched,
79 * -ENOPARAM if it wasn't matched and @desc->ignore_unknown indicated that
80 * unknown parameters are okay and -EINVAL if there was a conversion issue or
81 * the parameter wasn't recognised and unknowns aren't okay.
82 */
83int __fs_parse(struct p_log *log,
58 if (strcmp(p->name, name) == 0)
59 return p;
60
61 return NULL;
62}
63
64/*
65 * fs_parse - Parse a filesystem configuration parameter

--- 9 unchanged lines hidden (view full) ---

75 * the union in @result.
76 *
77 * The function returns the parameter number if the parameter was matched,
78 * -ENOPARAM if it wasn't matched and @desc->ignore_unknown indicated that
79 * unknown parameters are okay and -EINVAL if there was a conversion issue or
80 * the parameter wasn't recognised and unknowns aren't okay.
81 */
82int __fs_parse(struct p_log *log,
84 const struct fs_parameter_description *desc,
83 const struct fs_parameter_spec *desc,
85 struct fs_parameter *param,
86 struct fs_parse_result *result)
87{
88 const struct fs_parameter_spec *p;
89 const struct constant_table *e;
90 int ret = -ENOPARAM, b;
91
92 result->negated = false;

--- 257 unchanged lines hidden (view full) ---

350 return good;
351}
352
353/**
354 * fs_validate_description - Validate a parameter description
355 * @desc: The parameter description to validate.
356 */
357bool fs_validate_description(const char *name,
84 struct fs_parameter *param,
85 struct fs_parse_result *result)
86{
87 const struct fs_parameter_spec *p;
88 const struct constant_table *e;
89 int ret = -ENOPARAM, b;
90
91 result->negated = false;

--- 257 unchanged lines hidden (view full) ---

349 return good;
350}
351
352/**
353 * fs_validate_description - Validate a parameter description
354 * @desc: The parameter description to validate.
355 */
356bool fs_validate_description(const char *name,
358 const struct fs_parameter_description *desc)
357 const struct fs_parameter_spec *desc)
359{
360 const struct fs_parameter_spec *param, *p2;
361 bool good = true;
362
363 pr_notice("*** VALIDATE %s ***\n", name);
364
358{
359 const struct fs_parameter_spec *param, *p2;
360 bool good = true;
361
362 pr_notice("*** VALIDATE %s ***\n", name);
363
365 if (desc->specs) {
366 for (param = desc->specs; param->name; param++) {
367 enum fs_parameter_type t = param->type;
364 for (param = desc; param->name; param++) {
365 enum fs_parameter_type t = param->type;
368
366
369 /* Check that the type is in range */
370 if (t == __fs_param_wasnt_defined ||
371 t >= nr__fs_parameter_type) {
372 pr_err("VALIDATE %s: PARAM[%s] Bad type %u\n",
373 name, param->name, t);
367 /* Check that the type is in range */
368 if (t == __fs_param_wasnt_defined ||
369 t >= nr__fs_parameter_type) {
370 pr_err("VALIDATE %s: PARAM[%s] Bad type %u\n",
371 name, param->name, t);
372 good = false;
373 } else if (t == fs_param_is_enum) {
374 const struct constant_table *e = param->data;
375 if (!e || !e->name) {
376 pr_err("VALIDATE %s: PARAM[%s] enum with no values\n",
377 name, param->name);
374 good = false;
378 good = false;
375 } else if (t == fs_param_is_enum) {
376 const struct constant_table *e = param->data;
377 if (!e || !e->name) {
378 pr_err("VALIDATE %s: PARAM[%s] enum with no values\n",
379 name, param->name);
380 good = false;
381 }
382 }
379 }
380 }
383
381
384 /* Check for duplicate parameter names */
385 for (p2 = desc->specs; p2 < param; p2++) {
386 if (strcmp(param->name, p2->name) == 0) {
387 pr_err("VALIDATE %s: PARAM[%s]: Duplicate\n",
388 name, param->name);
389 good = false;
390 }
382 /* Check for duplicate parameter names */
383 for (p2 = desc; p2 < param; p2++) {
384 if (strcmp(param->name, p2->name) == 0) {
385 pr_err("VALIDATE %s: PARAM[%s]: Duplicate\n",
386 name, param->name);
387 good = false;
391 }
392 }
393 }
394 return good;
395}
396#endif /* CONFIG_VALIDATE_FS_PARSER */
388 }
389 }
390 }
391 return good;
392}
393#endif /* CONFIG_VALIDATE_FS_PARSER */