]> git.proxmox.com Git - grub2.git/blame - grub-core/kern/rescue_reader.c
Add noreturn attributes and remove unreachable code.
[grub2.git] / grub-core / kern / rescue_reader.c
CommitLineData
d558e6b5 1/* rescue_reader.c - rescue mode reader */
2/*
3 * GRUB -- GRand Unified Bootloader
88d17012 4 * Copyright (C) 2009,2010 Free Software Foundation, Inc.
d558e6b5 5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include <grub/types.h>
21#include <grub/reader.h>
f4c623e1 22#include <grub/parser.h>
d558e6b5 23#include <grub/misc.h>
24#include <grub/term.h>
f4c623e1 25#include <grub/mm.h>
d558e6b5 26
27#define GRUB_RESCUE_BUF_SIZE 256
28
29static char linebuf[GRUB_RESCUE_BUF_SIZE];
30
d558e6b5 31/* Prompt to input a command and read the line. */
32static grub_err_t
33grub_rescue_read_line (char **line, int cont)
34{
35 int c;
36 int pos = 0;
dfed5c6b 37 char str[4];
d558e6b5 38
39 grub_printf ((cont) ? "> " : "grub rescue> ");
40 grub_memset (linebuf, 0, GRUB_RESCUE_BUF_SIZE);
41
87fae34a 42 while ((c = grub_getkey ()) != '\n' && c != '\r')
d558e6b5 43 {
44 if (grub_isprint (c))
45 {
46 if (pos < GRUB_RESCUE_BUF_SIZE - 1)
47 {
dfed5c6b
VS
48 str[0] = c;
49 str[1] = 0;
d558e6b5 50 linebuf[pos++] = c;
dfed5c6b 51 grub_xputs (str);
d558e6b5 52 }
53 }
54 else if (c == '\b')
55 {
56 if (pos > 0)
57 {
dfed5c6b
VS
58 str[0] = c;
59 str[1] = ' ';
60 str[2] = c;
61 str[3] = 0;
d558e6b5 62 linebuf[--pos] = 0;
dfed5c6b 63 grub_xputs (str);
d558e6b5 64 }
65 }
66 grub_refresh ();
67 }
68
dfed5c6b 69 grub_xputs ("\n");
d558e6b5 70 grub_refresh ();
71
72 *line = grub_strdup (linebuf);
73
74 return 0;
75}
76
02a2bf83 77void __attribute__ ((noreturn))
f4c623e1 78grub_rescue_run (void)
d558e6b5 79{
f4c623e1
VS
80 grub_printf ("Entering rescue mode...\n");
81
82 while (1)
83 {
84 char *line;
85
86 /* Print an error, if any. */
87 grub_print_error ();
88 grub_errno = GRUB_ERR_NONE;
89
90 grub_rescue_read_line (&line, 0);
88d17012 91 if (! line || line[0] == '\0')
f4c623e1
VS
92 continue;
93
d56a6ac7 94 grub_rescue_parse_line (line, grub_rescue_read_line);
f4c623e1
VS
95 grub_free (line);
96 }
d558e6b5 97}