parted/parted-implement-wipesignatures-option.patch
Marcus Meissner 5631eac2bb 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 13:40:37 +00:00

207 lines
7.0 KiB
Diff

From: Petr Uzel <petr.uzel@suse.cz>
Date: Thu, 28 Apr 2016 17:18:44 +0200
Subject: [PATCH] parted: implement --wipesignatures option
References: bsc#943623, fate#319893, bsc#980834
Patch-mainline: no, custom extension
With this option, parted uses libblkid to wipe superblock signatures
from a disk region where it is about to create a new partition.
[sparschauer: Use own #if USE_BLKID block in linux_dev_ops (bsc#1047031)]
Signed-off-by: Sebastian Parschauer <sparschauer@suse.de>
---
doc/C/parted.8 | 4 ++++
include/parted/device.in.h | 2 ++
libparted/arch/linux.c | 39 +++++++++++++++++++++++++++++++++++++++
libparted/device.c | 17 +++++++++++++++++
parted/parted.c | 16 ++++++++++++++++
5 files changed, 78 insertions(+)
Index: parted-3.3/doc/C/parted.8
===================================================================
--- parted-3.3.orig/doc/C/parted.8
+++ parted-3.3/doc/C/parted.8
@@ -30,6 +30,10 @@ never prompts for user intervention
.B -v, --version
displays the version
.TP
+.B --wipesignatures
+mkpart wipes the superblock signatures from the disk region where it is
+about to create the partition
+.TP
.B -a \fIalignment-type\fP, --align \fIalignment-type\fP
Set alignment for newly created partitions, valid alignment types are:
.RS
Index: parted-3.3/include/parted/device.in.h
===================================================================
--- parted-3.3.orig/include/parted/device.in.h
+++ parted-3.3/include/parted/device.in.h
@@ -122,6 +122,7 @@ struct _PedDeviceArchOps {
/* These functions are optional */
PedAlignment *(*get_minimum_alignment)(const PedDevice *dev);
PedAlignment *(*get_optimum_alignment)(const PedDevice *dev);
+ int (*wipe_signatures)(const PedDevice *dev, PedSector start, PedSector length);
};
#include <parted/constraint.h>
@@ -158,6 +159,7 @@ extern PedConstraint *ped_device_get_opt
extern PedAlignment *ped_device_get_minimum_alignment(const PedDevice *dev);
extern PedAlignment *ped_device_get_optimum_alignment(const PedDevice *dev);
+extern int ped_device_wipe_signatures(const PedDevice *dev, PedSector start, PedSector length);
/* private stuff ;-) */
Index: parted-3.3/libparted/arch/linux.c
===================================================================
--- parted-3.3.orig/libparted/arch/linux.c
+++ parted-3.3/libparted/arch/linux.c
@@ -3395,6 +3395,44 @@ linux_get_optimum_alignment(const PedDev
blkid_topology_get_alignment_offset(tp) / dev->sector_size,
blkid_topology_get_optimal_io_size(tp) / dev->sector_size);
}
+
+static int
+linux_wipe_signatures(const PedDevice *dev, PedSector start, PedSector length)
+{
+ PED_ASSERT (dev != NULL);
+ LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
+
+ blkid_loff_t wipe_offset = start * dev->sector_size;
+ blkid_loff_t wipe_size = length * dev->sector_size;
+
+ _ensure_read_write (dev);
+
+ blkid_probe pr;
+ pr = blkid_new_probe();
+ if (!pr)
+ goto error;
+
+ if (blkid_probe_set_device(pr, arch_specific->fd, wipe_offset, wipe_size) == -1)
+ goto error_free_probe;
+ if (blkid_probe_enable_superblocks(pr, 1) == -1)
+ goto error_free_probe;
+ if (blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC) == -1)
+ goto error_free_probe;
+
+ while (blkid_do_probe(pr) == 0) {
+ if (blkid_do_wipe(pr, 0) == -1)
+ goto error_free_probe;
+ }
+
+ blkid_free_probe(pr);
+ return 1;
+
+error_free_probe:
+ blkid_free_probe(pr);
+
+error:
+ return 0;
+}
#endif
#if defined __s390__ || defined __s390x__
@@ -3471,6 +3509,9 @@ static PedDeviceArchOps linux_dev_ops =
get_minimum_alignment: linux_get_minimum_alignment,
get_optimum_alignment: linux_get_optimum_alignment,
#endif
+#if USE_BLKID
+ wipe_signatures: linux_wipe_signatures,
+#endif
};
PedDiskArchOps linux_disk_ops = {
Index: parted-3.3/libparted/device.c
===================================================================
--- parted-3.3.orig/libparted/device.c
+++ parted-3.3/libparted/device.c
@@ -559,4 +559,21 @@ ped_device_get_optimum_alignment(const P
return align;
}
+
+/**
+ * Wipe superblock signatures from the specified region on the device.
+ *
+ * \return zero on failure
+ */
+int
+ped_device_wipe_signatures(const PedDevice *dev, PedSector start, PedSector length)
+{
+ int ret = 0;
+
+ if (ped_architecture->dev_ops->wipe_signatures)
+ ret = ped_architecture->dev_ops->wipe_signatures(dev, start, length);
+
+ return ret;
+}
+
/** @} */
Index: parted-3.3/parted/parted.c
===================================================================
--- parted-3.3.orig/parted/parted.c
+++ parted-3.3/parted/parted.c
@@ -76,6 +76,7 @@ static int MEGABYTE_SECTORS (PedDevice*
enum
{
PRETEND_INPUT_TTY = CHAR_MAX + 1,
+ WIPESIGNATURES = CHAR_MAX + 2,
};
enum
@@ -117,6 +118,7 @@ static struct option const options[] = {
{"script", 0, NULL, 's'},
{"version", 0, NULL, 'v'},
{"align", required_argument, NULL, 'a'},
+ {"wipesignatures", 0, NULL, WIPESIGNATURES},
{"-pretend-input-tty", 0, NULL, PRETEND_INPUT_TTY},
{NULL, 0, NULL, 0}
};
@@ -128,11 +130,13 @@ static const char *const options_help []
{"script", N_("never prompts for user intervention")},
{"version", N_("displays the version")},
{"align=[none|cyl|min|opt]", N_("alignment for new partitions")},
+ {"wipesignatures", N_("wipe superblock signatures when creating partition")},
{NULL, NULL}
};
int opt_script_mode = 0;
int pretend_input_tty = 0;
+int wipesignatures = 0;
int opt_machine_mode = 0;
int disk_is_modified = 0;
int is_toggle_mode = 0;
@@ -651,6 +655,7 @@ _adjust_end_if_iec (PedSector* start, Pe
}
}
+
static int
do_mkpart (PedDevice** dev, PedDisk** diskp)
{
@@ -848,6 +853,14 @@ do_mkpart (PedDevice** dev, PedDisk** di
if (ped_partition_is_flag_available (part, PED_PARTITION_LBA))
ped_partition_set_flag (part, PED_PARTITION_LBA, 1);
+ if (wipesignatures) {
+ if (!ped_device_wipe_signatures(*dev, part->geom.start, part->geom.length))
+ ped_exception_throw (
+ PED_EXCEPTION_WARNING,
+ PED_EXCEPTION_OK,
+ _("Wiping the superblock signatures has failed."));
+ }
+
if (!ped_disk_commit (disk))
goto error_remove_part;
@@ -2252,6 +2265,9 @@ while (1)
case PRETEND_INPUT_TTY:
pretend_input_tty = 1;
break;
+ case WIPESIGNATURES:
+ wipesignatures = 1;
+ break;
default:
wrong = 1;
break;