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>
32 GRUB_MOD_LICENSE ("GPLv3+");
36 grub_mini_cmd_cat (struct grub_command
*cmd
__attribute__ ((unused
)),
37 int argc
, char *argv
[])
40 char buf
[GRUB_DISK_SECTOR_SIZE
];
44 return grub_error (GRUB_ERR_BAD_ARGUMENT
, N_("filename expected"));
46 file
= grub_file_open (argv
[0]);
50 while ((size
= grub_file_read (file
, buf
, sizeof (buf
))) > 0)
54 for (i
= 0; i
< size
; i
++)
56 unsigned char c
= buf
[i
];
58 if ((grub_isprint (c
) || grub_isspace (c
)) && c
!= '\r')
59 grub_printf ("%c", c
);
62 grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT
);
63 grub_printf ("<%x>", (int) c
);
64 grub_setcolorstate (GRUB_TERM_COLOR_STANDARD
);
71 grub_file_close (file
);
78 grub_mini_cmd_help (struct grub_command
*cmd
__attribute__ ((unused
)),
79 int argc
__attribute__ ((unused
)),
80 char *argv
[] __attribute__ ((unused
)))
84 for (p
= grub_command_list
; p
; p
= p
->next
)
85 grub_printf ("%s (%d%c)\t%s\n", p
->name
,
86 p
->prio
& GRUB_COMMAND_PRIO_MASK
,
87 (p
->prio
& GRUB_COMMAND_FLAG_ACTIVE
) ? '+' : '-',
93 /* dump ADDRESS [SIZE] */
95 grub_mini_cmd_dump (struct grub_command
*cmd
__attribute__ ((unused
)),
96 int argc
, char *argv
[])
102 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "no address specified");
104 addr
= (grub_uint8_t
*) grub_strtoul (argv
[0], 0, 0);
109 size
= (grub_size_t
) grub_strtoul (argv
[1], 0, 0);
113 grub_printf ("%x%x ", *addr
>> 4, *addr
& 0xf);
122 grub_mini_cmd_rmmod (struct grub_command
*cmd
__attribute__ ((unused
)),
123 int argc
, char *argv
[])
128 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "no module specified");
130 mod
= grub_dl_get (argv
[0]);
132 return grub_error (GRUB_ERR_BAD_ARGUMENT
, "no such module");
134 if (grub_dl_unref (mod
) <= 0)
135 grub_dl_unload (mod
);
142 grub_mini_cmd_lsmod (struct grub_command
*cmd
__attribute__ ((unused
)),
143 int argc
__attribute__ ((unused
)),
144 char *argv
[] __attribute__ ((unused
)))
148 /* TRANSLATORS: this is module list header. Name
149 is module name, Ref Count is a reference counter
150 (how many modules or open descriptors use it).
151 Dependencies are the other modules it uses.
153 grub_printf_ (N_("Name\tRef Count\tDependencies\n"));
158 grub_printf ("%s\t%d\t\t", mod
->name
, mod
->ref_count
);
159 for (dep
= mod
->dep
; dep
; dep
= dep
->next
)
164 grub_printf ("%s", dep
->mod
->name
);
173 static grub_err_t
__attribute__ ((noreturn
))
174 grub_mini_cmd_exit (struct grub_command
*cmd
__attribute__ ((unused
)),
175 int argc
__attribute__ ((unused
)),
176 char *argv
[] __attribute__ ((unused
)))
182 static grub_command_t cmd_cat
, cmd_help
;
183 static grub_command_t cmd_dump
, cmd_rmmod
, cmd_lsmod
, cmd_exit
;
185 GRUB_MOD_INIT(minicmd
)
188 grub_register_command ("cat", grub_mini_cmd_cat
,
189 N_("FILE"), N_("Show the contents of a file."));
191 grub_register_command ("help", grub_mini_cmd_help
,
192 0, N_("Show this message."));
194 grub_register_command ("dump", grub_mini_cmd_dump
,
195 N_("ADDR [SIZE]"), N_("Show memory contents."));
197 grub_register_command ("rmmod", grub_mini_cmd_rmmod
,
198 N_("MODULE"), N_("Remove a module."));
200 grub_register_command ("lsmod", grub_mini_cmd_lsmod
,
201 0, N_("Show loaded modules."));
203 grub_register_command ("exit", grub_mini_cmd_exit
,
204 0, N_("Exit from GRUB."));
207 GRUB_MOD_FINI(minicmd
)
209 grub_unregister_command (cmd_cat
);
210 grub_unregister_command (cmd_help
);
211 grub_unregister_command (cmd_dump
);
212 grub_unregister_command (cmd_rmmod
);
213 grub_unregister_command (cmd_lsmod
);
214 grub_unregister_command (cmd_exit
);