From 60581c90034a2637864b89a076ed3e70be167036 Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 8 Apr 1997 09:02:15 +0000 Subject: [PATCH] attempt cd9660 & part/nblks fix --- sys/arch/vax/vax/disksubr.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/sys/arch/vax/vax/disksubr.c b/sys/arch/vax/vax/disksubr.c index ecb1b062272..26ca3a9049a 100644 --- a/sys/arch/vax/vax/disksubr.c +++ b/sys/arch/vax/vax/disksubr.c @@ -70,14 +70,16 @@ 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[2].p_offset; - int maxsz = p->p_size, - sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; + int labelsect = blockpersec(lp->d_partitions[2].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 + p->p_offset <= labelsect && #if LABELSECTOR != 0 - bp->b_blkno + p->p_offset + sz > LABELSECTOR + labelsect && + bp->b_blkno + p->p_offset + sz > labelsect && #endif (bp->b_flags & B_READ) == 0 && wlabel == 0) { bp->b_error = EROFS; @@ -85,23 +87,24 @@ bounds_check_with_label(bp, lp, wlabel) } /* beyond partition? */ - if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) { - /* if exactly at end of disk, return an EOF */ - 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 an 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_cylin = (bp->b_blkno + p->p_offset) / lp->d_secpercyl; + bp->b_cylin = (bp->b_blkno + blockpersec(p->p_offset, lp)) / + lp->d_secpercyl; return(1); bad: @@ -178,8 +181,12 @@ readdisklabel(dev, strat, lp, osdep) dlp <= (struct disklabel *)(bp->b_un.b_addr+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"; -- 2.20.1