Adding upstream version 6.02~pre8+dfsg.
[syslinux-debian/hramrach.git] / com32 / modules / sanboot.c
blobff55f68e9c7f4d04f48638316e0b60957ab50c87
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2008 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
14 * sanboot.c
16 * Invoke the gPXE "sanboot" command, if available.
19 #include <alloca.h>
20 #include <inttypes.h>
21 #include <stdio.h>
22 #include <console.h>
23 #include <com32.h>
24 #include <string.h>
26 #include <sys/gpxe.h>
27 #include <syslinux/pxe_api.h>
29 struct segoff16 {
30 uint16_t offs, seg;
33 struct s_PXENV_FILE_EXEC {
34 uint16_t Status;
35 struct segoff16 Command;
38 static void sanboot(const char **args)
40 char *q;
41 struct s_PXENV_FILE_EXEC *fx;
43 fx = lmalloc(sizeof *fx);
44 if (!fx)
45 return;
47 q = (char *)(fx + 1);
49 fx->Status = 1;
50 fx->Command.offs = OFFS(q);
51 fx->Command.seg = SEG(q);
53 q = stpcpy(q, "sanboot");
55 while (*args) {
56 *q++ = ' ';
57 q = stpcpy(q, *args);
58 args++;
61 pxe_call(PXENV_FILE_EXEC, fx);
63 /* This should not return... */
66 int main(int argc, const char *argv[])
68 if (argc < 2) {
69 printf("Usage: sanboot rootpath\n");
70 return 1;
73 if (!is_gpxe()) {
74 printf("sanboot: gPXE API not detected\n");
75 return 1;
78 sanboot(argv + 1);
80 /* sanboot() should not return... */
81 printf("SAN boot failed.\n");
82 return 1;