diff options
author | Karel Zak | 2016-05-04 12:43:35 +0200 |
---|---|---|
committer | Karel Zak | 2016-05-04 12:43:35 +0200 |
commit | ba465623d84b9e330f248a477d078b5f280b7943 (patch) | |
tree | ddf639b7e8657d27e3a426cdad8ca7c3421952ec /disk-utils/fdisk-menu.c | |
parent | libfdisk: add fdisk_wipe_partition() (diff) | |
download | kernel-qcow2-util-linux-ba465623d84b9e330f248a477d078b5f280b7943.tar.gz kernel-qcow2-util-linux-ba465623d84b9e330f248a477d078b5f280b7943.tar.xz kernel-qcow2-util-linux-ba465623d84b9e330f248a477d078b5f280b7943.zip |
fdisk: 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 <kzak@redhat.com>
Diffstat (limited to 'disk-utils/fdisk-menu.c')
-rw-r--r-- | disk-utils/fdisk-menu.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c index becdb40e4..b099cc3c2 100644 --- a/disk-utils/fdisk-menu.c +++ b/disk-utils/fdisk-menu.c @@ -516,6 +516,37 @@ done: return rc; } +static int ask_for_wipe(struct fdisk_context *cxt, size_t partno) +{ + struct fdisk_partition *tmp = NULL; + char *fstype = NULL; + int rc, yes = 0; + + rc = fdisk_get_partition(cxt, partno, &tmp); + if (rc) + goto done; + + rc = fdisk_partition_to_string(tmp, cxt, FDISK_FIELD_FSTYPE, &fstype); + if (rc || fstype == NULL) + goto done; + + fdisk_warnx(cxt, _("Partition #%zu contains a %s signature."), partno + 1, fstype); + + if (pwipemode == WIPEMODE_AUTO && isatty(STDIN_FILENO)) + fdisk_ask_yesno(cxt, _("Do you want to remove the signature?"), &yes); + else if (pwipemode == WIPEMODE_ALWAYS) + yes = 1; + + if (yes) { + fdisk_info(cxt, _("The signature will be removed by a write command.")); + rc = fdisk_wipe_partition(cxt, partno, TRUE); + } +done: + fdisk_unref_partition(tmp); + free(fstype); + return rc; +} + /* * Basic fdisk actions */ @@ -610,8 +641,13 @@ static int generic_menu_cb(struct fdisk_context **cxt0, list_partition_types(cxt); break; case 'n': - rc = fdisk_add_partition(cxt, NULL, NULL); + { + size_t partno; + rc = fdisk_add_partition(cxt, NULL, &partno); + if (!rc) + rc = ask_for_wipe(cxt, partno); break; + } case 't': change_partition_type(cxt); break; |