From 3d6db3fdb1382fa2eb33cd7bccb27f6daaaf10ee Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 4 May 2016 12:43:35 +0200 Subject: [PATCH] sfdisk: add --wipe-partitions=auto|never|default The option allows to remove filesystes/RAIDs from newly created partitions before the partition table is updated (and partition device created). The default is "auto" in this case wipe is enabled in interactive mode only and user's confirmation (yes/no dialog) is required. Note that keep filesystem signature on partition is pretty valid use-case, so we don't erase anything by default. Signed-off-by: Karel Zak --- disk-utils/cfdisk.c | 47 +++++++++----------------------- disk-utils/sfdisk.8 | 12 +++++++++ disk-utils/sfdisk.c | 66 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 86 insertions(+), 39 deletions(-) diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index 3908e3136..b7014e330 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -180,7 +180,7 @@ static struct cfdisk_menuitem main_menuitems[] = { { 'b', N_("Bootable"), N_("Toggle bootable flag of the current partition") }, { 'd', N_("Delete"), N_("Delete the current partition") }, { 'n', N_("New"), N_("Create new partition from free space") }, - { 'q', N_("Quit"), N_("Quit program without writing partition table") }, + { 'q', N_("Quit"), N_("Quit program without writing changes") }, { 't', N_("Type"), N_("Change the partition type") }, { 'h', N_("Help"), N_("Print help screen") }, { 's', N_("Sort"), N_("Fix partitions order") }, @@ -1309,39 +1309,19 @@ static void extra_prepare_data(struct cfdisk *cf) free(data); } -#ifdef HAVE_LIBBLKID - if (fdisk_partition_has_start(pa) && fdisk_partition_has_size(pa)) { - int fd; - uintmax_t start, size; - blkid_probe pr = blkid_new_probe(); - - if (!pr) - goto done; - - DBG(UI, ul_debug("blkid prober: %p", pr)); - - start = fdisk_partition_get_start(pa) * fdisk_get_sector_size(cf->cxt); - size = fdisk_partition_get_size(pa) * fdisk_get_sector_size(cf->cxt); - fd = fdisk_get_devfd(cf->cxt); - - if (blkid_probe_set_device(pr, fd, start, size) == 0 && - blkid_do_fullprobe(pr) == 0) { - const char *bdata = NULL; - - if (!blkid_probe_lookup_value(pr, "TYPE", &bdata, NULL)) - extra_insert_pair(l, _("Filesystem:"), bdata); - if (!blkid_probe_lookup_value(pr, "LABEL", &bdata, NULL)) { - extra_insert_pair(l, _("Filesystem label:"), bdata); - devlabel = xstrdup(bdata); - } - if (!blkid_probe_lookup_value(pr, "UUID", &bdata, NULL)) { - extra_insert_pair(l, _("Filesystem UUID:"), bdata); - devuuid = xstrdup(bdata); - } - } - blkid_free_probe(pr); + if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_FSUUID, &data) && data) { + extra_insert_pair(l, _("Filesystem UUID:"), data); + free(data); + } + + if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_FSLABEL, &data) && data) { + extra_insert_pair(l, _("Filesystem LABEL:"), data); + free(data); + } + if (!fdisk_partition_to_string(pa, cf->cxt, FDISK_FIELD_FSTYPE, &data) && data) { + extra_insert_pair(l, _("Filesystem:"), data); + free(data); } -#endif /* HAVE_LIBBLKID */ #ifdef HAVE_LIBMOUNT if (devuuid || devlabel) { @@ -1352,7 +1332,6 @@ static void extra_prepare_data(struct cfdisk *cf) } } #endif /* HAVE_LIBMOUNT */ -done: free(devlabel); free(devuuid); } diff --git a/disk-utils/sfdisk.8 b/disk-utils/sfdisk.8 index 277b84373..79424c526 100644 --- a/disk-utils/sfdisk.8 +++ b/disk-utils/sfdisk.8 @@ -222,6 +222,18 @@ before a new partition table is created. See also .BR wipefs (8) command. +.TP +.BR -W , " \-\-wipe-partitions "\fIwhen +Wipe filesystem, RAID and partition-table signatures from a newly created +partitions, in order to avoid possible collisions. The argument \fIwhen\fR can +be \fBauto\fR, \fBnever\fR or \fBalways\fR. When this option is not given, the +default is \fBauto\fR, in which case signatures are wiped only when in +interactive mode and after confirmation by user. In all cases detected +signatures are reported by warning messages after a new partition is created. +See also +.BR wipefs (8) +command. + .TP .BR \-v , " \-\-version" Display version information and exit. diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 15fa99c47..009803e6c 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -89,7 +89,8 @@ enum { struct sfdisk { int act; /* ACT_* */ int partno; /* -N , default -1 */ - int wipemode; /* remove foreign signatures */ + int wipemode; /* remove foreign signatures from disk */ + int pwipemode; /* remove foreign signatures from partitions */ const char *label; /* --label