Browse Source

Added IMAGE_LOADED flag and find_image()

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
b9fea9cbac
2 changed files with 34 additions and 0 deletions
  1. 27
    0
      src/core/image.c
  2. 7
    0
      src/include/gpxe/image.h

+ 27
- 0
src/core/image.c View File

72
 	DBGC ( image, "IMAGE %p unregistered\n", image );
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
  * Load executable/loadable image into memory
93
  * Load executable/loadable image into memory
77
  *
94
  *
89
 		return rc;
106
 		return rc;
90
 	}
107
 	}
91
 
108
 
109
+	image->flags |= IMAGE_LOADED;
92
 	return 0;
110
 	return 0;
93
 }
111
 }
94
 
112
 
111
 			       image, image->type->name, strerror ( rc ) );
129
 			       image, image->type->name, strerror ( rc ) );
112
 			return rc;
130
 			return rc;
113
 		}
131
 		}
132
+		image->flags |= IMAGE_LOADED;
114
 		return 0;
133
 		return 0;
115
 	}
134
 	}
116
 
135
 
127
 int image_exec ( struct image *image ) {
146
 int image_exec ( struct image *image ) {
128
 	int rc;
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
 	assert ( image->type != NULL );
156
 	assert ( image->type != NULL );
131
 
157
 
158
+	/* Try executing the image */
132
 	if ( ( rc = image->type->exec ( image ) ) != 0 ) {
159
 	if ( ( rc = image->type->exec ( image ) ) != 0 ) {
133
 		DBGC ( image, "IMAGE %p could not execute: %s\n",
160
 		DBGC ( image, "IMAGE %p could not execute: %s\n",
134
 		       image, strerror ( rc ) );
161
 		       image, strerror ( rc ) );

+ 7
- 0
src/include/gpxe/image.h View File

45
 
45
 
46
 	/** Image type, if known */
46
 	/** Image type, if known */
47
 	struct image_type *type;
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
 /** An executable or loadable image type */
56
 /** An executable or loadable image type */
51
 struct image_type {
57
 struct image_type {
52
 	/** Name of this image type */
58
 	/** Name of this image type */
102
 
108
 
103
 extern int register_image ( struct image *image );
109
 extern int register_image ( struct image *image );
104
 extern void unregister_image ( struct image *image );
110
 extern void unregister_image ( struct image *image );
111
+struct image * find_image ( const char *name );
105
 extern int image_load ( struct image *image );
112
 extern int image_load ( struct image *image );
106
 extern int image_autoload ( struct image *image );
113
 extern int image_autoload ( struct image *image );
107
 extern int image_exec ( struct image *image );
114
 extern int image_exec ( struct image *image );

Loading…
Cancel
Save