From 28c56349127280da6038c73affaaeafbbeaa6a39 Mon Sep 17 00:00:00 2001 From: jonathan Date: Fri, 4 Aug 1995 02:34:24 +0000 Subject: [PATCH] Add dk_establish() and bounds_check_with_label(), from the alpha port, for the machine-independent SCSI driver. Untested. Only print diagnostics about reading Ultrix labels when DIAGNOSTIC is defined. --- sys/arch/pmax/pmax/disksubr.c | 73 +++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/sys/arch/pmax/pmax/disksubr.c b/sys/arch/pmax/pmax/disksubr.c index d5eff63a948d..0db5dc476a4c 100644 --- a/sys/arch/pmax/pmax/disksubr.c +++ b/sys/arch/pmax/pmax/disksubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: disksubr.c,v 1.5 1995/07/14 01:05:22 jonathan Exp $ */ +/* $NetBSD: disksubr.c,v 1.6 1995/08/04 02:34:24 jonathan Exp $ */ /* * Copyright (c) 1982, 1986, 1988 Regents of the University of California. @@ -149,7 +149,9 @@ compat_label(dev, strat, lp, osdep) goto done; } -/*XXX*/ printf("Ultrix label loop\n"); +#ifdef DIAGNOSTIC +/*XXX*/ printf("Interpreting Ultrix label\n"); +#endif lp->d_magic = DEC_LABEL_MAGIC; lp->d_npartitions = 0; @@ -164,7 +166,7 @@ compat_label(dev, strat, lp, osdep) (part==1) ? FS_SWAP : FS_BSDFFS; lp->d_npartitions += 1; -#ifdef DEBUG +#ifdef DIAGNOSTIC printf(" Ultrix label rz%d%c: start %d len %d\n", DISKUNIT(dev), "abcdefgh"[part], lp->d_partitions[part].p_offset, @@ -274,3 +276,68 @@ done: brelse(bp); return (error); } + + +/* + * was this the boot device ? + */ +int +dk_establish(dk, dev) + struct dkdevice *dk; + struct device *dev; +{ + /* see also arch/alpha/alpha/disksubr.c */ + printf("Warning: boot path unknown\n"); + return 1; +} + +/* + * UNTESTED !! + * + * Determine the size of the transfer, and make sure it is + * within the boundaries of the partition. Adjust transfer + * if needed, and signal errors or early completion. + */ +int +bounds_check_with_label(bp, lp, wlabel) + struct buf *bp; + struct disklabel *lp; + int wlabel; +{ + + struct partition *p = lp->d_partitions + dkpart(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; + + /* overwriting disk label ? */ + /* XXX should also protect bootstrap in first 8K */ + if (bp->b_blkno + p->p_offset <= LABELSECTOR + labelsect && + (bp->b_flags & B_READ) == 0 && wlabel == 0) { + bp->b_error = EROFS; + goto bad; + } + + /* 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) { + bp->b_resid = bp->b_bcount; + return(0); + } + /* or truncate if part of it fits */ + sz = maxsz - bp->b_blkno; + if (sz <= 0) { + bp->b_error = EINVAL; + goto bad; + } + 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; + return(1); +bad: + bp->b_flags |= B_ERROR; + return(-1); +}