[parted-devel] [PATCH] libparted: handle busy extended partition

Petr Uzel petr.uzel at suse.cz
Wed Oct 24 21:14:15 UTC 2012


When parted encounters busy partition during its loop for informing
the kernel about partition changes, it tries to compare geometry
of the to-be created partition with the geometry of the existing
partition (reported by the kernel). If these geometries match, there is
nothing more to do for parted.

However, this fails for msdos extended partitions, because kernel does
not report full size of extended partition (usually 1 or 2 sectors
instead), no matter how big it actually is (to avoid having overlapping
partitions in the kernel's representation of partition table). This
makes the comparison of geometries to fail for extended partitions, so
they need to be handled specially.

Steps to reproduce:
modprobe scsi_debug
parted -s /dev/sdX mklabel msdos
parted -s /dev/sdX mkpart extended 1M -- -1
exec 3>/dev/sdX1  # make sdX1 busy
parted -s /dev/sdX mkpart logical ext2 2M 4M

* libparted/arch/linux.c (_disk_sync_part_table): Do not check size
of extended partition if the previous one was also extended.
---
 libparted/arch/linux.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index e2b7365..54011e8 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2614,9 +2614,11 @@ _disk_sync_part_table (PedDisk* disk)
                                 if (!_kernel_get_partition_start_and_length(part,
                                                                 &start, &length))
                                         goto cleanup;
-                                if (start == part->geom.start
-				    && length == part->geom.length)
-                                        ok[i - 1] = 1;
+				if (start == part->geom.start
+				    && (length == part->geom.length
+					|| (part->type == PED_PARTITION_EXTENDED
+					    && length <= 2)))
+						ok[i - 1] = 1;
                                 /* If the new partition is unchanged and the
 				   existing one was not removed because it was
 				   in use, then reset the error flag and do not
-- 
1.7.10.4



More information about the parted-devel mailing list