From 2dd0100811e9a07f6e31db60af430c48bd4fa330 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Mon, 17 Apr 2023 19:43:16 +0100 Subject: [PATCH] Stop forcing 1 MiB gap when moving common partition boundary to the right (#227) Start with 2 partitions next to each other, containing file systems that GParted can move and resize. EG: |[#1 ext2 ][#2 swap ] | Move the start of partition #2 to the right. Then attempt to move the end of partition #1 to the right to meet it. EG: |[#1 ext2 ][#2 swap ] | The Resize/Move dialog will allow the free space following to be set to 0 so partition #1 is again adjacent to partition #2, but after closing the dialog a forced 1 MiB gap is added, shrinking the composed size of partition #1 by that 1 MiB. If instead the first operation to shrink and move partition #2 is applied, then partition #1 can be successfully resize right up to partition #2 without a 1 MiB gap. Relevant call sequence: Win_GParted::activate_resize() Dialog_Partition_Resize_Move::Dialog_Partition_Resize_Move() Dialog_Base_Partition::Get_New_Partition() prepare_new_partition() snap_to_alignment() snap_to_mebibyte() prepare_new_partition() created a new partition object to correctly represent the resized/moved partition #1. However this code in snap_to_mebibyte() [1] determined that the new location for partition #1 overlapped with where partition #2 currently is on disk, not where partition #2 will be after the previous operation is applied, therefore it forced a 1 MiB decrease in partition #1's size creating the gap. This is because snap_to_mebibyte() is working with the on disk view of the partitions obtained from devices[current_device] passed into the Dialog_Partition_Resize_Move() constructor. Hence why applying the operations one at a time doesn't suffer from the forced 1 MiB gap. Fix this by creating a copy of the current device object, replacing the on disk partition layout with the composed partition layout as displayed in the UI. Then pass this into the Dialog_Partition_Resize_Move constructor. [1] Dialog_Base_Partition::snap_to_mebibyte() lines 418 to 438 https://gitlab.gnome.org/GNOME/gparted/-/blob/GPARTED_1_5_0/src/Dialog_Base_Partition.cc#L418 Closes #227 - Unable to allocate 1 MiB between partitions when moving to the right --- src/Win_GParted.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc index 8154cf37..541104f0 100644 --- a/src/Win_GParted.cc +++ b/src/Win_GParted.cc @@ -2008,6 +2008,9 @@ void Win_GParted::activate_resize() return; } + Device display_device = devices[current_device].get_copy_without_partitions(); + display_device.partitions = display_partitions; + PartitionVector * display_partitions_ptr = &display_partitions; if ( selected_partition_ptr->type == TYPE_LOGICAL ) { @@ -2057,7 +2060,7 @@ void Win_GParted::activate_resize() working_ptn = selected_partition_ptr->clone(); } - Dialog_Partition_Resize_Move dialog(devices[current_device], + Dialog_Partition_Resize_Move dialog(display_device, fs_cap, fs_limits, *working_ptn,