diff options
author | Michael Brown <mcb30@ipxe.org> | 2021-01-25 16:18:28 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2021-01-25 17:03:56 +0000 |
commit | 989a7a8032db02eb0524bd78a674d3b087dea3a6 (patch) | |
tree | 3ead7f99b466e3274d29dbeb0df7374905ff92d5 /src/core | |
parent | ffc41ae9d12f319be67053e529091c8710303d3c (diff) | |
download | ipxe-989a7a8032db02eb0524bd78a674d3b087dea3a6.tar.gz |
[image] Provide image_memory()
Consolidate the remaining logic common to initrd_init() and imgmem()
into a shared image_memory() function.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/image.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/core/image.c b/src/core/image.c index 54b998025..9fe77c54c 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -505,3 +505,47 @@ int image_set_trust ( int require_trusted, int permanent ) { return 0; } + +/** + * Create registered image from block of memory + * + * @v name Name + * @v data Image data + * @v len Length + * @ret image Image, or NULL on error + */ +struct image * image_memory ( const char *name, userptr_t data, size_t len ) { + struct image *image; + int rc; + + /* Allocate image */ + image = alloc_image ( NULL ); + if ( ! image ) { + rc = -ENOMEM; + goto err_alloc_image; + } + + /* Set name */ + if ( ( rc = image_set_name ( image, name ) ) != 0 ) + goto err_set_name; + + /* Set data */ + if ( ( rc = image_set_data ( image, data, len ) ) != 0 ) + goto err_set_data; + + /* Register image */ + if ( ( rc = register_image ( image ) ) != 0 ) + goto err_register; + + /* Drop local reference to image */ + image_put ( image ); + + return image; + + err_register: + err_set_data: + err_set_name: + image_put ( image ); + err_alloc_image: + return NULL; +} |