Generic parser
Overview #
The generic parser is a simple parser for parsing mount options, filesystem options, driver options, subsystem options, etc.
Parser API #
match_token() #
int Find a token (and optional args) in a string
Parameters
char *s: the string to examine for token/argument pairsconst match_table_t table: match_table_t describing the set of allowed option tokens and the arguments that may be associated with them. Must be terminated with astruct match_tokenwhose pattern is set to the NULL pointer.substring_t args[]: array ofMAX_OPT_ARGSsubstring_telements. Used to return match locations.
Description
Detects which if any of a set of token strings has been passed
to it. Tokens can include up to MAX_OPT_ARGS instances of basic c-style
format identifiers which will be taken into account when matching the
tokens, and whose locations will be returned in the args array.
match_int() #
int scan a decimal representation of an integer from a substring_t
Parameters
substring_t *s: substring_t to be scannedint *result: resulting integer on success
Description
Attempts to parse the substring_t s as a decimal integer.
Return
On success, sets result to the integer represented by the string and returns 0. Returns -EINVAL or -ERANGE on failure.
match_uint() #
int scan a decimal representation of an integer from a substring_t
Parameters
substring_t *s: substring_t to be scannedunsigned int *result: resulting integer on success
Description
Attempts to parse the substring_t s as a decimal integer.
Return
On success, sets result to the integer represented by the string and returns 0. Returns -EINVAL or -ERANGE on failure.
match_u64() #
int scan a decimal representation of a u64 from a substring_t
Parameters
substring_t *s: substring_t to be scannedu64 *result: resulting unsigned long long on success
Description
Attempts to parse the substring_t s as a long decimal
integer.
Return
On success, sets result to the integer represented by the string and returns 0. Returns -EINVAL or -ERANGE on failure.
match_octal() #
int scan an octal representation of an integer from a substring_t
Parameters
substring_t *s: substring_t to be scannedint *result: resulting integer on success
Description
Attempts to parse the substring_t s as an octal integer.
Return
On success, sets result to the integer represented by the string and returns 0. Returns -EINVAL or -ERANGE on failure.
match_hex() #
int scan a hex representation of an integer from a substring_t
Parameters
substring_t *s: substring_t to be scannedint *result: resulting integer on success
Description
Attempts to parse the substring_t s as a hexadecimal integer.
Return
On success, sets result to the integer represented by the string and returns 0. Returns -EINVAL or -ERANGE on failure.
match_wildcard() #
bool parse if a string matches given wildcard pattern
Parameters
const char *pattern: wildcard patternconst char *str: the string to be parsed
Description
Parse the string str to check if matches wildcard pattern pattern. The pattern may contain two types of wildcards:
- '*' - matches zero or more characters
- '?' - matches one character
Return
If the str matches the pattern, return true, else return false.
match_strlcpy() #
size_t Copy the characters from a substring_t to a sized buffer
Parameters
char *dest: where to copy toconst substring_t *src:substring_tto copysize_t size: size of destination buffer
Description
Copy the characters in substring_t src to the
c-style string dest. Copy no more than size - 1 characters, plus
the terminating NUL.
Return
length of src.
match_strdup() #
char * allocate a new string with the contents of a substring_t
Parameters
const substring_t *s:substring_tto copy
Description
Allocates and returns a string filled with the contents of
the substring_t s. The caller is responsible for freeing the returned
string with kfree().
Return
the address of the newly allocated NUL-terminated string or
NULL on error.