mirror of
https://github.com/ipxe/ipxe
synced 2025-12-13 23:41:45 +03:00
[image] Provide image_set_uri() to modify an image's URI
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -88,7 +88,6 @@ static void free_image ( struct refcnt *refcnt ) {
|
|||||||
* @ret image Executable image
|
* @ret image Executable image
|
||||||
*/
|
*/
|
||||||
struct image * alloc_image ( struct uri *uri ) {
|
struct image * alloc_image ( struct uri *uri ) {
|
||||||
const char *name;
|
|
||||||
struct image *image;
|
struct image *image;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@@ -99,23 +98,42 @@ struct image * alloc_image ( struct uri *uri ) {
|
|||||||
|
|
||||||
/* Initialise image */
|
/* Initialise image */
|
||||||
ref_init ( &image->refcnt, free_image );
|
ref_init ( &image->refcnt, free_image );
|
||||||
if ( uri ) {
|
if ( uri && ( ( rc = image_set_uri ( image, uri ) ) != 0 ) )
|
||||||
image->uri = uri_get ( uri );
|
goto err_set_uri;
|
||||||
if ( uri->path ) {
|
|
||||||
name = basename ( ( char * ) uri->path );
|
|
||||||
if ( ( rc = image_set_name ( image, name ) ) != 0 )
|
|
||||||
goto err_set_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
|
|
||||||
err_set_name:
|
err_set_uri:
|
||||||
image_put ( image );
|
image_put ( image );
|
||||||
err_alloc:
|
err_alloc:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set image URI
|
||||||
|
*
|
||||||
|
* @v image Image
|
||||||
|
* @v uri New image URI
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
int image_set_uri ( struct image *image, struct uri *uri ) {
|
||||||
|
const char *name;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Set name, if image does not already have one */
|
||||||
|
if ( uri->path && ( ! ( image->name && image->name[0] ) ) ) {
|
||||||
|
name = basename ( ( char * ) uri->path );
|
||||||
|
if ( ( rc = image_set_name ( image, name ) ) != 0 )
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update image URI */
|
||||||
|
uri_put ( image->uri );
|
||||||
|
image->uri = uri_get ( uri );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set image name
|
* Set image name
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ static inline struct image * first_image ( void ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern struct image * alloc_image ( struct uri *uri );
|
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_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 register_image ( struct image *image );
|
extern int register_image ( struct image *image );
|
||||||
|
|||||||
Reference in New Issue
Block a user