mirror of https://github.com/ipxe/ipxe.git
[image] Provide image_set_len() utility function
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/373/head
parent
106f4c5391
commit
de4f31cdca
|
@ -175,6 +175,26 @@ int image_set_cmdline ( struct image *image, const char *cmdline ) {
|
|||
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
|
||||
*
|
||||
|
@ -184,17 +204,14 @@ int image_set_cmdline ( struct image *image, const char *cmdline ) {
|
|||
* @ret rc Return status code
|
||||
*/
|
||||
int image_set_data ( struct image *image, userptr_t data, size_t len ) {
|
||||
userptr_t new;
|
||||
int rc;
|
||||
|
||||
/* (Re)allocate image data */
|
||||
new = urealloc ( image->data, len );
|
||||
if ( ! new )
|
||||
return -ENOMEM;
|
||||
image->data = new;
|
||||
/* Set image length */
|
||||
if ( ( rc = image_set_len ( image, len ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Copy in new image data */
|
||||
memcpy_user ( image->data, 0, data, 0, len );
|
||||
image->len = len;
|
||||
|
||||
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_name ( struct image *image, const char *name );
|
||||
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 register_image ( struct image *image );
|
||||
extern void unregister_image ( struct image *image );
|
||||
|
|
Loading…
Reference in New Issue