[parted-devel] [PATCH] parted: fix the resizepart command logic
Wang Dong
dongdwdw at linux.vnet.ibm.com
Fri Mar 31 10:31:45 UTC 2017
When to resize a partition in interactive mode, if user provides an end
point which is before the old end point, parted will raise a warning
of data loss. But parted will modify the disk information even before
the response from user. Further more, if user finally declines to resize
at last, the disk information in memory will not be committed to device,
and will be different from that on device. This might lead to some confusion.
Becaus user will only see the disk in memory but not the real on device.
Now in the same situation, parted will raise warning first and decide whether
to change the disk information according user's response.
Signed-off-by: Wang Dong <dongdwdw at linux.vnet.ibm.com>
Reviewed-by: Andre Wild <wild at linux.vnet.ibm.com>
Signed-off-by: Hendrik Brueckner <brueckner at linux.vnet.ibm.com>
---
parted/parted.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index cc2e393..0636e58 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1561,19 +1561,19 @@ do_resizepart (PedDevice** dev, PedDisk** diskp)
end = oldend = part->geom.end;
if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, NULL))
goto error;
- /* Do not move start of the partition */
- constraint = constraint_from_start_end_fixed_start (*dev, start, range_end);
- if (!ped_disk_set_partition_geom (disk, part, constraint,
- start, end))
- goto error_destroy_constraint;
/* warn when shrinking partition - might lose data */
- if (part->geom.end < oldend)
+ if (end < oldend)
if (ped_exception_throw (
PED_EXCEPTION_WARNING,
PED_EXCEPTION_YES_NO,
_("Shrinking a partition can cause data loss, " \
"are you sure you want to continue?")) != PED_EXCEPTION_YES)
- goto error_destroy_constraint;
+ goto error;
+
+ /* Do not move start of the partition */
+ constraint = constraint_from_start_end_fixed_start (*dev, start, range_end);
+ if (!ped_disk_set_partition_geom (disk, part, constraint, start, end))
+ goto error_destroy_constraint;
if (!ped_disk_commit (disk))
goto error_destroy_constraint;
--
2.8.4
More information about the parted-devel
mailing list