[gparted] Fix minor cylinder alignment rounding error (size < 1 cylinder)



commit dd1db446393723b7cd0854afbff432d09dc127d9
Author: Curtis Gedak <gedakc gmail com>
Date:   Sat Jan 15 14:46:18 2011 -0700

    Fix minor cylinder alignment rounding error (size < 1 cylinder)
    
    Previously when creating a new partition on a device with 512
    byte sectors with 7 MiB chosen and cylinder alignment, the
    snap_to_cylinder logic would round up to 2 cylinders (~15.69
    MiB), instead of the correct 1 cylinder (~7.84 MiB).

 src/GParted_Core.cc |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index baf1442..d30ab3c 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -365,10 +365,10 @@ bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partitio
 {
 	Sector diff = 0;
 
-	//Determine if partition size is less than a disk cylinder
-	bool less_than_cylinder = false;
-	if ( ( partition .sector_end - partition .sector_start ) < device .cylsize )
-		less_than_cylinder = true;
+	//Determine if partition size is less than half a disk cylinder
+	bool less_than_half_cylinder = false;
+	if ( ( partition .sector_end - partition .sector_start ) < ( device .cylsize / 2 ) )
+		less_than_half_cylinder = true;
 
 	if ( partition.type == TYPE_LOGICAL ||
 	     partition.sector_start == device .sectors
@@ -393,7 +393,7 @@ bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partitio
 	}
 	if ( diff && ! partition .strict_start  )
 	{
-		if ( diff < ( device .cylsize / 2 ) || less_than_cylinder )
+		if ( diff < ( device .cylsize / 2 ) || less_than_half_cylinder )
 			partition .sector_start -= diff ;
 		else
 			partition .sector_start += (device .cylsize - diff ) ;
@@ -402,7 +402,7 @@ bool GParted_Core::snap_to_cylinder( const Device & device, Partition & partitio
 	diff = (partition .sector_end +1) % device .cylsize ;
 	if ( diff )
 	{
-		if ( diff < ( device .cylsize / 2 ) && ! less_than_cylinder )
+		if ( diff < ( device .cylsize / 2 ) && ! less_than_half_cylinder )
 			partition .sector_end -= diff ;
 		else
 			partition .sector_end += (device .cylsize - diff ) ;



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