diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2007-02-18 11:43:20 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2007-02-18 11:43:20 +0000 |
commit | 60d6d9e3f658e9a697073fa8ec8c1b23cadb66e0 (patch) | |
tree | cd5fee1a50423b09694ce693a54aea18a29895e9 | |
parent | 4dd981ca8b3a44bc13bf8e115ae5cadc8813c2ce (diff) |
In writedisklabel(), read the disklabel sector before rewriting it, to
preserve the non-disklabel contents; otherwise altering your disklabel may
render your machine unbootable.
ok deraadt@ krw@
-rw-r--r-- | sys/arch/vax/vax/disksubr.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sys/arch/vax/vax/disksubr.c b/sys/arch/vax/vax/disksubr.c index 3e312d60bbb..5d5604e8a8c 100644 --- a/sys/arch/vax/vax/disksubr.c +++ b/sys/arch/vax/vax/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.32 2006/10/21 16:01:54 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.33 2007/02/18 11:43:19 miod Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1999/06/30 18:48:06 ragge Exp $ */ /* @@ -253,19 +253,23 @@ writedisklabel(dev, strat, lp, osdep) int error = 0; bp = geteblk((int)lp->d_secsize); - - dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); - bcopy(lp, dlp, sizeof(struct disklabel)); - bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART); bp->b_blkno = LABELSECTOR; bp->b_cylinder = LABELSECTOR / lp->d_secpercyl; bp->b_bcount = lp->d_secsize; + bp->b_flags = B_READ; + (*strat)(bp); + if ((error = biowait(bp)) != 0) + goto done; + + dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); + bcopy(lp, dlp, sizeof(struct disklabel)); bp->b_flags = B_WRITE; (*strat)(bp); error = biowait(bp); - brelse(bp); +done: + brelse(bp); return (error); } |