diff options
author | Karel Zak | 2016-02-18 12:50:11 +0100 |
---|---|---|
committer | Karel Zak | 2016-02-18 12:58:12 +0100 |
commit | cb9a4b0033eca429689a403be2a192fe2842f2e9 (patch) | |
tree | d2bb843aaa8462e6714fa609aa1c9cc03b6aab27 /disk-utils/fdisk.c | |
parent | libfdisk: add API to control signatures wiping (diff) | |
download | kernel-qcow2-util-linux-cb9a4b0033eca429689a403be2a192fe2842f2e9.tar.gz kernel-qcow2-util-linux-cb9a4b0033eca429689a403be2a192fe2842f2e9.tar.xz kernel-qcow2-util-linux-cb9a4b0033eca429689a403be2a192fe2842f2e9.zip |
fdisk: add --wipe
This patch changes fdisk behavior and it wipes foreign signatures
from the device to avoid collisions. The wipe functionality is
automatically enabled in the interactive mode only (user is always
warned about it), otherwise it's possible to control all by --wipe
<auto|never|always>.
The program does not change behavior when executed in scripts (echo
<something> | fdisk), the option "--wipe=always" is required to enable
in this case.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/fdisk.c')
-rw-r--r-- | disk-utils/fdisk.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index c924d26b6..0b229839e 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -734,6 +734,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out) fputs(_(" -u, --units[=<unit>] display units: 'cylinders' or 'sectors' (default)\n"), out); fputs(_(" -s, --getsz display device size in 512-byte sectors [DEPRECATED]\n"), out); fputs(_(" --bytes print SIZE in bytes rather than in human readable format\n"), out); + fputs(_(" -w, --wipe <mode> wipe signatures (auto, always or never)\n"), out); fputs(USAGE_SEPARATOR, out); fputs(_(" -C, --cylinders <number> specify the number of cylinders\n"), out); @@ -761,6 +762,7 @@ 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 { @@ -782,6 +784,7 @@ int main(int argc, char **argv) { "version", no_argument, NULL, 'V' }, { "output", no_argument, NULL, 'o' }, { "protect-boot", no_argument, NULL, 'B' }, + { "wipe", required_argument, NULL, 'w' }, { NULL, 0, NULL, 0 } }; @@ -800,7 +803,7 @@ int main(int argc, char **argv) fdisk_set_ask(cxt, ask_callback, NULL); - while ((c = getopt_long(argc, argv, "b:Bc::C:hH:lL::o:sS:t:u::vV", + while ((c = getopt_long(argc, argv, "b:Bc::C:hH:lL::o:sS:t:u::vVw:", longopts, NULL)) != -1) { switch (c) { case 'b': @@ -891,6 +894,11 @@ int main(int argc, char **argv) case 'v': /* for backward compatibility only */ printf(UTIL_LINUX_VERSION); return EXIT_SUCCESS; + case 'w': + wipemode = wipemode_from_string(optarg); + if (wipemode < 0) + errx(EXIT_FAILURE, _("unsupported wipe mode")); + break; case 'h': usage(stdout); case OPT_BYTES: @@ -957,6 +965,24 @@ int main(int argc, char **argv) fflush(stdout); + if (fdisk_get_collision(cxt)) { + int dowipe = wipemode == WIPEMODE_ALWAYS ? 1 : 0; + + fdisk_warnx(cxt, _("%s: device already contains %s signature."), + argv[optind], fdisk_get_collision(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 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); |