[contrib] Allow Network Protocol header to display in rom-o-matic
[gpxe.git] / src / hci / commands / sanboot_cmd.c
blob783b747b29ab41e8491b0eb4ab3c368b15fc17a7
1 #include <stdio.h>
2 #include <string.h>
3 #include <getopt.h>
4 #include <gpxe/command.h>
5 #include <usr/autoboot.h>
7 FILE_LICENCE ( GPL2_OR_LATER );
9 /**
10 * "sanboot" command syntax message
12 * @v argv Argument list
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] );
22 /**
23 * The "sanboot" command
25 * @v argc Argument count
26 * @v argv Argument list
27 * @ret rc Exit code
29 static int sanboot_exec ( int argc, char **argv ) {
30 static struct option longopts[] = {
31 { "help", 0, NULL, 'h' },
32 { NULL, 0, NULL, 0 },
34 const char *root_path = NULL;
35 int c;
36 int rc;
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;
50 /* Need exactly one image name remaining after the options */
51 if ( optind != ( argc - 1 ) ) {
52 sanboot_syntax ( argv );
53 return 1;
55 root_path = argv[optind];
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;
64 return 0;
67 struct command sanboot_command __command = {
68 .name = "sanboot",
69 .exec = sanboot_exec,