Skip to content

Snap partition boundaries before dialogs update FS usage

Mike Fleetwood requested to merge mfleetwo/gparted:luks-move-error into master

Fixes #48 (closed) "Error when moving locked LUKS-encrypted partition".

Quoting the "PATCHSET OVERVIEW" section from the first commit:

A user had 2 adjacent partitions which were aligned to multiples of 33553920 bytes (32 MiB - 512 bytes), not MiB or cylinders. As far as GParted is concerned this is not aligned. The second partition contained closed LUKS encrypted data. Recreate this setup with:

# truncate -s 200G /tmp/disk.img
# losetup -f --show /tmp/disk.img
/dev/loop0
# sfdisk -u S /dev/loop0 << EOF
65535 2162655 83
2228190 78904140 83
EOF
# partprobe /dev/loop0
# echo -n badpassword | cryptsetup luksFormat /dev/loop0p2 -

When trying to move the second LUKS encrypted partition to the right by any amount, with the default MiB alignment, GParted displays this error dialog and fails to even queue the operation:

Could not add this operation to the list
A partition with used sectors (78907392) greater than its
length (78905344) is not valid
[                       OK                               ]

Overview of the steps involved:

  1. The Resize/Move dialog composed a new partition to start a whole multiple of MiB after the end of the previous non-aligned partition. The new partition also had it's size increased to a whole multiple of MiB, to 78907392 sectors (38529 MiB) which was 1.59 MiB larger than before. Neither the start or end of the new partition are aligned at this point.

  2. Win_GParted::activate_resize() applied the change back to the closed LUKS partition object, additionally making the used sectors equal to the partition size. (To match the fact that when opened the LUKS mapping it will automatically fill the new larger partition size).

  3. GParted_Core::snap_to_mebibyte() then aligned the partition start and end to whole MiB boundaries, reducing the partition size in the process to 78905344 (38528 MiB).

  4. GParted_Core::snap_to_alignment() reported the error saying that it couldn't add the operation to the list because it was invalid to have the file system used sectors larger than the partition size.

Fix this by having the snap to alignment adjustments applied before the dialogs update any associated file system usage. Specifically the Resize/Move, Paste (into new) and Create New dialogs as these are the only ones which either create or modify partition boundaries. Validation done by snap_to_alignment() will continue to occur at the current point when the operation is added to the list.

Edited by Mike Fleetwood

Merge request reports