]>
Commit | Line | Data |
---|---|---|
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 | ||
29 | static char linebuf[GRUB_RESCUE_BUF_SIZE]; | |
30 | ||
d558e6b5 | 31 | /* Prompt to input a command and read the line. */ |
32 | static grub_err_t | |
09fd6d82 CW |
33 | grub_rescue_read_line (char **line, int cont, |
34 | void *data __attribute__ ((unused))) | |
d558e6b5 | 35 | { |
36 | int c; | |
37 | int pos = 0; | |
dfed5c6b | 38 | char str[4]; |
d558e6b5 | 39 | |
40 | grub_printf ((cont) ? "> " : "grub rescue> "); | |
41 | grub_memset (linebuf, 0, GRUB_RESCUE_BUF_SIZE); | |
42 | ||
87fae34a | 43 | while ((c = grub_getkey ()) != '\n' && c != '\r') |
d558e6b5 | 44 | { |
45 | if (grub_isprint (c)) | |
46 | { | |
47 | if (pos < GRUB_RESCUE_BUF_SIZE - 1) | |
48 | { | |
dfed5c6b VS |
49 | str[0] = c; |
50 | str[1] = 0; | |
d558e6b5 | 51 | linebuf[pos++] = c; |
dfed5c6b | 52 | grub_xputs (str); |
d558e6b5 | 53 | } |
54 | } | |
55 | else if (c == '\b') | |
56 | { | |
57 | if (pos > 0) | |
58 | { | |
dfed5c6b VS |
59 | str[0] = c; |
60 | str[1] = ' '; | |
61 | str[2] = c; | |
62 | str[3] = 0; | |
d558e6b5 | 63 | linebuf[--pos] = 0; |
dfed5c6b | 64 | grub_xputs (str); |
d558e6b5 | 65 | } |
66 | } | |
67 | grub_refresh (); | |
68 | } | |
69 | ||
dfed5c6b | 70 | grub_xputs ("\n"); |
d558e6b5 | 71 | grub_refresh (); |
72 | ||
73 | *line = grub_strdup (linebuf); | |
74 | ||
75 | return 0; | |
76 | } | |
77 | ||
02a2bf83 | 78 | void __attribute__ ((noreturn)) |
f4c623e1 | 79 | grub_rescue_run (void) |
d558e6b5 | 80 | { |
f4c623e1 VS |
81 | grub_printf ("Entering rescue mode...\n"); |
82 | ||
83 | while (1) | |
84 | { | |
85 | char *line; | |
86 | ||
87 | /* Print an error, if any. */ | |
88 | grub_print_error (); | |
89 | grub_errno = GRUB_ERR_NONE; | |
90 | ||
09fd6d82 | 91 | grub_rescue_read_line (&line, 0, NULL); |
88d17012 | 92 | if (! line || line[0] == '\0') |
f4c623e1 VS |
93 | continue; |
94 | ||
09fd6d82 | 95 | grub_rescue_parse_line (line, grub_rescue_read_line, NULL); |
f4c623e1 VS |
96 | grub_free (line); |
97 | } | |
d558e6b5 | 98 | } |