[gparted] Fix numerical mismatch when graphically moving logical partition (#628554)



commit 9d4ae28759af168b6a187de5f2d6735f976eec71
Author: Curtis Gedak <gedakc gmail com>
Date:   Tue Sep 7 16:56:38 2010 -0600

    Fix numerical mismatch when graphically moving logical partition (#628554)

 src/Dialog_Base_Partition.cc        |   17 ++++-------------
 src/Dialog_Partition_Resize_Move.cc |   16 ++++++++++++++--
 2 files changed, 18 insertions(+), 15 deletions(-)
---
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index a8d1fe4..3dca4cf 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -241,8 +241,8 @@ void Dialog_Base_Partition::on_signal_move( int x_start, int x_end )
 {  
 	GRIP = true ;
 
-	spinbutton_before .set_value( x_start <= MIN_SPACE_BEFORE_MB * MB_PER_PIXEL ? MIN_SPACE_BEFORE_MB : x_start * MB_PER_PIXEL ) ;
-	
+	spinbutton_before .set_value( x_start * MB_PER_PIXEL ) ;
+
 	if ( x_end == 500 )
 	{
 		spinbutton_after .set_value( 0 ) ;
@@ -275,17 +275,8 @@ void Dialog_Base_Partition::on_signal_resize( int x_start, int x_end, Frame_Resi
 			spinbutton_after .set_value( TOTAL_MB - before_value - spinbutton_size .get_value() ) ;
 	}
 	else if ( arrow == Frame_Resizer_Base::ARROW_LEFT ) //don't touch freespace after, leave it as it is
-	{
-		if ( x_start <= MIN_SPACE_BEFORE_MB * MB_PER_PIXEL )
-		{
-			spinbutton_before .set_value( MIN_SPACE_BEFORE_MB );
-			spinbutton_size .set_value( TOTAL_MB - MIN_SPACE_BEFORE_MB - spinbutton_after.get_value() ) ;
-		}
-		else
-			spinbutton_before .set_value(
-				TOTAL_MB - spinbutton_size .get_value() - spinbutton_after .get_value() ) ;
-	}
-		
+		spinbutton_before .set_value( TOTAL_MB - spinbutton_size .get_value() - spinbutton_after .get_value() ) ;
+
 	Check_Change() ;
 	
 	GRIP = false ;
diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc
index fb1872f..43b3ec3 100644
--- a/src/Dialog_Partition_Resize_Move.cc
+++ b/src/Dialog_Partition_Resize_Move.cc
@@ -103,7 +103,13 @@ void Dialog_Partition_Resize_Move::Resize_Move_Normal( const std::vector<Partiti
 	if ( t +1 < partitions .size() && partitions[t +1] .type == GParted::TYPE_UNALLOCATED )
 		next = partitions[t +1] .get_sector_length() ;
 
-	MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition ) ;
+	//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.
+	if ( previous <= 0 )
+		MIN_SPACE_BEFORE_MB = 0 ;
+	else
+		MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition ) ;
 	total_length = previous + selected_partition .get_sector_length() + next;
 	TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, selected_partition .sector_size, UNIT_MIB ) ) ;
 	
@@ -193,7 +199,13 @@ void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector<Parti
 		next = partitions[ t +1 ] .get_sector_length() ;
 		
 	//now we have enough data to calculate some important values..
-	MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition ) ;
+	//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.
+	if ( previous <= 0 )
+		MIN_SPACE_BEFORE_MB = 0 ;
+	else
+		MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition ) ;
 	total_length = previous + selected_partition .get_sector_length() + next;
 	TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, selected_partition .sector_size, UNIT_MIB ) ) ;
 	MB_PER_PIXEL = TOTAL_MB / 500.00 ;



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