1 /* ----------------------------------------------------------------------- *
3 * Copyright 2010 Intel Corp. - 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., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
16 * parse cmdline for extlinux and syslinux installer
26 #include "../version.h"
30 /* These are the options we can set their values */
31 struct sys_options opt
= {
44 .activate_partition
= 0,
49 const struct option long_options
[] = {
50 {"force", 0, NULL
, 'f'}, /* DOS/Win32/mtools only */
51 {"install", 0, NULL
, 'i'},
52 {"directory", 1, NULL
, 'd'},
53 {"offset", 1, NULL
, 't'},
54 {"update", 0, NULL
, 'U'},
55 {"zipdrive", 0, NULL
, 'z'},
56 {"sectors", 1, NULL
, 'S'},
57 {"stupid", 0, NULL
, 's'},
58 {"heads", 1, NULL
, 'H'},
59 {"raid-mode", 0, NULL
, 'r'},
60 {"version", 0, NULL
, 'v'},
61 {"help", 0, NULL
, 'h'},
62 {"once", 1, NULL
, OPT_ONCE
},
63 {"clear-once", 0, NULL
, 'O'},
64 {"reset-adv", 0, NULL
, OPT_RESET_ADV
},
65 {"menu-save", 1, NULL
, 'M'},
66 {"mbr", 0, NULL
, 'm'}, /* DOS/Win32 only */
67 {"active", 0, NULL
, 'a'}, /* DOS/Win32 only */
71 const char short_options
[] = "t:fid:UuzS:H:rvho:OM:ma";
73 void __attribute__ ((noreturn
)) usage(int rv
, enum syslinux_mode mode
)
77 /* For unmounted fs installation (syslinux) */
79 "Usage: %s [options] device\n"
80 " --offset -t Offset of the file system on the device \n"
81 " --directory -d Directory for installation target\n",
86 /* Mounted fs installation (extlinux) */
87 /* Actually extlinux can also use -d to provide a directory too... */
89 "Usage: %s [options] directory\n",
93 case MODE_SYSLINUX_DOSWIN
:
94 /* For fs installation under Windows (syslinux.exe) */
96 "Usage: %s [options] <drive>: [bootsecfile]\n"
97 " --directory -d Directory for installation target\n",
103 " --install -i Install over the current bootsector\n"
104 " --update -U Update a previous EXTLINUX installation\n"
105 " --zip -z Force zipdrive geometry (-H 64 -S 32)\n"
106 " --sectors=# -S Force the number of sectors per track\n"
107 " --heads=# -H Force number of heads\n"
108 " --stupid -s Slow, safe and stupid mode\n"
109 " --raid -r Fall back to the next device on boot failure\n"
110 " --once=... %s Execute a command once upon boot\n"
111 " --clear-once -O Clear the boot-once command\n"
112 " --reset-adv Reset auxilliary data\n",
113 mode
== MODE_SYSLINUX
? " " : "-o");
114 /* Have to chop this roughly in half for the DOS installer for some reason */
116 " --menu-save= -M Set the label to select as default on the next boot\n"
117 " --mbr -m Install an MBR (DOS/Win32 installers only)\n"
118 " --active -a Mark partition as active (DOS/Win32 installers only)\n"
119 " --force -f Ignore precautions (DOS/Win32/mtools installers only)\n"
121 " Note: geometry is determined at boot time for devices which\n"
122 " are considered hard disks by the BIOS. Unfortunately, this is\n"
123 " not possible for devices which are considered floppy disks,\n"
124 " which includes zipdisks and LS-120 superfloppies.\n"
126 " The -z option is useful for USB devices which are considered\n"
127 " hard disks by some BIOSes and zipdrives by other BIOSes.");
132 void parse_options(int argc
, char *argv
[], enum syslinux_mode mode
)
137 while ((o
= getopt_long(argc
, argv
, short_options
,
138 long_options
, NULL
)) != EOF
) {
148 opt
.sectors
= strtoul(optarg
, NULL
, 0);
149 if (opt
.sectors
< 1 || opt
.sectors
> 63) {
151 "%s: invalid number of sectors: %u (must be 1-63)\n",
152 program
, opt
.sectors
);
157 opt
.heads
= strtoul(optarg
, NULL
, 0);
158 if (opt
.heads
< 1 || opt
.heads
> 256) {
160 "%s: invalid number of heads: %u (must be 1-256)\n",
182 if (mode
== MODE_SYSLINUX
) {
183 fprintf(stderr
, "%s: -o will change meaning in a future version, use -t or --offset\n", program
);
186 /* else fall through */
188 opt
.set_once
= optarg
;
192 opt
.offset
= strtoul(optarg
, NULL
, 0);
198 opt
.directory
= optarg
;
204 opt
.menu_save
= optarg
;
210 opt
.activate_partition
= 1;
214 "%s " VERSION_STR
" Copyright 1994-" YEAR_STR
215 " H. Peter Anvin et al\n", program
);
218 fprintf(stderr
, "%s: Unknown option: -%c\n", program
, optopt
);
219 usage(EX_USAGE
, mode
);
225 case MODE_SYSLINUX_DOSWIN
:
226 opt
.device
= argv
[optind
++];
230 opt
.directory
= argv
[optind
++];
234 if (argv
[optind
] && (mode
== MODE_SYSLINUX_DOSWIN
))
235 /* Allow for the boot-sector argument */
236 opt
.bootsecfile
= argv
[optind
++];
238 usage(EX_USAGE
, mode
); /* Excess arguments */
242 * Make any user-specified ADV modifications in memory
249 syslinux_reset_adv(syslinux_adv
);
252 if (syslinux_setadv(ADV_BOOTONCE
, strlen(opt
.set_once
), opt
.set_once
)) {
253 fprintf(stderr
, "%s: not enough space for boot-once command\n",
259 if (syslinux_setadv(ADV_MENUSAVE
, strlen(opt
.menu_save
), opt
.menu_save
)) {
260 fprintf(stderr
, "%s: not enough space for menu-save label\n",