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