Rename e1000_main.c to e1000.c to so we can type 'make bin/e1000.dsk' instead of...
[gpxe.git] / src / usr / imgmgmt.c
blobbead48678c4949575c680f0a28a055eb389c1d73
1 /*
2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <stdint.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <errno.h>
23 #include <gpxe/image.h>
24 #include <gpxe/downloader.h>
25 #include <gpxe/monojob.h>
26 #include <gpxe/open.h>
27 #include <gpxe/uri.h>
28 #include <usr/imgmgmt.h>
30 /** @file
32 * Image management
36 /**
37 * Fetch an image
39 * @v uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
40 * @v name Name for image, or NULL
41 * @v register_image Image registration routine
42 * @ret rc Return status code
44 int imgfetch ( struct image *image, const char *uri_string,
45 int ( * image_register ) ( struct image *image ) ) {
46 struct uri *uri;
47 int rc;
49 if ( ! ( uri = parse_uri ( uri_string ) ) )
50 return -ENOMEM;
52 image_set_uri ( image, uri );
54 if ( ( rc = create_downloader ( &monojob, image, image_register,
55 LOCATION_URI, uri ) ) == 0 )
56 rc = monojob_wait ( uri_string );
58 uri_put ( uri );
59 return rc;
62 /**
63 * Load an image
65 * @v image Image
66 * @ret rc Return status code
68 int imgload ( struct image *image ) {
69 int rc;
71 /* Try to load image */
72 if ( ( rc = image_autoload ( image ) ) != 0 )
73 return rc;
75 return 0;
78 /**
79 * Execute an image
81 * @v image Image
82 * @ret rc Return status code
84 int imgexec ( struct image *image ) {
85 return image_exec ( image );
88 /**
89 * Identify the first loaded image
91 * @ret image Image, or NULL
93 struct image * imgautoselect ( void ) {
94 struct image *image;
96 for_each_image ( image ) {
97 if ( image->flags & IMAGE_LOADED )
98 return image;
101 return NULL;
105 * Display status of an image
107 * @v image Executable/loadable image
109 void imgstat ( struct image *image ) {
110 printf ( "%s: %zd bytes", image->name, image->len );
111 if ( image->type )
112 printf ( " [%s]", image->type->name );
113 if ( image->flags & IMAGE_LOADED )
114 printf ( " [LOADED]" );
115 if ( image->cmdline )
116 printf ( " \"%s\"", image->cmdline );
117 printf ( "\n" );
121 * Free an image
123 * @v image Executable/loadable image
125 void imgfree ( struct image *image ) {
126 unregister_image ( image );