2009-05-08 Robert Millan <rmh.grub@aybabtu.com>

* util/i386/pc/grub-setup.c (setup): Factorize find_usable_region(),
        split in two functions (one for msdos and one for gpt).
This commit is contained in:
robertmh 2009-05-08 19:48:54 +00:00
parent 752473c2b0
commit 317e1a44b5
2 changed files with 54 additions and 32 deletions

View file

@ -1,3 +1,8 @@
2009-05-08 Robert Millan <rmh.grub@aybabtu.com>
* util/i386/pc/grub-setup.c (setup): Factorize find_usable_region(),
split in two functions (one for msdos and one for gpt).
2009-05-08 Pavel Roskin <proski@gnu.org> 2009-05-08 Pavel Roskin <proski@gnu.org>
* disk/raid.c (grub_raid_block_xor): Make buf2 constant, it's * disk/raid.c (grub_raid_block_xor): Make buf2 constant, it's

View file

@ -93,6 +93,7 @@ setup (const char *dir,
size_t boot_size, core_size; size_t boot_size, core_size;
grub_uint16_t core_sectors; grub_uint16_t core_sectors;
grub_device_t root_dev, dest_dev; grub_device_t root_dev, dest_dev;
const char *dest_partmap;
grub_uint8_t *boot_drive, *root_drive; grub_uint8_t *boot_drive, *root_drive;
grub_disk_addr_t *kernel_sector; grub_disk_addr_t *kernel_sector;
grub_uint16_t *boot_drive_check; grub_uint16_t *boot_drive_check;
@ -116,36 +117,39 @@ setup (const char *dir,
auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset, auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
unsigned length); unsigned length);
auto int find_usable_region (grub_disk_t disk, auto int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk,
const grub_partition_t p); const grub_partition_t p);
int find_usable_region (grub_disk_t disk __attribute__ ((unused)), int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p) const grub_partition_t p)
{ {
if (! strcmp (p->partmap->name, "pc_partition_map")) 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))
{ {
struct grub_pc_partition *pcdata = p->data; embed_region.start = p->start;
embed_region.end = p->start + p->len;
/* There's always an embed region, and it starts right after the MBR. */ return 1;
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;
}
else
{
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; return 0;
@ -315,7 +319,20 @@ setup (const char *dir,
try to embed the core image into after the MBR. */ try to embed the core image into after the MBR. */
if (dest_dev->disk->has_partitions && ! dest_dev->disk->partition) if (dest_dev->disk->has_partitions && ! dest_dev->disk->partition)
{ {
grub_partition_iterate (dest_dev->disk, find_usable_region); /* 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,
const grub_partition_t p);
int NESTED_FUNC_ATTR identify_partmap (grub_disk_t disk __attribute__ ((unused)),
const grub_partition_t p)
{
dest_partmap = p->partmap->name;
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) if (embed_region.end != embed_region.start)
embedding_area_exists = 1; embedding_area_exists = 1;