[gparted] Fix crash moving more than one logical partition right (#628863)



commit 7c0e3fa7789f413e8408e89ff7470e8ff86e7e72
Author: Curtis Gedak <gedakc gmail com>
Date:   Sun Oct 24 12:35:59 2010 -0600

    Fix crash moving more than one logical partition right (#628863)
    
    This problem would occur when using align to MiB for the
    destination partitions.
    
    Closes bug #628863 - gparted crashes applying move to right of
                         more than one logical partition

 src/Dialog_Partition_Resize_Move.cc |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc
index 43b3ec3..7987ef9 100644
--- a/src/Dialog_Partition_Resize_Move.cc
+++ b/src/Dialog_Partition_Resize_Move.cc
@@ -101,8 +101,31 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector<Partiti
 		START = selected_partition .sector_start ;
 	
 	if ( t +1 < partitions .size() && partitions[t +1] .type == GParted::TYPE_UNALLOCATED )
+	{
 		next = partitions[t +1] .get_sector_length() ;
 
+		//If this is a logical partition and there is extra free space
+		//  then check if we need to reserve 1 MiB of space after for
+		//  the next logical partition Extended Boot Record.
+		if (   selected_partition .type == TYPE_LOGICAL
+		    && next >= (MEBIBYTE / selected_partition .sector_size)
+		   )
+		{
+			//Find maximum sector_end (allocated or unallocated) within list of
+			//  partitions inside the extended partition
+			Sector max_sector_end = 0 ;
+			for (unsigned int k = 0 ; k < partitions .size() ; k++ )
+			{
+				if ( partitions[ k ] .sector_end > max_sector_end )
+					max_sector_end = partitions[ k ] .sector_end ;
+			}
+
+			//If not within 1 MiB of the end of the extended partition, then reserve 1 MiB
+			if ( ( max_sector_end - partitions[t+1] .sector_end ) > ( MEBIBYTE / selected_partition .sector_size ) )
+				next -= MEBIBYTE / selected_partition .sector_size ;
+		}
+	}
+
 	//Only calculate MIN_SPACE_BEFORE_MB if we have a previous (unallocated) partition.
 	//  Otherwise there will not be enough graphical space to reserve a full 1 MiB for MBR/EBR.
 	//  Since this is an existing partition, if an MBR/EBR was needed then it already exists with enough space.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]