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/fdisk.c | |
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/fdisk.c')
-rw-r--r-- | disk-utils/fdisk.c | 45 |
1 files changed, 27 insertions, 18 deletions
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); |