[gparted] Fix size reduced by 1 MiB when created after cylinder aligned partition



commit a30f991ca57453f29e2c3ad85c05be8e436fe860
Author: Curtis Gedak <gedakc gmail com>
Date:   Thu Sep 9 13:12:32 2010 -0600

    Fix size reduced by 1 MiB when created after cylinder aligned partition
    
    Prior to this enhancement creating a new partition aligned to MiB
    after a partition aligned to cylinder would result in the creation of
    a partition that was 1 MiB smaller in size than requested.  In the
    case of a 1 MiB new partition, a warning message would be displayed
    indicating that "A partition cannot have a length of 0 sectors".
    
    This problem is avoided by applying similar logic as was used to
    address the following bug:
    Bug #626946 - Destination partition smaller than source partition

 src/Dialog_Partition_New.cc |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index ff3ed8d..41c19a2 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -227,7 +227,16 @@ Partition Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
 	switch ( optionmenu_alignment .get_history() )
 	{
 		case  0 :  part_temp .alignment = GParted::ALIGN_CYLINDER;  break;
-		case  1 :  part_temp .alignment = GParted::ALIGN_MEBIBYTE;  break;
+		case  1 :  part_temp .alignment = GParted::ALIGN_MEBIBYTE;
+		           {
+		               //if free space available, grow partition so sector_end on mebibyte boundary
+		               Sector diff = ( MEBIBYTE / part_temp .sector_size ) - ( part_temp .sector_end + 1 ) % ( MEBIBYTE / part_temp .sector_size ) ;
+		               if (   diff
+		                   && ( ( part_temp .sector_end - START +1 + diff ) < total_length )
+		                  )
+		                   part_temp .sector_end += diff ;
+		           }
+		           break;
 		case  2 :  part_temp .alignment = GParted::ALIGN_STRICT;  break;
 
 		default :  part_temp .alignment = GParted::ALIGN_MEBIBYTE ;



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