checkpoint
[unix-history] / usr / src / sbin / icheck / icheck.c
index 368cc2e..203fcca 100644 (file)
@@ -1,4 +1,19 @@
-static char *sccsid = "@(#)icheck.c    1.14 (Berkeley) %G%";
+/*-
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.proprietary.c%
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1988 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)icheck.c   5.10 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * icheck
 
 /*
  * icheck
@@ -7,16 +22,17 @@ static       char *sccsid = "@(#)icheck.c    1.14 (Berkeley) %G%";
 #define        MAXFN   500
 #define        MAXNINDIR       (MAXBSIZE / sizeof (daddr_t))
 
 #define        MAXFN   500
 #define        MAXNINDIR       (MAXBSIZE / sizeof (daddr_t))
 
+#include <sys/param.h>
+#include <sys/time.h>
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
 #ifndef STANDALONE
 #include <stdio.h>
 #endif
 #ifndef STANDALONE
 #include <stdio.h>
 #endif
-#include "../h/param.h"
-#include "../h/inode.h"
-#include "../h/fs.h"
 
 union {
        struct  fs sb;
 
 union {
        struct  fs sb;
-       char pad[MAXBSIZE];
+       char pad[SBSIZE];
 } sbun;
 #define        sblock sbun.sb
 
 } sbun;
 #define        sblock sbun.sb
 
@@ -26,12 +42,13 @@ union {
 } cgun;
 #define        cgrp cgun.cg
 
 } cgun;
 #define        cgrp cgun.cg
 
-struct dinode  itab[MAXIPG];
+struct dinode itab[MAXBSIZE / sizeof(struct dinode)];
+
 daddr_t        blist[NB];
 daddr_t        blist[NB];
+daddr_t        fsblist[NB];
 char   *bmap;
 
 int    mflg;
 char   *bmap;
 
 int    mflg;
-int    sflg;
 int    dflg;
 int    fi;
 ino_t  ino;
 int    dflg;
 int    fi;
 ino_t  ino;
@@ -41,7 +58,8 @@ ino_t nrfile;
 ino_t  ndfile;
 ino_t  nbfile;
 ino_t  ncfile;
 ino_t  ndfile;
 ino_t  nbfile;
 ino_t  ncfile;
-ino_t  nmcfile;
+ino_t  nlfile;
+ino_t  nsfile;
 
 daddr_t        nblock;
 daddr_t        nfrag;
 
 daddr_t        nblock;
 daddr_t        nfrag;
@@ -54,9 +72,7 @@ daddr_t       nbfree;
 daddr_t        ndup;
 
 int    nerror;
 daddr_t        ndup;
 
 int    nerror;
-
-extern int inside[], around[];
-extern unsigned char *fragtbl[];
+long   dev_bsize = 1;
 
 long   atol();
 #ifndef STANDALONE
 
 long   atol();
 #ifndef STANDALONE
@@ -85,12 +101,8 @@ main(argc, argv)
                        mflg++;
                        continue;
 
                        mflg++;
                        continue;
 
-               case 's':
-                       sflg++;
-                       continue;
-
                case 'b':
                case 'b':
-                       for(i=0; i<NB; i++) {
+                       for(i=0; i<NB && argc >= 2; i++) {
                                n = atol(argv[1]);
                                if(n == 0)
                                        break;
                                n = atol(argv[1]);
                                if(n == 0)
                                        break;
@@ -124,8 +136,9 @@ check(file)
        register i, j, c;
        daddr_t d, cgd, cbase, b;
        long n;
        register i, j, c;
        daddr_t d, cgd, cbase, b;
        long n;
+       char buf[BUFSIZ];
 
 
-       fi = open(file, sflg ? 2 : 0);
+       fi = open(file, 0);
        if (fi < 0) {
                perror(file);
                nerror |= 04;
        if (fi < 0) {
                perror(file);
                nerror |= 04;
@@ -136,7 +149,8 @@ check(file)
        ndfile = 0;
        ncfile = 0;
        nbfile = 0;
        ndfile = 0;
        ncfile = 0;
        nbfile = 0;
-       nmcfile = 0;
+       nlfile = 0;
+       nsfile = 0;
 
        nblock = 0;
        nfrag = 0;
 
        nblock = 0;
        nfrag = 0;
@@ -150,6 +164,8 @@ check(file)
        getsb(&sblock, file);
        if (nerror)
                return;
        getsb(&sblock, file);
        if (nerror)
                return;
+       for (n=0; blist[n] != -1; n++)
+               fsblist[n] = dbtofsb(&sblock, blist[n]);
        ino = 0;
        n = roundup(howmany(sblock.fs_size, NBBY), sizeof(short));
 #ifdef STANDALONE
        ino = 0;
        n = roundup(howmany(sblock.fs_size, NBBY), sizeof(short));
 #ifdef STANDALONE
@@ -160,73 +176,76 @@ check(file)
        if (bmap==NULL) {
                printf("Not enough core; duplicates unchecked\n");
                dflg++;
        if (bmap==NULL) {
                printf("Not enough core; duplicates unchecked\n");
                dflg++;
-               if (sflg) {
-                       printf("No Updates\n");
-                       sflg = 0;
-               }
        }
        ino = 0;
        cginit = 1;
        }
        ino = 0;
        cginit = 1;
-       if(!dflg) {
-               for (i=0; i<(unsigned)n; i++)
+       if (!dflg) {
+               for (i = 0; i < (unsigned)n; i++)
                        bmap[i] = 0;
                        bmap[i] = 0;
-               for (c=0; c < sblock.fs_ncg; c++) {
-                       cgd = cgtod(c, &sblock);
-                       for (d = cgbase(c, &sblock); d < cgd; d += sblock.fs_frag)
-                               chk(d, "badcg", sblock.fs_bsize);
-                       d = cgimin(c, &sblock);
+               for (c = 0; c < sblock.fs_ncg; c++) {
+                       cgd = cgtod(&sblock, c);
+                       if (c == 0)
+                               d = cgbase(&sblock, c);
+                       else
+                               d = cgsblock(&sblock, c);
+                       (void)sprintf(buf, "spare super block %d", c);
+                       for (; d < cgd; d += sblock.fs_frag)
+                               chk(d, buf, sblock.fs_bsize);
+                       d = cgimin(&sblock, c);
+                       (void)sprintf(buf, "cylinder group %d", c);
                        while (cgd < d) {
                        while (cgd < d) {
-                               chk(cgd, "cg", sblock.fs_bsize);
+                               chk(cgd, buf, sblock.fs_bsize);
                                cgd += sblock.fs_frag;
                        }
                                cgd += sblock.fs_frag;
                        }
-                       d = cgdmin(c, &sblock);
-                       for (; cgd < d; cgd += sblock.fs_frag)
-                               chk(cgd, "inode", sblock.fs_bsize);
+                       d = cgdmin(&sblock, c);
+                       i = INOPB(&sblock);
+                       for (; cgd < d; cgd += sblock.fs_frag) {
+                               (void)sprintf(buf, "inodes %d-%d", ino, ino + i);
+                               chk(cgd, buf, sblock.fs_bsize);
+                               ino += i;
+                       }
                        if (c == 0) {
                        if (c == 0) {
-                               d += howmany(sblock.fs_cssize, sblock.fs_bsize)
-                                   * sblock.fs_frag;
-                               for (; cgd < d; cgd += sblock.fs_frag)
-                                       chk(cgd, "csum", sblock.fs_bsize);
+                               d += howmany(sblock.fs_cssize, sblock.fs_fsize);
+                               for (; cgd < d; cgd++)
+                                       chk(cgd, "csum", sblock.fs_fsize);
                        }
                }
        }
                        }
                }
        }
+       ino = 0;
        cginit = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
        cginit = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
-               bread(fsbtodb(&sblock, cgimin(c,&sblock)), (char *)itab,
-                   sblock.fs_ipg * sizeof (struct dinode));
-               for (j=0; j < sblock.fs_ipg; j++) {
-                       pass1(&itab[j]);
-                       ino++;
+               for (i = 0;
+                    i < sblock.fs_ipg / INOPF(&sblock);
+                    i += sblock.fs_frag) {
+                       bread(fsbtodb(&sblock, cgimin(&sblock, c) + i),
+                           (char *)itab, sblock.fs_bsize);
+                       for (j = 0; j < INOPB(&sblock); j++) {
+                               pass1(&itab[j]);
+                               ino++;
+                       }
                }
        }
        ino = 0;
 #ifndef STANDALONE
        sync();
 #endif
                }
        }
        ino = 0;
 #ifndef STANDALONE
        sync();
 #endif
-       if (sflg) {
-               makecg();
-               close(fi);
-#ifndef STANDALONE
-               if (bmap)
-                       free(bmap);
-#endif
-               return;
-       }
        nffree = 0;
        nbfree = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
        nffree = 0;
        nbfree = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
-               cbase = cgbase(c,&sblock);
-               bread(fsbtodb(&sblock, cgtod(c,&sblock)), (char *)&cgrp,
+               cbase = cgbase(&sblock, c);
+               bread(fsbtodb(&sblock, cgtod(&sblock, c)), (char *)&cgrp,
                        sblock.fs_cgsize);
                        sblock.fs_cgsize);
+               if (!cg_chkmagic(&cgrp))
+                       printf("cg %d: bad magic number\n", c);
                for (b = 0; b < sblock.fs_fpg; b += sblock.fs_frag) {
                for (b = 0; b < sblock.fs_fpg; b += sblock.fs_frag) {
-                       if (isblock(&sblock, cgrp.cg_free,
+                       if (isblock(&sblock, cg_blksfree(&cgrp),
                            b / sblock.fs_frag)) {
                                nbfree++;
                            b / sblock.fs_frag)) {
                                nbfree++;
-                               chk(cbase+b, "block", sblock.fs_bsize);
+                               chk(cbase+b, "free block", sblock.fs_bsize);
                        } else {
                                for (d = 0; d < sblock.fs_frag; d++)
                        } else {
                                for (d = 0; d < sblock.fs_frag; d++)
-                                       if (isset(cgrp.cg_free, b+d)) {
-                                               chk(cbase+b+d, "frag", sblock.fs_fsize);
+                                       if (isset(cg_blksfree(&cgrp), b+d)) {
+                                               chk(cbase+b+d, "free frag", sblock.fs_fsize);
                                                nffree++;
                                        }
                        }
                                                nffree++;
                                        }
                        }
@@ -238,13 +257,13 @@ check(file)
                free(bmap);
 #endif
 
                free(bmap);
 #endif
 
-       i = nrfile + ndfile + ncfile + nbfile + nmcfile;
+       i = nrfile + ndfile + ncfile + nbfile + nlfile + nsfile;
 #ifndef STANDALONE
 #ifndef STANDALONE
-       printf("files %6u (r=%u,d=%u,b=%u,c=%u,mc=%u)\n",
-               i, nrfile, ndfile, nbfile, ncfile, nmcfile);
+       printf("files %6u (r=%u,d=%u,b=%u,c=%u,sl=%u,sock=%u)\n",
+               i, nrfile, ndfile, nbfile, ncfile, nlfile, nsfile);
 #else
 #else
-       printf("files %u (r=%u,d=%u,b=%u,c=%u,mc=%u)\n",
-               i, nrfile, ndfile, nbfile, ncfile, nmcfile);
+       printf("files %u (r=%u,d=%u,b=%u,c=%u,sl=%u,sock=%u)\n",
+               i, nrfile, ndfile, nbfile, ncfile, nlfile, nsfile);
 #endif
        n = (nblock + nindir + niindir) * sblock.fs_frag + nfrag;
 #ifdef STANDALONE
 #endif
        n = (nblock + nindir + niindir) * sblock.fs_frag + nfrag;
 #ifdef STANDALONE
@@ -277,6 +296,8 @@ pass1(ip)
        daddr_t ind2[MAXNINDIR];
        daddr_t db, ib;
        register int i, j, k, siz;
        daddr_t ind2[MAXNINDIR];
        daddr_t db, ib;
        register int i, j, k, siz;
+       int lbn;
+       char buf[BUFSIZ];
 
        i = ip->di_mode & IFMT;
        if(i == 0)
 
        i = ip->di_mode & IFMT;
        if(i == 0)
@@ -294,6 +315,12 @@ pass1(ip)
        case IFREG:
                nrfile++;
                break;
        case IFREG:
                nrfile++;
                break;
+       case IFSOCK:
+               nsfile++;
+               break;
+       case IFLNK:
+               nlfile++;
+               break;
        default:
                printf("bad mode %u\n", ino);
                return;
        default:
                printf("bad mode %u\n", ino);
                return;
@@ -303,7 +330,8 @@ pass1(ip)
                if (db == 0)
                        continue;
                siz = dblksize(&sblock, ip, i);
                if (db == 0)
                        continue;
                siz = dblksize(&sblock, ip, i);
-               chk(db, "data (block)", siz);
+               (void)sprintf(buf, "logical data block %d", i);
+               chk(db, buf, siz);
                if (siz == sblock.fs_bsize)
                        nblock++;
                else
                if (siz == sblock.fs_bsize)
                        nblock++;
                else
@@ -311,7 +339,7 @@ pass1(ip)
        }
        for(i = 0; i < NIADDR; i++) {
                ib = ip->di_ib[i];
        }
        for(i = 0; i < NIADDR; i++) {
                ib = ip->di_ib[i];
-               if(ib == 0)
+               if (ib == 0)
                        continue;
                if (chk(ib, "1st indirect", sblock.fs_bsize))
                        continue;
                        continue;
                if (chk(ib, "1st indirect", sblock.fs_bsize))
                        continue;
@@ -322,8 +350,10 @@ pass1(ip)
                        if (ib == 0)
                                continue;
                        if (i == 0) {
                        if (ib == 0)
                                continue;
                        if (i == 0) {
-                               siz = dblksize(&sblock, ip, NDADDR + j);
-                               chk(ib, "data (large)", siz);
+                               lbn = NDADDR + j;
+                               siz = dblksize(&sblock, ip, lbn);
+                               (void)sprintf(buf, "logical data block %d", lbn);
+                               chk(ib, buf, siz);
                                if (siz == sblock.fs_bsize)
                                        nblock++;
                                else
                                if (siz == sblock.fs_bsize)
                                        nblock++;
                                else
@@ -339,9 +369,10 @@ pass1(ip)
                                ib = ind2[k];
                                if (ib == 0)
                                        continue;
                                ib = ind2[k];
                                if (ib == 0)
                                        continue;
-                               siz = dblksize(&sblock, ip,
-                                   NDADDR + NINDIR(&sblock) * (i + j) + k);
-                               chk(ib, "data (huge)", siz);
+                               lbn = NDADDR + NINDIR(&sblock) * (i + j) + k;
+                               siz = dblksize(&sblock, ip, lbn);
+                               (void)sprintf(buf, "logical data block %d", lbn);
+                               chk(ib, buf, siz);
                                if (siz == sblock.fs_bsize)
                                        nblock++;
                                else
                                if (siz == sblock.fs_bsize)
                                        nblock++;
                                else
@@ -357,21 +388,22 @@ chk(bno, s, size)
        int size;
 {
        register n, cg;
        int size;
 {
        register n, cg;
+       int frags;
 
 
-       cg = dtog(bno, &sblock);
-       if (cginit==0 &&
-           bno<cgdmin(cg,&sblock) || bno >= sblock.fs_frag * sblock.fs_size) {
+       cg = dtog(&sblock, bno);
+       if (cginit == 0 && bno >= sblock.fs_frag * sblock.fs_size) {
                printf("%ld bad; inode=%u, class=%s\n", bno, ino, s);
                return(1);
        }
                printf("%ld bad; inode=%u, class=%s\n", bno, ino, s);
                return(1);
        }
-       if (size == sblock.fs_bsize) {
+       frags = numfrags(&sblock, size);
+       if (frags == sblock.fs_frag) {
                if (duped(bno, size)) {
                        printf("%ld dup block; inode=%u, class=%s\n",
                            bno, ino, s);
                        ndup += sblock.fs_frag;
                }
        } else {
                if (duped(bno, size)) {
                        printf("%ld dup block; inode=%u, class=%s\n",
                            bno, ino, s);
                        ndup += sblock.fs_frag;
                }
        } else {
-               for (n = 0; n < size / sblock.fs_fsize; n++) {
+               for (n = 0; n < frags; n++) {
                        if (duped(bno + n, sblock.fs_fsize)) {
                                printf("%ld dup frag; inode=%u, class=%s\n",
                                    bno, ino, s);
                        if (duped(bno + n, sblock.fs_fsize)) {
                                printf("%ld dup frag; inode=%u, class=%s\n",
                                    bno, ino, s);
@@ -380,8 +412,9 @@ chk(bno, s, size)
                }
        }
        for (n=0; blist[n] != -1; n++)
                }
        }
        for (n=0; blist[n] != -1; n++)
-               if (bno == blist[n])
-                       printf("%ld arg; inode=%u, class=%s\n", bno, ino, s);
+               if (fsblist[n] >= bno && fsblist[n] < bno + frags)
+                       printf("%ld arg; frag %d of %d, inode=%u, class=%s\n",
+                               blist[n], fsblist[n] - bno, frags, ino, s);
        return(0);
 }
 
        return(0);
 }
 
@@ -407,169 +440,13 @@ duped(bno, size)
        return(0);
 }
 
        return(0);
 }
 
-makecg()
-{
-       int c, blk;
-       daddr_t dbase, d, dmin, dmax;
-       long i, j, s;
-       register struct csum *cs;
-       register struct dinode *dp;
-
-       sblock.fs_cstotal.cs_nbfree = 0;
-       sblock.fs_cstotal.cs_nffree = 0;
-       sblock.fs_cstotal.cs_nifree = 0;
-       sblock.fs_cstotal.cs_ndir = 0;
-       for (c = 0; c < sblock.fs_ncg; c++) {
-               dbase = cgbase(c, &sblock);
-               dmax = dbase + sblock.fs_fpg;
-               if (dmax > sblock.fs_size)
-                       dmax = sblock.fs_size;
-               dmin = cgdmin(c, &sblock) - dbase;
-               cs = &sblock.fs_cs(&sblock, c);
-               cgrp.cg_time = time(0);
-               cgrp.cg_magic = CG_MAGIC;
-               cgrp.cg_cgx = c;
-               cgrp.cg_ncyl = sblock.fs_cpg;
-               cgrp.cg_niblk = sblock.fs_ipg;
-               cgrp.cg_ndblk = dmax - dbase;
-               cgrp.cg_cs.cs_ndir = 0;
-               cgrp.cg_cs.cs_nffree = 0;
-               cgrp.cg_cs.cs_nbfree = 0;
-               cgrp.cg_cs.cs_nifree = 0;
-               cgrp.cg_rotor = dmin;
-               cgrp.cg_frotor = dmin;
-               cgrp.cg_irotor = 0;
-               for (i = 0; i < sblock.fs_frag; i++)
-                       cgrp.cg_frsum[i] = 0;
-               bread(fsbtodb(&sblock, cgimin(c, &sblock)), (char *)itab,
-                     sblock.fs_ipg * sizeof(struct dinode));
-               for (i = 0; i < sblock.fs_ipg; i++) {
-                       dp = &itab[i];
-                       if (dp == NULL)
-                               continue;
-                       if ((dp->di_mode & IFMT) != 0) {
-                               if ((dp->di_mode & IFMT) == IFDIR)
-                                       cgrp.cg_cs.cs_ndir++;
-                               setbit(cgrp.cg_iused, i);
-                               continue;
-                       }
-                       cgrp.cg_cs.cs_nifree++;
-                       clrbit(cgrp.cg_iused, i);
-               }
-               while (i < MAXIPG) {
-                       clrbit(cgrp.cg_iused, i);
-                       i++;
-               }
-               if (c == 0)
-                       for (i = 0; i < ROOTINO; i++) {
-                               setbit(cgrp.cg_iused, i);
-                               cgrp.cg_cs.cs_nifree--;
-                       }
-               for (s = 0; s < MAXCPG; s++) {
-                       cgrp.cg_btot[s] = 0;
-                       for (i = 0; i < NRPOS; i++)
-                               cgrp.cg_b[s][i] = 0;
-               }
-               if (c == 0) {
-                       dmin += howmany(sblock.fs_cssize, sblock.fs_bsize) *
-                           sblock.fs_frag;
-               }
-               for (d = 0; d < dmin; d++)
-                       clrbit(cgrp.cg_free, d);
-               for (; (d + sblock.fs_frag) <= dmax - dbase; d += sblock.fs_frag) {
-                       j = 0;
-                       for (i = 0; i < sblock.fs_frag; i++) {
-                               if (!isset(bmap, dbase+d+i)) {
-                                       setbit(cgrp.cg_free, d+i);
-                                       j++;
-                               } else
-                                       clrbit(cgrp.cg_free, d+i);
-                       }
-                       if (j == sblock.fs_frag) {
-                               cgrp.cg_cs.cs_nbfree++;
-                               cgrp.cg_btot[cbtocylno(&sblock, d)]++;
-                               cgrp.cg_b[cbtocylno(&sblock, d)]
-                                   [cbtorpos(&sblock, d)]++;
-                       } else if (j > 0) {
-                               cgrp.cg_cs.cs_nffree += j;
-                               blk = ((cgrp.cg_free[d / NBBY] >> (d % NBBY)) &
-                                      (0xff >> (NBBY - sblock.fs_frag)));
-                               fragacct(&sblock, blk, cgrp.cg_frsum, 1);
-                       }
-               }
-               for (j = d; d < dmax - dbase; d++) {
-                       if (!isset(bmap, dbase+d)) {
-                               setbit(cgrp.cg_free, d);
-                               cgrp.cg_cs.cs_nffree++;
-                       } else
-                               clrbit(cgrp.cg_free, d);
-               }
-               if (j != d) {
-                       blk = ((cgrp.cg_free[j / NBBY] >> (j % NBBY)) &
-                              (0xff >> (NBBY - sblock.fs_frag)));
-                       fragacct(&sblock, blk, cgrp.cg_frsum, 1);
-               }
-               for (; d < MAXBPG(&sblock); d++)
-                       clrbit(cgrp.cg_free, d);
-               sblock.fs_cstotal.cs_nffree += cgrp.cg_cs.cs_nffree;
-               sblock.fs_cstotal.cs_nbfree += cgrp.cg_cs.cs_nbfree;
-               sblock.fs_cstotal.cs_nifree += cgrp.cg_cs.cs_nifree;
-               sblock.fs_cstotal.cs_ndir += cgrp.cg_cs.cs_ndir;
-               *cs = cgrp.cg_cs;
-               bwrite(fsbtodb(&sblock, cgtod(c, &sblock)), &cgrp,
-                       sblock.fs_cgsize);
-       }
-       for (i = 0; i < howmany(sblock.fs_cssize, sblock.fs_bsize); i++) {
-               bwrite(fsbtodb(&sblock,
-                   sblock.fs_csaddr + (i * sblock.fs_frag)),
-                   (char *)sblock.fs_csp[i], sblock.fs_bsize);
-       }
-       sblock.fs_ronly = 0;
-       sblock.fs_fmod = 0;
-       bwrite(SBLOCK, (char *)&sblock, SBSIZE);
-}
-
-/*
- * update the frsum fields to reflect addition or deletion 
- * of some frags
- */
-fragacct(fs, fragmap, fraglist, cnt)
-       struct fs *fs;
-       int fragmap;
-       long fraglist[];
-       int cnt;
-{
-       int inblk;
-       register int field, subfield;
-       register int siz, pos;
-
-       inblk = (int)(fragtbl[fs->fs_frag][fragmap] << 1);
-       fragmap <<= 1;
-       for (siz = 1; siz < fs->fs_frag; siz++) {
-               if (((1 << siz) & inblk) == 0)
-                       continue;
-               field = around[siz];
-               subfield = inside[siz];
-               for (pos = siz; pos <= fs->fs_frag; pos++) {
-                       if ((fragmap & field) == subfield) {
-                               fraglist[siz] += cnt;
-                               pos += siz;
-                               field <<= siz;
-                               subfield <<= siz;
-                       }
-                       field <<= 1;
-                       subfield <<= 1;
-               }
-       }
-}
-
 getsb(fs, file)
        register struct fs *fs;
        char *file;
 {
 getsb(fs, file)
        register struct fs *fs;
        char *file;
 {
-       int i;
+       int i, j, size;
 
 
-       if (bread(SBLOCK, fs, SBSIZE)) {
+       if (bread(SBOFF, fs, SBSIZE)) {
                printf("bad super block");
                perror(file);
                nerror |= 04;
                printf("bad super block");
                perror(file);
                nerror |= 04;
@@ -580,27 +457,14 @@ getsb(fs, file)
                nerror |= 04;
                return;
        }
                nerror |= 04;
                return;
        }
-       for (i = 0; i < howmany(fs->fs_cssize, fs->fs_bsize); i++) {
-               fs->fs_csp[i] = (struct csum *)calloc(1, fs->fs_bsize);
-               bread(fsbtodb(fs, fs->fs_csaddr + (i * fs->fs_frag)),
-                     (char *)fs->fs_csp[i], fs->fs_bsize);
-       }
-}
-
-bwrite(blk, buf, size)
-       char *buf;
-       daddr_t blk;
-       register size;
-{
-       if (lseek(fi, blk * DEV_BSIZE, 0) < 0) {
-               perror("FS SEEK");
-               return(1);
-       }
-       if (write(fi, buf, size) != size) {
-               perror("FS WRITE");
-               return(1);
+       dev_bsize = fs->fs_fsize / fsbtodb(fs, 1);
+       for (i = 0, j = 0; i < sblock.fs_cssize; i += sblock.fs_bsize, j++) {
+               size = sblock.fs_cssize - i < sblock.fs_bsize ?
+                   sblock.fs_cssize - i : sblock.fs_bsize;
+               sblock.fs_csp[j] = (struct csum *)calloc(1, size);
+               bread(fsbtodb(fs, fs->fs_csaddr + (j * fs->fs_frag)),
+                     (char *)fs->fs_csp[j], size);
        }
        }
-       return (0);
 }
 
 bread(bno, buf, cnt)
 }
 
 bread(bno, buf, cnt)
@@ -609,12 +473,8 @@ bread(bno, buf, cnt)
 {
        register i;
 
 {
        register i;
 
-       lseek(fi, bno * DEV_BSIZE, 0);
+       lseek(fi, bno * dev_bsize, 0);
        if ((i = read(fi, buf, cnt)) != cnt) {
        if ((i = read(fi, buf, cnt)) != cnt) {
-               if (sflg) {
-                       printf("No Update\n");
-                       sflg = 0;
-               }
                for(i=0; i<sblock.fs_bsize; i++)
                        buf[i] = 0;
                return (1);
                for(i=0; i<sblock.fs_bsize; i++)
                        buf[i] = 0;
                return (1);
@@ -623,9 +483,8 @@ bread(bno, buf, cnt)
 }
 
 /*
 }
 
 /*
- * block operations
+ * check if a block is available
  */
  */
-
 isblock(fs, cp, h)
        struct fs *fs;
        unsigned char *cp;
 isblock(fs, cp, h)
        struct fs *fs;
        unsigned char *cp;
@@ -646,11 +505,18 @@ isblock(fs, cp, h)
                mask = 0x01 << (h & 0x7);
                return ((cp[h >> 3] & mask) == mask);
        default:
                mask = 0x01 << (h & 0x7);
                return ((cp[h >> 3] & mask) == mask);
        default:
+#ifdef STANDALONE
+               printf("isblock bad fs_frag %d\n", fs->fs_frag);
+#else
                fprintf(stderr, "isblock bad fs_frag %d\n", fs->fs_frag);
                fprintf(stderr, "isblock bad fs_frag %d\n", fs->fs_frag);
+#endif
                return;
        }
 }
 
                return;
        }
 }
 
+/*
+ * put a block into the map
+ */
 setblock(fs, cp, h)
        struct fs *fs;
        unsigned char *cp;
 setblock(fs, cp, h)
        struct fs *fs;
        unsigned char *cp;
@@ -670,7 +536,11 @@ setblock(fs, cp, h)
                cp[h >> 3] |= (0x01 << (h & 0x7));
                return;
        default:
                cp[h >> 3] |= (0x01 << (h & 0x7));
                return;
        default:
+#ifdef STANDALONE
+               printf("setblock bad fs_frag %d\n", fs->fs_frag);
+#else
                fprintf(stderr, "setblock bad fs_frag %d\n", fs->fs_frag);
                fprintf(stderr, "setblock bad fs_frag %d\n", fs->fs_frag);
+#endif
                return;
        }
 }
                return;
        }
 }