Line 0
Link Here
|
|
|
1 |
/* ----------------------------------------------------------------------- * |
2 |
* |
3 |
* Copyright 2010 Gert Hulselmans - All Rights Reserved |
4 |
* |
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. |
10 |
* |
11 |
* ----------------------------------------------------------------------- */ |
12 |
|
13 |
/* |
14 |
* whichsys.c |
15 |
* |
16 |
* Detemine which command to execute, based on the Syslinux bootloader variant |
17 |
* from which you run it. |
18 |
* |
19 |
* Usage: whichsys.c32 [-iso- command] [-pxe- command] [-sys- command] |
20 |
* Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap |
21 |
* whichsys.c32 -iso- config iso.cfg -pxe- config pxe.cfg |
22 |
* |
23 |
*/ |
24 |
|
25 |
#include <stdio.h> |
26 |
#include <stdbool.h> |
27 |
#include <alloca.h> |
28 |
#include <console.h> |
29 |
#include <string.h> |
30 |
#include <syslinux/boot.h> |
31 |
#include "syslinux/config.h" |
32 |
|
33 |
|
34 |
static struct syslinux_parameter { |
35 |
char **arg[1]; |
36 |
bool option; |
37 |
} isolinux, pxelinux, syslinux; |
38 |
|
39 |
/* XXX: this really should be librarized */ |
40 |
static void boot_args(char **args) |
41 |
{ |
42 |
int len = 0, a = 0; |
43 |
char **pp; |
44 |
const char *p; |
45 |
char c, *q, *str; |
46 |
|
47 |
for (pp = args; *pp; pp++) |
48 |
len += strlen(*pp) + 1; |
49 |
|
50 |
q = str = alloca(len); |
51 |
for (pp = args; *pp; pp++) { |
52 |
p = *pp; |
53 |
while ((c = *p++)) |
54 |
*q++ = c; |
55 |
*q++ = ' '; |
56 |
a = 1; |
57 |
} |
58 |
q -= a; |
59 |
*q = '\0'; |
60 |
|
61 |
if (!str[0]) |
62 |
syslinux_run_default(); |
63 |
else |
64 |
syslinux_run_command(str); |
65 |
} |
66 |
|
67 |
static void usage(void) |
68 |
{ |
69 |
static const char usage[] = "\ |
70 |
Usage: whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]\n\ |
71 |
Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap\n\ |
72 |
whichsys.c32 -iso- config iso.cfg -pxe- config pxe.cfg\n"; |
73 |
fprintf(stderr, usage); |
74 |
} |
75 |
|
76 |
int main(int argc, char *argv[]) |
77 |
{ |
78 |
const union syslinux_derivative_info *sdi; |
79 |
|
80 |
int arg = 0; |
81 |
|
82 |
openconsole(&dev_null_r, &dev_stdcon_w); |
83 |
|
84 |
/* If no argument got passed, let's show the usage */ |
85 |
if (argc == 1) { |
86 |
usage(); |
87 |
return 0; |
88 |
} |
89 |
|
90 |
arg++; |
91 |
|
92 |
while (arg < argc) { |
93 |
if (!strcmp(argv[arg], "-iso-")) { |
94 |
argv[arg] = NULL; |
95 |
isolinux.arg[0] = &argv[arg + 1]; |
96 |
isolinux.option = true; |
97 |
} |
98 |
if (!strcmp(argv[arg], "-pxe-")) { |
99 |
argv[arg] = NULL; |
100 |
pxelinux.arg[0] = &argv[arg + 1]; |
101 |
pxelinux.option = true; |
102 |
} |
103 |
if (!strcmp(argv[arg], "-sys-")) { |
104 |
argv[arg] = NULL; |
105 |
syslinux.arg[0] = &argv[arg + 1]; |
106 |
syslinux.option = true; |
107 |
} |
108 |
arg++; |
109 |
} |
110 |
|
111 |
sdi = syslinux_derivative_info(); |
112 |
|
113 |
switch (sdi->c.filesystem) { |
114 |
case SYSLINUX_FS_ISOLINUX: |
115 |
isolinux.option ? boot_args(isolinux.arg[0]) : fprintf(stderr, "No command specified for ISOLINUX.\n\n"); usage(); |
116 |
break; |
117 |
case SYSLINUX_FS_PXELINUX: |
118 |
pxelinux.option ? boot_args(pxelinux.arg[0]) : fprintf(stderr, "No command specified for PXELINUX.\n\n"); usage(); |
119 |
break; |
120 |
case SYSLINUX_FS_SYSLINUX: |
121 |
syslinux.option ? boot_args(syslinux.arg[0]) : fprintf(stderr, "No command specified for SYSLINUX.\n\n"); usage(); |
122 |
break; |
123 |
case SYSLINUX_FS_UNKNOWN: |
124 |
default: |
125 |
fprintf(stderr, "Unknown Syslinux filesystem\n\n"); |
126 |
} |
127 |
|
128 |
return -1; |
129 |
} |