1 #include <stdio.h> 2 #include <string.h> 3 #include <getopt.h> 4 #include <gpxe/command.h> 5 #include <usr/autoboot.h> 6 7 FILE_LICENCE ( GPL2_OR_LATER ); 8 9 /** 10 * "sanboot" command syntax message 11 * 12 * @v argv Argument list 13 */ 14 static void sanboot_syntax ( char **argv ) { 15 printf ( "Usage:\n" 16 " %s <root-path>\n" 17 "\n" 18 "Boot from SAN target\n", 19 argv[0] ); 20 } 21 22 /** 23 * The "sanboot" command 24 * 25 * @v argc Argument count 26 * @v argv Argument list 27 * @ret rc Exit code 28 */ 29 static int sanboot_exec ( int argc, char **argv ) { 30 static struct option longopts[] = { 31 { "help", 0, NULL, 'h' }, 32 { NULL, 0, NULL, 0 }, 33 }; 34 const char *root_path = NULL; 35 int c; 36 int rc; 37 38 /* Parse options */ 39 while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){ 40 switch ( c ) { 41 case 'h': 42 /* Display help text */ 43 default: 44 /* Unrecognised/invalid option */ 45 sanboot_syntax ( argv ); 46 return 1; 47 } 48 } 49 50 /* Need exactly one image name remaining after the options */ 51 if ( optind != ( argc - 1 ) ) { 52 sanboot_syntax ( argv ); 53 return 1; 54 } 55 root_path = argv[optind]; 56 57 /* Boot from root path */ 58 if ( ( rc = boot_root_path ( root_path ) ) != 0 ) { 59 printf ( "Could not boot from %s: %s\n", 60 root_path, strerror ( rc ) ); 61 return 1; 62 } 63 64 return 0; 65 } 66 67 struct command sanboot_command __command = { 68 .name = "sanboot", 69 .exec = sanboot_exec, 70 }; 71