sanboot_cmd.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <getopt.h>
00004 #include <gpxe/command.h>
00005 #include <usr/autoboot.h>
00006 
00007 FILE_LICENCE ( GPL2_OR_LATER );
00008 
00009 /**
00010  * "sanboot" command syntax message
00011  *
00012  * @v argv              Argument list
00013  */
00014 static void sanboot_syntax ( char **argv ) {
00015         printf ( "Usage:\n"
00016                  "  %s <root-path>\n"
00017                  "\n"
00018                  "Boot from SAN target\n",
00019                  argv[0] );
00020 }
00021 
00022 /**
00023  * The "sanboot" command
00024  *
00025  * @v argc              Argument count
00026  * @v argv              Argument list
00027  * @ret rc              Exit code
00028  */
00029 static int sanboot_exec ( int argc, char **argv ) {
00030         static struct option longopts[] = {
00031                 { "help", 0, NULL, 'h' },
00032                 { NULL, 0, NULL, 0 },
00033         };
00034         const char *root_path = NULL;
00035         int c;
00036         int rc;
00037 
00038         /* Parse options */
00039         while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
00040                 switch ( c ) {
00041                 case 'h':
00042                         /* Display help text */
00043                 default:
00044                         /* Unrecognised/invalid option */
00045                         sanboot_syntax ( argv );
00046                         return 1;
00047                 }
00048         }
00049 
00050         /* Need exactly one image name remaining after the options */
00051         if ( optind != ( argc - 1 ) ) {
00052                 sanboot_syntax ( argv );
00053                 return 1;
00054         }
00055         root_path = argv[optind];
00056 
00057         /* Boot from root path */
00058         if ( ( rc = boot_root_path ( root_path ) ) != 0 ) {
00059                 printf ( "Could not boot from %s: %s\n",
00060                          root_path, strerror ( rc ) );
00061                 return 1;
00062         }
00063 
00064         return 0;
00065 }
00066 
00067 struct command sanboot_command __command = {
00068         .name = "sanboot",
00069         .exec = sanboot_exec,
00070 };

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