prototyping fixes
[unix-history] / usr / src / sys / ufs / ffs / ufs_disksubr.c
index fe46936..0a4d05c 100644 (file)
@@ -1,39 +1,37 @@
 /*
  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
 /*
  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
  *
  *
- *     @(#)ufs_disksubr.c      7.9 (Berkeley) %G%
+ * %sccs.include.redist.c%
+ *
+ *     @(#)ufs_disksubr.c      7.17 (Berkeley) %G%
  */
 
  */
 
-#include "param.h"
-#include "systm.h"
-#include "buf.h"
-#include "disklabel.h"
-#include "syslog.h"
-
-#include "dir.h"
-#include "user.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/buf.h>
+#include <sys/disklabel.h>
+#include <sys/syslog.h>
 
 /*
 
 /*
- * Seek sort for disks.  We depend on the driver
- * which calls us using b_resid as the current cylinder number.
+ * Seek sort for disks.  We depend on the driver which calls us using b_resid
+ * as the current cylinder number.
  *
  *
- * The argument dp structure holds a b_actf activity chain pointer
- * on which we keep two queues, sorted in ascending cylinder order.
- * The first queue holds those requests which are positioned after
- * the current cylinder (in the first request); the second holds
- * requests which came in after their cylinder number was passed.
- * Thus we implement a one way scan, retracting after reaching the
- * end of the drive to the first request on the second queue,
- * at which time it becomes the first queue.
+ * The argument dp structure holds a b_actf activity chain pointer on which we
+ * keep two queues, sorted in ascending cylinder order.  The first queue holds
+ * those requests which are positioned after the current cylinder (in the first
+ * request); the second holds requests which came in after their cylinder number
+ * was passed.  Thus we implement a one way scan, retracting after reaching the
+ * end of the drive to the first request on the second queue, at which time it
+ * becomes the first queue.
  *
  *
- * A one-way scan is natural because of the way UNIX read-ahead
- * blocks are allocated.
+ * A one-way scan is natural because of the way UNIX read-ahead blocks are
+ * allocated.
  */
 
 #define        b_cylin b_resid
 
  */
 
 #define        b_cylin b_resid
 
+void
 disksort(dp, bp)
        register struct buf *dp, *bp;
 {
 disksort(dp, bp)
        register struct buf *dp, *bp;
 {
@@ -118,12 +116,11 @@ insert:
 }
 
 /*
 }
 
 /*
- * Attempt to read a disk label from a device
- * using the indicated stategy routine.
- * The label must be partly set up before this:
- * secpercyl and anything required in the strategy routine
- * (e.g., sector size) must be filled in before calling us.
- * Returns null on success and an error string on failure.
+ * Attempt to read a disk label from a device using the indicated stategy
+ * routine.  The label must be partly set up before this: secpercyl and
+ * anything required in the strategy routine (e.g., sector size) must be
+ * filled in before calling us.  Returns NULL on success and an error
+ * string on failure.
  */
 char *
 readdisklabel(dev, strat, lp)
  */
 char *
 readdisklabel(dev, strat, lp)
@@ -149,9 +146,7 @@ readdisklabel(dev, strat, lp)
        bp->b_flags = B_BUSY | B_READ;
        bp->b_cylin = LABELSECTOR / lp->d_secpercyl;
        (*strat)(bp);
        bp->b_flags = B_BUSY | B_READ;
        bp->b_cylin = LABELSECTOR / lp->d_secpercyl;
        (*strat)(bp);
-       biowait(bp);
-       if (bp->b_flags & B_ERROR) {
-               u.u_error = 0;          /* XXX */
+       if (biowait(bp)) {
                msg = "I/O error";
        } else for (dlp = (struct disklabel *)bp->b_un.b_addr;
            dlp <= (struct disklabel *)(bp->b_un.b_addr+DEV_BSIZE-sizeof(*dlp));
                msg = "I/O error";
        } else for (dlp = (struct disklabel *)bp->b_un.b_addr;
            dlp <= (struct disklabel *)(bp->b_un.b_addr+DEV_BSIZE-sizeof(*dlp));
@@ -159,7 +154,8 @@ readdisklabel(dev, strat, lp)
                if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
                        if (msg == NULL)
                                msg = "no disk label";
                if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
                        if (msg == NULL)
                                msg = "no disk label";
-               } else if (dkcksum(dlp) != 0)
+               } else if (dlp->d_npartitions > MAXPARTITIONS ||
+                          dkcksum(dlp) != 0)
                        msg = "disk label corrupted";
                else {
                        *lp = *dlp;
                        msg = "disk label corrupted";
                else {
                        *lp = *dlp;
@@ -167,17 +163,15 @@ readdisklabel(dev, strat, lp)
                        break;
                }
        }
                        break;
                }
        }
-       if (lp->d_npartitions > MAXPARTITIONS)
-               lp->d_npartitions = MAXPARTITIONS;
        bp->b_flags = B_INVAL | B_AGE;
        brelse(bp);
        return (msg);
 }
 
 /*
        bp->b_flags = B_INVAL | B_AGE;
        brelse(bp);
        return (msg);
 }
 
 /*
- * Check new disk label for sensibility
- * before setting it.
+ * Check new disk label for sensibility before setting it.
  */
  */
+int
 setdisklabel(olp, nlp, openmask)
        register struct disklabel *olp, *nlp;
        u_long openmask;
 setdisklabel(olp, nlp, openmask)
        register struct disklabel *olp, *nlp;
        u_long openmask;
@@ -222,6 +216,7 @@ setdisklabel(olp, nlp, openmask)
 /*
  * Write disk label back to device after modification.
  */
 /*
  * Write disk label back to device after modification.
  */
+int
 writedisklabel(dev, strat, lp)
        dev_t dev;
        int (*strat)();
 writedisklabel(dev, strat, lp)
        dev_t dev;
        int (*strat)();
@@ -244,12 +239,8 @@ writedisklabel(dev, strat, lp)
        bp->b_bcount = lp->d_secsize;
        bp->b_flags = B_READ;
        (*strat)(bp);
        bp->b_bcount = lp->d_secsize;
        bp->b_flags = B_READ;
        (*strat)(bp);
-       biowait(bp);
-       if (bp->b_flags & B_ERROR) {
-               error = u.u_error;              /* XXX */
-               u.u_error = 0;
+       if (error = biowait(bp))
                goto done;
                goto done;
-       }
        for (dlp = (struct disklabel *)bp->b_un.b_addr;
            dlp <= (struct disklabel *)
              (bp->b_un.b_addr + lp->d_secsize - sizeof(*dlp));
        for (dlp = (struct disklabel *)bp->b_un.b_addr;
            dlp <= (struct disklabel *)
              (bp->b_un.b_addr + lp->d_secsize - sizeof(*dlp));
@@ -259,11 +250,7 @@ writedisklabel(dev, strat, lp)
                        *dlp = *lp;
                        bp->b_flags = B_WRITE;
                        (*strat)(bp);
                        *dlp = *lp;
                        bp->b_flags = B_WRITE;
                        (*strat)(bp);
-                       biowait(bp);
-                       if (bp->b_flags & B_ERROR) {
-                               error = u.u_error;              /* XXX */
-                               u.u_error = 0;
-                       }
+                       error = biowait(bp);
                        goto done;
                }
        }
                        goto done;
                }
        }
@@ -303,6 +290,7 @@ hp0g: hard error reading fsbn 12345 of 12344-12347 (hp0 bn %d cn %d tn %d sn %d)
  * The message should be completed (with at least a newline) with printf
  * or addlog, respectively.  There is no trailing space.
  */
  * The message should be completed (with at least a newline) with printf
  * or addlog, respectively.  There is no trailing space.
  */
+void
 diskerr(bp, dname, what, pri, blkdone, lp)
        register struct buf *bp;
        char *dname, *what;
 diskerr(bp, dname, what, pri, blkdone, lp)
        register struct buf *bp;
        char *dname, *what;
@@ -310,9 +298,9 @@ diskerr(bp, dname, what, pri, blkdone, lp)
        register struct disklabel *lp;
 {
        int unit = dkunit(bp->b_dev), part = dkpart(bp->b_dev);
        register struct disklabel *lp;
 {
        int unit = dkunit(bp->b_dev), part = dkpart(bp->b_dev);
-       register int (*pr)(), sn;
+       register void (*pr) __P((const char *, ...));
        char partname = 'a' + part;
        char partname = 'a' + part;
-       extern printf(), addlog();
+       int sn;
 
        if (pri != LOG_PRINTF) {
                log(pri, "");
 
        if (pri != LOG_PRINTF) {
                log(pri, "");
@@ -332,11 +320,14 @@ diskerr(bp, dname, what, pri, blkdone, lp)
                (*pr)("%d-%d", bp->b_blkno,
                    bp->b_blkno + (bp->b_bcount - 1) / DEV_BSIZE);
        }
                (*pr)("%d-%d", bp->b_blkno,
                    bp->b_blkno + (bp->b_bcount - 1) / DEV_BSIZE);
        }
-       if (lp && (blkdone >= 0 || bp->b_bcount <= DEV_BSIZE)) {
+       if (lp && (blkdone >= 0 || bp->b_bcount <= lp->d_secsize)) {
+#ifdef tahoe
+               sn *= DEV_BSIZE / lp->d_secsize;                /* XXX */
+#endif
                sn += lp->d_partitions[part].p_offset;
                (*pr)(" (%s%d bn %d; cn %d", dname, unit, sn,
                    sn / lp->d_secpercyl);
                sn %= lp->d_secpercyl;
                sn += lp->d_partitions[part].p_offset;
                (*pr)(" (%s%d bn %d; cn %d", dname, unit, sn,
                    sn / lp->d_secpercyl);
                sn %= lp->d_secpercyl;
-               (*pr)(" tn %d sn %d)", sn / lp->d_ntracks, sn % lp->d_ntracks);
+               (*pr)(" tn %d sn %d)", sn / lp->d_nsectors, sn % lp->d_nsectors);
        }
 }
        }
 }