imgmgmt.c File Reference

Image management. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <gpxe/image.h>
#include <gpxe/downloader.h>
#include <gpxe/monojob.h>
#include <gpxe/open.h>
#include <gpxe/uri.h>
#include <usr/imgmgmt.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int imgfetch (struct image *image, const char *uri_string, int(*image_register)(struct image *image))
 Fetch an image.
int imgload (struct image *image)
 Load an image.
int imgexec (struct image *image)
 Execute an image.
struct imageimgautoselect (void)
 Identify the only loaded image.
void imgstat (struct image *image)
 Display status of an image.
void imgfree (struct image *image)
 Free an image.


Detailed Description

Image management.

Definition in file imgmgmt.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

int imgfetch ( struct image image,
const char *  uri_string,
int(*)(struct image *image image_register 
)

Fetch an image.

Parameters:
uri_string URI as a string (e.g. "http://www.nowhere.com/vmlinuz")
name Name for image, or NULL
register_image Image registration routine
Return values:
rc Return status code

Definition at line 46 of file imgmgmt.c.

References create_downloader(), ENOMEM, image_set_uri(), LOCATION_URI, monojob, monojob_wait(), parse_uri(), uri::password, strlen(), unparse_uri(), and URI_ALL.

Referenced by boot_next_server_and_filename(), comboot_fetch_kernel(), and imgfetch_core_exec().

00047                                                                   {
00048         char uri_string_redacted[ strlen ( uri_string ) + 3 /* "***" */
00049                                   + 1 /* NUL */ ];
00050         struct uri *uri;
00051         const char *password;
00052         int rc;
00053 
00054         if ( ! ( uri = parse_uri ( uri_string ) ) )
00055                 return -ENOMEM;
00056 
00057         image_set_uri ( image, uri );
00058 
00059         /* Redact password portion of URI, if necessary */
00060         password = uri->password;
00061         if ( password )
00062                 uri->password = "***";
00063         unparse_uri ( uri_string_redacted, sizeof ( uri_string_redacted ),
00064                       uri, URI_ALL );
00065         uri->password = password;
00066 
00067         if ( ( rc = create_downloader ( &monojob, image, image_register,
00068                                         LOCATION_URI, uri ) ) == 0 )
00069                 rc = monojob_wait ( uri_string_redacted );
00070 
00071         uri_put ( uri );
00072         return rc;
00073 }

int imgload ( struct image image  ) 

Load an image.

Parameters:
image Image
Return values:
rc Return status code

Definition at line 81 of file imgmgmt.c.

References image_autoload().

Referenced by imgload_exec().

00081                                     {
00082         int rc;
00083 
00084         /* Try to load image */
00085         if ( ( rc = image_autoload ( image ) ) != 0 )
00086                 return rc;
00087 
00088         return 0;
00089 }

int imgexec ( struct image image  ) 

Execute an image.

Parameters:
image Image
Return values:
rc Return status code

Definition at line 97 of file imgmgmt.c.

References image_exec().

Referenced by boot_next_server_and_filename(), and imgexec_exec().

00097                                     {
00098         return image_exec ( image );
00099 }

struct image* imgautoselect ( void   )  [read]

Identify the only loaded image.

Return values:
image Image, or NULL if 0 or >1 images are loaded

Definition at line 106 of file imgmgmt.c.

References image::flags, for_each_image, IMAGE_LOADED, and NULL.

Referenced by imgexec_exec().

00106                                       {
00107         struct image *image;
00108         struct image *selected_image = NULL;
00109         int flagged_images = 0;
00110 
00111         for_each_image ( image ) {
00112                 if ( image->flags & IMAGE_LOADED ) {
00113                         selected_image = image;
00114                         flagged_images++;
00115                 }
00116         }
00117 
00118         return ( ( flagged_images == 1 ) ? selected_image : NULL );
00119 }

void imgstat ( struct image image  ) 

Display status of an image.

Parameters:
image Executable/loadable image

Definition at line 126 of file imgmgmt.c.

References image::cmdline, image::flags, IMAGE_LOADED, image::len, image_type::name, image::name, printf(), and image::type.

Referenced by imgstat_exec().

00126                                      {
00127         printf ( "%s: %zd bytes", image->name, image->len );
00128         if ( image->type )
00129                 printf ( " [%s]", image->type->name );
00130         if ( image->flags & IMAGE_LOADED )
00131                 printf ( " [LOADED]" );
00132         if ( image->cmdline )
00133                 printf ( " \"%s\"", image->cmdline );
00134         printf ( "\n" );
00135 }

void imgfree ( struct image image  ) 

Free an image.

Parameters:
image Executable/loadable image

Definition at line 142 of file imgmgmt.c.

References unregister_image().

Referenced by imgfree_exec().

00142                                      {
00143         unregister_image ( image );
00144 }


Generated on Tue Apr 6 20:01:57 2010 for gPXE by  doxygen 1.5.7.1