forked from pool/parted
- parted-implement-wipesignatures-option.patch OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=117
159 lines
4.4 KiB
Diff
159 lines
4.4 KiB
Diff
From 4ff404cc2d7ab74d0b1000c0212318dcbb2dda11 Mon Sep 17 00:00:00 2001
|
|
From: Petr Uzel <petr.uzel@suse.cz>
|
|
Date: Thu, 28 Apr 2016 17:18:44 +0200
|
|
Subject: [PATCH] parted: implement --wipesignatures option
|
|
|
|
With this option, parted uses libblkid to wipe superblock signatures
|
|
from a disk region where it is about to create a new partition.
|
|
|
|
References: bsc#943623
|
|
References: fate#319893
|
|
---
|
|
doc/C/parted.8 | 4 +++
|
|
parted/parted.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
2 files changed, 74 insertions(+)
|
|
|
|
Index: parted-3.2/doc/C/parted.8
|
|
===================================================================
|
|
--- parted-3.2.orig/doc/C/parted.8
|
|
+++ parted-3.2/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.2/parted/parted.c
|
|
===================================================================
|
|
--- parted-3.2.orig/parted/parted.c
|
|
+++ parted-3.2/parted/parted.c
|
|
@@ -57,6 +57,11 @@
|
|
#include "c-strcase.h"
|
|
#include "xalloc.h"
|
|
|
|
+#include <sys/types.h>
|
|
+#include <sys/stat.h>
|
|
+#include <fcntl.h>
|
|
+#include <blkid/blkid.h>
|
|
+
|
|
#ifdef ENABLE_MTRACE
|
|
#include <mcheck.h>
|
|
#endif
|
|
@@ -76,6 +81,7 @@ static int MEGABYTE_SECTORS (PedDevice*
|
|
enum
|
|
{
|
|
PRETEND_INPUT_TTY = CHAR_MAX + 1,
|
|
+ WIPESIGNATURES = CHAR_MAX + 2,
|
|
};
|
|
|
|
enum
|
|
@@ -117,6 +123,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 +135,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;
|
|
@@ -650,6 +659,56 @@ _adjust_end_if_iec (PedSector* start, Pe
|
|
}
|
|
}
|
|
|
|
+#ifdef USE_BLKID
|
|
+static int
|
|
+_wipe_signatures (PedDevice *dev, PedSector start, PedSector length)
|
|
+{
|
|
+ int fd = open (dev->path, O_RDWR);
|
|
+ if (fd == -1)
|
|
+ goto error;
|
|
+
|
|
+ blkid_loff_t wipe_offset = start * dev->sector_size;
|
|
+ blkid_loff_t wipe_size = length * dev->sector_size;
|
|
+
|
|
+ blkid_probe pr;
|
|
+ pr = blkid_new_probe();
|
|
+ if (!pr)
|
|
+ goto error_close_fd;
|
|
+
|
|
+ if (blkid_probe_set_device(pr, 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);
|
|
+ close(fd);
|
|
+ return 1;
|
|
+
|
|
+error_free_probe:
|
|
+ blkid_free_probe(pr);
|
|
+
|
|
+error_close_fd:
|
|
+ close(fd);
|
|
+
|
|
+error:
|
|
+ return 0;
|
|
+
|
|
+}
|
|
+#else
|
|
+static int
|
|
+_wipe_signatures (PedDevice *dev, PedSector start, PedSector length)
|
|
+{
|
|
+ return 0;
|
|
+}
|
|
+#endif
|
|
+
|
|
static int
|
|
do_mkpart (PedDevice** dev, PedDisk** diskp)
|
|
{
|
|
@@ -840,6 +899,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 (!_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;
|
|
|
|
@@ -2196,6 +2263,9 @@ while (1)
|
|
case PRETEND_INPUT_TTY:
|
|
pretend_input_tty = 1;
|
|
break;
|
|
+ case WIPESIGNATURES:
|
|
+ wipesignatures = 1;
|
|
+ break;
|
|
default:
|
|
wrong = 1;
|
|
break;
|