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>
This commit is contained in:
parent
bb88152764
commit
5635d19550
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
if (fdisk_get_collision(cxt))
|
||||
follow_wipe_mode(cxt);
|
||||
|
||||
fdisk_warnx(cxt, _("Device %s already contains a %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 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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue