mirror of https://github.com/ipxe/ipxe.git
[nvo] Allow fragment list to be omitted
Allow the fragment list to be omitted when calling nvo_init(). Omitting the list will cause the whole of the NVS device to be used for NVO storage. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1/head
parent
ce7b0efa87
commit
b87ed3295e
|
@ -197,7 +197,7 @@ static struct settings_operations nvo_settings_operations = {
|
||||||
*
|
*
|
||||||
* @v nvo Non-volatile options block
|
* @v nvo Non-volatile options block
|
||||||
* @v nvs Underlying non-volatile storage device
|
* @v nvs Underlying non-volatile storage device
|
||||||
* @v fragments List of option-containing fragments
|
* @v fragments List of option-containing fragments, or NULL
|
||||||
* @v refcnt Containing object reference counter, or NULL
|
* @v refcnt Containing object reference counter, or NULL
|
||||||
*/
|
*/
|
||||||
void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
|
void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
|
||||||
|
@ -219,18 +219,32 @@ int register_nvo ( struct nvo_block *nvo, struct settings *parent ) {
|
||||||
struct nvo_fragment *fragment = nvo->fragments;
|
struct nvo_fragment *fragment = nvo->fragments;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Calculate total length of all fragments */
|
/* Calculate total length of all fragments, if applicable */
|
||||||
for ( fragment = nvo->fragments ; fragment->len ; fragment++ )
|
if ( fragment ) {
|
||||||
nvo->total_len += fragment->len;
|
for ( ; fragment->len ; fragment++ )
|
||||||
|
nvo->total_len += fragment->len;
|
||||||
|
} else {
|
||||||
|
nvo->total_len = nvo->nvs->size;
|
||||||
|
}
|
||||||
|
|
||||||
/* Allocate memory for options and read in from NVS */
|
/* Allocate memory for options (and fragment list, if applicable) */
|
||||||
nvo->data = malloc ( nvo->total_len );
|
nvo->data = zalloc ( nvo->total_len +
|
||||||
|
( fragment ? 0 : ( 2 * sizeof ( *fragment ) ) ) );
|
||||||
if ( ! nvo->data ) {
|
if ( ! nvo->data ) {
|
||||||
DBGC ( nvo, "NVO %p could not allocate %zd bytes\n",
|
DBGC ( nvo, "NVO %p could not allocate %zd bytes\n",
|
||||||
nvo, nvo->total_len );
|
nvo, nvo->total_len );
|
||||||
rc = -ENOMEM;
|
rc = -ENOMEM;
|
||||||
goto err_malloc;
|
goto err_malloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create fragment list, if applicable */
|
||||||
|
if ( ! fragment ) {
|
||||||
|
fragment = ( nvo->data + nvo->total_len );
|
||||||
|
fragment->len = nvo->total_len;
|
||||||
|
nvo->fragments = fragment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read data from NVS */
|
||||||
if ( ( rc = nvo_load ( nvo ) ) != 0 )
|
if ( ( rc = nvo_load ( nvo ) ) != 0 )
|
||||||
goto err_load;
|
goto err_load;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue