diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2011-07-07 22:48:24 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2011-07-07 22:48:24 +0000 |
commit | a4c10d765061e98acbf92e758cbf0b7ec14190b1 (patch) | |
tree | 9bd020d972902abb26459113759cb53f3b26323f /sys/arch | |
parent | 7c375cf7e321162fcfa54b6f23b0626bc5fdb14f (diff) |
Take more care to write 'dos' labels in the same place readdoslabel()
will look for them. Without changing native label handling.
Compile tested on hppa by kettenis@.
"I see no issues" deraadt@
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/hppa/hppa/disksubr.c | 18 | ||||
-rw-r--r-- | sys/arch/hppa64/hppa64/disksubr.c | 15 | ||||
-rw-r--r-- | sys/arch/macppc/macppc/disksubr.c | 16 |
3 files changed, 34 insertions, 15 deletions
diff --git a/sys/arch/hppa/hppa/disksubr.c b/sys/arch/hppa/hppa/disksubr.c index 950c30e50bc..2ca75fa3471 100644 --- a/sys/arch/hppa/hppa/disksubr.c +++ b/sys/arch/hppa/hppa/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.80 2011/04/16 03:21:15 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.81 2011/07/07 22:48:23 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -108,7 +108,7 @@ readliflabel(struct buf *bp, void (*strat)(struct buf *), SET(bp->b_flags, B_BUSY | B_READ | B_RAW); (*strat)(bp); if (biowait(bp)) - return bp->b_error; + return (bp->b_error); lvp = (struct lifvol *)bp->b_data; if (lvp->vol_id != LIF_VOL_ID) { @@ -252,6 +252,7 @@ int writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) { int error = EIO, partoff = -1; + int offset; struct disklabel *dlp; struct buf *bp = NULL; @@ -259,12 +260,17 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; - if (readliflabel(bp, strat, lp, &partoff, 1) != 0 && - readdoslabel(bp, strat, lp, &partoff, 1) != 0) + if (readliflabel(bp, strat, lp, &partoff, 1) == 0) { + bp->b_blkno = partoff + LABELSECTOR; + offset = LABELOFFSET; + } else if (readdoslabel(bp, strat, lp, &partoff, 1) == 0) { + bp->b_blkno = DL_BLKTOSEC(lp, partoff + LABELSECTOR) * + DL_BLKSPERSEC(lp); + offset = DL_BLKOFFSET(lp, partoff + LABELSECTOR) + LABELOFFSET; + } else goto done; /* Read it in, slap the new label in, and write it back out */ - bp->b_blkno = partoff + LABELSECTOR; bp->b_bcount = lp->d_secsize; CLR(bp->b_flags, B_READ | B_WRITE | B_DONE); SET(bp->b_flags, B_BUSY | B_READ | B_RAW); @@ -272,7 +278,7 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) if ((error = biowait(bp)) != 0) goto done; - dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); + dlp = (struct disklabel *)(bp->b_data + offset); *dlp = *lp; CLR(bp->b_flags, B_READ | B_WRITE | B_DONE); SET(bp->b_flags, B_BUSY | B_WRITE | B_RAW); diff --git a/sys/arch/hppa64/hppa64/disksubr.c b/sys/arch/hppa64/hppa64/disksubr.c index bbf5f3c0863..4acfe93e904 100644 --- a/sys/arch/hppa64/hppa64/disksubr.c +++ b/sys/arch/hppa64/hppa64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.64 2011/04/16 03:21:15 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.65 2011/07/07 22:48:23 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -252,6 +252,7 @@ int writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) { int error = EIO, partoff = -1; + int offset; struct disklabel *dlp; struct buf *bp = NULL; @@ -259,8 +260,14 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; - if (readliflabel(bp, strat, lp, &partoff, 1) != 0 && - readdoslabel(bp, strat, lp, &partoff, 1) != 0) + if (readliflabel(bp, strat, lp, &partoff, 1) == 0) { + bp->b_blkno = partoff + LABELSECTOR; + offset = LABELOFFSET; + } else if (readdoslabel(bp, strat, lp, &partoff, 1) == 0) { + bp->b_blkno = DL_BLKTOSEC(lp, partoff + LABELSECTOR) * + DL_BLKSPERSEC(lp); + offset = DL_BLKOFFSET(lp, partoff + LABELSECTOR) + LABELOFFSET; + } else goto done; /* Read it in, slap the new label in, and write it back out */ @@ -272,7 +279,7 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) if ((error = biowait(bp)) != 0) goto done; - dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); + dlp = (struct disklabel *)(bp->b_data + offset); *dlp = *lp; CLR(bp->b_flags, B_READ | B_WRITE | B_DONE); SET(bp->b_flags, B_BUSY | B_WRITE | B_RAW); diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c index 7de5fe48134..b73a12ccfb3 100644 --- a/sys/arch/macppc/macppc/disksubr.c +++ b/sys/arch/macppc/macppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.72 2011/04/16 03:21:15 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.73 2011/07/07 22:48:23 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -194,6 +194,7 @@ int writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) { int error = EIO, partoff = -1; + int offset; struct disklabel *dlp; struct buf *bp = NULL; @@ -201,12 +202,17 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) bp = geteblk((int)lp->d_secsize); bp->b_dev = dev; - if (readdpmelabel(bp, strat, lp, &partoff, 1) != 0 && - readdoslabel(bp, strat, lp, &partoff, 1) != 0) + if (readdpmelabel(bp, strat, lp, &partoff, 1) == 0) { + bp->b_blkno = partoff + LABELSECTOR; + offset = LABELOFFSET; + } else if (readdoslabel(bp, strat, lp, &partoff, 1) == 0) { + bp->b_blkno = DL_BLKTOSEC(lp, partoff + LABELSECTOR) * + DL_BLKSPERSEC(lp); + offset = DL_BLKOFFSET(lp, partoff + LABELSECTOR) + LABELOFFSET; + } else goto done; /* Read it in, slap the new label in, and write it back out */ - bp->b_blkno = partoff + LABELSECTOR; bp->b_bcount = lp->d_secsize; CLR(bp->b_flags, B_READ | B_WRITE | B_DONE); SET(bp->b_flags, B_BUSY | B_READ | B_RAW); @@ -214,7 +220,7 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) if ((error = biowait(bp)) != 0) goto done; - dlp = (struct disklabel *)(bp->b_data + LABELOFFSET); + dlp = (struct disklabel *)(bp->b_data + offset); *dlp = *lp; CLR(bp->b_flags, B_READ | B_WRITE | B_DONE); SET(bp->b_flags, B_BUSY | B_WRITE | B_RAW); |