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).
This commit is contained in:
parent
6ae39268f2
commit
dd1db44639
|
@ -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 ) ;
|
||||
|
|
Loading…
Reference in New Issue