diff options
author | Karel Zak | 2017-02-14 15:11:35 +0100 |
---|---|---|
committer | Karel Zak | 2017-02-14 15:13:35 +0100 |
commit | 5635d1955091ff7084b7cafc22b48cd5a5b17387 (patch) | |
tree | ad0a7b362d59ad143f5e9d4fccf5cf2c0b857cdb /disk-utils | |
parent | sfdisk: improve --wipe functionality (diff) | |
download | kernel-qcow2-util-linux-5635d1955091ff7084b7cafc22b48cd5a5b17387.tar.gz kernel-qcow2-util-linux-5635d1955091ff7084b7cafc22b48cd5a5b17387.tar.xz kernel-qcow2-util-linux-5635d1955091ff7084b7cafc22b48cd5a5b17387.zip |
fdisk: improve --wipe functionality
* always (except --wipe=never) wipe old partition tables
* improve warn messages
* improve man page
Addresses: https://github.com/karelzak/util-linux/issues/410
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils')
-rw-r--r-- | disk-utils/fdisk-menu.c | 33 | ||||
-rw-r--r-- | disk-utils/fdisk.8 | 11 | ||||
-rw-r--r-- | disk-utils/fdisk.c | 45 | ||||
-rw-r--r-- | disk-utils/fdisk.h | 2 |
4 files changed, 47 insertions, 44 deletions
diff --git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c index 3ea5e3ddd..baac9791a 100644 --- a/disk-utils/fdisk-menu.c +++ b/disk-utils/fdisk-menu.c @@ -1032,22 +1032,25 @@ static int createlabel_menu_cb(struct fdisk_context **cxt0, rc = fdisk_create_disklabel(cxt, "sgi"); break; } - return rc; + } else { + switch (ent->key) { + case 'g': + rc = fdisk_create_disklabel(cxt, "gpt"); + break; + case 'G': + rc = fdisk_create_disklabel(cxt, "sgi"); + break; + case 'o': + rc = fdisk_create_disklabel(cxt, "dos"); + break; + case 's': + rc = fdisk_create_disklabel(cxt, "sun"); + break; + } } - switch (ent->key) { - case 'g': - fdisk_create_disklabel(cxt, "gpt"); - break; - case 'G': - fdisk_create_disklabel(cxt, "sgi"); - break; - case 'o': - fdisk_create_disklabel(cxt, "dos"); - break; - case 's': - fdisk_create_disklabel(cxt, "sun"); - break; - } + if (rc == 0 && fdisk_get_collision(cxt)) + follow_wipe_mode(cxt); + return rc; } diff --git a/disk-utils/fdisk.8 b/disk-utils/fdisk.8 index 91c6b6f84..1706b928f 100644 --- a/disk-utils/fdisk.8 +++ b/disk-utils/fdisk.8 @@ -120,17 +120,6 @@ partition tables.) A reasonable value is 63. .TP \fB\-w\fR, \fB\-\-wipe\fR \fIwhen\fR -Wipe filesystem, RAID and partition-table signatures from the device, 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. -In all cases detected signatures are reported by warning messages -before a new partition table is created. See also -.BR wipefs (8) -command. - -.TP -\fB\-W\fR, \fB\-\-wipe-partition\fR \fIwhen\fR 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 diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index a2b4daa36..4ac58ee4d 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -51,6 +51,7 @@ #endif int pwipemode = WIPEMODE_AUTO; +static int wipemode = WIPEMODE_AUTO; /* * fdisk debug stuff (see fdisk.h and include/debug.h) @@ -723,6 +724,30 @@ static fdisk_sector_t get_dev_blocks(char *dev) return size/2; } + +void follow_wipe_mode(struct fdisk_context *cxt) +{ + int dowipe = wipemode == WIPEMODE_ALWAYS ? 1 : 0; + + if (isatty(STDIN_FILENO) && wipemode == WIPEMODE_AUTO) + dowipe = 1; /* do it in interactive mode */ + + if (fdisk_is_ptcollision(cxt) && wipemode != WIPEMODE_NEVER) + dowipe = 1; /* always remove old PT */ + + fdisk_enable_wipe(cxt, dowipe); + if (dowipe) + fdisk_warnx(cxt, _( + "The old %s signature will be removed by a write command."), + fdisk_get_collision(cxt)); + else + fdisk_warnx(cxt, _( + "The old %s signature may remain on the device. " + "It is recommended to wipe the device with wipefs(8) or " + "fdisk --wipe, in order to avoid possible collisions."), + fdisk_get_collision(cxt)); +} + static void __attribute__ ((__noreturn__)) usage(FILE *out) { fputs(USAGE_HEADER, out); @@ -777,7 +802,6 @@ int main(int argc, char **argv) { int rc, i, c, act = ACT_FDISK; int colormode = UL_COLORMODE_UNDEF; - int wipemode = WIPEMODE_AUTO; struct fdisk_context *cxt; char *outarg = NULL; enum { @@ -995,24 +1019,9 @@ int main(int argc, char **argv) fflush(stdout); - if (fdisk_get_collision(cxt)) { - int dowipe = wipemode == WIPEMODE_ALWAYS ? 1 : 0; - - fdisk_warnx(cxt, _("Device %s already contains a %s signature."), - argv[optind], fdisk_get_collision(cxt)); + if (fdisk_get_collision(cxt)) + follow_wipe_mode(cxt); - if (isatty(STDIN_FILENO) && wipemode == WIPEMODE_AUTO) - dowipe = 1; /* do it in interactive mode */ - - fdisk_enable_wipe(cxt, dowipe); - if (dowipe) - fdisk_warnx(cxt, _( - "The signature will be removed by a write command.")); - else - fdisk_warnx(cxt, _( - "It is strongly recommended to wipe the device with " - "wipefs(8), in order to avoid possible collisions.")); - } if (!fdisk_has_label(cxt)) { fdisk_info(cxt, _("Device does not contain a recognized partition table.")); fdisk_create_disklabel(cxt, NULL); diff --git a/disk-utils/fdisk.h b/disk-utils/fdisk.h index 7a7fb85d3..8c08bc34d 100644 --- a/disk-utils/fdisk.h +++ b/disk-utils/fdisk.h @@ -49,4 +49,6 @@ extern void change_partition_type(struct fdisk_context *cxt); extern void toggle_dos_compatibility_flag(struct fdisk_context *cxt); +extern void follow_wipe_mode(struct fdisk_context *cxt); + #endif /* UTIL_LINUX_FDISK_H */ |