Sfoglia il codice sorgente

[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>
tags/v1.20.1
Michael Brown 14 anni fa
parent
commit
b87ed3295e
1 ha cambiato i file con 20 aggiunte e 6 eliminazioni
  1. 20
    6
      src/core/nvo.c

+ 20
- 6
src/core/nvo.c Vedi File

@@ -197,7 +197,7 @@ static struct settings_operations nvo_settings_operations = {
197 197
  *
198 198
  * @v nvo		Non-volatile options block
199 199
  * @v nvs		Underlying non-volatile storage device
200
- * @v fragments		List of option-containing fragments
200
+ * @v fragments		List of option-containing fragments, or NULL
201 201
  * @v refcnt		Containing object reference counter, or NULL
202 202
  */
203 203
 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 ) {
219 219
 	struct nvo_fragment *fragment = nvo->fragments;
220 220
 	int rc;
221 221
 
222
-	/* Calculate total length of all fragments */
223
-	for ( fragment = nvo->fragments ; fragment->len ; fragment++ )
224
-		nvo->total_len += fragment->len;
222
+	/* Calculate total length of all fragments, if applicable */
223
+	if ( fragment ) {
224
+		for ( ; fragment->len ; fragment++ )
225
+			nvo->total_len += fragment->len;
226
+	} else {
227
+		nvo->total_len = nvo->nvs->size;
228
+	}
225 229
 
226
-	/* Allocate memory for options and read in from NVS */
227
-	nvo->data = malloc ( nvo->total_len );
230
+	/* Allocate memory for options (and fragment list, if applicable) */
231
+	nvo->data = zalloc ( nvo->total_len +
232
+			     ( fragment ? 0 : ( 2 * sizeof ( *fragment ) ) ) );
228 233
 	if ( ! nvo->data ) {
229 234
 		DBGC ( nvo, "NVO %p could not allocate %zd bytes\n",
230 235
 		       nvo, nvo->total_len );
231 236
 		rc = -ENOMEM;
232 237
 		goto err_malloc;
233 238
 	}
239
+
240
+	/* Create fragment list, if applicable */
241
+	if ( ! fragment ) {
242
+		fragment = ( nvo->data + nvo->total_len );
243
+		fragment->len = nvo->total_len;
244
+		nvo->fragments = fragment;
245
+	}
246
+
247
+	/* Read data from NVS */
234 248
 	if ( ( rc = nvo_load ( nvo ) ) != 0 )
235 249
 		goto err_load;
236 250
 

Loading…
Annulla
Salva