[parted-devel] [PATCH 1/2] parted: Preserve resizepart End when prompted for busy partition

Brian C. Lane bcl at redhat.com
Tue Sep 1 22:53:40 BST 2020


Resizing busy partitions is allowed, but the user is prompted, which
erases the cmdline. It is annoying to have to re-end the ending location
after answering Yes. This saves the word and pushes it back onto the
cmdline after the user agrees to resize the busy partition.
---
 parted/parted.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/parted/parted.c b/parted/parted.c
index df0c7ed..dbd38d0 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1546,6 +1546,7 @@ do_resizepart (PedDevice** dev, PedDisk** diskp)
         PedConstraint*          constraint;
         int rc = 0;
         char*                   end_input = NULL;
+        char*                   end_size = NULL;
 
         if (!disk) {
                 disk = ped_disk_new (*dev);
@@ -1561,9 +1562,23 @@ do_resizepart (PedDevice** dev, PedDisk** diskp)
 
         if (!command_line_get_partition (_("Partition number?"), disk, &part))
                 goto error;
+
+        /* Save the optional End value if the partition is busy. */
+        if (ped_partition_is_busy(part)) {
+            if (command_line_get_word_count())
+                end_size = command_line_pop_word();
+        }
+
+        /* If the partition is busy this may clear the command_line and prompt the user */
         if (!_partition_warn_busy (part))
                 goto error;
 
+        /* Push the End value back onto the command_line, if it exists */
+        if (end_size) {
+            command_line_push_word(end_size);
+            free(end_size);
+        }
+
         start = part->geom.start;
         end = oldend = part->geom.end;
         if (!command_line_get_sector (_("End?"), *dev, &end, &range_end, &end_input))
-- 
2.26.2




More information about the parted-devel mailing list