2010-08-27 18:04:49 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2012-06-28 13:27:54 +00:00
|
|
|
* Copyright (C) 1999,2000,2001,2002,2003,2004,2010,2012 Free Software Foundation, Inc.
|
2010-08-27 18:04:49 +00:00
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/types.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/err.h>
|
|
|
|
#include <grub/legacy_parse.h>
|
2010-09-15 09:39:53 +00:00
|
|
|
#include <grub/i386/pc/vesa_modes_table.h>
|
2012-02-12 14:25:25 +00:00
|
|
|
#include <grub/i18n.h>
|
2010-08-27 18:04:49 +00:00
|
|
|
|
2013-12-21 14:28:28 +00:00
|
|
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
|
2010-08-27 18:04:49 +00:00
|
|
|
struct legacy_command
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const char *map;
|
2010-09-12 13:50:52 +00:00
|
|
|
const char *suffix;
|
|
|
|
unsigned suffixarg;
|
2010-08-27 18:04:49 +00:00
|
|
|
unsigned argc;
|
|
|
|
enum arg_type {
|
|
|
|
TYPE_VERBATIM,
|
|
|
|
TYPE_FORCE_OPTION,
|
|
|
|
TYPE_NOAPM_OPTION,
|
|
|
|
TYPE_TYPE_OR_NOMEM_OPTION,
|
2010-09-11 23:07:41 +00:00
|
|
|
TYPE_OPTION,
|
2010-08-27 18:04:49 +00:00
|
|
|
TYPE_FILE,
|
2010-09-11 20:18:41 +00:00
|
|
|
TYPE_FILE_NO_CONSUME,
|
2010-08-27 18:04:49 +00:00
|
|
|
TYPE_PARTITION,
|
|
|
|
TYPE_BOOL,
|
|
|
|
TYPE_INT,
|
2010-09-15 09:39:53 +00:00
|
|
|
TYPE_REST_VERBATIM,
|
2011-10-05 08:21:32 +00:00
|
|
|
TYPE_VBE_MODE,
|
|
|
|
TYPE_WITH_CONFIGFILE_OPTION
|
2010-08-27 18:04:49 +00:00
|
|
|
} argt[4];
|
|
|
|
enum {
|
2010-09-20 12:48:17 +00:00
|
|
|
FLAG_IGNORE_REST = 0x001,
|
|
|
|
FLAG_FALLBACK_AVAILABLE = 0x004,
|
|
|
|
FLAG_FALLBACK = 0x008,
|
|
|
|
FLAG_COLOR_INVERT = 0x010,
|
|
|
|
FLAG_NO_MENUENTRY = 0x020,
|
|
|
|
FLAG_MENUENTRY_ONLY = 0x040,
|
|
|
|
FLAG_TERMINAL = 0x080,
|
|
|
|
FLAG_TITLE = 0x100,
|
2010-08-27 18:04:49 +00:00
|
|
|
} flags;
|
|
|
|
const char *shortdesc;
|
|
|
|
const char *longdesc;
|
|
|
|
};
|
|
|
|
|
2011-11-11 19:52:41 +00:00
|
|
|
/* Help texts are kept here mostly for reference. They are never shown. So
|
|
|
|
no need to gettextize.
|
|
|
|
*/
|
2011-03-23 11:05:13 +00:00
|
|
|
static struct legacy_command legacy_commands[] =
|
2010-08-27 18:04:49 +00:00
|
|
|
{
|
2012-07-02 09:31:31 +00:00
|
|
|
/* FIXME: background unsupported. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"blocklist", "blocklist '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILE",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Print the blocklist notation of the file FILE."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"boot", "boot\n", NULL, 0, 0, {}, 0, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"Boot the OS/chain-loader which has been loaded."},
|
2013-10-27 00:50:31 +00:00
|
|
|
{"bootp", "net_bootp; net_ls_addr; echo $\"" N_("Default server is ${net_default_server}") "\"; if [ x%s = x--with-configfile ]; then "
|
2011-10-05 08:21:32 +00:00
|
|
|
"if net_get_dhcp_option configfile_name pxe 150 string; then "
|
|
|
|
"configfile $configfile_name; fi; fi\n", NULL, 0, 1,
|
|
|
|
{TYPE_WITH_CONFIGFILE_OPTION}, FLAG_IGNORE_REST, "[--with-configfile]",
|
|
|
|
"Initialize a network device via BOOTP. If the option `--with-configfile'"
|
|
|
|
" is given, try to load a configuration file specified by the 150 vendor"
|
|
|
|
" tag."},
|
2013-11-05 01:43:27 +00:00
|
|
|
/* FIXME: border unsupported. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"cat", "cat '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILE",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Print the contents of the file FILE."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"chainloader", "chainloader %s '%s'\n", NULL, 0,
|
|
|
|
2, {TYPE_FORCE_OPTION, TYPE_FILE}, 0, "[--force] FILE",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Load the chain-loader FILE. If --force is specified, then load it"
|
|
|
|
" forcibly, whether the boot loader signature is present or not."},
|
2012-07-02 09:31:31 +00:00
|
|
|
{"clear", "clear\n", NULL, 0, 0, {}, 0, 0,
|
|
|
|
"Clear the screen."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"cmp", "cmp '%s' '%s'\n", NULL, 0,
|
|
|
|
2, {TYPE_FILE, TYPE_FILE}, FLAG_IGNORE_REST, "FILE1 FILE2",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Compare the file FILE1 with the FILE2 and inform the different values"
|
|
|
|
" if any."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"color", "set color_normal='%s'; set color_highlight='%s'\n", NULL, 0,
|
2010-09-12 13:26:38 +00:00
|
|
|
2, {TYPE_VERBATIM, TYPE_VERBATIM},
|
|
|
|
FLAG_IGNORE_REST | FLAG_FALLBACK_AVAILABLE, "NORMAL [HIGHLIGHT]",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Change the menu colors. The color NORMAL is used for most"
|
|
|
|
" lines in the menu, and the color HIGHLIGHT is used to highlight the"
|
|
|
|
" line where the cursor points. If you omit HIGHLIGHT, then the"
|
|
|
|
" inverted color of NORMAL is used for the highlighted line."
|
|
|
|
" The format of a color is \"FG/BG\". FG and BG are symbolic color names."
|
|
|
|
" A symbolic color name must be one of these: black, blue, green,"
|
|
|
|
" cyan, red, magenta, brown, light-gray, dark-gray, light-blue,"
|
|
|
|
" 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"
|
|
|
|
" \"blink-\" to FG if you want a blinking foreground color."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"color", "set color_normal='%s'; set color_highlight='%s'\n", NULL, 0,
|
2010-09-12 13:26:38 +00:00
|
|
|
1, {TYPE_VERBATIM},
|
|
|
|
FLAG_IGNORE_REST | FLAG_FALLBACK | FLAG_COLOR_INVERT, NULL, NULL},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"configfile", "legacy_configfile '%s'\n", NULL, 0, 1, {TYPE_FILE},
|
|
|
|
0, "FILE", "Load FILE as the configuration file."},
|
2010-08-27 18:04:49 +00:00
|
|
|
{"debug",
|
2010-09-12 13:50:52 +00:00
|
|
|
"if [ -z \"$debug\" ]; then set debug=all; else set debug=; fi\n", NULL, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
0, {}, 0, 0, "Turn on/off the debug mode."},
|
|
|
|
{"default",
|
|
|
|
"set default='%s'; if [ x\"$default\" = xsaved ]; then load_env; "
|
2010-09-12 13:50:52 +00:00
|
|
|
"set default=\"$saved_entry\"; fi\n", NULL, 0, 1, {TYPE_VERBATIM}, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"[NUM | `saved']",
|
|
|
|
"Set the default entry to entry number NUM (if not specified, it is"
|
|
|
|
" 0, the first entry) or the entry number saved by savedefault."},
|
2011-10-05 08:21:32 +00:00
|
|
|
{"dhcp", "net_bootp; net_ls_addr; if [ x%s = x--with-configfile ]; then "
|
|
|
|
"if net_get_dhcp_option configfile_name pxe 150 string; then "
|
|
|
|
"configfile $configfile_name; fi; fi\n", NULL, 0, 1,
|
|
|
|
{TYPE_WITH_CONFIGFILE_OPTION}, FLAG_IGNORE_REST, "[--with-configfile]",
|
|
|
|
"Initialize a network device via BOOTP. If the option `--with-configfile'"
|
|
|
|
" is given, try to load a configuration file specified by the 150 vendor"
|
|
|
|
" tag."},
|
2010-09-15 09:42:18 +00:00
|
|
|
{"displayapm", "lsapm\n", NULL, 0, 0, {}, 0, 0,
|
|
|
|
"Display APM BIOS information."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"displaymem", "lsmmap\n", NULL, 0, 0, {}, 0, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"Display what GRUB thinks the system address space map of the"
|
|
|
|
" machine is, including all regions of physical RAM installed."},
|
2012-07-02 09:31:31 +00:00
|
|
|
/* FIXME: device and efimap unsupported. */
|
2010-09-12 01:05:19 +00:00
|
|
|
/* NOTE: embed unsupported. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"fallback", "set fallback='%s'\n", NULL, 0,
|
|
|
|
1, {TYPE_VERBATIM}, 0, "NUM...",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Go into unattended boot mode: if the default boot entry has any"
|
|
|
|
" errors, instead of waiting for the user to do anything, it"
|
|
|
|
" immediately starts over using the NUM entry (same numbering as the"
|
|
|
|
" `default' command). This obviously won't help if the machine"
|
|
|
|
" was rebooted by a kernel that GRUB loaded."},
|
2011-04-08 12:32:41 +00:00
|
|
|
{"find", "search -f '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILENAME",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Search for the filename FILENAME in all of partitions and print the list of"
|
|
|
|
" the devices which contain the file."},
|
2012-07-02 09:31:31 +00:00
|
|
|
/* FIXME: findiso unsupported. */
|
|
|
|
/* FIXME: foreground unsupported. */
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: fstest unsupported. */
|
2010-09-15 12:11:08 +00:00
|
|
|
/* NOTE: The obsolete C/H/S geometry isn't shown anymore. */
|
|
|
|
{"geometry", "insmod regexp; ls -l (%s*)\n", NULL, 0, 1, {TYPE_VERBATIM}, 0, "DRIVE",
|
|
|
|
"Print the information for a drive DRIVE. "},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"halt", "halt %s\n", NULL, 0, 1, {TYPE_NOAPM_OPTION}, 0, "[--no-apm]",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Halt your system. If APM is available on it, turn off the power using"
|
|
|
|
" the APM BIOS, unless you specify the option `--no-apm'."},
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: help unsupported. */ /* NUL_TERMINATE */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"hiddenmenu", NULL,
|
|
|
|
"if sleep -i $timeout; then timeout=0; else timeout=-1; fi\n", 0,
|
|
|
|
0, {}, 0, "", "Hide the menu."},
|
|
|
|
{"hide", "parttool '%s' hidden+\n", NULL, 0, 1, {TYPE_PARTITION},
|
|
|
|
0, "PARTITION",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Hide PARTITION by setting the \"hidden\" bit in"
|
|
|
|
" its partition type code."},
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: ifconfig unsupported. */
|
|
|
|
/* FIXME: impsprobe unsupported. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"initrd", "legacy_initrd '%s' %s\n", NULL, 0, 2, {TYPE_FILE_NO_CONSUME,
|
|
|
|
TYPE_REST_VERBATIM}, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"FILE [ARG ...]",
|
|
|
|
"Load an initial ramdisk FILE for a Linux format boot image and set the"
|
|
|
|
" appropriate parameters in the Linux setup area in memory."},
|
2010-09-12 01:05:19 +00:00
|
|
|
/* NOTE: install unsupported. */
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: ioprobe unsupported. */
|
2010-08-27 19:27:26 +00:00
|
|
|
/* FIXME: really support --no-mem-option. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"kernel", "legacy_kernel %s %s '%s' %s\n", NULL, 0,
|
|
|
|
4, {TYPE_TYPE_OR_NOMEM_OPTION, TYPE_TYPE_OR_NOMEM_OPTION,
|
|
|
|
TYPE_FILE_NO_CONSUME, TYPE_REST_VERBATIM}, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"[--no-mem-option] [--type=TYPE] FILE [ARG ...]",
|
|
|
|
"Attempt to load the primary boot image from FILE. The rest of the"
|
|
|
|
" line is passed verbatim as the \"kernel command line\". Any modules"
|
|
|
|
" must be reloaded after using this command. The option --type is used"
|
|
|
|
" to suggest what type of kernel to be loaded. TYPE must be either of"
|
|
|
|
" \"netbsd\", \"freebsd\", \"openbsd\", \"linux\", \"biglinux\" and"
|
|
|
|
" \"multiboot\". The option --no-mem-option tells GRUB not to pass a"
|
|
|
|
" Linux's mem option automatically."},
|
2010-09-12 14:11:41 +00:00
|
|
|
{"lock", "if ! authenticate legacy; then return; fi", NULL, 0, 0, {}, 0,
|
|
|
|
0, "Break a command execution unless the user is authenticated."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"makeactive", "parttool \"$root\" boot+\n", NULL, 0, 0, {}, 0, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"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."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"map", "drivemap '%s' '%s'\n", NULL, 0,
|
|
|
|
2, {TYPE_PARTITION, TYPE_PARTITION},
|
2010-08-27 18:04:49 +00:00
|
|
|
FLAG_IGNORE_REST, "TO_DRIVE FROM_DRIVE",
|
|
|
|
"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"
|
|
|
|
" OS resides at a non-first drive."},
|
2010-09-12 01:05:19 +00:00
|
|
|
/* NOTE: md5crypt unsupported since GRUB has not enough entropy and this
|
2010-09-12 00:30:48 +00:00
|
|
|
hash shouldn't be used anymore. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"module", "legacy_initrd '%s' %s\n", NULL, 0, 2, {TYPE_FILE_NO_CONSUME,
|
|
|
|
TYPE_REST_VERBATIM}, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"FILE [ARG ...]",
|
|
|
|
"Load a boot module FILE for a Multiboot format boot image (no"
|
|
|
|
" interpretation of the file contents is made, so users of this"
|
|
|
|
" command must know what the kernel in question expects). The"
|
|
|
|
" rest of the line is passed as the \"module command line\", like"
|
|
|
|
" the `kernel' command."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"modulenounzip", "legacy_initrd_nounzip '%s' %s\n", NULL, 0, 2,
|
2010-09-12 00:30:48 +00:00
|
|
|
{TYPE_FILE_NO_CONSUME, TYPE_REST_VERBATIM}, 0,
|
|
|
|
"FILE [ARG ...]",
|
|
|
|
"The same as `module', except that automatic decompression is"
|
|
|
|
" disabled."},
|
2010-09-12 13:26:38 +00:00
|
|
|
{"pager", "set pager=%s; if [ \"$pager\" = 0 ]; then "
|
2010-09-12 13:50:52 +00:00
|
|
|
" echo Internal pager is now off; else "
|
|
|
|
"echo Internal pager is now on; fi\n", NULL, 0,
|
2010-09-12 13:26:38 +00:00
|
|
|
1, {TYPE_BOOL}, FLAG_FALLBACK_AVAILABLE, "[FLAG]",
|
2010-08-27 18:04:49 +00:00
|
|
|
"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."},
|
2010-09-12 13:26:38 +00:00
|
|
|
{"pager",
|
|
|
|
"if [ \"$pager\" = 1 ]; then pager=0; echo Internal pager is now off;"
|
2010-09-12 13:50:52 +00:00
|
|
|
"else pager=1; echo Internal pager is now on; fi\n", NULL, 0, 0, {},
|
2010-09-12 13:26:38 +00:00
|
|
|
FLAG_FALLBACK, NULL, NULL},
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: partnew unsupported. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"parttype", "parttool '%s' type=%s\n", NULL, 0,
|
|
|
|
2, {TYPE_PARTITION, TYPE_INT}, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"PART TYPE", "Change the type of the partition PART to TYPE."},
|
2010-09-12 09:09:01 +00:00
|
|
|
{"password", "if [ \"$superusers\" = "" ]; then superusers=legacy; fi;\n"
|
2010-09-15 11:51:02 +00:00
|
|
|
"legacy_password %s '%s'\n",
|
2010-09-12 13:54:39 +00:00
|
|
|
"menuentry \"Superuser menu\" --users \"legacy\" { configfile '%s'; }\n",
|
|
|
|
2, 3, {TYPE_OPTION, TYPE_VERBATIM, TYPE_FILE},
|
2010-09-15 11:51:02 +00:00
|
|
|
FLAG_IGNORE_REST | FLAG_FALLBACK_AVAILABLE | FLAG_NO_MENUENTRY,
|
|
|
|
"[--md5] PASSWD [FILE]",
|
2010-09-11 23:07:41 +00:00
|
|
|
"If used in the first section of a menu file, disable all"
|
|
|
|
" interactive editing control (menu entry editor and"
|
|
|
|
" command line). If the password PASSWD is entered, it loads the"
|
|
|
|
" FILE as a new config file and restarts the GRUB Stage 2. If you"
|
|
|
|
" omit the argument FILE, then GRUB just unlocks privileged"
|
|
|
|
" instructions. You can also use it in the script section, in"
|
|
|
|
" which case it will ask for the password, before continuing."
|
|
|
|
" The option --md5 tells GRUB that PASSWD is encrypted with"
|
|
|
|
" md5crypt."},
|
2010-09-12 13:54:39 +00:00
|
|
|
{"password", "if [ \"$superusers\" = "" ]; then superusers=legacy; fi;\n"
|
2010-09-15 11:51:02 +00:00
|
|
|
"legacy_password %s '%s'\n", NULL, 0, 2, {TYPE_OPTION, TYPE_VERBATIM},
|
|
|
|
FLAG_IGNORE_REST | FLAG_FALLBACK | FLAG_NO_MENUENTRY, NULL, NULL},
|
|
|
|
{"password", "if legacy_check_password %s '%s'; then configfile '%s'; "
|
|
|
|
"else return; fi\n", NULL, 2, 3, {TYPE_OPTION, TYPE_VERBATIM, TYPE_FILE},
|
|
|
|
FLAG_IGNORE_REST | FLAG_FALLBACK_AVAILABLE | FLAG_MENUENTRY_ONLY,
|
|
|
|
NULL, NULL},
|
|
|
|
{"password", "if ! legacy_check_password %s '%s'; then return fi;\n",
|
|
|
|
NULL, 0, 2, {TYPE_OPTION, TYPE_VERBATIM},
|
|
|
|
FLAG_IGNORE_REST | FLAG_FALLBACK | FLAG_MENUENTRY_ONLY, NULL, NULL},
|
2010-09-12 01:05:19 +00:00
|
|
|
/* NOTE: GRUB2 has a design principle of not eternally waiting for user
|
|
|
|
input. 60 seconds should be enough.
|
|
|
|
*/
|
2010-09-12 13:50:52 +00:00
|
|
|
{"pause", "echo %s; if ! sleep -i 60; then return; fi\n", NULL, 0, 1,
|
2010-09-12 01:05:19 +00:00
|
|
|
{TYPE_REST_VERBATIM}, 0,
|
|
|
|
"[MESSAGE ...]", "Print MESSAGE, then wait until a key is pressed."},
|
2013-11-09 20:29:11 +00:00
|
|
|
{"print", "echo %s\n", NULL, 0, 1,
|
|
|
|
{TYPE_REST_VERBATIM}, 0,
|
|
|
|
"[MESSAGE ...]", "Print MESSAGE."},
|
2012-07-02 09:31:31 +00:00
|
|
|
/* FIXME: quit unsupported. */
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: rarp unsupported. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"read", "read_dword %s\n", NULL, 0, 1, {TYPE_INT}, 0, "ADDR",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Read a 32-bit value from memory at address ADDR and"
|
|
|
|
" display it in hex format."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"reboot", "reboot\n", NULL, 0, 0, {}, 0, 0, "Reboot your system."},
|
|
|
|
{"root", "set root='%s'; set legacy_hdbias='%s'\n", NULL, 0,
|
2010-09-12 13:26:38 +00:00
|
|
|
2, {TYPE_PARTITION, TYPE_INT}, FLAG_FALLBACK_AVAILABLE,
|
2010-09-12 12:01:02 +00:00
|
|
|
"[DEVICE [HDBIAS]]",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Set the current \"root device\" to the device DEVICE, then"
|
|
|
|
" attempt to mount it to get the partition size (for passing the"
|
|
|
|
" partition descriptor in `ES:ESI', used by some chain-loaded"
|
|
|
|
" bootloaders), the BSD drive-type (for booting BSD kernels using"
|
|
|
|
" their native boot format), and correctly determine "
|
|
|
|
" the PC partition where a BSD sub-partition is located. The"
|
|
|
|
" optional HDBIAS parameter is a number to tell a BSD kernel"
|
|
|
|
" 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"
|
|
|
|
" FreeBSD root partition is on the SCSI disk, then use a `1' for HDBIAS."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"root", "echo \"$root\"\n", NULL, 0, 0, {}, FLAG_FALLBACK, NULL, NULL},
|
|
|
|
{"rootnoverify", "set root='%s'; set legacy_hdbias='%s'\n", NULL, 0,
|
2010-09-12 12:01:02 +00:00
|
|
|
2, {TYPE_PARTITION, TYPE_INT}, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"[DEVICE [HDBIAS]]",
|
|
|
|
"Similar to `root', but don't attempt to mount the partition. This"
|
|
|
|
" is useful for when an OS is outside of the area of the disk that"
|
|
|
|
" GRUB can read, but setting the correct root device is still"
|
|
|
|
" desired. Note that the items mentioned in `root' which"
|
|
|
|
" derived from attempting the mount will NOT work correctly."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"rootnoverify", "echo \"$root\"\n", NULL, 0,
|
|
|
|
0, {}, FLAG_FALLBACK, NULL, NULL},
|
2010-09-12 01:05:19 +00:00
|
|
|
/* FIXME: support saving NUM and fallback. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"savedefault", "saved_entry=${chosen}; save_env saved_entry\n", NULL, 0,
|
|
|
|
0, {}, 0, "[NUM | `fallback']",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Save the current entry as the default boot entry if no argument is"
|
|
|
|
" specified. If a number is specified, this number is saved. If"
|
|
|
|
" `fallback' is used, next fallback entry is saved."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"serial", "serial %s\n", NULL, 0, 1, {TYPE_REST_VERBATIM}, 0,
|
2010-08-27 18:04:49 +00:00
|
|
|
"[--unit=UNIT] [--port=PORT] [--speed=SPEED] [--word=WORD] "
|
|
|
|
"[--parity=PARITY] [--stop=STOP] [--device=DEV]",
|
|
|
|
"Initialize a serial device. UNIT is a digit that specifies which serial"
|
|
|
|
" device is used (e.g. 0 == COM1). If you need to specify the port number,"
|
|
|
|
" set it by --port. SPEED is the DTE-DTE speed. WORD is the word length,"
|
|
|
|
" PARITY is the type of parity, which is one of `no', `odd' and `even'."
|
|
|
|
" STOP is the length of stop bit(s). The option --device can be used only"
|
|
|
|
" in the grub shell, which specifies the file name of a tty device. The"
|
|
|
|
" default values are COM1, 9600, 8N1."},
|
2013-11-05 01:43:27 +00:00
|
|
|
/* FIXME: shade unsupported. */
|
2012-07-02 09:31:31 +00:00
|
|
|
/* FIXME: silent unsupported. */
|
|
|
|
/* FIXME: splashimage unsupported. */
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: setkey unsupported. */ /* NUL_TERMINATE */
|
2010-09-12 14:15:40 +00:00
|
|
|
/* NOTE: setup unsupported. */
|
2012-06-28 13:27:54 +00:00
|
|
|
/* FIXME: --no-echo, --no-edit unsupported. */
|
2010-09-20 12:48:17 +00:00
|
|
|
/* NOTE: both terminals are activated so --silent and --timeout
|
|
|
|
are useless. */
|
2012-07-02 09:31:31 +00:00
|
|
|
/* FIXME: graphics unsupported. */
|
2010-09-20 12:48:17 +00:00
|
|
|
{"terminal", NULL, NULL, 0, 0, {}, FLAG_TERMINAL | FLAG_IGNORE_REST,
|
|
|
|
"[--dumb] [--no-echo] [--no-edit] [--timeout=SECS] [--lines=LINES] "
|
2013-11-05 01:43:27 +00:00
|
|
|
"[--silent] [console] [serial] [hercules] [graphics]",
|
2010-09-20 12:48:17 +00:00
|
|
|
"Select a terminal. When multiple terminals are specified, wait until"
|
|
|
|
" you push any key to continue. If both console and serial are specified,"
|
|
|
|
" the terminal to which you input a key first will be selected. If no"
|
|
|
|
" argument is specified, print current setting. The option --dumb"
|
|
|
|
" specifies that your terminal is dumb, otherwise, vt100-compatibility"
|
|
|
|
" is assumed. If you specify --no-echo, input characters won't be echoed."
|
|
|
|
" If you specify --no-edit, the BASH-like editing feature will be disabled."
|
|
|
|
" If --timeout is present, this command will wait at most for SECS"
|
|
|
|
" seconds. The option --lines specifies the maximum number of lines."
|
|
|
|
" The option --silent is used to suppress messages."},
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: terminfo unsupported. */ /* NUL_TERMINATE */
|
2012-07-02 09:31:31 +00:00
|
|
|
{"testload", "testload '%s'\n", NULL, 0, 1, {TYPE_FILE}, 0, "FILE",
|
2010-09-05 18:43:43 +00:00
|
|
|
"Read the entire contents of FILE in several different ways and"
|
|
|
|
" compares them, to test the filesystem code. "
|
|
|
|
" If this test succeeds, then a good next"
|
|
|
|
" step is to try loading a kernel."},
|
2010-09-15 09:39:53 +00:00
|
|
|
{"testvbe", "insmod vbe; videotest '%s'\n", NULL, 0, 1, {TYPE_VBE_MODE}, 0,
|
|
|
|
"MODE", "Test the VBE mode MODE. Hit any key to return."},
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: tftpserver unsupported. */
|
2010-09-12 13:50:52 +00:00
|
|
|
{"timeout", "set timeout=%s\n", NULL, 0, 1, {TYPE_INT}, 0, "SEC",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Set a timeout, in SEC seconds, before automatically booting the"
|
|
|
|
" default entry (normally the first entry defined)."},
|
2010-09-20 12:48:17 +00:00
|
|
|
{"title", NULL, NULL, 0, 0, {}, FLAG_TITLE, "NAME ...",
|
|
|
|
"Start a new boot entry, and set its name to the contents of the"
|
|
|
|
" rest of the line, starting with the first non-space character."},
|
2010-09-12 13:50:52 +00:00
|
|
|
{"unhide", "parttool '%s' hidden-\n", NULL, 0,
|
|
|
|
1, {TYPE_PARTITION}, 0, "PARTITION",
|
2010-08-27 18:04:49 +00:00
|
|
|
"Unhide PARTITION by clearing the \"hidden\" bit in its"
|
|
|
|
" partition type code."},
|
2010-09-12 00:30:48 +00:00
|
|
|
/* FIXME: uppermem unsupported. */
|
2010-09-15 00:16:12 +00:00
|
|
|
{"uuid", "search --set=root --fs-uuid '%s'\n", NULL, 0, 1, {TYPE_VERBATIM},
|
|
|
|
0, "UUID", "Find root by UUID"},
|
2010-09-15 12:37:28 +00:00
|
|
|
{"vbeprobe", "insmod vbe; videoinfo '%s'\n", NULL, 0, 1, {TYPE_VBE_MODE},
|
|
|
|
FLAG_FALLBACK_AVAILABLE, "[MODE]",
|
2010-09-12 00:30:48 +00:00
|
|
|
"Probe VBE information. If the mode number MODE is specified, show only"
|
2010-09-15 12:37:28 +00:00
|
|
|
" the information about only the mode."},
|
|
|
|
{"vbeprobe", "insmod vbe; videoinfo\n", NULL, 0, 0, {},
|
|
|
|
FLAG_FALLBACK, NULL, NULL}
|
2012-07-02 09:31:31 +00:00
|
|
|
/* FIXME: verbose unsupported. */
|
|
|
|
/* FIXME: version unsupported. */
|
2013-11-05 01:43:27 +00:00
|
|
|
/* FIXME: viewport unsupported. */
|
2010-08-27 18:04:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
char *
|
|
|
|
grub_legacy_escape (const char *in, grub_size_t len)
|
|
|
|
{
|
2010-11-25 13:26:20 +00:00
|
|
|
char *ptr;
|
2010-11-25 13:35:16 +00:00
|
|
|
char *ret;
|
2010-11-25 13:37:02 +00:00
|
|
|
char saved;
|
2010-08-27 18:04:49 +00:00
|
|
|
int overhead = 0;
|
2010-11-25 13:26:20 +00:00
|
|
|
|
|
|
|
for (ptr = (char*)in; ptr < in + len && *ptr; ptr++)
|
2010-11-14 23:33:28 +00:00
|
|
|
if (*ptr == '\'')
|
|
|
|
overhead += 3;
|
2010-11-25 13:35:16 +00:00
|
|
|
ret = grub_malloc (ptr - in + overhead + 1);
|
|
|
|
if (!ret)
|
2010-08-27 18:04:49 +00:00
|
|
|
return NULL;
|
2010-11-25 13:26:20 +00:00
|
|
|
|
|
|
|
ptr = (char*)in;
|
|
|
|
saved = ptr[len];
|
|
|
|
ptr[len] = '\0';
|
2010-11-25 13:35:16 +00:00
|
|
|
grub_strchrsub (ret, ptr, '\'', "'\\''");
|
2010-11-25 13:26:20 +00:00
|
|
|
ptr[len] = saved;
|
2010-11-25 13:35:16 +00:00
|
|
|
return ret;
|
2010-08-27 18:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
adjust_file (const char *in, grub_size_t len)
|
|
|
|
{
|
|
|
|
const char *comma, *ptr, *rest;
|
|
|
|
char *ret, *outptr;
|
|
|
|
int overhead = 0;
|
2010-09-12 12:18:39 +00:00
|
|
|
int part = -1, subpart = -1;
|
2010-08-27 18:04:49 +00:00
|
|
|
if (in[0] != '(')
|
|
|
|
return grub_legacy_escape (in, len);
|
|
|
|
for (ptr = in + 1; ptr < in + len && *ptr && *ptr != ')'
|
|
|
|
&& *ptr != ','; ptr++)
|
|
|
|
if (*ptr == '\'' || *ptr == '\\')
|
|
|
|
overhead++;
|
|
|
|
comma = ptr;
|
2013-10-27 00:50:31 +00:00
|
|
|
if (*comma == ')' && comma - in == 3
|
|
|
|
&& in[1] == 'n' && in[2] == 'd')
|
|
|
|
{
|
|
|
|
rest = comma + 1;
|
|
|
|
for (ptr = rest; ptr < in + len && *ptr; ptr++)
|
|
|
|
if (*ptr == '\'' || *ptr == '\\')
|
|
|
|
overhead++;
|
|
|
|
|
|
|
|
ret = grub_malloc (ptr - in + overhead + 15);
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
outptr = grub_stpcpy (ret, "(tftp)");;
|
|
|
|
for (ptr = rest; ptr < in + len; ptr++)
|
|
|
|
{
|
|
|
|
if (*ptr == '\'' || *ptr == '\\')
|
|
|
|
*outptr++ = '\\';
|
|
|
|
|
|
|
|
*outptr++ = *ptr;
|
|
|
|
}
|
|
|
|
*outptr = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
2010-08-27 18:04:49 +00:00
|
|
|
if (*comma != ',')
|
|
|
|
return grub_legacy_escape (in, len);
|
misc: Make grub_strtol() "end" pointers have safer const qualifiers
Currently the string functions grub_strtol(), grub_strtoul(), and
grub_strtoull() don't declare the "end" pointer in such a way as to
require the pointer itself or the character array to be immutable to the
implementation, nor does the C standard do so in its similar functions,
though it does require us not to change any of it.
The typical declarations of these functions follow this pattern:
long
strtol(const char * restrict nptr, char ** restrict endptr, int base);
Much of the reason for this is historic, and a discussion of that
follows below, after the explanation of this change. (GRUB currently
does not include the "restrict" qualifiers, and we name the arguments a
bit differently.)
The implementation is semantically required to treat the character array
as immutable, but such accidental modifications aren't stopped by the
compiler, and the semantics for both the callers and the implementation
of these functions are sometimes also helped by adding that requirement.
This patch changes these declarations to follow this pattern instead:
long
strtol(const char * restrict nptr,
const char ** const restrict endptr,
int base);
This means that if any modification to these functions accidentally
introduces either an errant modification to the underlying character
array, or an accidental assignment to endptr rather than *endptr, the
compiler should generate an error. (The two uses of "restrict" in this
case basically mean strtol() isn't allowed to modify the character array
by going through *endptr, and endptr isn't allowed to point inside the
array.)
It also means the typical use case changes to:
char *s = ...;
const char *end;
long l;
l = strtol(s, &end, 10);
Or even:
const char *p = str;
while (p && *p) {
long l = strtol(p, &p, 10);
...
}
This fixes 26 places where we discard our attempts at treating the data
safely by doing:
const char *p = str;
long l;
l = strtol(p, (char **)&ptr, 10);
It also adds 5 places where we do:
char *p = str;
while (p && *p) {
long l = strtol(p, (const char ** const)&p, 10);
...
/* more calls that need p not to be pointer-to-const */
}
While moderately distasteful, this is a better problem to have.
With one minor exception, I have tested that all of this compiles
without relevant warnings or errors, and that /much/ of it behaves
correctly, with gcc 9 using 'gcc -W -Wall -Wextra'. The one exception
is the changes in grub-core/osdep/aros/hostdisk.c , which I have no idea
how to build.
Because the C standard defined type-qualifiers in a way that can be
confusing, in the past there's been a slow but fairly regular stream of
churn within our patches, which add and remove the const qualifier in many
of the users of these functions. This change should help avoid that in
the future, and in order to help ensure this, I've added an explanation
in misc.h so that when someone does get a compiler warning about a type
error, they have the fix at hand.
The reason we don't have "const" in these calls in the standard is
purely anachronistic: C78 (de facto) did not have type qualifiers in the
syntax, and the "const" type qualifier was added for C89 (I think; it
may have been later). strtol() appears to date from 4.3BSD in 1986,
which means it could not be added to those functions in the standard
without breaking compatibility, which is usually avoided.
The syntax chosen for type qualifiers is what has led to the churn
regarding usage of const, and is especially confusing on string
functions due to the lack of a string type. Quoting from C99, the
syntax is:
declarator:
pointer[opt] direct-declarator
direct-declarator:
identifier
( declarator )
direct-declarator [ type-qualifier-list[opt] assignment-expression[opt] ]
...
direct-declarator [ type-qualifier-list[opt] * ]
...
pointer:
* type-qualifier-list[opt]
* type-qualifier-list[opt] pointer
type-qualifier-list:
type-qualifier
type-qualifier-list type-qualifier
...
type-qualifier:
const
restrict
volatile
So the examples go like:
const char foo; // immutable object
const char *foo; // mutable pointer to object
char * const foo; // immutable pointer to mutable object
const char * const foo; // immutable pointer to immutable object
const char const * const foo; // XXX extra const keyword in the middle
const char * const * const foo; // immutable pointer to immutable
// pointer to immutable object
const char ** const foo; // immutable pointer to mutable pointer
// to immutable object
Making const left-associative for * and right-associative for everything
else may not have been the best choice ever, but here we are, and the
inevitable result is people using trying to use const (as they should!),
putting it at the wrong place, fighting with the compiler for a bit, and
then either removing it or typecasting something in a bad way. I won't
go into describing restrict, but its syntax has exactly the same issue
as with const.
Anyway, the last example above actually represents the *behavior* that's
required of strtol()-like functions, so that's our choice for the "end"
pointer.
Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-02-21 21:39:33 +00:00
|
|
|
part = grub_strtoull (comma + 1, &rest, 0);
|
2010-09-12 12:18:39 +00:00
|
|
|
if (rest[0] == ',' && rest[1] >= 'a' && rest[1] <= 'z')
|
|
|
|
{
|
|
|
|
subpart = rest[1] - 'a';
|
|
|
|
rest += 2;
|
|
|
|
}
|
2010-08-27 18:04:49 +00:00
|
|
|
for (ptr = rest; ptr < in + len && *ptr; ptr++)
|
|
|
|
if (*ptr == '\'' || *ptr == '\\')
|
|
|
|
overhead++;
|
|
|
|
|
2010-09-12 12:18:39 +00:00
|
|
|
/* 35 is enough for any 2 numbers. */
|
2013-10-27 00:50:31 +00:00
|
|
|
ret = grub_malloc (ptr - in + overhead + 35 + 5);
|
2010-08-27 18:04:49 +00:00
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
outptr = ret;
|
|
|
|
for (ptr = in; ptr < in + len && ptr <= comma; ptr++)
|
|
|
|
{
|
|
|
|
if (*ptr == '\'' || *ptr == '\\')
|
|
|
|
*outptr++ = '\\';
|
|
|
|
|
|
|
|
*outptr++ = *ptr;
|
|
|
|
}
|
2010-09-12 12:18:39 +00:00
|
|
|
if (subpart != -1)
|
|
|
|
grub_snprintf (outptr, 35, "%d,%d", part + 1, subpart + 1);
|
|
|
|
else
|
|
|
|
grub_snprintf (outptr, 35, "%d", part + 1);
|
2010-08-27 18:04:49 +00:00
|
|
|
while (*outptr)
|
|
|
|
outptr++;
|
|
|
|
for (ptr = rest; ptr < in + len; ptr++)
|
|
|
|
{
|
|
|
|
if (*ptr == '\'' || *ptr == '\\')
|
|
|
|
*outptr++ = '\\';
|
|
|
|
|
|
|
|
*outptr++ = *ptr;
|
|
|
|
}
|
2010-09-11 20:39:55 +00:00
|
|
|
*outptr = 0;
|
2010-08-27 18:04:49 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-11-30 15:20:13 +00:00
|
|
|
check_option (const char *a, const char *b, grub_size_t len)
|
2010-08-27 18:04:49 +00:00
|
|
|
{
|
|
|
|
if (grub_strlen (b) != len)
|
|
|
|
return 0;
|
|
|
|
return grub_strncmp (a, b, len) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_option (enum arg_type opt, const char *curarg, grub_size_t len)
|
|
|
|
{
|
|
|
|
switch (opt)
|
|
|
|
{
|
2011-10-05 08:21:32 +00:00
|
|
|
case TYPE_WITH_CONFIGFILE_OPTION:
|
|
|
|
return check_option (curarg, "--with-configfile", len);
|
2010-08-27 18:04:49 +00:00
|
|
|
case TYPE_NOAPM_OPTION:
|
|
|
|
return check_option (curarg, "--no-apm", len);
|
|
|
|
case TYPE_FORCE_OPTION:
|
|
|
|
return check_option (curarg, "--force", len);
|
|
|
|
case TYPE_TYPE_OR_NOMEM_OPTION:
|
|
|
|
return check_option (curarg, "--type=netbsd", len)
|
|
|
|
|| check_option (curarg, "--type=freebsd", len)
|
|
|
|
|| check_option (curarg, "--type=openbsd", len)
|
|
|
|
|| check_option (curarg, "--type=linux", len)
|
|
|
|
|| check_option (curarg, "--type=biglinux", len)
|
|
|
|
|| check_option (curarg, "--type=multiboot", len)
|
|
|
|
|| check_option (curarg, "--no-mem-option", len);
|
2010-09-11 23:07:41 +00:00
|
|
|
case TYPE_OPTION:
|
|
|
|
return (len >= 2 && curarg[0] == '-' && curarg[1] == '-');
|
2010-08-27 18:04:49 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2010-09-12 13:50:52 +00:00
|
|
|
grub_legacy_parse (const char *buf, char **entryname, char **suffix)
|
2010-08-27 18:04:49 +00:00
|
|
|
{
|
|
|
|
const char *ptr;
|
|
|
|
const char *cmdname;
|
|
|
|
unsigned i, cmdnum;
|
2010-09-20 12:48:17 +00:00
|
|
|
char *args[ARRAY_SIZE (legacy_commands[0].argt)];
|
2010-08-27 18:04:49 +00:00
|
|
|
|
2010-09-12 13:50:52 +00:00
|
|
|
*suffix = NULL;
|
2010-09-12 00:55:24 +00:00
|
|
|
|
2010-08-27 18:04:49 +00:00
|
|
|
for (ptr = buf; *ptr && grub_isspace (*ptr); ptr++);
|
|
|
|
if (!*ptr || *ptr == '#')
|
2010-09-12 12:01:02 +00:00
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
int len = grub_strlen (buf);
|
|
|
|
ret = grub_malloc (len + 2);
|
|
|
|
grub_memcpy (ret, buf, len);
|
2010-09-12 12:18:39 +00:00
|
|
|
if (len && ret[len - 1] == '\n')
|
|
|
|
ret[len] = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret[len] = '\n';
|
|
|
|
ret[len + 1] = 0;
|
|
|
|
}
|
2010-09-12 12:01:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2010-08-27 18:04:49 +00:00
|
|
|
|
|
|
|
cmdname = ptr;
|
|
|
|
for (ptr = buf; *ptr && !grub_isspace (*ptr) && *ptr != '='; ptr++);
|
|
|
|
|
|
|
|
for (cmdnum = 0; cmdnum < ARRAY_SIZE (legacy_commands); cmdnum++)
|
|
|
|
if (grub_strncmp (legacy_commands[cmdnum].name, cmdname, ptr - cmdname) == 0
|
2010-09-15 11:51:02 +00:00
|
|
|
&& legacy_commands[cmdnum].name[ptr - cmdname] == 0
|
|
|
|
&& (!(*entryname != NULL && (legacy_commands[cmdnum].flags
|
|
|
|
& FLAG_NO_MENUENTRY)))
|
|
|
|
&& (!(*entryname == NULL && (legacy_commands[cmdnum].flags
|
|
|
|
& FLAG_MENUENTRY_ONLY))))
|
2010-08-27 18:04:49 +00:00
|
|
|
break;
|
|
|
|
if (cmdnum == ARRAY_SIZE (legacy_commands))
|
|
|
|
return grub_xasprintf ("# Unsupported legacy command: %s\n", buf);
|
|
|
|
|
|
|
|
for (; grub_isspace (*ptr) || *ptr == '='; ptr++);
|
|
|
|
|
2010-09-20 12:48:17 +00:00
|
|
|
if (legacy_commands[cmdnum].flags & FLAG_TITLE)
|
|
|
|
{
|
|
|
|
const char *ptr2;
|
|
|
|
ptr2 = ptr + grub_strlen (ptr);
|
|
|
|
while (ptr2 > ptr && grub_isspace (*(ptr2 - 1)))
|
|
|
|
ptr2--;
|
|
|
|
*entryname = grub_strndup (ptr, ptr2 - ptr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legacy_commands[cmdnum].flags & FLAG_TERMINAL)
|
|
|
|
{
|
2010-10-16 20:16:52 +00:00
|
|
|
int dumb = 0, lines = 24;
|
|
|
|
#ifdef TODO
|
|
|
|
int no_echo = 0, no_edit = 0;
|
|
|
|
#endif
|
2012-06-28 13:27:54 +00:00
|
|
|
int hercules = 0;
|
2013-11-05 01:43:27 +00:00
|
|
|
int console = 0, serial = 0, graphics = 0;
|
2010-09-20 12:48:17 +00:00
|
|
|
/* Big enough for any possible resulting command. */
|
2013-11-05 01:43:27 +00:00
|
|
|
char outbuf[512] = "";
|
2010-09-20 12:48:17 +00:00
|
|
|
char *outptr;
|
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
/* "[--timeout=SECS] [--silent]"
|
|
|
|
" [console] [serial] [hercules]"*/
|
|
|
|
if (grub_memcmp (ptr, "--dumb", sizeof ("--dumb") - 1) == 0)
|
|
|
|
dumb = 1;
|
2010-10-16 20:16:52 +00:00
|
|
|
#ifdef TODO
|
2010-09-20 12:48:17 +00:00
|
|
|
if (grub_memcmp (ptr, "--no-echo", sizeof ("--no-echo") - 1) == 0)
|
|
|
|
no_echo = 1;
|
|
|
|
|
|
|
|
if (grub_memcmp (ptr, "--no-edit", sizeof ("--no-edit") - 1) == 0)
|
|
|
|
no_edit = 1;
|
2010-10-16 20:16:52 +00:00
|
|
|
#endif
|
2010-09-20 12:48:17 +00:00
|
|
|
if (grub_memcmp (ptr, "--lines=", sizeof ("--lines=") - 1) == 0)
|
|
|
|
{
|
|
|
|
lines = grub_strtoul (ptr + sizeof ("--lines=") - 1, 0, 0);
|
|
|
|
if (grub_errno)
|
|
|
|
{
|
|
|
|
lines = 24;
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grub_memcmp (ptr, "console", sizeof ("console") - 1) == 0)
|
|
|
|
console = 1;
|
|
|
|
|
|
|
|
if (grub_memcmp (ptr, "serial", sizeof ("serial") - 1) == 0)
|
|
|
|
serial = 1;
|
|
|
|
if (grub_memcmp (ptr, "hercules", sizeof ("hercules") - 1) == 0)
|
|
|
|
hercules = 1;
|
2013-11-05 01:43:27 +00:00
|
|
|
if (grub_memcmp (ptr, "graphics", sizeof ("graphics") - 1) == 0)
|
|
|
|
graphics = 1;
|
2010-09-20 12:48:17 +00:00
|
|
|
while (*ptr && !grub_isspace (*ptr))
|
|
|
|
ptr++;
|
|
|
|
while (*ptr && grub_isspace (*ptr))
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
2013-11-05 01:43:27 +00:00
|
|
|
if (!console && !serial && !hercules && !graphics)
|
2010-09-20 12:48:17 +00:00
|
|
|
return grub_strdup ("terminal_input; terminal_output; terminfo\n");
|
|
|
|
|
2013-11-05 01:43:27 +00:00
|
|
|
outptr = outbuf;
|
|
|
|
|
|
|
|
if (graphics)
|
|
|
|
outptr = grub_stpcpy (outptr, "insmod all_video; ");
|
|
|
|
|
|
|
|
outptr = grub_stpcpy (outptr, "terminal_input ");
|
2010-09-20 12:48:17 +00:00
|
|
|
if (serial)
|
2013-11-05 01:43:27 +00:00
|
|
|
outptr = grub_stpcpy (outptr, "serial ");
|
|
|
|
if (console || hercules || graphics)
|
|
|
|
outptr = grub_stpcpy (outptr, "console ");
|
|
|
|
outptr = grub_stpcpy (outptr, "; terminal_output ");
|
2010-09-20 12:48:17 +00:00
|
|
|
if (serial)
|
2013-11-05 01:43:27 +00:00
|
|
|
outptr = grub_stpcpy (outptr, "serial ");
|
2010-09-20 12:48:17 +00:00
|
|
|
if (console)
|
2013-11-05 01:43:27 +00:00
|
|
|
outptr = grub_stpcpy (outptr, "console ");
|
2012-06-28 13:27:54 +00:00
|
|
|
if (hercules)
|
2013-11-05 01:43:27 +00:00
|
|
|
outptr = grub_stpcpy (outptr, "mda_text ");
|
|
|
|
if (graphics)
|
|
|
|
outptr = grub_stpcpy (outptr, "gfxterm ");
|
|
|
|
outptr = grub_stpcpy (outptr, "; ");
|
|
|
|
*outptr = '\0';
|
2010-09-20 14:27:33 +00:00
|
|
|
if (serial)
|
2010-09-20 12:48:17 +00:00
|
|
|
{
|
2010-09-20 14:27:33 +00:00
|
|
|
grub_snprintf (outptr, outbuf + sizeof (outbuf) - outptr,
|
|
|
|
"terminfo serial -g 80x%d %s; ",
|
|
|
|
lines, dumb ? "dumb" : "vt100");
|
2010-09-20 12:48:17 +00:00
|
|
|
outptr += grub_strlen (outptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_strcpy (outptr, "\n");
|
2010-09-20 14:27:33 +00:00
|
|
|
|
2010-09-20 12:48:17 +00:00
|
|
|
return grub_strdup (outbuf);
|
|
|
|
}
|
|
|
|
|
2010-08-27 18:04:49 +00:00
|
|
|
grub_memset (args, 0, sizeof (args));
|
|
|
|
|
|
|
|
{
|
|
|
|
int hold_arg = 0;
|
2010-09-12 09:01:21 +00:00
|
|
|
const char *curarg = NULL;
|
2010-09-12 13:50:52 +00:00
|
|
|
for (i = 0; i < legacy_commands[cmdnum].argc; i++)
|
2010-08-27 18:04:49 +00:00
|
|
|
{
|
2010-09-12 09:01:21 +00:00
|
|
|
grub_size_t curarglen;
|
2010-08-27 18:04:49 +00:00
|
|
|
if (hold_arg)
|
|
|
|
{
|
|
|
|
ptr = curarg;
|
|
|
|
hold_arg = 0;
|
|
|
|
}
|
|
|
|
for (; grub_isspace (*ptr); ptr++);
|
|
|
|
curarg = ptr;
|
2010-09-12 13:26:38 +00:00
|
|
|
if (!*curarg)
|
|
|
|
break;
|
2010-08-27 18:23:39 +00:00
|
|
|
for (; *ptr && !grub_isspace (*ptr); ptr++);
|
2010-08-27 18:04:49 +00:00
|
|
|
if (i != legacy_commands[cmdnum].argc - 1
|
|
|
|
|| (legacy_commands[cmdnum].flags & FLAG_IGNORE_REST))
|
|
|
|
curarglen = ptr - curarg;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curarglen = grub_strlen (curarg);
|
|
|
|
while (curarglen > 0 && grub_isspace (curarg[curarglen - 1]))
|
|
|
|
curarglen--;
|
|
|
|
}
|
|
|
|
if (*ptr)
|
|
|
|
ptr++;
|
|
|
|
switch (legacy_commands[cmdnum].argt[i])
|
|
|
|
{
|
2010-09-11 20:18:41 +00:00
|
|
|
case TYPE_FILE_NO_CONSUME:
|
|
|
|
hold_arg = 1;
|
2015-01-27 16:17:58 +00:00
|
|
|
/* Fallthrough. */
|
2010-08-27 18:04:49 +00:00
|
|
|
case TYPE_PARTITION:
|
|
|
|
case TYPE_FILE:
|
2010-09-12 13:26:38 +00:00
|
|
|
args[i] = adjust_file (curarg, curarglen);
|
2010-08-27 18:04:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_REST_VERBATIM:
|
|
|
|
{
|
|
|
|
char *outptr, *outptr0;
|
|
|
|
int overhead = 3;
|
|
|
|
ptr = curarg;
|
|
|
|
while (*ptr)
|
|
|
|
{
|
2010-08-27 18:23:39 +00:00
|
|
|
for (; *ptr && grub_isspace (*ptr); ptr++);
|
2010-08-27 18:04:49 +00:00
|
|
|
for (; *ptr && !grub_isspace (*ptr); ptr++)
|
2010-11-14 23:33:28 +00:00
|
|
|
if (*ptr == '\'')
|
|
|
|
overhead += 3;
|
2010-08-27 18:04:49 +00:00
|
|
|
if (*ptr)
|
|
|
|
ptr++;
|
|
|
|
overhead += 3;
|
|
|
|
}
|
2010-11-14 23:33:28 +00:00
|
|
|
|
2010-09-12 13:26:38 +00:00
|
|
|
outptr0 = args[i] = grub_malloc (overhead + (ptr - curarg));
|
2010-08-27 18:04:49 +00:00
|
|
|
if (!outptr0)
|
|
|
|
return NULL;
|
|
|
|
ptr = curarg;
|
|
|
|
outptr = outptr0;
|
|
|
|
while (*ptr)
|
|
|
|
{
|
2010-08-27 18:23:39 +00:00
|
|
|
for (; *ptr && grub_isspace (*ptr); ptr++);
|
2010-08-27 18:04:49 +00:00
|
|
|
if (outptr != outptr0)
|
|
|
|
*outptr++ = ' ';
|
|
|
|
*outptr++ = '\'';
|
|
|
|
for (; *ptr && !grub_isspace (*ptr); ptr++)
|
|
|
|
{
|
2010-11-14 23:33:28 +00:00
|
|
|
if (*ptr == '\'')
|
|
|
|
{
|
|
|
|
*outptr++ = '\'';
|
|
|
|
*outptr++ = '\\';
|
|
|
|
*outptr++ = '\'';
|
|
|
|
*outptr++ = '\'';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*outptr++ = *ptr;
|
2010-08-27 18:04:49 +00:00
|
|
|
}
|
|
|
|
*outptr++ = '\'';
|
|
|
|
if (*ptr)
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
*outptr++ = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_VERBATIM:
|
2010-09-12 13:26:38 +00:00
|
|
|
args[i] = grub_legacy_escape (curarg, curarglen);
|
2010-08-27 18:04:49 +00:00
|
|
|
break;
|
2011-10-05 08:21:32 +00:00
|
|
|
case TYPE_WITH_CONFIGFILE_OPTION:
|
2010-08-27 18:04:49 +00:00
|
|
|
case TYPE_FORCE_OPTION:
|
|
|
|
case TYPE_NOAPM_OPTION:
|
|
|
|
case TYPE_TYPE_OR_NOMEM_OPTION:
|
2010-09-11 23:07:41 +00:00
|
|
|
case TYPE_OPTION:
|
2010-08-27 18:04:49 +00:00
|
|
|
if (is_option (legacy_commands[cmdnum].argt[i], curarg, curarglen))
|
|
|
|
{
|
2010-09-12 13:26:38 +00:00
|
|
|
args[i] = grub_strndup (curarg, curarglen);
|
2010-08-27 18:04:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-09-12 13:26:38 +00:00
|
|
|
args[i] = grub_strdup ("");
|
2010-08-27 18:04:49 +00:00
|
|
|
hold_arg = 1;
|
|
|
|
break;
|
|
|
|
case TYPE_INT:
|
|
|
|
{
|
|
|
|
const char *brk;
|
|
|
|
int base = 10;
|
|
|
|
brk = curarg;
|
|
|
|
if (brk[0] == '0' && brk[1] == 'x')
|
2011-05-04 23:27:54 +00:00
|
|
|
{
|
|
|
|
base = 16;
|
|
|
|
brk += 2;
|
|
|
|
}
|
2010-08-27 18:04:49 +00:00
|
|
|
else if (brk[0] == '0')
|
|
|
|
base = 8;
|
|
|
|
for (; *brk && brk < curarg + curarglen; brk++)
|
|
|
|
{
|
|
|
|
if (base == 8 && (*brk == '8' || *brk == '9'))
|
|
|
|
break;
|
|
|
|
if (grub_isdigit (*brk))
|
|
|
|
continue;
|
|
|
|
if (base != 16)
|
|
|
|
break;
|
|
|
|
if (!(*brk >= 'a' && *brk <= 'f')
|
|
|
|
&& !(*brk >= 'A' && *brk <= 'F'))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (brk == curarg)
|
2010-09-12 13:26:38 +00:00
|
|
|
args[i] = grub_strdup ("0");
|
2010-08-27 18:04:49 +00:00
|
|
|
else
|
2010-09-12 13:26:38 +00:00
|
|
|
args[i] = grub_strndup (curarg, brk - curarg);
|
2010-08-27 18:04:49 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-09-15 09:39:53 +00:00
|
|
|
case TYPE_VBE_MODE:
|
|
|
|
{
|
|
|
|
unsigned mod;
|
|
|
|
struct grub_vesa_mode_table_entry *modedesc;
|
|
|
|
|
|
|
|
mod = grub_strtoul (curarg, 0, 0);
|
|
|
|
if (grub_errno)
|
|
|
|
{
|
|
|
|
mod = 0;
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
if (mod < GRUB_VESA_MODE_TABLE_START
|
|
|
|
|| mod > GRUB_VESA_MODE_TABLE_END)
|
|
|
|
{
|
|
|
|
args[i] = grub_strdup ("auto");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
modedesc = &grub_vesa_mode_table[mod - GRUB_VESA_MODE_TABLE_START];
|
|
|
|
if (!modedesc->width)
|
|
|
|
{
|
|
|
|
args[i] = grub_strdup ("auto");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
args[i] = grub_xasprintf ("%ux%ux%u",
|
|
|
|
modedesc->width, modedesc->height,
|
|
|
|
modedesc->depth);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-27 18:04:49 +00:00
|
|
|
case TYPE_BOOL:
|
|
|
|
if (curarglen == 2 && curarg[0] == 'o' && curarg[1] == 'n')
|
2010-09-12 13:26:38 +00:00
|
|
|
args[i] = grub_strdup ("1");
|
2010-08-27 18:04:49 +00:00
|
|
|
else
|
2010-09-12 13:26:38 +00:00
|
|
|
args[i] = grub_strdup ("0");
|
2010-08-27 18:04:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-12 12:01:02 +00:00
|
|
|
|
2010-09-12 13:26:38 +00:00
|
|
|
while (legacy_commands[cmdnum].argc > 0
|
|
|
|
&& args[legacy_commands[cmdnum].argc - 1] == NULL
|
|
|
|
&& (legacy_commands[cmdnum].flags & FLAG_FALLBACK_AVAILABLE)
|
|
|
|
&& args[legacy_commands[cmdnum + 1].argc] == NULL)
|
|
|
|
cmdnum++;
|
|
|
|
|
|
|
|
for (; i < legacy_commands[cmdnum].argc; i++)
|
|
|
|
switch (legacy_commands[cmdnum].argt[i])
|
|
|
|
{
|
|
|
|
case TYPE_FILE_NO_CONSUME:
|
|
|
|
case TYPE_PARTITION:
|
|
|
|
case TYPE_FILE:
|
|
|
|
case TYPE_REST_VERBATIM:
|
|
|
|
case TYPE_VERBATIM:
|
2011-10-05 08:21:32 +00:00
|
|
|
case TYPE_WITH_CONFIGFILE_OPTION:
|
2010-09-12 13:26:38 +00:00
|
|
|
case TYPE_FORCE_OPTION:
|
|
|
|
case TYPE_NOAPM_OPTION:
|
|
|
|
case TYPE_TYPE_OR_NOMEM_OPTION:
|
|
|
|
case TYPE_OPTION:
|
|
|
|
args[i] = grub_strdup ("");
|
|
|
|
break;
|
|
|
|
case TYPE_BOOL:
|
|
|
|
case TYPE_INT:
|
|
|
|
args[i] = grub_strdup ("0");
|
2010-09-15 09:39:53 +00:00
|
|
|
break;
|
|
|
|
case TYPE_VBE_MODE:
|
|
|
|
args[i] = grub_strdup ("auto");
|
|
|
|
break;
|
2010-09-12 13:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (legacy_commands[cmdnum].flags & FLAG_COLOR_INVERT)
|
|
|
|
{
|
|
|
|
char *corig = args[legacy_commands[cmdnum].argc - 1];
|
|
|
|
char *slash = grub_strchr (corig, '/');
|
|
|
|
char *invert;
|
|
|
|
grub_size_t len;
|
|
|
|
|
|
|
|
len = grub_strlen (corig);
|
|
|
|
if (!slash)
|
|
|
|
{
|
2012-02-12 14:25:25 +00:00
|
|
|
grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid color specification `%s'"),
|
2010-09-12 13:26:38 +00:00
|
|
|
args[0]);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
invert = grub_malloc (len + 1);
|
|
|
|
if (!invert)
|
|
|
|
return NULL;
|
|
|
|
grub_memcpy (invert, slash + 1, len - (slash - corig) - 1);
|
|
|
|
invert[len - (slash - args[0]) - 1] = '/';
|
|
|
|
grub_memcpy (invert + len - (slash - corig), corig, slash - corig);
|
|
|
|
invert[len] = 0;
|
|
|
|
args[legacy_commands[cmdnum].argc] = invert;
|
|
|
|
}
|
|
|
|
|
2010-09-12 13:50:52 +00:00
|
|
|
if (legacy_commands[cmdnum].suffix)
|
|
|
|
{
|
|
|
|
*suffix = grub_xasprintf (legacy_commands[cmdnum].suffix,
|
|
|
|
args[legacy_commands[cmdnum].suffixarg]);
|
|
|
|
if (*suffix)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-12 12:01:02 +00:00
|
|
|
{
|
|
|
|
char *ret = grub_xasprintf (legacy_commands[cmdnum].map, args[0], args[1],
|
|
|
|
args[2], args[3]);
|
|
|
|
grub_free (args[0]);
|
|
|
|
grub_free (args[1]);
|
|
|
|
grub_free (args[2]);
|
|
|
|
grub_free (args[3]);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-08-27 18:04:49 +00:00
|
|
|
}
|