Support mixed inline and suffix commands
This commit is contained in:
parent
281d690594
commit
e64334df29
4 changed files with 94 additions and 80 deletions
|
@ -82,31 +82,31 @@ legacy_file (const char *filename)
|
||||||
|
|
||||||
{
|
{
|
||||||
char *oldname = NULL;
|
char *oldname = NULL;
|
||||||
int is_suffix;
|
char *newsuffix;
|
||||||
|
|
||||||
oldname = entryname;
|
oldname = entryname;
|
||||||
parsed = grub_legacy_parse (buf, &entryname, &is_suffix);
|
parsed = grub_legacy_parse (buf, &entryname, &newsuffix);
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
if (is_suffix)
|
if (newsuffix)
|
||||||
{
|
{
|
||||||
char *t;
|
char *t;
|
||||||
|
|
||||||
t = suffix;
|
t = suffix;
|
||||||
suffix = grub_realloc (suffix, grub_strlen (suffix)
|
suffix = grub_realloc (suffix, grub_strlen (suffix)
|
||||||
+ grub_strlen (parsed) + 1);
|
+ grub_strlen (newsuffix) + 1);
|
||||||
if (!suffix)
|
if (!suffix)
|
||||||
{
|
{
|
||||||
grub_free (t);
|
grub_free (t);
|
||||||
grub_free (entrysrc);
|
grub_free (entrysrc);
|
||||||
grub_free (parsed);
|
grub_free (parsed);
|
||||||
|
grub_free (newsuffix);
|
||||||
grub_free (suffix);
|
grub_free (suffix);
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
}
|
}
|
||||||
grub_memcpy (suffix + grub_strlen (suffix), parsed,
|
grub_memcpy (suffix + grub_strlen (suffix), newsuffix,
|
||||||
grub_strlen (parsed) + 1);
|
grub_strlen (newsuffix) + 1);
|
||||||
grub_free (parsed);
|
grub_free (newsuffix);
|
||||||
parsed = NULL;
|
newsuffix = NULL;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (oldname != entryname && oldname)
|
if (oldname != entryname && oldname)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,8 @@ struct legacy_command
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *map;
|
const char *map;
|
||||||
|
const char *suffix;
|
||||||
|
unsigned suffixarg;
|
||||||
unsigned argc;
|
unsigned argc;
|
||||||
enum arg_type {
|
enum arg_type {
|
||||||
TYPE_VERBATIM,
|
TYPE_VERBATIM,
|
||||||
|
@ -42,7 +44,6 @@ struct legacy_command
|
||||||
} argt[4];
|
} argt[4];
|
||||||
enum {
|
enum {
|
||||||
FLAG_IGNORE_REST = 1,
|
FLAG_IGNORE_REST = 1,
|
||||||
FLAG_SUFFIX = 2,
|
|
||||||
FLAG_FALLBACK_AVAILABLE = 4,
|
FLAG_FALLBACK_AVAILABLE = 4,
|
||||||
FLAG_FALLBACK = 8,
|
FLAG_FALLBACK = 8,
|
||||||
FLAG_COLOR_INVERT = 16,
|
FLAG_COLOR_INVERT = 16,
|
||||||
|
@ -53,22 +54,22 @@ struct legacy_command
|
||||||
|
|
||||||
struct legacy_command legacy_commands[] =
|
struct legacy_command legacy_commands[] =
|
||||||
{
|
{
|
||||||
{"blocklist", "blocklist '%s'\n", 1, {TYPE_FILE}, 0, "FILE",
|
{"blocklist", "blocklist '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILE",
|
||||||
"Print the blocklist notation of the file FILE."},
|
"Print the blocklist notation of the file FILE."},
|
||||||
{"boot", "boot\n", 0, {}, 0, 0,
|
{"boot", "boot\n", NULL, 0, 0, {}, 0, 0,
|
||||||
"Boot the OS/chain-loader which has been loaded."},
|
"Boot the OS/chain-loader which has been loaded."},
|
||||||
/* FIXME: bootp unsupported. */
|
/* FIXME: bootp unsupported. */
|
||||||
{"cat", "cat '%s'\n", 1, {TYPE_FILE}, 0, "FILE",
|
{"cat", "cat '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILE",
|
||||||
"Print the contents of the file FILE."},
|
"Print the contents of the file FILE."},
|
||||||
{"chainloader", "chainloader %s '%s'\n", 2, {TYPE_FORCE_OPTION, TYPE_FILE},
|
{"chainloader", "chainloader %s '%s'\n", NULL, 0,
|
||||||
0, "[--force] FILE",
|
2, {TYPE_FORCE_OPTION, TYPE_FILE}, 0, "[--force] FILE",
|
||||||
"Load the chain-loader FILE. If --force is specified, then load it"
|
"Load the chain-loader FILE. If --force is specified, then load it"
|
||||||
" forcibly, whether the boot loader signature is present or not."},
|
" forcibly, whether the boot loader signature is present or not."},
|
||||||
{"cmp", "cmp '%s' '%s'\n", 2, {TYPE_FILE, TYPE_FILE}, FLAG_IGNORE_REST,
|
{"cmp", "cmp '%s' '%s'\n", NULL, 0,
|
||||||
"FILE1 FILE2",
|
2, {TYPE_FILE, TYPE_FILE}, FLAG_IGNORE_REST, "FILE1 FILE2",
|
||||||
"Compare the file FILE1 with the FILE2 and inform the different values"
|
"Compare the file FILE1 with the FILE2 and inform the different values"
|
||||||
" if any."},
|
" if any."},
|
||||||
{"color", "set color_normal='%s'; set color_highlight='%s'\n",
|
{"color", "set color_normal='%s'; set color_highlight='%s'\n", NULL, 0,
|
||||||
2, {TYPE_VERBATIM, TYPE_VERBATIM},
|
2, {TYPE_VERBATIM, TYPE_VERBATIM},
|
||||||
FLAG_IGNORE_REST | FLAG_FALLBACK_AVAILABLE, "NORMAL [HIGHLIGHT]",
|
FLAG_IGNORE_REST | FLAG_FALLBACK_AVAILABLE, "NORMAL [HIGHLIGHT]",
|
||||||
"Change the menu colors. The color NORMAL is used for most"
|
"Change the menu colors. The color NORMAL is used for most"
|
||||||
|
@ -81,60 +82,62 @@ struct legacy_command legacy_commands[] =
|
||||||
" light-green, light-cyan, light-red, light-magenta, yellow and white."
|
" light-green, light-cyan, light-red, light-magenta, yellow and white."
|
||||||
" But only the first eight names can be used for BG. You can prefix"
|
" But only the first eight names can be used for BG. You can prefix"
|
||||||
" \"blink-\" to FG if you want a blinking foreground color."},
|
" \"blink-\" to FG if you want a blinking foreground color."},
|
||||||
{"color", "set color_normal='%s'; set color_highlight='%s'\n",
|
{"color", "set color_normal='%s'; set color_highlight='%s'\n", NULL, 0,
|
||||||
1, {TYPE_VERBATIM},
|
1, {TYPE_VERBATIM},
|
||||||
FLAG_IGNORE_REST | FLAG_FALLBACK | FLAG_COLOR_INVERT, NULL, NULL},
|
FLAG_IGNORE_REST | FLAG_FALLBACK | FLAG_COLOR_INVERT, NULL, NULL},
|
||||||
{"configfile", "legacy_configfile '%s'\n", 1, {TYPE_FILE}, 0, "FILE",
|
{"configfile", "legacy_configfile '%s'\n", NULL, 0, 1, {TYPE_FILE},
|
||||||
"Load FILE as the configuration file."},
|
0, "FILE", "Load FILE as the configuration file."},
|
||||||
{"debug",
|
{"debug",
|
||||||
"if [ -z \"$debug\" ]; then set debug=all; else set debug=; fi\n",
|
"if [ -z \"$debug\" ]; then set debug=all; else set debug=; fi\n", NULL, 0,
|
||||||
0, {}, 0, 0, "Turn on/off the debug mode."},
|
0, {}, 0, 0, "Turn on/off the debug mode."},
|
||||||
{"default",
|
{"default",
|
||||||
"set default='%s'; if [ x\"$default\" = xsaved ]; then load_env; "
|
"set default='%s'; if [ x\"$default\" = xsaved ]; then load_env; "
|
||||||
"set default=\"$saved_entry\"; fi\n", 1, {TYPE_VERBATIM}, 0,
|
"set default=\"$saved_entry\"; fi\n", NULL, 0, 1, {TYPE_VERBATIM}, 0,
|
||||||
"[NUM | `saved']",
|
"[NUM | `saved']",
|
||||||
"Set the default entry to entry number NUM (if not specified, it is"
|
"Set the default entry to entry number NUM (if not specified, it is"
|
||||||
" 0, the first entry) or the entry number saved by savedefault."},
|
" 0, the first entry) or the entry number saved by savedefault."},
|
||||||
/* FIXME: dhcp unsupported. */
|
/* FIXME: dhcp unsupported. */
|
||||||
/* FIXME: displayapm unsupported. */
|
/* FIXME: displayapm unsupported. */
|
||||||
{"displaymem", "lsmmap\n", 0, {}, 0, 0,
|
{"displaymem", "lsmmap\n", NULL, 0, 0, {}, 0, 0,
|
||||||
"Display what GRUB thinks the system address space map of the"
|
"Display what GRUB thinks the system address space map of the"
|
||||||
" machine is, including all regions of physical RAM installed."},
|
" machine is, including all regions of physical RAM installed."},
|
||||||
/* NOTE: embed unsupported. */
|
/* NOTE: embed unsupported. */
|
||||||
{"fallback", "set fallback='%s'\n", 1, {TYPE_VERBATIM}, 0, "NUM...",
|
{"fallback", "set fallback='%s'\n", NULL, 0,
|
||||||
|
1, {TYPE_VERBATIM}, 0, "NUM...",
|
||||||
"Go into unattended boot mode: if the default boot entry has any"
|
"Go into unattended boot mode: if the default boot entry has any"
|
||||||
" errors, instead of waiting for the user to do anything, it"
|
" errors, instead of waiting for the user to do anything, it"
|
||||||
" immediately starts over using the NUM entry (same numbering as the"
|
" immediately starts over using the NUM entry (same numbering as the"
|
||||||
" `default' command). This obviously won't help if the machine"
|
" `default' command). This obviously won't help if the machine"
|
||||||
" was rebooted by a kernel that GRUB loaded."},
|
" was rebooted by a kernel that GRUB loaded."},
|
||||||
{"find", "search -sf '%s'\n", 1, {TYPE_FILE}, 0, "FILENAME",
|
{"find", "search -sf '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILENAME",
|
||||||
"Search for the filename FILENAME in all of partitions and print the list of"
|
"Search for the filename FILENAME in all of partitions and print the list of"
|
||||||
" the devices which contain the file."},
|
" the devices which contain the file."},
|
||||||
/* FIXME: fstest unsupported. */
|
/* FIXME: fstest unsupported. */
|
||||||
/* FIXME: geometry unsupported. */
|
/* FIXME: geometry unsupported. */
|
||||||
{"halt", "halt %s\n", 1, {TYPE_NOAPM_OPTION}, 0, "[--no-apm]",
|
{"halt", "halt %s\n", NULL, 0, 1, {TYPE_NOAPM_OPTION}, 0, "[--no-apm]",
|
||||||
"Halt your system. If APM is available on it, turn off the power using"
|
"Halt your system. If APM is available on it, turn off the power using"
|
||||||
" the APM BIOS, unless you specify the option `--no-apm'."},
|
" the APM BIOS, unless you specify the option `--no-apm'."},
|
||||||
/* FIXME: help unsupported. */ /* NUL_TERMINATE */
|
/* FIXME: help unsupported. */ /* NUL_TERMINATE */
|
||||||
{"hiddenmenu", "if sleep -i $timeout; then timeout=0; else timeout=-1; fi\n",
|
{"hiddenmenu", NULL,
|
||||||
0, {}, FLAG_SUFFIX, "", "Hide the menu."},
|
"if sleep -i $timeout; then timeout=0; else timeout=-1; fi\n", 0,
|
||||||
{"hide", "parttool '%s' hidden+\n", 1, {TYPE_PARTITION}, 0, "PARTITION",
|
0, {}, 0, "", "Hide the menu."},
|
||||||
|
{"hide", "parttool '%s' hidden+\n", NULL, 0, 1, {TYPE_PARTITION},
|
||||||
|
0, "PARTITION",
|
||||||
"Hide PARTITION by setting the \"hidden\" bit in"
|
"Hide PARTITION by setting the \"hidden\" bit in"
|
||||||
" its partition type code."},
|
" its partition type code."},
|
||||||
/* FIXME: ifconfig unsupported. */
|
/* FIXME: ifconfig unsupported. */
|
||||||
/* FIXME: impsprobe unsupported. */
|
/* FIXME: impsprobe unsupported. */
|
||||||
{"initrd", "legacy_initrd '%s' %s\n", 2, {TYPE_FILE_NO_CONSUME,
|
{"initrd", "legacy_initrd '%s' %s\n", NULL, 0, 2, {TYPE_FILE_NO_CONSUME,
|
||||||
TYPE_REST_VERBATIM}, 0,
|
TYPE_REST_VERBATIM}, 0,
|
||||||
"FILE [ARG ...]",
|
"FILE [ARG ...]",
|
||||||
"Load an initial ramdisk FILE for a Linux format boot image and set the"
|
"Load an initial ramdisk FILE for a Linux format boot image and set the"
|
||||||
" appropriate parameters in the Linux setup area in memory."},
|
" appropriate parameters in the Linux setup area in memory."},
|
||||||
/* NOTE: install unsupported. */
|
/* NOTE: install unsupported. */
|
||||||
/* FIXME: ioprobe unsupported. */
|
/* FIXME: ioprobe unsupported. */
|
||||||
/* FIXME: really support --no-mem-option. */
|
/* FIXME: really support --no-mem-option. */
|
||||||
{"kernel", "legacy_kernel %s %s '%s' %s\n", 4, {TYPE_TYPE_OR_NOMEM_OPTION,
|
{"kernel", "legacy_kernel %s %s '%s' %s\n", NULL, 0,
|
||||||
TYPE_TYPE_OR_NOMEM_OPTION,
|
4, {TYPE_TYPE_OR_NOMEM_OPTION, TYPE_TYPE_OR_NOMEM_OPTION,
|
||||||
TYPE_FILE_NO_CONSUME,
|
TYPE_FILE_NO_CONSUME, TYPE_REST_VERBATIM}, 0,
|
||||||
TYPE_REST_VERBATIM}, 0,
|
|
||||||
"[--no-mem-option] [--type=TYPE] FILE [ARG ...]",
|
"[--no-mem-option] [--type=TYPE] FILE [ARG ...]",
|
||||||
"Attempt to load the primary boot image from FILE. The rest of the"
|
"Attempt to load the primary boot image from FILE. The rest of the"
|
||||||
" line is passed verbatim as the \"kernel command line\". Any modules"
|
" line is passed verbatim as the \"kernel command line\". Any modules"
|
||||||
|
@ -144,46 +147,49 @@ struct legacy_command legacy_commands[] =
|
||||||
" \"multiboot\". The option --no-mem-option tells GRUB not to pass a"
|
" \"multiboot\". The option --no-mem-option tells GRUB not to pass a"
|
||||||
" Linux's mem option automatically."},
|
" Linux's mem option automatically."},
|
||||||
/* FIXME: lock is unsupported. */
|
/* FIXME: lock is unsupported. */
|
||||||
{"makeactive", "parttool \"$root\" boot+\n", 0, {}, 0, 0,
|
{"makeactive", "parttool \"$root\" boot+\n", NULL, 0, 0, {}, 0, 0,
|
||||||
"Set the active partition on the root disk to GRUB's root device."
|
"Set the active partition on the root disk to GRUB's root device."
|
||||||
" This command is limited to _primary_ PC partitions on a hard disk."},
|
" This command is limited to _primary_ PC partitions on a hard disk."},
|
||||||
{"map", "drivemap '%s' '%s'\n", 2, {TYPE_PARTITION, TYPE_PARTITION},
|
{"map", "drivemap '%s' '%s'\n", NULL, 0,
|
||||||
|
2, {TYPE_PARTITION, TYPE_PARTITION},
|
||||||
FLAG_IGNORE_REST, "TO_DRIVE FROM_DRIVE",
|
FLAG_IGNORE_REST, "TO_DRIVE FROM_DRIVE",
|
||||||
"Map the drive FROM_DRIVE to the drive TO_DRIVE. This is necessary"
|
"Map the drive FROM_DRIVE to the drive TO_DRIVE. This is necessary"
|
||||||
" when you chain-load some operating systems, such as DOS, if such an"
|
" when you chain-load some operating systems, such as DOS, if such an"
|
||||||
" OS resides at a non-first drive."},
|
" OS resides at a non-first drive."},
|
||||||
/* NOTE: md5crypt unsupported since GRUB has not enough entropy and this
|
/* NOTE: md5crypt unsupported since GRUB has not enough entropy and this
|
||||||
hash shouldn't be used anymore. */
|
hash shouldn't be used anymore. */
|
||||||
{"module", "legacy_initrd '%s' %s\n", 1, {TYPE_FILE_NO_CONSUME,
|
{"module", "legacy_initrd '%s' %s\n", NULL, 0, 2, {TYPE_FILE_NO_CONSUME,
|
||||||
TYPE_REST_VERBATIM}, 0,
|
TYPE_REST_VERBATIM}, 0,
|
||||||
"FILE [ARG ...]",
|
"FILE [ARG ...]",
|
||||||
"Load a boot module FILE for a Multiboot format boot image (no"
|
"Load a boot module FILE for a Multiboot format boot image (no"
|
||||||
" interpretation of the file contents is made, so users of this"
|
" interpretation of the file contents is made, so users of this"
|
||||||
" command must know what the kernel in question expects). The"
|
" command must know what the kernel in question expects). The"
|
||||||
" rest of the line is passed as the \"module command line\", like"
|
" rest of the line is passed as the \"module command line\", like"
|
||||||
" the `kernel' command."},
|
" the `kernel' command."},
|
||||||
{"modulenounzip", "legacy_initrd_nounzip '%s' %s\n", 1,
|
{"modulenounzip", "legacy_initrd_nounzip '%s' %s\n", NULL, 0, 2,
|
||||||
{TYPE_FILE_NO_CONSUME, TYPE_REST_VERBATIM}, 0,
|
{TYPE_FILE_NO_CONSUME, TYPE_REST_VERBATIM}, 0,
|
||||||
"FILE [ARG ...]",
|
"FILE [ARG ...]",
|
||||||
"The same as `module', except that automatic decompression is"
|
"The same as `module', except that automatic decompression is"
|
||||||
" disabled."},
|
" disabled."},
|
||||||
{"pager", "set pager=%s; if [ \"$pager\" = 0 ]; then "
|
{"pager", "set pager=%s; if [ \"$pager\" = 0 ]; then "
|
||||||
" echo Internal pager is now off; else echo Internal pager is now on; fi\n",
|
" echo Internal pager is now off; else "
|
||||||
|
"echo Internal pager is now on; fi\n", NULL, 0,
|
||||||
1, {TYPE_BOOL}, FLAG_FALLBACK_AVAILABLE, "[FLAG]",
|
1, {TYPE_BOOL}, FLAG_FALLBACK_AVAILABLE, "[FLAG]",
|
||||||
"Toggle pager mode with no argument. If FLAG is given and its value"
|
"Toggle pager mode with no argument. If FLAG is given and its value"
|
||||||
" is `on', turn on the mode. If FLAG is `off', turn off the mode."},
|
" is `on', turn on the mode. If FLAG is `off', turn off the mode."},
|
||||||
{"pager",
|
{"pager",
|
||||||
"if [ \"$pager\" = 1 ]; then pager=0; echo Internal pager is now off;"
|
"if [ \"$pager\" = 1 ]; then pager=0; echo Internal pager is now off;"
|
||||||
"else pager=1; echo Internal pager is now on; fi\n", 0, {},
|
"else pager=1; echo Internal pager is now on; fi\n", NULL, 0, 0, {},
|
||||||
FLAG_FALLBACK, NULL, NULL},
|
FLAG_FALLBACK, NULL, NULL},
|
||||||
/* FIXME: partnew unsupported. */
|
/* FIXME: partnew unsupported. */
|
||||||
{"parttype", "parttool '%s' type=%s\n", 2, {TYPE_PARTITION, TYPE_INT}, 0,
|
{"parttype", "parttool '%s' type=%s\n", NULL, 0,
|
||||||
|
2, {TYPE_PARTITION, TYPE_INT}, 0,
|
||||||
"PART TYPE", "Change the type of the partition PART to TYPE."},
|
"PART TYPE", "Change the type of the partition PART to TYPE."},
|
||||||
/* FIXME: support config file reloading. */
|
/* FIXME: support config file reloading. */
|
||||||
/* FIXME: support usage in menuentry. */
|
/* FIXME: support usage in menuentry. */
|
||||||
{"password", "if [ \"$superusers\" = "" ]; then superusers=legacy; fi;\n"
|
{"password", "if [ \"$superusers\" = "" ]; then superusers=legacy; fi;\n"
|
||||||
"legacy_password %s '%s' %s", 3, {TYPE_OPTION, TYPE_VERBATIM,
|
"legacy_password %s '%s' %s", NULL, 0, 3, {TYPE_OPTION, TYPE_VERBATIM,
|
||||||
TYPE_FILE}, FLAG_IGNORE_REST,
|
TYPE_FILE}, FLAG_IGNORE_REST,
|
||||||
"[--md5] PASSWD [FILE]",
|
"[--md5] PASSWD [FILE]",
|
||||||
"If used in the first section of a menu file, disable all"
|
"If used in the first section of a menu file, disable all"
|
||||||
" interactive editing control (menu entry editor and"
|
" interactive editing control (menu entry editor and"
|
||||||
|
@ -197,15 +203,15 @@ struct legacy_command legacy_commands[] =
|
||||||
/* NOTE: GRUB2 has a design principle of not eternally waiting for user
|
/* NOTE: GRUB2 has a design principle of not eternally waiting for user
|
||||||
input. 60 seconds should be enough.
|
input. 60 seconds should be enough.
|
||||||
*/
|
*/
|
||||||
{"pause", "echo %s; if ! sleep -i 60; then return; fi\n", 1,
|
{"pause", "echo %s; if ! sleep -i 60; then return; fi\n", NULL, 0, 1,
|
||||||
{TYPE_REST_VERBATIM}, 0,
|
{TYPE_REST_VERBATIM}, 0,
|
||||||
"[MESSAGE ...]", "Print MESSAGE, then wait until a key is pressed."},
|
"[MESSAGE ...]", "Print MESSAGE, then wait until a key is pressed."},
|
||||||
/* FIXME: rarp unsupported. */
|
/* FIXME: rarp unsupported. */
|
||||||
{"read", "read_dword %s\n", 1, {TYPE_INT}, 0, "ADDR",
|
{"read", "read_dword %s\n", NULL, 0, 1, {TYPE_INT}, 0, "ADDR",
|
||||||
"Read a 32-bit value from memory at address ADDR and"
|
"Read a 32-bit value from memory at address ADDR and"
|
||||||
" display it in hex format."},
|
" display it in hex format."},
|
||||||
{"reboot", "reboot\n", 0, {}, 0, 0, "Reboot your system."},
|
{"reboot", "reboot\n", NULL, 0, 0, {}, 0, 0, "Reboot your system."},
|
||||||
{"root", "set root='%s'; set legacy_hdbias='%s'\n",
|
{"root", "set root='%s'; set legacy_hdbias='%s'\n", NULL, 0,
|
||||||
2, {TYPE_PARTITION, TYPE_INT}, FLAG_FALLBACK_AVAILABLE,
|
2, {TYPE_PARTITION, TYPE_INT}, FLAG_FALLBACK_AVAILABLE,
|
||||||
"[DEVICE [HDBIAS]]",
|
"[DEVICE [HDBIAS]]",
|
||||||
"Set the current \"root device\" to the device DEVICE, then"
|
"Set the current \"root device\" to the device DEVICE, then"
|
||||||
|
@ -218,8 +224,8 @@ struct legacy_command legacy_commands[] =
|
||||||
" how many BIOS drive numbers are on controllers before the current"
|
" how many BIOS drive numbers are on controllers before the current"
|
||||||
" one. For example, if there is an IDE disk and a SCSI disk, and your"
|
" one. For example, if there is an IDE disk and a SCSI disk, and your"
|
||||||
" FreeBSD root partition is on the SCSI disk, then use a `1' for HDBIAS."},
|
" FreeBSD root partition is on the SCSI disk, then use a `1' for HDBIAS."},
|
||||||
{"root", "echo \"$root\"\n", 0, {}, FLAG_FALLBACK, NULL, NULL},
|
{"root", "echo \"$root\"\n", NULL, 0, 0, {}, FLAG_FALLBACK, NULL, NULL},
|
||||||
{"rootnoverify", "set root='%s'; set legacy_hdbias='%s'\n",
|
{"rootnoverify", "set root='%s'; set legacy_hdbias='%s'\n", NULL, 0,
|
||||||
2, {TYPE_PARTITION, TYPE_INT}, 0,
|
2, {TYPE_PARTITION, TYPE_INT}, 0,
|
||||||
"[DEVICE [HDBIAS]]",
|
"[DEVICE [HDBIAS]]",
|
||||||
"Similar to `root', but don't attempt to mount the partition. This"
|
"Similar to `root', but don't attempt to mount the partition. This"
|
||||||
|
@ -227,14 +233,15 @@ struct legacy_command legacy_commands[] =
|
||||||
" GRUB can read, but setting the correct root device is still"
|
" GRUB can read, but setting the correct root device is still"
|
||||||
" desired. Note that the items mentioned in `root' which"
|
" desired. Note that the items mentioned in `root' which"
|
||||||
" derived from attempting the mount will NOT work correctly."},
|
" derived from attempting the mount will NOT work correctly."},
|
||||||
{"rootnoverify", "echo \"$root\"\n", 0, {}, FLAG_FALLBACK, NULL, NULL},
|
{"rootnoverify", "echo \"$root\"\n", NULL, 0,
|
||||||
|
0, {}, FLAG_FALLBACK, NULL, NULL},
|
||||||
/* FIXME: support saving NUM and fallback. */
|
/* FIXME: support saving NUM and fallback. */
|
||||||
{"savedefault", "saved_entry=${chosen}; save_env saved_entry\n", 0, {}, 0,
|
{"savedefault", "saved_entry=${chosen}; save_env saved_entry\n", NULL, 0,
|
||||||
"[NUM | `fallback']",
|
0, {}, 0, "[NUM | `fallback']",
|
||||||
"Save the current entry as the default boot entry if no argument is"
|
"Save the current entry as the default boot entry if no argument is"
|
||||||
" specified. If a number is specified, this number is saved. If"
|
" specified. If a number is specified, this number is saved. If"
|
||||||
" `fallback' is used, next fallback entry is saved."},
|
" `fallback' is used, next fallback entry is saved."},
|
||||||
{"serial", "serial %s\n", 1, {TYPE_REST_VERBATIM}, 0,
|
{"serial", "serial %s\n", NULL, 0, 1, {TYPE_REST_VERBATIM}, 0,
|
||||||
"[--unit=UNIT] [--port=PORT] [--speed=SPEED] [--word=WORD] "
|
"[--unit=UNIT] [--port=PORT] [--speed=SPEED] [--word=WORD] "
|
||||||
"[--parity=PARITY] [--stop=STOP] [--device=DEV]",
|
"[--parity=PARITY] [--stop=STOP] [--device=DEV]",
|
||||||
"Initialize a serial device. UNIT is a digit that specifies which serial"
|
"Initialize a serial device. UNIT is a digit that specifies which serial"
|
||||||
|
@ -248,25 +255,26 @@ struct legacy_command legacy_commands[] =
|
||||||
/* FIXME: setup unsupported. */
|
/* FIXME: setup unsupported. */
|
||||||
/* FIXME: terminal unsupported. */ /* NUL_TERMINATE */
|
/* FIXME: terminal unsupported. */ /* NUL_TERMINATE */
|
||||||
/* FIXME: terminfo unsupported. */ /* NUL_TERMINATE */
|
/* FIXME: terminfo unsupported. */ /* NUL_TERMINATE */
|
||||||
{"testload", "cat '%s'\n", 1, {TYPE_FILE}, 0, "FILE",
|
{"testload", "cat '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILE",
|
||||||
"Read the entire contents of FILE in several different ways and"
|
"Read the entire contents of FILE in several different ways and"
|
||||||
" compares them, to test the filesystem code. "
|
" compares them, to test the filesystem code. "
|
||||||
" If this test succeeds, then a good next"
|
" If this test succeeds, then a good next"
|
||||||
" step is to try loading a kernel."},
|
" step is to try loading a kernel."},
|
||||||
/* FIXME: testvbe unsupported. */
|
/* FIXME: testvbe unsupported. */
|
||||||
/* FIXME: tftpserver unsupported. */
|
/* FIXME: tftpserver unsupported. */
|
||||||
{"timeout", "set timeout=%s\n", 1, {TYPE_INT}, 0, "SEC",
|
{"timeout", "set timeout=%s\n", NULL, 0, 1, {TYPE_INT}, 0, "SEC",
|
||||||
"Set a timeout, in SEC seconds, before automatically booting the"
|
"Set a timeout, in SEC seconds, before automatically booting the"
|
||||||
" default entry (normally the first entry defined)."},
|
" default entry (normally the first entry defined)."},
|
||||||
/* title is handled separately. */
|
/* title is handled separately. */
|
||||||
{"unhide", "parttool '%s' hidden-\n", 1, {TYPE_PARTITION}, 0, "PARTITION",
|
{"unhide", "parttool '%s' hidden-\n", NULL, 0,
|
||||||
|
1, {TYPE_PARTITION}, 0, "PARTITION",
|
||||||
"Unhide PARTITION by clearing the \"hidden\" bit in its"
|
"Unhide PARTITION by clearing the \"hidden\" bit in its"
|
||||||
" partition type code."},
|
" partition type code."},
|
||||||
/* FIXME: uppermem unsupported. */
|
/* FIXME: uppermem unsupported. */
|
||||||
{"uuid", "search -u '%s'\n", 1, {TYPE_VERBATIM}, 0, "UUID",
|
{"uuid", "search -u '%s'\n", NULL, 0, 1, {TYPE_VERBATIM}, 0, "UUID",
|
||||||
"Find root by UUID"},
|
"Find root by UUID"},
|
||||||
/* FIXME: support MODE. */
|
/* FIXME: support MODE. */
|
||||||
{"vbeprobe", "vbeinfo\n", 0, {}, 0, "[MODE]",
|
{"vbeprobe", "vbeinfo\n", NULL, 0, 0, {}, 0, "[MODE]",
|
||||||
"Probe VBE information. If the mode number MODE is specified, show only"
|
"Probe VBE information. If the mode number MODE is specified, show only"
|
||||||
" the information about only the mode."}
|
" the information about only the mode."}
|
||||||
};
|
};
|
||||||
|
@ -384,13 +392,13 @@ is_option (enum arg_type opt, const char *curarg, grub_size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
grub_legacy_parse (const char *buf, char **entryname, int *suffix)
|
grub_legacy_parse (const char *buf, char **entryname, char **suffix)
|
||||||
{
|
{
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
const char *cmdname;
|
const char *cmdname;
|
||||||
unsigned i, cmdnum;
|
unsigned i, cmdnum;
|
||||||
|
|
||||||
*suffix = 0;
|
*suffix = NULL;
|
||||||
|
|
||||||
for (ptr = buf; *ptr && grub_isspace (*ptr); ptr++);
|
for (ptr = buf; *ptr && grub_isspace (*ptr); ptr++);
|
||||||
if (!*ptr || *ptr == '#')
|
if (!*ptr || *ptr == '#')
|
||||||
|
@ -437,8 +445,6 @@ grub_legacy_parse (const char *buf, char **entryname, int *suffix)
|
||||||
if (cmdnum == ARRAY_SIZE (legacy_commands))
|
if (cmdnum == ARRAY_SIZE (legacy_commands))
|
||||||
return grub_xasprintf ("# Unsupported legacy command: %s\n", buf);
|
return grub_xasprintf ("# Unsupported legacy command: %s\n", buf);
|
||||||
|
|
||||||
*suffix = !!(legacy_commands[cmdnum].flags & FLAG_SUFFIX);
|
|
||||||
|
|
||||||
for (; grub_isspace (*ptr) || *ptr == '='; ptr++);
|
for (; grub_isspace (*ptr) || *ptr == '='; ptr++);
|
||||||
|
|
||||||
char *args[ARRAY_SIZE (legacy_commands[0].argt)];
|
char *args[ARRAY_SIZE (legacy_commands[0].argt)];
|
||||||
|
@ -447,7 +453,7 @@ grub_legacy_parse (const char *buf, char **entryname, int *suffix)
|
||||||
{
|
{
|
||||||
int hold_arg = 0;
|
int hold_arg = 0;
|
||||||
const char *curarg = NULL;
|
const char *curarg = NULL;
|
||||||
for (i = 0; i < legacy_commands[cmdnum].argc + hold_arg; i++)
|
for (i = 0; i < legacy_commands[cmdnum].argc; i++)
|
||||||
{
|
{
|
||||||
grub_size_t curarglen;
|
grub_size_t curarglen;
|
||||||
if (hold_arg)
|
if (hold_arg)
|
||||||
|
@ -622,6 +628,14 @@ grub_legacy_parse (const char *buf, char **entryname, int *suffix)
|
||||||
args[legacy_commands[cmdnum].argc] = invert;
|
args[legacy_commands[cmdnum].argc] = invert;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (legacy_commands[cmdnum].suffix)
|
||||||
|
{
|
||||||
|
*suffix = grub_xasprintf (legacy_commands[cmdnum].suffix,
|
||||||
|
args[legacy_commands[cmdnum].suffixarg]);
|
||||||
|
if (*suffix)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char *ret = grub_xasprintf (legacy_commands[cmdnum].map, args[0], args[1],
|
char *ret = grub_xasprintf (legacy_commands[cmdnum].map, args[0], args[1],
|
||||||
args[2], args[3]);
|
args[2], args[3]);
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include <grub/types.h>
|
#include <grub/types.h>
|
||||||
|
|
||||||
char *grub_legacy_parse (const char *buf, char **entryname, int *suffix);
|
char *grub_legacy_parse (const char *buf, char **entryname, char **suffix);
|
||||||
char *grub_legacy_escape (const char *in, grub_size_t len);
|
char *grub_legacy_escape (const char *in, grub_size_t len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <grub/util/misc.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
|
@ -30,7 +31,6 @@ main (int argc, char **argv)
|
||||||
size_t bufsize = 0;
|
size_t bufsize = 0;
|
||||||
char *suffix = xstrdup ("");
|
char *suffix = xstrdup ("");
|
||||||
int suffixlen = 0;
|
int suffixlen = 0;
|
||||||
int is_suffix = 0;
|
|
||||||
|
|
||||||
if (argc >= 2 && argv[1][0] == '-')
|
if (argc >= 2 && argv[1][0] == '-')
|
||||||
{
|
{
|
||||||
|
@ -75,15 +75,15 @@ main (int argc, char **argv)
|
||||||
|
|
||||||
{
|
{
|
||||||
char *oldname = NULL;
|
char *oldname = NULL;
|
||||||
|
char *newsuffix;
|
||||||
|
|
||||||
oldname = entryname;
|
oldname = entryname;
|
||||||
parsed = grub_legacy_parse (buf, &entryname, &is_suffix);
|
parsed = grub_legacy_parse (buf, &entryname, &newsuffix);
|
||||||
if (is_suffix)
|
if (newsuffix)
|
||||||
{
|
{
|
||||||
suffixlen += strlen (parsed);
|
suffixlen += strlen (newsuffix);
|
||||||
suffix = xrealloc (suffix, suffixlen + 1);
|
suffix = xrealloc (suffix, suffixlen + 1);
|
||||||
strcat (suffix, parsed);
|
strcat (suffix, newsuffix);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (oldname != entryname && oldname)
|
if (oldname != entryname && oldname)
|
||||||
fprintf (out, "}\n\n");
|
fprintf (out, "}\n\n");
|
||||||
|
@ -91,25 +91,25 @@ main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *escaped = grub_legacy_escape (entryname, strlen (entryname));
|
char *escaped = grub_legacy_escape (entryname, strlen (entryname));
|
||||||
fprintf (out, "menuentry \'%s\' {\n", escaped);
|
fprintf (out, "menuentry \'%s\' {\n", escaped);
|
||||||
grub_free (escaped);
|
free (escaped);
|
||||||
grub_free (oldname);
|
free (oldname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsed)
|
if (parsed)
|
||||||
fprintf (out, "%s%s", entryname ? " " : "", parsed);
|
fprintf (out, "%s%s", entryname ? " " : "", parsed);
|
||||||
grub_free (parsed);
|
free (parsed);
|
||||||
parsed = NULL;
|
parsed = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entryname)
|
if (entryname)
|
||||||
fprintf (out, "}\n\n");
|
fprintf (out, "}\n\n");
|
||||||
|
|
||||||
fwrite (out, 1, suffixlen, suffix);
|
fwrite (suffix, 1, suffixlen, out);
|
||||||
|
|
||||||
grub_free (buf);
|
free (buf);
|
||||||
grub_free (suffix);
|
free (suffix);
|
||||||
grub_free (entryname);
|
free (entryname);
|
||||||
|
|
||||||
if (in != stdin)
|
if (in != stdin)
|
||||||
fclose (in);
|
fclose (in);
|
||||||
|
|
Loading…
Add table
Reference in a new issue