Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/mac68k/mac68k Fix a problem with bounds_check_with_...



details:   https://anonhg.NetBSD.org/src/rev/36009cae6e6d
branches:  trunk
changeset: 472536:36009cae6e6d
user:      scottr <scottr%NetBSD.org@localhost>
date:      Sat May 01 09:26:32 1999 +0000

description:
Fix a problem with bounds_check_with_label(), noted by Greg Oster:  we
had been returning (-1) as an error instead of 0.  This is the result of
not keeping up with its i386 ancestor, which it was originally derived
from back in 1993.  Re-sync.

diffstat:

 sys/arch/mac68k/mac68k/disksubr.c |  66 +++++++++++++++++---------------------
 1 files changed, 30 insertions(+), 36 deletions(-)

diffs (94 lines):

diff -r 0ad4188b3467 -r 36009cae6e6d sys/arch/mac68k/mac68k/disksubr.c
--- a/sys/arch/mac68k/mac68k/disksubr.c Sat May 01 09:12:47 1999 +0000
+++ b/sys/arch/mac68k/mac68k/disksubr.c Sat May 01 09:26:32 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disksubr.c,v 1.31 1999/05/01 09:12:47 scottr Exp $     */
+/*     $NetBSD: disksubr.c,v 1.32 1999/05/01 09:26:32 scottr Exp $     */
 
 /*
  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
@@ -581,55 +581,49 @@
 {
        struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
 #if 0
-       int labelsect = lp->d_partitions[0].p_offset;
+       int labelsector = lp->d_partitions[2].p_offset + LABELSECTOR;
 #endif
-       int maxsz = p->p_size;
-       int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
+       int sz;
+
+       sz = howmany(bp->b_bcount, lp->d_secsize);
 
-       /* overwriting disk label ? */
-       /* XXX should also protect bootstrap in first 8K */
-#if 0                          /* MF this is crap, especially on swap !! */
-       if (bp->b_blkno + p->p_offset <= LABELSECTOR + labelsect &&
+       if (bp->b_blkno + sz > p->p_size) {
+               sz = p->p_size - bp->b_blkno;
+               if (sz == 0) {
+                       /* If exactly at end of disk, return EOF. */
+                       bp->b_resid = bp->b_bcount;
+                       goto done;
+               }
+               if (sz < 0) {
+                       /* If past end of disk, return EINVAL. */
+                       bp->b_error = EINVAL;
+                       goto bad;
+               }
+               /* Otherwise, truncate request. */
+               bp->b_bcount = sz << DEV_BSHIFT;
+       }
+
+#if 0
+       /* Overwriting disk label? */
+       if (bp->b_blkno + p->p_offset <= labelsector &&
 #if LABELSECTOR != 0
-           bp->b_blkno + p->p_offset + sz > LABELSECTOR + labelsect &&
+           bp->b_blkno + p->p_offset + sz > labelsector &&
 #endif
-           (bp->b_flags & B_READ) == 0 && wlabel == 0) {
+           (bp->b_flags & B_READ) == 0 && !wlabel) {
                bp->b_error = EROFS;
                goto bad;
        }
 #endif
 
-#if defined(MBR_BBSECTOR) && defined(notyet)
-       /* overwriting master boot record? */
-       if (bp->b_blkno + p->p_offset <= MBR_BBSECTOR &&
-           (bp->b_flags & B_READ) == 0 && wlabel == 0) {
-               bp->b_error = EROFS;
-               goto bad;
-       }
-#endif
-
-       /* 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_cylin = (bp->b_blkno + p->p_offset) / lp->d_secpercyl;
+       bp->b_cylin = (bp->b_blkno + p->p_offset) /
+           (lp->d_secsize / DEV_BSIZE) / lp->d_secpercyl;
        return (1);
 
 bad:
        bp->b_flags |= B_ERROR;
-       return (-1);
+done:
+       return (0);
 }
 
 void



Home | Main Index | Thread Index | Old Index