Generic parser

Overview

The generic parser is a simple parser for parsing mount options,filesystem options, driver options, subsystem options, etc.

Parser API

intmatch_token(char*s,constmatch_table_ttable,substring_targs[])

Find a token (and optional args) in a string

Parameters

char*s

the string to examine for token/argument pairs

constmatch_table_ttable

match_table_t describing the set of allowed option tokens and thearguments that may be associated with them. Must be terminated with astructmatch_token whose pattern is set to the NULL pointer.

substring_targs[]

array ofMAX_OPT_ARGSsubstring_t elements. Used to return matchlocations.

Description

Detects which if any of a set of token strings has been passedto it. Tokens can include up toMAX_OPT_ARGS instances of basic c-styleformat identifiers which will be taken into account when matching thetokens, and whose locations will be returned in theargs array.

intmatch_int(substring_t*s,int*result)

scan a decimal representation of an integer from a substring_t

Parameters

substring_t*s

substring_t to be scanned

int*result

resulting integer on success

Description

Attempts to parse thesubstring_ts as a decimal integer.

Return

On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.

intmatch_uint(substring_t*s,unsignedint*result)

scan a decimal representation of an integer from a substring_t

Parameters

substring_t*s

substring_t to be scanned

unsignedint*result

resulting integer on success

Description

Attempts to parse thesubstring_ts as a decimal integer.

Return

On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.

intmatch_u64(substring_t*s,u64*result)

scan a decimal representation of a u64 from a substring_t

Parameters

substring_t*s

substring_t to be scanned

u64*result

resulting unsigned long long on success

Description

Attempts to parse thesubstring_ts as a long decimalinteger.

Return

On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.

intmatch_octal(substring_t*s,int*result)

scan an octal representation of an integer from a substring_t

Parameters

substring_t*s

substring_t to be scanned

int*result

resulting integer on success

Description

Attempts to parse thesubstring_ts as an octal integer.

Return

On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.

intmatch_hex(substring_t*s,int*result)

scan a hex representation of an integer from a substring_t

Parameters

substring_t*s

substring_t to be scanned

int*result

resulting integer on success

Description

Attempts to parse thesubstring_ts as a hexadecimal integer.

Return

On success, setsresult to the integer represented by the stringand returns 0. Returns -EINVAL or -ERANGE on failure.

boolmatch_wildcard(constchar*pattern,constchar*str)

parse if a string matches given wildcard pattern

Parameters

constchar*pattern

wildcard pattern

constchar*str

the string to be parsed

Description

Parse the stringstr to check if matches wildcardpatternpattern. The pattern may contain two types of wildcards:

  • ‘*’ - matches zero or more characters

  • ‘?’ - matches one character

Return

If thestr matches thepattern, return true, else return false.

size_tmatch_strlcpy(char*dest,constsubstring_t*src,size_tsize)

Copy the characters from a substring_t to a sized buffer

Parameters

char*dest

where to copy to

constsubstring_t*src

substring_t to copy

size_tsize

size of destination buffer

Description

Copy the characters insubstring_tsrc to thec-style stringdest. Copy no more thansize - 1 characters, plusthe terminating NUL.

Return

length ofsrc.

char*match_strdup(constsubstring_t*s)

allocate a new string with the contents of a substring_t

Parameters

constsubstring_t*s

substring_t to copy

Description

Allocates and returns a string filled with the contents ofthesubstring_ts. The caller is responsible for freeing the returnedstring withkfree().

Return

the address of the newly allocated NUL-terminated string orNULL on error.