|
@@ -72,19 +72,20 @@ static void imgfetch_core_syntax ( char **argv, int load ) {
|
72
|
72
|
/**
|
73
|
73
|
* The "imgfetch"/"module"/"kernel" command body
|
74
|
74
|
*
|
|
75
|
+ * @v image_type Image type to assign (or NULL)
|
|
76
|
+ * @v load Image will be automatically loaded after fetching
|
75
|
77
|
* @v argc Argument count
|
76
|
78
|
* @v argv Argument list
|
77
|
|
- * @v load Image will be automatically loaded after fetching
|
78
|
|
- * @ret image Fetched image
|
79
|
79
|
* @ret rc Return status code
|
80
|
80
|
*/
|
81
|
|
-static int imgfetch_core_exec ( int argc, char **argv, int load,
|
82
|
|
- struct image **image ) {
|
|
81
|
+static int imgfetch_core_exec ( struct image_type *image_type, int load,
|
|
82
|
+ int argc, char **argv ) {
|
83
|
83
|
static struct option longopts[] = {
|
84
|
84
|
{ "help", 0, NULL, 'h' },
|
85
|
85
|
{ "name", required_argument, NULL, 'n' },
|
86
|
86
|
{ NULL, 0, NULL, 0 },
|
87
|
87
|
};
|
|
88
|
+ struct image *image;
|
88
|
89
|
const char *name = NULL;
|
89
|
90
|
char *filename;
|
90
|
91
|
int c;
|
|
@@ -116,15 +117,33 @@ static int imgfetch_core_exec ( int argc, char **argv, int load,
|
116
|
117
|
if ( ! name )
|
117
|
118
|
name = basename ( filename );
|
118
|
119
|
|
|
120
|
+ /* Allocate image */
|
|
121
|
+ image = alloc_image();
|
|
122
|
+ if ( ! image ) {
|
|
123
|
+ printf ( "%s\n", strerror ( -ENOMEM ) );
|
|
124
|
+ return -ENOMEM;
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+ /* Fill in image name */
|
|
128
|
+ if ( name )
|
|
129
|
+ strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
|
|
130
|
+
|
|
131
|
+ /* Set image type (if specified) */
|
|
132
|
+ image->type = image_type;
|
|
133
|
+
|
|
134
|
+ /* Fill in command line */
|
|
135
|
+ imgfill_cmdline ( image, ( argc - optind ), &argv[optind] );
|
|
136
|
+
|
|
137
|
+ printf ( "name = %s, filename = %s\n", name, filename );
|
|
138
|
+
|
119
|
139
|
/* Fetch the image */
|
120
|
|
- if ( ( rc = imgfetch ( filename, name, image ) ) != 0 ) {
|
|
140
|
+ if ( ( rc = imgfetch ( image, filename, load ) ) != 0 ) {
|
121
|
141
|
printf ( "Could not fetch %s: %s\n", name, strerror ( rc ) );
|
|
142
|
+ image_put ( image );
|
122
|
143
|
return rc;
|
123
|
144
|
}
|
124
|
145
|
|
125
|
|
- /* Fill in command line */
|
126
|
|
- imgfill_cmdline ( *image, ( argc - optind ), &argv[optind] );
|
127
|
|
-
|
|
146
|
+ image_put ( image );
|
128
|
147
|
return 0;
|
129
|
148
|
}
|
130
|
149
|
|
|
@@ -136,11 +155,10 @@ static int imgfetch_core_exec ( int argc, char **argv, int load,
|
136
|
155
|
* @ret rc Exit code
|
137
|
156
|
*/
|
138
|
157
|
static int imgfetch_exec ( int argc, char **argv ) {
|
139
|
|
- struct image *image;
|
140
|
158
|
int rc;
|
141
|
159
|
|
142
|
|
- if ( ( rc = imgfetch_core_exec ( argc, argv, 0, &image ) ) != 0 )
|
143
|
|
- return 1;
|
|
160
|
+ if ( ( rc = imgfetch_core_exec ( NULL, 0, argc, argv ) ) != 0 )
|
|
161
|
+ return rc;
|
144
|
162
|
|
145
|
163
|
return 0;
|
146
|
164
|
}
|
|
@@ -153,18 +171,10 @@ static int imgfetch_exec ( int argc, char **argv ) {
|
153
|
171
|
* @ret rc Exit code
|
154
|
172
|
*/
|
155
|
173
|
static int kernel_exec ( int argc, char **argv ) {
|
156
|
|
- struct image *image;
|
157
|
174
|
int rc;
|
158
|
175
|
|
159
|
|
- if ( ( rc = imgfetch_core_exec ( argc, argv, 1, &image ) ) != 0 )
|
160
|
|
- return 1;
|
161
|
|
-
|
162
|
|
- /* Load image */
|
163
|
|
- if ( ( rc = imgload ( image ) ) != 0 ) {
|
164
|
|
- printf ( "Could not load %s: %s\n", image->name,
|
165
|
|
- strerror ( rc ) );
|
166
|
|
- return 1;
|
167
|
|
- }
|
|
176
|
+ if ( ( rc = imgfetch_core_exec ( NULL, 1, argc, argv ) ) != 0 )
|
|
177
|
+ return rc;
|
168
|
178
|
|
169
|
179
|
return 0;
|
170
|
180
|
}
|
|
@@ -177,14 +187,11 @@ static int kernel_exec ( int argc, char **argv ) {
|
177
|
187
|
* @ret rc Exit code
|
178
|
188
|
*/
|
179
|
189
|
static int initrd_exec ( int argc, char **argv ) {
|
180
|
|
- struct image *image;
|
181
|
190
|
int rc;
|
182
|
191
|
|
183
|
|
- if ( ( rc = imgfetch_core_exec ( argc, argv, 0, &image ) ) != 0 )
|
184
|
|
- return 1;
|
185
|
|
-
|
186
|
|
- /* Mark image as an intird */
|
187
|
|
- image->type = &initrd_image_type;
|
|
192
|
+ if ( ( rc = imgfetch_core_exec ( &initrd_image_type, 0,
|
|
193
|
+ argc, argv ) ) != 0 )
|
|
194
|
+ return rc;
|
188
|
195
|
|
189
|
196
|
return 0;
|
190
|
197
|
}
|
|
@@ -246,7 +253,7 @@ static int imgload_exec ( int argc, char **argv ) {
|
246
|
253
|
}
|
247
|
254
|
if ( ( rc = imgload ( image ) ) != 0 ) {
|
248
|
255
|
printf ( "Could not load %s: %s\n", name, strerror ( rc ) );
|
249
|
|
- return 1;
|
|
256
|
+ return rc;
|
250
|
257
|
}
|
251
|
258
|
|
252
|
259
|
return 0;
|