[parted-devel] [PATCH] parted: Fix resizepart command

Sebastian Parschauer sparschauer at suse.de
Wed Sep 20 09:37:02 UTC 2017


The resizepart command does not work properly with busy partitions,
neither in interactive nor script mode.
The check and the warning for that are located in the middle of
parameter checking and parted asks for the partition end again. So
move that after parameter checking.

In script mode the warnings about the busy partition and shrinking
the partition are shown. Parted fails in this case. So skip that
in script mode and just do what is requested.

NEWS: Mention the bugfix.

Fixes: 21c58e17c473 ("parted: add resizepart command")
Signed-off-by: Sebastian Parschauer <sparschauer at suse.de>
---
 NEWS            | 2 ++
 parted/parted.c | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index bb15212..e9e12db 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ GNU parted NEWS                                    -*- outline -*-
 
 ** Bug Fixes
 
+  Fix resizepart command with busy partitions and in script mode.
+
   Fix a udev cookie leak when using resizepart on device-mapper devices.
 
   Fix a gettext crash/error sometimes when using localized languages.
diff --git a/parted/parted.c b/parted/parted.c
index c471d49..c128a43 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1561,20 +1561,20 @@ do_resizepart (PedDevice** dev, PedDisk** diskp)
 
         if (!command_line_get_partition (_("Partition number?"), disk, &part))
                 goto error;
-        if (!_partition_warn_busy (part))
-                goto error;
-
         start = part->geom.start;
         end = oldend = part->geom.end;
         if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, NULL))
                 goto error;
+        if (!opt_script_mode && !_partition_warn_busy (part))
+                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 (!opt_script_mode && (part->geom.end < oldend))
                 if (ped_exception_throw (
                             PED_EXCEPTION_WARNING,
                             PED_EXCEPTION_YES_NO,
-- 
2.14.1




More information about the parted-devel mailing list