dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0157-Makefile.util.def-Add-partmap-msdos.c-to-common-libr.patch

f96e0b
From afa175e51f263d3090d1ba078bed97c7204ed986 Mon Sep 17 00:00:00 2001
f96e0b
From: Andrey Borzenkov <arvidjaar@gmail.com>
f96e0b
Date: Mon, 25 Feb 2013 22:11:06 +0100
f96e0b
Subject: [PATCH 157/482] 	* Makefile.util.def: Add partmap/msdos.c to
f96e0b
 common library. 	* include/grub/msdos_partition.h: Add
f96e0b
 GRUB_PC_PARTITION_TYPE_LDM 	* grub-core/disk/ldm.c: Check for existence of
f96e0b
 	GRUB_PC_PARTITION_TYPE_LDM.
f96e0b
f96e0b
---
f96e0b
 ChangeLog                      |  7 +++++++
f96e0b
 Makefile.util.def              |  2 +-
f96e0b
 grub-core/disk/ldm.c           | 42 ++++++++++++++++++++++++++++++++++++++++--
f96e0b
 include/grub/msdos_partition.h |  1 +
f96e0b
 4 files changed, 49 insertions(+), 3 deletions(-)
f96e0b
f96e0b
diff --git a/ChangeLog b/ChangeLog
f96e0b
index ff5a558..107c049 100644
f96e0b
--- a/ChangeLog
f96e0b
+++ b/ChangeLog
f96e0b
@@ -1,3 +1,10 @@
f96e0b
+2013-02-25  Andrey Borzenkov <arvidjaar@gmail.com>
f96e0b
+
f96e0b
+	* Makefile.util.def: Add partmap/msdos.c to common library.
f96e0b
+	* include/grub/msdos_partition.h: Add GRUB_PC_PARTITION_TYPE_LDM
f96e0b
+	* grub-core/disk/ldm.c: Check for existence of
f96e0b
+	GRUB_PC_PARTITION_TYPE_LDM.
f96e0b
+
f96e0b
 2013-02-25  Vladimir Serbinenko  <phcoder@gmail.com>
f96e0b
 
f96e0b
 	* grub-core/normal/misc.c (grub_normal_print_device_info): Use KiB to display
f96e0b
diff --git a/Makefile.util.def b/Makefile.util.def
f96e0b
index 3ee5e4e..1ccf390 100644
f96e0b
--- a/Makefile.util.def
f96e0b
+++ b/Makefile.util.def
f96e0b
@@ -32,6 +32,7 @@ library = {
f96e0b
   common = grub-core/disk/ldm.c;
f96e0b
   common = grub-core/disk/diskfilter.c;
f96e0b
   common = grub-core/partmap/gpt.c;
f96e0b
+  common = grub-core/partmap/msdos.c;
f96e0b
 };
f96e0b
 
f96e0b
 library = {
f96e0b
@@ -110,7 +111,6 @@ library = {
f96e0b
   common = grub-core/partmap/acorn.c;
f96e0b
   common = grub-core/partmap/amiga.c;
f96e0b
   common = grub-core/partmap/apple.c;
f96e0b
-  common = grub-core/partmap/msdos.c;
f96e0b
   common = grub-core/partmap/sun.c;
f96e0b
   common = grub-core/partmap/plan.c;
f96e0b
   common = grub-core/partmap/dvh.c;
f96e0b
diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c
f96e0b
index b92433d..a2e26b2 100644
f96e0b
--- a/grub-core/disk/ldm.c
f96e0b
+++ b/grub-core/disk/ldm.c
f96e0b
@@ -22,6 +22,7 @@
f96e0b
 #include <grub/err.h>
f96e0b
 #include <grub/misc.h>
f96e0b
 #include <grub/diskfilter.h>
f96e0b
+#include <grub/msdos_partition.h>
f96e0b
 #include <grub/gpt_partition.h>
f96e0b
 #include <grub/i18n.h>
f96e0b
 
f96e0b
@@ -103,6 +104,37 @@ read_int (grub_uint8_t *in, grub_size_t s)
f96e0b
   return ret;
f96e0b
 }
f96e0b
 
f96e0b
+static int
f96e0b
+check_ldm_partition (grub_disk_t disk __attribute__ ((unused)), const grub_partition_t p, void *data)
f96e0b
+{
f96e0b
+  int *has_ldm = data;
f96e0b
+
f96e0b
+  if (p->number >= 4)
f96e0b
+    return 1;
f96e0b
+  if (p->msdostype == GRUB_PC_PARTITION_TYPE_LDM)
f96e0b
+    {
f96e0b
+      *has_ldm = 1;
f96e0b
+      return 1;
f96e0b
+    }
f96e0b
+  return 0;
f96e0b
+}
f96e0b
+
f96e0b
+static int
f96e0b
+msdos_has_ldm_partition (grub_disk_t dsk)
f96e0b
+{
f96e0b
+  grub_err_t err;
f96e0b
+  int has_ldm = 0;
f96e0b
+
f96e0b
+  err = grub_partition_msdos_iterate (dsk, check_ldm_partition, &has_ldm);
f96e0b
+  if (err)
f96e0b
+    {
f96e0b
+      grub_errno = GRUB_ERR_NONE;
f96e0b
+      return 0;
f96e0b
+    }
f96e0b
+
f96e0b
+  return has_ldm;
f96e0b
+}
f96e0b
+
f96e0b
 static const grub_gpt_part_type_t ldm_type = GRUB_GPT_PARTITION_TYPE_LDM;
f96e0b
 
f96e0b
 /* Helper for gpt_ldm_sector.  */
f96e0b
@@ -760,17 +792,20 @@ grub_ldm_detect (grub_disk_t disk,
f96e0b
 
f96e0b
   {
f96e0b
     int i;
f96e0b
+    int has_ldm = msdos_has_ldm_partition (disk);
f96e0b
     for (i = 0; i < 3; i++)
f96e0b
       {
f96e0b
 	grub_disk_addr_t sector = LDM_LABEL_SECTOR;
f96e0b
 	switch (i)
f96e0b
 	  {
f96e0b
 	  case 0:
f96e0b
+	    if (!has_ldm)
f96e0b
+	      continue;
f96e0b
 	    sector = LDM_LABEL_SECTOR;
f96e0b
 	    break;
f96e0b
 	  case 1:
f96e0b
 	    /* LDM is never inside a partition.  */
f96e0b
-	    if (disk->partition)
f96e0b
+	    if (!has_ldm || disk->partition)
f96e0b
 	      continue;
f96e0b
 	    sector = grub_disk_get_size (disk);
f96e0b
 	    if (sector == GRUB_DISK_SIZE_UNKNOWN)
f96e0b
@@ -871,6 +906,7 @@ int
f96e0b
 grub_util_is_ldm (grub_disk_t disk)
f96e0b
 {
f96e0b
   int i;
f96e0b
+  int has_ldm = msdos_has_ldm_partition (disk);
f96e0b
   for (i = 0; i < 3; i++)
f96e0b
     {
f96e0b
       grub_disk_addr_t sector = LDM_LABEL_SECTOR;
f96e0b
@@ -880,11 +916,13 @@ grub_util_is_ldm (grub_disk_t disk)
f96e0b
       switch (i)
f96e0b
 	{
f96e0b
 	case 0:
f96e0b
+	  if (!has_ldm)
f96e0b
+	    continue;
f96e0b
 	  sector = LDM_LABEL_SECTOR;
f96e0b
 	  break;
f96e0b
 	case 1:
f96e0b
 	  /* LDM is never inside a partition.  */
f96e0b
-	  if (disk->partition)
f96e0b
+	  if (!has_ldm || disk->partition)
f96e0b
 	    continue;
f96e0b
 	  sector = grub_disk_get_size (disk);
f96e0b
 	  if (sector == GRUB_DISK_SIZE_UNKNOWN)
f96e0b
diff --git a/include/grub/msdos_partition.h b/include/grub/msdos_partition.h
f96e0b
index 1e9b65e..92f8539 100644
f96e0b
--- a/include/grub/msdos_partition.h
f96e0b
+++ b/include/grub/msdos_partition.h
f96e0b
@@ -43,6 +43,7 @@
f96e0b
 #define GRUB_PC_PARTITION_TYPE_FAT16_LBA	0xe
f96e0b
 #define GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED	0xf
f96e0b
 #define GRUB_PC_PARTITION_TYPE_PLAN9            0x39
f96e0b
+#define GRUB_PC_PARTITION_TYPE_LDM		0x42
f96e0b
 #define GRUB_PC_PARTITION_TYPE_EZD		0x55
f96e0b
 #define GRUB_PC_PARTITION_TYPE_MINIX		0x80
f96e0b
 #define GRUB_PC_PARTITION_TYPE_LINUX_MINIX	0x81
f96e0b
-- 
f96e0b
1.8.2.1
f96e0b