diff options
author | Michael Brown <mcb30@ipxe.org> | 2021-05-06 13:09:30 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2021-05-08 15:34:19 +0100 |
commit | de4f31cdcad7c4734c68da828351eeb7afd0360e (patch) | |
tree | d776dd3e9ffceb7b90019e80046d1b49d099a21b /src | |
parent | 106f4c539182b4a92b8a427b637497e6da19bd85 (diff) | |
download | ipxe-de4f31cdcad7c4734c68da828351eeb7afd0360e.zip ipxe-de4f31cdcad7c4734c68da828351eeb7afd0360e.tar.gz ipxe-de4f31cdcad7c4734c68da828351eeb7afd0360e.tar.bz2 |
[image] Provide image_set_len() utility function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/image.c | 25 | ||||
-rw-r--r-- | src/include/ipxe/image.h | 1 |
2 files changed, 22 insertions, 4 deletions
diff --git a/src/core/image.c b/src/core/image.c index 9fe77c5..ce8cf86 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -176,14 +176,13 @@ int image_set_cmdline ( struct image *image, const char *cmdline ) { } /** - * Set image data + * Set image length * * @v image Image - * @v data Image data * @v len Length of image data * @ret rc Return status code */ -int image_set_data ( struct image *image, userptr_t data, size_t len ) { +int image_set_len ( struct image *image, size_t len ) { userptr_t new; /* (Re)allocate image data */ @@ -191,10 +190,28 @@ int image_set_data ( struct image *image, userptr_t data, size_t len ) { if ( ! new ) return -ENOMEM; image->data = new; + image->len = len; + + return 0; +} + +/** + * Set image data + * + * @v image Image + * @v data Image data + * @v len Length of image data + * @ret rc Return status code + */ +int image_set_data ( struct image *image, userptr_t data, size_t len ) { + int rc; + + /* 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; } diff --git a/src/include/ipxe/image.h b/src/include/ipxe/image.h index 4fd2700..046edf9 100644 --- a/src/include/ipxe/image.h +++ b/src/include/ipxe/image.h @@ -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 ); |