From 6139dcd95357b5bf8bb3f4446eeca6f914bf890d Mon Sep 17 00:00:00 2001 From: okuji Date: Mon, 3 Sep 2007 20:10:19 +0000 Subject: [PATCH] 2007-09-03 Yoshinori K. Okuji Do not use devices at boot in chainloading. * loader/i386/pc/chainloader.c (boot_drive): New variable. (boot_part_addr): Likewise. (grub_chainloader_boot): Simply call grub_chainloader_real_boot with BOOT_DRIVE and BOOT_PART_ADDR. (grub_chainloader_cmd): Set BOOT_DRIVE and BOOT_PART_ADDR. Reported by Hitoshi Ozeki . --- ChangeLog | 11 ++++++ loader/i386/pc/chainloader.c | 70 +++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index e3701bf90..825053ac3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-09-03 Yoshinori K. Okuji + + Do not use devices at boot in chainloading. + + * loader/i386/pc/chainloader.c (boot_drive): New variable. + (boot_part_addr): Likewise. + (grub_chainloader_boot): Simply call grub_chainloader_real_boot + with BOOT_DRIVE and BOOT_PART_ADDR. + (grub_chainloader_cmd): Set BOOT_DRIVE and BOOT_PART_ADDR. + Reported by Hitoshi Ozeki . + 2007-08-29 Robert Millan Patch from Simon Peter : diff --git a/loader/i386/pc/chainloader.c b/loader/i386/pc/chainloader.c index e18868bf4..825dbb3b6 100644 --- a/loader/i386/pc/chainloader.c +++ b/loader/i386/pc/chainloader.c @@ -33,42 +33,13 @@ #include static grub_dl_t my_mod; +static int boot_drive; +static void *boot_part_addr; static grub_err_t grub_chainloader_boot (void) { - grub_device_t dev; - int drive = -1; - void *part_addr = 0; - - /* Open the root device. */ - dev = grub_device_open (0); - if (dev) - { - grub_disk_t disk = dev->disk; - - if (disk) - { - grub_partition_t p = disk->partition; - - /* In i386-pc, the id is equal to the BIOS drive number. */ - drive = (int) disk->id; - - if (p) - { - grub_disk_read (disk, p->offset, 446, 64, - (char *) GRUB_MEMORY_MACHINE_PART_TABLE_ADDR); - - /* Ignore errors. Perhaps it's not fatal. */ - part_addr = (void *) (GRUB_MEMORY_MACHINE_PART_TABLE_ADDR - + (p->index << 4)); - } - } - - grub_device_close (dev); - } - - grub_chainloader_real_boot (drive, part_addr); + grub_chainloader_real_boot (boot_drive, boot_part_addr); /* Never reach here. */ return GRUB_ERR_NONE; @@ -86,6 +57,9 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags) { grub_file_t file = 0; grub_uint16_t signature; + grub_device_t dev; + int drive = -1; + void *part_addr = 0; grub_dl_ref (my_mod); @@ -113,6 +87,38 @@ grub_chainloader_cmd (const char *filename, grub_chainloader_flags_t flags) } grub_file_close (file); + + /* Obtain the partition table from the root device. */ + dev = grub_device_open (0); + if (dev) + { + grub_disk_t disk = dev->disk; + + if (disk) + { + grub_partition_t p = disk->partition; + + /* In i386-pc, the id is equal to the BIOS drive number. */ + drive = (int) disk->id; + + if (p) + { + grub_disk_read (disk, p->offset, 446, 64, + (char *) GRUB_MEMORY_MACHINE_PART_TABLE_ADDR); + part_addr = (void *) (GRUB_MEMORY_MACHINE_PART_TABLE_ADDR + + (p->index << 4)); + } + } + + grub_device_close (dev); + } + + /* Ignore errors. Perhaps it's not fatal. */ + grub_errno = GRUB_ERR_NONE; + + boot_drive = drive; + boot_part_addr = part_addr; + grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 1); return;