[gparted] Ensure space for EBR when resizing Extended partition (#664050)



commit bee2a643e2040ab1664c4db7ad709063a8841c9a
Author: Curtis Gedak <gedakc gmail com>
Date:   Sat Mar 17 13:20:01 2012 -0600

    Ensure space for EBR when resizing Extended partition (#664050)
    
    When resizing an extended boot record we must ensure that at least 2
    sectors is reserved in front of the nearest logical partition for the
    Extended Boot Record.
    
    Please note that unless specifically told otherwise, the Linux kernel
    considers Extended Boot Records to be two sectors long, in order to
    "leave room for LILO".
    
    Closes Bug #664050 - Unable to resize extended partition

 src/GParted_Core.cc |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 58efa04..7df29ac 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -463,8 +463,10 @@ bool GParted_Core::snap_to_mebibyte( const Device & device, Partition & partitio
 		}
 	}
 
-	//Align start sector
+	//Calculate difference offset from Mebibyte boundary
 	diff = Sector(partition .sector_start % ( MEBIBYTE / partition .sector_size ));
+
+	//Align start sector only if permitted to change start sector
 	if ( diff && (   (! partition .strict_start)
 	              || (   partition .strict_start
 	                  && (   partition .status == STAT_NEW
@@ -473,8 +475,44 @@ bool GParted_Core::snap_to_mebibyte( const Device & device, Partition & partitio
 	                 )
 	             )
 	   )
+	{
 		partition .sector_start += ( (MEBIBYTE / partition .sector_size) - diff) ;
 
+		//If this is an extended partition then check to see if sufficient space is
+		//  available for any following logical partition Extended Boot Record
+		if ( partition .type == TYPE_EXTENDED )
+		{
+			//Locate the extended partition that contains the logical partitions.
+			int index_extended = -1 ;
+			for ( unsigned int t = 0 ; t < device .partitions .size() ; t++ )
+			{
+				if ( device .partitions[ t ] .type == TYPE_EXTENDED )
+					index_extended = t ;
+			}
+
+			//If there is logical partition that starts less than 2 sectors
+			//  from the start of this partition, then reserve a mebibyte for the EBR.
+			if ( index_extended != -1 )
+			{
+				for ( unsigned int t = 0; t < device .partitions[ index_extended ] .logicals .size(); t++ )
+				{
+					if (   ( device .partitions[ index_extended ] .logicals[ t ] .type == TYPE_LOGICAL )
+					    && ( (  (  device .partitions[ index_extended ] .logicals[ t ] .sector_start )
+					          - ( partition .sector_start )
+					         )
+					         //Unless specifically told otherwise, the Linux kernel considers extended
+					         //  boot records to be two sectors long, in order to "leave room for LILO".
+					         < 2
+					       )
+					   )
+					{
+						partition .sector_start -= (MEBIBYTE / partition .sector_size) ;
+					}
+				}
+			}
+		}
+	}
+
 	//If this is a logical partition not at end of drive then check to see if space is
 	//  required for a following logical partition Extended Boot Record
 	if ( partition .type == TYPE_LOGICAL )



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