>From 5e4ab9a30c67dddac16cc6377992fd836baa8809 Mon Sep 17 00:00:00 2001
From: Phillip Susi <psusi@cfl.rr.com>
Date: Thu, 12 Jan 2012 14:53:56 -0500
Subject: [PATCH] libparted: handle logical partitions starting immediately
 after the EBR

_blkpg_add_partition() set the length of the extended partition
to 2 sectors to allow LILO to be installed there, beacuse the
linux kernel does this.  If a logical partition used that second
sector, adding it would fail beacuse of the overlap.  Now
_blkpg_add_partition() will limit the length to only the first
sector if the second is used by a logical partition.
---
 libparted/arch/linux.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index e2c4139..781cd50 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2369,8 +2369,16 @@ _blkpg_add_partition (PedDisk* disk, const PedPartition *part)
         memset (&linux_part, 0, sizeof (linux_part));
         linux_part.start = part->geom.start * disk->dev->sector_size;
         /* see fs/partitions/msdos.c:msdos_partition(): "leave room for LILO" */
-        if (part->type & PED_PARTITION_EXTENDED)
+        if (part->type & PED_PARTITION_EXTENDED) {
                 linux_part.length = part->geom.length == 1 ? 512 : 1024;
+                PedPartition *walk;
+                /* if the second sector is claimed by a logical partition,
+                   then there's just no room for lilo, so don't try to use it */
+                for (walk = part->part_list; walk; walk = walk->next) {
+                        if (walk->geom.start == part->geom.start+1)
+                                linux_part.length = 512;
+                }
+	}
         else
                 linux_part.length = part->geom.length * disk->dev->sector_size;
         linux_part.pno = part->num;
-- 
1.7.5.4

