1 /* ----------------------------------------------------------------------- *
3 * Copyright 2010 Gert Hulselmans - 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 * ----------------------------------------------------------------------- */
16 * Detemine which command to execute, based on the Syslinux bootloader variant
17 * from which you run it.
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
29 #include <syslinux/boot.h>
30 #include "syslinux/config.h"
33 static struct syslinux_parameter
{
36 } isolinux
, pxelinux
, syslinux
;
38 /* XXX: this really should be librarized */
39 static void boot_args(char **args
)
46 for (pp
= args
; *pp
; pp
++)
47 len
+= strlen(*pp
) + 1;
49 q
= str
= alloca(len
);
50 for (pp
= args
; *pp
; pp
++) {
61 syslinux_run_default();
63 syslinux_run_command(str
);
66 static void usage(void)
68 static const char usage
[] = "\
69 Usage: whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]\n\
70 Examples: 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
);
75 int main(int argc
, char *argv
[])
77 const union syslinux_derivative_info
*sdi
;
81 /* If no argument got passed, let's show the usage */
90 if (!strcmp(argv
[arg
], "-iso-")) {
92 isolinux
.arg
[0] = &argv
[arg
+ 1];
93 isolinux
.option
= true;
95 if (!strcmp(argv
[arg
], "-pxe-")) {
97 pxelinux
.arg
[0] = &argv
[arg
+ 1];
98 pxelinux
.option
= true;
100 if (!strcmp(argv
[arg
], "-sys-")) {
102 syslinux
.arg
[0] = &argv
[arg
+ 1];
103 syslinux
.option
= true;
108 sdi
= syslinux_derivative_info();
110 switch (sdi
->c
.filesystem
) {
111 case SYSLINUX_FS_ISOLINUX
:
112 isolinux
.option
? boot_args(isolinux
.arg
[0]) : fprintf(stderr
, "No command specified for ISOLINUX.\n\n"); usage();
114 case SYSLINUX_FS_PXELINUX
:
115 pxelinux
.option
? boot_args(pxelinux
.arg
[0]) : fprintf(stderr
, "No command specified for PXELINUX.\n\n"); usage();
117 case SYSLINUX_FS_SYSLINUX
:
118 syslinux
.option
? boot_args(syslinux
.arg
[0]) : fprintf(stderr
, "No command specified for SYSLINUX.\n\n"); usage();
120 case SYSLINUX_FS_UNKNOWN
:
122 fprintf(stderr
, "Unknown Syslinux filesystem\n\n");