diff options
author | Michael Brown | 2007-08-02 21:18:32 +0200 |
---|---|---|
committer | Michael Brown | 2007-08-02 21:18:32 +0200 |
commit | d4947c05b27449b4320179d57028a0542fd1394f (patch) | |
tree | dc9732c85f3904d04c2d7addf511c01c99dfb7fd /src/core/image.c | |
parent | Allowed zero-cost enforced ordering of features in startup banner (diff) | |
download | ipxe-d4947c05b27449b4320179d57028a0542fd1394f.tar.gz ipxe-d4947c05b27449b4320179d57028a0542fd1394f.tar.xz ipxe-d4947c05b27449b4320179d57028a0542fd1394f.zip |
Allow images to hold references to the originating URI.
Some shuffling around of the image management code; this needs tidying up.
Diffstat (limited to 'src/core/image.c')
-rw-r--r-- | src/core/image.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/core/image.c b/src/core/image.c index 04bd0839..63c2502b 100644 --- a/src/core/image.c +++ b/src/core/image.c @@ -22,8 +22,10 @@ #include <stdio.h> #include <errno.h> #include <assert.h> +#include <libgen.h> #include <gpxe/list.h> #include <gpxe/umalloc.h> +#include <gpxe/uri.h> #include <gpxe/image.h> /** @file @@ -49,6 +51,7 @@ static struct image_type image_types_end[0] static void free_image ( struct refcnt *refcnt ) { struct image *image = container_of ( refcnt, struct image, refcnt ); + uri_put ( image->uri ); ufree ( image->data ); free ( image ); DBGC ( image, "IMAGE %p freed\n", image ); @@ -70,6 +73,45 @@ struct image * alloc_image ( void ) { } /** + * Set image URI + * + * @v image Image + * @v URI New image URI + * @ret rc Return status code + * + * If no name is set, the name will be updated to the base name of the + * URI path (if any). + */ +int image_set_uri ( struct image *image, struct uri *uri ) { + const char *path = uri->path; + + /* Replace URI reference */ + uri_put ( image->uri ); + image->uri = uri_get ( uri ); + + /* Set name if none already specified */ + if ( path && ( ! image->name[0] ) ) + image_set_name ( image, basename ( ( char * ) path ) ); + + return 0; +} + +/** + * Set image command line + * + * @v image Image + * @v cmdline New image command line + * @ret rc Return status code + */ +int image_set_cmdline ( struct image *image, const char *cmdline ) { + free ( image->cmdline ); + image->cmdline = strdup ( cmdline ); + if ( ! image->cmdline ) + return -ENOMEM; + return 0; +} + +/** * Register executable/loadable image * * @v image Executable/loadable image @@ -220,3 +262,39 @@ int image_exec ( struct image *image ) { /* Well, some formats might return... */ return 0; } + +/** + * Register and autoload an image + * + * @v image Image + * @ret rc Return status code + */ +int register_and_autoload_image ( struct image *image ) { + int rc; + + if ( ( rc = register_image ( image ) ) != 0 ) + return rc; + + if ( ( rc = image_autoload ( image ) ) != 0 ) + return rc; + + return 0; +} + +/** + * Register and autoexec an image + * + * @v image Image + * @ret rc Return status code + */ +int register_and_autoexec_image ( struct image *image ) { + int rc; + + if ( ( rc = register_and_autoload_image ( image ) ) != 0 ) + return rc; + + if ( ( rc = image_exec ( image ) ) != 0 ) + return rc; + + return 0; +} |