summaryrefslogtreecommitdiffstats
path: root/src/core/settings.c
diff options
context:
space:
mode:
authorMichael Brown2013-12-03 17:48:56 +0100
committerMichael Brown2013-12-05 01:37:02 +0100
commit22001cb206c1320aee27f679a63d2171d35e99c5 (patch)
treea972bb914371a68d4925dcc007238dcb836546ba /src/core/settings.c
parent[fbcon] Add support for displaying a cursor (diff)
downloadipxe-22001cb206c1320aee27f679a63d2171d35e99c5.tar.gz
ipxe-22001cb206c1320aee27f679a63d2171d35e99c5.tar.xz
ipxe-22001cb206c1320aee27f679a63d2171d35e99c5.zip
[settings] Explicitly separate the concept of a completed fetched setting
The fetch_setting() family of functions may currently modify the definition of the specified setting (e.g. to add missing type information). Clean up this interface by requiring callers to provide an explicit buffer to contain the completed definition of the fetched setting, if required. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/settings.c')
-rw-r--r--src/core/settings.c440
1 files changed, 253 insertions, 187 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index 03ef084a..e6cfc0d2 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -96,7 +96,7 @@ static inline void * generic_setting_data ( struct generic_setting *generic ) {
*/
static struct generic_setting *
find_generic_setting ( struct generic_settings *generics,
- struct setting *setting ) {
+ const struct setting *setting ) {
struct generic_setting *generic;
list_for_each_entry ( generic, &generics->list, list ) {
@@ -116,7 +116,7 @@ find_generic_setting ( struct generic_settings *generics,
* @ret rc Return status code
*/
int generic_settings_store ( struct settings *settings,
- struct setting *setting,
+ const struct setting *setting,
const void *data, size_t len ) {
struct generic_settings *generics =
container_of ( settings, struct generic_settings, settings );
@@ -551,7 +551,8 @@ struct settings * settings_target ( struct settings *settings ) {
* @v setting Setting
* @ret applies Setting applies within this settings block
*/
-int setting_applies ( struct settings *settings, struct setting *setting ) {
+int setting_applies ( struct settings *settings,
+ const struct setting *setting ) {
/* Find target settings block */
settings = settings_target ( settings );
@@ -570,7 +571,7 @@ int setting_applies ( struct settings *settings, struct setting *setting ) {
* @v len Length of setting data
* @ret rc Return status code
*/
-int store_setting ( struct settings *settings, struct setting *setting,
+int store_setting ( struct settings *settings, const struct setting *setting,
const void *data, size_t len ) {
int rc;
@@ -609,11 +610,12 @@ int store_setting ( struct settings *settings, struct setting *setting,
}
/**
- * Fetch value and origin of setting
+ * Fetch setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
- * @v origin Origin of setting to fill in
+ * @v origin Origin of setting to fill in, or NULL
+ * @v fetched Fetched setting to fill in, or NULL
* @v data Buffer to fill with setting data
* @v len Length of buffer
* @ret len Length of setting data, or negative error
@@ -621,17 +623,19 @@ int store_setting ( struct settings *settings, struct setting *setting,
* The actual length of the setting will be returned even if
* the buffer was too small.
*/
-static int fetch_setting_and_origin ( struct settings *settings,
- struct setting *setting,
- struct settings **origin,
- void *data, size_t len ) {
+int fetch_setting ( struct settings *settings, const struct setting *setting,
+ struct settings **origin, struct setting *fetched,
+ void *data, size_t len ) {
struct settings *child;
+ struct setting tmp;
int ret;
/* Avoid returning uninitialised data on error */
memset ( data, 0, len );
if ( origin )
*origin = NULL;
+ if ( fetched )
+ memcpy ( fetched, setting, sizeof ( *fetched ) );
/* Find target settings block */
settings = settings_target ( settings );
@@ -641,22 +645,33 @@ static int fetch_setting_and_origin ( struct settings *settings,
return -ENOTSUP;
/* Try this block first, if applicable */
- if ( setting_applies ( settings, setting ) &&
- ( ( ret = settings->op->fetch ( settings, setting,
- data, len ) ) >= 0 ) ) {
- /* Record origin, if applicable */
- if ( origin )
- *origin = settings;
- /* Default to string setting type, if not yet specified */
- if ( ! setting->type )
- setting->type = &setting_type_string;
- return ret;
+ if ( setting_applies ( settings, setting ) ) {
+
+ /* Create modifiable copy of setting */
+ memcpy ( &tmp, setting, sizeof ( tmp ) );
+ if ( ( ret = settings->op->fetch ( settings, &tmp,
+ data, len ) ) >= 0 ) {
+
+ /* Default to string type, if not yet specified */
+ if ( ! tmp.type )
+ tmp.type = &setting_type_string;
+
+ /* Record origin, if applicable */
+ if ( origin )
+ *origin = settings;
+
+ /* Record fetched setting, if applicable */
+ if ( fetched )
+ memcpy ( fetched, &tmp, sizeof ( *fetched ) );
+
+ return ret;
+ }
}
/* Recurse into each child block in turn */
list_for_each_entry ( child, &settings->children, siblings ) {
- if ( ( ret = fetch_setting_and_origin ( child, setting, origin,
- data, len ) ) >= 0 )
+ if ( ( ret = fetch_setting ( child, setting, origin, fetched,
+ data, len ) ) >= 0 )
return ret;
}
@@ -664,56 +679,95 @@ static int fetch_setting_and_origin ( struct settings *settings,
}
/**
- * Fetch value of setting
+ * Fetch allocated copy of setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
- * @v data Buffer to fill with setting data
- * @v len Length of buffer
- * @ret len Length of setting data, or negative error
+ * @v origin Origin of setting to fill in, or NULL
+ * @v fetched Fetched setting to fill in, or NULL
+ * @v data Buffer to allocate and fill with setting data
+ * @v alloc Allocation function
+ * @ret len Length of setting, or negative error
*
- * The actual length of the setting will be returned even if
- * the buffer was too small.
+ * The caller is responsible for eventually freeing the allocated
+ * buffer.
*/
-int fetch_setting ( struct settings *settings, struct setting *setting,
- void *data, size_t len ) {
- return fetch_setting_and_origin ( settings, setting, NULL, data, len );
+static int fetch_setting_alloc ( struct settings *settings,
+ const struct setting *setting,
+ struct settings **origin,
+ struct setting *fetched,
+ void **data,
+ void * ( * alloc ) ( size_t len ) ) {
+ struct settings *tmp_origin;
+ struct setting tmp_fetched;
+ int len;
+ int check_len;
+
+ /* Use local buffers if necessary */
+ if ( ! origin )
+ origin = &tmp_origin;
+ if ( ! fetched )
+ fetched = &tmp_fetched;
+
+ /* Avoid returning uninitialised data on error */
+ *data = NULL;
+
+ /* Check existence, and fetch setting length */
+ len = fetch_setting ( settings, setting, origin, fetched, NULL, 0 );
+ if ( len < 0 )
+ return len;
+
+ /* Allocate buffer */
+ *data = alloc ( len );
+ if ( ! *data )
+ return -ENOMEM;
+
+ /* Fetch setting value */
+ check_len = fetch_setting ( *origin, fetched, NULL, NULL, *data, len );
+ assert ( check_len == len );
+ return len;
}
/**
- * Fetch origin of setting
+ * Fetch copy of setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
- * @ret origin Origin of setting, or NULL if not found
+ * @v origin Origin of setting to fill in, or NULL
+ * @v fetched Fetched setting to fill in, or NULL
+ * @v data Buffer to allocate and fill with setting data
+ * @ret len Length of setting, or negative error
*
- * This function can also be used as an existence check for the
- * setting.
+ * The caller is responsible for eventually freeing the allocated
+ * buffer.
*/
-struct settings * fetch_setting_origin ( struct settings *settings,
- struct setting *setting ) {
- struct settings *origin;
+int fetch_setting_copy ( struct settings *settings,
+ const struct setting *setting,
+ struct settings **origin, struct setting *fetched,
+ void **data ) {
- fetch_setting_and_origin ( settings, setting, &origin, NULL, 0 );
- return origin;
+ return fetch_setting_alloc ( settings, setting, origin, fetched,
+ data, malloc );
}
/**
- * Fetch length of setting
+ * Fetch value of setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
- * @ret len Length of setting data, or negative error
- *
- * This function can also be used as an existence check for the
- * setting.
+ * @v data Buffer to fill with setting string data
+ * @v len Length of buffer
+ * @ret len Length of setting, or negative error
*/
-int fetch_setting_len ( struct settings *settings, struct setting *setting ) {
- return fetch_setting ( settings, setting, NULL, 0 );
+int fetch_raw_setting ( struct settings *settings,
+ const struct setting *setting,
+ void *data, size_t len ) {
+
+ return fetch_setting ( settings, setting, NULL, NULL, data, len );
}
/**
- * Fetch copy of setting
+ * Fetch value of setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
@@ -723,28 +777,11 @@ int fetch_setting_len ( struct settings *settings, struct setting *setting ) {
* The caller is responsible for eventually freeing the allocated
* buffer.
*/
-int fetch_setting_copy ( struct settings *settings, struct setting *setting,
- void **data ) {
- int len;
- int check_len;
-
- /* Avoid returning uninitialised data on error */
- *data = NULL;
-
- /* Check existence, and fetch setting length */
- len = fetch_setting_len ( settings, setting );
- if ( len < 0 )
- return len;
-
- /* Allocate buffer */
- *data = malloc ( len );
- if ( ! *data )
- return -ENOMEM;
+int fetch_raw_setting_copy ( struct settings *settings,
+ const struct setting *setting,
+ void **data ) {
- /* Fetch setting */
- check_len = fetch_setting ( settings, setting, *data, len );
- assert ( check_len == len );
- return len;
+ return fetch_setting_copy ( settings, setting, NULL, NULL, data );
}
/**
@@ -760,11 +797,23 @@ int fetch_setting_copy ( struct settings *settings, struct setting *setting,
* The returned length will be the length of the underlying setting
* data.
*/
-int fetch_string_setting ( struct settings *settings, struct setting *setting,
+int fetch_string_setting ( struct settings *settings,
+ const struct setting *setting,
char *data, size_t len ) {
+
memset ( data, 0, len );
- return fetch_setting ( settings, setting, data,
- ( ( len > 0 ) ? ( len - 1 ) : 0 ) );
+ return fetch_raw_setting ( settings, setting, data,
+ ( ( len > 0 ) ? ( len - 1 ) : 0 ) );
+}
+
+/**
+ * Allocate memory for copy of string setting
+ *
+ * @v len Length of setting
+ * @ret ptr Allocated memory
+ */
+static void * fetch_string_setting_copy_alloc ( size_t len ) {
+ return zalloc ( len + 1 /* NUL */ );
}
/**
@@ -779,36 +828,13 @@ int fetch_string_setting ( struct settings *settings, struct setting *setting,
* The returned length will be the length of the underlying setting
* data. The caller is responsible for eventually freeing the
* allocated buffer.
- *
- * To allow the caller to distinguish between a non-existent setting
- * and an error in allocating memory for the copy, this function will
- * return success (and a NULL buffer pointer) for a non-existent
- * setting.
*/
int fetch_string_setting_copy ( struct settings *settings,
- struct setting *setting,
- char **data ) {
- int len;
- int check_len = 0;
-
- /* Avoid returning uninitialised data on error */
- *data = NULL;
-
- /* Fetch setting length, and return success if non-existent */
- len = fetch_setting_len ( settings, setting );
- if ( len < 0 )
- return 0;
-
- /* Allocate string buffer */
- *data = malloc ( len + 1 );
- if ( ! *data )
- return -ENOMEM;
+ const struct setting *setting, char **data ) {
- /* Fetch setting */
- check_len = fetch_string_setting ( settings, setting, *data,
- ( len + 1 ) );
- assert ( check_len == len );
- return len;
+ return fetch_setting_alloc ( settings, setting, NULL, NULL,
+ ( ( void ** ) data ),
+ fetch_string_setting_copy_alloc );
}
/**
@@ -821,12 +847,12 @@ int fetch_string_setting_copy ( struct settings *settings,
* @ret len Length of setting, or negative error
*/
int fetch_ipv4_array_setting ( struct settings *settings,
- struct setting *setting,
+ const struct setting *setting,
struct in_addr *inp, unsigned int count ) {
int len;
- len = fetch_setting ( settings, setting, inp,
- ( sizeof ( *inp ) * count ) );
+ len = fetch_raw_setting ( settings, setting, inp,
+ ( sizeof ( *inp ) * count ) );
if ( len < 0 )
return len;
if ( ( len % sizeof ( *inp ) ) != 0 )
@@ -842,8 +868,10 @@ int fetch_ipv4_array_setting ( struct settings *settings,
* @v inp IPv4 address to fill in
* @ret len Length of setting, or negative error
*/
-int fetch_ipv4_setting ( struct settings *settings, struct setting *setting,
+int fetch_ipv4_setting ( struct settings *settings,
+ const struct setting *setting,
struct in_addr *inp ) {
+
return fetch_ipv4_array_setting ( settings, setting, inp, 1 );
}
@@ -887,7 +915,8 @@ static int numeric_setting_value ( int is_signed, const void *raw, size_t len,
* @v value Integer value to fill in
* @ret len Length of setting, or negative error
*/
-int fetch_numeric_setting ( struct settings *settings, struct setting *setting,
+int fetch_numeric_setting ( struct settings *settings,
+ const struct setting *setting,
unsigned long *value, int is_signed ) {
unsigned long tmp;
int len;
@@ -896,7 +925,7 @@ int fetch_numeric_setting ( struct settings *settings, struct setting *setting,
*value = 0;
/* Fetch raw (network-ordered, variable-length) setting */
- len = fetch_setting ( settings, setting, &tmp, sizeof ( tmp ) );
+ len = fetch_raw_setting ( settings, setting, &tmp, sizeof ( tmp ) );
if ( len < 0 )
return len;
@@ -912,7 +941,8 @@ int fetch_numeric_setting ( struct settings *settings, struct setting *setting,
* @v value Integer value to fill in
* @ret len Length of setting, or negative error
*/
-int fetch_int_setting ( struct settings *settings, struct setting *setting,
+int fetch_int_setting ( struct settings *settings,
+ const struct setting *setting,
long *value ) {
return fetch_numeric_setting ( settings, setting,
@@ -927,7 +957,8 @@ int fetch_int_setting ( struct settings *settings, struct setting *setting,
* @v value Integer value to fill in
* @ret len Length of setting, or negative error
*/
-int fetch_uint_setting ( struct settings *settings, struct setting *setting,
+int fetch_uint_setting ( struct settings *settings,
+ const struct setting *setting,
unsigned long *value ) {
return fetch_numeric_setting ( settings, setting, value, 0 );
@@ -940,7 +971,8 @@ int fetch_uint_setting ( struct settings *settings, struct setting *setting,
* @v setting Setting to fetch
* @ret value Setting value, or zero
*/
-long fetch_intz_setting ( struct settings *settings, struct setting *setting ){
+long fetch_intz_setting ( struct settings *settings,
+ const struct setting *setting ) {
unsigned long value;
fetch_numeric_setting ( settings, setting, &value, 1 );
@@ -955,7 +987,7 @@ long fetch_intz_setting ( struct settings *settings, struct setting *setting ){
* @ret value Setting value, or zero
*/
unsigned long fetch_uintz_setting ( struct settings *settings,
- struct setting *setting ) {
+ const struct setting *setting ) {
unsigned long value;
fetch_numeric_setting ( settings, setting, &value, 0 );
@@ -970,11 +1002,12 @@ unsigned long fetch_uintz_setting ( struct settings *settings,
* @v uuid UUID to fill in
* @ret len Length of setting, or negative error
*/
-int fetch_uuid_setting ( struct settings *settings, struct setting *setting,
+int fetch_uuid_setting ( struct settings *settings,
+ const struct setting *setting,
union uuid *uuid ) {
int len;
- len = fetch_setting ( settings, setting, uuid, sizeof ( *uuid ) );
+ len = fetch_raw_setting ( settings, setting, uuid, sizeof ( *uuid ) );
if ( len < 0 )
return len;
if ( len != sizeof ( *uuid ) )
@@ -1005,7 +1038,7 @@ void clear_settings ( struct settings *settings ) {
* @ret 0 Settings are the same
* @ret non-zero Settings are not the same
*/
-int setting_cmp ( struct setting *a, struct setting *b ) {
+int setting_cmp ( const struct setting *a, const struct setting *b ) {
/* If the settings have tags, compare them */
if ( a->tag && ( a->tag == b->tag ) && ( a->scope == b->scope ) )
@@ -1036,7 +1069,7 @@ int setting_cmp ( struct setting *a, struct setting *b ) {
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-int setting_format ( struct setting_type *type, const void *raw,
+int setting_format ( const struct setting_type *type, const void *raw,
size_t raw_len, char *buf, size_t len ) {
/* Sanity check */
@@ -1055,7 +1088,7 @@ int setting_format ( struct setting_type *type, const void *raw,
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-int setting_parse ( struct setting_type *type, const char *value,
+int setting_parse ( const struct setting_type *type, const char *value,
void *buf, size_t len ) {
/* Sanity check */
@@ -1074,7 +1107,7 @@ int setting_parse ( struct setting_type *type, const char *value,
* @ret value Numeric value
* @ret rc Return status code
*/
-int setting_numerate ( struct setting_type *type, const void *raw,
+int setting_numerate ( const struct setting_type *type, const void *raw,
size_t raw_len, unsigned long *value ) {
/* Sanity check */
@@ -1093,7 +1126,7 @@ int setting_numerate ( struct setting_type *type, const void *raw,
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-int setting_denumerate ( struct setting_type *type, unsigned long value,
+int setting_denumerate ( const struct setting_type *type, unsigned long value,
void *buf, size_t len ) {
/* Sanity check */
@@ -1108,28 +1141,37 @@ int setting_denumerate ( struct setting_type *type, unsigned long value,
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
+ * @v origin Origin of setting to fill in, or NULL
+ * @v fetched Fetched setting to fill in, or NULL
* @v buf Buffer to contain formatted value
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-int fetchf_setting ( struct settings *settings, struct setting *setting,
+int fetchf_setting ( struct settings *settings, const struct setting *setting,
+ struct settings **origin, struct setting *fetched,
char *buf, size_t len ) {
+ struct setting tmp_fetched;
void *raw;
int raw_len;
int ret;
+ /* Use local buffers if necessary */
+ if ( ! fetched )
+ fetched = &tmp_fetched;
+
/* Fetch raw value */
- raw_len = fetch_setting_copy ( settings, setting, &raw );
+ raw_len = fetch_setting_copy ( settings, setting, origin, fetched,
+ &raw );
if ( raw_len < 0 ) {
ret = raw_len;
goto err_fetch_copy;
}
/* Sanity check */
- assert ( setting->type != NULL );
+ assert ( fetched->type != NULL );
/* Format setting */
- if ( ( ret = setting_format ( setting->type, raw, raw_len, buf,
+ if ( ( ret = setting_format ( fetched->type, raw, raw_len, buf,
len ) ) < 0 )
goto err_format;
@@ -1144,22 +1186,34 @@ int fetchf_setting ( struct settings *settings, struct setting *setting,
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
+ * @v origin Origin of setting to fill in, or NULL
+ * @v fetched Fetched setting to fill in, or NULL
* @v value Buffer to allocate and fill with formatted value
* @ret len Length of formatted value, or negative error
*
* The caller is responsible for eventually freeing the allocated
* buffer.
*/
-int fetchf_setting_copy ( struct settings *settings, struct setting *setting,
+int fetchf_setting_copy ( struct settings *settings,
+ const struct setting *setting,
+ struct settings **origin, struct setting *fetched,
char **value ) {
+ struct settings *tmp_origin;
+ struct setting tmp_fetched;
int len;
int check_len;
+ /* Use local buffers if necessary */
+ if ( ! origin )
+ origin = &tmp_origin;
+ if ( ! fetched )
+ fetched = &tmp_fetched;
+
/* Avoid returning uninitialised data on error */
*value = NULL;
/* Check existence, and fetch formatted value length */
- len = fetchf_setting ( settings, setting, NULL, 0 );
+ len = fetchf_setting ( settings, setting, origin, fetched, NULL, 0 );
if ( len < 0 )
return len;
@@ -1169,7 +1223,7 @@ int fetchf_setting_copy ( struct settings *settings, struct setting *setting,
return -ENOMEM;
/* Fetch formatted value */
- check_len = fetchf_setting ( settings, setting, *value,
+ check_len = fetchf_setting ( *origin, fetched, NULL, NULL, *value,
( len + 1 /* NUL */ ) );
assert ( check_len == len );
return len;
@@ -1183,7 +1237,7 @@ int fetchf_setting_copy ( struct settings *settings, struct setting *setting,
* @v value Formatted setting data, or NULL
* @ret rc Return status code
*/
-int storef_setting ( struct settings *settings, struct setting *setting,
+int storef_setting ( struct settings *settings, const struct setting *setting,
const char *value ) {
void *raw;
int raw_len;
@@ -1231,27 +1285,36 @@ int storef_setting ( struct settings *settings, struct setting *setting,
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
+ * @v origin Origin of setting to fill in, or NULL
+ * @v fetched Fetched setting to fill in, or NULL
* @v value Numeric value to fill in
* @ret rc Return status code
*/
-int fetchn_setting ( struct settings *settings, struct setting *setting,
+int fetchn_setting ( struct settings *settings, const struct setting *setting,
+ struct settings **origin, struct setting *fetched,
unsigned long *value ) {
+ struct setting tmp_fetched;
void *raw;
int raw_len;
int rc;
+ /* Use local buffers if necessary */
+ if ( ! fetched )
+ fetched = &tmp_fetched;
+
/* Fetch raw value */
- raw_len = fetch_setting_copy ( settings, setting, &raw );
+ raw_len = fetch_setting_copy ( settings, setting, origin, fetched,
+ &raw );
if ( raw_len < 0 ) {
rc = raw_len;
goto err_fetch_copy;
}
/* Sanity check */
- assert ( setting->type != NULL );
+ assert ( fetched->type != NULL );
/* Numerate setting */
- if ( ( rc = setting_numerate ( setting->type, raw, raw_len,
+ if ( ( rc = setting_numerate ( fetched->type, raw, raw_len,
value ) ) < 0 )
goto err_numerate;
@@ -1269,7 +1332,7 @@ int fetchn_setting ( struct settings *settings, struct setting *setting,
* @v value Numeric value
* @ret rc Return status code
*/
-int storen_setting ( struct settings *settings, struct setting *setting,
+int storen_setting ( struct settings *settings, const struct setting *setting,
unsigned long value ) {
void *raw;
int raw_len;
@@ -1357,8 +1420,8 @@ static unsigned int parse_setting_tag ( const char *name ) {
* @v name Name
* @ret type Setting type, or NULL
*/
-static struct setting_type * find_setting_type ( const char *name ) {
- struct setting_type *type;
+static const struct setting_type * find_setting_type ( const char *name ) {
+ const struct setting_type *type;
for_each_table_entry ( type, SETTING_TYPES ) {
if ( strcmp ( name, type->name ) == 0 )
@@ -1461,7 +1524,7 @@ int parse_setting_name ( char *name, get_child_settings_t get_child,
* @v len Length of buffer
* @ret len Length of setting name, or negative error
*/
-int setting_name ( struct settings *settings, struct setting *setting,
+int setting_name ( struct settings *settings, const struct setting *setting,
char *buf, size_t len ) {
const char *name;
@@ -1487,7 +1550,7 @@ int setting_name ( struct settings *settings, struct setting *setting,
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-static int parse_string_setting ( struct setting_type *type __unused,
+static int parse_string_setting ( const struct setting_type *type __unused,
const char *value, void *buf, size_t len ) {
size_t raw_len = strlen ( value ); /* Exclude terminating NUL */
@@ -1509,7 +1572,7 @@ static int parse_string_setting ( struct setting_type *type __unused,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_string_setting ( struct setting_type *type __unused,
+static int format_string_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len, char *buf,
size_t len ) {
@@ -1523,7 +1586,7 @@ static int format_string_setting ( struct setting_type *type __unused,
}
/** A string setting type */
-struct setting_type setting_type_string __setting_type = {
+const struct setting_type setting_type_string __setting_type = {
.name = "string",
.parse = parse_string_setting,
.format = format_string_setting,
@@ -1538,7 +1601,7 @@ struct setting_type setting_type_string __setting_type = {
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-static int parse_uristring_setting ( struct setting_type *type __unused,
+static int parse_uristring_setting ( const struct setting_type *type __unused,
const char *value, void *buf, size_t len ){
char tmp[ len + 1 /* NUL */ ];
size_t raw_len;
@@ -1564,7 +1627,7 @@ static int parse_uristring_setting ( struct setting_type *type __unused,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_uristring_setting ( struct setting_type *type __unused,
+static int format_uristring_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len,
char *buf, size_t len ) {
char tmp[ raw_len + 1 /* NUL */ ];
@@ -1578,7 +1641,7 @@ static int format_uristring_setting ( struct setting_type *type __unused,
}
/** A URI-encoded string setting type */
-struct setting_type setting_type_uristring __setting_type = {
+const struct setting_type setting_type_uristring __setting_type = {
.name = "uristring",
.parse = parse_uristring_setting,
.format = format_uristring_setting,
@@ -1593,7 +1656,7 @@ struct setting_type setting_type_uristring __setting_type = {
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-static int parse_ipv4_setting ( struct setting_type *type __unused,
+static int parse_ipv4_setting ( const struct setting_type *type __unused,
const char *value, void *buf, size_t len ) {
struct in_addr ipv4;
@@ -1619,7 +1682,7 @@ static int parse_ipv4_setting ( struct setting_type *type __unused,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_ipv4_setting ( struct setting_type *type __unused,
+static int format_ipv4_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len, char *buf,
size_t len ) {
const struct in_addr *ipv4 = raw;
@@ -1630,7 +1693,7 @@ static int format_ipv4_setting ( struct setting_type *type __unused,
}
/** An IPv4 address setting type */
-struct setting_type setting_type_ipv4 __setting_type = {
+const struct setting_type setting_type_ipv4 __setting_type = {
.name = "ipv4",
.parse = parse_ipv4_setting,
.format = format_ipv4_setting,
@@ -1685,7 +1748,7 @@ static const char setting_type_int_name[][8] = {
* @v type Setting type
* @ret index Integer setting type index
*/
-static unsigned int setting_type_int_index ( struct setting_type *type ) {
+static unsigned int setting_type_int_index ( const struct setting_type *type ) {
return ( ( type->name - setting_type_int_name[0] ) /
sizeof ( setting_type_int_name[0] ) );
@@ -1697,7 +1760,7 @@ static unsigned int setting_type_int_index ( struct setting_type *type ) {
* @v type Setting type
* @ret index Integer setting type width
*/
-static unsigned int setting_type_int_width ( struct setting_type *type ) {
+static unsigned int setting_type_int_width ( const struct setting_type *type ) {
return ( 1 << setting_type_int_index ( type ) );
}
@@ -1708,7 +1771,7 @@ static unsigned int setting_type_int_width ( struct setting_type *type ) {
* @v type Setting type
* @ret is_signed Integer setting type is signed
*/
-static int setting_type_int_is_signed ( struct setting_type *type ) {
+static int setting_type_int_is_signed ( const struct setting_type *type ) {
return ( ( type->name - setting_type_int_name[0] ) & 1 );
}
@@ -1721,7 +1784,7 @@ static int setting_type_int_is_signed ( struct setting_type *type ) {
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-static int denumerate_int_setting ( struct setting_type *type,
+static int denumerate_int_setting ( const struct setting_type *type,
unsigned long value, void *buf,
size_t len ) {
unsigned int size = setting_type_int_width ( type );
@@ -1747,7 +1810,7 @@ static int denumerate_int_setting ( struct setting_type *type,
* @v value Numeric value to fill in
* @ret rc Return status code
*/
-static int numerate_int_setting ( struct setting_type *type,
+static int numerate_int_setting ( const struct setting_type *type,
const void *raw, size_t raw_len,
unsigned long *value ) {
int is_signed = setting_type_int_is_signed ( type );
@@ -1771,8 +1834,8 @@ static int numerate_int_setting ( struct setting_type *type,
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
-static int parse_int_setting ( struct setting_type *type, const char *value,
- void *buf, size_t len ) {
+static int parse_int_setting ( const struct setting_type *type,
+ const char *value, void *buf, size_t len ) {
char *endp;
unsigned long num_value;
@@ -1794,8 +1857,9 @@ static int parse_int_setting ( struct setting_type *type, const char *value,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_int_setting ( struct setting_type *type, const void *raw,
- size_t raw_len, char *buf, size_t len ) {
+static int format_int_setting ( const struct setting_type *type,
+ const void *raw, size_t raw_len,
+ char *buf, size_t len ) {
unsigned long value;
int ret;
@@ -1817,8 +1881,9 @@ static int format_int_setting ( struct setting_type *type, const void *raw,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_uint_setting ( struct setting_type *type, const void *raw,
- size_t raw_len, char *buf, size_t len ) {
+static int format_uint_setting ( const struct setting_type *type,
+ const void *raw, size_t raw_len,
+ char *buf, size_t len ) {
unsigned long value;
int ret;
@@ -1859,27 +1924,27 @@ static int format_uint_setting ( struct setting_type *type, const void *raw,
}
/** A signed 8-bit integer setting type */
-struct setting_type setting_type_int8 __setting_type =
+const struct setting_type setting_type_int8 __setting_type =
SETTING_TYPE_INT ( SETTING_TYPE_INT8 );
/** A signed 16-bit integer setting type */
-struct setting_type setting_type_int16 __setting_type =
+const struct setting_type setting_type_int16 __setting_type =
SETTING_TYPE_INT ( SETTING_TYPE_INT16 );
/** A signed 32-bit integer setting type */
-struct setting_type setting_type_int32 __setting_type =
+const struct setting_type setting_type_int32 __setting_type =
SETTING_TYPE_INT ( SETTING_TYPE_INT32 );
/** An unsigned 8-bit integer setting type */
-struct setting_type setting_type_uint8 __setting_type =
+const struct setting_type setting_type_uint8 __setting_type =
SETTING_TYPE_UINT ( SETTING_TYPE_INT8 );
/** An unsigned 16-bit integer setting type */
-struct setting_type setting_type_uint16 __setting_type =
+const struct setting_type setting_type_uint16 __setting_type =
SETTING_TYPE_UINT ( SETTING_TYPE_INT16 );
/** An unsigned 32-bit integer setting type */
-struct setting_type setting_type_uint32 __setting_type =
+const struct setting_type setting_type_uint32 __setting_type =
SETTING_TYPE_UINT ( SETTING_TYPE_INT32 );
/**
@@ -1918,7 +1983,7 @@ static int format_hex_setting ( const char *delimiter, const void *raw,
* @v size Integer size, in bytes
* @ret len Length of raw value, or negative error
*/
-static int parse_hex_setting ( struct setting_type *type __unused,
+static int parse_hex_setting ( const struct setting_type *type __unused,
const char *value, void *buf, size_t len ) {
return hex_decode ( value, ':', buf, len );
}
@@ -1933,7 +1998,7 @@ static int parse_hex_setting ( struct setting_type *type __unused,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_hex_colon_setting ( struct setting_type *type __unused,
+static int format_hex_colon_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len,
char *buf, size_t len ) {
return format_hex_setting ( ":", raw, raw_len, buf, len );
@@ -1949,7 +2014,7 @@ static int format_hex_colon_setting ( struct setting_type *type __unused,
* @v size Integer size, in bytes
* @ret len Length of raw value, or negative error
*/
-static int parse_hex_hyphen_setting ( struct setting_type *type __unused,
+static int parse_hex_hyphen_setting ( const struct setting_type *type __unused,
const char *value, void *buf,
size_t len ) {
return hex_decode ( value, '-', buf, len );
@@ -1965,7 +2030,7 @@ static int parse_hex_hyphen_setting ( struct setting_type *type __unused,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_hex_hyphen_setting ( struct setting_type *type __unused,
+static int format_hex_hyphen_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len,
char *buf, size_t len ) {
return format_hex_setting ( "-", raw, raw_len, buf, len );
@@ -1981,7 +2046,7 @@ static int format_hex_hyphen_setting ( struct setting_type *type __unused,
* @v size Integer size, in bytes
* @ret len Length of raw value, or negative error
*/
-static int parse_hex_raw_setting ( struct setting_type *type __unused,
+static int parse_hex_raw_setting ( const struct setting_type *type __unused,
const char *value, void *buf, size_t len ) {
return hex_decode ( value, 0, buf, len );
}
@@ -1996,28 +2061,28 @@ static int parse_hex_raw_setting ( struct setting_type *type __unused,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_hex_raw_setting ( struct setting_type *type __unused,
+static int format_hex_raw_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len,
char *buf, size_t len ) {
return format_hex_setting ( "", raw, raw_len, buf, len );
}
/** A hex-string setting (colon-delimited) */
-struct setting_type setting_type_hex __setting_type = {
+const struct setting_type setting_type_hex __setting_type = {
.name = "hex",
.parse = parse_hex_setting,
.format = format_hex_colon_setting,
};
/** A hex-string setting (hyphen-delimited) */
-struct setting_type setting_type_hexhyp __setting_type = {
+const struct setting_type setting_type_hexhyp __setting_type = {
.name = "hexhyp",
.parse = parse_hex_hyphen_setting,
.format = format_hex_hyphen_setting,
};
/** A hex-string setting (non-delimited) */
-struct setting_type setting_type_hexraw __setting_type = {
+const struct setting_type setting_type_hexraw __setting_type = {
.name = "hexraw",
.parse = parse_hex_raw_setting,
.format = format_hex_raw_setting,
@@ -2033,7 +2098,7 @@ struct setting_type setting_type_hexraw __setting_type = {
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_uuid_setting ( struct setting_type *type __unused,
+static int format_uuid_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len, char *buf,
size_t len ) {
const union uuid *uuid = raw;
@@ -2047,7 +2112,7 @@ static int format_uuid_setting ( struct setting_type *type __unused,
}
/** UUID setting type */
-struct setting_type setting_type_uuid __setting_type = {
+const struct setting_type setting_type_uuid __setting_type = {
.name = "uuid",
.format = format_uuid_setting,
};
@@ -2062,7 +2127,7 @@ struct setting_type setting_type_uuid __setting_type = {
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
-static int format_busdevfn_setting ( struct setting_type *type __unused,
+static int format_busdevfn_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len, char *buf,
size_t len ) {
unsigned long busdevfn;
@@ -2080,7 +2145,7 @@ static int format_busdevfn_setting ( struct setting_type *type __unused,
}
/** PCI bus:dev.fn setting type */
-struct setting_type setting_type_busdevfn __setting_type = {
+const struct setting_type setting_type_busdevfn __setting_type = {
.name = "busdevfn",
.format = format_busdevfn_setting,
};
@@ -2153,7 +2218,8 @@ char * expand_settings ( const char *string ) {
/* Fetch and format setting value. Ignore
* errors; treat non-existent settings as empty.
*/
- fetchf_setting_copy ( settings, &setting, &value );
+ fetchf_setting_copy ( settings, &setting, NULL, NULL,
+ &value );
}
/* Construct expanded string and discard old string */
@@ -2177,7 +2243,7 @@ char * expand_settings ( const char *string ) {
*/
/** Hostname setting */
-struct setting hostname_setting __setting ( SETTING_HOST ) = {
+const struct setting hostname_setting __setting ( SETTING_HOST ) = {
.name = "hostname",
.description = "Host name",
.tag = DHCP_HOST_NAME,
@@ -2185,7 +2251,7 @@ struct setting hostname_setting __setting ( SETTING_HOST ) = {
};
/** Domain name setting */
-struct setting domain_setting __setting ( SETTING_IPv4_EXTRA ) = {
+const struct setting domain_setting __setting ( SETTING_IPv4_EXTRA ) = {
.name = "domain",
.description = "DNS domain",
.tag = DHCP_DOMAIN_NAME,
@@ -2193,7 +2259,7 @@ struct setting domain_setting __setting ( SETTING_IPv4_EXTRA ) = {
};
/** TFTP server setting */
-struct setting next_server_setting __setting ( SETTING_BOOT ) = {
+const struct setting next_server_setting __setting ( SETTING_BOOT ) = {
.name = "next-server",
.description = "TFTP server",
.tag = DHCP_EB_SIADDR,
@@ -2201,7 +2267,7 @@ struct setting next_server_setting __setting ( SETTING_BOOT ) = {
};
/** Filename setting */
-struct setting filename_setting __setting ( SETTING_BOOT ) = {
+const struct setting filename_setting __setting ( SETTING_BOOT ) = {
.name = "filename",
.description = "Boot filename",
.tag = DHCP_BOOTFILE_NAME,
@@ -2209,7 +2275,7 @@ struct setting filename_setting __setting ( SETTING_BOOT ) = {
};
/** Root path setting */
-struct setting root_path_setting __setting ( SETTING_SANBOOT ) = {
+const struct setting root_path_setting __setting ( SETTING_SANBOOT ) = {
.name = "root-path",
.description = "SAN root path",
.tag = DHCP_ROOT_PATH,
@@ -2217,7 +2283,7 @@ struct setting root_path_setting __setting ( SETTING_SANBOOT ) = {
};
/** Username setting */
-struct setting username_setting __setting ( SETTING_AUTH ) = {
+const struct setting username_setting __setting ( SETTING_AUTH ) = {
.name = "username",
.description = "User name",
.tag = DHCP_EB_USERNAME,
@@ -2225,7 +2291,7 @@ struct setting username_setting __setting ( SETTING_AUTH ) = {
};
/** Password setting */
-struct setting password_setting __setting ( SETTING_AUTH ) = {
+const struct setting password_setting __setting ( SETTING_AUTH ) = {
.name = "password",
.description = "Password",
.tag = DHCP_EB_PASSWORD,
@@ -2233,7 +2299,7 @@ struct setting password_setting __setting ( SETTING_AUTH ) = {
};
/** Priority setting */
-struct setting priority_setting __setting ( SETTING_MISC ) = {
+const struct setting priority_setting __setting ( SETTING_MISC ) = {
.name = "priority",
.description = "Settings priority",
.tag = DHCP_EB_PRIORITY,
@@ -2241,7 +2307,7 @@ struct setting priority_setting __setting ( SETTING_MISC ) = {
};
/** DHCP user class setting */
-struct setting user_class_setting __setting ( SETTING_HOST_EXTRA ) = {
+const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA ) = {
.name = "user-class",
.description = "DHCP user class",
.tag = DHCP_USER_CLASS_ID,
@@ -2256,7 +2322,7 @@ struct setting user_class_setting __setting ( SETTING_HOST_EXTRA ) = {
*/
/** Built-in setting scope */
-struct settings_scope builtin_scope;
+const struct settings_scope builtin_scope;
/**
* Fetch error number setting
@@ -2277,7 +2343,7 @@ static int errno_fetch ( void *data, size_t len ) {
}
/** Error number setting */
-struct setting errno_setting __setting ( SETTING_MISC ) = {
+const struct setting errno_setting __setting ( SETTING_MISC ) = {
.name = "errno",
.description = "Last error",
.type = &setting_type_uint32,
@@ -2305,7 +2371,7 @@ static int buildarch_fetch ( void *data, size_t len ) {
}
/** Build architecture setting */
-struct setting buildarch_setting __setting ( SETTING_MISC ) = {
+const struct setting buildarch_setting __setting ( SETTING_MISC ) = {
.name = "buildarch",
.description = "Build architecture",
.type = &setting_type_string,
@@ -2333,7 +2399,7 @@ static int platform_fetch ( void *data, size_t len ) {
}
/** Platform setting */
-struct setting platform_setting __setting ( SETTING_MISC ) = {
+const struct setting platform_setting __setting ( SETTING_MISC ) = {
.name = "platform",
.description = "Platform",
.type = &setting_type_string,
@@ -2359,7 +2425,7 @@ static int version_fetch ( void *data, size_t len ) {
}
/** Version setting */
-struct setting version_setting __setting ( SETTING_MISC ) = {
+const struct setting version_setting __setting ( SETTING_MISC ) = {
.name = "version",
.description = "Version",
.type = &setting_type_string,
@@ -2401,7 +2467,7 @@ static int builtin_fetch ( struct settings *settings __unused,
* @ret applies Setting applies within this settings block
*/
static int builtin_applies ( struct settings *settings __unused,
- struct setting *setting ) {
+ const struct setting *setting ) {
return ( setting->scope == &builtin_scope );
}