Date: Wed, 10 Mar 2010 13:29:08 +0200 From: Andriy Gapon <avg@icyb.net.ua> To: freebsd-geom@freebsd.org Cc: Marcel Moolenaar <xcllnt@mac.com> Subject: Re: another gpt vs mbr (sanity) check Message-ID: <4B978284.5070202@icyb.net.ua> In-Reply-To: <4B9389C1.9000102@icyb.net.ua> References: <4B9389C1.9000102@icyb.net.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4B978284.5070202>