1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Filesystem parameter description and parser
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #ifndef _LINUX_FS_PARSER_H
9 #define _LINUX_FS_PARSER_H
11 #include <linux/fs_context.h>
15 struct constant_table {
21 * The type of parameter expected.
23 enum fs_parameter_type {
24 __fs_param_wasnt_defined,
28 fs_param_is_u32_octal,
38 nr__fs_parameter_type,
42 * Specification of the type of value a parameter wants.
44 * Note that the fsparam_flag(), fsparam_string(), fsparam_u32(), ... macros
45 * should be used to generate elements of this type.
47 struct fs_parameter_spec {
49 u8 opt; /* Option number (returned by fs_parse()) */
50 enum fs_parameter_type type:8; /* The desired parameter type */
52 #define fs_param_v_optional 0x0001 /* The value is optional */
53 #define fs_param_neg_with_no 0x0002 /* "noxxx" is negative param */
54 #define fs_param_neg_with_empty 0x0004 /* "xxx=" is negative param */
55 #define fs_param_deprecated 0x0008 /* The param is deprecated */
62 struct fs_parse_result {
63 bool negated; /* T if param was "noxxx" */
65 bool boolean; /* For spec_bool */
66 int int_32; /* For spec_s32/spec_enum */
67 unsigned int uint_32; /* For spec_u32{,_octal,_hex}/spec_enum */
68 u64 uint_64; /* For spec_u64 */
72 extern int __fs_parse(struct p_log *log,
73 const struct fs_parameter_spec *desc,
74 struct fs_parameter *value,
75 struct fs_parse_result *result);
77 static inline int fs_parse(struct fs_context *fc,
78 const struct fs_parameter_spec *desc,
79 struct fs_parameter *param,
80 struct fs_parse_result *result)
82 return __fs_parse(&fc->log, desc, param, result);
85 extern int fs_lookup_param(struct fs_context *fc,
86 struct fs_parameter *param,
90 extern int lookup_constant(const struct constant_table tbl[], const char *name, int not_found);
92 #ifdef CONFIG_VALIDATE_FS_PARSER
93 extern bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size,
94 int low, int high, int special);
95 extern bool fs_validate_description(const char *name,
96 const struct fs_parameter_spec *desc);
98 static inline bool validate_constant_table(const struct constant_table *tbl, size_t tbl_size,
99 int low, int high, int special)
101 static inline bool fs_validate_description(const char *name,
102 const struct fs_parameter_spec *desc)
107 * Parameter type, name, index and flags element constructors. Use as:
109 * fsparam_xxxx("foo", Opt_foo)
111 * If existing helpers are not enough, direct use of __fsparam() would
112 * work, but any such case is probably a sign that new helper is needed.
113 * Helpers will remain stable; low-level implementation may change.
115 #define __fsparam(TYPE, NAME, OPT, FLAGS, DATA) \
124 #define fsparam_flag(NAME, OPT) __fsparam(fs_param_is_flag, NAME, OPT, 0, NULL)
125 #define fsparam_flag_no(NAME, OPT) \
126 __fsparam(fs_param_is_flag, NAME, OPT, \
127 fs_param_neg_with_no, NULL)
128 #define fsparam_bool(NAME, OPT) __fsparam(fs_param_is_bool, NAME, OPT, 0, NULL)
129 #define fsparam_u32(NAME, OPT) __fsparam(fs_param_is_u32, NAME, OPT, 0, NULL)
130 #define fsparam_u32oct(NAME, OPT) \
131 __fsparam(fs_param_is_u32_octal, NAME, OPT, 0, NULL)
132 #define fsparam_u32hex(NAME, OPT) \
133 __fsparam(fs_param_is_u32_hex, NAME, OPT, 0, NULL)
134 #define fsparam_s32(NAME, OPT) __fsparam(fs_param_is_s32, NAME, OPT, 0, NULL)
135 #define fsparam_u64(NAME, OPT) __fsparam(fs_param_is_u64, NAME, OPT, 0, NULL)
136 #define fsparam_enum(NAME, OPT, array) __fsparam(fs_param_is_enum, NAME, OPT, 0, array)
137 #define fsparam_string(NAME, OPT) \
138 __fsparam(fs_param_is_string, NAME, OPT, 0, NULL)
139 #define fsparam_blob(NAME, OPT) __fsparam(fs_param_is_blob, NAME, OPT, 0, NULL)
140 #define fsparam_bdev(NAME, OPT) __fsparam(fs_param_is_blockdev, NAME, OPT, 0, NULL)
141 #define fsparam_path(NAME, OPT) __fsparam(fs_param_is_path, NAME, OPT, 0, NULL)
142 #define fsparam_fd(NAME, OPT) __fsparam(fs_param_is_fd, NAME, OPT, 0, NULL)
145 #endif /* _LINUX_FS_PARSER_H */