Blame SOURCES/0030-libparted-handle-logical-partitions-starting-immedia.patch

fc4a62
From 535f60c9ef91cc662d5ccaecb2f7048a3c2241d9 Mon Sep 17 00:00:00 2001
fc4a62
From: Phillip Susi <psusi@ubuntu.com>
fc4a62
Date: Thu, 12 Jan 2012 14:53:56 -0500
fc4a62
Subject: [PATCH] libparted: handle logical partitions starting immediately
fc4a62
 after the EBR
fc4a62
fc4a62
_blkpg_add_partition() set the length of the extended partition
fc4a62
to 2 sectors to allow LILO to be installed there, beacuse the
fc4a62
linux kernel does this.  If a logical partition used that second
fc4a62
sector, adding it would fail beacuse of the overlap.  Now
fc4a62
_blkpg_add_partition() will limit the length to only the first
fc4a62
sector if the second is used by a logical partition.
fc4a62
fc4a62
Previously parted did create the partition table, and after a
fc4a62
reboot, the kernel would recognize the table, and happily create
fc4a62
the extended partition as 2 sectors long, thus overlapping the
fc4a62
logical partition, but when parted tried to recreate the same
fc4a62
table with BLKPG, the kernel rightly rejected it.
fc4a62
fc4a62
(cherry picked from commit f503870153eda7659b09e52e4adeda3bebf06471)
fc4a62
---
fc4a62
 NEWS                                            |  8 ++++++++
fc4a62
 libparted/arch/linux.c                          | 17 +++++++++++++++--
fc4a62
 tests/t2310-dos-extended-2-sector-min-offset.sh | 16 ++++------------
fc4a62
 3 files changed, 27 insertions(+), 14 deletions(-)
fc4a62
fc4a62
diff --git a/NEWS b/NEWS
fc4a62
index 4d30b1b..d1ab2a6 100644
fc4a62
--- a/NEWS
fc4a62
+++ b/NEWS
fc4a62
@@ -11,6 +11,14 @@ GNU parted NEWS                                    -*- outline -*-
fc4a62
 
fc4a62
 ** Bug Fixes
fc4a62
 
fc4a62
+  libparted: handle logical partitions starting immediately after
fc4a62
+  the EBR.  Creating a logical partition one sector after the EBR
fc4a62
+  used to cause parted to complain that it could not inform the
fc4a62
+  kernel of the changes, but after a reboot, everything was fine.
fc4a62
+  Parted will now correctly inform the kernel of the changes, but
fc4a62
+  only set the length of the extended partition to 1 sector instead
fc4a62
+  of two, which would cause it to overlap the logical partition.
fc4a62
+
fc4a62
   If a drive was 100 times an even multiple of two, sizes specified as
fc4a62
   a percentage would trigger the exact placement rule and refuse to round
fc4a62
   to the nearest half percent.
fc4a62
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
fc4a62
index 4daa881..788cdc3 100644
fc4a62
--- a/libparted/arch/linux.c
fc4a62
+++ b/libparted/arch/linux.c
fc4a62
@@ -2371,8 +2371,21 @@ _blkpg_add_partition (PedDisk* disk, const PedPartition *part)
fc4a62
         memset (&linux_part, 0, sizeof (linux_part));
fc4a62
         linux_part.start = part->geom.start * disk->dev->sector_size;
fc4a62
         /* see fs/partitions/msdos.c:msdos_partition(): "leave room for LILO" */
fc4a62
-        if (part->type & PED_PARTITION_EXTENDED)
fc4a62
-                linux_part.length = part->geom.length == 1 ? 512 : 1024;
fc4a62
+        if (part->type & PED_PARTITION_EXTENDED) {
fc4a62
+                linux_part.length = 1;
fc4a62
+                if (disk->dev->sector_size == 512) {
fc4a62
+                        if (linux_part.length == 1)
fc4a62
+                                linux_part.length = 2;
fc4a62
+                        PedPartition *walk;
fc4a62
+                        /* if the second sector is claimed by a logical partition,
fc4a62
+                           then there's just no room for lilo, so don't try to use it */
fc4a62
+                        for (walk = part->part_list; walk; walk = walk->next) {
fc4a62
+                                if (walk->geom.start == part->geom.start+1)
fc4a62
+                                        linux_part.length = 1;
fc4a62
+                        }
fc4a62
+                }
fc4a62
+                linux_part.length *= disk->dev->sector_size;
fc4a62
+        }
fc4a62
         else
fc4a62
                 linux_part.length = part->geom.length * disk->dev->sector_size;
fc4a62
         linux_part.pno = part->num;
fc4a62
diff --git a/tests/t2310-dos-extended-2-sector-min-offset.sh b/tests/t2310-dos-extended-2-sector-min-offset.sh
fc4a62
index 89453ae..bd7defb 100644
fc4a62
--- a/tests/t2310-dos-extended-2-sector-min-offset.sh
fc4a62
+++ b/tests/t2310-dos-extended-2-sector-min-offset.sh
fc4a62
@@ -1,8 +1,6 @@
fc4a62
 #!/bin/sh
fc4a62
-# Ensure that parted leaves at least 2 sectors between the beginning
fc4a62
+# Ensure that parted allows a single sector between the beginning
fc4a62
 # of an extended partition and the first logical partition.
fc4a62
-# Before parted-2.3, it could be made to leave just one, and that
fc4a62
-# would cause trouble with the Linux kernel.
fc4a62
 
fc4a62
 # Copyright (C) 2010-2012 Free Software Foundation, Inc.
fc4a62
 
fc4a62
@@ -35,7 +33,7 @@ cat <<EOF > exp || framework_failure
fc4a62
 BYT;
fc4a62
 $scsi_dev:2048s:scsi:512:512:msdos:Linux scsi_debug:;
fc4a62
 1:64s:128s:65s:::lba;
fc4a62
-5:66s:128s:63s:::;
fc4a62
+5:65s:128s:64s:::;
fc4a62
 EOF
fc4a62
 
fc4a62
 cat <<EOF > err.exp || framework_failure
fc4a62
@@ -49,15 +47,9 @@ parted --align=min -s $scsi_dev mkpart extended 64s 128s> out 2>&1 || fail=1
fc4a62
 parted -m -s $scsi_dev u s print
fc4a62
 compare /dev/null out || fail=1
fc4a62
 
fc4a62
-# Provoke a failure by trying to create a partition that starts just
fc4a62
+# Trying to create a partition that starts just
fc4a62
 # one sector after the start of the extended partition.
fc4a62
-parted --align=min -s $scsi_dev mkpart logical 65s 128s > err 2>&1 && fail=1
fc4a62
-compare err.exp err || fail=1
fc4a62
-
fc4a62
-# The above failed, but created the partition nonetheless.  Remove it.
fc4a62
-parted -s $scsi_dev rm 5 || fail=1
fc4a62
-
fc4a62
-parted --align=min -s $scsi_dev mkpart logical 66s 128s > out 2>&1 || fail=1
fc4a62
+parted --align=min -s $scsi_dev mkpart logical 65s 128s > out 2>&1 || fail=1
fc4a62
 compare /dev/null out || fail=1
fc4a62
 
fc4a62
 parted -m -s $scsi_dev u s print > out 2>&1
fc4a62
-- 
fc4a62
2.1.0
fc4a62