mirror of
https://github.com/ipxe/ipxe
synced 2025-12-14 16:01:38 +03:00
Added IMAGE_LOADED flag and find_image()
This commit is contained in:
@@ -72,6 +72,23 @@ void unregister_image ( struct image *image ) {
|
|||||||
DBGC ( image, "IMAGE %p unregistered\n", image );
|
DBGC ( image, "IMAGE %p unregistered\n", image );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find image by name
|
||||||
|
*
|
||||||
|
* @v name Image name
|
||||||
|
* @ret image Executable/loadable image, or NULL
|
||||||
|
*/
|
||||||
|
struct image * find_image ( const char *name ) {
|
||||||
|
struct image *image;
|
||||||
|
|
||||||
|
list_for_each_entry ( image, &images, list ) {
|
||||||
|
if ( strcmp ( image->name, name ) == 0 )
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load executable/loadable image into memory
|
* Load executable/loadable image into memory
|
||||||
*
|
*
|
||||||
@@ -89,6 +106,7 @@ int image_load ( struct image *image ) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
image->flags |= IMAGE_LOADED;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +129,7 @@ int image_autoload ( struct image *image ) {
|
|||||||
image, image->type->name, strerror ( rc ) );
|
image, image->type->name, strerror ( rc ) );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
image->flags |= IMAGE_LOADED;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,8 +146,16 @@ int image_autoload ( struct image *image ) {
|
|||||||
int image_exec ( struct image *image ) {
|
int image_exec ( struct image *image ) {
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
/* Image must be loaded first */
|
||||||
|
if ( ! ( image->flags & IMAGE_LOADED ) ) {
|
||||||
|
DBGC ( image, "IMAGE %p could not execute: not loaded\n",
|
||||||
|
image );
|
||||||
|
return -ENOTTY;
|
||||||
|
}
|
||||||
|
|
||||||
assert ( image->type != NULL );
|
assert ( image->type != NULL );
|
||||||
|
|
||||||
|
/* Try executing the image */
|
||||||
if ( ( rc = image->type->exec ( image ) ) != 0 ) {
|
if ( ( rc = image->type->exec ( image ) ) != 0 ) {
|
||||||
DBGC ( image, "IMAGE %p could not execute: %s\n",
|
DBGC ( image, "IMAGE %p could not execute: %s\n",
|
||||||
image, strerror ( rc ) );
|
image, strerror ( rc ) );
|
||||||
|
|||||||
@@ -45,8 +45,14 @@ struct image {
|
|||||||
|
|
||||||
/** Image type, if known */
|
/** Image type, if known */
|
||||||
struct image_type *type;
|
struct image_type *type;
|
||||||
|
|
||||||
|
/** Flags */
|
||||||
|
unsigned int flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Image is loaded */
|
||||||
|
#define IMAGE_LOADED 0x0001
|
||||||
|
|
||||||
/** An executable or loadable image type */
|
/** An executable or loadable image type */
|
||||||
struct image_type {
|
struct image_type {
|
||||||
/** Name of this image type */
|
/** Name of this image type */
|
||||||
@@ -102,6 +108,7 @@ extern struct list_head images;
|
|||||||
|
|
||||||
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 );
|
||||||
|
struct image * find_image ( const char *name );
|
||||||
extern int image_load ( struct image *image );
|
extern int image_load ( struct image *image );
|
||||||
extern int image_autoload ( struct image *image );
|
extern int image_autoload ( struct image *image );
|
||||||
extern int image_exec ( struct image *image );
|
extern int image_exec ( struct image *image );
|
||||||
|
|||||||
Reference in New Issue
Block a user