]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
2009-05-08 Robert Millan <rmh.grub@aybabtu.com>
authorrobertmh <robertmh@localhost>
Fri, 8 May 2009 19:48:54 +0000 (19:48 +0000)
committerrobertmh <robertmh@localhost>
Fri, 8 May 2009 19:48:54 +0000 (19:48 +0000)
        * util/i386/pc/grub-setup.c (setup): Factorize find_usable_region(),
        split in two functions (one for msdos and one for gpt).

ChangeLog
util/i386/pc/grub-setup.c

index 2427e107e8c1dfc0ddad0b7c1366c6f13b925dda..c307abe68eea4b7b0fd4e2b3a5fb10bde74f138e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * disk/raid.c (grub_raid_block_xor): Make buf2 constant, it's
index 10ce041487659c37b1689af30107cbed419ff5d5..f0f79f419ae4b641b7b795c4777d3c5ddf3f30e4 100644 (file)
@@ -93,6 +93,7 @@ setup (const char *dir,
   size_t boot_size, core_size;
   grub_uint16_t core_sectors;
   grub_device_t root_dev, dest_dev;
+  const char *dest_partmap;
   grub_uint8_t *boot_drive, *root_drive;
   grub_disk_addr_t *kernel_sector;
   grub_uint16_t *boot_drive_check;
@@ -116,38 +117,41 @@ setup (const char *dir,
   auto void NESTED_FUNC_ATTR save_blocklists (grub_disk_addr_t sector, unsigned offset,
                             unsigned length);
 
-  auto int find_usable_region (grub_disk_t disk,
-                              const grub_partition_t p);
-  int find_usable_region (grub_disk_t disk __attribute__ ((unused)),
-                         const grub_partition_t p)
+  auto int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk,
+                                                     const grub_partition_t p);
+  int NESTED_FUNC_ATTR find_usable_region_msdos (grub_disk_t disk __attribute__ ((unused)),
+                                                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;
-       }
-      else
+      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_gpt_partentry *gptdata = p->data;
+         embed_region.start = p->start;
+         embed_region.end = p->start + p->len;
          
-         /* 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 1;
        }
-
+      
       return 0;
     }
   
@@ -315,11 +319,24 @@ setup (const char *dir,
      try to embed the core image into after the MBR.  */
   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)
        embedding_area_exists = 1;
-
+      
       /* If there is enough space...  */
       if ((unsigned long) core_sectors <= embed_region.end - embed_region.start)
        {
@@ -359,9 +376,9 @@ setup (const char *dir,
          goto finish;
        }
     }
-
+  
   /* If we reached this point, it means we were unable to embed.  */
-
+  
   if (embedding_area_exists)
     grub_util_warn ("Embedding area is too small for core.img.");
   else