another gpt vs mbr (sanity) check
Andriy Gapon
avg at icyb.net.ua
Wed Mar 10 11:29:11 UTC 2010
on 07/03/2010 13:10 Andriy Gapon said the following:
>
> Below is a simplistic patch that adds such a check.
> Ideally it should probably check the whole MBR partition table instead of just a
> type of the first entry.
For what it's worth, here is a new version of the patch.
In this version g_part_gpt recognizes MBR as a valid protective/hybrid MBR if
_any_ of the partitions in MBR partition table has type 0xEE (GPT protective
partition).
--- a/sys/geom/part/g_part_gpt.c
+++ b/sys/geom/part/g_part_gpt.c
@@ -568,7 +568,8 @@ g_part_gpt_probe
{
struct g_provider *pp;
char *buf;
- int error, res;
+ int error, res, typ;
+ int i, has_pmbr;
/* We don't nest, which means that our depth should be 0. */
if (table->gpt_depth != 0)
@@ -598,10 +599,18 @@ g_part_gpt_probe
if (buf == NULL)
return (error);
res = le16dec(buf + DOSMAGICOFFSET);
+ for (has_pmbr = 0, i = 0; i < NDOSPART; i++) {
+ typ = *(unsigned char*)(buf + DOSPARTOFF + i * DOSPARTSIZE + 4);
+ if (typ == DOSPTYP_PMBR) {
+ has_pmbr = 1;
+ break;
+ }
+ }
g_free(buf);
if (res != DOSMAGIC)
return (ENXIO);
-
+ if (!has_pmbr)
+ return (ENXIO);
/* Check that there's a primary header. */
buf = g_read_data(cp, pp->sectorsize, pp->sectorsize, &error);
if (buf == NULL)
--
Andriy Gapon
More information about the freebsd-geom
mailing list