parted/parted-fix-resizepart-and-rm-command.patch
Arvin Schnell c34e26e7e1 Accepting request 971201 from home:aschnell:branches:Base:System
- update to version 3.5:
  * Add support for JSON output.
  * Add support for linux-home flag for GPT.
  * Add --fix option.
  added patches:
  - direct-handling-of-partition-type-id-and-uuid.patch
  - parted-json-no-type-flag.patch
  refreshed patches:
  - libparted-open-the-device-RO-and-lazily-switch-to-RW.patch
  - parted-2.4-ncursesw6.patch
  - parted-add-ignore-busy-option.patch
  - parted-fix-resizepart-and-rm-command.patch
  - parted-implement-wipesignatures-option.patch
  - parted-print-max-partitions-for-yast.patch
  - parted-type.patch
  - tests-disable.patch
  removed patches:
  - parted-escape-printed-device-path.patch
  - parted-mkpart-allow-empty-gpt-part-name.patch

OBS-URL: https://build.opensuse.org/request/show/971201
OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=152
2022-04-21 05:58:32 +00:00

123 lines
5.4 KiB
Diff

From: Sebastian Parschauer <sparschauer@suse.de>
Date: Tue, 7 Nov 2017 14:09:46 +0100
Subject: parted: Fix resizepart and rm command
References: bsc#1058667
Patch-mainline: not yet, based on v3 submitted on 2017-11-07
In script mode the resizepart command fails when shrinking and
if the partition is busy. Also the warnings printed in this
case are only applicable to interactive mode. A similar problem
exists with the rm command.
So print different warnings in script mode and continue if growing
a busy partition. Require the '--ignore-busy' option to be set in
order to shrink or remove a busy partition. Shrinking cannot be
more dangerous in script mode than removing. So allow shrinking a
partition in script mode which is not busy.
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 anyway 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.
Fixes: 21c58e17c473 ("parted: add resizepart command")
Reported-by: Arvin Schnell <aschnell@suse.com>
Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
---
parted/parted.c | 39 ++++++++++++++++++++++++++++++++-------
2 files changed, 36 insertions(+), 7 deletions(-)
Index: parted-3.3/parted/parted.c
===================================================================
--- parted-3.3.orig/parted/parted.c
+++ parted-3.3/parted/parted.c
@@ -229,13 +229,19 @@ _timer_handler (PedTimer* timer, void* c
}
static int
-_partition_warn_busy (PedPartition* part)
+_partition_warn_busy (PedPartition* part, bool dangerous)
{
char* path;
if (ped_partition_is_busy (part)) {
path = ped_partition_get_path (part);
- if (ped_exception_throw (
+ if (opt_script_mode && (!dangerous || ignore_busy)) {
+ ped_exception_throw (
+ PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_UNHANDLED,
+ _("Partition %s is being used, continuing anyway."),
+ path);
+ } else if (ped_exception_throw (
PED_EXCEPTION_WARNING,
PED_EXCEPTION_YES_NO,
_("Partition %s is being used. Are you sure you " \
@@ -1655,6 +1661,11 @@ do_resizepart (PedDevice** dev, PedDisk*
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;
+ const bool danger_if_busy = false;
int rc = 0;
char* end_input = NULL;
char* end_size = NULL;
@@ -1671,7 +1682,8 @@ do_resizepart (PedDevice** dev, PedDisk*
}
/* If the partition is busy this may clear the command_line and prompt the user */
- 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, danger_if_busy))
goto error;
/* Push the End value back onto the command_line, if it exists */
@@ -1871,13 +1873,23 @@ do_resizepart (PedDevice** dev, PedDisk*
start, end))
goto error_destroy_constraint;
/* warn when shrinking partition - might lose data */
- if (part->geom.end < oldend)
- if (ped_exception_throw (
+ if (part->geom.end < oldend) {
+ if (opt_script_mode && (!ped_partition_is_busy (part) || ignore_busy)) {
+ char *path = ped_partition_get_path (part);
+ ped_exception_throw (
+ PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_UNHANDLED,
+ _("Shrinking partition %s, data loss possible."), path);
+ free(path);
+ } else 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;
+ }
+ }
ped_disk_commit (disk);
if ((*dev)->type != PED_DEVICE_FILE)
@@ -1714,6 +1739,7 @@ static int
do_rm (PedDevice** dev, PedDisk** diskp)
{
PedPartition* part = NULL;
+ const bool danger_if_busy = true;
if (!*diskp)
*diskp = ped_disk_new (*dev);
@@ -1722,7 +1748,7 @@ do_rm (PedDevice** dev, PedDisk** diskp)
if (!command_line_get_partition (_("Partition number?"), *diskp, &part))
goto error;
- if (!_partition_warn_busy (part))
+ if (!_partition_warn_busy (part, danger_if_busy))
goto error;
if (!ped_disk_delete_partition (*diskp, part))