[gparted] Ensure Align to MiB does not overlap following partition (#661744)



commit c56d0df8aee1d7bdaf88e3cafa5ae0dc9433e582
Author: Curtis Gedak <gedakc gmail com>
Date:   Tue Mar 27 14:26:19 2012 -0600

    Ensure Align to MiB does not overlap following partition (#661744)
    
    Normally the GUI should restrict partitions from overlapping other
    partitions.  However we have received a report where an overlap has
    occurred.
    
    Unfortunately we did not have enough details to recreate the problem.
    Based on the report my thoughts are that somehow the problem arose
    due to partitions aligned to boundaries other than MiB in combination
    with the size of a partition being rounded up in the GUI resizer.
    
    In an effort to prevent this problem in the future I have added a
    check for primary or extended partitions overlapping other primary or
    extended partitions.
    
    Closes Bug #661744 - libparted "Can't have overlapping partitions."
                         after successful move+resize?!

 src/GParted_Core.cc |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index faff717..9b9cdaf 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -549,6 +549,23 @@ bool GParted_Core::snap_to_mebibyte( const Device & device, Partition & partitio
 		}
 	}
 
+	//If this is a primary or an extended partition and the partition overlaps
+	//  the start of the next primary or extended partition then subtract a
+	//  mebibyte from the end of the partition to address the overlap.
+	if ( partition .type == TYPE_PRIMARY || partition .type == TYPE_EXTENDED )
+	{
+		for ( unsigned int t = 0 ; t < device .partitions .size() ; t++ )
+		{
+			if (   (   device .partitions[ t ] .type == TYPE_PRIMARY
+			        || device .partitions[ t ] .type == TYPE_EXTENDED
+			       )
+			    && ( device .partitions[ t ] .sector_start > partition .sector_start )
+			    && ( device .partitions[ t ] .sector_start <= partition .sector_end )
+			   )
+				partition .sector_end -= ( MEBIBYTE / partition .sector_size );
+		}
+	}
+
 	//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



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