TianoCore EDK2 master
Loading...
Searching...
No Matches
QemuFwCfgSimpleParser.c File Reference

Go to the source code of this file.

Macros

#define UINT64_STRING_MAX_SIZE    MAX (sizeof "18446744073709551615", sizeof "0xFFFFFFFFFFFFFFFF")
 
#define BOOL_STRING_MAX_SIZE   (sizeof "disabled")
 
#define CRLF_LENGTH   (sizeof "\r\n" - 1)
 

Functions

STATIC RETURN_STATUS QemuFwCfgGetAsString (IN CONST CHAR8 *FileName, IN OUT UINTN *BufferSize, OUT CHAR8 *Buffer)
 
STATIC VOID StripNewline (IN OUT UINTN *BufferSize, IN OUT CHAR8 *Buffer)
 
STATIC RETURN_STATUS QemuFwCfgParseUint64WithLimit (IN CONST CHAR8 *FileName, IN BOOLEAN ParseAsHex, IN UINT64 Limit, OUT UINT64 *Value)
 
RETURN_STATUS EFIAPI QemuFwCfgSimpleParserInit (VOID)
 
RETURN_STATUS EFIAPI QemuFwCfgParseBool (IN CONST CHAR8 *FileName, OUT BOOLEAN *Value)
 
RETURN_STATUS EFIAPI QemuFwCfgParseUint8 (IN CONST CHAR8 *FileName, IN BOOLEAN ParseAsHex, OUT UINT8 *Value)
 
RETURN_STATUS EFIAPI QemuFwCfgParseUint16 (IN CONST CHAR8 *FileName, IN BOOLEAN ParseAsHex, OUT UINT16 *Value)
 
RETURN_STATUS EFIAPI QemuFwCfgParseUint32 (IN CONST CHAR8 *FileName, IN BOOLEAN ParseAsHex, OUT UINT32 *Value)
 
RETURN_STATUS EFIAPI QemuFwCfgParseUint64 (IN CONST CHAR8 *FileName, IN BOOLEAN ParseAsHex, OUT UINT64 *Value)
 
RETURN_STATUS EFIAPI QemuFwCfgParseUintn (IN CONST CHAR8 *FileName, IN BOOLEAN ParseAsHex, OUT UINTN *Value)
 

Variables

STATIC CONST CHAR8 *CONST mTrueString []
 
STATIC CONST CHAR8 *CONST mFalseString []
 

Detailed Description

Parse the contents of named fw_cfg files as simple (scalar) data types.

Copyright (C) 2020, Red Hat, Inc.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file QemuFwCfgSimpleParser.c.

Macro Definition Documentation

◆ BOOL_STRING_MAX_SIZE

#define BOOL_STRING_MAX_SIZE   (sizeof "disabled")

Definition at line 23 of file QemuFwCfgSimpleParser.c.

◆ CRLF_LENGTH

#define CRLF_LENGTH   (sizeof "\r\n" - 1)

Definition at line 28 of file QemuFwCfgSimpleParser.c.

◆ UINT64_STRING_MAX_SIZE

#define UINT64_STRING_MAX_SIZE    MAX (sizeof "18446744073709551615", sizeof "0xFFFFFFFFFFFFFFFF")

Definition at line 16 of file QemuFwCfgSimpleParser.c.

Function Documentation

◆ QemuFwCfgGetAsString()

STATIC RETURN_STATUS QemuFwCfgGetAsString ( IN CONST CHAR8 *  FileName,
IN OUT UINTN BufferSize,
OUT CHAR8 *  Buffer 
)

Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg file into the caller-provided CHAR8 array. NUL-terminate the array.

Parameters
[in]FileNameThe name of the fw_cfg file to look up and read.
[in,out]BufferSizeOn input, number of bytes available in Buffer.
                       On output, the number of bytes that have been
                       stored to Buffer.

                       On error, BufferSize is indeterminate.
[out]BufferThe buffer to read the fw_cfg file into. If the fw_cfg file contents are not NUL-terminated, then a NUL character is placed into Buffer after the fw_cfg file contents.

On error, Buffer is indeterminate.

Return values
RETURN_SUCCESSBuffer has been populated with the fw_cfg file contents. Buffer is NUL-terminated regardless of whether the fw_cfg file itself was NUL-terminated.
RETURN_UNSUPPORTEDFirmware configuration is unavailable.
RETURN_PROTOCOL_ERRORThe fw_cfg file does not fit into Buffer. (This is considered a QEMU configuration error; BufferSize is considered authoritative for the contents of the fw_cfg file identified by FileName.)
RETURN_PROTOCOL_ERRORThe fw_cfg file contents are not themselves NUL-terminated, and an extra NUL byte does not fit into Buffer. (Again a QEMU configuration error.)
Returns
Error codes propagated from QemuFwCfgFindFile().

Definition at line 87 of file QemuFwCfgSimpleParser.c.

◆ QemuFwCfgParseBool()

RETURN_STATUS EFIAPI QemuFwCfgParseBool ( IN CONST CHAR8 *  FileName,
OUT BOOLEAN *  Value 
)

Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg file into a small array with automatic storage duration. Parse the array as the textual representation of a BOOLEAN.

Parameters
[in]FileNameThe name of the fw_cfg file to look up and parse.
[out]ValueOn success, Value is TRUE if the contents of the fw_cfg file case-insensitively match "true", "yes", "y", "enable", "enabled", "1".

On success, Value is FALSE if the contents of the fw_cfg file case-insensitively match "false", "no", "n", "disable", "disabled", "0".

On failure, Value is not changed.

Return values
RETURN_SUCCESSParsing successful. Value has been set.
RETURN_UNSUPPORTEDFirmware configuration is unavailable.
RETURN_PROTOCOL_ERRORParsing failed. Value has not been changed.
Returns
Error codes propagated from QemuFwCfgFindFile(). Value has not been changed.

Definition at line 270 of file QemuFwCfgSimpleParser.c.

◆ QemuFwCfgParseUint16()

RETURN_STATUS EFIAPI QemuFwCfgParseUint16 ( IN CONST CHAR8 *  FileName,
IN BOOLEAN  ParseAsHex,
OUT UINT16 *  Value 
)

Definition at line 332 of file QemuFwCfgSimpleParser.c.

◆ QemuFwCfgParseUint32()

RETURN_STATUS EFIAPI QemuFwCfgParseUint32 ( IN CONST CHAR8 *  FileName,
IN BOOLEAN  ParseAsHex,
OUT UINT32 *  Value 
)

Definition at line 357 of file QemuFwCfgSimpleParser.c.

◆ QemuFwCfgParseUint64()

RETURN_STATUS EFIAPI QemuFwCfgParseUint64 ( IN CONST CHAR8 *  FileName,
IN BOOLEAN  ParseAsHex,
OUT UINT64 *  Value 
)

Definition at line 382 of file QemuFwCfgSimpleParser.c.

◆ QemuFwCfgParseUint64WithLimit()

STATIC RETURN_STATUS QemuFwCfgParseUint64WithLimit ( IN CONST CHAR8 *  FileName,
IN BOOLEAN  ParseAsHex,
IN UINT64  Limit,
OUT UINT64 *  Value 
)

Read the fw_cfg file identified by FileName as a string into a small array with automatic storage duration, using QemuFwCfgGetAsString(). Parse the string as a UINT64. Perform a range-check on the parsed value.

Parameters
[in]FileNameThe name of the fw_cfg file to look up and parse.
[in]ParseAsHexIf TRUE, call BaseLib's AsciiStrHexToUint64S() for parsing the fw_cfg file.

If FALSE, call BaseLib's AsciiStrDecimalToUint64S() for parsing the fw_cfg file.

Parameters
[in]LimitThe inclusive upper bound on the parsed UINT64 value.
[out]ValueOn success, Value has been parsed with the BaseLib function determined by ParseAsHex, and has been range-checked against [0, Limit].

On failure, Value is not changed.

Return values
RETURN_SUCCESSParsing successful. Value has been set.
RETURN_UNSUPPORTEDFirmware configuration is unavailable.
RETURN_PROTOCOL_ERRORParsing failed. Value has not been changed.
RETURN_PROTOCOL_ERRORParsing succeeded, but the result does not fit in the [0, Limit] range. Value has not been changed.
Returns
Error codes propagated from QemuFwCfgFindFile() and from the BaseLib function selected by ParseAsHex. Value has not been changed.

Definition at line 209 of file QemuFwCfgSimpleParser.c.

◆ QemuFwCfgParseUint8()

RETURN_STATUS EFIAPI QemuFwCfgParseUint8 ( IN CONST CHAR8 *  FileName,
IN BOOLEAN  ParseAsHex,
OUT UINT8 *  Value 
)

Look up FileName with QemuFwCfgFindFile() from QemuFwCfgLib. Read the fw_cfg file into a small array with automatic storage duration. Parse the array as the textual representation of a UINT8.

Parameters
[in]FileNameThe name of the fw_cfg file to look up and parse.
[in]ParseAsHexIf TRUE, call BaseLib's AsciiStrHexToUint64S() for parsing the fw_cfg file.

If FALSE, call BaseLib's AsciiStrDecimalToUint64S() for parsing the fw_cfg file.

Parameters
[out]ValueOn success, Value has been parsed with the BaseLib function determined by ParseAsHex, and also range-checked for [0, MAX_UINT8].

On failure, Value is not changed.

Return values
RETURN_SUCCESSParsing successful. Value has been set.
RETURN_UNSUPPORTEDFirmware configuration is unavailable.
RETURN_PROTOCOL_ERRORParsing failed. Value has not been changed.
RETURN_PROTOCOL_ERRORParsing succeeded, but the result does not fit in the [0, MAX_UINT8] range. Value has not been changed.
Returns
Error codes propagated from QemuFwCfgFindFile() and from the BaseLib function selected by ParseAsHex. Value has not been changed.

Definition at line 307 of file QemuFwCfgSimpleParser.c.

◆ QemuFwCfgParseUintn()

RETURN_STATUS EFIAPI QemuFwCfgParseUintn ( IN CONST CHAR8 *  FileName,
IN BOOLEAN  ParseAsHex,
OUT UINTN Value 
)

Definition at line 407 of file QemuFwCfgSimpleParser.c.

◆ QemuFwCfgSimpleParserInit()

RETURN_STATUS EFIAPI QemuFwCfgSimpleParserInit ( VOID  )

Definition at line 258 of file QemuFwCfgSimpleParser.c.

◆ StripNewline()

STATIC VOID StripNewline ( IN OUT UINTN BufferSize,
IN OUT CHAR8 *  Buffer 
)

Remove a trailing \r
or
sequence from a string.

Parameters
[in,out]BufferSizeOn input, the number of bytes in Buffer, including the terminating NUL.

On output, the adjusted string size (including the terminating NUL), after stripping the \r
or
suffix.

Parameters
[in,out]BufferThe NUL-terminated string to trim.

Definition at line 147 of file QemuFwCfgSimpleParser.c.

Variable Documentation

◆ mFalseString

STATIC CONST CHAR8* CONST mFalseString[]
Initial value:
= {
"false", "no", "n", "disable", "disabled", "0"
}

Definition at line 36 of file QemuFwCfgSimpleParser.c.

◆ mTrueString

STATIC CONST CHAR8* CONST mTrueString[]
Initial value:
= {
"true", "yes", "y", "enable", "enabled", "1"
}

Definition at line 33 of file QemuFwCfgSimpleParser.c.