cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone
0b5e55
diff -up util-linux-2.23.2/libblkid/src/partitions/gpt.c.kzak util-linux-2.23.2/libblkid/src/partitions/gpt.c
0b5e55
--- util-linux-2.23.2/libblkid/src/partitions/gpt.c.kzak	2013-07-30 10:39:26.206738239 +0200
0b5e55
+++ util-linux-2.23.2/libblkid/src/partitions/gpt.c	2014-01-23 11:06:17.364011293 +0100
0b5e55
@@ -156,13 +156,15 @@ static int last_lba(blkid_probe pr, uint
0b5e55
  * Note that the PMBR detection is optional (enabled by default) and could be
0b5e55
  * disabled by BLKID_PARTS_FOPCE_GPT flag (see also blkid_paertitions_set_flags()).
0b5e55
  */
0b5e55
-static int is_pmbr_valid(blkid_probe pr)
0b5e55
+static int is_pmbr_valid(blkid_probe pr, int *has)
0b5e55
 {
0b5e55
 	int flags = blkid_partitions_get_flags(pr);
0b5e55
 	unsigned char *data;
0b5e55
 	struct dos_partition *p;
0b5e55
 	int i;
0b5e55
 
0b5e55
+	if (has)
0b5e55
+		*has = 0;
0b5e55
 	if (flags & BLKID_PARTS_FORCE_GPT)
0b5e55
 		goto ok;			/* skip PMBR check */
0b5e55
 
0b5e55
@@ -182,6 +184,8 @@ static int is_pmbr_valid(blkid_probe pr)
0b5e55
 failed:
0b5e55
 	return 0;
0b5e55
 ok:
0b5e55
+	if (has)
0b5e55
+		*has = 1;
0b5e55
 	return 1;
0b5e55
 }
0b5e55
 
0b5e55
@@ -305,7 +309,7 @@ static int probe_gpt_pt(blkid_probe pr,
0b5e55
 	if (last_lba(pr, &lastlba))
0b5e55
 		goto nothing;
0b5e55
 
0b5e55
-	if (!is_pmbr_valid(pr))
0b5e55
+	if (!is_pmbr_valid(pr, NULL))
0b5e55
 		goto nothing;
0b5e55
 
0b5e55
 	h = get_gpt_header(pr, &hdr, &e, (lba = GPT_PRIMARY_LBA), lastlba);
0b5e55
@@ -410,3 +414,39 @@ const struct blkid_idinfo gpt_pt_idinfo
0b5e55
 	.magics		= BLKID_NONE_MAGIC
0b5e55
 };
0b5e55
 
0b5e55
+
0b5e55
+
0b5e55
+/* probe for *alone* protective MBR */
0b5e55
+static int probe_pmbr_pt(blkid_probe pr,
0b5e55
+		const struct blkid_idmag *mag __attribute__((__unused__)))
0b5e55
+{
0b5e55
+	int has = 0;
0b5e55
+	struct gpt_entry *e;
0b5e55
+	uint64_t lastlba = 0;
0b5e55
+	struct gpt_header hdr;
0b5e55
+
0b5e55
+	if (last_lba(pr, &lastlba))
0b5e55
+		goto nothing;
0b5e55
+
0b5e55
+	is_pmbr_valid(pr, &has;;
0b5e55
+	if (!has)
0b5e55
+		goto nothing;
0b5e55
+
0b5e55
+	if (!get_gpt_header(pr, &hdr, &e, GPT_PRIMARY_LBA, lastlba) &&
0b5e55
+	    !get_gpt_header(pr, &hdr, &e, lastlba, lastlba))
0b5e55
+		return 0;
0b5e55
+nothing:
0b5e55
+	return 1;
0b5e55
+}
0b5e55
+
0b5e55
+const struct blkid_idinfo pmbr_pt_idinfo =
0b5e55
+{
0b5e55
+	.name		= "PMBR",
0b5e55
+	.probefunc	= probe_pmbr_pt,
0b5e55
+	.magics		=
0b5e55
+	{
0b5e55
+		{ .magic = "\x55\xAA", .len = 2, .sboff = 510 },
0b5e55
+		{ NULL }
0b5e55
+	}
0b5e55
+};
0b5e55
+
0b5e55
diff -up util-linux-2.23.2/libblkid/src/partitions/partitions.c.kzak util-linux-2.23.2/libblkid/src/partitions/partitions.c
0b5e55
--- util-linux-2.23.2/libblkid/src/partitions/partitions.c.kzak	2013-07-30 10:39:26.207738249 +0200
0b5e55
+++ util-linux-2.23.2/libblkid/src/partitions/partitions.c	2014-01-23 11:06:17.364011293 +0100
0b5e55
@@ -125,6 +125,7 @@ static const struct blkid_idinfo *idinfo
0b5e55
 	&sun_pt_idinfo,
0b5e55
 	&dos_pt_idinfo,
0b5e55
 	&gpt_pt_idinfo,
0b5e55
+	&pmbr_pt_idinfo,	/* always after GPT */
0b5e55
 	&mac_pt_idinfo,
0b5e55
 	&ultrix_pt_idinfo,
0b5e55
 	&bsd_pt_idinfo,
0b5e55
diff -up util-linux-2.23.2/libblkid/src/partitions/partitions.h.kzak util-linux-2.23.2/libblkid/src/partitions/partitions.h
0b5e55
--- util-linux-2.23.2/libblkid/src/partitions/partitions.h.kzak	2013-07-30 10:39:26.208738259 +0200
0b5e55
+++ util-linux-2.23.2/libblkid/src/partitions/partitions.h	2014-01-23 11:06:17.364011293 +0100
0b5e55
@@ -59,6 +59,7 @@ extern const struct blkid_idinfo mac_pt_
0b5e55
 extern const struct blkid_idinfo dos_pt_idinfo;
0b5e55
 extern const struct blkid_idinfo minix_pt_idinfo;
0b5e55
 extern const struct blkid_idinfo gpt_pt_idinfo;
0b5e55
+extern const struct blkid_idinfo pmbr_pt_idinfo;
0b5e55
 extern const struct blkid_idinfo ultrix_pt_idinfo;
0b5e55
 
0b5e55
 #endif /* BLKID_PARTITIONS_H */