mirror of
https://github.com/ipxe/ipxe
synced 2026-03-16 03:02:07 +03:00
[settings] Add parsing for UUID and GUID settings types
The ":uuid" and ":guid" settings types are currently format-only: it is possible to format a setting as a UUID (via e.g. "show foo:uuid") but it is not currently possible to parse a string into a UUID setting (via e.g. "set foo:uuid 406343fe-998b-44be-8a28-44ca38cb202b"). Use uuid_aton() to implement parsing of these settings types, and add appropriate test cases for both. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -2194,6 +2194,37 @@ const struct setting_type setting_type_base64 __setting_type = {
|
||||
.format = format_base64_setting,
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse UUID/GUID setting value
|
||||
*
|
||||
* @v type Setting type
|
||||
* @v value Formatted setting value
|
||||
* @v buf Buffer to contain raw value
|
||||
* @v len Length of buffer
|
||||
* @v size Integer size, in bytes
|
||||
* @ret len Length of raw value, or negative error
|
||||
*/
|
||||
static int parse_uuid_setting ( const struct setting_type *type,
|
||||
const char *value, void *buf, size_t len ) {
|
||||
union uuid uuid;
|
||||
int rc;
|
||||
|
||||
/* Parse UUID */
|
||||
if ( ( rc = uuid_aton ( value, &uuid ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Mangle GUID byte ordering */
|
||||
if ( type == &setting_type_guid )
|
||||
uuid_mangle ( &uuid );
|
||||
|
||||
/* Copy value */
|
||||
if ( len > sizeof ( uuid ) )
|
||||
len = sizeof ( uuid );
|
||||
memcpy ( buf, uuid.raw, len );
|
||||
|
||||
return ( sizeof ( uuid ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format UUID/GUID setting value
|
||||
*
|
||||
@@ -2227,12 +2258,14 @@ static int format_uuid_setting ( const struct setting_type *type,
|
||||
/** UUID setting type */
|
||||
const struct setting_type setting_type_uuid __setting_type = {
|
||||
.name = "uuid",
|
||||
.parse = parse_uuid_setting,
|
||||
.format = format_uuid_setting,
|
||||
};
|
||||
|
||||
/** GUID setting type */
|
||||
const struct setting_type setting_type_guid __setting_type = {
|
||||
.name = "guid",
|
||||
.parse = parse_uuid_setting,
|
||||
.format = format_uuid_setting,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user