diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-09-15 14:35:51 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2013-09-15 14:35:51 +0000 |
commit | 630d76730e9e3d493098c30f2205e19e49895d17 (patch) | |
tree | 3bce14b524559e6423f97cff6f8c611e7f7842dc | |
parent | 7f7d775155b9933eeb3b036d749137be5a37a556 (diff) |
Use DL_SECTOBLK() and DL_BLKTOSEC() to clarify code and remove
repeated handrolling of same code. Use daddr_t variable to
calculate daddr_t return values, and u_int64_t variables to
calculate disk sector values.
No functional change.
-rw-r--r-- | sys/scsi/cd.c | 7 | ||||
-rw-r--r-- | sys/scsi/sd.c | 15 |
2 files changed, 12 insertions, 10 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index cce3860a9b2..e793cffb272 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.c,v 1.208 2013/06/11 16:42:17 deraadt Exp $ */ +/* $OpenBSD: cd.c,v 1.209 2013/09/15 14:35:50 krw Exp $ */ /* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */ /* @@ -518,7 +518,7 @@ cdstart(struct scsi_xfer *xs) struct buf *bp; struct scsi_rw_big *cmd_big; struct scsi_rw *cmd_small; - int secno, nsecs; + u_int64_t secno, nsecs; struct partition *p; int read; @@ -552,8 +552,7 @@ cdstart(struct scsi_xfer *xs) * First, translate the block to absolute and put it in terms * of the logical blocksize of the device. */ - secno = - bp->b_blkno / (sc->sc_dk.dk_label->d_secsize / DEV_BSIZE); + secno = DL_BLKTOSEC(sc->sc_dk.dk_label, bp->b_blkno); p = &sc->sc_dk.dk_label->d_partitions[DISKPART(bp->b_dev)]; secno += DL_GETPOFFSET(p); nsecs = howmany(bp->b_bcount, sc->sc_dk.dk_label->d_secsize); diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index d144aa71758..96c55de359c 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.246 2013/06/11 16:42:17 deraadt Exp $ */ +/* $OpenBSD: sd.c,v 1.247 2013/09/15 14:35:50 krw Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /*- @@ -658,7 +658,8 @@ sdstart(struct scsi_xfer *xs) return; } - secno = bp->b_blkno / (sc->sc_dk.dk_label->d_secsize / DEV_BSIZE); + secno = DL_BLKTOSEC(sc->sc_dk.dk_label, bp->b_blkno); + p = &sc->sc_dk.dk_label->d_partitions[DISKPART(bp->b_dev)]; secno += DL_GETPOFFSET(p); nsecs = howmany(bp->b_bcount, sc->sc_dk.dk_label->d_secsize); @@ -1195,9 +1196,10 @@ sd_interpret_sense(struct scsi_xfer *xs) daddr_t sdsize(dev_t dev) { + struct disklabel *lp; struct sd_softc *sc; int part, omask; - int64_t size; + daddr_t size; sc = sdlookup(DISKUNIT(dev)); if (sc == NULL) @@ -1214,13 +1216,14 @@ sdsize(dev_t dev) size = -1; goto exit; } + + lp = sc->sc_dk.dk_label; if ((sc->sc_link->flags & SDEV_MEDIA_LOADED) == 0) size = -1; - else if (sc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) + else if (lp->d_partitions[part].p_fstype != FS_SWAP) size = -1; else - size = DL_GETPSIZE(&sc->sc_dk.dk_label->d_partitions[part]) * - (sc->sc_dk.dk_label->d_secsize / DEV_BSIZE); + size = DL_SECTOBLK(lp, DL_GETPSIZE(&lp->d_partitions[part])); if (omask == 0 && sdclose(dev, 0, S_IFBLK, NULL) != 0) size = -1; |