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>
29 #include <grub/i18n.h>
31 /* set ENVVAR=VALUE */
33 grub_core_cmd_set (struct grub_command
*cmd
__attribute__ ((unused
)),
34 int argc
, char *argv
[])
39 auto int print_env (struct grub_env_var
*env
);
41 int print_env (struct grub_env_var
*env
)
43 grub_printf ("%s=%s\n", env
->name
, env
->value
);
49 grub_env_iterate (print_env
);
54 val
= grub_strchr (var
, '=');
56 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "not an assignment");
59 grub_env_set (var
, val
+ 1);
66 grub_core_cmd_unset (struct grub_command
*cmd
__attribute__ ((unused
)),
67 int argc
, char *argv
[])
70 return grub_error (GRUB_ERR_BAD_ARGUMENT
,
71 N_("one argument expected"));
73 grub_env_unset (argv
[0]);
79 grub_core_cmd_insmod (struct grub_command
*cmd
__attribute__ ((unused
)),
80 int argc
, char *argv
[])
85 return grub_error (GRUB_ERR_BAD_ARGUMENT
, N_("one argument expected"));
87 if (argv
[0][0] == '/' || argv
[0][0] == '(' || argv
[0][0] == '+')
88 mod
= grub_dl_load_file (argv
[0]);
90 mod
= grub_dl_load (argv
[0]);
99 grub_mini_print_devices (const char *name
)
101 grub_printf ("(%s) ", name
);
107 grub_mini_print_files (const char *filename
,
108 const struct grub_dirhook_info
*info
)
110 grub_printf ("%s%s ", filename
, info
->dir
? "/" : "");
117 grub_core_cmd_ls (struct grub_command
*cmd
__attribute__ ((unused
)),
118 int argc
, char *argv
[])
122 grub_device_iterate (grub_mini_print_devices
);
129 grub_device_t dev
= 0;
133 device_name
= grub_file_get_device_name (argv
[0]);
136 dev
= grub_device_open (device_name
);
140 fs
= grub_fs_probe (dev
);
141 path
= grub_strchr (argv
[0], ')');
147 if (! path
&& ! device_name
)
149 grub_error (GRUB_ERR_BAD_ARGUMENT
, "invalid argument");
155 if (grub_errno
== GRUB_ERR_UNKNOWN_FS
)
156 grub_errno
= GRUB_ERR_NONE
;
158 grub_printf ("(%s): Filesystem is %s.\n",
159 device_name
, fs
? fs
->name
: "unknown");
163 (fs
->dir
) (dev
, path
, grub_mini_print_files
);
170 grub_device_close (dev
);
172 grub_free (device_name
);
179 grub_register_core_commands (void)
182 cmd
= grub_register_command ("set", grub_core_cmd_set
,
183 N_("[ENVVAR=VALUE]"),
184 N_("Set an environment variable."));
186 cmd
->flags
|= GRUB_COMMAND_FLAG_EXTRACTOR
;
187 grub_register_command ("unset", grub_core_cmd_unset
,
189 N_("Remove an environment variable."));
190 grub_register_command ("ls", grub_core_cmd_ls
,
191 N_("[ARG]"), N_("List devices or files."));
192 grub_register_command ("insmod", grub_core_cmd_insmod
,
193 N_("MODULE"), N_("Insert a module."));