return 1;
}
-static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id)
+static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id,
+ struct blkid_chain *chn)
{
const struct blkid_idmag *mag;
+ blkid_loff_t off;
int rc = 1; /* = nothing detected */
if (pr->size <= 0 || (id->minsz && id->minsz > pr->size))
goto nothing; /* the device is too small */
- if (blkid_probe_get_idmag(pr, id, NULL, &mag))
+ if (blkid_probe_get_idmag(pr, id, &off, &mag))
goto nothing;
/* final check by probing function */
if (rc == -1) {
/* reset after error */
reset_partlist(blkid_probe_get_partlist(pr));
+ if (chn && !chn->binary)
+ blkid_probe_chain_reset_vals(pr, chn);
DBG(DEBUG_LOWPROBE, printf(
"%s probefunc failed\n", id->name));
}
+ if (rc == 0 && mag && chn && !chn->binary)
+ blkid_probe_set_magic(pr, off, mag->len,
+ (unsigned char *) mag->magic);
+
DBG(DEBUG_LOWPROBE, printf(
"%s: <--- (rc = %d)\n", id->name, rc));
}
continue;
/* apply checks from idinfo */
- if (idinfo_probe(pr, idinfos[i]) != 0)
+ if (idinfo_probe(pr, idinfos[i], chn) != 0)
continue;
name = idinfos[i]->name;
blkid_probe_set_partlist(prc, ls);
- rc = idinfo_probe(prc, id);
+ rc = idinfo_probe(prc, id, blkid_probe_get_chain(pr));
blkid_probe_set_partlist(prc, NULL);
blkid_partlist_set_parent(ls, NULL);
*/
int blkid_do_wipe(blkid_probe pr, int dryrun)
{
- const char *off;
+ const char *off = NULL;
size_t len = 0;
loff_t offset, l;
char buf[BUFSIZ];
- int fd;
+ int fd, rc;
struct blkid_chain *chn;
if (!pr)
if (!chn)
return -1;
- if (blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL) ||
- blkid_probe_lookup_value(pr, "SBMAGIC", NULL, &len) ||
- len == 0 || off == NULL)
+ switch (chn->driver->id) {
+ case BLKID_CHAIN_SUBLKS:
+ rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL);
+ if (!rc)
+ rc = blkid_probe_lookup_value(pr, "SBMAGIC", NULL, &len);
+ break;
+ case BLKID_CHAIN_PARTS:
+ rc = blkid_probe_lookup_value(pr, "PTMAGIC_OFFSET", &off, NULL);
+ if (!rc)
+ rc = blkid_probe_lookup_value(pr, "PTMAGIC", NULL, &len);
+ break;
+ default:
+ return 0;
+ }
+
+ if (rc || len == 0 || off == NULL)
return 0;
offset = strtoll(off, NULL, 10);
static struct wipe_desc *
get_desc_for_probe(struct wipe_desc *wp, blkid_probe pr)
{
- const char *off, *type, *usage, *mag;
+ const char *off, *type, *mag, *p, *usage = NULL;
size_t len;
+ loff_t offset;
+ int rc;
- if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0 &&
- blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL) == 0 &&
- blkid_probe_lookup_value(pr, "SBMAGIC", &mag, &len) == 0 &&
- blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0) {
+ /* superblocks */
+ if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL) == 0) {
+ rc = blkid_probe_lookup_value(pr, "SBMAGIC_OFFSET", &off, NULL);
+ if (!rc)
+ rc = blkid_probe_lookup_value(pr, "SBMAGIC", &mag, &len);
+ if (rc)
+ return wp;
- loff_t offset = strtoll(off, NULL, 10);
- const char *p;
+ /* partitions */
+ } else if (blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL) == 0) {
+ rc = blkid_probe_lookup_value(pr, "PTMAGIC_OFFSET", &off, NULL);
+ if (!rc)
+ rc = blkid_probe_lookup_value(pr, "PTMAGIC", &mag, &len);
+ if (rc)
+ return wp;
+ usage = "partition table";
+ } else
+ return wp;
- wp = add_offset(wp, offset, 0);
- if (!wp)
- return NULL;
+ offset = strtoll(off, NULL, 10);
+ wp = add_offset(wp, offset, 0);
+ if (!wp)
+ return NULL;
+
+ if (usage || blkid_probe_lookup_value(pr, "USAGE", &usage, NULL) == 0)
wp->usage = xstrdup(usage);
- wp->type = xstrdup(type);
- wp->on_disk = 1;
- wp->magic = xmalloc(len);
- memcpy(wp->magic, mag, len);
- wp->len = len;
+ wp->type = xstrdup(type);
+ wp->on_disk = 1;
- if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0)
- wp->label = xstrdup(p);
+ wp->magic = xmalloc(len);
+ memcpy(wp->magic, mag, len);
+ wp->len = len;
- if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0)
- wp->uuid = xstrdup(p);
- }
+ if (blkid_probe_lookup_value(pr, "LABEL", &p, NULL) == 0)
+ wp->label = xstrdup(p);
+
+ if (blkid_probe_lookup_value(pr, "UUID", &p, NULL) == 0)
+ wp->uuid = xstrdup(p);
return wp;
}
new_probe(const char *devname, int mode)
{
blkid_probe pr;
- int rc;
if (!devname)
return NULL;
if (!pr)
goto error;
- blkid_probe_enable_superblocks(pr, 0); /* enabled by default ;-( */
-
- blkid_probe_enable_partitions(pr, 1);
- rc = blkid_do_fullprobe(pr);
- blkid_probe_enable_partitions(pr, 0);
-
- if (rc == 0) {
- const char *type = NULL;
- blkid_probe_lookup_value(pr, "PTTYPE", &type, NULL);
- warnx(_("WARNING: %s: appears to contain '%s' "
- "partition table"), devname, type);
- }
-
blkid_probe_enable_superblocks(pr, 1);
blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC |
BLKID_SUBLKS_TYPE | BLKID_SUBLKS_USAGE |
BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID);
+ blkid_probe_enable_partitions(pr, 1);
+ blkid_probe_set_partitions_flags(pr, BLKID_PARTS_MAGIC);
+
return pr;
error:
err(EXIT_FAILURE, _("error: %s: probing initialization failed"), devname);