[parted-devel] [PATCH] parted: improve snapping to boundaries of free space
Petr Uzel
petr.uzel at suse.cz
Fri Oct 23 14:08:14 UTC 2015
When creating a new partition, parted tries to snap its boundaries.
If the new partition lies within free space, it only makes sense
to snap it so that is it bigger, not smaller.
* parted/parted.c (snap_to_boundaries): Limit direction in what snapping
is done.
---
parted/parted.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/parted/parted.c b/parted/parted.c
index a9426c4..840e9e3 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -379,6 +379,14 @@ snap_to_boundaries (PedGeometry* new_geom, PedGeometry* old_geom,
end_part = ped_disk_get_partition_by_sector (disk, end);
adjacent = (start_part->geom.end + 1 == end_part->geom.start);
+ /* If start lies within free space, then don't allow it to move up.
+ * If end lies within free space, then don't allow it to move down.
+ */
+ if (start_part->type == PED_PARTITION_FREESPACE)
+ start_allow &= ~MOVE_UP;
+ if (end_part->type == PED_PARTITION_FREESPACE)
+ end_allow &= ~MOVE_DOWN;
+
/* If we can snap to old_geom, then we will... */
/* and this will enforce the snapped positions */
if (old_geom) {
--
1.8.4.5
More information about the parted-devel
mailing list