mirror of
https://github.com/ipxe/ipxe
synced 2026-03-16 03:02:07 +03:00
[image] Provide image_set_len() utility function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -175,6 +175,26 @@ int image_set_cmdline ( struct image *image, const char *cmdline ) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set image length
|
||||||
|
*
|
||||||
|
* @v image Image
|
||||||
|
* @v len Length of image data
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
int image_set_len ( struct image *image, size_t len ) {
|
||||||
|
userptr_t new;
|
||||||
|
|
||||||
|
/* (Re)allocate image data */
|
||||||
|
new = urealloc ( image->data, len );
|
||||||
|
if ( ! new )
|
||||||
|
return -ENOMEM;
|
||||||
|
image->data = new;
|
||||||
|
image->len = len;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set image data
|
* Set image data
|
||||||
*
|
*
|
||||||
@@ -184,17 +204,14 @@ int image_set_cmdline ( struct image *image, const char *cmdline ) {
|
|||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int image_set_data ( struct image *image, userptr_t data, size_t len ) {
|
int image_set_data ( struct image *image, userptr_t data, size_t len ) {
|
||||||
userptr_t new;
|
int rc;
|
||||||
|
|
||||||
/* (Re)allocate image data */
|
/* Set image length */
|
||||||
new = urealloc ( image->data, len );
|
if ( ( rc = image_set_len ( image, len ) ) != 0 )
|
||||||
if ( ! new )
|
return rc;
|
||||||
return -ENOMEM;
|
|
||||||
image->data = new;
|
|
||||||
|
|
||||||
/* Copy in new image data */
|
/* Copy in new image data */
|
||||||
memcpy_user ( image->data, 0, data, 0, len );
|
memcpy_user ( image->data, 0, data, 0, len );
|
||||||
image->len = len;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ extern struct image * alloc_image ( struct uri *uri );
|
|||||||
extern int image_set_uri ( struct image *image, struct uri *uri );
|
extern int image_set_uri ( struct image *image, struct uri *uri );
|
||||||
extern int image_set_name ( struct image *image, const char *name );
|
extern int image_set_name ( struct image *image, const char *name );
|
||||||
extern int image_set_cmdline ( struct image *image, const char *cmdline );
|
extern int image_set_cmdline ( struct image *image, const char *cmdline );
|
||||||
|
extern int image_set_len ( struct image *image, size_t len );
|
||||||
extern int image_set_data ( struct image *image, userptr_t data, size_t len );
|
extern int image_set_data ( struct image *image, userptr_t data, size_t len );
|
||||||
extern int register_image ( struct image *image );
|
extern int register_image ( struct image *image );
|
||||||
extern void unregister_image ( struct image *image );
|
extern void unregister_image ( struct image *image );
|
||||||
|
|||||||
Reference in New Issue
Block a user