Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/sgimips/sgimips Forgot to commit bounds_check_with_...



details:   https://anonhg.NetBSD.org/src/rev/b2f03902d0e7
branches:  trunk
changeset: 499693:b2f03902d0e7
user:      soren <soren%NetBSD.org@localhost>
date:      Mon Nov 27 06:00:09 2000 +0000

description:
Forgot to commit bounds_check_with_label().

diffstat:

 sys/arch/sgimips/sgimips/disksubr.c |  55 ++++++++++++++++++++++++++++++++----
 1 files changed, 49 insertions(+), 6 deletions(-)

diffs (69 lines):

diff -r a84211e92179 -r b2f03902d0e7 sys/arch/sgimips/sgimips/disksubr.c
--- a/sys/arch/sgimips/sgimips/disksubr.c       Mon Nov 27 05:57:25 2000 +0000
+++ b/sys/arch/sgimips/sgimips/disksubr.c       Mon Nov 27 06:00:09 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disksubr.c,v 1.2 2000/11/20 08:24:21 chs Exp $ */
+/*     $NetBSD: disksubr.c,v 1.3 2000/11/27 06:00:09 soren Exp $       */
 
 /*
  * Copyright (c) 2000 Soren S. Jorvang
@@ -157,11 +157,54 @@
        return ENODEV;
 }
 
-int      
-bounds_check_with_label(bp, lp, wlabel) 
+
+/*
+ * 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; 
-{               
-       return 1;
+       int wlabel;
+{
+       struct partition *p = lp->d_partitions + DISKPART(bp->b_dev);
+       int maxsz = p->p_size;
+       int sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT;
+
+       /*
+        * Overwriting disk label?
+        * The label is always in sector LABELSECTOR.
+        */
+       if (bp->b_blkno + p->p_offset <= LABELSECTOR &&
+           (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);
 }



Home | Main Index | Thread Index | Old Index