wipefs: don't do step-back if <type> does not match

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2017-06-16 11:36:41 +02:00
parent 92296e9ba2
commit 193d6f27fb
1 changed files with 14 additions and 5 deletions

View File

@ -171,13 +171,16 @@ clone_offset(struct wipe_desc *wp0)
} }
static struct wipe_desc * static struct wipe_desc *
get_desc_for_probe(struct wipe_desc *wp, blkid_probe pr) get_desc_for_probe(struct wipe_desc *wp, blkid_probe pr, int *found)
{ {
const char *off, *type, *mag, *p, *usage = NULL; const char *off, *type, *mag, *p, *usage = NULL;
size_t len; size_t len;
loff_t offset; loff_t offset;
int rc, ispt = 0; int rc, ispt = 0;
if (found)
*found = 0;
/* superblocks */ /* superblocks */
if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) { if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) {
rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL); rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL);
@ -224,6 +227,8 @@ get_desc_for_probe(struct wipe_desc *wp, blkid_probe pr)
if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0) if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0)
wp->uuid = xstrdup(p); wp->uuid = xstrdup(p);
if (found)
*found = 1;
return wp; return wp;
} }
@ -278,14 +283,18 @@ read_offsets(struct wipe_desc *wp, const char *devname)
return NULL; return NULL;
while (blkid_do_probe(pr) == 0) { while (blkid_do_probe(pr) == 0) {
wp = get_desc_for_probe(wp, pr); int found = 0;
wp = get_desc_for_probe(wp, pr, &found);
if (!wp) if (!wp)
break; break;
/* hide last detected signature and scan again */ /* hide last detected signature and scan again */
if (found) {
blkid_probe_hide_range(pr, wp->offset, wp->len); blkid_probe_hide_range(pr, wp->offset, wp->len);
blkid_probe_step_back(pr); blkid_probe_step_back(pr);
} }
}
blkid_free_probe(pr); blkid_free_probe(pr);
return wp; return wp;
@ -394,7 +403,7 @@ do_wipe(struct wipe_desc *wp, const char *devname, int flags)
wp0 = clone_offset(wp); wp0 = clone_offset(wp);
while (blkid_do_probe(pr) == 0) { while (blkid_do_probe(pr) == 0) {
wp = get_desc_for_probe(wp, pr); wp = get_desc_for_probe(wp, pr, NULL);
if (!wp) if (!wp)
break; break;