5c67ea6cd9
* grub-core/commands/i386/pc/sendkey.c (grub_cmd_sendkey: find_key_code, find_ascii_code): Make static instead of nested. * grub-core/commands/legacycfg.c (legacy_file: getline): Likewise. Rename to ... (legacy_file_getline): ... this. * grub-core/commands/loadenv.c (grub_cmd_load_env: set_var): Likewise. * grub-core/kern/corecmd.c (grub_core_cmd_set: print_env): Likewise. * grub-core/kern/fs.c (grub_fs_probe: dummy_func): Likewise. Rename to ... (probe_dummy_iter): ... this. * grub-core/kern/i386/coreboot/mmap.c (grub_linuxbios_table_iterate: check_signature): Likewise. * grub-core/kern/parser.c (grub_parser_split_cmdline: check_varstate): Likewise. Mark inline. * grub-core/lib/arg.c (find_short: fnd_short): Likewise. Pass an additional parameter. (find_long: fnd_long): Likewise. Pass two additional parameters. * grub-core/lib/crc.c (init_crc32c_table: reflect): Likewise. * grub-core/lib/crc64.c (init_crc64_table: reflect): Likewise. * grub-core/lib/ieee1275/cmos.c (grub_cmos_find_port: hook): Likewise. Rename to ... (grub_cmos_find_port_iter): ... this. * grub-core/lib/ieee1275/datetime.c (find_rtc: hook): Likewise. Rename to ... (find_rtc_iter): ... this. * grub-core/normal/menu_entry.c (run): Fold nested editor_getsource function directly into the function body, since it is only called once.
194 lines
4.3 KiB
C
194 lines
4.3 KiB
C
/* corecmd.c - critical commands which are registered in kernel */
|
|
/*
|
|
* GRUB -- GRand Unified Bootloader
|
|
* Copyright (C) 2009 Free Software Foundation, Inc.
|
|
*
|
|
* 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/mm.h>
|
|
#include <grub/dl.h>
|
|
#include <grub/err.h>
|
|
#include <grub/env.h>
|
|
#include <grub/misc.h>
|
|
#include <grub/term.h>
|
|
#include <grub/file.h>
|
|
#include <grub/device.h>
|
|
#include <grub/command.h>
|
|
#include <grub/i18n.h>
|
|
|
|
/* Helper for grub_core_cmd_set. */
|
|
static int
|
|
print_env (struct grub_env_var *env)
|
|
{
|
|
grub_printf ("%s=%s\n", env->name, env->value);
|
|
return 0;
|
|
}
|
|
|
|
/* set ENVVAR=VALUE */
|
|
static grub_err_t
|
|
grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)),
|
|
int argc, char *argv[])
|
|
{
|
|
char *var;
|
|
char *val;
|
|
|
|
if (argc < 1)
|
|
{
|
|
grub_env_iterate (print_env);
|
|
return 0;
|
|
}
|
|
|
|
var = argv[0];
|
|
val = grub_strchr (var, '=');
|
|
if (! val)
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "not an assignment");
|
|
|
|
val[0] = 0;
|
|
grub_env_set (var, val + 1);
|
|
val[0] = '=';
|
|
|
|
return 0;
|
|
}
|
|
|
|
static grub_err_t
|
|
grub_core_cmd_unset (struct grub_command *cmd __attribute__ ((unused)),
|
|
int argc, char *argv[])
|
|
{
|
|
if (argc < 1)
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT,
|
|
N_("one argument expected"));
|
|
|
|
grub_env_unset (argv[0]);
|
|
return 0;
|
|
}
|
|
|
|
/* insmod MODULE */
|
|
static grub_err_t
|
|
grub_core_cmd_insmod (struct grub_command *cmd __attribute__ ((unused)),
|
|
int argc, char *argv[])
|
|
{
|
|
grub_dl_t mod;
|
|
|
|
if (argc == 0)
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
|
|
|
|
if (argv[0][0] == '/' || argv[0][0] == '(' || argv[0][0] == '+')
|
|
mod = grub_dl_load_file (argv[0]);
|
|
else
|
|
mod = grub_dl_load (argv[0]);
|
|
|
|
if (mod)
|
|
grub_dl_ref (mod);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
grub_mini_print_devices (const char *name)
|
|
{
|
|
grub_printf ("(%s) ", name);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
grub_mini_print_files (const char *filename,
|
|
const struct grub_dirhook_info *info)
|
|
{
|
|
grub_printf ("%s%s ", filename, info->dir ? "/" : "");
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* ls [ARG] */
|
|
static grub_err_t
|
|
grub_core_cmd_ls (struct grub_command *cmd __attribute__ ((unused)),
|
|
int argc, char *argv[])
|
|
{
|
|
if (argc < 1)
|
|
{
|
|
grub_device_iterate (grub_mini_print_devices);
|
|
grub_xputs ("\n");
|
|
grub_refresh ();
|
|
}
|
|
else
|
|
{
|
|
char *device_name;
|
|
grub_device_t dev = 0;
|
|
grub_fs_t fs;
|
|
char *path;
|
|
|
|
device_name = grub_file_get_device_name (argv[0]);
|
|
if (grub_errno)
|
|
goto fail;
|
|
dev = grub_device_open (device_name);
|
|
if (! dev)
|
|
goto fail;
|
|
|
|
fs = grub_fs_probe (dev);
|
|
path = grub_strchr (argv[0], ')');
|
|
if (! path)
|
|
path = argv[0];
|
|
else
|
|
path++;
|
|
|
|
if (! path && ! device_name)
|
|
{
|
|
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
|
|
goto fail;
|
|
}
|
|
|
|
if (! path)
|
|
{
|
|
if (grub_errno == GRUB_ERR_UNKNOWN_FS)
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
grub_printf ("(%s): Filesystem is %s.\n",
|
|
device_name, fs ? fs->name : "unknown");
|
|
}
|
|
else if (fs)
|
|
{
|
|
(fs->dir) (dev, path, grub_mini_print_files);
|
|
grub_xputs ("\n");
|
|
grub_refresh ();
|
|
}
|
|
|
|
fail:
|
|
if (dev)
|
|
grub_device_close (dev);
|
|
|
|
grub_free (device_name);
|
|
}
|
|
|
|
return grub_errno;
|
|
}
|
|
|
|
void
|
|
grub_register_core_commands (void)
|
|
{
|
|
grub_command_t cmd;
|
|
cmd = grub_register_command ("set", grub_core_cmd_set,
|
|
N_("[ENVVAR=VALUE]"),
|
|
N_("Set an environment variable."));
|
|
if (cmd)
|
|
cmd->flags |= GRUB_COMMAND_FLAG_EXTRACTOR;
|
|
grub_register_command ("unset", grub_core_cmd_unset,
|
|
N_("ENVVAR"),
|
|
N_("Remove an environment variable."));
|
|
grub_register_command ("ls", grub_core_cmd_ls,
|
|
N_("[ARG]"), N_("List devices or files."));
|
|
grub_register_command ("insmod", grub_core_cmd_insmod,
|
|
N_("MODULE"), N_("Insert a module."));
|
|
}
|