2005-11-06 22:19:59 +00:00
|
|
|
/* execute.c -- Execute a GRUB script. */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-22 13:37:27 +00:00
|
|
|
* Copyright (C) 2005,2007,2008,2009,2010 Free Software Foundation, Inc.
|
2005-11-06 22:19:59 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2005-11-06 22:19:59 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2005-11-06 22:19:59 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2005-11-06 22:19:59 +00:00
|
|
|
* 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
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2005-11-06 22:19:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/env.h>
|
2009-05-02 Bean <bean123ch@gmail.com>
* conf/common.rmk (grub_script.tab.c): Change normal/parser.y to
script/sh/parser.y.
(pkglib_MODULES): Add normal.mod and sh.mod.
(normal_SOURCES): New variable.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
(sh_mod_SOURCES): Likewise.
(sh_mod_CFLAGS): Likewise.
(sh_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (normal/lexer.c_DEPENDENCIES): Changed to
script/sh/lexer.c_DEPENDENCIES.
(kernel_img_SOURCES): Remove kern/rescue.c, and kern/reader.c,
kern/rescue_reader.c and kern/rescue_parser.c.
(kernel_img_HEADERS): Remove rescue.h, add reader.h.
(grub_emu_SOURCES): Change source files.
(pkglib_MODULES): Remove normal.mod.
(normal_SOURCES): Removed.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1276.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/command.h (grub_command_execute): New inline function.
* include/grub/menu.h (grub_menu_entry): Removed commands field.
* include/grub/normal.h: Remove <grub/setjmp.h>.
(grub_fs_module_list): Moved to normal/autofs.c.
(grub_exit_env): Removed.
(grub_command_execute): Likewise.
(grub_normal_menu_addentry): Renamed to grub_menu_addentry, removed
parameter script.
(read_command_list): New function declaration.
(read_fs_list): Likewise.
* include/parser.h: Include <grub/reader.h>.
(grub_parser_split_cmdline): Change type of getline parameter.
(grub_parser): New structure.
(grub_parser_class): New variable.
(grub_parser_execute): New function declaration.
(grub_register_rescue_parser): Likewise.
(grub_parser_register): New inline function.
(grub_parser_unregister): Likewise.
(grub_parser_get_current): Likewise.
(grub_parser_set_current): Likewise.
* include/grub/reader.h: New file.
* kern/reader.c: Likewise.
* kern/rescue_parser.c: Likewise.
* kern/rescue_reader.c: Likewise.
* normal/autofs.c: Likewise.
* normal/dyncmd.c: Likewise.
* include/grub/rescue.h: Removed.
* normal/command.h: Likewise.
* include/grub/script.h: Moved to ...
* include/grub/script_sh.h: ... Moved here.
* normal/execute.c: Moved to ...
* script/sh/execute.c: ... Moved here.
* normal/function.c: Moved to ...
* script/sh/function.c: ... Moved here.
* normal/lexer.c: Moved to ...
* script/sh/lexer.c: ... Moved here.
* normal/parser.y: Moved to ...
* script/sh/parser.y: ... Moved here.
* normal/script.c: Moved to ...
* script/sh/script.c: ... Moved here.
* normal/main.c: Remove <grub/rescue.h> and <grub/script.h>, include
<grub/reader.h>.
(grub_exit_env): Removed.
(fs_module_list): Moved to normal/autofs.c.
(grub_file_getline): Don't handle comment here.
(free_menu): Skip removed field entry->commands.
(grub_normal_menu_addentry): Removed as grub_menu_entry, removed
script parameter.
(read_config_file): Removed nested parameter, change getline function.
(grub_enter_normal_mode): Removed.
(grub_dyncmd_dispatcher): Moved to normal/dyncmd.c.
(read_command_list): Likewise.
(autoload_fs_module): Moved to normal/autofs.c.
(read_fs_list): Likewise.
(reader_nested): New variable.
(grub_normal_execute): Run parser.sh to switch to sh parser.
(grub_cmd_rescue): Removed.
(cmd_normal): Removed.
(grub_cmd_normal): Unregister itself at the beginning. Don't register
rescue command.
(grub_cmdline_run): New function.
(grub_normal_reader_init): Likewise.
(grub_normal_read_line): Likewise.
(grub_env_write_pager): Likewise.
(cmdline): New variable.
(grub_normal_reader): Likewise.
(GRUB_MOD_INIT): Register normal reader and set as current, register
pager hook, register normal command with grub_register_command_prio,
so that it won't show up in command.lst.
(GRUB_MOD_FINI): Unregister normal reader, unhook pager, clear
grub_fs_autoload_hook.
* normal/menu.c: Remove <grub/script.h>, add <grub/command.h>.
(grub_menu_execute_entry): Replace grub_script_execute with
grub_parser_execute, change parameter to grub_command_execute.
* normal/menu_text.c: Remove <grub/script.h>.
* normal/menu_entry.c: Remove <grub/script.h>, add <grub/command.h>
and <grub/parser.h>.
(run): Change editor_getline to use new parser interface. Change
parameter to grub_command_execute.
* kern/main.c: Remove <grub/rescue.h>, include <grub/command.h>,
<grub/reader.h> and <grub/parser.h>.
(grub_load_normal_mode): Execute normal command.
(grub_main): Call grub_register_core_commands,
grub_register_rescue_parser and grub_register_rescue_reader, use
grub_reader_loop to enter input loop.
* kern/parser.c (grub_parser_spli_cmdline): Change type of getline
parameter.
(grub_parser_class): New variable.
(grub_parser_execute): New function.
* loader/i386/multiboot.c: Remove <grub/rescue.h>.
* loader/multiboot2.c: Likewise.
* loader/sparc64/ieee1275/linux.c: Likewise.
* util/grub-emu.c (read_command_list): New dummy function.
2009-05-02 19:49:34 +00:00
|
|
|
#include <grub/script_sh.h>
|
|
|
|
#include <grub/command.h>
|
|
|
|
#include <grub/menu.h>
|
2009-03-21 Bean <bean123ch@gmail.com>
* commands/blocklist.c: Add include file <grub/command.h>, remove
<grub/normal.h> and <grub/arg.h>.
(grub_cmd_blocklist): Use the new command interface.
(GRUB_MOD_INIT): Likewise.
(GRUB_MOD_FINI): Likewise.
* commands/boot.c: Likewise.
* commands/cat.c: Likewise.
* commands/cmp.c: Likewise.
* commands/configfile.c: Likewise.
* commands/crc.c: Likewise.
* commands/echo.c: Likewise.
* commands/halt.c: Likewise.
* commands/handler.c: Likewise.
* commands/hdparm.c: Likewise.
* commands/help.c: Likewise.
* commands/hexdump.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/ls.c: Likewise.
* commands/lsmmap.c: Likewise.
* commands/lspci.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/read.c: Likewise.
* commands/reboot.c: Likewise.
* commands/search.c: Likewise.
* commands/sleep.c: Likewise.
* commands/test.c: Likewise.
* commands/usbtest.c: Likewise.
* commands/videotest.c: Likewise.
* commands/i386/cpuid.c: Likewise.
* commands/i386/pc/halt.c: Likewise.
* commands/i386/pc/play.c: Likewise.
* commands/i386/pc/pxecmd.c: Likewise.
* commands/i386/pc/vbeinfo.c: Likewise.
* commands/i386/pc/vbetest.c: Likewise.
* commands/ieee1275/suspend.c: Likewise.
* disk/loopback.c: Likewise.
* font/font_cmd.c: Likewise.
* hello/hello.c: Likewise.
* loader/efi/appleloader.c: Likewise.
* loader/efi/chainloader.c: Likewise.
* loader/i386/bsd.c: Likewise.
* loader/i386/efi/linux.c: Likewise.
* loader/i386/ieee1275/linux.c: Likewise.
* loader/i386/linux.c: Likewise.
* loader/i386/pc/chainloader.c: Likewise.
* loader/i386/pc/linux.c: Likewise.
* loader/powerpc/ieee1275/linux.c: Likewise.
* loader/multiboot_loader.c: Likewise.
* term/gfxterm.c: Likewise.
* term/i386/pc/serial.c: Likewise.
* term/terminfo.c: Likewise.
* term/i386/pc/vesafb.c: Removed <grub/arg.h>.
* term/i386/pc/vga.c: Likewise.
* video/readers/jpeg.c: Likewise.
* video/readers/png.c: Likewise.
* video/readers/tga.c: Likewise.
* util/grub-fstest (cmd_loopback): Removed.
(cmd_blocklist): Likewise.
(cmd_ls): Likewise.
(grub_register_command): Likewise.
(grub_unregister_command): Likewise.
(execute_command): Use grub_command_find to locate command and execute
it.
* include/grub/efi/chainloader.h: Removed.
* loader/efi/chainloader_normal.c: Likewise.
* loader/i386/bsd_normal.c: Likewise.
* loader/i386/pc/chainloader_normal.c: Likewise.
* loader/i386/pc/multiboot_normal.c: Likewise.
* loader/linux_normal.c: Likewise.
* loader/multiboot_loader_normal.c: Likewise.
* loader/powerpc/ieee1275/linux_normal.c: Likewise.
* gencmdlist.sh: Scan new registration command grub_register_extcmd
and grub_register_command_p1.
* conf/common.rmk (grub_fstest_SOURCES): Add kern/list.c,
kern/command.c, lib/arg.c and commands/extcmd.c.
(pkglib_MODULES): Remove boot.mod, and minicmd.mod and extcmd.mod.
(minicmd_mod_SOURCES): New variable.
(minicmd_mod_CFLAGS): Likewise.
(minicmd_mod_LDFLAGS): Likewise.
(extcmd_mod_SOURCES): Likewise.
(extcmd_mod_CFLAGS): Likewise.
(extcmd_mod_LDFLAGS): Likewise.
(boot_mod_SOURCES): Removed.
(boot_mod_CFLAGS): Likewise.
(boot_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (kernel_img_SOURCES): Add kern/command.c and
kern/corecmd.c.
(kernel_img_HEADERS): Add command.h.
(grub_emu_SOURCES): Remove commands/boot.c and normal/arg.c, add
commands/minicmd.c, kern/command.c, kern/corecmd.c, commands/extcmd.c
and lib/arg.c.
(pkglib_MODULES): Change _linux.mod, _chain.mod, _bsd.mod and
_multiboot.mod as linux.mod, chain.mod, bsd.mod and multiboot.mod,
remove the corresponding normal mode command.
(normal_mod_SOURCES): Remove normal/arg.c.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1275.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/arg.h: Move from here ...
* include/grub/lib/arg.h: ... to here.
* normal/arg.c: Move from here ...
* lib/arg.c: ... to here.
* commands/extcmd.c: New file.
* commands/minicmd.c: Likewise.
* include/grub/command.h: Likewise.
* include/grub/extcmd.h: Likewise.
* kern/command.c: Likewise.
* kern/corecmd.c: Likewise.
* kern/list.c (grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(grub_prio_list_insert): Likewise.
* kern/rescue.c (grub_rescue_command): Removed.
(grub_rescue_command_list): Likewise.
(grub_rescue_register_command): Likewise.
(grub_rescue_unregister_command): Likewise.
(grub_rescue_cmd_boot): Move to minicmd.c
(grub_rescue_cmd_help): Likewise.
(grub_rescue_cmd_info): Likewise.
(grub_rescue_cmd_boot): Likewise.
(grub_rescue_cmd_testload): Likewise.
(grub_rescue_cmd_dump): Likewise.
(grub_rescue_cmd_rmmod): Likewise.
(grub_rescue_cmd_lsmod): Likewise.
(grub_rescue_cmd_exit): Likewise.
(grub_rescue_print_devices): Moved to corecmd.c.
(grub_rescue_print_files): Likewise.
(grub_rescue_cmd_ls): Likewise.
(grub_rescue_cmd_insmod): Likewise.
(grub_rescue_cmd_set): Likewise.
(grub_rescue_cmd_unset): Likewise.
(attemp_normal_mode): Use grub_command_find to get normal module.
(grub_enter_rescue_mode): Use grub_register_core_commands to register
commands, remove grub_rescue_regiter_command calls.
* normal/command.c (grub_regiser_command): Removed.
(grub_unregister_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(rescue_command): Likewise.
(export_command): Moved to corecmd.c.
(set_command): Removed.
(unset_command): Likewise.
(insmod_command): Likewise.
(rmmod_command): Likewise.
(lsmod_command): Likewise.
(grub_command_init): Likewise.
* normal/completion.c (iterate_command): Use cmd->prio to check for
active command.
(complete_arguments): Use grub_extcmd_t structure to find options.
(grub_normal_do_completion): Change function grub_iterate_commands to
grub_command_iterate.
* normal/execute.c (grub_script_execute_cmd): No need to parse
argument here.
* normal/main.c (grub_dyncmd_dispatcher): New function.
(read_command_list): Register unload commands as dyncmd.
(grub_cmd_normal): Use new command interface, register rescue,
unregister normal at entry, register normal, unregister rescue at exit.
* include/grub/list.h (grub_list_test_t): New type.
(grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(GRUB_AS_NAMED_LIST_P): New macro.
(GRUB_AS_PRIO_LIST): Likewise.
(GRUB_AS_PRIO_LIST_P): Likewise.
(GRUB_PRIO_LIST_PRIO_MASK): New constant.
(GRUB_PRIO_LIST_FLAG_ACTIVE): Likewise.
(grub_prio_list): New structure.
(grub_prio_list_insert): New function.
(grub_prio_list_remove): New inline function.
* include/grub/normal.h: Remove <grub/arg.h>, add <grub/command.h>.
(GRUB_COMMAND_FLAG_CMDLINE): Moved to command.h.
(GRUB_COMMAND_FLAG_MENU): Likewise.
(GRUB_COMMAND_FLAG_BOTH): Likewise.
(GRUB_COMMAND_FLAG_TITLE): Likewise.
(GRUB_COMMAND_FLAG_NO_ECHO): Likewise.
(GRUB_COMMAND_FLAG_NO_ARG_PARSE): Removed.
(GRUB_COMMAND_FLAG_NOT_LOADED): Likewise.
(grub_command): Likewise.
(grub_register_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(grub_command_init): Likewise.
(grub_arg_parse): Likewise.
(grub_arg_show_help): Likewise.
* include/grub/rescue.h (grub_rescue_register_command): Removed.
(grub_rescue_unregister_command): Likewise.
* include/grub/i386/bsd.h: Remove grub_rescue_cmd_freebsd,
grub_rescue_cmd_openbsd, grub_rescue_cmd_netbsd,
grub_rescue_cmd_freebsd_loadenv and grub_rescue_cmd_freebsd_module.
* include/grub/i386/efi/loader.h: Remove grub_rescue_cmd_linux and
grub_rescue_cmd_initrd.
* include/grub/i386/loader.h: Likewise.
* include/grub/x86_64/loader.h: Likewise.
* include/grub/i386/pc/chainloader.h: Remove grub_chainloader_cmd.
2009-03-21 08:39:59 +00:00
|
|
|
#include <grub/lib/arg.h>
|
2009-05-02 Bean <bean123ch@gmail.com>
* conf/common.rmk (grub_script.tab.c): Change normal/parser.y to
script/sh/parser.y.
(pkglib_MODULES): Add normal.mod and sh.mod.
(normal_SOURCES): New variable.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
(sh_mod_SOURCES): Likewise.
(sh_mod_CFLAGS): Likewise.
(sh_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (normal/lexer.c_DEPENDENCIES): Changed to
script/sh/lexer.c_DEPENDENCIES.
(kernel_img_SOURCES): Remove kern/rescue.c, and kern/reader.c,
kern/rescue_reader.c and kern/rescue_parser.c.
(kernel_img_HEADERS): Remove rescue.h, add reader.h.
(grub_emu_SOURCES): Change source files.
(pkglib_MODULES): Remove normal.mod.
(normal_SOURCES): Removed.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1276.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/command.h (grub_command_execute): New inline function.
* include/grub/menu.h (grub_menu_entry): Removed commands field.
* include/grub/normal.h: Remove <grub/setjmp.h>.
(grub_fs_module_list): Moved to normal/autofs.c.
(grub_exit_env): Removed.
(grub_command_execute): Likewise.
(grub_normal_menu_addentry): Renamed to grub_menu_addentry, removed
parameter script.
(read_command_list): New function declaration.
(read_fs_list): Likewise.
* include/parser.h: Include <grub/reader.h>.
(grub_parser_split_cmdline): Change type of getline parameter.
(grub_parser): New structure.
(grub_parser_class): New variable.
(grub_parser_execute): New function declaration.
(grub_register_rescue_parser): Likewise.
(grub_parser_register): New inline function.
(grub_parser_unregister): Likewise.
(grub_parser_get_current): Likewise.
(grub_parser_set_current): Likewise.
* include/grub/reader.h: New file.
* kern/reader.c: Likewise.
* kern/rescue_parser.c: Likewise.
* kern/rescue_reader.c: Likewise.
* normal/autofs.c: Likewise.
* normal/dyncmd.c: Likewise.
* include/grub/rescue.h: Removed.
* normal/command.h: Likewise.
* include/grub/script.h: Moved to ...
* include/grub/script_sh.h: ... Moved here.
* normal/execute.c: Moved to ...
* script/sh/execute.c: ... Moved here.
* normal/function.c: Moved to ...
* script/sh/function.c: ... Moved here.
* normal/lexer.c: Moved to ...
* script/sh/lexer.c: ... Moved here.
* normal/parser.y: Moved to ...
* script/sh/parser.y: ... Moved here.
* normal/script.c: Moved to ...
* script/sh/script.c: ... Moved here.
* normal/main.c: Remove <grub/rescue.h> and <grub/script.h>, include
<grub/reader.h>.
(grub_exit_env): Removed.
(fs_module_list): Moved to normal/autofs.c.
(grub_file_getline): Don't handle comment here.
(free_menu): Skip removed field entry->commands.
(grub_normal_menu_addentry): Removed as grub_menu_entry, removed
script parameter.
(read_config_file): Removed nested parameter, change getline function.
(grub_enter_normal_mode): Removed.
(grub_dyncmd_dispatcher): Moved to normal/dyncmd.c.
(read_command_list): Likewise.
(autoload_fs_module): Moved to normal/autofs.c.
(read_fs_list): Likewise.
(reader_nested): New variable.
(grub_normal_execute): Run parser.sh to switch to sh parser.
(grub_cmd_rescue): Removed.
(cmd_normal): Removed.
(grub_cmd_normal): Unregister itself at the beginning. Don't register
rescue command.
(grub_cmdline_run): New function.
(grub_normal_reader_init): Likewise.
(grub_normal_read_line): Likewise.
(grub_env_write_pager): Likewise.
(cmdline): New variable.
(grub_normal_reader): Likewise.
(GRUB_MOD_INIT): Register normal reader and set as current, register
pager hook, register normal command with grub_register_command_prio,
so that it won't show up in command.lst.
(GRUB_MOD_FINI): Unregister normal reader, unhook pager, clear
grub_fs_autoload_hook.
* normal/menu.c: Remove <grub/script.h>, add <grub/command.h>.
(grub_menu_execute_entry): Replace grub_script_execute with
grub_parser_execute, change parameter to grub_command_execute.
* normal/menu_text.c: Remove <grub/script.h>.
* normal/menu_entry.c: Remove <grub/script.h>, add <grub/command.h>
and <grub/parser.h>.
(run): Change editor_getline to use new parser interface. Change
parameter to grub_command_execute.
* kern/main.c: Remove <grub/rescue.h>, include <grub/command.h>,
<grub/reader.h> and <grub/parser.h>.
(grub_load_normal_mode): Execute normal command.
(grub_main): Call grub_register_core_commands,
grub_register_rescue_parser and grub_register_rescue_reader, use
grub_reader_loop to enter input loop.
* kern/parser.c (grub_parser_spli_cmdline): Change type of getline
parameter.
(grub_parser_class): New variable.
(grub_parser_execute): New function.
* loader/i386/multiboot.c: Remove <grub/rescue.h>.
* loader/multiboot2.c: Likewise.
* loader/sparc64/ieee1275/linux.c: Likewise.
* util/grub-emu.c (read_command_list): New dummy function.
2009-05-02 19:49:34 +00:00
|
|
|
#include <grub/normal.h>
|
2010-06-10 06:42:03 +00:00
|
|
|
#include <grub/extcmd.h>
|
2012-02-12 14:25:25 +00:00
|
|
|
#include <grub/i18n.h>
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2010-01-26 07:02:24 +00:00
|
|
|
/* Max digits for a char is 3 (0xFF is 255), similarly for an int it
|
|
|
|
is sizeof (int) * 3, and one extra for a possible -ve sign. */
|
|
|
|
#define ERRNO_DIGITS_MAX (sizeof (int) * 3 + 1)
|
|
|
|
|
2010-05-05 10:49:31 +00:00
|
|
|
static unsigned long is_continue;
|
2010-05-05 10:04:26 +00:00
|
|
|
static unsigned long active_loops;
|
|
|
|
static unsigned long active_breaks;
|
2010-08-25 14:05:52 +00:00
|
|
|
static unsigned long function_return;
|
2010-05-12 12:29:09 +00:00
|
|
|
|
2010-08-15 06:32:33 +00:00
|
|
|
#define GRUB_SCRIPT_SCOPE_MALLOCED 1
|
|
|
|
#define GRUB_SCRIPT_SCOPE_ARGS_MALLOCED 2
|
2010-05-12 12:29:09 +00:00
|
|
|
|
2010-05-11 05:22:10 +00:00
|
|
|
/* Scope for grub script functions. */
|
|
|
|
struct grub_script_scope
|
|
|
|
{
|
2010-08-15 06:32:33 +00:00
|
|
|
unsigned flags;
|
|
|
|
unsigned shifts;
|
2010-05-12 04:49:12 +00:00
|
|
|
struct grub_script_argv argv;
|
2010-05-11 05:22:10 +00:00
|
|
|
};
|
2010-05-05 09:17:50 +00:00
|
|
|
static struct grub_script_scope *scope = 0;
|
|
|
|
|
2010-07-29 18:02:56 +00:00
|
|
|
/* Wildcard translator for GRUB script. */
|
2010-09-03 15:05:23 +00:00
|
|
|
struct grub_script_wildcard_translator *grub_wildcard_translator;
|
2010-07-29 18:02:56 +00:00
|
|
|
|
2010-08-15 06:32:33 +00:00
|
|
|
static void
|
|
|
|
replace_scope (struct grub_script_scope *new_scope)
|
|
|
|
{
|
|
|
|
if (scope)
|
|
|
|
{
|
|
|
|
scope->argv.argc += scope->shifts;
|
|
|
|
scope->argv.args -= scope->shifts;
|
|
|
|
|
|
|
|
if (scope->flags & GRUB_SCRIPT_SCOPE_ARGS_MALLOCED)
|
|
|
|
grub_script_argv_free (&scope->argv);
|
|
|
|
|
|
|
|
if (scope->flags & GRUB_SCRIPT_SCOPE_MALLOCED)
|
|
|
|
grub_free (scope);
|
|
|
|
}
|
|
|
|
scope = new_scope;
|
|
|
|
}
|
|
|
|
|
2010-05-07 04:38:09 +00:00
|
|
|
grub_err_t
|
2010-05-05 10:49:31 +00:00
|
|
|
grub_script_break (grub_command_t cmd, int argc, char *argv[])
|
2010-05-05 10:04:26 +00:00
|
|
|
{
|
|
|
|
char *p = 0;
|
|
|
|
unsigned long count;
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
count = 1;
|
2012-02-12 20:33:48 +00:00
|
|
|
else if (argc > 1)
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count = grub_strtoul (argv[0], &p, 10);
|
|
|
|
if (grub_errno)
|
|
|
|
return grub_errno;
|
|
|
|
if (*p != '\0')
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("unrecognized number"));
|
|
|
|
if (count == 0)
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't break 0 loops"));
|
|
|
|
}
|
2010-05-05 10:04:26 +00:00
|
|
|
|
2010-05-05 10:49:31 +00:00
|
|
|
is_continue = grub_strcmp (cmd->name, "break") ? 1 : 0;
|
2012-01-14 14:44:34 +00:00
|
|
|
active_breaks = count;
|
|
|
|
if (active_breaks > active_loops)
|
|
|
|
active_breaks = active_loops;
|
2010-05-05 10:04:26 +00:00
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2010-06-13 04:18:47 +00:00
|
|
|
grub_err_t
|
|
|
|
grub_script_shift (grub_command_t cmd __attribute__((unused)),
|
|
|
|
int argc, char *argv[])
|
2010-05-07 04:38:09 +00:00
|
|
|
{
|
|
|
|
char *p = 0;
|
|
|
|
unsigned long n = 0;
|
|
|
|
|
|
|
|
if (! scope)
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
n = 1;
|
2010-05-12 12:05:07 +00:00
|
|
|
|
2010-05-07 04:38:09 +00:00
|
|
|
else if (argc > 1)
|
|
|
|
return GRUB_ERR_BAD_ARGUMENT;
|
2010-05-12 12:05:07 +00:00
|
|
|
|
2010-05-07 04:38:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
n = grub_strtoul (argv[0], &p, 10);
|
2010-05-12 12:13:49 +00:00
|
|
|
if (*p != '\0')
|
2010-05-07 04:38:09 +00:00
|
|
|
return GRUB_ERR_BAD_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2010-05-12 12:13:49 +00:00
|
|
|
if (n > scope->argv.argc)
|
|
|
|
return GRUB_ERR_BAD_ARGUMENT;
|
|
|
|
|
2010-08-15 06:32:33 +00:00
|
|
|
scope->shifts += n;
|
2010-05-12 12:05:07 +00:00
|
|
|
scope->argv.argc -= n;
|
|
|
|
scope->argv.args += n;
|
2010-05-07 04:38:09 +00:00
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2010-08-15 06:32:33 +00:00
|
|
|
grub_err_t
|
|
|
|
grub_script_setparams (grub_command_t cmd __attribute__((unused)),
|
|
|
|
int argc, char **args)
|
|
|
|
{
|
|
|
|
struct grub_script_scope *new_scope;
|
2010-09-04 05:26:23 +00:00
|
|
|
struct grub_script_argv argv = { 0, 0, 0 };
|
2010-08-15 06:32:33 +00:00
|
|
|
|
|
|
|
if (! scope)
|
|
|
|
return GRUB_ERR_INVALID_COMMAND;
|
|
|
|
|
|
|
|
new_scope = grub_malloc (sizeof (*new_scope));
|
|
|
|
if (! new_scope)
|
|
|
|
return grub_errno;
|
|
|
|
|
|
|
|
if (grub_script_argv_make (&argv, argc, args))
|
|
|
|
{
|
|
|
|
grub_free (new_scope);
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_scope->shifts = 0;
|
|
|
|
new_scope->argv = argv;
|
|
|
|
new_scope->flags = GRUB_SCRIPT_SCOPE_MALLOCED |
|
|
|
|
GRUB_SCRIPT_SCOPE_ARGS_MALLOCED;
|
|
|
|
|
|
|
|
replace_scope (new_scope);
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2010-08-25 14:05:52 +00:00
|
|
|
grub_err_t
|
|
|
|
grub_script_return (grub_command_t cmd __attribute__((unused)),
|
|
|
|
int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
unsigned long n;
|
|
|
|
|
|
|
|
if (! scope || argc > 1)
|
2012-02-12 14:25:25 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
2012-02-26 16:28:05 +00:00
|
|
|
/* TRANSLATORS: it's about not being
|
|
|
|
inside a function. */
|
2012-03-04 11:14:33 +00:00
|
|
|
N_("not in function body"));
|
2010-08-25 14:05:52 +00:00
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
{
|
2012-02-04 11:21:21 +00:00
|
|
|
const char *t;
|
2010-08-25 14:05:52 +00:00
|
|
|
function_return = 1;
|
2012-02-04 10:52:10 +00:00
|
|
|
t = grub_env_get ("?");
|
|
|
|
if (!t)
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
return grub_strtoul (t, NULL, 10);
|
2010-08-25 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n = grub_strtoul (argv[0], &p, 10);
|
2012-02-12 20:33:48 +00:00
|
|
|
if (grub_errno)
|
|
|
|
return grub_errno;
|
2010-08-25 14:05:52 +00:00
|
|
|
if (*p != '\0')
|
2012-02-12 20:33:48 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
|
|
|
N_("unrecognized number"));
|
2010-08-25 14:05:52 +00:00
|
|
|
|
|
|
|
function_return = 1;
|
2012-02-12 20:33:48 +00:00
|
|
|
return n ? grub_error (n, N_("false")) : GRUB_ERR_NONE;
|
2010-08-25 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
static int
|
|
|
|
grub_env_special (const char *name)
|
2010-05-05 09:17:50 +00:00
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
if (grub_isdigit (name[0]) ||
|
|
|
|
grub_strcmp (name, "#") == 0 ||
|
|
|
|
grub_strcmp (name, "*") == 0 ||
|
|
|
|
grub_strcmp (name, "@") == 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-05 09:17:50 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
static char **
|
|
|
|
grub_script_env_get (const char *name, grub_script_arg_type_t type)
|
|
|
|
{
|
2010-08-15 06:32:33 +00:00
|
|
|
unsigned i;
|
2010-06-10 06:42:03 +00:00
|
|
|
struct grub_script_argv result = { 0, 0, 0 };
|
2010-05-05 09:17:50 +00:00
|
|
|
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
if (! grub_env_special (name))
|
2010-05-05 09:17:50 +00:00
|
|
|
{
|
2011-11-11 19:34:37 +00:00
|
|
|
const char *v = grub_env_get (name);
|
2010-05-12 04:49:12 +00:00
|
|
|
if (v && v[0])
|
2010-05-05 09:17:50 +00:00
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
2010-05-21 10:13:24 +00:00
|
|
|
{
|
|
|
|
if (grub_script_argv_split_append (&result, v))
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
else
|
2011-11-11 19:34:37 +00:00
|
|
|
if (grub_script_argv_append (&result, v, grub_strlen (v)))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
2010-05-05 09:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
else if (! scope)
|
2010-05-21 10:13:24 +00:00
|
|
|
{
|
2011-11-11 19:34:37 +00:00
|
|
|
if (grub_script_argv_append (&result, 0, 0))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-05 09:17:50 +00:00
|
|
|
else if (grub_strcmp (name, "#") == 0)
|
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
char buffer[ERRNO_DIGITS_MAX + 1];
|
|
|
|
grub_snprintf (buffer, sizeof (buffer), "%u", scope->argv.argc);
|
2011-11-11 19:34:37 +00:00
|
|
|
if (grub_script_argv_append (&result, buffer, grub_strlen (buffer)))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
else if (grub_strcmp (name, "*") == 0)
|
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
for (i = 0; i < scope->argv.argc; i++)
|
2010-05-12 04:49:12 +00:00
|
|
|
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (i != 0 && grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (grub_script_argv_split_append (&result, scope->argv.args[i]))
|
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-11 19:34:37 +00:00
|
|
|
if (i != 0 && grub_script_argv_append (&result, " ", 1))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
|
|
|
|
2011-11-11 19:34:37 +00:00
|
|
|
if (grub_script_argv_append (&result, scope->argv.args[i],
|
|
|
|
grub_strlen (scope->argv.args[i])))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (grub_strcmp (name, "@") == 0)
|
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
for (i = 0; i < scope->argv.argc; i++)
|
2010-05-12 04:49:12 +00:00
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (i != 0 && grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
|
|
|
|
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
2010-05-21 10:13:24 +00:00
|
|
|
{
|
|
|
|
if (grub_script_argv_split_append (&result, scope->argv.args[i]))
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
else
|
2011-11-11 19:34:37 +00:00
|
|
|
if (grub_script_argv_append (&result, scope->argv.args[i],
|
|
|
|
grub_strlen (scope->argv.args[i])))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
2010-05-05 09:17:50 +00:00
|
|
|
}
|
|
|
|
else
|
2010-05-12 04:49:12 +00:00
|
|
|
{
|
|
|
|
unsigned long num = grub_strtoul (name, 0, 10);
|
|
|
|
if (num == 0)
|
|
|
|
; /* XXX no file name, for now. */
|
|
|
|
|
|
|
|
else if (num <= scope->argv.argc)
|
|
|
|
{
|
|
|
|
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
2010-05-21 10:13:24 +00:00
|
|
|
{
|
|
|
|
if (grub_script_argv_split_append (&result,
|
|
|
|
scope->argv.args[num - 1]))
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
else
|
2011-11-11 19:34:37 +00:00
|
|
|
if (grub_script_argv_append (&result, scope->argv.args[num - 1],
|
|
|
|
grub_strlen (scope->argv.args[num - 1])
|
|
|
|
))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-12 05:15:22 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
return result.args;
|
2010-05-21 10:13:24 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
grub_script_argv_free (&result);
|
|
|
|
return 0;
|
2010-05-05 09:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_script_env_set (const char *name, const char *val)
|
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
if (grub_env_special (name))
|
2012-02-12 14:25:25 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
|
|
|
N_("invalid variable name `%s'"), name);
|
2010-05-05 09:17:50 +00:00
|
|
|
|
|
|
|
return grub_env_set (name, val);
|
|
|
|
}
|
|
|
|
|
2010-07-29 17:22:09 +00:00
|
|
|
/* Convert arguments in ARGLIST into ARGV form. */
|
2010-05-12 04:49:12 +00:00
|
|
|
static int
|
|
|
|
grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
|
|
|
|
struct grub_script_argv *argv)
|
2010-01-22 13:37:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
2010-05-12 04:49:12 +00:00
|
|
|
char **values = 0;
|
|
|
|
struct grub_script_arg *arg = 0;
|
2010-06-10 06:42:03 +00:00
|
|
|
struct grub_script_argv result = { 0, 0, 0 };
|
2010-05-12 04:49:12 +00:00
|
|
|
|
2012-02-26 18:02:46 +00:00
|
|
|
auto int append (const char *s, int escape_type);
|
|
|
|
int append (const char *s, int escape_type)
|
2010-07-29 17:22:09 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
char *p = 0;
|
|
|
|
|
2010-09-03 15:05:23 +00:00
|
|
|
if (! grub_wildcard_translator || escape_type == 0)
|
2011-11-11 19:34:37 +00:00
|
|
|
return grub_script_argv_append (&result, s, grub_strlen (s));
|
2010-07-29 17:22:09 +00:00
|
|
|
|
|
|
|
if (escape_type > 0)
|
2010-09-03 15:05:23 +00:00
|
|
|
p = grub_wildcard_translator->escape (s);
|
2010-07-29 17:22:09 +00:00
|
|
|
else if (escape_type < 0)
|
2010-09-03 15:05:23 +00:00
|
|
|
p = grub_wildcard_translator->unescape (s);
|
2010-07-29 17:22:09 +00:00
|
|
|
|
|
|
|
if (! p)
|
|
|
|
return 1;
|
|
|
|
|
2011-11-11 19:34:37 +00:00
|
|
|
r = grub_script_argv_append (&result, p, grub_strlen (p));
|
2010-07-29 17:22:09 +00:00
|
|
|
grub_free (p);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-05-21 10:13:24 +00:00
|
|
|
for (; arglist && arglist->arg; arglist = arglist->next)
|
2005-11-06 22:19:59 +00:00
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
|
2010-01-22 13:37:27 +00:00
|
|
|
arg = arglist->arg;
|
|
|
|
while (arg)
|
2005-11-06 22:19:59 +00:00
|
|
|
{
|
2010-01-22 13:37:27 +00:00
|
|
|
switch (arg->type)
|
|
|
|
{
|
|
|
|
case GRUB_SCRIPT_ARG_TYPE_VAR:
|
2010-05-12 04:49:12 +00:00
|
|
|
case GRUB_SCRIPT_ARG_TYPE_DQVAR:
|
|
|
|
values = grub_script_env_get (arg->str, arg->type);
|
|
|
|
for (i = 0; values && values[i]; i++)
|
2010-01-22 13:37:27 +00:00
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (i != 0 && grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
2010-05-18 15:33:35 +00:00
|
|
|
|
|
|
|
if (arg->type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
2010-05-21 10:45:09 +00:00
|
|
|
{
|
2011-11-11 19:34:37 +00:00
|
|
|
if (grub_script_argv_append (&result, values[i],
|
|
|
|
grub_strlen (values[i])))
|
2010-05-21 10:45:09 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-18 15:33:35 +00:00
|
|
|
else
|
2010-05-21 10:45:09 +00:00
|
|
|
{
|
2010-07-29 17:22:09 +00:00
|
|
|
if (append (values[i], 1))
|
2010-05-21 10:45:09 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-18 15:33:35 +00:00
|
|
|
|
|
|
|
grub_free (values[i]);
|
2010-01-22 13:37:27 +00:00
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_free (values);
|
2010-01-22 13:37:27 +00:00
|
|
|
break;
|
|
|
|
|
2010-04-30 06:39:31 +00:00
|
|
|
case GRUB_SCRIPT_ARG_TYPE_BLOCK:
|
2011-11-11 19:34:37 +00:00
|
|
|
if (grub_script_argv_append (&result, "{", 1)
|
|
|
|
|| grub_script_argv_append (&result, arg->str,
|
|
|
|
grub_strlen (arg->str))
|
|
|
|
|| grub_script_argv_append (&result, "}", 1))
|
2010-06-10 06:42:03 +00:00
|
|
|
goto fail;
|
2010-08-09 16:12:24 +00:00
|
|
|
result.script = arg->script;
|
2010-06-10 06:42:03 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-22 13:37:27 +00:00
|
|
|
case GRUB_SCRIPT_ARG_TYPE_TEXT:
|
2012-02-26 18:02:46 +00:00
|
|
|
if (arg->str[0] &&
|
2011-11-11 19:34:37 +00:00
|
|
|
grub_script_argv_append (&result, arg->str,
|
|
|
|
grub_strlen (arg->str)))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
2010-01-22 13:37:27 +00:00
|
|
|
break;
|
|
|
|
|
2012-02-26 18:02:46 +00:00
|
|
|
case GRUB_SCRIPT_ARG_TYPE_GETTEXT:
|
|
|
|
{
|
|
|
|
const char *t = _(arg->str);
|
|
|
|
if (grub_script_argv_append (&result, t, grub_strlen (t)))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-01-22 13:37:27 +00:00
|
|
|
case GRUB_SCRIPT_ARG_TYPE_DQSTR:
|
|
|
|
case GRUB_SCRIPT_ARG_TYPE_SQSTR:
|
2010-11-07 10:43:14 +00:00
|
|
|
if (append (arg->str, 1))
|
2010-05-21 10:13:24 +00:00
|
|
|
goto fail;
|
2010-01-22 13:37:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
arg = arg->next;
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
if (! result.args[result.argc - 1])
|
|
|
|
result.argc--;
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2010-07-29 17:22:09 +00:00
|
|
|
/* Perform wildcard expansion. */
|
|
|
|
|
2010-09-03 15:05:23 +00:00
|
|
|
if (grub_wildcard_translator)
|
2010-07-29 17:22:09 +00:00
|
|
|
{
|
|
|
|
int j;
|
|
|
|
int failed = 0;
|
|
|
|
char **expansions = 0;
|
|
|
|
struct grub_script_argv unexpanded = result;
|
|
|
|
|
|
|
|
result.argc = 0;
|
|
|
|
result.args = 0;
|
|
|
|
for (i = 0; unexpanded.args[i]; i++)
|
|
|
|
{
|
2010-09-03 15:05:23 +00:00
|
|
|
if (grub_wildcard_translator->expand (unexpanded.args[i],
|
|
|
|
&expansions))
|
2010-07-29 17:22:09 +00:00
|
|
|
{
|
|
|
|
grub_script_argv_free (&unexpanded);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! expansions)
|
|
|
|
{
|
|
|
|
grub_script_argv_next (&result);
|
|
|
|
append (unexpanded.args[i], -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (j = 0; expansions[j]; j++)
|
|
|
|
{
|
|
|
|
failed = (failed || grub_script_argv_next (&result) ||
|
|
|
|
append (expansions[j], -1));
|
|
|
|
grub_free (expansions[j]);
|
|
|
|
}
|
|
|
|
grub_free (expansions);
|
|
|
|
|
|
|
|
if (failed)
|
|
|
|
{
|
|
|
|
grub_script_argv_free (&unexpanded);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grub_script_argv_free (&unexpanded);
|
|
|
|
}
|
2010-05-18 15:33:35 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
*argv = result;
|
|
|
|
return 0;
|
2010-05-21 10:13:24 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
grub_script_argv_free (&result);
|
|
|
|
return 1;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_script_execute_cmd (struct grub_script_cmd *cmd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char errnobuf[ERRNO_DIGITS_MAX + 1];
|
|
|
|
|
|
|
|
if (cmd == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = cmd->exec (cmd);
|
2010-01-23 03:42:46 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
|
|
|
|
grub_env_set ("?", errnobuf);
|
|
|
|
return ret;
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 09:17:50 +00:00
|
|
|
/* Execute a function call. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_function_call (grub_script_function_t func, int argc, char **args)
|
|
|
|
{
|
|
|
|
grub_err_t ret = 0;
|
2010-05-05 10:04:26 +00:00
|
|
|
unsigned long loops = active_loops;
|
2010-05-11 05:22:10 +00:00
|
|
|
struct grub_script_scope *old_scope;
|
2010-05-05 09:17:50 +00:00
|
|
|
struct grub_script_scope new_scope;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops = 0;
|
2010-08-15 06:32:33 +00:00
|
|
|
new_scope.flags = 0;
|
|
|
|
new_scope.shifts = 0;
|
2010-05-12 04:49:12 +00:00
|
|
|
new_scope.argv.argc = argc;
|
|
|
|
new_scope.argv.args = args;
|
2010-05-11 05:22:10 +00:00
|
|
|
|
|
|
|
old_scope = scope;
|
|
|
|
scope = &new_scope;
|
2010-05-05 09:17:50 +00:00
|
|
|
|
|
|
|
ret = grub_script_execute (func->func);
|
|
|
|
|
2010-08-25 14:05:52 +00:00
|
|
|
function_return = 0;
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops = loops;
|
2010-08-15 06:32:33 +00:00
|
|
|
replace_scope (old_scope); /* free any scopes by setparams */
|
2010-05-05 09:17:50 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-07-22 15:45:14 +00:00
|
|
|
/* Execute a source script. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_sourcecode (const char *source, int argc, char **args)
|
|
|
|
{
|
|
|
|
grub_err_t ret = 0;
|
|
|
|
struct grub_script *parsed_script;
|
|
|
|
struct grub_script_scope new_scope;
|
|
|
|
struct grub_script_scope *old_scope;
|
|
|
|
|
|
|
|
auto grub_err_t getline (char **line, int cont);
|
|
|
|
grub_err_t getline (char **line, int cont __attribute__ ((unused)))
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
if (! source)
|
|
|
|
{
|
|
|
|
*line = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = grub_strchr (source, '\n');
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
*line = grub_strndup (source, p - source);
|
|
|
|
else
|
|
|
|
*line = grub_strdup (source);
|
|
|
|
source = p ? p + 1 : 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_scope.argv.argc = argc;
|
|
|
|
new_scope.argv.args = args;
|
2010-09-30 18:59:20 +00:00
|
|
|
new_scope.flags = 0;
|
2010-07-22 15:45:14 +00:00
|
|
|
|
|
|
|
old_scope = scope;
|
|
|
|
scope = &new_scope;
|
|
|
|
|
|
|
|
while (source)
|
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
getline (&line, 0);
|
|
|
|
parsed_script = grub_script_parse (line, getline);
|
|
|
|
if (! parsed_script)
|
|
|
|
{
|
|
|
|
ret = grub_errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = grub_script_execute (parsed_script);
|
|
|
|
grub_free (line);
|
|
|
|
}
|
|
|
|
|
2010-05-11 05:22:10 +00:00
|
|
|
scope = old_scope;
|
2010-05-05 09:17:50 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-11-06 22:19:59 +00:00
|
|
|
/* Execute a single command line. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct grub_script_cmdline *cmdline = (struct grub_script_cmdline *) cmd;
|
|
|
|
grub_command_t grubcmd;
|
|
|
|
grub_err_t ret = 0;
|
|
|
|
grub_script_function_t func = 0;
|
2009-12-29 09:04:06 +00:00
|
|
|
char errnobuf[18];
|
2009-06-04 16:18:35 +00:00
|
|
|
char *cmdname;
|
2010-09-05 09:27:28 +00:00
|
|
|
int argc;
|
|
|
|
char **args;
|
|
|
|
int invert;
|
2010-06-10 06:42:03 +00:00
|
|
|
struct grub_script_argv argv = { 0, 0, 0 };
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Lookup the command. */
|
2010-08-10 04:22:16 +00:00
|
|
|
if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0])
|
2010-01-22 13:37:27 +00:00
|
|
|
return grub_errno;
|
|
|
|
|
2010-09-05 09:27:28 +00:00
|
|
|
invert = 0;
|
|
|
|
argc = argv.argc - 1;
|
|
|
|
args = argv.args + 1;
|
2010-05-12 04:49:12 +00:00
|
|
|
cmdname = argv.args[0];
|
2010-09-05 09:27:28 +00:00
|
|
|
if (grub_strcmp (cmdname, "!") == 0)
|
|
|
|
{
|
|
|
|
if (argv.argc < 2 || ! argv.args[1])
|
|
|
|
{
|
|
|
|
grub_script_argv_free (&argv);
|
2012-02-12 14:25:25 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
|
|
|
N_("no command is specified"));
|
2010-09-05 09:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
invert = 1;
|
|
|
|
argc = argv.argc - 2;
|
|
|
|
args = argv.args + 2;
|
|
|
|
cmdname = argv.args[1];
|
|
|
|
}
|
2009-06-04 16:18:35 +00:00
|
|
|
grubcmd = grub_command_find (cmdname);
|
2005-11-06 22:19:59 +00:00
|
|
|
if (! grubcmd)
|
|
|
|
{
|
2008-01-15 15:32:17 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
2005-11-06 22:19:59 +00:00
|
|
|
/* It's not a GRUB command, try all functions. */
|
2009-06-04 16:18:35 +00:00
|
|
|
func = grub_script_function_find (cmdname);
|
2005-11-06 22:19:59 +00:00
|
|
|
if (! func)
|
2006-04-30 20:29:51 +00:00
|
|
|
{
|
|
|
|
/* As a last resort, try if it is an assignment. */
|
2009-06-04 16:18:35 +00:00
|
|
|
char *assign = grub_strdup (cmdname);
|
2006-04-30 20:29:51 +00:00
|
|
|
char *eq = grub_strchr (assign, '=');
|
|
|
|
|
|
|
|
if (eq)
|
|
|
|
{
|
2009-12-13 12:35:20 +00:00
|
|
|
/* This was set because the command was not found. */
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
2006-04-30 20:29:51 +00:00
|
|
|
/* Create two strings and set the variable. */
|
|
|
|
*eq = '\0';
|
|
|
|
eq++;
|
2010-05-05 09:17:50 +00:00
|
|
|
grub_script_env_set (assign, eq);
|
2006-04-30 20:29:51 +00:00
|
|
|
}
|
|
|
|
grub_free (assign);
|
2009-09-08 19:10:34 +00:00
|
|
|
|
2009-12-29 09:04:06 +00:00
|
|
|
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
|
2010-05-05 09:17:50 +00:00
|
|
|
grub_script_env_set ("?", errnobuf);
|
2009-09-08 19:10:34 +00:00
|
|
|
|
2010-05-18 15:33:35 +00:00
|
|
|
grub_script_argv_free (&argv);
|
2010-02-14 13:46:19 +00:00
|
|
|
grub_print_error ();
|
|
|
|
|
2006-04-30 20:29:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute the GRUB command or function. */
|
|
|
|
if (grubcmd)
|
2010-06-10 06:42:03 +00:00
|
|
|
{
|
2010-09-20 21:01:34 +00:00
|
|
|
if (grub_extractor_level && !(grubcmd->flags
|
|
|
|
& GRUB_COMMAND_FLAG_EXTRACTOR))
|
|
|
|
ret = grub_error (GRUB_ERR_EXTRACTOR,
|
|
|
|
"%s isn't allowed to execute in an extractor",
|
2010-09-16 21:48:32 +00:00
|
|
|
cmdname);
|
|
|
|
else if ((grubcmd->flags & GRUB_COMMAND_FLAG_BLOCKS) &&
|
|
|
|
(grubcmd->flags & GRUB_COMMAND_FLAG_EXTCMD))
|
2010-09-05 09:27:28 +00:00
|
|
|
ret = grub_extcmd_dispatcher (grubcmd, argc, args, argv.script);
|
2010-06-10 06:42:03 +00:00
|
|
|
else
|
2010-09-05 09:27:28 +00:00
|
|
|
ret = (grubcmd->func) (grubcmd, argc, args);
|
2010-06-10 06:42:03 +00:00
|
|
|
}
|
2005-11-06 22:19:59 +00:00
|
|
|
else
|
2010-09-05 09:27:28 +00:00
|
|
|
ret = grub_script_function_call (func, argc, args);
|
|
|
|
|
|
|
|
if (invert)
|
2010-09-07 16:16:04 +00:00
|
|
|
{
|
|
|
|
if (ret == GRUB_ERR_TEST_FAILURE)
|
|
|
|
grub_errno = ret = GRUB_ERR_NONE;
|
|
|
|
else if (ret == GRUB_ERR_NONE)
|
2012-02-12 14:25:25 +00:00
|
|
|
ret = grub_error (GRUB_ERR_TEST_FAILURE, N_("false"));
|
2010-09-07 16:16:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
2010-09-08 03:51:02 +00:00
|
|
|
ret = GRUB_ERR_NONE;
|
2010-09-07 16:16:04 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Free arguments. */
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_script_argv_free (&argv);
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2010-02-10 17:09:44 +00:00
|
|
|
if (grub_errno == GRUB_ERR_TEST_FAILURE)
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
|
|
|
grub_print_error ();
|
|
|
|
|
2009-12-29 09:04:06 +00:00
|
|
|
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
|
2005-11-06 22:19:59 +00:00
|
|
|
grub_env_set ("?", errnobuf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-31 09:15:43 +00:00
|
|
|
/* Execute a block of one or more commands. */
|
2005-11-06 22:19:59 +00:00
|
|
|
grub_err_t
|
2010-05-05 08:35:06 +00:00
|
|
|
grub_script_execute_cmdlist (struct grub_script_cmd *list)
|
2005-11-06 22:19:59 +00:00
|
|
|
{
|
2010-01-26 07:02:24 +00:00
|
|
|
int ret = 0;
|
2010-05-05 08:35:06 +00:00
|
|
|
struct grub_script_cmd *cmd;
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Loop over every command and execute it. */
|
2010-08-25 14:05:52 +00:00
|
|
|
for (cmd = list->next; cmd; cmd = cmd->next)
|
|
|
|
{
|
|
|
|
if (active_breaks)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret = grub_script_execute_cmd (cmd);
|
|
|
|
|
|
|
|
if (function_return)
|
|
|
|
break;
|
|
|
|
}
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2010-01-26 07:02:24 +00:00
|
|
|
return ret;
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute an if statement. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_cmdif (struct grub_script_cmd *cmd)
|
|
|
|
{
|
2010-08-25 14:05:52 +00:00
|
|
|
int ret;
|
2011-11-11 19:34:37 +00:00
|
|
|
const char *result;
|
2010-08-25 14:05:52 +00:00
|
|
|
struct grub_script_cmdif *cmdif = (struct grub_script_cmdif *) cmd;
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Check if the commands results in a true or a false. The value is
|
2006-05-28 21:58:35 +00:00
|
|
|
read from the env variable `?'. */
|
2010-08-25 14:05:52 +00:00
|
|
|
ret = grub_script_execute_cmd (cmdif->exec_to_evaluate);
|
|
|
|
if (function_return)
|
|
|
|
return ret;
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2010-08-25 14:05:52 +00:00
|
|
|
result = grub_env_get ("?");
|
2009-05-03 06:50:20 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
2005-11-06 22:19:59 +00:00
|
|
|
/* Execute the `if' or the `else' part depending on the value of
|
2006-05-28 21:58:35 +00:00
|
|
|
`?'. */
|
|
|
|
if (result && ! grub_strcmp (result, "0"))
|
|
|
|
return grub_script_execute_cmd (cmdif->exec_on_true);
|
2005-11-06 22:19:59 +00:00
|
|
|
else
|
2006-05-28 21:58:35 +00:00
|
|
|
return grub_script_execute_cmd (cmdif->exec_on_false);
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
|
2010-01-23 05:33:41 +00:00
|
|
|
/* Execute a for statement. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_cmdfor (struct grub_script_cmd *cmd)
|
|
|
|
{
|
2010-05-19 04:55:41 +00:00
|
|
|
unsigned i;
|
|
|
|
grub_err_t result;
|
2010-06-10 06:42:03 +00:00
|
|
|
struct grub_script_argv argv = { 0, 0, 0 };
|
2010-01-23 05:33:41 +00:00
|
|
|
struct grub_script_cmdfor *cmdfor = (struct grub_script_cmdfor *) cmd;
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
if (grub_script_arglist_to_argv (cmdfor->words, &argv))
|
2010-01-23 05:33:41 +00:00
|
|
|
return grub_errno;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops++;
|
2010-01-23 05:33:41 +00:00
|
|
|
result = 0;
|
2010-05-12 04:49:12 +00:00
|
|
|
for (i = 0; i < argv.argc; i++)
|
2010-01-23 05:33:41 +00:00
|
|
|
{
|
2010-05-05 10:49:31 +00:00
|
|
|
if (is_continue && active_breaks == 1)
|
|
|
|
active_breaks = 0;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
if (! active_breaks)
|
|
|
|
{
|
2010-05-12 12:29:09 +00:00
|
|
|
grub_script_env_set (cmdfor->name->str, argv.args[i]);
|
2010-05-05 10:04:26 +00:00
|
|
|
result = grub_script_execute_cmd (cmdfor->list);
|
2010-08-25 14:05:52 +00:00
|
|
|
if (function_return)
|
|
|
|
break;
|
2010-05-05 10:04:26 +00:00
|
|
|
}
|
2010-01-23 05:33:41 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
if (active_breaks)
|
|
|
|
active_breaks--;
|
|
|
|
|
|
|
|
active_loops--;
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_script_argv_free (&argv);
|
2010-01-23 05:33:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-23 05:49:26 +00:00
|
|
|
/* Execute a "while" or "until" command. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_cmdwhile (struct grub_script_cmd *cmd)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
struct grub_script_cmdwhile *cmdwhile = (struct grub_script_cmdwhile *) cmd;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops++;
|
2010-01-23 05:49:26 +00:00
|
|
|
do {
|
2010-08-25 14:05:52 +00:00
|
|
|
result = grub_script_execute_cmd (cmdwhile->cond);
|
|
|
|
if (function_return)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (cmdwhile->until ? !result : result)
|
2010-01-23 05:49:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
result = grub_script_execute_cmd (cmdwhile->list);
|
2010-08-25 14:05:52 +00:00
|
|
|
if (function_return)
|
|
|
|
break;
|
2010-05-05 10:04:26 +00:00
|
|
|
|
2010-05-05 10:49:31 +00:00
|
|
|
if (active_breaks == 1 && is_continue)
|
|
|
|
active_breaks = 0;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
if (active_breaks)
|
2010-05-05 10:49:31 +00:00
|
|
|
break;
|
2010-05-05 10:04:26 +00:00
|
|
|
|
2010-01-23 05:49:26 +00:00
|
|
|
} while (1); /* XXX Put a check for ^C here */
|
|
|
|
|
2010-05-05 10:49:31 +00:00
|
|
|
if (active_breaks)
|
|
|
|
active_breaks--;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops--;
|
2010-01-23 05:49:26 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-11-06 22:19:59 +00:00
|
|
|
/* Execute any GRUB pre-parsed command or script. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute (struct grub_script *script)
|
|
|
|
{
|
|
|
|
if (script == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return grub_script_execute_cmd (script->cmd);
|
|
|
|
}
|
2009-03-21 Bean <bean123ch@gmail.com>
* commands/blocklist.c: Add include file <grub/command.h>, remove
<grub/normal.h> and <grub/arg.h>.
(grub_cmd_blocklist): Use the new command interface.
(GRUB_MOD_INIT): Likewise.
(GRUB_MOD_FINI): Likewise.
* commands/boot.c: Likewise.
* commands/cat.c: Likewise.
* commands/cmp.c: Likewise.
* commands/configfile.c: Likewise.
* commands/crc.c: Likewise.
* commands/echo.c: Likewise.
* commands/halt.c: Likewise.
* commands/handler.c: Likewise.
* commands/hdparm.c: Likewise.
* commands/help.c: Likewise.
* commands/hexdump.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/ls.c: Likewise.
* commands/lsmmap.c: Likewise.
* commands/lspci.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/read.c: Likewise.
* commands/reboot.c: Likewise.
* commands/search.c: Likewise.
* commands/sleep.c: Likewise.
* commands/test.c: Likewise.
* commands/usbtest.c: Likewise.
* commands/videotest.c: Likewise.
* commands/i386/cpuid.c: Likewise.
* commands/i386/pc/halt.c: Likewise.
* commands/i386/pc/play.c: Likewise.
* commands/i386/pc/pxecmd.c: Likewise.
* commands/i386/pc/vbeinfo.c: Likewise.
* commands/i386/pc/vbetest.c: Likewise.
* commands/ieee1275/suspend.c: Likewise.
* disk/loopback.c: Likewise.
* font/font_cmd.c: Likewise.
* hello/hello.c: Likewise.
* loader/efi/appleloader.c: Likewise.
* loader/efi/chainloader.c: Likewise.
* loader/i386/bsd.c: Likewise.
* loader/i386/efi/linux.c: Likewise.
* loader/i386/ieee1275/linux.c: Likewise.
* loader/i386/linux.c: Likewise.
* loader/i386/pc/chainloader.c: Likewise.
* loader/i386/pc/linux.c: Likewise.
* loader/powerpc/ieee1275/linux.c: Likewise.
* loader/multiboot_loader.c: Likewise.
* term/gfxterm.c: Likewise.
* term/i386/pc/serial.c: Likewise.
* term/terminfo.c: Likewise.
* term/i386/pc/vesafb.c: Removed <grub/arg.h>.
* term/i386/pc/vga.c: Likewise.
* video/readers/jpeg.c: Likewise.
* video/readers/png.c: Likewise.
* video/readers/tga.c: Likewise.
* util/grub-fstest (cmd_loopback): Removed.
(cmd_blocklist): Likewise.
(cmd_ls): Likewise.
(grub_register_command): Likewise.
(grub_unregister_command): Likewise.
(execute_command): Use grub_command_find to locate command and execute
it.
* include/grub/efi/chainloader.h: Removed.
* loader/efi/chainloader_normal.c: Likewise.
* loader/i386/bsd_normal.c: Likewise.
* loader/i386/pc/chainloader_normal.c: Likewise.
* loader/i386/pc/multiboot_normal.c: Likewise.
* loader/linux_normal.c: Likewise.
* loader/multiboot_loader_normal.c: Likewise.
* loader/powerpc/ieee1275/linux_normal.c: Likewise.
* gencmdlist.sh: Scan new registration command grub_register_extcmd
and grub_register_command_p1.
* conf/common.rmk (grub_fstest_SOURCES): Add kern/list.c,
kern/command.c, lib/arg.c and commands/extcmd.c.
(pkglib_MODULES): Remove boot.mod, and minicmd.mod and extcmd.mod.
(minicmd_mod_SOURCES): New variable.
(minicmd_mod_CFLAGS): Likewise.
(minicmd_mod_LDFLAGS): Likewise.
(extcmd_mod_SOURCES): Likewise.
(extcmd_mod_CFLAGS): Likewise.
(extcmd_mod_LDFLAGS): Likewise.
(boot_mod_SOURCES): Removed.
(boot_mod_CFLAGS): Likewise.
(boot_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (kernel_img_SOURCES): Add kern/command.c and
kern/corecmd.c.
(kernel_img_HEADERS): Add command.h.
(grub_emu_SOURCES): Remove commands/boot.c and normal/arg.c, add
commands/minicmd.c, kern/command.c, kern/corecmd.c, commands/extcmd.c
and lib/arg.c.
(pkglib_MODULES): Change _linux.mod, _chain.mod, _bsd.mod and
_multiboot.mod as linux.mod, chain.mod, bsd.mod and multiboot.mod,
remove the corresponding normal mode command.
(normal_mod_SOURCES): Remove normal/arg.c.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1275.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/arg.h: Move from here ...
* include/grub/lib/arg.h: ... to here.
* normal/arg.c: Move from here ...
* lib/arg.c: ... to here.
* commands/extcmd.c: New file.
* commands/minicmd.c: Likewise.
* include/grub/command.h: Likewise.
* include/grub/extcmd.h: Likewise.
* kern/command.c: Likewise.
* kern/corecmd.c: Likewise.
* kern/list.c (grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(grub_prio_list_insert): Likewise.
* kern/rescue.c (grub_rescue_command): Removed.
(grub_rescue_command_list): Likewise.
(grub_rescue_register_command): Likewise.
(grub_rescue_unregister_command): Likewise.
(grub_rescue_cmd_boot): Move to minicmd.c
(grub_rescue_cmd_help): Likewise.
(grub_rescue_cmd_info): Likewise.
(grub_rescue_cmd_boot): Likewise.
(grub_rescue_cmd_testload): Likewise.
(grub_rescue_cmd_dump): Likewise.
(grub_rescue_cmd_rmmod): Likewise.
(grub_rescue_cmd_lsmod): Likewise.
(grub_rescue_cmd_exit): Likewise.
(grub_rescue_print_devices): Moved to corecmd.c.
(grub_rescue_print_files): Likewise.
(grub_rescue_cmd_ls): Likewise.
(grub_rescue_cmd_insmod): Likewise.
(grub_rescue_cmd_set): Likewise.
(grub_rescue_cmd_unset): Likewise.
(attemp_normal_mode): Use grub_command_find to get normal module.
(grub_enter_rescue_mode): Use grub_register_core_commands to register
commands, remove grub_rescue_regiter_command calls.
* normal/command.c (grub_regiser_command): Removed.
(grub_unregister_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(rescue_command): Likewise.
(export_command): Moved to corecmd.c.
(set_command): Removed.
(unset_command): Likewise.
(insmod_command): Likewise.
(rmmod_command): Likewise.
(lsmod_command): Likewise.
(grub_command_init): Likewise.
* normal/completion.c (iterate_command): Use cmd->prio to check for
active command.
(complete_arguments): Use grub_extcmd_t structure to find options.
(grub_normal_do_completion): Change function grub_iterate_commands to
grub_command_iterate.
* normal/execute.c (grub_script_execute_cmd): No need to parse
argument here.
* normal/main.c (grub_dyncmd_dispatcher): New function.
(read_command_list): Register unload commands as dyncmd.
(grub_cmd_normal): Use new command interface, register rescue,
unregister normal at entry, register normal, unregister rescue at exit.
* include/grub/list.h (grub_list_test_t): New type.
(grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(GRUB_AS_NAMED_LIST_P): New macro.
(GRUB_AS_PRIO_LIST): Likewise.
(GRUB_AS_PRIO_LIST_P): Likewise.
(GRUB_PRIO_LIST_PRIO_MASK): New constant.
(GRUB_PRIO_LIST_FLAG_ACTIVE): Likewise.
(grub_prio_list): New structure.
(grub_prio_list_insert): New function.
(grub_prio_list_remove): New inline function.
* include/grub/normal.h: Remove <grub/arg.h>, add <grub/command.h>.
(GRUB_COMMAND_FLAG_CMDLINE): Moved to command.h.
(GRUB_COMMAND_FLAG_MENU): Likewise.
(GRUB_COMMAND_FLAG_BOTH): Likewise.
(GRUB_COMMAND_FLAG_TITLE): Likewise.
(GRUB_COMMAND_FLAG_NO_ECHO): Likewise.
(GRUB_COMMAND_FLAG_NO_ARG_PARSE): Removed.
(GRUB_COMMAND_FLAG_NOT_LOADED): Likewise.
(grub_command): Likewise.
(grub_register_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(grub_command_init): Likewise.
(grub_arg_parse): Likewise.
(grub_arg_show_help): Likewise.
* include/grub/rescue.h (grub_rescue_register_command): Removed.
(grub_rescue_unregister_command): Likewise.
* include/grub/i386/bsd.h: Remove grub_rescue_cmd_freebsd,
grub_rescue_cmd_openbsd, grub_rescue_cmd_netbsd,
grub_rescue_cmd_freebsd_loadenv and grub_rescue_cmd_freebsd_module.
* include/grub/i386/efi/loader.h: Remove grub_rescue_cmd_linux and
grub_rescue_cmd_initrd.
* include/grub/i386/loader.h: Likewise.
* include/grub/x86_64/loader.h: Likewise.
* include/grub/i386/pc/chainloader.h: Remove grub_chainloader_cmd.
2009-03-21 08:39:59 +00:00
|
|
|
|