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

Sebastian Parschauer sparschauer at suse.de
Thu Sep 21 09:16:34 UTC 2017


In script mode the resizepart 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. Do that
directly in _partition_warn_busy() to also fix do_rm().

In interactive mode there is a problem if providing the partition
number and the end of the partition as arguments to the resizepart
command directly with a busy partition. The warning is shown and
after continuing anyways parted asks for the partition end although
it has already been provided. So count the number of words on
command line and warn after processing all of them or after getting
the partition number.

NEWS: Mention the bugfix.

Fixes: 21c58e17c473 ("parted: add resizepart command")
Reported-by: Arvin Schnell <aschnell at suse.com>
Signed-off-by: Sebastian Parschauer <sparschauer at suse.de>
---
 NEWS            |  2 ++
 parted/parted.c | 17 ++++++++++++++---
 2 files changed, 16 insertions(+), 3 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..c6233ec 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -223,6 +223,9 @@ _partition_warn_busy (PedPartition* part)
 {
         char* path;
 
+        if (opt_script_mode)
+                goto out;
+
         if (ped_partition_is_busy (part)) {
                 path = ped_partition_get_path (part);
                 if (ped_exception_throw (
@@ -237,6 +240,7 @@ _partition_warn_busy (PedPartition* part)
                 }
                 free (path);
         }
+out:
         return 1;
 }
 
@@ -1545,6 +1549,10 @@ do_resizepart (PedDevice** dev, PedDisk** diskp)
         PedSector               start, end, oldend;
         PedGeometry             *range_end = NULL;
         PedConstraint*          constraint;
+        int                     cmdline_words = command_line_get_word_count();
+        /* update this if adding/removing arguments to/from this command */
+        const int               part_idx = 1;
+        const int               end_idx = 2;
         int rc = 0;
 
         if (!disk) {
@@ -1561,20 +1569,23 @@ do_resizepart (PedDevice** dev, PedDisk** diskp)
 
         if (!command_line_get_partition (_("Partition number?"), disk, &part))
                 goto error;
-        if (!_partition_warn_busy (part))
+        /* warn early if the partition end is not provided on cmdline */
+        if (cmdline_words <= part_idx && !_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 (cmdline_words >= end_idx && !_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