2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-23 01:51:58 +00:00

[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>
This commit is contained in:
Michael Brown 2010-11-25 00:05:20 +00:00
parent ce7b0efa87
commit b87ed3295e

View File

@ -197,7 +197,7 @@ static struct settings_operations nvo_settings_operations = {
*
* @v nvo Non-volatile options block
* @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
*/
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;
int rc;
/* Calculate total length of all fragments */
for ( fragment = nvo->fragments ; fragment->len ; fragment++ )
nvo->total_len += fragment->len;
/* Calculate total length of all fragments, if applicable */
if ( fragment ) {
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 */
nvo->data = malloc ( nvo->total_len );
/* Allocate memory for options (and fragment list, if applicable) */
nvo->data = zalloc ( nvo->total_len +
( fragment ? 0 : ( 2 * sizeof ( *fragment ) ) ) );
if ( ! nvo->data ) {
DBGC ( nvo, "NVO %p could not allocate %zd bytes\n",
nvo, nvo->total_len );
rc = -ENOMEM;
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 )
goto err_load;