1
/* minicmd.c - commands for the rescue mode */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2003,2005,2006,2007,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/file.h>
26
#include <grub/disk.h>
27
#include <grub/term.h>
28
#include <grub/loader.h>
29
#include <grub/command.h>
30
#include <grub/i18n.h>
34
grub_mini_cmd_cat (struct grub_command *cmd __attribute__ ((unused)),
35
int argc, char *argv[])
38
char buf[GRUB_DISK_SECTOR_SIZE];
42
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
44
file = grub_file_open (argv[0]);
48
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0)
52
for (i = 0; i < size; i++)
54
unsigned char c = buf[i];
56
if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
57
grub_printf ("%c", c);
60
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
61
grub_printf ("<%x>", (int) c);
62
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
69
grub_file_close (file);
76
grub_mini_cmd_help (struct grub_command *cmd __attribute__ ((unused)),
77
int argc __attribute__ ((unused)),
78
char *argv[] __attribute__ ((unused)))
82
for (p = grub_command_list; p; p = p->next)
83
grub_printf ("%s (%d%c)\t%s\n", p->name,
84
p->prio & GRUB_PRIO_LIST_PRIO_MASK,
85
(p->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) ? '+' : '-',
93
grub_rescue_cmd_info (void)
95
extern void grub_disk_cache_get_performance (unsigned long *,
97
unsigned long hits, misses;
99
grub_disk_cache_get_performance (&hits, &misses);
100
grub_printf ("Disk cache: hits = %u, misses = %u ", hits, misses);
103
unsigned long ratio = hits * 10000 / (hits + misses);
104
grub_printf ("(%u.%u%%)\n", ratio / 100, ratio % 100);
107
grub_printf ("(N/A)\n");
111
/* dump ADDRESS [SIZE] */
113
grub_mini_cmd_dump (struct grub_command *cmd __attribute__ ((unused)),
114
int argc, char *argv[])
117
grub_size_t size = 4;
120
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no address specified");
122
addr = (grub_uint8_t *) grub_strtoul (argv[0], 0, 0);
127
size = (grub_size_t) grub_strtoul (argv[1], 0, 0);
131
grub_printf ("%x%x ", *addr >> 4, *addr & 0xf);
140
grub_mini_cmd_rmmod (struct grub_command *cmd __attribute__ ((unused)),
141
int argc, char *argv[])
146
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
148
mod = grub_dl_get (argv[0]);
150
return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module");
152
if (grub_dl_unref (mod) <= 0)
153
grub_dl_unload (mod);
160
grub_mini_cmd_lsmod (struct grub_command *cmd __attribute__ ((unused)),
161
int argc __attribute__ ((unused)),
162
char *argv[] __attribute__ ((unused)))
166
grub_printf ("Name\tRef Count\tDependencies\n");
171
grub_printf ("%s\t%d\t\t", mod->name, mod->ref_count);
172
for (dep = mod->dep; dep; dep = dep->next)
177
grub_printf ("%s", dep->mod->name);
187
grub_mini_cmd_exit (struct grub_command *cmd __attribute__ ((unused)),
188
int argc __attribute__ ((unused)),
189
char *argv[] __attribute__ ((unused)))
195
static grub_command_t cmd_cat, cmd_help;
196
static grub_command_t cmd_dump, cmd_rmmod, cmd_lsmod, cmd_exit;
198
GRUB_MOD_INIT(minicmd)
201
grub_register_command ("cat", grub_mini_cmd_cat,
202
N_("FILE"), N_("Show the contents of a file."));
204
grub_register_command ("help", grub_mini_cmd_help,
205
0, N_("Show this message."));
207
grub_register_command ("dump", grub_mini_cmd_dump,
208
N_("ADDR"), N_("Dump memory."));
210
grub_register_command ("rmmod", grub_mini_cmd_rmmod,
211
N_("MODULE"), N_("Remove a module."));
213
grub_register_command ("lsmod", grub_mini_cmd_lsmod,
214
0, N_("Show loaded modules."));
216
grub_register_command ("exit", grub_mini_cmd_exit,
217
0, N_("Exit from GRUB."));
220
GRUB_MOD_FINI(minicmd)
222
grub_unregister_command (cmd_cat);
223
grub_unregister_command (cmd_help);
224
grub_unregister_command (cmd_dump);
225
grub_unregister_command (cmd_rmmod);
226
grub_unregister_command (cmd_lsmod);
227
grub_unregister_command (cmd_exit);