1
/* corecmd.c - critical commands which are registered in kernel */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2009 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
24
#include <grub/misc.h>
25
#include <grub/term.h>
26
#include <grub/file.h>
27
#include <grub/device.h>
28
#include <grub/command.h>
30
/* set ENVVAR=VALUE */
32
grub_core_cmd_set (struct grub_command *cmd __attribute__ ((unused)),
33
int argc, char *argv[])
38
auto int print_env (struct grub_env_var *env);
40
int print_env (struct grub_env_var *env)
42
grub_printf ("%s=%s\n", env->name, env->value);
48
grub_env_iterate (print_env);
53
val = grub_strchr (var, '=');
55
return grub_error (GRUB_ERR_BAD_ARGUMENT, "not an assignment");
58
grub_env_set (var, val + 1);
65
grub_core_cmd_unset (struct grub_command *cmd __attribute__ ((unused)),
66
int argc, char *argv[])
69
return grub_error (GRUB_ERR_BAD_ARGUMENT,
70
"no environment variable specified");
72
grub_env_unset (argv[0]);
77
grub_core_cmd_export (struct grub_command *cmd __attribute__ ((unused)),
78
int argc, char **args)
81
return grub_error (GRUB_ERR_BAD_ARGUMENT,
82
"no environment variable specified");
84
grub_env_export (args[0]);
90
grub_core_cmd_insmod (struct grub_command *cmd __attribute__ ((unused)),
91
int argc, char *argv[])
97
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
99
p = grub_strchr (argv[0], '/');
101
mod = grub_dl_load (argv[0]);
103
mod = grub_dl_load_file (argv[0]);
112
grub_mini_print_devices (const char *name)
114
grub_printf ("(%s) ", name);
120
grub_mini_print_files (const char *filename,
121
const struct grub_dirhook_info *info)
123
grub_printf ("%s%s ", filename, info->dir ? "/" : "");
130
grub_core_cmd_ls (struct grub_command *cmd __attribute__ ((unused)),
131
int argc, char *argv[])
135
grub_device_iterate (grub_mini_print_devices);
146
device_name = grub_file_get_device_name (argv[0]);
147
dev = grub_device_open (device_name);
151
fs = grub_fs_probe (dev);
152
path = grub_strchr (argv[0], ')');
158
if (! path && ! device_name)
160
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
166
if (grub_errno == GRUB_ERR_UNKNOWN_FS)
167
grub_errno = GRUB_ERR_NONE;
169
grub_printf ("(%s): Filesystem is %s.\n",
170
device_name, fs ? fs->name : "unknown");
174
(fs->dir) (dev, path, grub_mini_print_files);
181
grub_device_close (dev);
183
grub_free (device_name);
190
grub_register_core_commands (void)
192
grub_register_command ("set", grub_core_cmd_set,
193
"set [ENVVAR=VALUE]", "set an environment variable");
194
grub_register_command ("unset", grub_core_cmd_unset,
195
"unset ENVVAR", "remove an environment variable");
196
grub_register_command ("export", grub_core_cmd_export,
197
"export ENVVAR", "Export a variable.");
198
grub_register_command ("ls", grub_core_cmd_ls,
199
"ls [ARG]", "list devices or files");
200
grub_register_command ("insmod", grub_core_cmd_insmod,
201
"insmod MODULE", "insert a module");