imgmgmt.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <stdint.h>
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <errno.h>
00025 #include <gpxe/image.h>
00026 #include <gpxe/downloader.h>
00027 #include <gpxe/monojob.h>
00028 #include <gpxe/open.h>
00029 #include <gpxe/uri.h>
00030 #include <usr/imgmgmt.h>
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 int imgfetch ( struct image *image, const char *uri_string,
00047 int ( * image_register ) ( struct image *image ) ) {
00048 char uri_string_redacted[ strlen ( uri_string ) + 3
00049 + 1 ];
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
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 }
00074
00075
00076
00077
00078
00079
00080
00081 int imgload ( struct image *image ) {
00082 int rc;
00083
00084
00085 if ( ( rc = image_autoload ( image ) ) != 0 )
00086 return rc;
00087
00088 return 0;
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 int imgexec ( struct image *image ) {
00098 return image_exec ( image );
00099 }
00100
00101
00102
00103
00104
00105
00106 struct image * imgautoselect ( void ) {
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 }
00120
00121
00122
00123
00124
00125
00126 void imgstat ( struct image *image ) {
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 }
00136
00137
00138
00139
00140
00141
00142 void imgfree ( struct image *image ) {
00143 unregister_image ( image );
00144 }