From owner-freebsd-geom@FreeBSD.ORG Wed Mar 10 11:29:11 2010 Return-Path: Delivered-To: freebsd-geom@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9F3721065670 for ; Wed, 10 Mar 2010 11:29:11 +0000 (UTC) (envelope-from avg@icyb.net.ua) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id E38F18FC15 for ; Wed, 10 Mar 2010 11:29:10 +0000 (UTC) Received: from porto.topspin.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id NAA12070; Wed, 10 Mar 2010 13:29:09 +0200 (EET) (envelope-from avg@icyb.net.ua) Received: from localhost.topspin.kiev.ua ([127.0.0.1]) by porto.topspin.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1NpK68-0007q9-Mw; Wed, 10 Mar 2010 13:29:08 +0200 Message-ID: <4B978284.5070202@icyb.net.ua> Date: Wed, 10 Mar 2010 13:29:08 +0200 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.23 (X11/20100211) MIME-Version: 1.0 To: freebsd-geom@freebsd.org References: <4B9389C1.9000102@icyb.net.ua> In-Reply-To: <4B9389C1.9000102@icyb.net.ua> X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Marcel Moolenaar Subject: Re: another gpt vs mbr (sanity) check X-BeenThere: freebsd-geom@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: GEOM-specific discussions and implementations List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Mar 2010 11:29:11 -0000 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