]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
wipefs: don't erase nested partition tables by default
authorKarel Zak <kzak@redhat.com>
Thu, 24 Apr 2014 11:42:54 +0000 (13:42 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 24 Apr 2014 11:42:54 +0000 (13:42 +0200)
It's possible the partition contains a partition table (BSD, or hybrid
boot images). It could be unexpected for users that the lost all (or
another) partitions when work with non-whole disk device. Let's
require --force.

For example:

 # wipefs --all /dev/sdb

erases all including partition table, but on hybrid disk where the
first partition starts at first sector (so partition table is within
the first partition):

 # wipefs --all /dev/sdb1
 /dev/sdb1: ignore nested "dos" partition table on non-whole disk device
 wipefs: Use the --force option to force erase.

asks for --force.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1077310
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/wipefs.8
misc-utils/wipefs.c

index 0f280b38a5824723b57af468af2659b97746b008..207b67501afc88ecad7adb97af08cda531360448 100644 (file)
@@ -37,6 +37,11 @@ table will still be visible by another magic string on another offset.
 When used with option \fB-a\fR, all magic strings that are visible for libblkid are
 erased.
 
+Note that by default
+.B wipefs
+does not erase nested partition tables on non-whole disk devices. The option 
+\-\-force is required.
+
 .SH OPTIONS
 .TP
 .BR \-a , " \-\-all"
index 5dfaf0c55e049f4ca83b7d8b6a962a3f56a650a2..2c1ea59473c863cdb88740dd9e634b3de21c5cd5 100644 (file)
@@ -365,7 +365,7 @@ static void rereadpt(int fd, const char *devname)
 static struct wipe_desc *
 do_wipe(struct wipe_desc *wp, const char *devname, int flags)
 {
-       int mode = O_RDWR, reread = 0;
+       int mode = O_RDWR, reread = 0, need_force = 0;
        blkid_probe pr;
        struct wipe_desc *w, *wp0;
        int zap = (flags & WP_FL_ALL) ? 1 : wp->zap;
@@ -405,6 +405,15 @@ do_wipe(struct wipe_desc *wp, const char *devname, int flags)
                if (!wp->on_disk)
                        continue;
 
+               if (!(flags & WP_FL_FORCE)
+                   && wp->is_parttable
+                   && !blkid_probe_is_wholedisk(pr)) {
+                       warnx(_("%s: ignore nested \"%s\" partition "
+                               "table on non-whole disk device."), devname, wp->type);
+                       need_force = 1;
+                       continue;
+               }
+
                if (zap) {
                        if (backup)
                                do_backup(wp, backup);
@@ -419,6 +428,9 @@ do_wipe(struct wipe_desc *wp, const char *devname, int flags)
                        warnx(_("%s: offset 0x%jx not found"), devname, w->offset);
        }
 
+       if (need_force)
+               warnx(_("Use the --force option to force erase."));
+
        fsync(blkid_probe_get_fd(pr));
 
        if (reread && (mode & O_EXCL))