From 6a6607e1c69728b2fd55faf7927db5c979628514 Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Sat, 30 Jun 2012 10:35:08 -0600 Subject: [PATCH] Avoid end partition overlap when resizing extended partition (#678831) When resizing an extended partition, a problem can occur with MiB alignment wherein the requested end sector could be less than the end sector of the last logical partition. This would be an invalid geometry because all the logical partitions must be wholly contained within the extended partition. Check for this situation and if found then set requested end for the extended partition to the end of the last logical partition. Closes Bug #678831 - Partition End Overlap when Resizing Extended Partition --- src/GParted_Core.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index b5b74234..a664d2ba 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -566,6 +566,26 @@ bool GParted_Core::snap_to_mebibyte( const Device & device, Partition & partitio } } + //If this is an extended partition then check to see if the end of the + // extended partition encompasses the end of the last logical partition. + if ( partition .type == TYPE_EXTENDED ) + { + //If there is logical partition that has an end sector beyond the + // end of the extended partition, then set the extended partition + // end sector to be the same as the end of the logical partition. + for ( unsigned int t = 0; t < partition .logicals .size(); t++ ) + { + if ( ( partition .logicals[ t ] .type == TYPE_LOGICAL ) + && ( ( partition .logicals[ t ] .sector_end ) + > ( partition .sector_end ) + ) + ) + { + partition .sector_end = partition .logicals[ t ] .sector_end ; + } + } + } + //If this is a GPT partition table and the partition ends less than 34 sectors // from the end of the device, then reserve at least a mebibyte for the // backup partition table