MCPcopy Create free account
hub / github.com/coreboot/coreboot / cbfs_copy_instance

Function cbfs_copy_instance

util/cbfstool/cbfs_image.c:356–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

354}
355
356int cbfs_copy_instance(struct cbfs_image *image, struct buffer *dst)
357{
358 assert(image);
359
360 struct cbfs_file *src_entry, *dst_entry;
361 size_t align;
362 ssize_t last_entry_size;
363
364 size_t copy_end = buffer_size(dst);
365
366 align = CBFS_ALIGNMENT;
367
368 dst_entry = (struct cbfs_file *)buffer_get(dst);
369
370 /* Copy non-empty files */
371 for (src_entry = cbfs_find_first_entry(image);
372 src_entry && cbfs_is_valid_entry(image, src_entry);
373 src_entry = cbfs_find_next_entry(image, src_entry)) {
374 size_t entry_size;
375
376 if ((src_entry->type == htobe32(CBFS_TYPE_NULL)) ||
377 (src_entry->type == htobe32(CBFS_TYPE_CBFSHEADER)) ||
378 (src_entry->type == htobe32(CBFS_TYPE_DELETED)))
379 continue;
380
381 entry_size = htobe32(src_entry->len) + htobe32(src_entry->offset);
382 memcpy(dst_entry, src_entry, entry_size);
383 dst_entry = (struct cbfs_file *)(
384 (uintptr_t)dst_entry + align_up(entry_size, align));
385
386 if ((size_t)((uint8_t *)dst_entry - (uint8_t *)buffer_get(dst))
387 >= copy_end) {
388 ERROR("Ran out of room in copy region.\n");
389 return 1;
390 }
391 }
392
393 /* Last entry size is all the room above it, except for top 4 bytes
394 * which may be used by the master header pointer. This messes with
395 * the ability to stash something "top-aligned" into the region, but
396 * keeps things simpler. */
397 last_entry_size = copy_end -
398 ((uint8_t *)dst_entry - (uint8_t *)buffer_get(dst)) -
399 cbfs_calculate_file_header_size("") - sizeof(int32_t);
400
401 if (last_entry_size < 0)
402 WARN("No room to create the last entry!\n");
403 else
404 return cbfs_create_empty_entry(dst_entry, CBFS_TYPE_NULL,
405 last_entry_size, "");
406
407 return 0;
408}
409
410int cbfs_expand_to_region(struct buffer *region)
411{

Callers 1

cbfs_copyFunction · 0.85

Calls 9

buffer_sizeFunction · 0.85
buffer_getFunction · 0.85
cbfs_find_first_entryFunction · 0.85
cbfs_is_valid_entryFunction · 0.85
cbfs_find_next_entryFunction · 0.85
cbfs_create_empty_entryFunction · 0.85
align_upFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected