summaryrefslogtreecommitdiff
path: root/gpxe/src/hci/commands/sanboot_cmd.c
blob: 783b747b29ab41e8491b0eb4ab3c368b15fc17a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <gpxe/command.h>
#include <usr/autoboot.h>

FILE_LICENCE ( GPL2_OR_LATER );

/**
 * "sanboot" command syntax message
 *
 * @v argv		Argument list
 */
static void sanboot_syntax ( char **argv ) {
	printf ( "Usage:\n"
		 "  %s <root-path>\n"
		 "\n"
		 "Boot from SAN target\n",
		 argv[0] );
}

/**
 * The "sanboot" command
 *
 * @v argc		Argument count
 * @v argv		Argument list
 * @ret rc		Exit code
 */
static int sanboot_exec ( int argc, char **argv ) {
	static struct option longopts[] = {
		{ "help", 0, NULL, 'h' },
		{ NULL, 0, NULL, 0 },
	};
	const char *root_path = NULL;
	int c;
	int rc;

	/* Parse options */
	while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
		switch ( c ) {
		case 'h':
			/* Display help text */
		default:
			/* Unrecognised/invalid option */
			sanboot_syntax ( argv );
			return 1;
		}
	}

	/* Need exactly one image name remaining after the options */
	if ( optind != ( argc - 1 ) ) {
		sanboot_syntax ( argv );
		return 1;
	}
	root_path = argv[optind];

	/* Boot from root path */
	if ( ( rc = boot_root_path ( root_path ) ) != 0 ) {
		printf ( "Could not boot from %s: %s\n",
			 root_path, strerror ( rc ) );
		return 1;
	}

	return 0;
}

struct command sanboot_command __command = {
	.name = "sanboot",
	.exec = sanboot_exec,
};