mirror of
https://github.com/ipxe/ipxe
synced 2026-01-28 20:12:28 +03:00
[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>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user