summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2007-06-09 23:35:24 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2007-06-09 23:35:24 +0000
commitaaa08abf86a1c3b604cc4eb57ef555c0beafd757 (patch)
tree0a7714aae61d05afa52dd3ffb0c26326d8e426a7 /sys
parentbf5598aa66e79a8ff8eafdb8ca244c24338b015a (diff)
blocks/sectors != blocks/blocks. Fix calculation of b_cylinder in
bounds_check_with_label(). Tweak error path to eliminate duplicate code.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/subr_disk.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c
index 2657372d773..f133fbc5bb7 100644
--- a/sys/kern/subr_disk.c
+++ b/sys/kern/subr_disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_disk.c,v 1.57 2007/06/09 23:06:45 krw Exp $ */
+/* $OpenBSD: subr_disk.c,v 1.58 2007/06/09 23:35:23 krw Exp $ */
/* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */
/*
@@ -301,10 +301,8 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp,
int sz = howmany(bp->b_bcount, DEV_BSIZE);
/* avoid division by zero */
- if (lp->d_secpercyl == 0) {
- bp->b_error = EINVAL;
+ if (lp->d_secpercyl == 0)
goto bad;
- }
/* beyond partition? */
if (bp->b_blkno + sz > blockpersec(DL_GETPSIZE(p), lp)) {
@@ -314,21 +312,21 @@ bounds_check_with_label(struct buf *bp, struct disklabel *lp,
bp->b_resid = bp->b_bcount;
return (-1);
}
- if (sz < 0) {
+ if (sz < 0)
/* If past end of disk, return EINVAL. */
- bp->b_error = EINVAL;
goto bad;
- }
+
/* Otherwise, truncate request. */
bp->b_bcount = sz << DEV_BSHIFT;
}
/* calculate cylinder for disksort to order transfers with */
bp->b_cylinder = (bp->b_blkno + blockpersec(DL_GETPOFFSET(p), lp)) /
- lp->d_secpercyl;
+ blockpersec(lp->d_secpercyl, lp);
return (1);
bad:
+ bp->b_error = EINVAL;
bp->b_flags |= B_ERROR;
return (-1);
}