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#include <stdio.h>
26#include <alloca.h>
27#include <console.h>
28#include <string.h>
29#include <syslinux/boot.h>
30#include "syslinux/config.h"
31
32
33static struct syslinux_parameter {
34 char **arg[1];
35 bool option;
36} isolinux, pxelinux, syslinux;
37
38
39static void boot_args(char **args)
40{
41 int len = 0, a = 0;
42 char **pp;
43 const char *p;
44 char c, *q, *str;
45
46 for (pp = args; *pp; pp++)
47 len += strlen(*pp) + 1;
48
49 q = str = alloca(len);
50 for (pp = args; *pp; pp++) {
51 p = *pp;
52 while ((c = *p++))
53 *q++ = c;
54 *q++ = ' ';
55 a = 1;
56 }
57 q -= a;
58 *q = '\0';
59
60 if (!str[0])
61 syslinux_run_default();
62 else
63 syslinux_run_command(str);
64}
65
66static void usage(void)
67{
68 static const char usage[] = "\
69Usage: whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]\n\
70Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap\n\
71 whichsys.c32 -iso- config iso.cfg -pxe- config pxe.cfg\n";
72 fprintf(stderr, usage);
73}
74
75int main(int argc, char *argv[])
76{
77 const union syslinux_derivative_info *sdi;
78
79 int arg = 0;
80
81 openconsole(&dev_null_r, &dev_stdcon_w);
82
83
84 if (argc == 1) {
85 usage();
86 return 0;
87 }
88
89 arg++;
90
91 while (arg < argc) {
92 if (!strcmp(argv[arg], "-iso-")) {
93 argv[arg] = NULL;
94 isolinux.arg[0] = &argv[arg + 1];
95 isolinux.option = true;
96 }
97 if (!strcmp(argv[arg], "-pxe-")) {
98 argv[arg] = NULL;
99 pxelinux.arg[0] = &argv[arg + 1];
100 pxelinux.option = true;
101 }
102 if (!strcmp(argv[arg], "-sys-")) {
103 argv[arg] = NULL;
104 syslinux.arg[0] = &argv[arg + 1];
105 syslinux.option = true;
106 }
107 arg++;
108 }
109
110 sdi = syslinux_derivative_info();
111
112 switch (sdi->c.filesystem) {
113 case SYSLINUX_FS_ISOLINUX:
114 isolinux.option ? boot_args(isolinux.arg[0]) : fprintf(stderr, "No command specified for ISOLINUX.\n\n"); usage();
115 break;
116 case SYSLINUX_FS_PXELINUX:
117 pxelinux.option ? boot_args(pxelinux.arg[0]) : fprintf(stderr, "No command specified for PXELINUX.\n\n"); usage();
118 break;
119 case SYSLINUX_FS_SYSLINUX:
120 syslinux.option ? boot_args(syslinux.arg[0]) : fprintf(stderr, "No command specified for SYSLINUX.\n\n"); usage();
121 break;
122 case SYSLINUX_FS_UNKNOWN:
123 default:
124 fprintf(stderr, "Unknown Syslinux filesystem\n\n");
125 }
126
127 return -1;
128}
129