summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2007-06-10 16:37:10 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2007-06-10 16:37:10 +0000
commit56f99c60f29823b46202674837fe805b4b1acb70 (patch)
treed7ae5820d13e40f48701dc4b00829c8ddf0a195c
parentd4c7bc29b9e295e2a35a6b4aa36526d4f5028ba2 (diff)
when we change fields in the label to version 1, fix the checksum (but only
if it was ok beforehands)
-rw-r--r--sys/kern/subr_disk.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index f133fbc5bb7..5e2f9064225 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.58 2007/06/09 23:35:23 krw Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.59 2007/06/10 16:37:09 deraadt Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -191,11 +191,15 @@ disklabeltokernlabel(struct disklabel *lp)
{
struct __partitionv0 *v0pp = (struct __partitionv0 *)lp->d_partitions;
struct partition *pp = lp->d_partitions;
- int i, oversion = lp->d_version;
+ int i, oversion = lp->d_version, changed = 0, okbefore = 0;
+
+ if (dkcksum(lp) == 0)
+ okbefore = 1;
if (oversion == 0) {
lp->d_version = 1;
lp->d_secperunith = 0;
+ changed = 1;
}
for (i = 0; i < MAXPARTITIONS; i++, pp++, v0pp++) {
@@ -229,8 +233,15 @@ disklabeltokernlabel(struct disklabel *lp)
}
/* XXX this should not be here */
- DL_SETPOFFSET(&lp->d_partitions[RAW_PART], 0);
- DL_SETPSIZE(&lp->d_partitions[RAW_PART], DL_GETDSIZE(lp));
+ if (DL_GETPOFFSET(&lp->d_partitions[RAW_PART]) != 0) {
+ DL_SETPOFFSET(&lp->d_partitions[RAW_PART], 0);
+ DL_SETPSIZE(&lp->d_partitions[RAW_PART], DL_GETDSIZE(lp));
+ changed = 1;
+ }
+ if (changed && okbefore) {
+ lp->d_checksum = 0;
+ lp->d_checksum = dkcksum(lp);
+ }
}
/*