parted/parted-fix-resizepart-and-rm-command.patch

123 lines
5.4 KiB
Diff
Raw Normal View History

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(-)
Accepting request 760713 from home:anicka:branches:Base:System - fix crash in do_resizepart + parted-fix-end_input-usage.patch: Fix end_input usage in do_resizepart - update to version 3.3, noteworthy changes: - s390: Re-enabled virtio-attached DASD heuristics by using HDIO_GETGEO when probing device geometry. Fixes a bug with KVM virtio-blk backed by a DASD. Parted now recognizes NVMe devices, NVDIMM, and RAM drives. - Fix atari disklabel false positives by probing other labels first. - Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does. - Fix set and disk_set to not crash when there are no flags to set. - Fix a udev cookie leak when using resizepart on device-mapper devices. - Fix a gettext crash/error sometimes when using localized languages. - Fix fat resize to preverve boot code, and thus not render the filesystem unreconized by Windows. - Fix rescue command: the rescue command often failed to find filesystems due to leaving on cylinder alignment. - libparted-fs-resize: Prevent crash resizing FAT file systems with very deep directories with path names over 512 bytes long. - Use 512b sector size when communicating with device-mapper. Fixes problems with partitions being created too small on dm devices with sector sizes > 5121b - Don't crash in the disk_set command when a disk label is not found - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - If the user specifies start/end of the partition as cylinders and a cylinder has a size which is power of 2, then such address OBS-URL: https://build.opensuse.org/request/show/760713 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 14:40:37 +01:00
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 " \
Accepting request 760713 from home:anicka:branches:Base:System - fix crash in do_resizepart + parted-fix-end_input-usage.patch: Fix end_input usage in do_resizepart - update to version 3.3, noteworthy changes: - s390: Re-enabled virtio-attached DASD heuristics by using HDIO_GETGEO when probing device geometry. Fixes a bug with KVM virtio-blk backed by a DASD. Parted now recognizes NVMe devices, NVDIMM, and RAM drives. - Fix atari disklabel false positives by probing other labels first. - Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does. - Fix set and disk_set to not crash when there are no flags to set. - Fix a udev cookie leak when using resizepart on device-mapper devices. - Fix a gettext crash/error sometimes when using localized languages. - Fix fat resize to preverve boot code, and thus not render the filesystem unreconized by Windows. - Fix rescue command: the rescue command often failed to find filesystems due to leaving on cylinder alignment. - libparted-fs-resize: Prevent crash resizing FAT file systems with very deep directories with path names over 512 bytes long. - Use 512b sector size when communicating with device-mapper. Fixes problems with partitions being created too small on dm devices with sector sizes > 5121b - Don't crash in the disk_set command when a disk label is not found - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - If the user specifies start/end of the partition as cylinders and a cylinder has a size which is power of 2, then such address OBS-URL: https://build.opensuse.org/request/show/760713 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 14:40:37 +01:00
@@ -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;
Accepting request 760713 from home:anicka:branches:Base:System - fix crash in do_resizepart + parted-fix-end_input-usage.patch: Fix end_input usage in do_resizepart - update to version 3.3, noteworthy changes: - s390: Re-enabled virtio-attached DASD heuristics by using HDIO_GETGEO when probing device geometry. Fixes a bug with KVM virtio-blk backed by a DASD. Parted now recognizes NVMe devices, NVDIMM, and RAM drives. - Fix atari disklabel false positives by probing other labels first. - Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does. - Fix set and disk_set to not crash when there are no flags to set. - Fix a udev cookie leak when using resizepart on device-mapper devices. - Fix a gettext crash/error sometimes when using localized languages. - Fix fat resize to preverve boot code, and thus not render the filesystem unreconized by Windows. - Fix rescue command: the rescue command often failed to find filesystems due to leaving on cylinder alignment. - libparted-fs-resize: Prevent crash resizing FAT file systems with very deep directories with path names over 512 bytes long. - Use 512b sector size when communicating with device-mapper. Fixes problems with partitions being created too small on dm devices with sector sizes > 5121b - Don't crash in the disk_set command when a disk label is not found - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - If the user specifies start/end of the partition as cylinders and a cylinder has a size which is power of 2, then such address OBS-URL: https://build.opensuse.org/request/show/760713 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 14:40:37 +01:00
@@ -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))
Accepting request 760713 from home:anicka:branches:Base:System - fix crash in do_resizepart + parted-fix-end_input-usage.patch: Fix end_input usage in do_resizepart - update to version 3.3, noteworthy changes: - s390: Re-enabled virtio-attached DASD heuristics by using HDIO_GETGEO when probing device geometry. Fixes a bug with KVM virtio-blk backed by a DASD. Parted now recognizes NVMe devices, NVDIMM, and RAM drives. - Fix atari disklabel false positives by probing other labels first. - Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does. - Fix set and disk_set to not crash when there are no flags to set. - Fix a udev cookie leak when using resizepart on device-mapper devices. - Fix a gettext crash/error sometimes when using localized languages. - Fix fat resize to preverve boot code, and thus not render the filesystem unreconized by Windows. - Fix rescue command: the rescue command often failed to find filesystems due to leaving on cylinder alignment. - libparted-fs-resize: Prevent crash resizing FAT file systems with very deep directories with path names over 512 bytes long. - Use 512b sector size when communicating with device-mapper. Fixes problems with partitions being created too small on dm devices with sector sizes > 5121b - Don't crash in the disk_set command when a disk label is not found - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - If the user specifies start/end of the partition as cylinders and a cylinder has a size which is power of 2, then such address OBS-URL: https://build.opensuse.org/request/show/760713 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 14:40:37 +01:00
+ /* 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;
Accepting request 760713 from home:anicka:branches:Base:System - fix crash in do_resizepart + parted-fix-end_input-usage.patch: Fix end_input usage in do_resizepart - update to version 3.3, noteworthy changes: - s390: Re-enabled virtio-attached DASD heuristics by using HDIO_GETGEO when probing device geometry. Fixes a bug with KVM virtio-blk backed by a DASD. Parted now recognizes NVMe devices, NVDIMM, and RAM drives. - Fix atari disklabel false positives by probing other labels first. - Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does. - Fix set and disk_set to not crash when there are no flags to set. - Fix a udev cookie leak when using resizepart on device-mapper devices. - Fix a gettext crash/error sometimes when using localized languages. - Fix fat resize to preverve boot code, and thus not render the filesystem unreconized by Windows. - Fix rescue command: the rescue command often failed to find filesystems due to leaving on cylinder alignment. - libparted-fs-resize: Prevent crash resizing FAT file systems with very deep directories with path names over 512 bytes long. - Use 512b sector size when communicating with device-mapper. Fixes problems with partitions being created too small on dm devices with sector sizes > 5121b - Don't crash in the disk_set command when a disk label is not found - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - If the user specifies start/end of the partition as cylinders and a cylinder has a size which is power of 2, then such address OBS-URL: https://build.opensuse.org/request/show/760713 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 14:40:37 +01:00
/* 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)
Accepting request 760713 from home:anicka:branches:Base:System - fix crash in do_resizepart + parted-fix-end_input-usage.patch: Fix end_input usage in do_resizepart - update to version 3.3, noteworthy changes: - s390: Re-enabled virtio-attached DASD heuristics by using HDIO_GETGEO when probing device geometry. Fixes a bug with KVM virtio-blk backed by a DASD. Parted now recognizes NVMe devices, NVDIMM, and RAM drives. - Fix atari disklabel false positives by probing other labels first. - Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does. - Fix set and disk_set to not crash when there are no flags to set. - Fix a udev cookie leak when using resizepart on device-mapper devices. - Fix a gettext crash/error sometimes when using localized languages. - Fix fat resize to preverve boot code, and thus not render the filesystem unreconized by Windows. - Fix rescue command: the rescue command often failed to find filesystems due to leaving on cylinder alignment. - libparted-fs-resize: Prevent crash resizing FAT file systems with very deep directories with path names over 512 bytes long. - Use 512b sector size when communicating with device-mapper. Fixes problems with partitions being created too small on dm devices with sector sizes > 5121b - Don't crash in the disk_set command when a disk label is not found - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - If the user specifies start/end of the partition as cylinders and a cylinder has a size which is power of 2, then such address OBS-URL: https://build.opensuse.org/request/show/760713 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 14:40:37 +01:00
@@ -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);
Accepting request 760713 from home:anicka:branches:Base:System - fix crash in do_resizepart + parted-fix-end_input-usage.patch: Fix end_input usage in do_resizepart - update to version 3.3, noteworthy changes: - s390: Re-enabled virtio-attached DASD heuristics by using HDIO_GETGEO when probing device geometry. Fixes a bug with KVM virtio-blk backed by a DASD. Parted now recognizes NVMe devices, NVDIMM, and RAM drives. - Fix atari disklabel false positives by probing other labels first. - Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does. - Fix set and disk_set to not crash when there are no flags to set. - Fix a udev cookie leak when using resizepart on device-mapper devices. - Fix a gettext crash/error sometimes when using localized languages. - Fix fat resize to preverve boot code, and thus not render the filesystem unreconized by Windows. - Fix rescue command: the rescue command often failed to find filesystems due to leaving on cylinder alignment. - libparted-fs-resize: Prevent crash resizing FAT file systems with very deep directories with path names over 512 bytes long. - Use 512b sector size when communicating with device-mapper. Fixes problems with partitions being created too small on dm devices with sector sizes > 5121b - Don't crash in the disk_set command when a disk label is not found - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - If the user specifies start/end of the partition as cylinders and a cylinder has a size which is power of 2, then such address OBS-URL: https://build.opensuse.org/request/show/760713 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 14:40:37 +01:00
@@ -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;
Accepting request 760713 from home:anicka:branches:Base:System - fix crash in do_resizepart + parted-fix-end_input-usage.patch: Fix end_input usage in do_resizepart - update to version 3.3, noteworthy changes: - s390: Re-enabled virtio-attached DASD heuristics by using HDIO_GETGEO when probing device geometry. Fixes a bug with KVM virtio-blk backed by a DASD. Parted now recognizes NVMe devices, NVDIMM, and RAM drives. - Fix atari disklabel false positives by probing other labels first. - Fix resizepart to adjust the end to be -1 sector when using iec power of 2 units so that the next partition can start immediately following the new end, just like mkpart does. - Fix set and disk_set to not crash when there are no flags to set. - Fix a udev cookie leak when using resizepart on device-mapper devices. - Fix a gettext crash/error sometimes when using localized languages. - Fix fat resize to preverve boot code, and thus not render the filesystem unreconized by Windows. - Fix rescue command: the rescue command often failed to find filesystems due to leaving on cylinder alignment. - libparted-fs-resize: Prevent crash resizing FAT file systems with very deep directories with path names over 512 bytes long. - Use 512b sector size when communicating with device-mapper. Fixes problems with partitions being created too small on dm devices with sector sizes > 5121b - Don't crash in the disk_set command when a disk label is not found - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - libparted-fs-resize: Prevent crash resizing FAT16 file systems. - If the user specifies start/end of the partition as cylinders and a cylinder has a size which is power of 2, then such address OBS-URL: https://build.opensuse.org/request/show/760713 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=144
2020-01-12 14:40:37 +01:00
if (!ped_disk_delete_partition (*diskp, part))