2N/A/* rescue_reader.c - rescue mode reader */
2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2009,2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <grub/types.h>
2N/A#include <grub/reader.h>
2N/A#include <grub/parser.h>
2N/A#include <grub/misc.h>
2N/A#include <grub/term.h>
2N/A#include <grub/mm.h>
2N/A
2N/A#define GRUB_RESCUE_BUF_SIZE 256
2N/A
2N/Astatic char linebuf[GRUB_RESCUE_BUF_SIZE];
2N/A
2N/A/* Prompt to input a command and read the line. */
2N/Astatic grub_err_t
2N/Agrub_rescue_read_line (char **line, int cont)
2N/A{
2N/A int c;
2N/A int pos = 0;
2N/A char str[4];
2N/A
2N/A grub_printf ((cont) ? "> " : "grub rescue> ");
2N/A grub_memset (linebuf, 0, GRUB_RESCUE_BUF_SIZE);
2N/A
2N/A while ((c = grub_getkey ()) != '\n' && c != '\r')
2N/A {
2N/A if (grub_isprint (c))
2N/A {
2N/A if (pos < GRUB_RESCUE_BUF_SIZE - 1)
2N/A {
2N/A str[0] = c;
2N/A str[1] = 0;
2N/A linebuf[pos++] = c;
2N/A grub_xputs (str);
2N/A }
2N/A }
2N/A else if (c == '\b')
2N/A {
2N/A if (pos > 0)
2N/A {
2N/A str[0] = c;
2N/A str[1] = ' ';
2N/A str[2] = c;
2N/A str[3] = 0;
2N/A linebuf[--pos] = 0;
2N/A grub_xputs (str);
2N/A }
2N/A }
2N/A grub_refresh ();
2N/A }
2N/A
2N/A grub_xputs ("\n");
2N/A grub_refresh ();
2N/A
2N/A *line = grub_strdup (linebuf);
2N/A
2N/A return 0;
2N/A}
2N/A
2N/Avoid __attribute__ ((noreturn))
2N/Agrub_rescue_run (void)
2N/A{
2N/A grub_printf ("Entering rescue mode...\n");
2N/A
2N/A while (1)
2N/A {
2N/A char *line;
2N/A
2N/A /* Print an error, if any. */
2N/A grub_print_error ();
2N/A grub_errno = GRUB_ERR_NONE;
2N/A
2N/A grub_rescue_read_line (&line, 0);
2N/A if (! line || line[0] == '\0')
2N/A continue;
2N/A
2N/A grub_rescue_parse_line (line, grub_rescue_read_line);
2N/A grub_free (line);
2N/A }
2N/A}