Author: eugen
Date: Sat Sep 12 18:42:14 2020
New Revision: 365668
URL: https://svnweb.freebsd.org/changeset/base/365668

Log:
  MFC r365477: geom_part: extend kern.geom.part.check_integrity to work on GPT
  
  In short, this change allows accessing partition and recovering secondary
  GPT in case it is unaccessible but primary table is fine.
  
  Reported by:  Alex Korchmar

Modified:
  stable/11/sys/geom/part/g_part.c
  stable/11/sys/geom/part/g_part_gpt.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/geom/part/g_part.c
==============================================================================
--- stable/11/sys/geom/part/g_part.c    Sat Sep 12 18:40:39 2020        
(r365667)
+++ stable/11/sys/geom/part/g_part.c    Sat Sep 12 18:42:14 2020        
(r365668)
@@ -132,9 +132,9 @@ struct g_part_alias_list {
 SYSCTL_DECL(_kern_geom);
 SYSCTL_NODE(_kern_geom, OID_AUTO, part, CTLFLAG_RW, 0,
     "GEOM_PART stuff");
-static u_int check_integrity = 1;
+u_int geom_part_check_integrity = 1;
 SYSCTL_UINT(_kern_geom_part, OID_AUTO, check_integrity,
-    CTLFLAG_RWTUN, &check_integrity, 1,
+    CTLFLAG_RWTUN, &geom_part_check_integrity, 1,
     "Enable integrity checking");
 
 /*
@@ -409,7 +409,7 @@ g_part_check_integrity(struct g_part_table *table, str
        if (failed != 0) {
                printf("GEOM_PART: integrity check failed (%s, %s)\n",
                    pp->name, table->gpt_scheme->name);
-               if (check_integrity != 0)
+               if (geom_part_check_integrity != 0)
                        return (EINVAL);
                table->gpt_corrupt = 1;
        }

Modified: stable/11/sys/geom/part/g_part_gpt.c
==============================================================================
--- stable/11/sys/geom/part/g_part_gpt.c        Sat Sep 12 18:40:39 2020        
(r365667)
+++ stable/11/sys/geom/part/g_part_gpt.c        Sat Sep 12 18:42:14 2020        
(r365668)
@@ -54,6 +54,8 @@ FEATURE(geom_part_gpt, "GEOM partitioning class for GP
 CTASSERT(offsetof(struct gpt_hdr, padding) == 92);
 CTASSERT(sizeof(struct gpt_ent) == 128);
 
+extern u_int geom_part_check_integrity;
+
 #define        EQUUID(a,b)     (memcmp(a, b, sizeof(struct uuid)) == 0)
 
 #define        MBRSIZE         512
@@ -448,8 +450,9 @@ gpt_read_hdr(struct g_part_gpt_table *table, struct g_
        if (hdr->hdr_lba_self != table->lba[elt])
                goto fail;
        hdr->hdr_lba_alt = le64toh(buf->hdr_lba_alt);
-       if (hdr->hdr_lba_alt == hdr->hdr_lba_self ||
-           hdr->hdr_lba_alt > last)
+       if (hdr->hdr_lba_alt == hdr->hdr_lba_self)
+               goto fail;
+       if (hdr->hdr_lba_alt > last && geom_part_check_integrity)
                goto fail;
 
        /* Check the managed area. */
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to