Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.0:Rings:1-MinimalX
parted
parted-fix-resizepart-and-rm-command.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File parted-fix-resizepart-and-rm-command.patch of Package parted
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(-) diff --git a/parted/parted.c b/parted/parted.c index 3cc8f77..2e31659 100644 --- a/parted/parted.c +++ b/parted/parted.c @@ -228,13 +228,19 @@ _timer_handler (PedTimer* timer, void* context) } 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 " \ @@ -1634,6 +1640,11 @@ 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; + const bool danger_if_busy = false; int rc = 0; if (!disk) { @@ -1650,26 +1661,39 @@ 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, danger_if_busy)) 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, danger_if_busy)) + 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 (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) @@ -1690,6 +1714,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); @@ -1698,7 +1723,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; ped_disk_delete_partition (*diskp, part);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor