Index: head/sys/geom/part/g_part_gpt.c =================================================================== --- head/sys/geom/part/g_part_gpt.c (revision 238894) +++ head/sys/geom/part/g_part_gpt.c (working copy) @@ -50,6 +50,15 @@ __FBSDID("$FreeBSD$"); FEATURE(geom_part_gpt, "GEOM partitioning class for GPT partitions support"); +SYSCTL_DECL(_kern_geom_part); +static SYSCTL_NODE(_kern_geom_part, OID_AUTO, gpt, CTLFLAG_RW, 0, + "GEOM_PART_GPT GUID Partition Table"); + +static int gpt_force = 1; +TUNABLE_INT("kern.geom.part.gpt.force", &gpt_force); +SYSCTL_UINT(_kern_geom_part_gpt, OID_AUTO, force, + CTLFLAG_RW | CTLFLAG_TUN, &gpt_force, 1, "Force GPT detection"); + CTASSERT(offsetof(struct gpt_hdr, padding) == 92); CTASSERT(sizeof(struct gpt_ent) == 128); @@ -743,6 +752,7 @@ static int g_part_gpt_probe(struct g_part_table *table, struct g_consumer *cp) { struct g_provider *pp; + struct dos_partition *dp; char *buf; int error, res; @@ -774,10 +784,30 @@ g_part_gpt_probe(struct g_part_table *table, struc if (buf == NULL) return (error); res = le16dec(buf + DOSMAGICOFFSET); + if (res != DOSMAGIC) { + g_free(buf); + return (ENXIO); + } + if (gpt_force == 0) { + /* Test Protective MBR for validity */ + dp = (struct dos_partition *)(buf + DOSPARTOFF); + for (res = 0, error = ENXIO; res < NDOSPART; res++) { + if (dp[res].dp_flag == 0 && + dp[res].dp_typ == 0) + continue; + if (dp[res].dp_flag != 0 && + dp[res].dp_flag != 0x80) + break; + if (dp[res].dp_typ == DOSPTYP_PMBR && + dp[res].dp_start == 1) + error = 0; + } + if (error != 0) { + g_free(buf); + return (ENXIO); + } + } g_free(buf); - if (res != DOSMAGIC) - return (ENXIO); - /* Check that there's a primary header. */ buf = g_read_data(cp, pp->sectorsize, pp->sectorsize, &error); if (buf == NULL) Index: head/sbin/geom/class/part/gpart.8 =================================================================== --- head/sbin/geom/class/part/gpart.8 (revision 238894) +++ head/sbin/geom/class/part/gpart.8 (working copy) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 19, 2012 +.Dd June 30, 2012 .Dt GPART 8 .Os .Sh NAME @@ -957,6 +957,13 @@ disk metadata. If some inconsistency is detected, the partition table will be rejected with a diagnostic message: .Sy "GEOM_PART: Integrity check failed (provider, scheme)" . +.It Va kern.geom.part.gpt.force : No 1 +This variable controls how the GUID Partition Table (GPT) module does +validity tests for the Protective MBR. +The Protective MBR is required by the UEFI specification and in case when +it is damaged or contains invalid values, GPT will not be detected. +If this variable set to 1 GPT module ignores some inconsistencies in the +Protective MBR. .It Va kern.geom.part.ldm.debug : No 0 Debug level of the Logical Disk Manager (LDM) module. This can be set to a number between 0 and 2 inclusive.