From: Milan Broz Date: Mon, 5 Mar 2012 21:07:09 +0000 (+0100) Subject: wipefs: Fix mismatch if more -o options used. X-Git-Tag: v2.22-rc1~704 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24df2633d3dda02be6f5b686f3347653745fdd08;p=thirdparty%2Futil-linux.git wipefs: Fix mismatch if more -o options used. If there are more offset options specified, some could be lost. Try pvcreate /dev/sd[bcde] mdadm -C -l 5 -n4 /dev/md0 /dev/sd[bcde] mdadm --stop /dev/md0 wipefs -n -o 0x1000 -o 0x218 /dev/sdb - LVM2 signature remains there wipefs -n -o 0x218 -o 0x1010 /dev/sdb - no report about ignored signature Signed-off-by: Milan Broz --- diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index 24edf25d81..74de3a3a36 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -261,45 +261,79 @@ read_offsets(struct wipe_desc *wp, const char *devname) return wp; } +static void +free_wipe(struct wipe_desc *wp) +{ + while (wp) { + struct wipe_desc *next = wp->next; + + free(wp->usage); + free(wp->type); + free(wp->magic); + free(wp->label); + free(wp->uuid); + free(wp); + + wp = next; + } +} + +static void do_wipe_real(blkid_probe pr, const char *devname, struct wipe_desc *w, int noact, int quiet) +{ + size_t i; + + if (blkid_do_wipe(pr, noact)) + warn(_("%s: failed to erase %s magic string at offset 0x%08jx"), + devname, w->type, w->offset); + + if (quiet) + return; + + printf(_("%s: %zd bytes were erased at offset 0x%08jx (%s): "), + devname, w->len, w->offset, w->type); + + for (i = 0; i < w->len; i++) { + printf("%02x", w->magic[i]); + if (i + 1 < w->len) + fputc(' ', stdout); + } + putchar('\n'); +} + static struct wipe_desc * do_wipe(struct wipe_desc *wp, const char *devname, int noact, int all, int quiet) { blkid_probe pr = new_probe(devname, O_RDWR); - struct wipe_desc *w; + struct wipe_desc *w, *wp0 = clone_offset(wp); + int zap = all ? 1 : wp->zap; if (!pr) return NULL; while (blkid_do_probe(pr) == 0) { - w = get_desc_for_probe(wp, pr); - if (!w) + wp = get_desc_for_probe(wp, pr); + if (!wp) break; - wp = w; - if (!wp->on_disk) + + /* Check if offset is in provided list */ + w = wp0; + while(w && w->offset != wp->offset) + w = w->next; + if (wp0 && !w) continue; - wp->zap = all ? 1 : wp->zap; - if (!wp->zap) + + /* Mark done if found in provided list */ + if (w) + w->on_disk = wp->on_disk; + + if (!wp->on_disk) continue; - if (blkid_do_wipe(pr, noact)) - warn(_("%s: failed to erase %s magic string at offset 0x%08jx"), - devname, wp->type, wp->offset); - else if (!quiet) { - size_t i; - - printf(_("%s: %zd bytes were erased at offset 0x%08jx (%s): "), - devname, wp->len, wp->offset, wp->type); - - for (i = 0; i < wp->len; i++) { - printf("%02x", wp->magic[i]); - if (i + 1 < wp->len) - fputc(' ', stdout); - } - putchar('\n'); - } + if (zap) + do_wipe_real(pr, devname, wp, noact, quiet); } - for (w = wp; w != NULL; w = w->next) { + for (w = wp0; w != NULL; w = w->next) { if (!w->on_disk && !quiet) warnx(_("%s: offset 0x%jx not found"), devname, w->offset); } @@ -307,27 +341,11 @@ do_wipe(struct wipe_desc *wp, const char *devname, int noact, int all, int quiet fsync(blkid_probe_get_fd(pr)); close(blkid_probe_get_fd(pr)); blkid_free_probe(pr); + free_wipe(wp0); return wp; } -static void -free_wipe(struct wipe_desc *wp) -{ - while (wp) { - struct wipe_desc *next = wp->next; - - free(wp->usage); - free(wp->type); - free(wp->magic); - free(wp->label); - free(wp->uuid); - free(wp); - - wp = next; - } -} - static loff_t strtoll_offset(const char *str) {