remove all trailing whitespace
This commit is contained in:
parent
d2d4966571
commit
b39f9d20a9
222 changed files with 3286 additions and 3286 deletions
|
@ -106,7 +106,7 @@ grub_ncurses_putchar (grub_uint32_t c)
|
|||
c = '?';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
addch (c | grub_console_attr);
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ grub_ncurses_getcharwidth (grub_uint32_t code __attribute__ ((unused)))
|
|||
static void
|
||||
grub_ncurses_setcolorstate (grub_term_color_state state)
|
||||
{
|
||||
switch (state)
|
||||
switch (state)
|
||||
{
|
||||
case GRUB_TERM_COLOR_STANDARD:
|
||||
grub_console_cur_color = grub_console_standard_color;
|
||||
|
@ -170,12 +170,12 @@ static int
|
|||
grub_ncurses_checkkey (void)
|
||||
{
|
||||
int c;
|
||||
|
||||
|
||||
/* Check for SAVED_CHAR. This should not be true, because this
|
||||
means checkkey is called twice continuously. */
|
||||
if (saved_char != ERR)
|
||||
return saved_char;
|
||||
|
||||
|
||||
wtimeout (stdscr, 100);
|
||||
c = getch ();
|
||||
/* If C is not ERR, then put it back in the input queue. */
|
||||
|
@ -192,7 +192,7 @@ static int
|
|||
grub_ncurses_getkey (void)
|
||||
{
|
||||
int c;
|
||||
|
||||
|
||||
/* If checkkey has already got a character, then return it. */
|
||||
if (saved_char != ERR)
|
||||
{
|
||||
|
@ -214,7 +214,7 @@ grub_ncurses_getkey (void)
|
|||
case KEY_RIGHT:
|
||||
c = 6;
|
||||
break;
|
||||
|
||||
|
||||
case KEY_UP:
|
||||
c = 16;
|
||||
break;
|
||||
|
@ -234,7 +234,7 @@ grub_ncurses_getkey (void)
|
|||
case KEY_BACKSPACE:
|
||||
/* XXX: For some reason ncurses on xterm does not return
|
||||
KEY_BACKSPACE. */
|
||||
case 127:
|
||||
case 127:
|
||||
c = 8;
|
||||
break;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ strip_extra_slashes (char *dir)
|
|||
p[0] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ grub_get_prefix (const char *dir)
|
|||
char *abs_dir, *prev_dir;
|
||||
char *prefix;
|
||||
struct stat st, prev_st;
|
||||
|
||||
|
||||
/* Save the current directory. */
|
||||
saved_cwd = xgetcwd ();
|
||||
|
||||
|
@ -114,7 +114,7 @@ grub_get_prefix (const char *dir)
|
|||
abs_dir = xgetcwd ();
|
||||
strip_extra_slashes (abs_dir);
|
||||
prev_dir = xstrdup (abs_dir);
|
||||
|
||||
|
||||
if (stat (".", &prev_st) < 0)
|
||||
grub_util_error ("Cannot stat `%s'", dir);
|
||||
|
||||
|
@ -187,7 +187,7 @@ find_root_device (const char *dir, dev_t dev)
|
|||
DIR *dp;
|
||||
char *saved_cwd;
|
||||
struct dirent *ent;
|
||||
|
||||
|
||||
dp = opendir (dir);
|
||||
if (! dp)
|
||||
return 0;
|
||||
|
@ -201,11 +201,11 @@ find_root_device (const char *dir, dev_t dev)
|
|||
closedir (dp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
while ((ent = readdir (dp)) != 0)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
|
||||
/* Avoid:
|
||||
- dotfiles (like "/dev/.tmp.md0") since they could be duplicates.
|
||||
- dotdirs (like "/dev/.static") since they could contain duplicates. */
|
||||
|
@ -219,7 +219,7 @@ find_root_device (const char *dir, dev_t dev)
|
|||
if (S_ISLNK (st.st_mode))
|
||||
/* Don't follow symbolic links. */
|
||||
continue;
|
||||
|
||||
|
||||
if (S_ISDIR (st.st_mode))
|
||||
{
|
||||
/* Find it recursively. */
|
||||
|
@ -231,7 +231,7 @@ find_root_device (const char *dir, dev_t dev)
|
|||
{
|
||||
if (chdir (saved_cwd) < 0)
|
||||
grub_util_error ("Cannot restore the original directory");
|
||||
|
||||
|
||||
free (saved_cwd);
|
||||
closedir (dp);
|
||||
return res;
|
||||
|
@ -380,7 +380,7 @@ grub_guess_root_device (const char *dir)
|
|||
{
|
||||
struct stat st;
|
||||
char *os_dev;
|
||||
|
||||
|
||||
if (stat (dir, &st) < 0)
|
||||
grub_util_error ("Cannot stat `%s'", dir);
|
||||
|
||||
|
@ -437,7 +437,7 @@ grub_util_get_grub_dev (const char *os_dev)
|
|||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case GRUB_DEV_ABSTRACTION_RAID:
|
||||
|
@ -500,7 +500,7 @@ grub_util_get_grub_dev (const char *os_dev)
|
|||
}
|
||||
else
|
||||
grub_util_error ("Unknown kind of RAID device `%s'", os_dev);
|
||||
|
||||
|
||||
break;
|
||||
|
||||
default: /* GRUB_DEV_ABSTRACTION_NONE */
|
||||
|
|
|
@ -95,7 +95,7 @@ create_envblk_file (const char *name)
|
|||
{
|
||||
FILE *fp;
|
||||
char *buf;
|
||||
|
||||
|
||||
buf = malloc (DEFAULT_ENVBLK_SIZE);
|
||||
if (! buf)
|
||||
grub_util_error ("out of memory");
|
||||
|
@ -107,7 +107,7 @@ create_envblk_file (const char *name)
|
|||
memcpy (buf, GRUB_ENVBLK_SIGNATURE, sizeof (GRUB_ENVBLK_SIGNATURE) - 1);
|
||||
memset (buf + sizeof (GRUB_ENVBLK_SIGNATURE) - 1, '#',
|
||||
DEFAULT_ENVBLK_SIZE - sizeof (GRUB_ENVBLK_SIGNATURE) + 1);
|
||||
|
||||
|
||||
if (fwrite (buf, 1, DEFAULT_ENVBLK_SIZE, fp) != DEFAULT_ENVBLK_SIZE)
|
||||
grub_util_error ("cannot write to the file %s", name);
|
||||
|
||||
|
@ -123,7 +123,7 @@ open_envblk_file (const char *name)
|
|||
char *buf;
|
||||
size_t size;
|
||||
grub_envblk_t envblk;
|
||||
|
||||
|
||||
fp = fopen (name, "rb");
|
||||
if (! fp)
|
||||
{
|
||||
|
@ -145,12 +145,12 @@ open_envblk_file (const char *name)
|
|||
buf = malloc (size);
|
||||
if (! buf)
|
||||
grub_util_error ("out of memory");
|
||||
|
||||
|
||||
if (fread (buf, 1, size, fp) != size)
|
||||
grub_util_error ("cannot read the file %s", name);
|
||||
|
||||
fclose (fp);
|
||||
|
||||
|
||||
envblk = grub_envblk_open (buf, size);
|
||||
if (! envblk)
|
||||
grub_util_error ("invalid environment block");
|
||||
|
@ -162,7 +162,7 @@ static void
|
|||
list_variables (const char *name)
|
||||
{
|
||||
grub_envblk_t envblk;
|
||||
|
||||
|
||||
auto int print_var (const char *name, const char *value);
|
||||
int print_var (const char *name, const char *value)
|
||||
{
|
||||
|
@ -179,11 +179,11 @@ static void
|
|||
write_envblk (const char *name, grub_envblk_t envblk)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
|
||||
fp = fopen (name, "wb");
|
||||
if (! fp)
|
||||
grub_util_error ("cannot open the file %s", name);
|
||||
|
||||
|
||||
if (fwrite (grub_envblk_buffer (envblk), 1, grub_envblk_size (envblk), fp)
|
||||
!= grub_envblk_size (envblk))
|
||||
grub_util_error ("cannot write to the file %s", name);
|
||||
|
@ -196,7 +196,7 @@ static void
|
|||
set_variables (const char *name, int argc, char *argv[])
|
||||
{
|
||||
grub_envblk_t envblk;
|
||||
|
||||
|
||||
envblk = open_envblk_file (name);
|
||||
while (argc)
|
||||
{
|
||||
|
@ -223,7 +223,7 @@ static void
|
|||
unset_variables (const char *name, int argc, char *argv[])
|
||||
{
|
||||
grub_envblk_t envblk;
|
||||
|
||||
|
||||
envblk = open_envblk_file (name);
|
||||
while (argc)
|
||||
{
|
||||
|
@ -242,9 +242,9 @@ main (int argc, char *argv[])
|
|||
{
|
||||
char *filename;
|
||||
char *command;
|
||||
|
||||
|
||||
progname = "grub-editenv";
|
||||
|
||||
|
||||
/* Check for options. */
|
||||
while (1)
|
||||
{
|
||||
|
@ -285,7 +285,7 @@ main (int argc, char *argv[])
|
|||
fprintf (stderr, "no command specified\n");
|
||||
usage (1);
|
||||
}
|
||||
|
||||
|
||||
filename = argv[optind];
|
||||
command = argv[optind + 1];
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ static struct option options[] =
|
|||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
static int
|
||||
static int
|
||||
usage (int status)
|
||||
{
|
||||
if (status)
|
||||
|
@ -138,7 +138,7 @@ main (int argc, char *argv[])
|
|||
char *dev_map = DEFAULT_DEVICE_MAP;
|
||||
volatile int hold = 0;
|
||||
int opt;
|
||||
|
||||
|
||||
progname = "grub-emu";
|
||||
|
||||
while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1)
|
||||
|
@ -185,7 +185,7 @@ main (int argc, char *argv[])
|
|||
|
||||
sleep (1);
|
||||
}
|
||||
|
||||
|
||||
signal (SIGINT, SIG_IGN);
|
||||
grub_console_init ();
|
||||
|
||||
|
@ -218,7 +218,7 @@ main (int argc, char *argv[])
|
|||
prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1);
|
||||
sprintf (prefix, "(%s)%s", root_dev, dir);
|
||||
free (dir);
|
||||
|
||||
|
||||
/* Start GRUB! */
|
||||
if (setjmp (main_env) == 0)
|
||||
grub_main ();
|
||||
|
@ -226,6 +226,6 @@ main (int argc, char *argv[])
|
|||
grub_fini_all ();
|
||||
|
||||
grub_machine_fini ();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
/* XXX: this file assumes particular Mach-O layout and does no checks. */
|
||||
/* However as build system ensures correct usage of this tool this
|
||||
/* However as build system ensures correct usage of this tool this
|
||||
shouldn't be a problem. */
|
||||
|
||||
int
|
||||
|
@ -71,7 +71,7 @@ main (int argc, char **argv)
|
|||
fclose (out);
|
||||
printf ("Couldn't allocate buffer\n");
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
fread (buf, 1, bufsize, in);
|
||||
head = (struct grub_macho_header32 *) buf;
|
||||
if (grub_le_to_cpu32 (head->magic) != GRUB_MACHO_MAGIC32)
|
||||
|
@ -81,22 +81,22 @@ main (int argc, char **argv)
|
|||
free (buf);
|
||||
printf ("Invalid Mach-O fle\n");
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
curcmd = (struct grub_macho_segment32 *) (buf + sizeof (*head));
|
||||
for (i = 0; i < grub_le_to_cpu32 (head->ncmds); i++,
|
||||
curcmd = (struct grub_macho_segment32 *)
|
||||
for (i = 0; i < grub_le_to_cpu32 (head->ncmds); i++,
|
||||
curcmd = (struct grub_macho_segment32 *)
|
||||
(((char *) curcmd) + curcmd->cmdsize))
|
||||
{
|
||||
if (curcmd->cmd != GRUB_MACHO_CMD_SEGMENT32)
|
||||
continue;
|
||||
fwrite (buf + grub_le_to_cpu32 (curcmd->fileoff), 1,
|
||||
fwrite (buf + grub_le_to_cpu32 (curcmd->fileoff), 1,
|
||||
grub_le_to_cpu32 (curcmd->filesize), out);
|
||||
if (grub_le_to_cpu32 (curcmd->vmsize)
|
||||
if (grub_le_to_cpu32 (curcmd->vmsize)
|
||||
> grub_le_to_cpu32 (curcmd->filesize))
|
||||
{
|
||||
bssstart = grub_le_to_cpu32 (curcmd->vmaddr)
|
||||
bssstart = grub_le_to_cpu32 (curcmd->vmaddr)
|
||||
+ grub_le_to_cpu32 (curcmd->filesize) ;
|
||||
bssend = grub_le_to_cpu32 (curcmd->vmaddr)
|
||||
bssend = grub_le_to_cpu32 (curcmd->vmaddr)
|
||||
+ grub_le_to_cpu32 (curcmd->vmsize) ;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ for option in "$@"; do
|
|||
;;
|
||||
--output=)
|
||||
grub_cfg=`echo "$option" | sed 's/--output=//'`
|
||||
;;
|
||||
;;
|
||||
-*)
|
||||
echo "Unrecognized option \`$option'" 1>&2
|
||||
usage
|
||||
|
|
|
@ -55,7 +55,7 @@ make_device_map (const char *device_map, int floppy_disks)
|
|||
fp = stdout;
|
||||
else
|
||||
fp = fopen (device_map, "w");
|
||||
|
||||
|
||||
if (! fp)
|
||||
grub_util_error ("cannot open %s", device_map);
|
||||
|
||||
|
@ -98,7 +98,7 @@ Generate a device map file automatically.\n\
|
|||
Report bugs to <%s>.\n\
|
||||
",
|
||||
DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
|
||||
|
||||
|
||||
exit (status);
|
||||
}
|
||||
|
||||
|
@ -107,14 +107,14 @@ main (int argc, char *argv[])
|
|||
{
|
||||
char *dev_map = 0;
|
||||
int floppy_disks = 1;
|
||||
|
||||
|
||||
progname = "grub-mkdevicemap";
|
||||
|
||||
|
||||
/* Check for options. */
|
||||
while (1)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "snm:r:hVv", options, 0);
|
||||
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
else
|
||||
|
@ -134,7 +134,7 @@ main (int argc, char *argv[])
|
|||
case 's':
|
||||
floppy_disks = 2;
|
||||
break;
|
||||
|
||||
|
||||
case 'h':
|
||||
usage (0);
|
||||
break;
|
||||
|
@ -156,6 +156,6 @@ main (int argc, char *argv[])
|
|||
make_device_map (dev_map ? : DEFAULT_DEVICE_MAP, floppy_disks);
|
||||
|
||||
free (dev_map);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -80,21 +80,21 @@ probe_partmap (grub_disk_t disk)
|
|||
{
|
||||
char *name;
|
||||
char *underscore;
|
||||
|
||||
|
||||
if (disk->partition == NULL)
|
||||
{
|
||||
grub_util_info ("No partition map found for %s", disk->name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
name = strdup (disk->partition->partmap->name);
|
||||
if (! name)
|
||||
grub_util_error ("Not enough memory");
|
||||
|
||||
|
||||
underscore = strchr (name, '_');
|
||||
if (! underscore)
|
||||
grub_util_error ("Invalid partition map %s", name);
|
||||
|
||||
|
||||
*underscore = '\0';
|
||||
printf ("%s\n", name);
|
||||
free (name);
|
||||
|
@ -109,7 +109,7 @@ probe (const char *path, char *device_name)
|
|||
int abstraction_type;
|
||||
grub_device_t dev = NULL;
|
||||
grub_fs_t fs;
|
||||
|
||||
|
||||
if (path == NULL)
|
||||
{
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
|
@ -134,7 +134,7 @@ probe (const char *path, char *device_name)
|
|||
|
||||
abstraction_type = grub_util_get_dev_abstraction (device_name);
|
||||
/* No need to check for errors; lack of abstraction is permissible. */
|
||||
|
||||
|
||||
if (print == PRINT_ABSTRACTION)
|
||||
{
|
||||
char *abstraction_name;
|
||||
|
@ -157,7 +157,7 @@ probe (const char *path, char *device_name)
|
|||
drive_name = grub_util_get_grub_dev (device_name);
|
||||
if (! drive_name)
|
||||
grub_util_error ("Cannot find a GRUB drive for %s. Check your device.map.\n", device_name);
|
||||
|
||||
|
||||
if (print == PRINT_DRIVE)
|
||||
{
|
||||
printf ("(%s)\n", drive_name);
|
||||
|
@ -206,15 +206,15 @@ probe (const char *path, char *device_name)
|
|||
grub_file_t file;
|
||||
grub_util_info ("reading %s via OS facilities", path);
|
||||
filebuf_via_sys = grub_util_read_image (path);
|
||||
|
||||
|
||||
grub_util_info ("reading %s via GRUB facilities", path);
|
||||
asprintf (&grub_path, "(%s)%s", drive_name, path);
|
||||
file = grub_file_open (grub_path);
|
||||
filebuf_via_grub = xmalloc (file->size);
|
||||
grub_file_read (file, filebuf_via_grub, file->size);
|
||||
|
||||
|
||||
grub_util_info ("comparing");
|
||||
|
||||
|
||||
if (memcmp (filebuf_via_grub, filebuf_via_sys, file->size))
|
||||
grub_util_error ("files differ");
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ Probe device information for a given path (or device, if the -d option is given)
|
|||
Report bugs to <%s>.\n\
|
||||
",
|
||||
DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
|
||||
|
||||
|
||||
exit (status);
|
||||
}
|
||||
|
||||
|
@ -284,14 +284,14 @@ main (int argc, char *argv[])
|
|||
{
|
||||
char *dev_map = 0;
|
||||
char *argument;
|
||||
|
||||
|
||||
progname = "grub-probe";
|
||||
|
||||
|
||||
/* Check for options. */
|
||||
while (1)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "dm:t:hVv", options, 0);
|
||||
|
||||
|
||||
if (c == -1)
|
||||
break;
|
||||
else
|
||||
|
@ -360,10 +360,10 @@ main (int argc, char *argv[])
|
|||
}
|
||||
|
||||
argument = argv[optind];
|
||||
|
||||
|
||||
/* Initialize the emulated biosdisk driver. */
|
||||
grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
|
||||
|
||||
|
||||
/* Initialize all modules. */
|
||||
grub_init_all ();
|
||||
|
||||
|
@ -372,12 +372,12 @@ main (int argc, char *argv[])
|
|||
probe (NULL, argument);
|
||||
else
|
||||
probe (argument, NULL);
|
||||
|
||||
|
||||
/* Free resources. */
|
||||
grub_fini_all ();
|
||||
grub_util_biosdisk_fini ();
|
||||
|
||||
|
||||
free (dev_map);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ case "${GRUB_FS}" in
|
|||
esac
|
||||
|
||||
for i in /hurd/${hurd_fs}.static /hurd/exec ; do
|
||||
if test -e "$i" ; then
|
||||
if test -e "$i" ; then
|
||||
echo "Found Hurd module: $i" >&2
|
||||
at_least_one=true
|
||||
else
|
||||
|
|
|
@ -52,7 +52,7 @@ EOF
|
|||
;;
|
||||
linux)
|
||||
LINUXPROBED="`linux-boot-prober ${DEVICE} 2> /dev/null | tr ' ' '^' | paste -s -d ' '`"
|
||||
|
||||
|
||||
for LINUX in ${LINUXPROBED} ; do
|
||||
LROOT="`echo ${LINUX} | cut -d ':' -f 1`"
|
||||
LBOOT="`echo ${LINUX} | cut -d ':' -f 2`"
|
||||
|
|
138
util/hostdisk.c
138
util/hostdisk.c
|
@ -160,12 +160,12 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
{
|
||||
int drive;
|
||||
struct stat st;
|
||||
|
||||
|
||||
drive = find_grub_drive (name);
|
||||
if (drive < 0)
|
||||
return grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
"no mapping exists for `%s'", name);
|
||||
|
||||
|
||||
disk->has_partitions = 1;
|
||||
disk->id = drive;
|
||||
|
||||
|
@ -203,7 +203,7 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
close (fd);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
if (ioctl (fd, DIOCGMEDIASIZE, &nr))
|
||||
# else
|
||||
|
@ -219,9 +219,9 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
|
||||
if (nr % 512)
|
||||
grub_util_error ("unaligned device size");
|
||||
|
||||
|
||||
grub_util_info ("the size of %s is %llu", name, disk->total_sectors);
|
||||
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
@ -234,9 +234,9 @@ grub_util_biosdisk_open (const char *name, grub_disk_t disk)
|
|||
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot stat `%s'", map[drive].device);
|
||||
|
||||
disk->total_sectors = st.st_size >> GRUB_DISK_SECTOR_BITS;
|
||||
|
||||
|
||||
grub_util_info ("the size of %s is %lu", name, disk->total_sectors);
|
||||
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
@ -314,18 +314,18 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
|||
#ifdef O_BINARY
|
||||
flags |= O_BINARY;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
/* Linux has a bug that the disk cache for a whole disk is not consistent
|
||||
with the one for a partition of the disk. */
|
||||
{
|
||||
int is_partition = 0;
|
||||
char dev[PATH_MAX];
|
||||
|
||||
|
||||
strcpy (dev, map[disk->id].device);
|
||||
if (disk->partition && strncmp (map[disk->id].device, "/dev/", 5) == 0)
|
||||
is_partition = linux_find_partition (dev, disk->partition->start);
|
||||
|
||||
|
||||
/* Open the partition. */
|
||||
grub_dprintf ("hostdisk", "opening the device `%s' in open_device()", dev);
|
||||
fd = open (dev, flags);
|
||||
|
@ -411,18 +411,18 @@ open_device (const grub_disk_t disk, grub_disk_addr_t sector, int flags)
|
|||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
/* Read LEN bytes from FD in BUF. Return less than or equal to zero if an
|
||||
error occurs, otherwise return LEN. */
|
||||
static ssize_t
|
||||
nread (int fd, char *buf, size_t len)
|
||||
{
|
||||
ssize_t size = len;
|
||||
|
||||
|
||||
while (len)
|
||||
{
|
||||
ssize_t ret = read (fd, buf, len);
|
||||
|
||||
|
||||
if (ret <= 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
|
@ -430,11 +430,11 @@ nread (int fd, char *buf, size_t len)
|
|||
else
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
len -= ret;
|
||||
buf += ret;
|
||||
}
|
||||
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -444,11 +444,11 @@ static ssize_t
|
|||
nwrite (int fd, const char *buf, size_t len)
|
||||
{
|
||||
ssize_t size = len;
|
||||
|
||||
|
||||
while (len)
|
||||
{
|
||||
ssize_t ret = write (fd, buf, len);
|
||||
|
||||
|
||||
if (ret <= 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
|
@ -456,11 +456,11 @@ nwrite (int fd, const char *buf, size_t len)
|
|||
else
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
len -= ret;
|
||||
buf += ret;
|
||||
}
|
||||
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -473,13 +473,13 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
fd = open_device (disk, sector, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
if (sector == 0 && size > 1)
|
||||
{
|
||||
/* Work around a bug in Linux ez remapping. Linux remaps all
|
||||
sectors that are read together with the MBR in one read. It
|
||||
should only remap the MBR, so we split the read in two
|
||||
should only remap the MBR, so we split the read in two
|
||||
parts. -jochen */
|
||||
if (nread (fd, buf, GRUB_DISK_SECTOR_SIZE) != GRUB_DISK_SECTOR_SIZE)
|
||||
{
|
||||
|
@ -487,12 +487,12 @@ grub_util_biosdisk_read (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
close (fd);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
|
||||
buf += GRUB_DISK_SECTOR_SIZE;
|
||||
size--;
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
|
||||
|
||||
if (nread (fd, buf, size << GRUB_DISK_SECTOR_BITS)
|
||||
!= (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
|
||||
grub_error (GRUB_ERR_READ_ERROR, "cannot read from `%s'", map[disk->id].device);
|
||||
|
@ -510,7 +510,7 @@ grub_util_biosdisk_write (grub_disk_t disk, grub_disk_addr_t sector,
|
|||
fd = open_device (disk, sector, O_WRONLY);
|
||||
if (fd < 0)
|
||||
return grub_errno;
|
||||
|
||||
|
||||
if (nwrite (fd, buf, size << GRUB_DISK_SECTOR_BITS)
|
||||
!= (ssize_t) (size << GRUB_DISK_SECTOR_BITS))
|
||||
grub_error (GRUB_ERR_WRITE_ERROR, "cannot write to `%s'", map[disk->id].device);
|
||||
|
@ -544,7 +544,7 @@ read_device_map (const char *dev_map)
|
|||
{
|
||||
grub_util_error ("%s:%d: %s", dev_map, lineno, msg);
|
||||
}
|
||||
|
||||
|
||||
fp = fopen (dev_map, "r");
|
||||
if (! fp)
|
||||
grub_util_error ("Cannot open `%s'", dev_map);
|
||||
|
@ -554,9 +554,9 @@ read_device_map (const char *dev_map)
|
|||
char *p = buf;
|
||||
char *e;
|
||||
int drive;
|
||||
|
||||
|
||||
lineno++;
|
||||
|
||||
|
||||
/* Skip leading spaces. */
|
||||
while (*p && isspace (*p))
|
||||
p++;
|
||||
|
@ -636,7 +636,7 @@ void
|
|||
grub_util_biosdisk_fini (void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
|
||||
for (i = 0; i < sizeof (map) / sizeof (map[0]); i++)
|
||||
{
|
||||
if (map[i].drive)
|
||||
|
@ -645,7 +645,7 @@ grub_util_biosdisk_fini (void)
|
|||
free (map[i].device);
|
||||
map[i].drive = map[i].device = NULL;
|
||||
}
|
||||
|
||||
|
||||
grub_disk_dev_unregister (&grub_util_biosdisk_dev);
|
||||
}
|
||||
|
||||
|
@ -672,13 +672,13 @@ make_device_name (int drive, int dos_part, int bsd_part)
|
|||
*/
|
||||
p = xmalloc (len + 2);
|
||||
sprintf (p, "%s", map[drive].drive);
|
||||
|
||||
|
||||
if (dos_part >= 0)
|
||||
sprintf (p + strlen (p), ",%d", dos_part + 1);
|
||||
|
||||
|
||||
if (bsd_part >= 0)
|
||||
sprintf (p + strlen (p), ",%c", bsd_part + 'a');
|
||||
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -689,7 +689,7 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
char *path = xmalloc (PATH_MAX);
|
||||
if (! realpath (os_dev, path))
|
||||
return 0;
|
||||
|
||||
|
||||
if (strncmp ("/dev/", path, 5) == 0)
|
||||
{
|
||||
char *p = path + 5;
|
||||
|
@ -700,20 +700,20 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
p = strstr (p, "part");
|
||||
if (p)
|
||||
strcpy (p, "disc");
|
||||
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/* If this is a SCSI disk. */
|
||||
if (strncmp ("scsi/", p, 5) == 0)
|
||||
{
|
||||
p = strstr (p, "part");
|
||||
if (p)
|
||||
strcpy (p, "disc");
|
||||
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/* If this is a DAC960 disk. */
|
||||
if (strncmp ("rd/c", p, 4) == 0)
|
||||
{
|
||||
|
@ -724,7 +724,7 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/* If this is a CCISS disk. */
|
||||
if (strncmp ("cciss/c", p, sizeof ("cciss/c") - 1) == 0)
|
||||
{
|
||||
|
@ -735,7 +735,7 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/* If this is a Compaq Intelligent Drive Array. */
|
||||
if (strncmp ("ida/c", p, sizeof ("ida/c") - 1) == 0)
|
||||
{
|
||||
|
@ -746,7 +746,7 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/* If this is an I2O disk. */
|
||||
if (strncmp ("i2o/hd", p, sizeof ("i2o/hd") - 1) == 0)
|
||||
{
|
||||
|
@ -754,7 +754,7 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
p[sizeof ("i2o/hda") - 1] = '\0';
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/* If this is a MultiMediaCard (MMC). */
|
||||
if (strncmp ("mmcblk", p, sizeof ("mmcblk") - 1) == 0)
|
||||
{
|
||||
|
@ -765,7 +765,7 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
/* If this is an IDE, SCSI or Virtio disk. */
|
||||
if (strncmp ("vdisk", p, 5) == 0
|
||||
&& p[5] >= 'a' && p[5] <= 'z')
|
||||
|
@ -794,7 +794,7 @@ convert_system_partition_to_system_disk (const char *os_dev)
|
|||
}
|
||||
|
||||
return path;
|
||||
|
||||
|
||||
#elif defined(__GNU__)
|
||||
char *path = xstrdup (os_dev);
|
||||
if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0)
|
||||
|
@ -852,7 +852,7 @@ find_system_device (const char *os_dev)
|
|||
os_disk = convert_system_partition_to_system_disk (os_dev);
|
||||
if (! os_disk)
|
||||
return -1;
|
||||
|
||||
|
||||
for (i = 0; i < (int) (sizeof (map) / sizeof (map[0])); i++)
|
||||
if (map[i].device && strcmp (map[i].device, os_disk) == 0)
|
||||
{
|
||||
|
@ -884,17 +884,17 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (grub_strcmp (os_dev, convert_system_partition_to_system_disk (os_dev))
|
||||
if (grub_strcmp (os_dev, convert_system_partition_to_system_disk (os_dev))
|
||||
== 0)
|
||||
return make_device_name (drive, -1, -1);
|
||||
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
if (! S_ISCHR (st.st_mode))
|
||||
#else
|
||||
if (! S_ISBLK (st.st_mode))
|
||||
#endif
|
||||
return make_device_name (drive, -1, -1);
|
||||
|
||||
|
||||
#if defined(__linux__) || defined(__CYGWIN__)
|
||||
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
|
||||
partition, so mapping them to GRUB devices is not trivial.
|
||||
|
@ -913,7 +913,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
int bsd_part = -1;
|
||||
auto int find_partition (grub_disk_t disk,
|
||||
const grub_partition_t partition);
|
||||
|
||||
|
||||
int find_partition (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t partition)
|
||||
{
|
||||
|
@ -921,7 +921,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
|
||||
if (strcmp (partition->partmap->name, "pc_partition_map") == 0)
|
||||
pcdata = partition->data;
|
||||
|
||||
|
||||
if (pcdata)
|
||||
{
|
||||
if (pcdata->bsd_part < 0)
|
||||
|
@ -937,7 +937,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
grub_util_info ("Partition %d starts from %lu",
|
||||
partition->index, partition->start);
|
||||
}
|
||||
|
||||
|
||||
if (hdg.start == partition->start)
|
||||
{
|
||||
if (pcdata)
|
||||
|
@ -952,15 +952,15 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
name = make_device_name (drive, -1, -1);
|
||||
|
||||
|
||||
if (MAJOR (st.st_rdev) == FLOPPY_MAJOR)
|
||||
return name;
|
||||
|
||||
|
||||
fd = open (os_dev, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
|
@ -968,7 +968,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
free (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (ioctl (fd, HDIO_GETGEO, &hdg))
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
|
@ -977,28 +977,28 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
free (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
close (fd);
|
||||
|
||||
grub_util_info ("%s starts from %lu", os_dev, hdg.start);
|
||||
|
||||
|
||||
if (hdg.start == 0 && device_is_wholedisk (os_dev))
|
||||
return name;
|
||||
|
||||
grub_util_info ("opening the device %s", name);
|
||||
disk = grub_disk_open (name);
|
||||
free (name);
|
||||
|
||||
|
||||
if (! disk)
|
||||
return 0;
|
||||
|
||||
|
||||
grub_partition_iterate (disk, find_partition);
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
{
|
||||
grub_disk_close (disk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (dos_part < 0)
|
||||
{
|
||||
grub_disk_close (disk);
|
||||
|
@ -1006,43 +1006,43 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
"cannot find the partition of `%s'", os_dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return make_device_name (drive, dos_part, bsd_part);
|
||||
}
|
||||
|
||||
|
||||
#elif defined(__GNU__)
|
||||
/* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?". */
|
||||
{
|
||||
char *p;
|
||||
int dos_part = -1;
|
||||
int bsd_part = -1;
|
||||
|
||||
|
||||
p = strrchr (os_dev, 's');
|
||||
if (p)
|
||||
{
|
||||
long int n;
|
||||
char *q;
|
||||
|
||||
|
||||
p++;
|
||||
n = strtol (p, &q, 10);
|
||||
if (p != q && n != GRUB_LONG_MIN && n != GRUB_LONG_MAX)
|
||||
{
|
||||
dos_part = (int) n;
|
||||
|
||||
|
||||
if (*q >= 'a' && *q <= 'g')
|
||||
bsd_part = *q - 'a';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return make_device_name (drive, dos_part, bsd_part);
|
||||
}
|
||||
|
||||
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
/* FreeBSD uses "/dev/[a-z]+[0-9]+(s[0-9]+[a-z]?)?". */
|
||||
{
|
||||
int dos_part = -1;
|
||||
int bsd_part = -1;
|
||||
|
||||
|
||||
if (strncmp ("/dev/", os_dev, 5) == 0)
|
||||
{
|
||||
char *p, *q;
|
||||
|
@ -1067,7 +1067,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return make_device_name (drive, dos_part, bsd_part);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@ is_dir (const char *path, const char *name)
|
|||
#endif
|
||||
|
||||
static grub_err_t
|
||||
grub_hostfs_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
grub_hostfs_dir (grub_device_t device, const char *path,
|
||||
int (*hook) (const char *filename,
|
||||
const struct grub_dirhook_info *info))
|
||||
{
|
||||
DIR *dir;
|
||||
|
|
|
@ -92,7 +92,7 @@ read_kernel_module (const char *dir, size_t *size)
|
|||
{
|
||||
char *kernel_image;
|
||||
char *kernel_path;
|
||||
|
||||
|
||||
kernel_path = grub_util_get_path (dir, "kernel.mod");
|
||||
*size = grub_util_get_image_size (kernel_path);
|
||||
kernel_image = grub_util_read_image (kernel_path);
|
||||
|
@ -162,7 +162,7 @@ locate_sections (Elf_Shdr *sections, Elf_Half section_entsize,
|
|||
Elf_Addr current_address;
|
||||
Elf_Addr *section_addresses;
|
||||
Elf_Shdr *s;
|
||||
|
||||
|
||||
section_addresses = xmalloc (sizeof (*section_addresses) * num_sections);
|
||||
memset (section_addresses, 0, sizeof (*section_addresses) * num_sections);
|
||||
|
||||
|
@ -176,10 +176,10 @@ locate_sections (Elf_Shdr *sections, Elf_Half section_entsize,
|
|||
{
|
||||
Elf_Word align = grub_le_to_cpu32 (s->sh_addralign);
|
||||
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
||||
|
||||
|
||||
if (align)
|
||||
current_address = align_address (current_address, align);
|
||||
|
||||
|
||||
grub_util_info ("locating the section %s at 0x%x",
|
||||
name, current_address);
|
||||
section_addresses[i] = current_address;
|
||||
|
@ -196,10 +196,10 @@ locate_sections (Elf_Shdr *sections, Elf_Half section_entsize,
|
|||
{
|
||||
Elf_Word align = grub_le_to_cpu32 (s->sh_addralign);
|
||||
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
||||
|
||||
|
||||
if (align)
|
||||
current_address = align_address (current_address, align);
|
||||
|
||||
|
||||
grub_util_info ("locating the section %s at 0x%x",
|
||||
name, current_address);
|
||||
section_addresses[i] = current_address;
|
||||
|
@ -216,7 +216,7 @@ find_symtab_section (Elf_Shdr *sections,
|
|||
{
|
||||
int i;
|
||||
Elf_Shdr *s;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -232,7 +232,7 @@ find_strtab (Elf_Ehdr *e, Elf_Shdr *sections, Elf_Half section_entsize)
|
|||
{
|
||||
Elf_Shdr *s;
|
||||
char *strtab;
|
||||
|
||||
|
||||
s = (Elf_Shdr *) ((char *) sections
|
||||
+ grub_le_to_cpu16 (e->e_shstrndx) * section_entsize);
|
||||
strtab = (char *) e + grub_le_to_cpu32 (s->sh_offset);
|
||||
|
@ -253,13 +253,13 @@ relocate_symbols (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
Elf_Word i;
|
||||
Elf_Shdr *strtab_section;
|
||||
const char *strtab;
|
||||
|
||||
|
||||
strtab_section
|
||||
= (Elf_Shdr *) ((char *) sections
|
||||
+ (grub_le_to_cpu32 (symtab_section->sh_link)
|
||||
* section_entsize));
|
||||
strtab = (char *) e + grub_le_to_cpu32 (strtab_section->sh_offset);
|
||||
|
||||
|
||||
symtab_size = grub_le_to_cpu32 (symtab_section->sh_size);
|
||||
sym_size = grub_le_to_cpu32 (symtab_section->sh_entsize);
|
||||
symtab_offset = grub_le_to_cpu32 (symtab_section->sh_offset);
|
||||
|
@ -271,9 +271,9 @@ relocate_symbols (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
{
|
||||
Elf_Section index;
|
||||
const char *name;
|
||||
|
||||
|
||||
name = strtab + grub_le_to_cpu32 (sym->st_name);
|
||||
|
||||
|
||||
index = grub_le_to_cpu16 (sym->st_shndx);
|
||||
if (index == STN_ABS)
|
||||
{
|
||||
|
@ -288,7 +288,7 @@ relocate_symbols (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
}
|
||||
else if (index >= num_sections)
|
||||
grub_util_error ("section %d does not exist", index);
|
||||
|
||||
|
||||
sym->st_value = (grub_le_to_cpu32 (sym->st_value)
|
||||
+ section_addresses[index]);
|
||||
grub_util_info ("locating %s at 0x%x", name, sym->st_value);
|
||||
|
@ -306,7 +306,7 @@ static Elf_Addr
|
|||
get_symbol_address (Elf_Ehdr *e, Elf_Shdr *s, Elf_Word i)
|
||||
{
|
||||
Elf_Sym *sym;
|
||||
|
||||
|
||||
sym = (Elf_Sym *) ((char *) e
|
||||
+ grub_le_to_cpu32 (s->sh_offset)
|
||||
+ i * grub_le_to_cpu32 (s->sh_entsize));
|
||||
|
@ -332,7 +332,7 @@ relocate_addresses (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
{
|
||||
Elf_Half i;
|
||||
Elf_Shdr *s;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -375,7 +375,7 @@ relocate_addresses (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
Elf_Addr sym_addr;
|
||||
Elf_Addr *target;
|
||||
Elf_Addr addend;
|
||||
|
||||
|
||||
offset = grub_le_to_cpu (r->r_offset);
|
||||
target = get_target_address (e, target_section, offset);
|
||||
info = grub_le_to_cpu (r->r_info);
|
||||
|
@ -414,7 +414,7 @@ relocate_addresses (Elf_Ehdr *e, Elf_Shdr *sections,
|
|||
break;
|
||||
|
||||
case R_X86_64_64:
|
||||
*target = grub_cpu_to_le64 (grub_le_to_cpu64 (*target)
|
||||
*target = grub_cpu_to_le64 (grub_le_to_cpu64 (*target)
|
||||
+ addend + sym_addr);
|
||||
grub_util_info ("relocating an R_X86_64_64 entry to 0x%llx at the offset 0x%llx",
|
||||
*target, offset);
|
||||
|
@ -470,7 +470,7 @@ add_fixup_entry (struct grub_pe32_fixup_block **block, grub_uint16_t type,
|
|||
FILE *out)
|
||||
{
|
||||
struct grub_pe32_fixup_block *b = *block;
|
||||
|
||||
|
||||
/* First, check if it is necessary to write out the current block. */
|
||||
if (b)
|
||||
{
|
||||
|
@ -485,7 +485,7 @@ add_fixup_entry (struct grub_pe32_fixup_block **block, grub_uint16_t type,
|
|||
Elf_Addr next_address;
|
||||
unsigned padding_size;
|
||||
size_t index;
|
||||
|
||||
|
||||
next_address = current_address + b->block_size;
|
||||
padding_size = ((align_pe32_section (next_address)
|
||||
- next_address)
|
||||
|
@ -528,7 +528,7 @@ add_fixup_entry (struct grub_pe32_fixup_block **block, grub_uint16_t type,
|
|||
{
|
||||
grub_uint16_t entry;
|
||||
size_t index;
|
||||
|
||||
|
||||
/* If not allocated yet, allocate a block with enough entries. */
|
||||
if (! b)
|
||||
{
|
||||
|
@ -559,7 +559,7 @@ static Elf_Addr
|
|||
make_header_space (FILE *out)
|
||||
{
|
||||
Elf_Addr addr;
|
||||
|
||||
|
||||
addr = get_starting_section_address ();
|
||||
write_padding (out, addr);
|
||||
|
||||
|
@ -576,7 +576,7 @@ write_text_sections (FILE *out, Elf_Addr current_address,
|
|||
Elf_Half i;
|
||||
Elf_Shdr *s;
|
||||
Elf_Addr addr;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -586,7 +586,7 @@ write_text_sections (FILE *out, Elf_Addr current_address,
|
|||
Elf_Off offset = grub_le_to_cpu32 (s->sh_offset);
|
||||
Elf_Word size = grub_le_to_cpu32 (s->sh_size);
|
||||
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
||||
|
||||
|
||||
if (align)
|
||||
{
|
||||
addr = align_address (current_address, align);
|
||||
|
@ -598,13 +598,13 @@ write_text_sections (FILE *out, Elf_Addr current_address,
|
|||
current_address = addr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
grub_util_info ("writing the text section %s at 0x%x",
|
||||
name, current_address);
|
||||
|
||||
|
||||
if (fwrite ((char *) e + offset, size, 1, out) != 1)
|
||||
grub_util_error ("write failed");
|
||||
|
||||
|
||||
current_address += size;
|
||||
}
|
||||
|
||||
|
@ -615,7 +615,7 @@ write_text_sections (FILE *out, Elf_Addr current_address,
|
|||
addr - current_address);
|
||||
write_padding (out, addr - current_address);
|
||||
}
|
||||
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
@ -629,7 +629,7 @@ write_data_sections (FILE *out, Elf_Addr current_address,
|
|||
Elf_Half i;
|
||||
Elf_Shdr *s;
|
||||
Elf_Addr addr;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -639,7 +639,7 @@ write_data_sections (FILE *out, Elf_Addr current_address,
|
|||
Elf_Off offset = grub_le_to_cpu32 (s->sh_offset);
|
||||
Elf_Word size = grub_le_to_cpu32 (s->sh_size);
|
||||
const char *name = strtab + grub_le_to_cpu32 (s->sh_name);
|
||||
|
||||
|
||||
if (align)
|
||||
{
|
||||
addr = align_address (current_address, align);
|
||||
|
@ -651,19 +651,19 @@ write_data_sections (FILE *out, Elf_Addr current_address,
|
|||
current_address = addr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
grub_util_info ("writing the data section %s at 0x%x",
|
||||
name, current_address);
|
||||
|
||||
|
||||
if (s->sh_type == grub_cpu_to_le32 (SHT_NOBITS))
|
||||
write_padding (out, size);
|
||||
else
|
||||
if (fwrite ((char *) e + offset, size, 1, out) != 1)
|
||||
grub_util_error ("write failed");
|
||||
|
||||
|
||||
current_address += size;
|
||||
}
|
||||
|
||||
|
||||
addr = align_pe32_section (current_address);
|
||||
if (addr != current_address)
|
||||
{
|
||||
|
@ -671,7 +671,7 @@ write_data_sections (FILE *out, Elf_Addr current_address,
|
|||
addr - current_address);
|
||||
write_padding (out, addr - current_address);
|
||||
}
|
||||
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
@ -689,7 +689,7 @@ make_mods_section (FILE *out, Elf_Addr current_address,
|
|||
memset (&modinfo, 0, sizeof (modinfo));
|
||||
|
||||
path_list = grub_util_resolve_dependencies (dir, "moddep.lst", mods);
|
||||
|
||||
|
||||
total_module_size = sizeof (struct grub_module_info);
|
||||
for (p = path_list; p; p = p->next)
|
||||
{
|
||||
|
@ -711,15 +711,15 @@ make_mods_section (FILE *out, Elf_Addr current_address,
|
|||
struct grub_module_header header;
|
||||
size_t mod_size;
|
||||
char *mod_image;
|
||||
|
||||
|
||||
memset (&header, 0, sizeof (header));
|
||||
|
||||
|
||||
grub_util_info ("adding module %s", p->name);
|
||||
|
||||
|
||||
mod_size = grub_util_get_image_size (p->name);
|
||||
header.type = grub_cpu_to_le32 (OBJ_TYPE_ELF);
|
||||
header.size = grub_cpu_to_le32 (mod_size + sizeof (header));
|
||||
|
||||
|
||||
mod_image = grub_util_read_image (p->name);
|
||||
|
||||
if (fwrite (&header, sizeof (header), 1, out) != 1
|
||||
|
@ -728,7 +728,7 @@ make_mods_section (FILE *out, Elf_Addr current_address,
|
|||
|
||||
free (mod_image);
|
||||
}
|
||||
|
||||
|
||||
for (p = path_list; p; )
|
||||
{
|
||||
struct grub_util_path_list *q;
|
||||
|
@ -737,9 +737,9 @@ make_mods_section (FILE *out, Elf_Addr current_address,
|
|||
free (p);
|
||||
p = q;
|
||||
}
|
||||
|
||||
|
||||
current_address += total_module_size;
|
||||
|
||||
|
||||
addr = align_pe32_section (current_address);
|
||||
if (addr != current_address)
|
||||
{
|
||||
|
@ -761,7 +761,7 @@ make_reloc_section (FILE *out, Elf_Addr current_address, Elf_Ehdr *e,
|
|||
Elf_Half i;
|
||||
Elf_Shdr *s;
|
||||
struct grub_pe32_fixup_block *fixup_block = 0;
|
||||
|
||||
|
||||
for (i = 0, s = sections;
|
||||
i < num_sections;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
|
||||
|
@ -773,15 +773,15 @@ make_reloc_section (FILE *out, Elf_Addr current_address, Elf_Ehdr *e,
|
|||
Elf_Off rtab_offset;
|
||||
Elf_Addr section_address;
|
||||
Elf_Word j;
|
||||
|
||||
|
||||
grub_util_info ("translating the relocation section %s",
|
||||
strtab + grub_le_to_cpu32 (s->sh_name));
|
||||
|
||||
|
||||
rtab_size = grub_le_to_cpu32 (s->sh_size);
|
||||
r_size = grub_le_to_cpu32 (s->sh_entsize);
|
||||
rtab_offset = grub_le_to_cpu32 (s->sh_offset);
|
||||
num_rs = rtab_size / r_size;
|
||||
|
||||
|
||||
section_address = section_addresses[grub_le_to_cpu32 (s->sh_info)];
|
||||
|
||||
for (j = 0, r = (Elf_Rel *) ((char *) e + rtab_offset);
|
||||
|
@ -888,7 +888,7 @@ make_header (FILE *out, Elf_Addr text_address, Elf_Addr data_address,
|
|||
o->image_size = grub_cpu_to_le32 (end_address);
|
||||
o->header_size = grub_cpu_to_le32 (text_address);
|
||||
o->subsystem = grub_cpu_to_le16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION);
|
||||
|
||||
|
||||
/* Do these really matter? */
|
||||
o->stack_reserve_size = grub_cpu_to_le32 (0x10000);
|
||||
o->stack_commit_size = grub_cpu_to_le32 (0x10000);
|
||||
|
@ -896,7 +896,7 @@ make_header (FILE *out, Elf_Addr text_address, Elf_Addr data_address,
|
|||
o->heap_commit_size = grub_cpu_to_le32 (0x10000);
|
||||
|
||||
o->num_data_directories = grub_cpu_to_le32 (GRUB_PE32_NUM_DATA_DIRECTORIES);
|
||||
|
||||
|
||||
o->base_relocation_table.rva = grub_cpu_to_le32 (reloc_address);
|
||||
o->base_relocation_table.size = grub_cpu_to_le32 (end_address
|
||||
- reloc_address);
|
||||
|
@ -982,7 +982,7 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[])
|
|||
e = (Elf_Ehdr *) kernel_image;
|
||||
if (! check_elf_header (e, kernel_size))
|
||||
grub_util_error ("invalid ELF header");
|
||||
|
||||
|
||||
section_offset = grub_cpu_to_le32 (e->e_shoff);
|
||||
section_entsize = grub_cpu_to_le16 (e->e_shentsize);
|
||||
num_sections = grub_cpu_to_le16 (e->e_shnum);
|
||||
|
@ -1002,20 +1002,20 @@ convert_elf (const char *dir, char *prefix, FILE *out, char *mods[])
|
|||
|
||||
if (GRUB_KERNEL_MACHINE_PREFIX + strlen (prefix) + 1 > GRUB_KERNEL_MACHINE_DATA_END)
|
||||
grub_util_error ("prefix too long");
|
||||
|
||||
|
||||
strcpy (kernel_image + offset + GRUB_KERNEL_MACHINE_PREFIX, prefix);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Relocate sections then symbols in the virtual address space. */
|
||||
section_addresses = locate_sections (sections, section_entsize,
|
||||
num_sections, strtab);
|
||||
|
||||
|
||||
symtab_section = find_symtab_section (sections,
|
||||
section_entsize, num_sections);
|
||||
if (! symtab_section)
|
||||
grub_util_error ("no symbol table");
|
||||
|
||||
|
||||
start_address = relocate_symbols (e, sections, symtab_section,
|
||||
section_addresses, section_entsize,
|
||||
num_sections);
|
||||
|
|
|
@ -58,11 +58,11 @@ compress_kernel (char *kernel_img, size_t kernel_size,
|
|||
{
|
||||
lzo_uint size;
|
||||
char *wrkmem;
|
||||
|
||||
|
||||
grub_util_info ("kernel_img=%p, kernel_size=0x%x", kernel_img, kernel_size);
|
||||
if (kernel_size < GRUB_KERNEL_MACHINE_RAW_SIZE)
|
||||
grub_util_error ("the core image is too small");
|
||||
|
||||
|
||||
if (lzo_init () != LZO_E_OK)
|
||||
grub_util_error ("cannot initialize LZO");
|
||||
|
||||
|
@ -70,7 +70,7 @@ compress_kernel (char *kernel_img, size_t kernel_size,
|
|||
wrkmem = xmalloc (LZO1X_999_MEM_COMPRESS);
|
||||
|
||||
memcpy (*core_img, kernel_img, GRUB_KERNEL_MACHINE_RAW_SIZE);
|
||||
|
||||
|
||||
grub_util_info ("compressing the core image");
|
||||
if (lzo1x_999_compress ((const lzo_byte *) (kernel_img
|
||||
+ GRUB_KERNEL_MACHINE_RAW_SIZE),
|
||||
|
@ -189,7 +189,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
size_t mod_size;
|
||||
|
||||
mod_size = grub_util_get_image_size (p->name);
|
||||
|
||||
|
||||
header = (struct grub_module_header *) (kernel_img + offset);
|
||||
header->type = grub_cpu_to_le32 (OBJ_TYPE_ELF);
|
||||
header->size = grub_cpu_to_le32 (mod_size + sizeof (*header));
|
||||
|
@ -202,7 +202,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
if (memdisk_path)
|
||||
{
|
||||
struct grub_module_header *header;
|
||||
|
||||
|
||||
header = (struct grub_module_header *) (kernel_img + offset);
|
||||
header->type = grub_cpu_to_le32 (OBJ_TYPE_MEMDISK);
|
||||
header->size = grub_cpu_to_le32 (memdisk_size + sizeof (*header));
|
||||
|
@ -230,7 +230,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
&core_img, &core_size);
|
||||
|
||||
grub_util_info ("the core size is 0x%x", core_size);
|
||||
|
||||
|
||||
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
|
||||
if (num > 0xffff)
|
||||
grub_util_error ("the core image is too big");
|
||||
|
@ -239,9 +239,9 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
boot_size = grub_util_get_image_size (boot_path);
|
||||
if (boot_size != GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("diskboot.img is not one sector size");
|
||||
|
||||
|
||||
boot_img = grub_util_read_image (boot_path);
|
||||
|
||||
|
||||
/* i386 is a little endian architecture. */
|
||||
*((grub_uint16_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
|
||||
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
|
||||
|
@ -250,7 +250,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
grub_util_write_image (boot_img, boot_size, out);
|
||||
free (boot_img);
|
||||
free (boot_path);
|
||||
|
||||
|
||||
module_addr = (path_list
|
||||
? (GRUB_BOOT_MACHINE_KERNEL_ADDR + GRUB_DISK_SECTOR_SIZE
|
||||
+ kernel_size)
|
||||
|
@ -277,7 +277,7 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
|
|||
if (core_size > GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR)
|
||||
grub_util_error ("Core image is too big (%p > %p)\n", core_size,
|
||||
GRUB_MEMORY_MACHINE_UPPER - GRUB_MEMORY_MACHINE_LINK_ADDR);
|
||||
|
||||
|
||||
grub_util_write_image (core_img, core_size, out);
|
||||
free (kernel_img);
|
||||
free (core_img);
|
||||
|
@ -344,7 +344,7 @@ main (int argc, char *argv[])
|
|||
FILE *fp = stdout;
|
||||
|
||||
progname = "grub-mkimage";
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
int c = getopt_long (argc, argv, "d:p:m:c:o:hVv", options, 0);
|
||||
|
@ -357,7 +357,7 @@ main (int argc, char *argv[])
|
|||
case 'o':
|
||||
if (output)
|
||||
free (output);
|
||||
|
||||
|
||||
output = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
|
@ -373,7 +373,7 @@ main (int argc, char *argv[])
|
|||
free (memdisk);
|
||||
|
||||
memdisk = xstrdup (optarg);
|
||||
|
||||
|
||||
if (prefix)
|
||||
free (prefix);
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ setup (const char *dir,
|
|||
FILE *fp;
|
||||
struct { grub_uint64_t start; grub_uint64_t end; } embed_region;
|
||||
embed_region.start = embed_region.end = ~0UL;
|
||||
|
||||
|
||||
auto void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
|
||||
unsigned length);
|
||||
auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
|
||||
|
@ -122,44 +122,44 @@ setup (const char *dir,
|
|||
const grub_partition_t p)
|
||||
{
|
||||
struct grub_pc_partition *pcdata = p->data;
|
||||
|
||||
|
||||
/* There's always an embed region, and it starts right after the MBR. */
|
||||
embed_region.start = 1;
|
||||
|
||||
|
||||
/* For its end offset, include as many dummy partitions as we can. */
|
||||
if (! grub_pc_partition_is_empty (pcdata->dos_type)
|
||||
&& ! grub_pc_partition_is_bsd (pcdata->dos_type)
|
||||
&& embed_region.end > p->start)
|
||||
embed_region.end = p->start;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
auto int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk,
|
||||
const grub_partition_t p);
|
||||
int NESTED_FUNC_ATTR find_usable_region_gpt (grub_disk_t disk __attribute__ ((unused)),
|
||||
const grub_partition_t p)
|
||||
{
|
||||
struct grub_gpt_partentry *gptdata = p->data;
|
||||
|
||||
|
||||
/* If there's an embed region, it is in a dedicated partition. */
|
||||
if (! memcmp (&gptdata->type, &grub_gpt_partition_type_bios_boot, 16))
|
||||
{
|
||||
embed_region.start = p->start;
|
||||
embed_region.end = p->start + p->len;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void NESTED_FUNC_ATTR save_first_sector (grub_disk_addr_t sector, unsigned offset,
|
||||
unsigned length)
|
||||
{
|
||||
grub_util_info ("the first sector is <%llu,%u,%u>",
|
||||
sector, offset, length);
|
||||
|
||||
|
||||
if (offset != 0 || length != GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("The first sector of the core file is not sector-aligned");
|
||||
|
||||
|
@ -173,7 +173,7 @@ setup (const char *dir,
|
|||
|
||||
grub_util_info ("saving <%llu,%u,%u> with the segment 0x%x",
|
||||
sector, offset, length, (unsigned) current_segment);
|
||||
|
||||
|
||||
if (offset != 0 || last_length != GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("Non-sector-aligned data is found in the core file");
|
||||
|
||||
|
@ -191,11 +191,11 @@ setup (const char *dir,
|
|||
if (block->len)
|
||||
grub_util_error ("The sectors of the core file are too fragmented");
|
||||
}
|
||||
|
||||
|
||||
last_length = length;
|
||||
current_segment += GRUB_DISK_SECTOR_SIZE >> 4;
|
||||
}
|
||||
|
||||
|
||||
/* Read the boot image by the OS service. */
|
||||
boot_path = grub_util_get_path (dir, boot_file);
|
||||
boot_size = grub_util_get_image_size (boot_path);
|
||||
|
@ -212,7 +212,7 @@ setup (const char *dir,
|
|||
+ GRUB_BOOT_MACHINE_KERNEL_SECTOR);
|
||||
boot_drive_check = (grub_uint16_t *) (boot_img
|
||||
+ GRUB_BOOT_MACHINE_DRIVE_CHECK);
|
||||
|
||||
|
||||
core_path = grub_util_get_path (dir, core_file);
|
||||
core_size = grub_util_get_image_size (core_path);
|
||||
core_sectors = ((core_size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
|
@ -221,7 +221,7 @@ setup (const char *dir,
|
|||
grub_util_error ("The size of `%s' is too small", core_path);
|
||||
else if (core_size > 0xFFFF * GRUB_DISK_SECTOR_SIZE)
|
||||
grub_util_error ("The size of `%s' is too large", core_path);
|
||||
|
||||
|
||||
core_img = grub_util_read_image (core_path);
|
||||
|
||||
/* Have FIRST_BLOCK to point to the first blocklist. */
|
||||
|
@ -264,7 +264,7 @@ setup (const char *dir,
|
|||
GRUB_BOOT_MACHINE_PART_END - GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC);
|
||||
|
||||
free (tmp_img);
|
||||
|
||||
|
||||
/* If DEST_DRIVE is a hard disk, enable the workaround, which is
|
||||
for buggy BIOSes which don't pass boot drive correctly. Instead,
|
||||
they pass 0x00 or 0x01 even when booted from 0x80. */
|
||||
|
@ -304,7 +304,7 @@ setup (const char *dir,
|
|||
dos_part = grub_le_to_cpu32 (*install_dos_part);
|
||||
bsd_part = grub_le_to_cpu32 (*install_bsd_part);
|
||||
}
|
||||
|
||||
|
||||
grub_util_info ("dos partition is %d, bsd partition is %d",
|
||||
dos_part, bsd_part);
|
||||
|
||||
|
@ -319,7 +319,7 @@ setup (const char *dir,
|
|||
grub_util_warn ("Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea.");
|
||||
goto unable_to_embed;
|
||||
}
|
||||
|
||||
|
||||
/* Unlike root_dev, with dest_dev we're interested in the partition map even
|
||||
if dest_dev itself is a whole disk. */
|
||||
auto int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk,
|
||||
|
@ -331,7 +331,7 @@ setup (const char *dir,
|
|||
return 1;
|
||||
}
|
||||
grub_partition_iterate (dest_dev->disk, identify_partmap);
|
||||
|
||||
|
||||
grub_partition_iterate (dest_dev->disk, (strcmp (dest_partmap, "pc_partition_map") ?
|
||||
find_usable_region_gpt : find_usable_region_msdos));
|
||||
if (embed_region.end == embed_region.start)
|
||||
|
@ -356,69 +356,69 @@ setup (const char *dir,
|
|||
|
||||
|
||||
grub_util_info ("will embed the core image at sector 0x%llx", embed_region.start);
|
||||
|
||||
|
||||
*install_dos_part = grub_cpu_to_le32 (dos_part);
|
||||
*install_bsd_part = grub_cpu_to_le32 (bsd_part);
|
||||
|
||||
|
||||
/* The first blocklist contains the whole sectors. */
|
||||
first_block->start = grub_cpu_to_le64 (embed_region.start + 1);
|
||||
first_block->len = grub_cpu_to_le16 (core_sectors - 1);
|
||||
first_block->segment
|
||||
= grub_cpu_to_le16 (GRUB_BOOT_MACHINE_KERNEL_SEG
|
||||
+ (GRUB_DISK_SECTOR_SIZE >> 4));
|
||||
|
||||
|
||||
/* Make sure that the second blocklist is a terminator. */
|
||||
block = first_block - 1;
|
||||
block->start = 0;
|
||||
block->len = 0;
|
||||
block->segment = 0;
|
||||
|
||||
|
||||
/* Write the core image onto the disk. */
|
||||
if (grub_disk_write (dest_dev->disk, embed_region.start, 0, core_size, core_img))
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
|
||||
/* FIXME: can this be skipped? */
|
||||
*boot_drive = 0xFF;
|
||||
*root_drive = 0xFF;
|
||||
|
||||
|
||||
*kernel_sector = grub_cpu_to_le64 (embed_region.start);
|
||||
|
||||
|
||||
/* Write the boot image onto the disk. */
|
||||
if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE,
|
||||
boot_img))
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
|
||||
goto finish;
|
||||
|
||||
|
||||
unable_to_embed:
|
||||
|
||||
|
||||
if (must_embed)
|
||||
grub_util_error ("Embedding is not possible, but this is required when "
|
||||
"the root device is on a RAID array or LVM volume.");
|
||||
|
||||
|
||||
grub_util_warn ("Embedding is not possible. GRUB can only be installed in this "
|
||||
"setup by using blocklists. However, blocklists are UNRELIABLE and "
|
||||
"its use is discouraged.");
|
||||
if (! force)
|
||||
grub_util_error ("If you really want blocklists, use --force.");
|
||||
|
||||
|
||||
/* Make sure that GRUB reads the identical image as the OS. */
|
||||
tmp_img = xmalloc (core_size);
|
||||
core_path_dev = grub_util_get_path (dir, core_file);
|
||||
|
||||
|
||||
/* It is a Good Thing to sync two times. */
|
||||
sync ();
|
||||
sync ();
|
||||
|
||||
#define MAX_TRIES 5
|
||||
|
||||
|
||||
for (i = 0; i < MAX_TRIES; i++)
|
||||
{
|
||||
grub_util_info ("attempting to read the core image `%s' from GRUB%s",
|
||||
core_path_dev, (i == 0) ? "" : " again");
|
||||
|
||||
|
||||
grub_disk_cache_invalidate_all ();
|
||||
|
||||
|
||||
file = grub_file_open (core_path_dev);
|
||||
if (file)
|
||||
{
|
||||
|
@ -434,7 +434,7 @@ unable_to_embed:
|
|||
#if 0
|
||||
FILE *dump;
|
||||
FILE *dump2;
|
||||
|
||||
|
||||
dump = fopen ("dump.img", "wb");
|
||||
if (dump)
|
||||
{
|
||||
|
@ -448,8 +448,8 @@ unable_to_embed:
|
|||
fwrite (core_img, 1, core_size, dump2);
|
||||
fclose (dump2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
grub_util_info ("succeeded in opening the core image but the data is different");
|
||||
}
|
||||
else
|
||||
|
@ -465,7 +465,7 @@ unable_to_embed:
|
|||
|
||||
if (grub_errno)
|
||||
grub_util_info ("error message = %s", grub_errmsg);
|
||||
|
||||
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
sync ();
|
||||
sleep (1);
|
||||
|
@ -483,16 +483,16 @@ unable_to_embed:
|
|||
block->segment = 0;
|
||||
|
||||
block--;
|
||||
|
||||
|
||||
if ((char *) block <= core_img)
|
||||
grub_util_error ("No terminator in the core image");
|
||||
}
|
||||
|
||||
|
||||
/* Now read the core image to determine where the sectors are. */
|
||||
file = grub_file_open (core_path_dev);
|
||||
if (! file)
|
||||
grub_util_error ("%s", grub_errmsg);
|
||||
|
||||
|
||||
file->read_hook = save_first_sector;
|
||||
if (grub_file_read (file, tmp_img, GRUB_DISK_SECTOR_SIZE)
|
||||
!= GRUB_DISK_SECTOR_SIZE)
|
||||
|
@ -505,10 +505,10 @@ unable_to_embed:
|
|||
grub_util_error ("Failed to read the rest sectors of the core image");
|
||||
|
||||
grub_file_close (file);
|
||||
|
||||
|
||||
free (core_path_dev);
|
||||
free (tmp_img);
|
||||
|
||||
|
||||
*kernel_sector = grub_cpu_to_le64 (first_sector);
|
||||
|
||||
/* FIXME: can this be skipped? */
|
||||
|
@ -535,7 +535,7 @@ unable_to_embed:
|
|||
|
||||
/* Sync is a Good Thing. */
|
||||
sync ();
|
||||
|
||||
|
||||
free (core_path);
|
||||
free (core_img);
|
||||
free (boot_img);
|
||||
|
@ -591,7 +591,7 @@ static char *
|
|||
get_device_name (char *dev)
|
||||
{
|
||||
size_t len = strlen (dev);
|
||||
|
||||
|
||||
if (dev[0] != '(' || dev[len - 1] != ')')
|
||||
return 0;
|
||||
|
||||
|
@ -609,7 +609,7 @@ main (int argc, char *argv[])
|
|||
char *root_dev = 0;
|
||||
char *dest_dev;
|
||||
int must_embed = 0, force = 0;
|
||||
|
||||
|
||||
progname = "grub-setup";
|
||||
|
||||
/* Check for options. */
|
||||
|
@ -642,7 +642,7 @@ main (int argc, char *argv[])
|
|||
|
||||
dir = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
|
||||
case 'm':
|
||||
if (dev_map)
|
||||
free (dev_map);
|
||||
|
@ -656,7 +656,7 @@ main (int argc, char *argv[])
|
|||
|
||||
root_dev = xstrdup (optarg);
|
||||
break;
|
||||
|
||||
|
||||
case 'f':
|
||||
force = 1;
|
||||
break;
|
||||
|
@ -700,7 +700,7 @@ main (int argc, char *argv[])
|
|||
|
||||
/* Initialize all modules. */
|
||||
grub_init_all ();
|
||||
|
||||
|
||||
dest_dev = get_device_name (argv[optind]);
|
||||
if (! dest_dev)
|
||||
{
|
||||
|
@ -722,7 +722,7 @@ main (int argc, char *argv[])
|
|||
|
||||
if (! tmp)
|
||||
grub_util_error ("Invalid root device `%s'", root_dev);
|
||||
|
||||
|
||||
tmp = xstrdup (tmp);
|
||||
free (root_dev);
|
||||
root_dev = tmp;
|
||||
|
@ -741,7 +741,7 @@ main (int argc, char *argv[])
|
|||
#ifdef __linux__
|
||||
if (grub_util_lvm_isvolume (root_dev))
|
||||
must_embed = 1;
|
||||
|
||||
|
||||
if (root_dev[0] == 'm' && root_dev[1] == 'd'
|
||||
&& root_dev[2] >= '0' && root_dev[2] <= '9')
|
||||
{
|
||||
|
@ -776,13 +776,13 @@ main (int argc, char *argv[])
|
|||
/* Free resources. */
|
||||
grub_fini_all ();
|
||||
grub_util_biosdisk_fini ();
|
||||
|
||||
|
||||
free (boot_file);
|
||||
free (core_file);
|
||||
free (dir);
|
||||
free (dev_map);
|
||||
free (root_dev);
|
||||
free (dest_dev);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ grub_util_lvm_isvolume (char *name)
|
|||
char *devname;
|
||||
struct stat st;
|
||||
int err;
|
||||
|
||||
|
||||
devname = xmalloc (strlen (name) + 13);
|
||||
|
||||
strcpy (devname, "/dev/mapper/");
|
||||
|
|
42
util/misc.c
42
util/misc.c
|
@ -55,7 +55,7 @@ void
|
|||
grub_util_warn (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
||||
fprintf (stderr, "%s: warn: ", progname);
|
||||
va_start (ap, fmt);
|
||||
vfprintf (stderr, fmt, ap);
|
||||
|
@ -70,7 +70,7 @@ grub_util_info (const char *fmt, ...)
|
|||
if (verbosity > 0)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
||||
fprintf (stderr, "%s: info: ", progname);
|
||||
va_start (ap, fmt);
|
||||
vfprintf (stderr, fmt, ap);
|
||||
|
@ -84,7 +84,7 @@ void
|
|||
grub_util_error (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
|
||||
fprintf (stderr, "%s: error: ", progname);
|
||||
va_start (ap, fmt);
|
||||
vfprintf (stderr, fmt, ap);
|
||||
|
@ -98,7 +98,7 @@ grub_err_printf (const char *fmt, ...)
|
|||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = vfprintf (stderr, fmt, ap);
|
||||
va_end (ap);
|
||||
|
@ -110,7 +110,7 @@ void *
|
|||
xmalloc (size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
|
||||
p = malloc (size);
|
||||
if (! p)
|
||||
grub_util_error ("out of memory");
|
||||
|
@ -133,7 +133,7 @@ xstrdup (const char *str)
|
|||
{
|
||||
size_t len;
|
||||
char *dup;
|
||||
|
||||
|
||||
len = strlen (str);
|
||||
dup = (char *) xmalloc (len + 1);
|
||||
memcpy (dup, str, len + 1);
|
||||
|
@ -145,7 +145,7 @@ char *
|
|||
grub_util_get_path (const char *dir, const char *file)
|
||||
{
|
||||
char *path;
|
||||
|
||||
|
||||
path = (char *) xmalloc (strlen (dir) + 1 + strlen (file) + 1);
|
||||
sprintf (path, "%s/%s", dir, file);
|
||||
return path;
|
||||
|
@ -155,13 +155,13 @@ size_t
|
|||
grub_util_get_fp_size (FILE *fp)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
|
||||
if (fflush (fp) == EOF)
|
||||
grub_util_error ("fflush failed");
|
||||
|
||||
if (fstat (fileno (fp), &st) == -1)
|
||||
grub_util_error ("fstat failed");
|
||||
|
||||
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
|
@ -169,12 +169,12 @@ size_t
|
|||
grub_util_get_image_size (const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
|
||||
grub_util_info ("getting the size of %s", path);
|
||||
|
||||
|
||||
if (stat (path, &st) == -1)
|
||||
grub_util_error ("cannot stat %s", path);
|
||||
|
||||
|
||||
return st.st_size;
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ grub_util_read_image (const char *path)
|
|||
char *img;
|
||||
FILE *fp;
|
||||
size_t size;
|
||||
|
||||
|
||||
grub_util_info ("reading %s", path);
|
||||
|
||||
size = grub_util_get_image_size (path);
|
||||
|
@ -207,7 +207,7 @@ grub_util_read_image (const char *path)
|
|||
grub_util_read_at (img, size, 0, fp);
|
||||
|
||||
fclose (fp);
|
||||
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
|
@ -216,11 +216,11 @@ grub_util_load_image (const char *path, char *buf)
|
|||
{
|
||||
FILE *fp;
|
||||
size_t size;
|
||||
|
||||
|
||||
grub_util_info ("reading %s", path);
|
||||
|
||||
size = grub_util_get_image_size (path);
|
||||
|
||||
|
||||
fp = fopen (path, "rb");
|
||||
if (! fp)
|
||||
grub_util_error ("cannot open %s", path);
|
||||
|
@ -282,10 +282,10 @@ grub_memalign (grub_size_t align, grub_size_t size)
|
|||
(void) size;
|
||||
grub_util_error ("grub_memalign is not supported");
|
||||
#endif
|
||||
|
||||
|
||||
if (! p)
|
||||
grub_util_error ("out of memory");
|
||||
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ grub_get_rtc (void)
|
|||
struct timeval tv;
|
||||
|
||||
gettimeofday (&tv, 0);
|
||||
|
||||
|
||||
return (tv.tv_sec * GRUB_TICKS_PER_SECOND
|
||||
+ (((tv.tv_sec % GRUB_TICKS_PER_SECOND) * 1000000 + tv.tv_usec)
|
||||
* GRUB_TICKS_PER_SECOND / 1000000));
|
||||
|
@ -325,7 +325,7 @@ grub_get_time_ms (void)
|
|||
struct timeval tv;
|
||||
|
||||
gettimeofday (&tv, 0);
|
||||
|
||||
|
||||
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
|
@ -351,7 +351,7 @@ grub_millisleep (grub_uint32_t ms)
|
|||
|
||||
#endif
|
||||
|
||||
void
|
||||
void
|
||||
grub_arch_sync_caches (void *address __attribute__ ((unused)),
|
||||
grub_size_t len __attribute__ ((unused)))
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ grub_util_getdiskname (int major, int minor)
|
|||
sprintf (name, "/dev/sd%c", 'a' + minor / 16);
|
||||
else
|
||||
grub_util_error ("Unknown device number: %d, %d", major, minor);
|
||||
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ grub_util_raid_getmembers (char *name)
|
|||
if (version.major != 0 || version.minor != 90)
|
||||
grub_util_error ("Unsupported RAID version: %d.%d",
|
||||
version.major, version.minor);
|
||||
|
||||
|
||||
ret = ioctl (fd, GET_ARRAY_INFO, &info);
|
||||
if (ret != 0)
|
||||
grub_util_error ("ioctl GET_ARRAY_INFO error: %s", strerror (errno));
|
||||
|
@ -105,7 +105,7 @@ grub_util_raid_getmembers (char *name)
|
|||
}
|
||||
|
||||
devicelist[j] = NULL;
|
||||
|
||||
|
||||
return devicelist;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ static struct dep_list *
|
|||
read_dep_list (FILE *fp)
|
||||
{
|
||||
struct dep_list *dep_list = 0;
|
||||
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp))
|
||||
{
|
||||
char *p;
|
||||
|
@ -91,7 +91,7 @@ read_dep_list (FILE *fp)
|
|||
dep = xmalloc (sizeof (*dep));
|
||||
dep->name = xstrdup (buf);
|
||||
dep->list = 0;
|
||||
|
||||
|
||||
dep->next = dep_list;
|
||||
dep_list = dep;
|
||||
|
||||
|
@ -115,7 +115,7 @@ read_dep_list (FILE *fp)
|
|||
p++;
|
||||
|
||||
*p++ = '\0';
|
||||
|
||||
|
||||
mod = (struct mod_list *) xmalloc (sizeof (*mod));
|
||||
mod->name = xstrdup (name);
|
||||
mod->next = dep->list;
|
||||
|
@ -131,7 +131,7 @@ get_module_name (const char *str)
|
|||
{
|
||||
char *base;
|
||||
char *ext;
|
||||
|
||||
|
||||
base = strrchr (str, '/');
|
||||
if (! base)
|
||||
base = (char *) str;
|
||||
|
@ -142,13 +142,13 @@ get_module_name (const char *str)
|
|||
if (ext && strcmp (ext, ".mod") == 0)
|
||||
{
|
||||
char *name;
|
||||
|
||||
|
||||
name = xmalloc (ext - base + 1);
|
||||
memcpy (name, base, ext - base);
|
||||
name[ext - base] = '\0';
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
return xstrdup (base);
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ get_module_path (const char *prefix, const char *str)
|
|||
char *base;
|
||||
char *ext;
|
||||
char *ret;
|
||||
|
||||
|
||||
ext = strrchr (str, '.');
|
||||
if (ext && strcmp (ext, ".mod") == 0)
|
||||
base = xstrdup (str);
|
||||
|
@ -168,7 +168,7 @@ get_module_path (const char *prefix, const char *str)
|
|||
base = xmalloc (strlen (str) + 4 + 1);
|
||||
sprintf (base, "%s.mod", str);
|
||||
}
|
||||
|
||||
|
||||
dir = strchr (str, '/');
|
||||
if (dir)
|
||||
return base;
|
||||
|
@ -189,7 +189,7 @@ add_module (const char *dir,
|
|||
struct grub_util_path_list *path;
|
||||
struct mod_list *mod;
|
||||
struct dep_list *dep;
|
||||
|
||||
|
||||
mod_name = get_module_name (name);
|
||||
|
||||
/* Check if the module has already been added. */
|
||||
|
|
|
@ -82,7 +82,7 @@ grub_libusb_init (void)
|
|||
if (grub_libusb_devices ())
|
||||
return grub_errno;
|
||||
|
||||
grub_usb_controller_dev_register (&usb_controller);
|
||||
grub_usb_controller_dev_register (&usb_controller);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue