commit-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[2199] 2009-05-08 Robert Millan <address@hidden>


From: Robert Millan
Subject: [2199] 2009-05-08 Robert Millan <address@hidden>
Date: Fri, 08 May 2009 19:48:55 +0000

Revision: 2199
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=2199
Author:   robertmh
Date:     2009-05-08 19:48:54 +0000 (Fri, 08 May 2009)
Log Message:
-----------
2009-05-08  Robert Millan  <address@hidden>

        * util/i386/pc/grub-setup.c (setup): Factorize find_usable_region(),
        split in two functions (one for msdos and one for gpt).

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/util/i386/pc/grub-setup.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog       2009-05-08 19:29:04 UTC (rev 2198)
+++ trunk/grub2/ChangeLog       2009-05-08 19:48:54 UTC (rev 2199)
@@ -1,3 +1,8 @@
+2009-05-08  Robert Millan  <address@hidden>
+
+       * 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  <address@hidden>
 
        * disk/raid.c (grub_raid_block_xor): Make buf2 constant, it's

Modified: trunk/grub2/util/i386/pc/grub-setup.c
===================================================================
--- trunk/grub2/util/i386/pc/grub-setup.c       2009-05-08 19:29:04 UTC (rev 
2198)
+++ trunk/grub2/util/i386/pc/grub-setup.c       2009-05-08 19:48:54 UTC (rev 
2199)
@@ -93,6 +93,7 @@
   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 @@
   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;
+      
+      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. 
 */
-         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;
        }
-      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;
     }
   
@@ -315,11 +319,24 @@
      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 @@
          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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]