grub-devel
[Top][All Lists]
Advanced

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

Re: grub-probe fails to find PC partition due to Apple disklabel


From: Chris Knadle
Subject: Re: grub-probe fails to find PC partition due to Apple disklabel
Date: Wed, 23 Jul 2008 15:10:38 -0400
User-agent: KMail/1.9.9

Thanks for your pointsers, Pavel; they were all helpful.

On Tuesday 22 July 2008, Pavel Roskin wrote:
> Quoting Chris Knadle <address@hidden>:
> > Since I want the first (high) 16 bits, I
> > think I need to make the comparison in a way such as:
> >
> >    if ((apart.first_phys_block & 0xFFFF0000) == (0x4552 << 16))
>
> That won't work on little endian systems, including ordinary PC.  You
> are assuming big endian byte order here.  Instead, the data from the
> disk should be converted to CPU-endian from whatever it is and
> compared to the magic value.

   Yes, I did suspect that problem; so this needs a #ifdef for CPU 
architecture and choosing the appropriate conversion with one of the 
functions in include/grub/type.h -- okay.

   The next problem is that I'm not able to figure out how to get partition.c 
to "give up" the Apple_partition_map that is detected, and to re-detect for 
others.  Right now part_map_iterate() detects an Apple partition based on 
Sector 0 [which is unavoidable, since Sector 0 is not going to have an HFS+ 
magic number], after which it becomes "fixated" on it.  Calling 
grub_partition_map_unregister() does lead to secceding in detection of a 
pc_partition_map, but then still isn't fully successful in a grub-probe.

   Below is a patch based on the git tree if you want to see where I'm 
currently at.

-- 

Chris Knadle
address@hidden

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

diff --git a/partmap/apple.c b/partmap/apple.c
index 4e5c481..3786301 100644
--- a/partmap/apple.c
+++ b/partmap/apple.c
@@ -23,6 +23,7 @@
 #include <grub/partition.h>

 #define GRUB_APPLE_PART_MAGIC  0x504D
+#define GRUB_APPLE_HFSPLUS_MAGIC 0x4552

 struct grub_apple_part
 {
@@ -102,6 +103,7 @@ apple_partition_map_iterate (grub_disk_t disk,
   struct grub_disk raw;
   int partno = 0;
   unsigned pos = GRUB_DISK_SECTOR_SIZE;
+  grub_uint16_t magic;

   /* Enforce raw disk access.  */
   raw = *disk;
@@ -111,6 +113,21 @@ apple_partition_map_iterate (grub_disk_t disk,

   for (;;)
     {
+
+      /* load + check partition magic number */
+      if (grub_disk_read (&raw, 0, 0, sizeof(grub_uint16_t), (char *) 
&magic))
+        return grub_errno;
+      if (grub_be_to_cpu16(magic) != GRUB_APPLE_HFSPLUS_MAGIC  && partno > 
0 ) {
+         grub_dprintf("partition",
+            "non-Apple partition %d: bad magic (found 0x%x; wanted 0x%x\n",
+            partno, grub_be_to_cpu16 (magic),
+            GRUB_APPLE_HFSPLUS_MAGIC);
+         grub_errno = 1;
+         grub_partition_map_unregister(part.partmap);
+         return 1;
+      }
+
+
       if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
                          pos % GRUB_DISK_SECTOR_SIZE,
                          sizeof (struct grub_apple_part),  (char *) &apart))





reply via email to

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