aboutsummaryrefslogtreecommitdiff
path: root/sys/geom/part
diff options
context:
space:
mode:
authorEugene Grosbein <eugen@FreeBSD.org>2020-09-08 22:23:53 +0000
committerEugene Grosbein <eugen@FreeBSD.org>2020-09-08 22:23:53 +0000
commitcea05ed9a99ebca658b7bc3118b260fbbef374aa (patch)
treedca14ccff780f56ab3500616849c2a35472c0e35 /sys/geom/part
parent4a8201c13aa42f7bb18fd7e6985298e25c3f0100 (diff)
downloadsrc-cea05ed9a99ebca658b7bc3118b260fbbef374aa.tar.gz
src-cea05ed9a99ebca658b7bc3118b260fbbef374aa.zip
geom_part: extend kern.geom.part.check_integrity to work on GPT
There are multiple USB/SATA bridges on the market that unconditionally cut some LBAs off connected media. This could be a problem for pre-partitioned drives so GEOM complains and does not create devices in /dev for slices/partitions preventing access to existing data. We have kern.geom.part.check_integrity that allows us to correct partitioning if changed from default 1 to 0 but it works for MBR only. If backup copy of GPT is unavailable due to decreases number of LBAs, kernel still does not give access to partitions and prints to dmesg: GEOM: md0: corrupt or invalid GPT detected. GEOM: md0: GPT rejected -- may not be recoverable. This change makes it work for GPT too, so it created partitions in /dev and prints to dmesg this instead: GEOM: md0: the secondary GPT table is corrupt or invalid. GEOM: md0: using the primary only -- recovery suggested. Then "gpart recover" re-created backup copy of GPT and allows further manipulations with partitions. This change is no-op for default configuration having kern.geom.part.check_integrity=1 Reported by: Alex Korchmar MFC after: 3 days.
Notes
Notes: svn path=/head/; revision=365477
Diffstat (limited to 'sys/geom/part')
-rw-r--r--sys/geom/part/g_part.c6
-rw-r--r--sys/geom/part/g_part_gpt.c7
2 files changed, 8 insertions, 5 deletions
diff --git a/sys/geom/part/g_part.c b/sys/geom/part/g_part.c
index e045bdef1600..621058c9d402 100644
--- a/sys/geom/part/g_part.c
+++ b/sys/geom/part/g_part.c
@@ -140,9 +140,9 @@ struct g_part_alias_list {
SYSCTL_DECL(_kern_geom);
SYSCTL_NODE(_kern_geom, OID_AUTO, part, CTLFLAG_RW | CTLFLAG_MPSAFE, 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");
static u_int auto_resize = 1;
SYSCTL_UINT(_kern_geom_part, OID_AUTO, auto_resize,
@@ -428,7 +428,7 @@ g_part_check_integrity(struct g_part_table *table, struct g_consumer *cp)
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;
}
diff --git a/sys/geom/part/g_part_gpt.c b/sys/geom/part/g_part_gpt.c
index 24de674d2d84..c9eef1c8f715 100644
--- a/sys/geom/part/g_part_gpt.c
+++ b/sys/geom/part/g_part_gpt.c
@@ -66,6 +66,8 @@ SYSCTL_UINT(_kern_geom_part_gpt, OID_AUTO, allow_nesting,
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
@@ -480,8 +482,9 @@ gpt_read_hdr(struct g_part_gpt_table *table, struct g_consumer *cp,
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. */