summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_disk.c
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2015-08-26 15:36:46 +0000
committerkrw <krw@openbsd.org>2015-08-26 15:36:46 +0000
commitdf25fdcfef96d56e59100f084d91738d75573d39 (patch)
treecb8c76b0ca2bd7c4ef0fa28d8b86cbf21fbc4bf9 /sys/kern/subr_disk.c
parenttweak previous; (diff)
downloadwireguard-openbsd-df25fdcfef96d56e59100f084d91738d75573d39.tar.xz
wireguard-openbsd-df25fdcfef96d56e59100f084d91738d75573d39.zip
Enhance setdisklabel() to ensure that the disk size and 'C'
partition information of the in-memory disklabel remains correct. ok deraadt@
Diffstat (limited to 'sys/kern/subr_disk.c')
-rw-r--r--sys/kern/subr_disk.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index 4fc92de0bba..0d4988d4dc2 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.189 2015/08/24 23:03:11 krw Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.190 2015/08/26 15:36:46 krw Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -924,6 +924,12 @@ setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_int openmask)
memcmp(nlp->d_uid, &uid, sizeof(nlp->d_uid)) == 0);
}
+ /* Preserve the disk size and RAW_PART values. */
+ DL_SETDSIZE(nlp, DL_GETDSIZE(olp));
+ npp = &nlp->d_partitions[RAW_PART];
+ DL_SETPOFFSET(npp, 0);
+ DL_SETPSIZE(npp, DL_GETDSIZE(nlp));
+
nlp->d_checksum = 0;
nlp->d_checksum = dkcksum(nlp);
*olp = *nlp;