From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1OrgI9-0008Ko-Ev for mharc-grub-devel@gnu.org; Fri, 03 Sep 2010 20:07:33 -0400 Received: from [140.186.70.92] (port=50445 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OrgI5-0008In-V4 for grub-devel@gnu.org; Fri, 03 Sep 2010 20:07:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OrgI4-0003BW-7w for grub-devel@gnu.org; Fri, 03 Sep 2010 20:07:29 -0400 Received: from mail-ey0-f169.google.com ([209.85.215.169]:60037) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OrgI3-0003BF-PV for grub-devel@gnu.org; Fri, 03 Sep 2010 20:07:28 -0400 Received: by eyh5 with SMTP id 5so1797029eyh.0 for ; Fri, 03 Sep 2010 17:07:27 -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:cc:subject:x-enigmail-version :content-type; bh=+cdmPLNsLydL5IXqxz9XRMkXgXRQMsOiAGUji+L1Ue0=; b=uEJM++6HTOOTS7zWgsMwHn6etJSPR3W6QuAKiipoR191NnPfuIThXzGbV8/mUvFe6u Z8mzuqPaRNe1oBcy9Nrc6vel594AoqZq/Wkjxrg89CZUxnFeKWExqgq45mdRVWol9k6j YkVGFvdeYgg0f6XvYW15rkBEZK9t8bbUJNkRs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :x-enigmail-version:content-type; b=nZ3v+PboyfPpJiv++Xblpbje7B0eHsAQ689wN+bhO3Q6YoTJR6H7ZvS9PDaI0pK0aG Mmbb4S9w7R9mx0WF0kUDfseW84vLoYWXZuu3uYqE7U7JhwSPp7n/2KAGHhhHhs9EPUFV Ucd8Lagvvv7uLcVYBvogiAJV9786VL/P6YU6E= Received: by 10.213.104.203 with SMTP id q11mr71949ebo.12.1283558846896; Fri, 03 Sep 2010 17:07:26 -0700 (PDT) Received: from debian.bg45.phnet (100.71.63.81.cust.bluewin.ch [81.63.71.100]) by mx.google.com with ESMTPS id a48sm3673664eei.6.2010.09.03.17.07.24 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 03 Sep 2010 17:07:26 -0700 (PDT) Message-ID: <4C818DBC.10002@gmail.com> Date: Sat, 04 Sep 2010 02:07:24 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100805 Icedove/3.0.6 MIME-Version: 1.0 To: The development of GRUB 2 X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigEB3B58BC92F25795F07E6EB9" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Fam Zheng , =?UTF-8?B?R3LDqWdvaXJlIFN1dHJl?= Subject: [RFT] nested partition issues X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Sep 2010 00:07:32 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigEB3B58BC92F25795F07E6EB9 Content-Type: multipart/mixed; boundary="------------020807030508000602050701" This is a multi-part message in MIME format. --------------020807030508000602050701 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello. It was reported to me about several issues with nested partitions. Please try attached patch and report back any remaining problems --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------020807030508000602050701 Content-Type: text/x-diff; name="nested.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="nested.diff" =3D=3D=3D modified file 'Makefile.util.def' --- Makefile.util.def 2010-08-31 23:09:00 +0000 +++ Makefile.util.def 2010-09-03 23:04:39 +0000 @@ -89,6 +89,7 @@ common =3D grub-core/partmap/msdos.c; common =3D grub-core/partmap/sun.c; common =3D grub-core/partmap/sunpc.c; + common =3D grub-core/partmap/bsdlabel.c; common =3D grub-core/script/function.c; common =3D grub-core/script/lexer.c; common =3D grub-core/script/main.c; =3D=3D=3D modified file 'grub-core/disk/efi/efidisk.c' --- grub-core/disk/efi/efidisk.c 2010-02-16 12:13:02 +0000 +++ grub-core/disk/efi/efidisk.c 2010-09-03 23:29:51 +0000 @@ -731,7 +731,7 @@ { /* This is a hard disk partition. */ grub_disk_t parent =3D 0; - char *partition_name =3D 0; + const grub_partition_t tpart =3D NULL; char *device_name; grub_efi_device_path_t *dup_dp, *dup_ldp; grub_efi_hard_drive_device_path_t hd; @@ -770,7 +770,7 @@ if (grub_partition_get_start (part) =3D=3D hd.partition_start && grub_partition_get_len (part) =3D=3D hd.partition_size) { - partition_name =3D grub_partition_get_name (part); + tpart =3D part; return 1; } =20 @@ -799,13 +799,15 @@ grub_memcpy (&hd, ldp, sizeof (hd)); grub_partition_iterate (parent, find_partition); =20 - if (! partition_name) + if (! tpart) { grub_disk_close (parent); return 0; } =20 - device_name =3D grub_xasprintf ("%s,%s", parent->name, partition_n= ame); + device_name =3D grub_xasprintf ("%s,%s%d", parent->name, + tpart->partmap->name, + tpart->number + 1); grub_free (partition_name); grub_disk_close (parent); =20 =3D=3D=3D modified file 'grub-core/kern/device.c' --- grub-core/kern/device.c 2010-03-31 20:03:48 +0000 +++ grub-core/kern/device.c 2010-09-03 23:29:23 +0000 @@ -135,28 +135,22 @@ =20 int iterate_partition (grub_disk_t disk, const grub_partition_t partit= ion) { - char *partition_name; struct part_ent *p; =20 - partition_name =3D grub_partition_get_name (partition); - if (! partition_name) - return 1; =20 p =3D grub_malloc (sizeof (*p)); if (!p) { - grub_free (partition_name); return 1; } =20 - p->name =3D grub_xasprintf ("%s,%s", disk->name, partition_name); + p->name =3D grub_xasprintf ("%s,%s%d", disk->name, partition->part= map->name, + partition->number + 1); if (!p->name) { - grub_free (partition_name); grub_free (p); return 1; } - grub_free (partition_name); =20 p->next =3D ents; ents =3D p; =3D=3D=3D modified file 'grub-core/normal/completion.c' --- grub-core/normal/completion.c 2010-08-28 13:31:21 +0000 +++ grub-core/normal/completion.c 2010-09-03 23:29:36 +0000 @@ -100,15 +100,10 @@ iterate_partition (grub_disk_t disk, const grub_partition_t p) { const char *disk_name =3D disk->name; - char *partition_name =3D grub_partition_get_name (p); char *name; int ret; =20 - if (! partition_name) - return 1; - - name =3D grub_xasprintf ("%s,%s", disk_name, partition_name); - grub_free (partition_name); + name =3D grub_xasprintf ("%s,%s%d", disk_name, p->partmap->name, p->nu= mber + 1); =20 if (! name) return 1; =3D=3D=3D modified file 'grub-core/partmap/bsdlabel.c' --- grub-core/partmap/bsdlabel.c 2010-07-16 23:57:48 +0000 +++ grub-core/partmap/bsdlabel.c 2010-09-03 23:13:07 +0000 @@ -23,18 +23,23 @@ #include #include #include +#include =20 #ifdef GRUB_UTIL #include #endif =20 static struct grub_partition_map grub_bsdlabel_partition_map; +static struct grub_partition_map grub_netbsdlabel_partition_map; +static struct grub_partition_map grub_openbsdlabel_partition_map; + =0C =20 static grub_err_t -bsdlabel_partition_map_iterate (grub_disk_t disk, - int (*hook) (grub_disk_t disk, - const grub_partition_t partition)) +iterate_real (grub_disk_t disk, grub_disk_addr_t sector, int freebsd, + struct grub_partition_map *pmap, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) { struct grub_partition_bsd_disk_label label; struct grub_partition p; @@ -42,8 +47,7 @@ unsigned pos; =20 /* Read the BSD label. */ - if (grub_disk_read (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, - 0, sizeof (label), &label)) + if (grub_disk_read (disk, sector, 0, sizeof (label), &label)) return grub_errno; =20 /* Check if it is valid. */ @@ -52,12 +56,12 @@ =20 /* A kludge to determine a base of be.offset. */ if (GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION - < grub_cpu_to_le16 (label.num_partitions)) + < grub_cpu_to_le16 (label.num_partitions) && freebsd) { struct grub_partition_bsd_entry whole_disk_be; =20 - pos =3D sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR - * GRUB_DISK_SECTOR_SIZE + sizeof (struct grub_partition_bsd_entry) + pos =3D sizeof (label) + sector * GRUB_DISK_SECTOR_SIZE + + sizeof (struct grub_partition_bsd_entry) * GRUB_PC_PARTITION_BSD_LABEL_WHOLE_DISK_PARTITION; =20 if (grub_disk_read (disk, pos / GRUB_DISK_SECTOR_SIZE, @@ -68,8 +72,7 @@ delta =3D grub_le_to_cpu32 (whole_disk_be.offset); } =20 - pos =3D sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR - * GRUB_DISK_SECTOR_SIZE; + pos =3D sizeof (label) + sector * GRUB_DISK_SECTOR_SIZE; =20 for (p.number =3D 0; p.number < grub_cpu_to_le16 (label.num_partitions); @@ -88,13 +91,7 @@ =20 p.start =3D grub_le_to_cpu32 (be.offset); p.len =3D grub_le_to_cpu32 (be.size); - p.partmap =3D &grub_bsdlabel_partition_map; - - grub_dprintf ("partition", - "partition %d: type 0x%x, start 0x%llx, len 0x%llx\n", - p.number, be.fs_type, - (unsigned long long) p.start, - (unsigned long long) p.len); + p.partmap =3D pmap; =20 if (p.len =3D=3D 0) continue; @@ -103,13 +100,6 @@ { #ifdef GRUB_UTIL char *partname; -#endif - grub_dprintf ("partition", - "partition %d: invalid start (found 0x%llx, wanted >=3D 0x%llx)\n", - p.number, - (unsigned long long) p.start, - (unsigned long long) delta); -#ifdef GRUB_UTIL /* disk->partition !=3D NULL as 0 < delta */ partname =3D grub_partition_get_name (disk->partition); grub_util_warn ("Discarding improperly nested partition (%s,%s,%s%d)"= , @@ -124,24 +114,118 @@ if (hook (disk, &p)) return grub_errno; } - return GRUB_ERR_NONE; } =20 -=0C -/* Partition map type. */ +static grub_err_t +bsdlabel_partition_map_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + + if (disk->partition && grub_strcmp (disk->partition->partmap->name, "m= sdos") + =3D=3D 0 && disk->partition->msdostype =3D=3D GRUB_PC_PARTITION_TY= PE_FREEBSD) + return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 1, + &grub_bsdlabel_partition_map, hook); + + if (disk->partition=20 + && (grub_strcmp (disk->partition->partmap->name, "msdos") =3D=3D 0= + || disk->partition->partmap =3D=3D &grub_bsdlabel_partition_map + || disk->partition->partmap =3D=3D &grub_netbsdlabel_partition_map + || disk->partition->partmap =3D=3D &grub_openbsdlabel_partition_map))= + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supporte= d"); + + return iterate_real (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0,=20 + &grub_bsdlabel_partition_map, hook); +} + +static grub_err_t +netopenbsdlabel_partition_map_iterate (grub_disk_t disk, grub_uint8_t ty= pe, + struct grub_partition_map *pmap, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + grub_err_t err; + + if (disk->partition && grub_strcmp (disk->partition->partmap->name, "m= sdos") + =3D=3D 0) + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"= ); + + { + struct grub_msdos_partition_mbr mbr; + unsigned i; + + err =3D grub_disk_read (disk, 0, 0, sizeof (mbr), &mbr); + if (err) + return err; + + for (i =3D 0; i < ARRAY_SIZE (mbr.entries); i++) + if (mbr.entries[i].type =3D=3D type) + { + err =3D iterate_real (disk, mbr.entries[i].start + + GRUB_PC_PARTITION_BSD_LABEL_SECTOR, 0, pmap, + hook); + if (err !=3D GRUB_ERR_BAD_PART_TABLE) + return err; + } + } + + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no bsdlabel found"); +} + +static grub_err_t +netbsdlabel_partition_map_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + return netopenbsdlabel_partition_map_iterate (disk, + GRUB_PC_PARTITION_TYPE_NETBSD, + &grub_netbsdlabel_partition_map, + hook); +} + +static grub_err_t +openbsdlabel_partition_map_iterate (grub_disk_t disk, + int (*hook) (grub_disk_t disk, + const grub_partition_t partition)) +{ + return netopenbsdlabel_partition_map_iterate (disk, + GRUB_PC_PARTITION_TYPE_OPENBSD, + &grub_openbsdlabel_partition_map, + hook); +} + + static struct grub_partition_map grub_bsdlabel_partition_map =3D { .name =3D "bsd", .iterate =3D bsdlabel_partition_map_iterate, }; =20 +static struct grub_partition_map grub_openbsdlabel_partition_map =3D + { + .name =3D "openbsd", + .iterate =3D openbsdlabel_partition_map_iterate, + }; + +static struct grub_partition_map grub_netbsdlabel_partition_map =3D + { + .name =3D "netbsd", + .iterate =3D netbsdlabel_partition_map_iterate, + }; + +=0C + GRUB_MOD_INIT(part_bsd) { grub_partition_map_register (&grub_bsdlabel_partition_map); + grub_partition_map_register (&grub_netbsdlabel_partition_map); + grub_partition_map_register (&grub_openbsdlabel_partition_map); } =20 GRUB_MOD_FINI(part_bsd) { grub_partition_map_unregister (&grub_bsdlabel_partition_map); + grub_partition_map_unregister (&grub_netbsdlabel_partition_map); + grub_partition_map_unregister (&grub_openbsdlabel_partition_map); } =3D=3D=3D modified file 'grub-core/partmap/msdos.c' --- grub-core/partmap/msdos.c 2010-03-26 14:44:13 +0000 +++ grub-core/partmap/msdos.c 2010-09-03 22:48:07 +0000 @@ -37,6 +37,15 @@ int labeln =3D 0; grub_disk_addr_t lastaddr; grub_disk_addr_t ext_offset; + grub_disk_addr_t delta =3D 0; + + if (disk->partition && disk->partition->partmap =3D=3D &grub_msdos_par= tition_map) + { + if (disk->partition->msdostype =3D=3D GRUB_PC_PARTITION_TYPE_LINUX= _MINIX) + delta =3D disk->partition->offset; + else + return grub_error (GRUB_ERR_BAD_PART_TABLE, "no embedding supported"); + } =20 p.offset =3D 0; ext_offset =3D 0; @@ -81,8 +90,9 @@ { e =3D mbr.entries + p.index; =20 - p.start =3D p.offset + grub_le_to_cpu32 (e->start); + p.start =3D p.offset + grub_le_to_cpu32 (e->start) - delta; p.len =3D grub_le_to_cpu32 (e->length); + p.msdostype =3D e->type; =20 grub_dprintf ("partition", "partition %d: flag 0x%x, type 0x%x, start 0x%llx, len 0x%llx\n", =3D=3D=3D modified file 'include/grub/partition.h' --- include/grub/partition.h 2010-07-14 09:26:17 +0000 +++ include/grub/partition.h 2010-09-03 22:48:07 +0000 @@ -65,6 +65,10 @@ =20 /* The type partition map. */ grub_partition_map_t partmap; + + /* The type of partition whne it's on MSDOS. + Used for embedding detection. */ + grub_uint8_t msdostype; }; =20 grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *di= sk, =3D=3D=3D modified file 'util/grub-install.in' --- util/grub-install.in 2010-08-30 18:23:04 +0000 +++ util/grub-install.in 2010-09-03 23:18:51 +0000 @@ -332,7 +332,12 @@ # filesystem will be accessible). partmap_module=3D for x in `$grub_probe --target=3Dpartmap --device ${grub_device} 2> /dev= /null`; do - partmap_module=3D"$partmap_module part_$x"; + case "$x" in + netbsd | openbsd)=20 + partmap_module=3D"$partmap_module part_bsd";; + *) + partmap_module=3D"$partmap_module part_$x";; + esac done =20 # Device abstraction module, if any (lvm, raid). --------------020807030508000602050701-- --------------enigEB3B58BC92F25795F07E6EB9 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAkyBjbwACgkQNak7dOguQglGEAD/XyU0E6dN1yCEzqRoK25RfNqv SA4lZF1Oz0mCyEf9AxAA/3L+pM07uaMPvPiGfATmdxTaB85scC0h8NNXEK2KjEPQ =Rxdt -----END PGP SIGNATURE----- --------------enigEB3B58BC92F25795F07E6EB9--