diff options
author | 2007-06-09 23:35:23 +0000 | |
---|---|---|
committer | 2007-06-09 23:35:23 +0000 | |
commit | c109476c1da5254aeb646dcade67b8a8366f8267 (patch) | |
tree | 52079c03b3c4578ef62085f3171dc481277d2221 /sys/kern/subr_disk.c | |
parent | The differences in the last non-homogeneous bounds_check_with_label() (diff) | |
download | wireguard-openbsd-c109476c1da5254aeb646dcade67b8a8366f8267.tar.xz wireguard-openbsd-c109476c1da5254aeb646dcade67b8a8366f8267.zip |
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/kern/subr_disk.c')
-rw-r--r-- | sys/kern/subr_disk.c | 14 |
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); } |