From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KcrO7-0003Xm-4B for mharc-grub-devel@gnu.org; Mon, 08 Sep 2008 20:47:23 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KcrO5-0003Xb-6N for grub-devel@gnu.org; Mon, 08 Sep 2008 20:47:21 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KcrO4-0003XP-Il for grub-devel@gnu.org; Mon, 08 Sep 2008 20:47:20 -0400 Received: from [199.232.76.173] (port=57927 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KcrO4-0003XM-CJ for grub-devel@gnu.org; Mon, 08 Sep 2008 20:47:20 -0400 Received: from fg-out-1718.google.com ([72.14.220.159]:7309) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KcrO3-0003rv-Ou for grub-devel@gnu.org; Mon, 08 Sep 2008 20:47:20 -0400 Received: by fg-out-1718.google.com with SMTP id l26so1599452fgb.30 for ; Mon, 08 Sep 2008 17:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:content-type; bh=7am7W5QevKLLIvWcM0aA5ks2c+EOuJpdVbt10k9jrxQ=; b=hBX/RlvwBM4RXbJtG04uKd5Z7vy9Hl/3VVSPj5+EAczJHfme3rEObfVTr9cfNej4QS 5rKV9vAKtQ/jdj7sO7a90noPltBR9s/wz/mPlxch07vCcQE5PfFfJc2JbCnmDyIcx4cm 8tcUt6X1hM0mpUi+eC+UIaMRXfPnP01p7snvg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; b=MUMWYrQMX8E+Ft6qMAJhICn59ZcSGocVbjoEfWZm9xVpM2THyB7PbKnzIaUYOQW954 due52U77i/PH4ImsnOp406JV++o1rnxmIKSKYdv14dYxL/KMvI2VHOvK6gTP5xXB1CpJ 5GVTYgnkzql5nPoLA2B3hoWeF8gh15b+9hFNU= Received: by 10.86.26.11 with SMTP id 11mr11797611fgz.71.1220921238488; Mon, 08 Sep 2008 17:47:18 -0700 (PDT) Received: from ?192.168.1.15? ( [83.77.151.64]) by mx.google.com with ESMTPS id 4sm5961795fgg.4.2008.09.08.17.47.13 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 08 Sep 2008 17:47:15 -0700 (PDT) Message-ID: <48C5C78F.8010502@gmail.com> Date: Tue, 09 Sep 2008 02:47:11 +0200 From: phcoder User-Agent: Thunderbird 2.0.0.16 (X11/20080724) MIME-Version: 1.0 To: The development of GRUB 2 References: <48BED2B2.1060000@gmail.com> <20080904194015.GF9133@thorin> <48C05923.3060001@gmail.com> <20080908133815.GA21754@thorin> <48C56E79.9080502@gmail.com> <20080908183119.GC31031@thorin> In-Reply-To: <20080908183119.GC31031@thorin> X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------040203050606090007090808" X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: [PATCH] Re: Multiple partition maps 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: Tue, 09 Sep 2008 00:47:21 -0000 This is a multi-part message in MIME format. --------------040203050606090007090808 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Robert Millan wrote: > On Mon, Sep 08, 2008 at 08:27:05PM +0200, phcoder wrote: >> Robert Millan wrote: >>> On Thu, Sep 04, 2008 at 11:54:43PM +0200, phcoder wrote: >>>> BTW GPT module checks the protective MBR. In some cases when legay OS >>>> modified the MBR it's no longer "protective MBR". And in theese cases >>>> GRUB will refuse to boot. Isn't the magic number check enough? >>> If there's at least one protective GPT partition (0xee), I think this should >>> be considered enough to accept the partmap as GPT. >>> >> In GPT module if first partition is not of type 0xee then it's >> considered that no GPT is present. Is think that this check is >> error-prone (with e.g. bootcamp) and unnecessary > > Agreed. Can you fix this? > I send a patch for it. However I couldn't test it because of the bug in the make system. About the bug I'll post in appropriate thread. In that patch the pc module explicitely checks for the absence of GPT table. IMO it's ugly. Another alternative would be to assign priorities to the partition tables. I also tried this way and send patch for it. Again I couldn't test it. Vladimir 'phcoder' Serbinenko --------------040203050606090007090808 Content-Type: text/x-diff; name="parts.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="parts.diff" Index: kern/partition.c =================================================================== --- kern/partition.c (revision 1861) +++ kern/partition.c (working copy) @@ -25,8 +25,20 @@ void grub_partition_map_register (grub_partition_map_t partmap) { - partmap->next = grub_partition_map_list; - grub_partition_map_list = partmap; + grub_partition_map_t cur, prev=0; + for (cur=grub_partition_map_list;cur && cur->priority>partmap->priority; + cur=cur->next) + prev=cur; + if (!prev) + { + partmap->next = grub_partition_map_list; + grub_partition_map_list = partmap; + } + else + { + partmap->next=prev->next; + prev->next=partmap; + } } void Index: include/grub/partition.h =================================================================== --- include/grub/partition.h (revision 1861) +++ include/grub/partition.h (working copy) @@ -42,6 +42,9 @@ /* Return the name of the partition PARTITION. */ char *(*get_name) (const grub_partition_t partition); + + /* Partmaps with higher priorities are checked first */ + int priority; /* The next partition map type. */ struct grub_partition_map *next; Index: partmap/amiga.c =================================================================== --- partmap/amiga.c (revision 1861) +++ partmap/amiga.c (working copy) @@ -205,7 +205,8 @@ .name = "amiga_partition_map", .iterate = amiga_partition_map_iterate, .probe = amiga_partition_map_probe, - .get_name = amiga_partition_map_get_name + .get_name = amiga_partition_map_get_name, + .priority = 0 }; GRUB_MOD_INIT(amiga_partition_map) Index: partmap/apple.c =================================================================== --- partmap/apple.c (revision 1861) +++ partmap/apple.c (working copy) @@ -241,7 +241,8 @@ .name = "apple_partition_map", .iterate = apple_partition_map_iterate, .probe = apple_partition_map_probe, - .get_name = apple_partition_map_get_name + .get_name = apple_partition_map_get_name, + .priority = 0 }; GRUB_MOD_INIT(apple_partition_map) Index: partmap/acorn.c =================================================================== --- partmap/acorn.c (revision 1861) +++ partmap/acorn.c (working copy) @@ -192,7 +192,8 @@ .name = "Linux/ADFS partition map", .iterate = acorn_partition_map_iterate, .probe = acorn_partition_map_probe, - .get_name = acorn_partition_map_get_name + .get_name = acorn_partition_map_get_name, + .priority = 0 }; GRUB_MOD_INIT(acorn_partition_map) Index: partmap/pc.c =================================================================== --- partmap/pc.c (revision 1861) +++ partmap/pc.c (working copy) @@ -111,7 +111,7 @@ pcdata.dos_part = -1; p.data = &pcdata; p.partmap = &grub_pc_partition_map; - + while (1) { int i; @@ -303,7 +303,8 @@ .name = "pc_partition_map", .iterate = pc_partition_map_iterate, .probe = pc_partition_map_probe, - .get_name = pc_partition_map_get_name + .get_name = pc_partition_map_get_name, + .priority = -10 }; GRUB_MOD_INIT(pc_partition_map) Index: partmap/sun.c =================================================================== --- partmap/sun.c (revision 1861) +++ partmap/sun.c (working copy) @@ -205,7 +205,8 @@ .name = "sun_partition_map", .iterate = sun_partition_map_iterate, .probe = sun_partition_map_probe, - .get_name = sun_partition_map_get_name + .get_name = sun_partition_map_get_name, + .priority = 0 }; GRUB_MOD_INIT(sun_partition_map) Index: partmap/gpt.c =================================================================== --- partmap/gpt.c (revision 1861) +++ partmap/gpt.c (working copy) @@ -58,18 +58,6 @@ raw = *disk; raw.partition = 0; - /* Read the protective MBR. */ - if (grub_disk_read (&raw, 0, 0, sizeof (mbr), (char *) &mbr)) - return grub_errno; - - /* Check if it is valid. */ - if (mbr.signature != grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE)) - return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); - - /* Make sure the MBR is a protective MBR and not a normal MBR. */ - if (mbr.entries[0].type != GRUB_PC_PARTITION_TYPE_GPT_DISK) - return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found"); - /* Read the GPT header. */ if (grub_disk_read (&raw, 1, 0, sizeof (gpt), (char *) &gpt)) return grub_errno; @@ -183,7 +171,8 @@ .name = "gpt_partition_map", .iterate = gpt_partition_map_iterate, .probe = gpt_partition_map_probe, - .get_name = gpt_partition_map_get_name + .get_name = gpt_partition_map_get_name, + .priority = 0 }; GRUB_MOD_INIT(gpt_partition_map) --------------040203050606090007090808 Content-Type: text/x-diff; name="partsb.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="partsb.diff" Index: pc.c =================================================================== --- pc.c (revision 1861) +++ pc.c (working copy) @@ -19,11 +19,17 @@ #include #include +#include #include #include #include #include +static grub_uint8_t grub_gpt_magic[8] = + { + 0x45, 0x46, 0x49, 0x20, 0x50, 0x41, 0x52, 0x54 + }; + static struct grub_partition_map grub_pc_partition_map; #ifndef GRUB_UTIL @@ -111,6 +117,13 @@ pcdata.dos_part = -1; p.data = &pcdata; p.partmap = &grub_pc_partition_map; + + /* Read the GPT header. */ + if (grub_disk_read (&raw, 1, 0, sizeof (gpt), (char *) &gpt)) + return grub_errno; + + if (!grub_memcmp (gpt.magic, grub_gpt_magic, sizeof (grub_gpt_magic))) + return grub_error (GRUB_ERR_BAD_PART_TABLE, "valid GPT header"); while (1) { Index: gpt.c =================================================================== --- gpt.c (revision 1861) +++ gpt.c (working copy) @@ -58,18 +58,6 @@ raw = *disk; raw.partition = 0; - /* Read the protective MBR. */ - if (grub_disk_read (&raw, 0, 0, sizeof (mbr), (char *) &mbr)) - return grub_errno; - - /* Check if it is valid. */ - if (mbr.signature != grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE)) - return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature"); - - /* Make sure the MBR is a protective MBR and not a normal MBR. */ - if (mbr.entries[0].type != GRUB_PC_PARTITION_TYPE_GPT_DISK) - return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found"); - /* Read the GPT header. */ if (grub_disk_read (&raw, 1, 0, sizeof (gpt), (char *) &gpt)) return grub_errno; --------------040203050606090007090808--