119 lines
5.3 KiB
Diff
119 lines
5.3 KiB
Diff
|
From fab679e6ffad84f3454b73529ef0a444b1d2f7ec Mon Sep 17 00:00:00 2001
|
||
|
From: Phillip Susi <psusi@ubuntu.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.
|
||
|
|
||
|
Previously parted did create the partition table, and after a
|
||
|
reboot, the kernel would recognize the table, and happily create
|
||
|
the extended partition as 2 sectors long, thus overlapping the
|
||
|
logical partition, but when parted tried to recreate the same
|
||
|
table with BLKPG, the kernel rightly rejected it.
|
||
|
---
|
||
|
NEWS | 8 ++++++++
|
||
|
libparted/arch/linux.c | 17 +++++++++++++++--
|
||
|
tests/t2310-dos-extended-2-sector-min-offset.sh | 18 +++++-------------
|
||
|
3 files changed, 28 insertions(+), 15 deletions(-)
|
||
|
|
||
|
diff --git a/NEWS b/NEWS
|
||
|
index 04b905c..c884eac 100644
|
||
|
--- a/NEWS
|
||
|
+++ b/NEWS
|
||
|
@@ -4,6 +4,14 @@ GNU parted NEWS -*- outline -*-
|
||
|
|
||
|
** Bug Fixes
|
||
|
|
||
|
+ libparted: handle logical partitions starting immediately after
|
||
|
+ the EBR. Creating a logical partition one sector after the EBR
|
||
|
+ used to cause parted to complain that it could not inform the
|
||
|
+ kernel of the changes, but after a reboot, everything was fine.
|
||
|
+ Parted will now correctly inform the kernel of the changes, but
|
||
|
+ only set the length of the extended partition to 1 sector instead
|
||
|
+ of two, which would cause it to overlap the logical partition.
|
||
|
+
|
||
|
parted: fix EOF and ctrl-c handling. parted used to refuse to exit
|
||
|
in response to ctrl-c and would get stuck in an infinite loop
|
||
|
prompting for more input when it reached EOF on stdin.
|
||
|
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
|
||
|
index 083591f..1f1d67f 100644
|
||
|
--- a/libparted/arch/linux.c
|
||
|
+++ b/libparted/arch/linux.c
|
||
|
@@ -2473,8 +2473,21 @@ _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)
|
||
|
- linux_part.length = part->geom.length == 1 ? 512 : 1024;
|
||
|
+ if (part->type & PED_PARTITION_EXTENDED) {
|
||
|
+ linux_part.length = 1;
|
||
|
+ if (disk->dev->sector_size == 512) {
|
||
|
+ if (linux_part.length == 1)
|
||
|
+ linux_part.length = 2;
|
||
|
+ 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 = 1;
|
||
|
+ }
|
||
|
+ }
|
||
|
+ linux_part.length *= disk->dev->sector_size;
|
||
|
+ }
|
||
|
else
|
||
|
linux_part.length = part->geom.length * disk->dev->sector_size;
|
||
|
linux_part.pno = part->num;
|
||
|
diff --git a/tests/t2310-dos-extended-2-sector-min-offset.sh b/tests/t2310-dos-extended-2-sector-min-offset.sh
|
||
|
index 17c777c..f74cba5 100644
|
||
|
--- a/tests/t2310-dos-extended-2-sector-min-offset.sh
|
||
|
+++ b/tests/t2310-dos-extended-2-sector-min-offset.sh
|
||
|
@@ -1,10 +1,8 @@
|
||
|
#!/bin/sh
|
||
|
-# Ensure that parted leaves at least 2 sectors between the beginning
|
||
|
+# Ensure that parted allows a single sector between the beginning
|
||
|
# of an extended partition and the first logical partition.
|
||
|
-# Before parted-2.3, it could be made to leave just one, and that
|
||
|
-# would cause trouble with the Linux kernel.
|
||
|
|
||
|
-# Copyright (C) 2010-2012 Free Software Foundation, Inc.
|
||
|
+# Copyright (C) 2010-2013 Free Software Foundation, Inc.
|
||
|
|
||
|
# This program is free software; you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
@@ -35,7 +33,7 @@ cat <<EOF > exp || framework_failure
|
||
|
BYT;
|
||
|
$scsi_dev:2048s:scsi:512:512:msdos:Linux scsi_debug:;
|
||
|
1:64s:128s:65s:::lba;
|
||
|
-5:66s:128s:63s:::;
|
||
|
+5:65s:128s:64s:::;
|
||
|
EOF
|
||
|
|
||
|
cat <<EOF > err.exp || framework_failure
|
||
|
@@ -48,15 +46,9 @@ parted --align=min -s $scsi_dev mkpart extended 64s 128s> out 2>&1 || fail=1
|
||
|
parted -m -s $scsi_dev u s print
|
||
|
compare /dev/null out || fail=1
|
||
|
|
||
|
-# Provoke a failure by trying to create a partition that starts just
|
||
|
+# Trying to create a partition that starts just
|
||
|
# one sector after the start of the extended partition.
|
||
|
-parted --align=min -s $scsi_dev mkpart logical 65s 128s > err 2>&1 && fail=1
|
||
|
-compare err.exp err || fail=1
|
||
|
-
|
||
|
-# The above failed, but created the partition nonetheless. Remove it.
|
||
|
-parted -s $scsi_dev rm 5 || fail=1
|
||
|
-
|
||
|
-parted --align=min -s $scsi_dev mkpart logical 66s 128s > out 2>&1 || fail=1
|
||
|
+parted --align=min -s $scsi_dev mkpart logical 65s 128s > out 2>&1 || fail=1
|
||
|
compare /dev/null out || fail=1
|
||
|
|
||
|
parted -m -s $scsi_dev u s print > out 2>&1
|
||
|
--
|
||
|
1.8.5.3
|
||
|
|