From 8e089b93ee6fb19096f734f619c38491435c413e Mon Sep 17 00:00:00 2001 From: deraadt Date: Sat, 5 Apr 1997 21:56:02 +0000 Subject: [PATCH] correct DEV_BSIZE vs lp->d_secsize confusion; spotted by hte late night icb gang. Other ports need fixing still --- sys/arch/arc/arc/disksubr.c | 18 +++++++++--------- sys/arch/i386/i386/disksubr.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sys/arch/arc/arc/disksubr.c b/sys/arch/arc/arc/disksubr.c index 6472fe44dd1..105ba2c8acc 100644 --- a/sys/arch/arc/arc/disksubr.c +++ b/sys/arch/arc/arc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.8 1997/01/24 11:17:12 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.9 1997/04/05 21:56:04 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -412,12 +412,12 @@ bounds_check_with_label(bp, lp, wlabel) { struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); int labelsector = lp->d_partitions[RAW_PART].p_offset + LABELSECTOR; - int sz; + int sz = howmany(bp->b_bcount, DEV_BSIZE); - sz = howmany(bp->b_bcount, lp->d_secsize); +#define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) - if (bp->b_blkno + sz > p->p_size) { - sz = p->p_size - bp->b_blkno; + if (bp->b_blkno + sz > blockpersec(p->p_size, lp)) { + sz = blockpersec(p->p_size, lp) - bp->b_blkno; if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; @@ -433,9 +433,9 @@ bounds_check_with_label(bp, lp, wlabel) } /* Overwriting disk label? */ - if (bp->b_blkno + p->p_offset <= labelsector && + if (bp->b_blkno + blockpersec(p->p_offset, lp) <= labelsector && #if LABELSECTOR != 0 - bp->b_blkno + p->p_offset + sz > labelsector && + bp->b_blkno + blockpersec(p->p_offset, lp) + sz > labelsector && #endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; @@ -443,8 +443,8 @@ bounds_check_with_label(bp, lp, wlabel) } /* calculate cylinder for disksort to order transfers with */ - bp->b_cylin = (bp->b_blkno + p->p_offset) / - (lp->d_secsize / DEV_BSIZE) / lp->d_secpercyl; + bp->b_cylin = (bp->b_blkno + blockpersec(p->p_offset, lp)) / + lp->d_secpercyl; return (1); bad: diff --git a/sys/arch/i386/i386/disksubr.c b/sys/arch/i386/i386/disksubr.c index 9064e1f44be..130a49574da 100644 --- a/sys/arch/i386/i386/disksubr.c +++ b/sys/arch/i386/i386/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.17 1997/01/24 11:17:09 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.18 1997/04/05 21:56:02 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -412,12 +412,12 @@ bounds_check_with_label(bp, lp, wlabel) { struct partition *p = lp->d_partitions + DISKPART(bp->b_dev); int labelsector = lp->d_partitions[RAW_PART].p_offset + LABELSECTOR; - int sz; + int sz = howmany(bp->b_bcount, DEV_BSIZE); - sz = howmany(bp->b_bcount, lp->d_secsize); +#define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) - if (bp->b_blkno + sz > p->p_size) { - sz = p->p_size - bp->b_blkno; + if (bp->b_blkno + sz > blockpersec(p->p_size, lp)) { + sz = blockpersec(p->p_size, lp) - bp->b_blkno; if (sz == 0) { /* If exactly at end of disk, return EOF. */ bp->b_resid = bp->b_bcount; @@ -433,9 +433,9 @@ bounds_check_with_label(bp, lp, wlabel) } /* Overwriting disk label? */ - if (bp->b_blkno + p->p_offset <= labelsector && + if (bp->b_blkno + blockpersec(p->p_offset, lp) <= labelsector && #if LABELSECTOR != 0 - bp->b_blkno + p->p_offset + sz > labelsector && + bp->b_blkno + blockpersec(p->p_offset, lp) + sz > labelsector && #endif (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; @@ -443,8 +443,8 @@ bounds_check_with_label(bp, lp, wlabel) } /* calculate cylinder for disksort to order transfers with */ - bp->b_cylin = (bp->b_blkno + p->p_offset) / - (lp->d_secsize / DEV_BSIZE) / lp->d_secpercyl; + bp->b_cylin = (bp->b_blkno + blockpersec(p->p_offset, lp)) / + lp->d_secpercyl; return (1); bad: -- 2.20.1