diff options
| author | Karel Zak <kzak@redhat.com> | 2016-02-18 12:57:13 +0100 |
|---|---|---|
| committer | Karel Zak <kzak@redhat.com> | 2016-02-18 12:58:12 +0100 |
| commit | 15b5e942f2c159db8f726079573bb77cdad560ed (patch) | |
| tree | 9bed09b92c12888d782a9bdd75e7e6e471d54afa /disk-utils/sfdisk.c | |
| parent | cb9a4b0033eca429689a403be2a192fe2842f2e9 (diff) | |
| download | util-linux-15b5e942f2c159db8f726079573bb77cdad560ed.tar.gz | |
sfdisk: add --wipe
This patch changes sfdisk 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> | sfdisk), the option "--wipe=always" is required to enable
in this case.
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/sfdisk.c')
| -rw-r--r-- | disk-utils/sfdisk.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 4e99df53b8..81371eb347 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -89,6 +89,7 @@ enum { struct sfdisk { int act; /* ACT_* */ int partno; /* -N <partno>, default -1 */ + int wipemode; /* remove foreign signatures */ const char *label; /* --label <label> */ const char *label_nested; /* --label-nested <label> */ const char *backup_file; /* -O <path> */ @@ -1528,6 +1529,26 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv) fputs(_(" OK\n\n"), stdout); } + if (fdisk_get_collision(sf->cxt)) { + int dowipe = sf->wipemode == WIPEMODE_ALWAYS ? 1 : 0; + + fdisk_warnx(sf->cxt, _("%s: device already contains %s signature."), + devname, fdisk_get_collision(sf->cxt)); + + if (sf->interactive && sf->wipemode == WIPEMODE_AUTO) + dowipe = 1; /* do it in interactive mode */ + + fdisk_enable_wipe(sf->cxt, dowipe); + if (dowipe) + fdisk_warnx(sf->cxt, _( + "The signature will be removed by write command.")); + else + fdisk_warnx(sf->cxt, _( + "It is strongly recommended to wipe the device with " + "wipefs(8), in order to avoid possible collisions.")); + fputc('\n', stderr); + } + if (sf->backup) backup_partition_table(sf, devname); @@ -1548,6 +1569,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv) fdisk_script_set_header(dp, "label", label); + if (!sf->quiet && sf->interactive) { if (!fdisk_has_label(sf->cxt) && !sf->label) fdisk_info(sf->cxt, @@ -1740,6 +1762,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out) fputs(_(" -O, --backup-file <path> override default backup file name\n"), out); fputs(_(" -o, --output <list> output columns\n"), out); fputs(_(" -q, --quiet suppress extra info messages\n"), out); + fputs(_(" -w, --wipe <mode> wipe signatures (auto, always or never)\n"), out); fputs(_(" -X, --label <name> specify label type (dos, gpt, ...)\n"), out); fputs(_(" -Y, --label-nested <name> specify nested label type (dos, bsd)\n"), out); fputs(USAGE_SEPARATOR, out); @@ -1764,6 +1787,7 @@ int main(int argc, char *argv[]) int colormode = UL_COLORMODE_UNDEF; struct sfdisk _sf = { .partno = -1, + .wipemode = WIPEMODE_AUTO, .interactive = isatty(STDIN_FILENO) ? 1 : 0, }, *sf = &_sf; @@ -1810,6 +1834,7 @@ int main(int argc, char *argv[]) { "quiet", no_argument, NULL, 'q' }, { "verify", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'v' }, + { "wipe", required_argument, NULL, 'w' }, { "part-uuid", no_argument, NULL, OPT_PARTUUID }, { "part-label", no_argument, NULL, OPT_PARTLABEL }, @@ -1831,7 +1856,7 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); atexit(close_stdout); - while ((c = getopt_long(argc, argv, "aAbcdfFghJlLo:O:nN:qrsTu:vVX:Y:", + while ((c = getopt_long(argc, argv, "aAbcdfFghJlLo:O:nN:qrsTu:vVX:Y:w:", longopts, &longidx)) != -1) { switch(c) { case 'A': @@ -1914,6 +1939,11 @@ int main(int argc, char *argv[]) case 'V': sf->verify = 1; break; + case 'w': + sf->wipemode = wipemode_from_string(optarg); + if (sf->wipemode < 0) + errx(EXIT_FAILURE, _("unsupported wipe mode")); + break; case 'X': sf->label = optarg; break; |
