summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorchs <chs@NetBSD.org>2000-11-24 00:17:35 +0000
committerchs <chs@NetBSD.org>2000-11-24 00:17:35 +0000
commitf6b62f776cf1871513a488805c16bc29db116dfe (patch)
tree8fb0a2d25b27fb2b719e35f52fa58affb125958d /sys/dev
parent299c5ebbdc8600bbf958c084ca7e8748f0f31ec6 (diff)
avoid division and remainder operations for devices where
the sector size is DEV_BSIZE (ie. practically everything).
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/scsipi/sd.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/sys/dev/scsipi/sd.c b/sys/dev/scsipi/sd.c
index e03b36befd6..0a533fce469 100644
--- a/sys/dev/scsipi/sd.c
+++ b/sys/dev/scsipi/sd.c
@@ -1,4 +1,4 @@
-/* $NetBSD: sd.c,v 1.165 2000/11/22 00:32:24 soren Exp $ */
+/* $NetBSD: sd.c,v 1.166 2000/11/24 00:17:35 chs Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -555,6 +555,7 @@ sdstrategy(bp)
struct disklabel *lp;
daddr_t blkno;
int s;
+ boolean_t sector_aligned;
SC_DEBUG(sd->sc_link, SDEV_DB2, ("sdstrategy "));
SC_DEBUG(sd->sc_link, SDEV_DB1,
@@ -577,8 +578,12 @@ sdstrategy(bp)
* The transfer must be a whole number of blocks, offset must not be
* negative.
*/
- if ((bp->b_bcount % lp->d_secsize) != 0 ||
- bp->b_blkno < 0) {
+ if (lp->d_secsize == DEV_BSIZE) {
+ sector_aligned = (bp->b_bcount & (DEV_BSIZE - 1)) == 0;
+ } else {
+ sector_aligned = (bp->b_bcount % lp->d_secsize) == 0;
+ }
+ if (!sector_aligned || bp->b_blkno < 0) {
bp->b_error = EINVAL;
goto bad;
}
@@ -601,7 +606,9 @@ sdstrategy(bp)
* Now convert the block number to absolute and put it in
* terms of the device's logical block size.
*/
- if (lp->d_secsize >= DEV_BSIZE)
+ if (lp->d_secsize == DEV_BSIZE)
+ blkno = bp->b_blkno;
+ else if (lp->d_secsize > DEV_BSIZE)
blkno = bp->b_blkno / (lp->d_secsize / DEV_BSIZE);
else
blkno = bp->b_blkno * (DEV_BSIZE / lp->d_secsize);
@@ -708,7 +715,10 @@ sdstart(v)
* We have a buf, now we should make a command.
*/
- nblks = howmany(bp->b_bcount, lp->d_secsize);
+ if (lp->d_secsize == DEV_BSIZE)
+ nblks = bp->b_bcount >> DEV_BSHIFT;
+ else
+ nblks = howmany(bp->b_bcount, lp->d_secsize);
#if NSD_SCSIBUS > 0
/*