mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-28 10:10:29 +00:00
Add new options into /sbin/grub, and eliminate the completion code from Stage 1.5.
This commit is contained in:
1 parent
cc1aa59379
commit
447e862f7e
7 files changed
+131
-9
No files matched your search
+69
-4
@@ -508,11 +508,17 @@ get_diskinfo (int drive, struct geometry *geometry)
|
||||
if (! devname)
|
||||
return -1;
|
||||
|
||||
if (verbose)
|
||||
grub_printf ("Attempt to open drive 0x%x (%s)\n",
|
||||
drive, devname);
|
||||
|
||||
/* Open read/write, or read-only if that failed. */
|
||||
disks[drive].flags = open (devname, O_RDWR);
|
||||
if (! read_only)
|
||||
disks[drive].flags = open (devname, O_RDWR);
|
||||
|
||||
if (disks[drive].flags == -1)
|
||||
{
|
||||
if (errno == EACCES || errno == EROFS)
|
||||
if (read_only || errno == EACCES || errno == EROFS)
|
||||
{
|
||||
disks[drive].flags = open (devname, O_RDONLY);
|
||||
if (disks[drive].flags == -1)
|
||||
@@ -632,6 +638,55 @@ nwrite (int fd, char *buf, size_t len)
|
||||
return size;
|
||||
}
|
||||
|
||||
/* Dump BUF in the format of hexadecimal numbers. */
|
||||
static void
|
||||
hex_dump (void *buf, size_t size)
|
||||
{
|
||||
/* FIXME: How to determine which length is readable? */
|
||||
#define MAX_COLUMN 70
|
||||
|
||||
/* use unsigned char for numerical computations */
|
||||
unsigned char *ptr = buf;
|
||||
/* count the width of the line */
|
||||
int column = 0;
|
||||
/* how many bytes written */
|
||||
int count = 0;
|
||||
|
||||
while (size > 0)
|
||||
{
|
||||
/* high 4 bits */
|
||||
int hi = *ptr >> 4;
|
||||
/* low 4 bits */
|
||||
int low = *ptr & 0xf;
|
||||
|
||||
/* grub_printf does not handle prefix number, such as %2x, so
|
||||
format the number by hand... */
|
||||
grub_printf ("%x%x", hi, low);
|
||||
column += 2;
|
||||
count++;
|
||||
ptr++;
|
||||
size--;
|
||||
|
||||
/* Insert space or newline with the interval 4 bytes. */
|
||||
if (size != 0 && (count % 4) == 0)
|
||||
{
|
||||
if (column < MAX_COLUMN)
|
||||
{
|
||||
grub_printf (" ");
|
||||
column++;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_printf ("\n");
|
||||
column = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a newline at the end for readability. */
|
||||
grub_printf ("\n");
|
||||
}
|
||||
|
||||
int
|
||||
biosdisk (int subfunc, int drive, struct geometry *geometry,
|
||||
int sector, int nsec, int segment)
|
||||
@@ -669,10 +724,20 @@ biosdisk (int subfunc, int drive, struct geometry *geometry,
|
||||
if (nread (fd, buf, nsec * SECTOR_SIZE) != nsec * SECTOR_SIZE)
|
||||
return -1;
|
||||
break;
|
||||
|
||||
case BIOSDISK_WRITE:
|
||||
if (nwrite (fd, buf, nsec * SECTOR_SIZE) != nsec * SECTOR_SIZE)
|
||||
return -1;
|
||||
if (verbose)
|
||||
{
|
||||
grub_printf ("Write %d sectors starting from %d sector"
|
||||
" to drive 0x%x (%s)\n",
|
||||
nsec, sector, drive, device_map[drive]);
|
||||
hex_dump (buf, nsec * SECTOR_SIZE);
|
||||
}
|
||||
if (! read_only)
|
||||
if (nwrite (fd, buf, nsec * SECTOR_SIZE) != nsec * SECTOR_SIZE)
|
||||
return -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
grub_printf ("unknown subfunc %d\n", subfunc);
|
||||
break;
|
||||
|
||||
+19
@@ -34,6 +34,8 @@ int grub_stage2 (void);
|
||||
char *program_name = 0;
|
||||
int use_config_file = 1;
|
||||
int use_curses = 1;
|
||||
int verbose = 0;
|
||||
int read_only = 0;
|
||||
static int default_boot_drive;
|
||||
static int default_install_partition;
|
||||
static char *default_config_file;
|
||||
@@ -47,6 +49,8 @@ static char *default_config_file;
|
||||
#define OPT_NO_CONFIG_FILE -8
|
||||
#define OPT_NO_CURSES -9
|
||||
#define OPT_BATCH -10
|
||||
#define OPT_VERBOSE -11
|
||||
#define OPT_READ_ONLY -12
|
||||
#define OPTSTRING ""
|
||||
|
||||
static struct option longopts[] =
|
||||
@@ -60,6 +64,8 @@ static struct option longopts[] =
|
||||
{"no-config-file", no_argument, 0, OPT_NO_CONFIG_FILE},
|
||||
{"no-curses", no_argument, 0, OPT_NO_CURSES},
|
||||
{"batch", no_argument, 0, OPT_BATCH},
|
||||
{"verbose", no_argument, 0, OPT_VERBOSE},
|
||||
{"read-only", no_argument, 0, OPT_READ_ONLY},
|
||||
{0},
|
||||
};
|
||||
|
||||
@@ -83,6 +89,8 @@ Enter the GRand Unified Bootloader command shell.\n\
|
||||
--install-partition=PAR specify stage2 install_partition [default=0x%x]\n\
|
||||
--no-config-file do not use the config file\n\
|
||||
--no-curses do not use curses\n\
|
||||
--read-only do not write anything to devices\n\
|
||||
--verbose print verbose messages\n\
|
||||
--version print version information and exit\n\
|
||||
\n\
|
||||
Report bugs to bug-grub@gnu.org\n\
|
||||
@@ -167,6 +175,14 @@ main (int argc, char **argv)
|
||||
use_curses = 0;
|
||||
break;
|
||||
|
||||
case OPT_READ_ONLY:
|
||||
read_only = 1;
|
||||
break;
|
||||
|
||||
case OPT_VERBOSE:
|
||||
verbose = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage (1);
|
||||
}
|
||||
@@ -174,6 +190,9 @@ main (int argc, char **argv)
|
||||
while (c != EOF);
|
||||
|
||||
/* Wait until the HOLD variable is cleared by an attached debugger. */
|
||||
if (hold && verbose)
|
||||
grub_printf ("Run \"gdb %s %d\", and set HOLD to zero.\n",
|
||||
program_name, (int) getpid ());
|
||||
while (hold)
|
||||
sleep (1);
|
||||
|
||||
|
||||
Reference in new issue
Block a user