]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: export info about PT magic strings
authorKarel Zak <kzak@redhat.com>
Sun, 13 Nov 2011 20:25:12 +0000 (21:25 +0100)
committerKarel Zak <kzak@redhat.com>
Sun, 13 Nov 2011 20:25:12 +0000 (21:25 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/partitions/gpt.c
libblkid/src/partitions/partitions.c
libblkid/src/partitions/ultrix.c
libblkid/src/probe.c
misc-utils/wipefs.c

index c0517c427117fcf0a8c771f5e47f82991c9b35f6..bee6e26f4d8489e06530f98c761de214e26fd2e3 100644 (file)
@@ -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);
index 86bf432247c46d8d67f6f1d13cfdd6519dce44c0..aa8ca7c73fd797e0739701ba39ae64e63ae2a4a0 100644 (file)
@@ -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);
index f637c5474456a9e094310a98fd82004ea58e32b0..dd18fe3dac2dfe39b7f9f7b5d40731ab340c9169 100644 (file)
@@ -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);
index 49b042095a801cda3f97c5a012c5931176fa8387..ee01a65e5e6ed60303cc0434f1e625b9bf949ab9 100644 (file)
@@ -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);
index 1cd3159d1d8f17e96b4d8945259fa0225b675c51..4ba6d0797047cc6a47995200544957a0a1a0118d 100644 (file)
@@ -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);