From: deraadt Date: Mon, 7 Apr 1997 08:59:19 +0000 (+0000) Subject: deal with partition/block size differences X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a91fb0ebab8b44d15e1fadf219838356be8d1010;p=openbsd deal with partition/block size differences --- diff --git a/sys/arch/hp300/hp300/disksubr.c b/sys/arch/hp300/hp300/disksubr.c index d96bdf81ba5..1256d41c6d3 100644 --- a/sys/arch/hp300/hp300/disksubr.c +++ b/sys/arch/hp300/hp300/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.3 1997/01/12 15:13:14 downsj Exp $ */ +/* $OpenBSD: disksubr.c,v 1.4 1997/04/07 08:59:19 deraadt Exp $ */ /* $NetBSD: disksubr.c,v 1.8 1996/02/02 19:50:26 scottr Exp $ */ /* @@ -95,8 +95,12 @@ readdisklabel(dev, strat, lp, osdep) DEV_BSIZE - sizeof(*dlp)); dlp = (struct disklabel *)((char *)dlp + sizeof(long))) { if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { - if (msg == NULL) - msg = "no disk label"; + if (msg == NULL) { +#if defined(CD9660) + if (iso_disklabelspoof(dev, strat, lp) != 0) +#endif + msg = "no disk label"; + } } else if (dlp->d_npartitions > MAXPARTITIONS || dkcksum(dlp) != 0) msg = "disk label corrupted"; @@ -211,39 +215,41 @@ bounds_check_with_label(bp, lp, wlabel) struct disklabel *lp; int wlabel; { +#define blockpersec(count, lp) ((count) * (((lp)->d_secsize) / DEV_BSIZE)) struct partition *p = &lp->d_partitions[DISKPART(bp->b_dev)]; - int labelsect = lp->d_partitions[0].p_offset; - int maxsz = p->p_size; - int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; + int labelsect = blockpersec(lp->d_partitions[0].p_offset, lp) + + LABELSECTOR; + int sz = howmany(bp->b_bcount, DEV_BSIZE); /* Overwriting disk label? */ - if (bp->b_blkno + p->p_offset <= LABELSECTOR + labelsect && + if (bp->b_blkno + blockpersec(p->p_offset, lp) <= labelsect && (bp->b_flags & B_READ) == 0 && !wlabel) { bp->b_error = EROFS; goto bad; } /* beyond partition? */ - if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) { - if (bp->b_blkno == maxsz) { + 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; return (0); } - /* ...or truncate if part of it fits */ - sz = maxsz - bp->b_blkno; - if (sz <= 0) { + if (sz < 0) { bp->b_error = EINVAL; goto bad; } + /* ... or truncate if part of it fits */ bp->b_bcount = sz << DEV_BSHIFT; } /* calculate cylinder for disksort to order transfers with */ - bp->b_resid = (bp->b_blkno + p->p_offset) / lp->d_secpercyl; + bp->b_resid = (bp->b_blkno + blockpersec(p->p_offset, lp)) / + lp->d_secpercyl; return (1); - bad: +bad: bp->b_flags |= B_ERROR; return (-1); }