Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KLjjZ-0002gv-2D for mharc-grub-devel@gnu.org; Wed, 23 Jul 2008 15:10:45 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KLjjX-0002fa-6K for grub-devel@gnu.org; Wed, 23 Jul 2008 15:10:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KLjjV-0002ep-3u for grub-devel@gnu.org; Wed, 23 Jul 2008 15:10:42 -0400 Received: from [199.232.76.173] (port=37870 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KLjjU-0002ek-RV for grub-devel@gnu.org; Wed, 23 Jul 2008 15:10:40 -0400 Received: from lethe.ofobscurity.com ([64.85.165.57]:50784) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KLjjU-00058S-86 for grub-devel@gnu.org; Wed, 23 Jul 2008 15:10:40 -0400 Received: from user-160u3tu.cable.mindspring.com ([76.15.15.190] helo=anan7.local) by lethe.ofobscurity.com with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1KLjjO-0005mu-UA for grub-devel@gnu.org; Wed, 23 Jul 2008 15:10:35 -0400 From: Chris Knadle Organization: CoreDump.us To: The development of GRUB 2 Date: Wed, 23 Jul 2008 15:10:38 -0400 User-Agent: KMail/1.9.9 References: <200804131734.50447.Chris.Knadle@coredump.us> <200807222253.49161.Chris.Knadle@coredump.us> <20080722234800.7ebar1eoro40c0w8-cebfxv@webmail.spamcop.net> In-Reply-To: <20080722234800.7ebar1eoro40c0w8-cebfxv@webmail.spamcop.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200807231510.38838.Chris.Knadle@coredump.us> X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: Re: grub-probe fails to find PC partition due to Apple disklabel X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jul 2008 19:10:43 -0000 Thanks for your pointsers, Pavel; they were all helpful. On Tuesday 22 July 2008, Pavel Roskin wrote: > Quoting Chris Knadle : > > 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 Chris.Knadle@coredump.us =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 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 #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))