]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: detect alone PMBR
authorKarel Zak <kzak@redhat.com>
Mon, 20 Jan 2014 09:51:00 +0000 (10:51 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 20 Jan 2014 11:29:16 +0000 (12:29 +0100)
wipefs(8) has to also erase PMBR, not GPR header only, otherwise the
device could be still interpreted as a device with a partition table.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1054186
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/partitions/gpt.c
libblkid/src/partitions/partitions.c
libblkid/src/partitions/partitions.h

index 9894417e7cfbd77c9756663283ccc327f6660ac9..14a255af6a5d5d2a84b4f3386ea15adc3a332a3f 100644 (file)
@@ -155,13 +155,15 @@ static int last_lba(blkid_probe pr, uint64_t *lba)
  * Note that the PMBR detection is optional (enabled by default) and could be
  * disabled by BLKID_PARTS_FOPCE_GPT flag (see also blkid_paertitions_set_flags()).
  */
-static int is_pmbr_valid(blkid_probe pr)
+static int is_pmbr_valid(blkid_probe pr, int *has)
 {
        int flags = blkid_partitions_get_flags(pr);
        unsigned char *data;
        struct dos_partition *p;
        int i;
 
+       if (has)
+               *has = 0;
        if (flags & BLKID_PARTS_FORCE_GPT)
                goto ok;                        /* skip PMBR check */
 
@@ -179,6 +181,8 @@ static int is_pmbr_valid(blkid_probe pr)
 failed:
        return 0;
 ok:
+       if (has)
+               *has = 1;
        return 1;
 }
 
@@ -302,7 +306,7 @@ static int probe_gpt_pt(blkid_probe pr,
        if (last_lba(pr, &lastlba))
                goto nothing;
 
-       if (!is_pmbr_valid(pr))
+       if (!is_pmbr_valid(pr, NULL))
                goto nothing;
 
        h = get_gpt_header(pr, &hdr, &e, (lba = GPT_PRIMARY_LBA), lastlba);
@@ -411,3 +415,39 @@ const struct blkid_idinfo gpt_pt_idinfo =
        .magics         = BLKID_NONE_MAGIC
 };
 
+
+
+/* probe for *alone* protective MBR */
+static int probe_pmbr_pt(blkid_probe pr,
+               const struct blkid_idmag *mag __attribute__((__unused__)))
+{
+       int has = 0;
+       struct gpt_entry *e;
+       uint64_t lastlba = 0;
+       struct gpt_header hdr;
+
+       if (last_lba(pr, &lastlba))
+               goto nothing;
+
+       is_pmbr_valid(pr, &has);
+       if (!has)
+               goto nothing;
+
+       if (!get_gpt_header(pr, &hdr, &e, GPT_PRIMARY_LBA, lastlba) &&
+           !get_gpt_header(pr, &hdr, &e, lastlba, lastlba))
+               return 0;
+nothing:
+       return 1;
+}
+
+const struct blkid_idinfo pmbr_pt_idinfo =
+{
+       .name           = "PMBR",
+       .probefunc      = probe_pmbr_pt,
+       .magics         =
+       {
+               { .magic = "\x55\xAA", .len = 2, .sboff = 510 },
+               { NULL }
+       }
+};
+
index f7d6c45331c0f5716986c10075aa698f9f7e52b1..6c915d92f9f19dcb4ab99eefe84ab3d8077a0477 100644 (file)
@@ -127,6 +127,7 @@ static const struct blkid_idinfo *idinfos[] =
        &sun_pt_idinfo,
        &dos_pt_idinfo,
        &gpt_pt_idinfo,
+       &pmbr_pt_idinfo,        /* always after GPT */
        &mac_pt_idinfo,
        &ultrix_pt_idinfo,
        &bsd_pt_idinfo,
index 55acd50934ebca5f488d31fa92d446ca7010f722..3651bbb4df0b697905d8b24a377bf153cd555675 100644 (file)
@@ -65,6 +65,7 @@ extern const struct blkid_idinfo mac_pt_idinfo;
 extern const struct blkid_idinfo dos_pt_idinfo;
 extern const struct blkid_idinfo minix_pt_idinfo;
 extern const struct blkid_idinfo gpt_pt_idinfo;
+extern const struct blkid_idinfo pmbr_pt_idinfo;
 extern const struct blkid_idinfo ultrix_pt_idinfo;
 
 #endif /* BLKID_PARTITIONS_H */