From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1TxMS8-00019Y-9M for mharc-grub-devel@gnu.org; Mon, 21 Jan 2013 13:50:40 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxMS5-00019N-G0 for grub-devel@gnu.org; Mon, 21 Jan 2013 13:50:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TxMS3-0002ZI-Qq for grub-devel@gnu.org; Mon, 21 Jan 2013 13:50:37 -0500 Received: from mail-la0-f49.google.com ([209.85.215.49]:48396) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxMS3-0002Z8-Ez for grub-devel@gnu.org; Mon, 21 Jan 2013 13:50:35 -0500 Received: by mail-la0-f49.google.com with SMTP id fs13so262806lab.22 for ; Mon, 21 Jan 2013 10:50:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:subject:message-id:in-reply-to:references :x-mailer:mime-version:content-type; bh=KxbCy8rM6sttq+oA6jNiVUQVi+KPsn2WwhP4ShsIFdY=; b=D5vHk7CnoKZ/UPVV9oXm5JkEdv8jU4h1W2SoTtjGwdfMOmRymh9PcZpl5aZlsiD3vZ CbKOoqNd+LYwo57HJBBN+tmq73egwKo3ZeJATHCe+Do9g6LXkfnQzX0Il9/QLxTHVqOx Lu8ELVJgVsm8J1JbpeZSHE6pR+92gWdEWhptdL4x2mmeLzw4m+dl42EarIWvxQ2Y7sWq Rkt6DCD35PVu89JjFzyb1UmnyXb5ttuxIVmeBfU0Fe0f6TbaVNueDSgZgXGuJ0lCj8Ta 7lOFNVEch9ta0I+RxrqSx+7KZCLi4bupS4hEr2YjlhtAWUtKHhoT+raTWNPXc9KS1XVe hahA== X-Received: by 10.112.83.202 with SMTP id s10mr8148800lby.101.1358794234207; Mon, 21 Jan 2013 10:50:34 -0800 (PST) Received: from opensuse.site (ppp91-78-198-46.pppoe.mtu-net.ru. [91.78.198.46]) by mx.google.com with ESMTPS id to7sm5941921lab.13.2013.01.21.10.50.32 (version=SSLv3 cipher=RC4-SHA bits=128/128); Mon, 21 Jan 2013 10:50:33 -0800 (PST) Date: Mon, 21 Jan 2013 22:50:30 +0400 From: Andrey Borzenkov To: grub-devel@gnu.org Subject: Re: Should LDM check be less aggressive? Message-ID: <20130121225030.0f98e9b8@opensuse.site> In-Reply-To: <50FC6882.3030703@gmail.com> References: <20121121065833.7497e7e8@opensuse.site> <50FC6882.3030703@gmail.com> X-Mailer: Claws Mail 3.9.0 (GTK+ 2.24.10; x86_64-suse-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/zLNruMfB5MhP0/hFjs23Rs0"; protocol="application/pgp-signature" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.215.49 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 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: Mon, 21 Jan 2013 18:50:38 -0000 --Sig_/zLNruMfB5MhP0/hFjs23Rs0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable =D0=92 Sun, 20 Jan 2013 22:58:26 +0100 Vladimir '=CF=86-coder/phcoder' Serbinenko =D0=BF=D0=B8= =D1=88=D0=B5=D1=82: > On 21.11.2012 03:58, Andrey Borzenkov wrote: >=20 > > + if (p->msdostype =3D=3D GRUB_PC_PARTITION_TYPE_SFS) >=20 > SFS is confusing as the partition in question isn't SFS, it just happens > that LDM and SFS ids collide. > Also another problem is that of booting in case of corrupted msdos table > if LDM is intact but given that the kernels won't be able to recognize > such a case anyway it's a minor one. Could you update the patch not to > mention SFS? >=20 Done. Also updated for new hook API. From: Andrey Borzenkov Subject: [PATCH] check for LDM partition before checking LDM label There are several reports of leftover LDM label at the end of disk blocking installation of grub. Check for existence of LDM partition before checking for LDM label validity. This is the same check as done by Linux kernel. Signed-off-by: Andrey Borzenkov --- ChangeLog | 7 +++++++ Makefile.util.def | 2 +- grub-core/disk/ldm.c | 42 ++++++++++++++++++++++++++++++++++++= ++-- include/grub/msdos_partition.h | 1 + 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 32b891a..dccdcc1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2013-01-21 Andrey Borzenkov + + * Makefile.util.def: add partmap/msdos.c to common library + * include/grub/msdos_partition.h: add GRUB_PC_PARTITION_TYPE_LDM + * grub-core/disk/ldm.c: check for existence of + GRUB_PC_PARTITION_TYPE_LDM + 2013-01-21 Vladimir Serbinenko =20 Make color variables global instead of it being per-terminal. diff --git a/Makefile.util.def b/Makefile.util.def index 3ee5e4e..1ccf390 100644 --- a/Makefile.util.def +++ b/Makefile.util.def @@ -32,6 +32,7 @@ library =3D { common =3D grub-core/disk/ldm.c; common =3D grub-core/disk/diskfilter.c; common =3D grub-core/partmap/gpt.c; + common =3D grub-core/partmap/msdos.c; }; =20 library =3D { @@ -110,7 +111,6 @@ library =3D { common =3D grub-core/partmap/acorn.c; common =3D grub-core/partmap/amiga.c; common =3D grub-core/partmap/apple.c; - common =3D grub-core/partmap/msdos.c; common =3D grub-core/partmap/sun.c; common =3D grub-core/partmap/plan.c; common =3D grub-core/partmap/dvh.c; diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c index b92433d..a2e26b2 100644 --- a/grub-core/disk/ldm.c +++ b/grub-core/disk/ldm.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include =20 @@ -103,6 +104,37 @@ read_int (grub_uint8_t *in, grub_size_t s) return ret; } =20 +static int +check_ldm_partition (grub_disk_t disk __attribute__ ((unused)), const grub= _partition_t p, void *data) +{ + int *has_ldm =3D data; + + if (p->number >=3D 4) + return 1; + if (p->msdostype =3D=3D GRUB_PC_PARTITION_TYPE_LDM) + { + *has_ldm =3D 1; + return 1; + } + return 0; +} + +static int +msdos_has_ldm_partition (grub_disk_t dsk) +{ + grub_err_t err; + int has_ldm =3D 0; + + err =3D grub_partition_msdos_iterate (dsk, check_ldm_partition, &has_ldm= ); + if (err) + { + grub_errno =3D GRUB_ERR_NONE; + return 0; + } + + return has_ldm; +} + static const grub_gpt_part_type_t ldm_type =3D GRUB_GPT_PARTITION_TYPE_LDM; =20 /* Helper for gpt_ldm_sector. */ @@ -760,17 +792,20 @@ grub_ldm_detect (grub_disk_t disk, =20 { int i; + int has_ldm =3D msdos_has_ldm_partition (disk); for (i =3D 0; i < 3; i++) { grub_disk_addr_t sector =3D LDM_LABEL_SECTOR; switch (i) { case 0: + if (!has_ldm) + continue; sector =3D LDM_LABEL_SECTOR; break; case 1: /* LDM is never inside a partition. */ - if (disk->partition) + if (!has_ldm || disk->partition) continue; sector =3D grub_disk_get_size (disk); if (sector =3D=3D GRUB_DISK_SIZE_UNKNOWN) @@ -871,6 +906,7 @@ int grub_util_is_ldm (grub_disk_t disk) { int i; + int has_ldm =3D msdos_has_ldm_partition (disk); for (i =3D 0; i < 3; i++) { grub_disk_addr_t sector =3D LDM_LABEL_SECTOR; @@ -880,11 +916,13 @@ grub_util_is_ldm (grub_disk_t disk) switch (i) { case 0: + if (!has_ldm) + continue; sector =3D LDM_LABEL_SECTOR; break; case 1: /* LDM is never inside a partition. */ - if (disk->partition) + if (!has_ldm || disk->partition) continue; sector =3D grub_disk_get_size (disk); if (sector =3D=3D GRUB_DISK_SIZE_UNKNOWN) diff --git a/include/grub/msdos_partition.h b/include/grub/msdos_partition.h index 1e9b65e..92f8539 100644 --- a/include/grub/msdos_partition.h +++ b/include/grub/msdos_partition.h @@ -43,6 +43,7 @@ #define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe #define GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED 0xf #define GRUB_PC_PARTITION_TYPE_PLAN9 0x39 +#define GRUB_PC_PARTITION_TYPE_LDM 0x42 #define GRUB_PC_PARTITION_TYPE_EZD 0x55 #define GRUB_PC_PARTITION_TYPE_MINIX 0x80 #define GRUB_PC_PARTITION_TYPE_LINUX_MINIX 0x81 --=20 tg: (812be57..) fu/tighten-LDM-check (depends on: master) --Sig_/zLNruMfB5MhP0/hFjs23Rs0 Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlD9jfYACgkQR6LMutpd94xVZwCbBQ7FsixHQDc9xr8fHbUbNyR1 gE0AoJEZC7k6v9qzRN266wH/ezYEj9K1 =FNIG -----END PGP SIGNATURE----- --Sig_/zLNruMfB5MhP0/hFjs23Rs0--