diff options
author | Karel Zak | 2011-11-13 21:25:12 +0100 |
---|---|---|
committer | Karel Zak | 2011-11-13 21:25:12 +0100 |
commit | 44765fdd841fb1369cf68f360131ed076f3a2771 (patch) | |
tree | e9b51e8f0a87381c04b17b08ea15076e5304ef91 | |
parent | libblkid: add BLKID_PARTS_MAGIC (diff) | |
download | kernel-qcow2-util-linux-44765fdd841fb1369cf68f360131ed076f3a2771.tar.gz kernel-qcow2-util-linux-44765fdd841fb1369cf68f360131ed076f3a2771.tar.xz kernel-qcow2-util-linux-44765fdd841fb1369cf68f360131ed076f3a2771.zip |
libblkid: export info about PT magic strings
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r-- | libblkid/src/partitions/gpt.c | 5 | ||||
-rw-r--r-- | libblkid/src/partitions/partitions.c | 16 | ||||
-rw-r--r-- | libblkid/src/partitions/ultrix.c | 6 | ||||
-rw-r--r-- | libblkid/src/probe.c | 23 | ||||
-rw-r--r-- | misc-utils/wipefs.c | 73 |
5 files changed, 80 insertions, 43 deletions
diff --git a/libblkid/src/partitions/gpt.c b/libblkid/src/partitions/gpt.c index c0517c427..bee6e26f4 100644 --- a/libblkid/src/partitions/gpt.c +++ b/libblkid/src/partitions/gpt.c @@ -26,6 +26,7 @@ /* Signature - “EFI PART” */ #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL +#define GPT_HEADER_SIGNATURE_STR "EFI PART" /* basic types */ typedef uint16_t efi_char16_t; @@ -326,6 +327,10 @@ static int probe_gpt_pt(blkid_probe pr, if (!tab) goto err; + blkid_probe_set_magic(pr, lba << 9, + sizeof(GPT_HEADER_SIGNATURE_STR) - 1, + (unsigned char *) GPT_HEADER_SIGNATURE_STR); + ssf = blkid_probe_get_sectorsize(pr) / 512; fu = le64_to_cpu(h->first_usable_lba); diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c index 86bf43224..aa8ca7c73 100644 --- a/libblkid/src/partitions/partitions.c +++ b/libblkid/src/partitions/partitions.c @@ -530,15 +530,17 @@ int blkid_is_nested_dimension(blkid_partition par, 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 */ @@ -549,9 +551,15 @@ static int idinfo_probe(blkid_probe pr, const struct blkid_idinfo *id) 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)); } @@ -594,7 +602,7 @@ static int partitions_probe(blkid_probe pr, struct blkid_chain *chn) 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; @@ -678,7 +686,7 @@ int blkid_partitions_do_subprobe(blkid_probe pr, blkid_partition parent, 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); diff --git a/libblkid/src/partitions/ultrix.c b/libblkid/src/partitions/ultrix.c index f637c5474..dd18fe3da 100644 --- a/libblkid/src/partitions/ultrix.c +++ b/libblkid/src/partitions/ultrix.c @@ -15,7 +15,9 @@ #include "partitions.h" #define ULTRIX_MAXPARTITIONS 8 + #define ULTRIX_MAGIC 0x032957 +#define ULTRIX_MAGIC_STR "\x02\x29\x57" /* sector with partition table */ #define ULTRIX_SECTOR ((16384 - sizeof(struct ultrix_disklabel)) >> 9) @@ -62,6 +64,10 @@ static int probe_ultrix_pt(blkid_probe pr, if (!tab) goto err; + blkid_probe_set_magic(pr, (ULTRIX_SECTOR << 9) + ULTRIX_OFFSET, + sizeof(ULTRIX_MAGIC_STR) - 1, + (unsigned char *) ULTRIX_MAGIC_STR); + for (i = 0; i < ULTRIX_MAXPARTITIONS; i++) { if (!l->pt_part[i].pi_nblocks) blkid_partlist_increment_partno(ls); diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 49b042095..ee01a65e5 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -947,11 +947,11 @@ int blkid_do_probe(blkid_probe pr) */ 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) @@ -961,9 +961,22 @@ int blkid_do_wipe(blkid_probe pr, int dryrun) 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); diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index 1cd3159d1..4ba6d0797 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -142,35 +142,51 @@ add_offset(struct wipe_desc *wp0, loff_t offset, int zap) 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; } @@ -179,7 +195,6 @@ static blkid_probe new_probe(const char *devname, int mode) { blkid_probe pr; - int rc; if (!devname) return NULL; @@ -198,24 +213,14 @@ new_probe(const char *devname, int mode) 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); |