Просмотр исходного кода

Added IMAGE_LOADED flag and find_image()

tags/v0.9.3
Michael Brown 17 лет назад
Родитель
Сommit
b9fea9cbac
2 измененных файлов: 34 добавлений и 0 удалений
  1. 27
    0
      src/core/image.c
  2. 7
    0
      src/include/gpxe/image.h

+ 27
- 0
src/core/image.c Просмотреть файл

@@ -72,6 +72,23 @@ void unregister_image ( struct image *image ) {
72 72
 	DBGC ( image, "IMAGE %p unregistered\n", image );
73 73
 }
74 74
 
75
+/**
76
+ * Find image by name
77
+ *
78
+ * @v name		Image name
79
+ * @ret image		Executable/loadable image, or NULL
80
+ */
81
+struct image * find_image ( const char *name ) {
82
+	struct image *image;
83
+
84
+	list_for_each_entry ( image, &images, list ) {
85
+		if ( strcmp ( image->name, name ) == 0 )
86
+			return image;
87
+	}
88
+
89
+	return NULL;
90
+}
91
+
75 92
 /**
76 93
  * Load executable/loadable image into memory
77 94
  *
@@ -89,6 +106,7 @@ int image_load ( struct image *image ) {
89 106
 		return rc;
90 107
 	}
91 108
 
109
+	image->flags |= IMAGE_LOADED;
92 110
 	return 0;
93 111
 }
94 112
 
@@ -111,6 +129,7 @@ int image_autoload ( struct image *image ) {
111 129
 			       image, image->type->name, strerror ( rc ) );
112 130
 			return rc;
113 131
 		}
132
+		image->flags |= IMAGE_LOADED;
114 133
 		return 0;
115 134
 	}
116 135
 
@@ -127,8 +146,16 @@ int image_autoload ( struct image *image ) {
127 146
 int image_exec ( struct image *image ) {
128 147
 	int rc;
129 148
 
149
+	/* Image must be loaded first */
150
+	if ( ! ( image->flags & IMAGE_LOADED ) ) {
151
+		DBGC ( image, "IMAGE %p could not execute: not loaded\n",
152
+		       image );
153
+		return -ENOTTY;
154
+	}
155
+
130 156
 	assert ( image->type != NULL );
131 157
 
158
+	/* Try executing the image */
132 159
 	if ( ( rc = image->type->exec ( image ) ) != 0 ) {
133 160
 		DBGC ( image, "IMAGE %p could not execute: %s\n",
134 161
 		       image, strerror ( rc ) );

+ 7
- 0
src/include/gpxe/image.h Просмотреть файл

@@ -45,8 +45,14 @@ struct image {
45 45
 
46 46
 	/** Image type, if known */
47 47
 	struct image_type *type;
48
+
49
+	/** Flags */
50
+	unsigned int flags;
48 51
 };
49 52
 
53
+/** Image is loaded */
54
+#define IMAGE_LOADED 0x0001
55
+
50 56
 /** An executable or loadable image type */
51 57
 struct image_type {
52 58
 	/** Name of this image type */
@@ -102,6 +108,7 @@ extern struct list_head images;
102 108
 
103 109
 extern int register_image ( struct image *image );
104 110
 extern void unregister_image ( struct image *image );
111
+struct image * find_image ( const char *name );
105 112
 extern int image_load ( struct image *image );
106 113
 extern int image_autoload ( struct image *image );
107 114
 extern int image_exec ( struct image *image );

Загрузка…
Отмена
Сохранить