From 3a53d17c8d8b284e20dd5427bcbdfcd79b41df4e Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 5 Apr 2020 09:25:52 +0100 Subject: [PATCH] Remove unnecessary portion of MiB alignment check As a partition's position is completely defined by it's starting and ending sector, it is aligned if both boundaries are aligned. The size of a partition just depends on the starting and ending sector. Therefore it is never necessary to also check if the size of the partition is also an exact multiple of MiB. Remove this unnecessary portion of the alignment check when resizing/moving a partition (or copy/pasting into a new partition). --- src/Dialog_Base_Partition.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc index 67b43b81..f1b040f6 100644 --- a/src/Dialog_Base_Partition.cc +++ b/src/Dialog_Base_Partition.cc @@ -210,14 +210,13 @@ void Dialog_Base_Partition::prepare_new_partition() case 1: new_partition->alignment = ALIGN_MEBIBYTE; { - // If partition size is not an integer multiple of MiB or - // the start or end sectors are not MiB aligned, and space - // is available, then add 1 MiB to partition so requested - // size is kept after snap_to_mebibyte() method rounding. + // If partition start or end sectors are not MiB aligned, + // and space is available, then add 1 MiB to partition so + // requesting size is kept after snap_to_mebibyte() method + // rounding. Sector partition_size = new_partition->sector_end - new_partition->sector_start + 1; Sector sectors_in_mib = MEBIBYTE / new_partition->sector_size; - if ( ( ( partition_size % sectors_in_mib > 0 ) - || ( new_partition->sector_start % sectors_in_mib > 0 ) + if ( ( ( new_partition->sector_start % sectors_in_mib > 0 ) || ( ( new_partition->sector_end + 1 ) % sectors_in_mib > 0 ) ) && ( partition_size + sectors_in_mib < total_length )