parameterize BSIZE, FSIZE, and FRAG into fs_bsize, fs_fsize, and fs_frag
authorKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Tue, 5 Jan 1982 17:37:35 +0000 (09:37 -0800)
committerKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Tue, 5 Jan 1982 17:37:35 +0000 (09:37 -0800)
SCCS-vsn: sys/ufs/ffs/fs.h 1.9
SCCS-vsn: include/protocols/dumprestore.h 1.3
SCCS-vsn: sys/ufs/ffs/ffs_alloc.c 1.11
SCCS-vsn: sys/ufs/lfs/lfs_alloc.c 1.11
SCCS-vsn: sys/ufs/ffs/ffs_tables.c 1.3
SCCS-vsn: sbin/newfs/mkfs.c 1.10
SCCS-vsn: sbin/fsck/main.c 1.14
SCCS-vsn: old/dcheck/dcheck.c 1.4
SCCS-vsn: sbin/icheck/icheck.c 1.10
SCCS-vsn: sbin/ncheck/ncheck.c 1.4
SCCS-vsn: sbin/dumpfs/dumpfs.c 1.6
SCCS-vsn: sbin/restore/main.c 1.8
SCCS-vsn: sbin/dump/dump.h 1.4
SCCS-vsn: sbin/dump/itime.c 1.4
SCCS-vsn: sbin/dump/main.c 1.5
SCCS-vsn: sbin/dump/tape.c 1.5
SCCS-vsn: sbin/dump/traverse.c 1.4

17 files changed:
usr/src/include/protocols/dumprestore.h
usr/src/old/dcheck/dcheck.c
usr/src/sbin/dump/dump.h
usr/src/sbin/dump/itime.c
usr/src/sbin/dump/main.c
usr/src/sbin/dump/tape.c
usr/src/sbin/dump/traverse.c
usr/src/sbin/dumpfs/dumpfs.c
usr/src/sbin/fsck/main.c
usr/src/sbin/icheck/icheck.c
usr/src/sbin/ncheck/ncheck.c
usr/src/sbin/newfs/mkfs.c
usr/src/sbin/restore/main.c
usr/src/sys/ufs/ffs/ffs_alloc.c
usr/src/sys/ufs/ffs/ffs_tables.c
usr/src/sys/ufs/ffs/fs.h
usr/src/sys/ufs/lfs/lfs_alloc.c

index 3c2b711..6e70adc 100644 (file)
@@ -1,12 +1,23 @@
 /* Copyright (c) 1981 Regents of the University of California */
 
 /* Copyright (c) 1981 Regents of the University of California */
 
-/* "@(#)dumprestore.h 1.2 %G%" */
+/* "@(#)dumprestore.h 1.3 %G%" */
 
 
+/*
+ * TP_BSIZE is the size of file blocks on the dump tapes.
+ * Note that TP_BSIZE must be a multiple of DEV_BSIZE.
+ *
+ * NTREC is the number of TP_BSIZE blocks that are written
+ * in each tape record.
+ *
+ * BLKING calculates the number of TP_BSIZE blocks in a file
+ * system frag.
+ *
+ * TP_NINDIR is the number of indirect pointers in a TS_INODE
+ * or TS_ADDR record. Note that it must be a power of two.
+ */
 #define TP_BSIZE       1024
 #define NTREC          10
 #define TP_BSIZE       1024
 #define NTREC          10
-#define MLEN           16
-#define MSIZ           4096
-#define BLKING         (FSIZE/TP_BSIZE)
+#define BLKING(fs)     ((fs)->fs_fsize/TP_BSIZE)
 #define TP_NINDIR      (TP_BSIZE/2)
 
 #define TS_TAPE        1
 #define TP_NINDIR      (TP_BSIZE/2)
 
 #define TS_TAPE        1
index aac54c0..a236cb1 100644 (file)
@@ -1,9 +1,11 @@
-static char *sccsid = "@(#)dcheck.c    1.3 (Berkeley) %G%";
+static char *sccsid = "@(#)dcheck.c    1.4 (Berkeley) %G%";
 /*
  * dcheck - check directory consistency
  */
 #define        NB      10
 /*
  * dcheck - check directory consistency
  */
 #define        NB      10
-#define        NDIR    (BSIZE/sizeof(struct direct))
+#define        NDIR(fs)        ((fs)->fs_bsize/sizeof(struct direct))
+#define        MAXNDIR         (MAXBSIZE/sizeof(struct direct))
+#define        MAXNINDIR       (MAXBSIZE/sizeof(daddr_t))
 
 #include <stdio.h>
 #include "../h/param.h"
 
 #include <stdio.h>
 #include "../h/param.h"
@@ -13,7 +15,7 @@ static        char *sccsid = "@(#)dcheck.c    1.3 (Berkeley) %G%";
 
 union {
        struct  fs fs;
 
 union {
        struct  fs fs;
-       char pad[BSIZE];
+       char pad[MAXBSIZE];
 } fsun;
 #define        sblock  fsun.fs
 
 } fsun;
 #define        sblock  fsun.fs
 
@@ -78,7 +80,7 @@ char *file;
        headpr = 0;
        printf("%s:\n", file);
        sync();
        headpr = 0;
        printf("%s:\n", file);
        sync();
-       bread(SBLOCK, (char *)&sblock, BSIZE);
+       bread(SBLOCK, (char *)&sblock, MAXBSIZE);
        if (sblock.fs_magic != FS_MAGIC) {
                printf("%s: not a file system\n", file);
                nerror++;
        if (sblock.fs_magic != FS_MAGIC) {
                printf("%s: not a file system\n", file);
                nerror++;
@@ -99,7 +101,7 @@ char *file;
                ecount[i] = 0;
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
                ecount[i] = 0;
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
-               bread(cgimin(c, &sblock), (char *)itab,
+               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]);
                    sblock.fs_ipg * sizeof (struct dinode));
                for (j = 0; j < sblock.fs_ipg; j++) {
                        pass1(&itab[j]);
@@ -108,7 +110,7 @@ char *file;
        }
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
        }
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
-               bread(cgimin(c, &sblock), (char *)itab,
+               bread(fsbtodb(&sblock, cgimin(c, &sblock)), (char *)itab,
                    sblock.fs_ipg * sizeof (struct dinode));
                for (j = 0; j < sblock.fs_ipg; j++) {
                        pass2(&itab[j]);
                    sblock.fs_ipg * sizeof (struct dinode));
                for (j = 0; j < sblock.fs_ipg; j++) {
                        pass2(&itab[j]);
@@ -121,7 +123,7 @@ char *file;
 pass1(ip)
 register struct dinode *ip;
 {
 pass1(ip)
 register struct dinode *ip;
 {
-       struct direct dbuf[NDIR];
+       struct direct dbuf[MAXNDIR];
        long doff;
        struct direct *dp;
        register i, j;
        long doff;
        struct direct *dp;
        register i, j;
@@ -139,8 +141,8 @@ register struct dinode *ip;
                d = bmap(i);
                if(d == 0)
                        break;
                d = bmap(i);
                if(d == 0)
                        break;
-               bread(d, (char *)dbuf, BSIZE);
-               for(j=0; j<NDIR; j++) {
+               bread(fsbtodb(&sblock, d), (char *)dbuf, sblock.fs_bsize);
+               for(j=0; j < NDIR(&sblock); j++) {
                        if(doff >= ip->di_size)
                                break;
                        doff += sizeof(struct direct);
                        if(doff >= ip->di_size)
                                break;
                        doff += sizeof(struct direct);
@@ -189,10 +191,10 @@ char *buf;
 {
        register i;
 
 {
        register i;
 
-       lseek(fi, bno*FSIZE, 0);
+       lseek(fi, bno * DEV_BSIZE, 0);
        if (read(fi, buf, cnt) != cnt) {
                printf("read error %d\n", bno);
        if (read(fi, buf, cnt) != cnt) {
                printf("read error %d\n", bno);
-               for(i=0; i<BSIZE; i++)
+               for(i=0; i < cnt; i++)
                        buf[i] = 0;
        }
 }
                        buf[i] = 0;
        }
 }
@@ -200,15 +202,15 @@ char *buf;
 daddr_t
 bmap(i)
 {
 daddr_t
 bmap(i)
 {
-       daddr_t ibuf[NINDIR];
+       daddr_t ibuf[MAXNINDIR];
 
        if(i < NDADDR)
                return(gip->di_db[i]);
        i -= NDADDR;
 
        if(i < NDADDR)
                return(gip->di_db[i]);
        i -= NDADDR;
-       if(i > NINDIR) {
+       if(i > NINDIR(&sblock)) {
                printf("%u - huge directory\n", ino);
                return((daddr_t)0);
        }
                printf("%u - huge directory\n", ino);
                return((daddr_t)0);
        }
-       bread(gip->di_ib[0], (char *)ibuf, sizeof(ibuf));
+       bread(fsbtodb(&sblock, gip->di_ib[0]), (char *)ibuf, sizeof(ibuf));
        return(ibuf[i]);
 }
        return(ibuf[i]);
 }
index 9f38755..ebfc52c 100644 (file)
@@ -1,8 +1,11 @@
 /*
 /*
- * "@(#)dump.h 1.3 (Berkeley) %G%"
+ * "@(#)dump.h 1.4 (Berkeley) %G%"
  */
  */
-#define        NI      16
-#define        DIRPB   (BSIZE/sizeof(struct direct))
+#define        NI              16
+#define        DIRPB(fs)       ((fs)->fs_bsize / sizeof(struct direct))
+#define        MAXDIRPB        (MAXBSIZE / sizeof(struct direct))
+#define MAXINOPB       (MAXBSIZE / sizeof(struct dinode))
+#define MAXNINDIR      (MAXBSIZE / sizeof(daddr_t))
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
 int (*signal())();
 #include <fstab.h>
 
 int (*signal())();
 #include <fstab.h>
 
-#define        MWORD(m,i)      (m[(unsigned)(i-1)/MLEN])
-#define        MBIT(i)         (1<<((unsigned)(i-1)%MLEN))
+#define        MWORD(m,i)      (m[(unsigned)(i-1)/NBBY])
+#define        MBIT(i)         (1<<((unsigned)(i-1)%NBBY))
 #define        BIS(i,w)        (MWORD(w,i) |=  MBIT(i))
 #define        BIC(i,w)        (MWORD(w,i) &= ~MBIT(i))
 #define        BIT(i,w)        (MWORD(w,i) & MBIT(i))
 
 #define        BIS(i,w)        (MWORD(w,i) |=  MBIT(i))
 #define        BIC(i,w)        (MWORD(w,i) &= ~MBIT(i))
 #define        BIT(i,w)        (MWORD(w,i) & MBIT(i))
 
-short  clrmap[MSIZ];
-short  dirmap[MSIZ];
-short  nodmap[MSIZ];
+int    msiz;
+char   *clrmap;
+char   *dirmap;
+char   *nodmap;
 
 /*
  *     All calculations done in 0.1" units!
 
 /*
  *     All calculations done in 0.1" units!
@@ -55,6 +59,8 @@ int   blockswritten;  /* number of blocks written on current tape */
 int    tapeno;         /* current tape number */
 time_t tstart_writing; /* when started writing the first tape block */
 char   *processname;
 int    tapeno;         /* current tape number */
 time_t tstart_writing; /* when started writing the first tape block */
 char   *processname;
+struct fs *sblock;     /* the file system super block */
+char   buf[MAXBSIZE];
 
 char   *ctime();
 char   *prdate();
 
 char   *ctime();
 char   *prdate();
index bc4bd9d..558a883 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)itime.c     1.3 (Berkeley) %G%";
+static char *sccsid = "@(#)itime.c     1.4 (Berkeley) %G%";
 #include "dump.h"
 
 char *prdate(d)
 #include "dump.h"
 
 char *prdate(d)
@@ -210,7 +210,7 @@ int makeidate(ip, buf)
 }
 
 /*
 }
 
 /*
- * This is an estimation of the size of the file.
+ * This is an estimation of the number of TP_BSIZE blocks in the file.
  * It assumes that there are no unallocated blocks; hence
  * the estimate may be high
  */
  * It assumes that there are no unallocated blocks; hence
  * the estimate may be high
  */
@@ -220,29 +220,28 @@ est(ip)
        long s;
 
        esize++;
        long s;
 
        esize++;
-       s = (ip->di_size + FSIZE-1) / FSIZE;
-       esize += s;
-       s /= FRAG;
-       if (s > NDADDR) {
-               s -= NDADDR;
-               if (s > BSIZE / sizeof(daddr_t))
-                       esize++;
-               s = (s + (BSIZE/sizeof(daddr_t)) - 1) / (BSIZE/sizeof(daddr_t));
-               esize += s * FRAG;
+       /* calc number of TP_BSIZE blocks */
+       s = roundup(ip->di_size, sblock->fs_fsize) / TP_BSIZE;
+       if (ip->di_size > sblock->fs_bsize * NDADDR) {
+               /* calc number of indirect blocks on the dump tape */
+               s += howmany(s - NDADDR * BLKING(sblock) * sblock->fs_frag,
+                       TP_NINDIR);
        }
        }
+       esize += s;
 }
 
 bmapest(map)
 }
 
 bmapest(map)
-short *map;
+       char *map;
 {
        register i, n;
 
        n = -1;
 {
        register i, n;
 
        n = -1;
-       for(i=0; i<MSIZ; i++)
+       for (i = 0; i < msiz; i++)
                if(map[i])
                        n = i;
        if(n < 0)
                return;
                if(map[i])
                        n = i;
        if(n < 0)
                return;
+       n++;
        esize++;
        esize++;
-       esize += (n + (BSIZE/sizeof(short))-1) / (BSIZE/sizeof(short)) * FRAG;
+       esize += howmany(n * sizeof map[0], TP_BSIZE);
 }
 }
index 69c2bd1..df076d3 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)main.c      1.4 (Berkeley) %G%";
+static char *sccsid = "@(#)main.c      1.5 (Berkeley) %G%";
 #include "dump.h"
 
 int    notify = 0;     /* notify operator flag */
 #include "dump.h"
 
 int    notify = 0;     /* notify operator flag */
@@ -11,7 +11,7 @@ main(argc, argv)
        char    *argv[];
 {
        char            *arg;
        char    *argv[];
 {
        char            *arg;
-       register        i;
+       int             i;
        float           fetapes;
        register        struct  fstab   *dt;
 
        float           fetapes;
        register        struct  fstab   *dt;
 
@@ -21,7 +21,10 @@ main(argc, argv)
        tape = TAPE;
        disk = DISK;
        increm = NINCREM;
        tape = TAPE;
        disk = DISK;
        increm = NINCREM;
-
+       if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0) {
+               msg("TP_BSIZE must be a multiple of DEV_BSIZE\n");
+               dumpabort();
+       }
        incno = '9';
        uflag = 0;
        arg = "u";
        incno = '9';
        uflag = 0;
        arg = "u";
@@ -146,13 +149,22 @@ main(argc, argv)
                msg("Cannot open %s\n", disk);
                Exit(X_ABORT);
        }
                msg("Cannot open %s\n", disk);
                Exit(X_ABORT);
        }
-       CLR(clrmap);
-       CLR(dirmap);
-       CLR(nodmap);
        esize = 0;
        esize = 0;
+       sblock = (struct fs *)buf;
+       sync();
+       bread(SBLOCK, sblock, MAXBSIZE);
+       if (sblock->fs_magic != FS_MAGIC) {
+               msg("bad sblock magic number\n");
+               dumpabort();
+       }
+       msiz = roundup(howmany(sblock->fs_ipg * sblock->fs_ncg, NBBY),
+               TP_BSIZE);
+       clrmap = (char *)calloc(msiz, sizeof(char));
+       dirmap = (char *)calloc(msiz, sizeof(char));
+       nodmap = (char *)calloc(msiz, sizeof(char));
 
        msg("mapping (Pass I) [regular files]\n");
 
        msg("mapping (Pass I) [regular files]\n");
-       pass(mark, (short *)NULL);              /* mark updates esize */
+       pass(mark, (char *)NULL);               /* mark updates esize */
 
        do {
                msg("mapping (Pass II) [directories]\n");
 
        do {
                msg("mapping (Pass II) [directories]\n");
@@ -164,21 +176,21 @@ main(argc, argv)
        bmapest(nodmap);
 
        fetapes =
        bmapest(nodmap);
 
        fetapes =
-               (        esize          /* blocks */
-                       *FSIZE          /* bytes / block */
-                       *(1.0/density)  /* 0.1" / byte */
+               (         esize         /* blocks */
+                       * TP_BSIZE      /* bytes / block */
+                       * (1.0/density) /* 0.1" / byte */
                  +
                  +
-                        esize          /* blocks */
-                       *(1.0/NTREC)    /* IRG's / block */
-                       *             /* 0.1" / IRG */
+                         esize         /* blocks */
+                       * (1.0/NTREC)   /* IRG's / block */
+                       * 7             /* 0.1" / IRG */
                ) * (1.0 / tsize )      /* tape / 0.1" */
        ;
        etapes = fetapes;               /* truncating assignment */
        etapes++;
                ) * (1.0 / tsize )      /* tape / 0.1" */
        ;
        etapes = fetapes;               /* truncating assignment */
        etapes++;
-       /*
-        *      esize is typically about 5% too low; we frob it here
-        */
-       esize += ((5*esize)/100);
+       /* count the nodemap on each additional tape */
+       for (i = 1; i < etapes; i++)
+               bmapest(nodmap);
+       esize += i + 10;        /* headers + 10 trailer blocks */
        msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes);
 
        otape();                        /* bitmap is the first to tape write */
        msg("estimated %ld tape blocks on %3.2f tape(s).\n", esize, fetapes);
 
        otape();                        /* bitmap is the first to tape write */
@@ -192,7 +204,7 @@ main(argc, argv)
        pass(dump, nodmap);
 
        spcl.c_type = TS_END;
        pass(dump, nodmap);
 
        spcl.c_type = TS_END;
-       for(i=0; i<NTREC; i++)
+       for(i = 0; i < NTREC; i++)
                spclrec();
        msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
        msg("DUMP IS DONE\n");
                spclrec();
        msg("DUMP: %ld tape blocks on %d tape(s)\n",spcl.c_tapea,spcl.c_volume);
        msg("DUMP IS DONE\n");
index dd5565f..9851fa3 100644 (file)
@@ -1,15 +1,15 @@
-static char *sccsid = "@(#)tape.c      1.4 (Berkeley) %G%";
+static char *sccsid = "@(#)tape.c      1.5 (Berkeley) %G%";
 #include "dump.h"
 
 char   tblock[NTREC][TP_BSIZE];
 int    trecno = 0;
 
 taprec(dp)
 #include "dump.h"
 
 char   tblock[NTREC][TP_BSIZE];
 int    trecno = 0;
 
 taprec(dp)
-char *dp;
+       char *dp;
 {
        register i;
 
 {
        register i;
 
-       for(i=0; i<TP_BSIZE; i++)
+       for (i=0; i < TP_BSIZE; i++)
                tblock[trecno][i] = *dp++;
        trecno++;
        spcl.c_tapea++;
                tblock[trecno][i] = *dp++;
        trecno++;
        spcl.c_tapea++;
@@ -21,23 +21,24 @@ dmpblk(blkno, size)
        daddr_t blkno;
        int size;
 {
        daddr_t blkno;
        int size;
 {
-       int avail, blks;
+       int avail, tpblks, dblkno;
 
 
-       if (size % FRAG != 0)
+       if (size % TP_BSIZE != 0)
                msg("bad size to dmpblk: %d\n", size);
        avail = NTREC - trecno;
                msg("bad size to dmpblk: %d\n", size);
        avail = NTREC - trecno;
-       for (blks = size / TP_BSIZE; blks > avail; ) {
-               bread(blkno, tblock[trecno], TP_BSIZE * avail);
+       dblkno = fsbtodb(sblock, blkno);
+       for (tpblks = size / TP_BSIZE; tpblks > avail; ) {
+               bread(dblkno, tblock[trecno], TP_BSIZE * avail);
                trecno += avail;
                spcl.c_tapea += avail;
                flusht();
                trecno += avail;
                spcl.c_tapea += avail;
                flusht();
-               blkno += avail;
-               blks -= avail;
+               dblkno += avail * (TP_BSIZE / DEV_BSIZE);
+               tpblks -= avail;
                avail = NTREC - trecno;
        }
                avail = NTREC - trecno;
        }
-       bread(blkno, tblock[trecno], TP_BSIZE * blks);
-       trecno += blks;
-       spcl.c_tapea += blks;
+       bread(dblkno, tblock[trecno], TP_BSIZE * tpblks);
+       trecno += tpblks;
+       spcl.c_tapea += tpblks;
        if(trecno >= NTREC)
                flusht();
 }
        if(trecno >= NTREC)
                flusht();
 }
index 7798ba9..f202a7b 100644 (file)
@@ -1,25 +1,18 @@
-static char *sccsid = "@(#)traverse.c  1.3 (Berkeley) %G%";
-#include "dump.h"
+static char *sccsid = "@(#)traverse.c  1.4 (Berkeley) %G%";
 
 
-struct fs      sblock;
+#include "dump.h"
 
 pass(fn, map)
        int (*fn)();
 
 pass(fn, map)
        int (*fn)();
-       short *map;
+       char *map;
 {
        struct dinode *dp;
        int bits;
        ino_t maxino;
 
 {
        struct dinode *dp;
        int bits;
        ino_t maxino;
 
-       sync();
-       bread(SBLOCK, &sblock, sizeof sblock);
-       if (sblock.fs_magic != FS_MAGIC) {
-               msg("bad sblock magic number\n");
-               dumpabort();
-       }
-       maxino = sblock.fs_ipg * sblock.fs_ncg;
+       maxino = sblock->fs_ipg * sblock->fs_ncg - 1;
        for (ino = 0; ino < maxino; ) {
        for (ino = 0; ino < maxino; ) {
-               if((ino % MLEN) == 0) {
+               if((ino % NBBY) == 0) {
                        bits = ~0;
                        if(map != NULL)
                                bits = *map++;
                        bits = ~0;
                        if(map != NULL)
                                bits = *map++;
@@ -33,47 +26,6 @@ pass(fn, map)
        }
 }
 
        }
 }
 
-icat(dp, fn1)
-       register struct dinode  *dp;
-       int (*fn1)();
-{
-       register int i;
-
-       for (i = 0; i < NDADDR; i++) {
-               if (dp->di_db[i] != 0)
-                       (*fn1)(dp->di_db[i]);
-       }
-       for (i = 0; i < NIADDR; i++) {
-               if (dp->di_ib[i] != 0)
-                       indir(dp->di_ib[i], fn1, i);
-       }
-}
-
-indir(d, fn1, n)
-       daddr_t d;
-       int (*fn1)();
-       int n;
-{
-       register i;
-       daddr_t idblk[NINDIR];
-
-       bread(d, (char *)idblk, sizeof(idblk));
-       if(n <= 0) {
-               for(i=0; i<NINDIR; i++) {
-                       d = idblk[i];
-                       if(d != 0)
-                               (*fn1)(d);
-               }
-       } else {
-               n--;
-               for(i=0; i<NINDIR; i++) {
-                       d = idblk[i];
-                       if(d != 0)
-                               indir(d, fn1, n);
-               }
-       }
-}
-
 mark(ip)
        struct dinode *ip;
 {
 mark(ip)
        struct dinode *ip;
 {
@@ -85,10 +37,10 @@ mark(ip)
        BIS(ino, clrmap);
        if(f == IFDIR)
                BIS(ino, dirmap);
        BIS(ino, clrmap);
        if(f == IFDIR)
                BIS(ino, dirmap);
-       if(ip->di_mtime >= spcl.c_ddate ||
-          ip->di_ctime >= spcl.c_ddate) {
+       if ((ip->di_mtime >= spcl.c_ddate || ip->di_ctime >= spcl.c_ddate) &&
+           !BIT(ino, nodmap)) {
                BIS(ino, nodmap);
                BIS(ino, nodmap);
-               if (f != IFREG){
+               if (f != IFREG && f != IFDIR) {
                        esize += 1;
                        return;
                }
                        esize += 1;
                        return;
                }
@@ -97,24 +49,58 @@ mark(ip)
 }
 
 add(ip)
 }
 
 add(ip)
-       struct dinode *ip;
+       register struct dinode  *ip;
 {
 {
+       register int i;
 
        if(BIT(ino, nodmap))
                return;
        nsubdir = 0;
        dadded = 0;
 
        if(BIT(ino, nodmap))
                return;
        nsubdir = 0;
        dadded = 0;
-       icat(ip, dsrch);
+       for (i = 0; i < NDADDR; i++) {
+               if (ip->di_db[i] != 0)
+                       dsrch(ip->di_db[i], dblksize(sblock, ip, i));
+       }
+       for (i = 0; i < NIADDR; i++) {
+               if (ip->di_ib[i] != 0)
+                       indir(ip->di_ib[i], i);
+       }
        if(dadded) {
        if(dadded) {
-               BIS(ino, nodmap);
-               est(ip);
                nadded++;
                nadded++;
+               if (!BIT(ino, nodmap)) {
+                       BIS(ino, nodmap);
+                       est(ip);
+               }
        }
        if(nsubdir == 0)
                if(!BIT(ino, nodmap))
                        BIC(ino, dirmap);
 }
 
        }
        if(nsubdir == 0)
                if(!BIT(ino, nodmap))
                        BIC(ino, dirmap);
 }
 
+indir(d, n)
+       daddr_t d;
+       int n;
+{
+       register i;
+       daddr_t idblk[MAXNINDIR];
+
+       bread(fsbtodb(sblock, d), (char *)idblk, sblock->fs_bsize);
+       if(n <= 0) {
+               for(i=0; i < NINDIR(sblock); i++) {
+                       d = idblk[i];
+                       if(d != 0)
+                               dsrch(d, sblock->fs_bsize);
+               }
+       } else {
+               n--;
+               for(i=0; i < NINDIR(sblock); i++) {
+                       d = idblk[i];
+                       if(d != 0)
+                               indir(d, n);
+               }
+       }
+}
+
 dump(ip)
        struct dinode *ip;
 {
 dump(ip)
        struct dinode *ip;
 {
@@ -134,12 +120,12 @@ dump(ip)
                spclrec();
                return;
        }
                spclrec();
                return;
        }
-       if (ip->di_size > NDADDR * BSIZE)
-               i = NDADDR * FRAG;
+       if (ip->di_size > NDADDR * sblock->fs_bsize)
+               i = NDADDR * sblock->fs_frag;
        else
        else
-               i = howmany(ip->di_size, FSIZE);
+               i = howmany(ip->di_size, sblock->fs_fsize);
        blksout(&ip->di_db[0], i);
        blksout(&ip->di_db[0], i);
-       size = ip->di_size - NDADDR * BSIZE;
+       size = ip->di_size - NDADDR * sblock->fs_bsize;
        if (size <= 0)
                return;
        for (i = 0; i < NIADDR; i++) {
        if (size <= 0)
                return;
        for (i = 0; i < NIADDR; i++) {
@@ -155,23 +141,23 @@ dmpindir(blk, lvl, size)
        long *size;
 {
        int i, cnt;
        long *size;
 {
        int i, cnt;
-       daddr_t idblk[NINDIR];
+       daddr_t idblk[MAXNINDIR];
 
        if (blk != 0)
 
        if (blk != 0)
-               bread(blk, (char *)idblk, sizeof(idblk));
+               bread(fsbtodb(sblock, blk), (char *)idblk, sblock->fs_bsize);
        else
        else
-               blkclr(idblk, sizeof(idblk));
+               blkclr(idblk, sblock->fs_bsize);
        if (lvl <= 0) {
        if (lvl <= 0) {
-               if (*size < NINDIR * BSIZE)
-                       cnt = howmany(*size, TP_BSIZE);
+               if (*size < NINDIR(sblock) * sblock->fs_bsize)
+                       cnt = howmany(*size, sblock->fs_fsize);
                else
                else
-                       cnt = NINDIR * BLKING * FRAG;
-               *size -= NINDIR * BSIZE;
+                       cnt = NINDIR(sblock) * sblock->fs_frag;
+               *size -= NINDIR(sblock) * sblock->fs_bsize;
                blksout(&idblk[0], cnt);
                return;
        }
        lvl--;
                blksout(&idblk[0], cnt);
                return;
        }
        lvl--;
-       for (i = 0; i < NINDIR; i++) {
+       for (i = 0; i < NINDIR(sblock); i++) {
                dmpindir(idblk[i], lvl, size);
                if (*size <= 0)
                        return;
                dmpindir(idblk[i], lvl, size);
                if (*size <= 0)
                        return;
@@ -182,53 +168,52 @@ blksout(blkp, frags)
        daddr_t *blkp;
        int frags;
 {
        daddr_t *blkp;
        int frags;
 {
-       int i, j, count, blks;
+       int i, j, count, blks, tbperdb;
 
 
-       blks = frags * BLKING;
+       blks = frags * BLKING(sblock);
+       tbperdb = BLKING(sblock) * sblock->fs_frag;
        for (i = 0; i < blks; i += TP_NINDIR) {
                if (i + TP_NINDIR > blks)
                        count = blks;
                else
                        count = i + TP_NINDIR;
                for (j = i; j < count; j++)
        for (i = 0; i < blks; i += TP_NINDIR) {
                if (i + TP_NINDIR > blks)
                        count = blks;
                else
                        count = i + TP_NINDIR;
                for (j = i; j < count; j++)
-                       if (blkp[j / (BLKING * FRAG)] != 0)
+                       if (blkp[j / tbperdb] != 0)
                                spcl.c_addr[j - i] = 1;
                        else
                                spcl.c_addr[j - i] = 0;
                spcl.c_count = count - i;
                spclrec();
                                spcl.c_addr[j - i] = 1;
                        else
                                spcl.c_addr[j - i] = 0;
                spcl.c_count = count - i;
                spclrec();
-               for (j = i; j < count; j += (BLKING * FRAG))
-                       if (blkp[j / (BLKING * FRAG)] != 0)
-                               if (j + (BLKING * FRAG) <= count)
-                                       dmpblk(blkp[j / (BLKING * FRAG)],
-                                           BSIZE);
+               for (j = i; j < count; j += tbperdb)
+                       if (blkp[j / tbperdb] != 0)
+                               if (j + tbperdb <= count)
+                                       dmpblk(blkp[j / tbperdb],
+                                           sblock->fs_bsize);
                                else
                                else
-                                       dmpblk(blkp[j / (BLKING * FRAG)],
+                                       dmpblk(blkp[j / tbperdb],
                                            (count - j) * TP_BSIZE);
                spcl.c_type = TS_ADDR;
        }
 }
 
 bitmap(map, typ)
                                            (count - j) * TP_BSIZE);
                spcl.c_type = TS_ADDR;
        }
 }
 
 bitmap(map, typ)
-       short *map;
+       char *map;
 {
        register i, n;
        char *cp;
 
        n = -1;
 {
        register i, n;
        char *cp;
 
        n = -1;
-       for(i=0; i<MSIZ; i++)
+       for (i = 0; i < msiz; i++)
                if(map[i])
                        n = i;
                if(map[i])
                        n = i;
-       if(n < 0)
+       if (n < 0)
                return;
                return;
+       n++;
        spcl.c_type = typ;
        spcl.c_type = typ;
-       spcl.c_count = (n*sizeof(map[0]) + TP_BSIZE)/TP_BSIZE;
+       spcl.c_count = howmany(n * sizeof(map[0]), TP_BSIZE);
        spclrec();
        spclrec();
-       cp = (char *)map;
-       for(i=0; i<spcl.c_count; i++) {
+       for (i = 0, cp = map; i < spcl.c_count; i++, cp += TP_BSIZE)
                taprec(cp);
                taprec(cp);
-               cp += TP_BSIZE;
-       }
 }
 
 spclrec()
 }
 
 spclrec()
@@ -246,18 +231,19 @@ spclrec()
        taprec((char *)&spcl);
 }
 
        taprec((char *)&spcl);
 }
 
-dsrch(d)
+dsrch(d, size)
        daddr_t d;
        daddr_t d;
+       int size;
 {
        register char *cp;
        register i;
        register ino_t in;
 {
        register char *cp;
        register i;
        register ino_t in;
-       struct direct dblk[DIRPB];
+       struct direct dblk[MAXDIRPB];
 
        if(dadded)
                return;
 
        if(dadded)
                return;
-       bread(d, (char *)dblk, sizeof(dblk));
-       for(i=0; i<DIRPB; i++) {
+       bread(fsbtodb(sblock, d), (char *)dblk, size);
+       for(i=0; i < DIRPB(sblock); i++) {
                in = dblk[i].d_ino;
                if(in == 0)
                        continue;
                in = dblk[i].d_ino;
                if(in == 0)
                        continue;
@@ -282,14 +268,14 @@ getino(ino)
        daddr_t ino;
 {
        static daddr_t minino, maxino;
        daddr_t ino;
 {
        static daddr_t minino, maxino;
-       static struct dinode itab[INOPB];
+       static struct dinode itab[MAXINOPB];
 
        if (ino >= minino && ino < maxino) {
                return (&itab[ino - minino]);
        }
 
        if (ino >= minino && ino < maxino) {
                return (&itab[ino - minino]);
        }
-       bread(itod(ino, &sblock), itab, BSIZE);
-       minino = ino - (ino % INOPB);
-       maxino = minino + INOPB;
+       bread(fsbtodb(sblock, itod(ino, sblock)), itab, sblock->fs_bsize);
+       minino = ino - (ino % INOPB(sblock));
+       maxino = minino + INOPB(sblock);
        return (&itab[ino - minino]);
 }
 
        return (&itab[ino - minino]);
 }
 
@@ -304,12 +290,12 @@ bread(da, ba, c)
        register n;
        register        regc;
 
        register n;
        register        regc;
 
-       if (lseek(fi, (long)(da*FSIZE), 0) < 0){
+       if (lseek(fi, (long)(da * DEV_BSIZE), 0) < 0){
                msg("bread: lseek fails\n");
        }
        regc = c;       /* put c someplace safe; it gets clobbered */
        n = read(fi, ba, c);
                msg("bread: lseek fails\n");
        }
        regc = c;       /* put c someplace safe; it gets clobbered */
        n = read(fi, ba, c);
-       if(n != c || regc != c){
+       if (n != c || regc != c) {
                msg("(This should not happen)bread from %s [block %d]: c=0x%x, regc=0x%x, &c=0x%x, n=0x%x\n",
                        disk, da, c, regc, &c, n);
 #ifdef ERNIE
                msg("(This should not happen)bread from %s [block %d]: c=0x%x, regc=0x%x, &c=0x%x, n=0x%x\n",
                        disk, da, c, regc, &c, n);
 #ifdef ERNIE
@@ -329,17 +315,6 @@ bread(da, ba, c)
        }
 }
 
        }
 }
 
-CLR(map)
-       register short *map;
-{
-       register n;
-
-       n = MSIZ;
-       do
-               *map++ = 0;
-       while(--n);
-}
-
 blkclr(cp, size)
        char *cp;
        long size;
 blkclr(cp, size)
        char *cp;
        long size;
index be539aa..266bcf7 100644 (file)
@@ -1,4 +1,5 @@
-static char *sccsid = "@(#)dumpfs.c    1.5 (Berkeley) %G%";
+static char *sccsid = "@(#)dumpfs.c    1.6 (Berkeley) %G%";
+
 #include "../h/param.h"
 #include "../h/fs.h"
 #include "../h/inode.h"
 #include "../h/param.h"
 #include "../h/fs.h"
 #include "../h/inode.h"
@@ -9,13 +10,13 @@ static       char *sccsid = "@(#)dumpfs.c    1.5 (Berkeley) %G%";
 
 union {
        struct fs fs;
 
 union {
        struct fs fs;
-       char pad[BSIZE];
+       char pad[MAXBSIZE];
 } fsun;
 #define        afs     fsun.fs
 
 union {
        struct cg cg;
 } fsun;
 #define        afs     fsun.fs
 
 union {
        struct cg cg;
-       char pad[BSIZE];
+       char pad[MAXBSIZE];
 } cgun;
 #define        acg     cgun.cg
 
 } cgun;
 #define        acg     cgun.cg
 
@@ -27,8 +28,8 @@ main(argc, argv)
        close(0);
        if (open(argv[1], 0) != 0)
                perror(argv[1]), exit(1);
        close(0);
        if (open(argv[1], 0) != 0)
                perror(argv[1]), exit(1);
-       lseek(0, SBLOCK*FSIZE, 0);
-       if (read(0, &afs, BSIZE) != BSIZE)
+       lseek(0, SBLOCK * DEV_BSIZE, 0);
+       if (read(0, &afs, MAXBSIZE) != MAXBSIZE)
                perror(argv[1]), exit(1);
        printf("magic\t%x\n", afs.fs_magic);
        printf("sblkno\t%d\n", afs.fs_sblkno);
                perror(argv[1]), exit(1);
        printf("magic\t%x\n", afs.fs_magic);
        printf("sblkno\t%d\n", afs.fs_sblkno);
@@ -36,6 +37,12 @@ main(argc, argv)
        printf("size\t%d\n", afs.fs_size);
        printf("blocks\t%d\n", afs.fs_dsize);
        printf("ncg\t%d\n", afs.fs_ncg);
        printf("size\t%d\n", afs.fs_size);
        printf("blocks\t%d\n", afs.fs_dsize);
        printf("ncg\t%d\n", afs.fs_ncg);
+       printf("bsize\t%d\n", afs.fs_bsize);
+       printf("fsize\t%d\n", afs.fs_fsize);
+       printf("frag\t%d\n", afs.fs_frag);
+       printf("minfree\t%d%%\n", afs.fs_minfree);
+       printf("rotdelay %dms\n", afs.fs_rotdelay);
+       printf("csaddr\t%d\n", afs.fs_csaddr);
        printf("cssize\t%d\n", afs.fs_cssize);
        printf("cgsize\t%d\n", afs.fs_cgsize);
        printf("ntrak\t%d\nnsect\t%d\nspc\t%d\nncyl\t%d\n",
        printf("cssize\t%d\n", afs.fs_cssize);
        printf("cgsize\t%d\n", afs.fs_cgsize);
        printf("ntrak\t%d\nnsect\t%d\nspc\t%d\nncyl\t%d\n",
@@ -58,14 +65,15 @@ main(argc, argv)
                }
        }
        printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
                }
        }
        printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
-       for (i = 0; i < howmany(cssize(&afs), BSIZE); i++) {
-               afs.fs_csp[i] = (struct csum *)calloc(1, BSIZE);
-               lseek(0, (csaddr(&afs) + (i * FRAG)) * FSIZE, 0);
-               if (read(0, afs.fs_csp[i], BSIZE) != BSIZE)
+       for (i = 0; i < howmany(afs.fs_cssize, afs.fs_bsize); i++) {
+               afs.fs_csp[i] = (struct csum *)calloc(1, afs.fs_bsize);
+               lseek(0, fsbtodb(&afs, (afs.fs_csaddr + (i * afs.fs_frag))) *
+                   DEV_BSIZE, 0);
+               if (read(0, afs.fs_csp[i], afs.fs_bsize) != afs.fs_bsize)
                        perror(argv[1]), exit(1);
        }
        for (i = 0; i < afs.fs_ncg; i++) {
                        perror(argv[1]), exit(1);
        }
        for (i = 0; i < afs.fs_ncg; i++) {
-               struct csum *cs = &afs.fs_cs(i);
+               struct csum *cs = &afs.fs_cs(&afs, i);
                if (i && i % 4 == 0)
                        printf("\n\t");
                printf("(%d,%d,%d,%d) ",
                if (i && i % 4 == 0)
                        printf("\n\t");
                printf("(%d,%d,%d,%d) ",
@@ -85,9 +93,9 @@ dumpcg(c)
        int i,j;
 
        printf("\ncg %d:\n", c);
        int i,j;
 
        printf("\ncg %d:\n", c);
-       lseek(0, cgtod(c,&afs)*FSIZE, 0);
+       lseek(0, fsbtodb(&afs, cgtod(c,&afs)) * DEV_BSIZE, 0);
        printf("tell\t%x\n", tell(0));
        printf("tell\t%x\n", tell(0));
-       if (read(0, (char *)&acg, afs.fs_cgsize) != afs.fs_cgsize) {
+       if (read(0, (char *)&acg, afs.fs_bsize) != afs.fs_bsize) {
                printf("\terror reading cg\n");
                return;
        }
                printf("\terror reading cg\n");
                return;
        }
@@ -99,7 +107,7 @@ dumpcg(c)
            acg.cg_cs.cs_nffree, acg.cg_cs.cs_nbfree);
        printf("rotor\t%d\nirotor\t%d\nfrotor\t%d\nfrsum",
            acg.cg_rotor, acg.cg_irotor, acg.cg_frotor);
            acg.cg_cs.cs_nffree, acg.cg_cs.cs_nbfree);
        printf("rotor\t%d\nirotor\t%d\nfrotor\t%d\nfrsum",
            acg.cg_rotor, acg.cg_irotor, acg.cg_frotor);
-       for (i = 1, j = 0; i < FRAG; i++) {
+       for (i = 1, j = 0; i < afs.fs_frag; i++) {
                printf("\t%d", acg.cg_frsum[i]);
                j += i * acg.cg_frsum[i];
        }
                printf("\t%d", acg.cg_frsum[i]);
                j += i * acg.cg_frsum[i];
        }
index 92e241a..5c3abda 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)main.c      1.13 (Berkeley) %G%";
+static char *sccsid = "@(#)main.c      1.14 (Berkeley) %G%";
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -12,8 +12,11 @@ static       char *sccsid = "@(#)main.c      1.13 (Berkeley) %G%";
 
 typedef        int     (*SIG_TYP)();
 
 
 typedef        int     (*SIG_TYP)();
 
-#define        NDIRECT (BSIZE/sizeof(struct direct))
-#define        SPERB   (BSIZE/sizeof(short))
+#define        NDIRECT(fs)     ((fs)->fs_bsize / sizeof(struct direct))
+#define        MAXNDIRECT      (MAXBSIZE / sizeof(struct direct))
+#define        MAXINOPB        (MAXBSIZE / sizeof(struct dinode))
+#define        MAXNINDIR       (MAXBSIZE / sizeof(daddr_t))
+#define        SPERB           (MAXBSIZE / sizeof(short))
 
 #define        MAXDUP  10              /* limit on dup blks (per inode) */
 #define        MAXBAD  10              /* limit on bad blks (per inode) */
 
 #define        MAXDUP  10              /* limit on dup blks (per inode) */
 #define        MAXBAD  10              /* limit on bad blks (per inode) */
@@ -42,13 +45,13 @@ struct bufarea {
        daddr_t b_bno;
        int     b_size;
        union {
        daddr_t b_bno;
        int     b_size;
        union {
-               char    b_buf[BSIZE];           /* buffer space */
+               char    b_buf[MAXBSIZE];        /* buffer space */
                short   b_lnks[SPERB];          /* link counts */
                short   b_lnks[SPERB];          /* link counts */
-               daddr_t b_indir[NINDIR];        /* indirect block */
+               daddr_t b_indir[MAXNINDIR];     /* indirect block */
                struct  fs b_fs;                /* super block */
                struct  cg b_cg;                /* cylinder group */
                struct  fs b_fs;                /* super block */
                struct  cg b_cg;                /* cylinder group */
-               struct dinode b_dinode[INOPB];  /* inode block */
-               DIRECT b_dir[NDIRECT];          /* directory */
+               struct dinode b_dinode[MAXINOPB]; /* inode block */
+               DIRECT b_dir[MAXNDIRECT];       /* directory */
        } b_un;
        char    b_dirty;
 };
        } b_un;
        char    b_dirty;
 };
@@ -172,7 +175,7 @@ int pass1(), pass1b(), pass2(), pass4(), pass5();
 int    (*pfunc)();
 char   *rawname(), *rindex(), *unrawname();
 extern int inside[], around[];
 int    (*pfunc)();
 char   *rawname(), *rindex(), *unrawname();
 extern int inside[], around[];
-extern unsigned char fragtbl[];
+extern unsigned char *fragtbl[];
 
 char   *devname;
 
 
 char   *devname;
 
@@ -370,7 +373,7 @@ check(dev)
        }
        pfunc = pass1;
        inum = 0;
        }
        pfunc = pass1;
        inum = 0;
-       n_blks += howmany(sblock.fs_cssize, BSIZE) * FRAG;
+       n_blks += howmany(sblock.fs_cssize, sblock.fs_bsize) * sblock.fs_frag;
        for (c = 0; c < sblock.fs_ncg; c++) {
                if (getblk(&cgblk, cgtod(c, &sblock), sblock.fs_cgsize) == 0)
                        continue;
        for (c = 0; c < sblock.fs_ncg; c++) {
                if (getblk(&cgblk, cgtod(c, &sblock), sblock.fs_cgsize) == 0)
                        continue;
@@ -571,13 +574,13 @@ out1b:
        for (c = 0; c < sblock.fs_ncg; c++) {
                daddr_t cbase = cgbase(c,&sblock);
                short bo[MAXCPG][NRPOS];
        for (c = 0; c < sblock.fs_ncg; c++) {
                daddr_t cbase = cgbase(c,&sblock);
                short bo[MAXCPG][NRPOS];
-               long frsum[FRAG];
+               long frsum[MAXFRAG];
                int blk;
 
                for (n = 0; n < sblock.fs_cpg; n++)
                        for (i = 0; i < NRPOS; i++)
                                bo[n][i] = 0;
                int blk;
 
                for (n = 0; n < sblock.fs_cpg; n++)
                        for (i = 0; i < NRPOS; i++)
                                bo[n][i] = 0;
-               for (i = 0; i < FRAG; i++) {
+               for (i = 0; i < sblock.fs_frag; i++) {
                        frsum[i] = 0;
                }
                /*
                        frsum[i] = 0;
                }
                /*
@@ -587,28 +590,28 @@ out1b:
                n_bad += cgtod(c, &sblock) - cbase;
                if (getblk(&cgblk, cgtod(c, &sblock), sblock.fs_cgsize) == 0)
                        continue;
                n_bad += cgtod(c, &sblock) - cbase;
                if (getblk(&cgblk, cgtod(c, &sblock), sblock.fs_cgsize) == 0)
                        continue;
-               for (b = 0; b < sblock.fs_fpg; b += FRAG) {
-                       if (isblock(cgrp.cg_free, b/FRAG)) {
-                               if (pass5(cbase+b, FRAG) == STOP)
+               for (b = 0; b < sblock.fs_fpg; b += sblock.fs_frag) {
+                       if (isblock(&sblock, cgrp.cg_free, b/sblock.fs_frag)) {
+                               if (pass5(cbase+b, sblock.fs_frag) == STOP)
                                        goto out5;
                                /* this is clumsy ... */
                                        goto out5;
                                /* this is clumsy ... */
-                               n_ffree -= FRAG;
+                               n_ffree -= sblock.fs_frag;
                                n_bfree++;
                                n_bfree++;
-                               s = b * NSPF;
+                               s = b * NSPF(&sblock);
                                bo[s/sblock.fs_spc]
                                    [s%sblock.fs_nsect*NRPOS/sblock.fs_nsect]++;
                        } else {
                                bo[s/sblock.fs_spc]
                                    [s%sblock.fs_nsect*NRPOS/sblock.fs_nsect]++;
                        } else {
-                               for (d = 0; d < FRAG; d++)
+                               for (d = 0; d < sblock.fs_frag; d++)
                                        if (isset(cgrp.cg_free, b+d))
                                                if (pass5(cbase+b+d,1) == STOP)
                                                        goto out5;
                                blk = ((cgrp.cg_free[b / NBBY] >> (b % NBBY)) &
                                        if (isset(cgrp.cg_free, b+d))
                                                if (pass5(cbase+b+d,1) == STOP)
                                                        goto out5;
                                blk = ((cgrp.cg_free[b / NBBY] >> (b % NBBY)) &
-                                      (0xff >> (NBBY - FRAG)));
+                                      (0xff >> (NBBY - sblock.fs_frag)));
                                if (blk != 0)
                                if (blk != 0)
-                                       fragacct(blk, frsum, 1);
+                                       fragacct(&sblock, blk, frsum, 1);
                        }
                }
                        }
                }
-               for (i = 0; i < FRAG; i++) {
+               for (i = 0; i < sblock.fs_frag; i++) {
                        if (cgrp.cg_frsum[i] != frsum[i]) {
                                printf("cg[%d].cg_frsum[%d] have %d calc %d\n",
                                        c, i, cgrp.cg_frsum[i], frsum[i]);
                        if (cgrp.cg_frsum[i] != frsum[i]) {
                                printf("cg[%d].cg_frsum[%d] have %d calc %d\n",
                                        c, i, cgrp.cg_frsum[i], frsum[i]);
@@ -627,7 +630,7 @@ out5:
        if (dupblk)
                pwarn("%d DUP BLKS IN BIT MAPS\n", dupblk);
        if (fixcg == 0) {
        if (dupblk)
                pwarn("%d DUP BLKS IN BIT MAPS\n", dupblk);
        if (fixcg == 0) {
-               if ((b = n_blks+n_ffree+FRAG*n_bfree+n_index+n_bad) != fmax) {
+               if ((b = n_blks+n_ffree+sblock.fs_frag*n_bfree+n_index+n_bad) != fmax) {
                        pwarn("%ld BLK(S) MISSING\n", fmax - b);
                        fixcg = 1;
                } else if (inosumbad + offsumbad + frsumbad) {
                        pwarn("%ld BLK(S) MISSING\n", fmax - b);
                        fixcg = 1;
                } else if (inosumbad + offsumbad + frsumbad) {
@@ -665,8 +668,8 @@ out5:
        }
 
        pwarn("%d files, %d used, %d free (%d frags, %d blocks)\n",
        }
 
        pwarn("%d files, %d used, %d free (%d frags, %d blocks)\n",
-           n_files, n_blks - howmany(sblock.fs_cssize, BSIZE) * FRAG,
-           n_ffree + FRAG * n_bfree, n_ffree, n_bfree);
+           n_files, n_blks - howmany(sblock.fs_cssize, sblock.fs_bsize) * sblock.fs_frag,
+           n_ffree + sblock.fs_frag * n_bfree, n_ffree, n_bfree);
        if (dfile.mod) {
                time(&sblock.fs_time);
                sbdirty();
        if (dfile.mod) {
                time(&sblock.fs_time);
                sbdirty();
@@ -751,17 +754,17 @@ ckinode(dp, flg)
        if (SPECIAL)
                return (KEEPON);
        func = (flg == ADDR) ? pfunc : dirscan;
        if (SPECIAL)
                return (KEEPON);
        func = (flg == ADDR) ? pfunc : dirscan;
-       ndb = howmany(dp->di_size, BSIZE);
+       ndb = howmany(dp->di_size, sblock.fs_bsize);
        for (ap = &dp->di_db[0]; ap < &dp->di_db[NDADDR]; ap++) {
        for (ap = &dp->di_db[0]; ap < &dp->di_db[NDADDR]; ap++) {
-               if (--ndb == 0 && (dp->di_size&BMASK))
-                       size = howmany(dp->di_size&BMASK, FSIZE);
+               if (--ndb == 0 && (dp->di_size % sblock.fs_bsize))
+                       size = howmany(dp->di_size % sblock.fs_bsize, sblock.fs_fsize);
                else
                else
-                       size = FRAG;
+                       size = sblock.fs_frag;
                if (*ap && (ret = (*func)(*ap, size)) & STOP)
                        return (ret);
        }
        for (ap = &dp->di_ib[0], n = 1; n <= 2; ap++, n++) {
                if (*ap && (ret = (*func)(*ap, size)) & STOP)
                        return (ret);
        }
        for (ap = &dp->di_ib[0], n = 1; n <= 2; ap++, n++) {
-               if (*ap && (ret = iblock(*ap, n, flg, dp->di_size - BSIZE * NDADDR)) & STOP)
+               if (*ap && (ret = iblock(*ap, n, flg, dp->di_size - sblock.fs_bsize * NDADDR)) & STOP)
                        return (ret);
        }
        return (KEEPON);
                        return (ret);
        }
        return (KEEPON);
@@ -780,30 +783,30 @@ iblock(blk, ilevel, flg, isize)
 
        if (flg == ADDR) {
                func = pfunc;
 
        if (flg == ADDR) {
                func = pfunc;
-               if (((n = (*func)(blk, FRAG)) & KEEPON) == 0)
+               if (((n = (*func)(blk, sblock.fs_frag)) & KEEPON) == 0)
                        return (n);
        } else
                func = dirscan;
        if (outrange(blk))              /* protect thyself */
                return (SKIP);
        initbarea(&ib);
                        return (n);
        } else
                func = dirscan;
        if (outrange(blk))              /* protect thyself */
                return (SKIP);
        initbarea(&ib);
-       if (getblk(&ib, blk, BSIZE) == NULL)
+       if (getblk(&ib, blk, sblock.fs_bsize) == NULL)
                return (SKIP);
        ilevel--;
        if (ilevel == 0) {
                return (SKIP);
        ilevel--;
        if (ilevel == 0) {
-               nif = isize / BSIZE + 1;
+               nif = isize / sblock.fs_bsize + 1;
        } else /* ilevel == 1 */ {
        } else /* ilevel == 1 */ {
-               nif = isize / (BSIZE * NINDIR) + 1;
+               nif = isize / (sblock.fs_bsize * NINDIR(&sblock)) + 1;
        }
        }
-       if (nif > NINDIR)
-               nif = NINDIR;
+       if (nif > NINDIR(&sblock))
+               nif = NINDIR(&sblock);
        aplim = & ib.b_un.b_indir[nif];
        for (ap = ib.b_un.b_indir, i = 1; ap < aplim; ap++, i++)
                if (*ap) {
                        if (ilevel > 0)
        aplim = & ib.b_un.b_indir[nif];
        for (ap = ib.b_un.b_indir, i = 1; ap < aplim; ap++, i++)
                if (*ap) {
                        if (ilevel > 0)
-                               n = iblock(*ap, ilevel, flg, isize - i * NINDIR * BSIZE);
+                               n = iblock(*ap, ilevel, flg, isize - i * NINDIR(&sblock) * sblock.fs_bsize);
                        else
                        else
-                               n = (*func)(*ap, FRAG);
+                               n = (*func)(*ap, sblock.fs_frag);
                        if (n & STOP)
                                return (n);
                }
                        if (n & STOP)
                                return (n);
                }
@@ -1038,14 +1041,14 @@ dirscan(blk, nf)
        DIRECT direntry;
 
        if (outrange(blk)) {
        DIRECT direntry;
 
        if (outrange(blk)) {
-               filsize -= BSIZE;
+               filsize -= sblock.fs_bsize;
                return (SKIP);
        }
                return (SKIP);
        }
-       edirp = &dirblk.b_dir[NDIRECT*nf/FRAG];
+       edirp = &dirblk.b_dir[NDIRECT(&sblock)*nf/sblock.fs_frag];
        for (dirp = dirblk.b_dir; dirp < edirp &&
                filsize > 0; dirp++, filsize -= sizeof(DIRECT)) {
        for (dirp = dirblk.b_dir; dirp < edirp &&
                filsize > 0; dirp++, filsize -= sizeof(DIRECT)) {
-               if (getblk(&fileblk, blk, nf * FSIZE) == NULL) {
-                       filsize -= (&dirblk.b_dir[NDIRECT]-dirp)*sizeof(DIRECT);
+               if (getblk(&fileblk, blk, nf * sblock.fs_fsize) == NULL) {
+                       filsize -= (&dirblk.b_dir[NDIRECT(&sblock)]-dirp)*sizeof(DIRECT);
                        return (SKIP);
                }
                p1 = &dirp->d_name[DIRSIZ];
                        return (SKIP);
                }
                p1 = &dirp->d_name[DIRSIZ];
@@ -1053,7 +1056,7 @@ dirscan(blk, nf)
                while (p1 > (char *)dirp)
                        *--p2 = *--p1;
                if ((n = (*pfunc)(&direntry)) & ALTERD) {
                while (p1 > (char *)dirp)
                        *--p2 = *--p1;
                if ((n = (*pfunc)(&direntry)) & ALTERD) {
-                       if (getblk(&fileblk, blk, nf * FSIZE) != NULL) {
+                       if (getblk(&fileblk, blk, nf * sblock.fs_fsize) != NULL) {
                                p1 = &dirp->d_name[DIRSIZ];
                                p2 = &direntry.d_name[DIRSIZ];
                                while (p1 > (char *)dirp)
                                p1 = &dirp->d_name[DIRSIZ];
                                p2 = &direntry.d_name[DIRSIZ];
                                while (p1 > (char *)dirp)
@@ -1190,11 +1193,10 @@ setup(dev)
        initbarea(&fileblk);
        initbarea(&inoblk);
        initbarea(&cgblk);
        initbarea(&fileblk);
        initbarea(&inoblk);
        initbarea(&cgblk);
-       if (getblk(&sblk, super, BSIZE) == NULL) {
-               ckfini();
+       if (bread(&dfile, &sblock, super, MAXBSIZE) == 0)
                return (0);
                return (0);
-       }
        sblk.b_bno = super;
        sblk.b_bno = super;
+       sblk.b_size = MAXBSIZE;
        if (sblock.fs_magic != FS_MAGIC)
                { badsb("MAGIC NUMBER WRONG"); return (0); }
        if (sblock.fs_ncg < 1)
        if (sblock.fs_magic != FS_MAGIC)
                { badsb("MAGIC NUMBER WRONG"); return (0); }
        if (sblock.fs_ncg < 1)
@@ -1205,21 +1207,21 @@ setup(dev)
                { badsb("NSECT < 1"); return (0); }
        if (sblock.fs_ntrak < 1)
                { badsb("NTRAK < 1"); return (0); }
                { badsb("NSECT < 1"); return (0); }
        if (sblock.fs_ntrak < 1)
                { badsb("NTRAK < 1"); return (0); }
-       if (sblock.fs_ipg*sblock.fs_ncg > 65535 || sblock.fs_ipg%INOPB)
+       if (sblock.fs_ipg*sblock.fs_ncg > 65535 || sblock.fs_ipg%INOPB(&sblock))
                { badsb("TOO MANY INODES IMPLIED"); return (0); }
                { badsb("TOO MANY INODES IMPLIED"); return (0); }
-       if (sblock.fs_ipg/INOPF+IBLOCK >=
-           sblock.fs_cpg*sblock.fs_nsect*sblock.fs_ntrak/NSPF)
+       if (sblock.fs_ipg/INOPF(&sblock)+IBLOCK(&sblock) >=
+           sblock.fs_cpg*sblock.fs_nsect*sblock.fs_ntrak/NSPF(&sblock))
                { badsb("IMPLIES MORE INODE THAN DATA BLOCKS"); return (0); }
 /* THE FOLLOWING COULD BE CHECKED MORE CLOSELY... */
        if ((sblock.fs_ncg + 1) * sblock.fs_cpg < sblock.fs_ncyl ||
            (sblock.fs_ncg - 1) * sblock.fs_cpg > sblock.fs_ncyl)
                { badsb("NCYL DOES NOT JIVE WITH NCG*CPG"); return (0); }
                { badsb("IMPLIES MORE INODE THAN DATA BLOCKS"); return (0); }
 /* THE FOLLOWING COULD BE CHECKED MORE CLOSELY... */
        if ((sblock.fs_ncg + 1) * sblock.fs_cpg < sblock.fs_ncyl ||
            (sblock.fs_ncg - 1) * sblock.fs_cpg > sblock.fs_ncyl)
                { badsb("NCYL DOES NOT JIVE WITH NCG*CPG"); return (0); }
-       if (sblock.fs_fpg != sblock.fs_cpg * sblock.fs_spc / NSPF)
+       if (sblock.fs_fpg != sblock.fs_cpg * sblock.fs_spc / NSPF(&sblock))
                { badsb("FPG DOES NOT JIVE WITH CPG & SPC"); return (0); }
        if (sblock.fs_size <=
                { badsb("FPG DOES NOT JIVE WITH CPG & SPC"); return (0); }
        if (sblock.fs_size <=
-           (sblock.fs_ncg-1)*sblock.fs_fpg+IBLOCK+sblock.fs_ipg/INOPF)
+           (sblock.fs_ncg-1)*sblock.fs_fpg+IBLOCK(&sblock)+sblock.fs_ipg/INOPF(&sblock))
                { badsb("SIZE PREPOSTEROUSLY SMALL"); return (0); }
                { badsb("SIZE PREPOSTEROUSLY SMALL"); return (0); }
-       if (sblock.fs_size*NSPF >
+       if (sblock.fs_size*NSPF(&sblock) >
            (sblock.fs_ncg+2)*sblock.fs_cpg*sblock.fs_spc)
                { badsb("SIZE PREPOSTEROUSLY LARGE"); return (0); }
        /* rest we COULD repair... */
            (sblock.fs_ncg+2)*sblock.fs_cpg*sblock.fs_spc)
                { badsb("SIZE PREPOSTEROUSLY LARGE"); return (0); }
        /* rest we COULD repair... */
@@ -1229,7 +1231,7 @@ setup(dev)
                { badsb("SPC DOES NOT JIVE w/NTRAK*NSECT"); return (0); }
        if (sblock.fs_cgsize != cgsize(&sblock))
                { badsb("CGSIZE INCORRECT"); return (0); }
                { badsb("SPC DOES NOT JIVE w/NTRAK*NSECT"); return (0); }
        if (sblock.fs_cgsize != cgsize(&sblock))
                { badsb("CGSIZE INCORRECT"); return (0); }
-       if (sblock.fs_cssize != cssize(&sblock))
+       if (sblock.fs_cssize != sblock.fs_ncg * sizeof(struct csum))
                { badsb("CSSIZE INCORRECT"); return (0); }
        fmax = sblock.fs_size;
        imax = sblock.fs_ncg * sblock.fs_ipg;
                { badsb("CSSIZE INCORRECT"); return (0); }
        fmax = sblock.fs_size;
        imax = sblock.fs_ncg * sblock.fs_ipg;
@@ -1266,14 +1268,14 @@ ginode()
 
        if (inum > imax)
                return (NULL);
 
        if (inum > imax)
                return (NULL);
-       if (inum < startinum || inum >= startinum + INOPB) {
+       if (inum < startinum || inum >= startinum + INOPB(&sblock)) {
                iblk = itod(inum, &sblock);
                iblk = itod(inum, &sblock);
-               if (getblk(&inoblk, iblk, BSIZE) == NULL) {
+               if (getblk(&inoblk, iblk, sblock.fs_bsize) == NULL) {
                        return (NULL);
                }
                        return (NULL);
                }
-               startinum = (inum / INOPB) * INOPB;
+               startinum = (inum / INOPB(&sblock)) * INOPB(&sblock);
        }
        }
-       return (&inoblk.b_un.b_dinode[inum % INOPB]);
+       return (&inoblk.b_un.b_dinode[inum % INOPB(&sblock)]);
 }
 
 ftypeok(dp)
 }
 
 ftypeok(dp)
@@ -1346,13 +1348,15 @@ getblk(bp, blk, size)
        int size;
 {
        register struct filecntl *fcp;
        int size;
 {
        register struct filecntl *fcp;
+       daddr_t dblk;
 
        fcp = &dfile;
 
        fcp = &dfile;
-       if (bp->b_bno == blk)
+       dblk = fsbtodb(&sblock, blk);
+       if (bp->b_bno == dblk)
                return (bp);
        flush(fcp, bp);
                return (bp);
        flush(fcp, bp);
-       if (bread(fcp, bp->b_un.b_buf, blk, size) != 0) {
-               bp->b_bno = blk;
+       if (bread(fcp, bp->b_un.b_buf, dblk, size) != 0) {
+               bp->b_bno = dblk;
                bp->b_size = size;
                return (bp);
        }
                bp->b_size = size;
                return (bp);
        }
@@ -1445,10 +1449,10 @@ makecg()
        sblock.fs_cstotal.cs_nffree = 0;
        sblock.fs_cstotal.cs_nifree = 0;
        sblock.fs_cstotal.cs_ndir = 0;
        sblock.fs_cstotal.cs_nffree = 0;
        sblock.fs_cstotal.cs_nifree = 0;
        sblock.fs_cstotal.cs_ndir = 0;
-       for (i = 0; i < howmany(cssize(&sblock), BSIZE); i++) {
-               sblock.fs_csp[i] = (struct csum *)calloc(1, BSIZE);
+       for (i = 0; i < howmany(sblock.fs_cssize, sblock.fs_bsize); i++) {
+               sblock.fs_csp[i] = (struct csum *)calloc(1, sblock.fs_bsize);
                getblk((char *)sblock.fs_csp[i],
                getblk((char *)sblock.fs_csp[i],
-                      csaddr(&sblock) + (i * FRAG), BSIZE);
+                   sblock.fs_csaddr + (i * sblock.fs_frag), sblock.fs_bsize);
        }
        for (c = 0; c < sblock.fs_ncg; c++) {
                dbase = cgbase(c, &sblock);
        }
        for (c = 0; c < sblock.fs_ncg; c++) {
                dbase = cgbase(c, &sblock);
@@ -1456,7 +1460,7 @@ makecg()
                if (dmax > sblock.fs_size)
                        dmax = sblock.fs_size;
                dmin = cgdmin(c, &sblock) - dbase;
                if (dmax > sblock.fs_size)
                        dmax = sblock.fs_size;
                dmin = cgdmin(c, &sblock) - dbase;
-               cs = &sblock.fs_cs(c);
+               cs = &sblock.fs_cs(&sblock, c);
                cgrp.cg_time = time(0);
                cgrp.cg_magic = CG_MAGIC;
                cgrp.cg_cgx = c;
                cgrp.cg_time = time(0);
                cgrp.cg_magic = CG_MAGIC;
                cgrp.cg_cgx = c;
@@ -1470,7 +1474,7 @@ makecg()
                cgrp.cg_rotor = dmin;
                cgrp.cg_frotor = dmin;
                cgrp.cg_irotor = 0;
                cgrp.cg_rotor = dmin;
                cgrp.cg_frotor = dmin;
                cgrp.cg_irotor = 0;
-               for (i = 0; i < FRAG; i++)
+               for (i = 0; i < sblock.fs_frag; i++)
                        cgrp.cg_frsum[i] = 0;
                inum = sblock.fs_ipg * c;
                for (i = 0; i < sblock.fs_ipg; inum++, i++) {
                        cgrp.cg_frsum[i] = 0;
                inum = sblock.fs_ipg * c;
                for (i = 0; i < sblock.fs_ipg; inum++, i++) {
@@ -1494,29 +1498,29 @@ makecg()
                        for (i = 0; i < NRPOS; i++)
                                cgrp.cg_b[s][i] = 0;
                if (c == 0) {
                        for (i = 0; i < NRPOS; i++)
                                cgrp.cg_b[s][i] = 0;
                if (c == 0) {
-                       dmin += howmany(cssize(&sblock), BSIZE) * FRAG;
+                       dmin += howmany(sblock.fs_cssize, sblock.fs_bsize) * sblock.fs_frag;
                }
                for (d = 0; d < dmin; d++)
                        clrbit(cgrp.cg_free, d);
                }
                for (d = 0; d < dmin; d++)
                        clrbit(cgrp.cg_free, d);
-               for (; (d + FRAG) <= dmax - dbase; d += FRAG) {
+               for (; (d + sblock.fs_frag) <= dmax - dbase; d += sblock.fs_frag) {
                        j = 0;
                        j = 0;
-                       for (i = 0; i < FRAG; i++) {
+                       for (i = 0; i < sblock.fs_frag; i++) {
                                if (!getbmap(dbase+d+i)) {
                                        setbit(cgrp.cg_free, d+i);
                                        j++;
                                } else
                                        clrbit(cgrp.cg_free, d+i);
                        }
                                if (!getbmap(dbase+d+i)) {
                                        setbit(cgrp.cg_free, d+i);
                                        j++;
                                } else
                                        clrbit(cgrp.cg_free, d+i);
                        }
-                       if (j == FRAG) {
+                       if (j == sblock.fs_frag) {
                                cgrp.cg_cs.cs_nbfree++;
                                cgrp.cg_cs.cs_nbfree++;
-                               s = d * NSPF;
+                               s = d * NSPF(&sblock);
                                cgrp.cg_b[s/sblock.fs_spc]
                                  [s%sblock.fs_nsect*NRPOS/sblock.fs_nsect]++;
                        } else if (j > 0) {
                                cgrp.cg_cs.cs_nffree += j;
                                blk = ((cgrp.cg_free[d / NBBY] >> (d % NBBY)) &
                                cgrp.cg_b[s/sblock.fs_spc]
                                  [s%sblock.fs_nsect*NRPOS/sblock.fs_nsect]++;
                        } else if (j > 0) {
                                cgrp.cg_cs.cs_nffree += j;
                                blk = ((cgrp.cg_free[d / NBBY] >> (d % NBBY)) &
-                                      (0xff >> (NBBY - FRAG)));
-                               fragacct(blk, cgrp.cg_frsum, 1);
+                                      (0xff >> (NBBY - sblock.fs_frag)));
+                               fragacct(&sblock, blk, cgrp.cg_frsum, 1);
                        }
                }
                for (j = d; d < dmax - dbase; d++) {
                        }
                }
                for (j = d; d < dmax - dbase; d++) {
@@ -1528,21 +1532,23 @@ makecg()
                }
                if (j != d) {
                        blk = ((cgrp.cg_free[j / NBBY] >> (j % NBBY)) &
                }
                if (j != d) {
                        blk = ((cgrp.cg_free[j / NBBY] >> (j % NBBY)) &
-                              (0xff >> (NBBY - FRAG)));
-                       fragacct(blk, cgrp.cg_frsum, 1);
+                              (0xff >> (NBBY - sblock.fs_frag)));
+                       fragacct(&sblock, blk, cgrp.cg_frsum, 1);
                }
                }
-               for (; d < MAXBPG; d++)
+               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;
                        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(&dfile, &cgrp, cgtod(c, &sblock), sblock.fs_cgsize);
+               bwrite(&dfile, &cgrp, fsbtodb(&sblock, cgtod(c, &sblock)),
+                       roundup(sblock.fs_cgsize, DEV_BSIZE));
        }
        }
-       for (i = 0; i < howmany(cssize(&sblock), BSIZE); i++) {
+       for (i = 0; i < howmany(sblock.fs_cssize, sblock.fs_bsize); i++) {
                bwrite(&dfile, (char *)sblock.fs_csp[i],
                bwrite(&dfile, (char *)sblock.fs_csp[i],
-                      csaddr(&sblock) + (i * FRAG), BSIZE);
+                   fsbtodb(&sblock, sblock.fs_csaddr + (i * sblock.fs_frag)),
+                   sblock.fs_bsize);
        }
        sblock.fs_ronly = 0;
        sblock.fs_fmod = 0;
        }
        sblock.fs_ronly = 0;
        sblock.fs_fmod = 0;
@@ -1553,7 +1559,8 @@ makecg()
  * update the frsum fields to reflect addition or deletion 
  * of some frags
  */
  * update the frsum fields to reflect addition or deletion 
  * of some frags
  */
-fragacct(fragmap, fraglist, cnt)
+fragacct(fs, fragmap, fraglist, cnt)
+       struct fs *fs;
        int fragmap;
        long fraglist[];
        int cnt;
        int fragmap;
        long fraglist[];
        int cnt;
@@ -1562,14 +1569,14 @@ fragacct(fragmap, fraglist, cnt)
        register int field, subfield;
        register int siz, pos;
 
        register int field, subfield;
        register int siz, pos;
 
-       inblk = (int)(fragtbl[fragmap] << 1);
+       inblk = (int)(fragtbl[fs->fs_frag][fragmap] << 1);
        fragmap <<= 1;
        fragmap <<= 1;
-       for (siz = 1; siz < FRAG; siz++) {
+       for (siz = 1; siz < fs->fs_frag; siz++) {
                if (((1 << siz) & inblk) == 0)
                        continue;
                field = around[siz];
                subfield = inside[siz];
                if (((1 << siz) & inblk) == 0)
                        continue;
                field = around[siz];
                subfield = inside[siz];
-               for (pos = siz; pos <= FRAG; pos++) {
+               for (pos = siz; pos <= fs->fs_frag; pos++) {
                        if ((fragmap & field) == subfield) {
                                fraglist[siz] += cnt;
                                pos += siz;
                        if ((fragmap & field) == subfield) {
                                fraglist[siz] += cnt;
                                pos += siz;
@@ -1675,8 +1682,8 @@ linkup()
                printf("\n\n");
                return (0);
        }
                printf("\n\n");
                return (0);
        }
-       if (dp->di_size & BMASK) {
-               dp->di_size = roundup(dp->di_size, BSIZE);
+       if (dp->di_size % sblock.fs_bsize) {
+               dp->di_size = roundup(dp->di_size, sblock.fs_bsize);
                inodirty();
        }
        filsize = dp->di_size;
                inodirty();
        }
        filsize = dp->di_size;
@@ -1714,7 +1721,7 @@ bread(fcp, buf, blk, size)
        register size;
        char *buf;
 {
        register size;
        char *buf;
 {
-       if (lseek(fcp->rfdes, blk*FSIZE, 0) < 0)
+       if (lseek(fcp->rfdes, blk * DEV_BSIZE, 0) < 0)
                rwerr("SEEK", blk);
        else if (read(fcp->rfdes, buf, size) == size)
                return (1);
                rwerr("SEEK", blk);
        else if (read(fcp->rfdes, buf, size) == size)
                return (1);
@@ -1731,7 +1738,7 @@ bwrite(fcp, buf, blk, size)
 
        if (fcp->wfdes < 0)
                return (0);
 
        if (fcp->wfdes < 0)
                return (0);
-       if (lseek(fcp->wfdes, blk*FSIZE, 0) < 0)
+       if (lseek(fcp->wfdes, blk * DEV_BSIZE, 0) < 0)
                rwerr("SEEK", blk);
        else if (write(fcp->wfdes, buf, size) == size) {
                fcp->mod = 1;
                rwerr("SEEK", blk);
        else if (write(fcp->wfdes, buf, size) == size) {
                fcp->mod = 1;
@@ -1747,3 +1754,32 @@ catch()
        ckfini();
        exit(12);
 }
        ckfini();
        exit(12);
 }
+
+/*
+ * block operations
+ */
+
+isblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       unsigned char mask;
+
+       switch (fs->fs_frag) {
+       case 8:
+               return (cp[h] == 0xff);
+       case 4:
+               mask = 0x0f << ((h & 0x1) << 2);
+               return ((cp[h >> 1] & mask) == mask);
+       case 2:
+               mask = 0x03 << ((h & 0x3) << 1);
+               return ((cp[h >> 2] & mask) == mask);
+       case 1:
+               mask = 0x01 << (h & 0x7);
+               return ((cp[h >> 3] & mask) == mask);
+       default:
+               fprintf(stderr, "isblock bad fs_frag %d\n", fs->fs_frag);
+               return;
+       }
+}
index a5fd021..86a16d2 100644 (file)
@@ -1,10 +1,11 @@
-static char *sccsid = "@(#)icheck.c    1.9 (Berkeley) %G%";
+static char *sccsid = "@(#)icheck.c    1.10 (Berkeley) %G%";
 
 /*
  * icheck
  */
 #define        NB      500
 #define        MAXFN   500
 
 /*
  * icheck
  */
 #define        NB      500
 #define        MAXFN   500
+#define MAXNINDIR (MAXBSIZE / sizeof (daddr_t))
 
 #ifndef STANDALONE
 #include <stdio.h>
 
 #ifndef STANDALONE
 #include <stdio.h>
@@ -15,13 +16,13 @@ static      char *sccsid = "@(#)icheck.c    1.9 (Berkeley) %G%";
 
 union {
        struct  fs sb;
 
 union {
        struct  fs sb;
-       char pad[BSIZE];
+       char pad[MAXBSIZE];
 } sbun;
 #define        sblock sbun.sb
 
 union {
        struct  cg cg;
 } sbun;
 #define        sblock sbun.sb
 
 union {
        struct  cg cg;
-       char pad[BSIZE];
+       char pad[MAXBSIZE];
 } cgun;
 #define        cgrp cgun.cg
 
 } cgun;
 #define        cgrp cgun.cg
 
@@ -55,7 +56,7 @@ daddr_t       ndup;
 int    nerror;
 
 extern int inside[], around[];
 int    nerror;
 
 extern int inside[], around[];
-extern unsigned char fragtbl[];
+extern unsigned char *fragtbl[];
 
 long   atol();
 #ifndef STANDALONE
 
 long   atol();
 #ifndef STANDALONE
@@ -146,17 +147,9 @@ check(file)
 #ifndef STANDALONE
        sync();
 #endif
 #ifndef STANDALONE
        sync();
 #endif
-       bread(SBLOCK, (char *)&sblock, BSIZE);
-       if (sblock.fs_magic != FS_MAGIC) {
-               printf("%s: bad magic number\n", file);
-               nerror |= 04;
+       getsb(&sblock, file);
+       if (nerror)
                return;
                return;
-       }
-       for (n = 0; n < howmany(cssize(&sblock), BSIZE); n++) {
-               sblock.fs_csp[n] = (struct csum *)calloc(1, BSIZE);
-               bread(csaddr(&sblock) + (n * FRAG),
-                     (char *)sblock.fs_csp[n], BSIZE);
-       }
        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
@@ -179,26 +172,27 @@ check(file)
                        bmap[i] = 0;
                for (c=0; c < sblock.fs_ncg; c++) {
                        cgd = cgtod(c, &sblock);
                        bmap[i] = 0;
                for (c=0; c < sblock.fs_ncg; c++) {
                        cgd = cgtod(c, &sblock);
-                       for (d = cgbase(c, &sblock); d < cgd; d += FRAG)
-                               chk(d, "badcg", BSIZE);
+                       for (d = cgbase(c, &sblock); d < cgd; d += sblock.fs_frag)
+                               chk(d, "badcg", sblock.fs_bsize);
                        d = cgimin(c, &sblock);
                        while (cgd < d) {
                        d = cgimin(c, &sblock);
                        while (cgd < d) {
-                               chk(cgd, "cg", BSIZE);
-                               cgd += FRAG;
+                               chk(cgd, "cg", sblock.fs_bsize);
+                               cgd += sblock.fs_frag;
                        }
                        d = cgdmin(c, &sblock);
                        }
                        d = cgdmin(c, &sblock);
-                       for (; cgd < d; cgd += FRAG)
-                               chk(cgd, "inode", BSIZE);
+                       for (; cgd < d; cgd += sblock.fs_frag)
+                               chk(cgd, "inode", sblock.fs_bsize);
                        if (c == 0) {
                        if (c == 0) {
-                               d += howmany(cssize(&sblock), FSIZE);
-                               for (; cgd < d; cgd += FRAG)
-                                       chk(cgd, "csum", BSIZE);
+                               d += howmany(sblock.fs_cssize, sblock.fs_bsize)
+                                   * sblock.fs_frag;
+                               for (; cgd < d; cgd += sblock.fs_frag)
+                                       chk(cgd, "csum", sblock.fs_bsize);
                        }
                }
        }
        cginit = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
                        }
                }
        }
        cginit = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
-               bread(cgimin(c,&sblock), (char *)itab,
+               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]);
                    sblock.fs_ipg * sizeof (struct dinode));
                for (j=0; j < sblock.fs_ipg; j++) {
                        pass1(&itab[j]);
@@ -209,7 +203,6 @@ check(file)
 #ifndef STANDALONE
        sync();
 #endif
 #ifndef STANDALONE
        sync();
 #endif
-       bread(SBLOCK, (char *)&sblock, sizeof(sblock));
        if (sflg) {
                makecg();
                close(fi);
        if (sflg) {
                makecg();
                close(fi);
@@ -223,15 +216,17 @@ check(file)
        nbfree = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
                cbase = cgbase(c,&sblock);
        nbfree = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
                cbase = cgbase(c,&sblock);
-               bread(cgtod(c,&sblock), (char *)&cgrp, sblock.fs_cgsize);
-               for (b = 0; b < sblock.fs_fpg; b += FRAG) {
-                       if (isblock(cgrp.cg_free, b / FRAG)) {
+               bread(fsbtodb(&sblock, cgtod(c,&sblock)), (char *)&cgrp,
+                       sblock.fs_cgsize);
+               for (b = 0; b < sblock.fs_fpg; b += sblock.fs_frag) {
+                       if (isblock(&sblock, cgrp.cg_free,
+                           b / sblock.fs_frag)) {
                                nbfree++;
                                nbfree++;
-                               chk(cbase+b, "block", BSIZE);
+                               chk(cbase+b, "block", sblock.fs_bsize);
                        } else {
                        } else {
-                               for (d = 0; d < FRAG; d++)
+                               for (d = 0; d < sblock.fs_frag; d++)
                                        if (isset(cgrp.cg_free, b+d)) {
                                        if (isset(cgrp.cg_free, b+d)) {
-                                               chk(cbase+b+d, "frag", FSIZE);
+                                               chk(cbase+b+d, "frag", sblock.fs_fsize);
                                                nffree++;
                                        }
                        }
                                                nffree++;
                                        }
                        }
@@ -251,22 +246,22 @@ check(file)
        printf("files %u (r=%u,d=%u,b=%u,c=%u,mc=%u)\n",
                i, nrfile, ndfile, nbfile, ncfile, nmcfile);
 #endif
        printf("files %u (r=%u,d=%u,b=%u,c=%u,mc=%u)\n",
                i, nrfile, ndfile, nbfile, ncfile, nmcfile);
 #endif
-       n = (nblock + nindir + niindir) * FRAG + nfrag;
+       n = (nblock + nindir + niindir) * sblock.fs_frag + nfrag;
 #ifdef STANDALONE
        printf("used %ld (i=%ld,ii=%ld,b=%ld,f=%ld)\n",
                n, nindir, niindir, nblock, nfrag);
 #ifdef STANDALONE
        printf("used %ld (i=%ld,ii=%ld,b=%ld,f=%ld)\n",
                n, nindir, niindir, nblock, nfrag);
-       printf("free %ld (b=%ld,f=%ld)\n", nffree + FRAG * nbfree,
+       printf("free %ld (b=%ld,f=%ld)\n", nffree + sblock.fs_frag * nbfree,
            nbfree, nffree);
 #else
        printf("used %7ld (i=%ld,ii=%ld,b=%ld,f=%ld)\n",
                n, nindir, niindir, nblock, nfrag);
            nbfree, nffree);
 #else
        printf("used %7ld (i=%ld,ii=%ld,b=%ld,f=%ld)\n",
                n, nindir, niindir, nblock, nfrag);
-       printf("free %7ld (b=%ld,f=%ld)\n", nffree + FRAG * nbfree,
+       printf("free %7ld (b=%ld,f=%ld)\n", nffree + sblock.fs_frag * nbfree,
            nbfree, nffree);
 #endif
        if(!dflg) {
                n = 0;
                for (d = 0; d < sblock.fs_size; d++)
            nbfree, nffree);
 #endif
        if(!dflg) {
                n = 0;
                for (d = 0; d < sblock.fs_size; d++)
-                       if(!duped(d, FSIZE)) {
+                       if(!duped(d, sblock.fs_fsize)) {
                                if(mflg)
                                        printf("%ld missing\n", d);
                                n++;
                                if(mflg)
                                        printf("%ld missing\n", d);
                                n++;
@@ -278,8 +273,8 @@ check(file)
 pass1(ip)
        register struct dinode *ip;
 {
 pass1(ip)
        register struct dinode *ip;
 {
-       daddr_t ind1[NINDIR];
-       daddr_t ind2[NINDIR];
+       daddr_t ind1[MAXNINDIR];
+       daddr_t ind2[MAXNINDIR];
        daddr_t db, ib;
        register int i, j, k, siz;
 
        daddr_t db, ib;
        register int i, j, k, siz;
 
@@ -307,49 +302,50 @@ pass1(ip)
                db = ip->di_db[i];
                if (db == 0)
                        continue;
                db = ip->di_db[i];
                if (db == 0)
                        continue;
-               siz = dblksize(ip, i);
+               siz = dblksize(&sblock, ip, i);
                chk(db, "data (block)", siz);
                chk(db, "data (block)", siz);
-               if (siz == BSIZE)
+               if (siz == sblock.fs_bsize)
                        nblock++;
                else
                        nblock++;
                else
-                       nfrag += howmany(siz, FSIZE);
+                       nfrag += howmany(siz, sblock.fs_fsize);
        }
        for(i = 0; i < NIADDR; i++) {
                ib = ip->di_ib[i];
                if(ib == 0)
                        continue;
        }
        for(i = 0; i < NIADDR; i++) {
                ib = ip->di_ib[i];
                if(ib == 0)
                        continue;
-               if (chk(ib, "1st indirect", BSIZE))
+               if (chk(ib, "1st indirect", sblock.fs_bsize))
                        continue;
                        continue;
-               bread(ib, (char *)ind1, BSIZE);
+               bread(fsbtodb(&sblock, ib), (char *)ind1, sblock.fs_bsize);
                nindir++;
                nindir++;
-               for (j = 0; j < NINDIR; j++) {
+               for (j = 0; j < NINDIR(&sblock); j++) {
                        ib = ind1[j];
                        if (ib == 0)
                                continue;
                        if (i == 0) {
                        ib = ind1[j];
                        if (ib == 0)
                                continue;
                        if (i == 0) {
-                               siz = dblksize(ip, NDADDR + j);
+                               siz = dblksize(&sblock, ip, NDADDR + j);
                                chk(ib, "data (large)", siz);
                                chk(ib, "data (large)", siz);
-                               if (siz == BSIZE)
+                               if (siz == sblock.fs_bsize)
                                        nblock++;
                                else
                                        nblock++;
                                else
-                                       nfrag += howmany(siz, FSIZE);
+                                       nfrag += howmany(siz, sblock.fs_fsize);
                                continue;
                        }
                                continue;
                        }
-                       if (chk(ib, "2nd indirect", BSIZE))
+                       if (chk(ib, "2nd indirect", sblock.fs_bsize))
                                continue;
                                continue;
-                       bread(ib, (char *)ind2, BSIZE);
+                       bread(fsbtodb(&sblock, ib), (char *)ind2,
+                               sblock.fs_bsize);
                        niindir++;
                        niindir++;
-                       for (k = 0; k < NINDIR; k++) {
+                       for (k = 0; k < NINDIR(&sblock); k++) {
                                ib = ind2[k];
                                if (ib == 0)
                                        continue;
                                ib = ind2[k];
                                if (ib == 0)
                                        continue;
-                               siz = dblksize(ip,
-                                   NDADDR + NINDIR * (i + j) + k);
+                               siz = dblksize(&sblock, ip,
+                                   NDADDR + NINDIR(&sblock) * (i + j) + k);
                                chk(ib, "data (huge)", siz);
                                chk(ib, "data (huge)", siz);
-                               if (siz == BSIZE)
+                               if (siz == sblock.fs_bsize)
                                        nblock++;
                                else
                                        nblock++;
                                else
-                                       nfrag += howmany(siz, FSIZE);
+                                       nfrag += howmany(siz, sblock.fs_fsize);
                        }
                }
        }
                        }
                }
        }
@@ -364,19 +360,19 @@ chk(bno, s, size)
 
        cg = dtog(bno, &sblock);
        if (cginit==0 &&
 
        cg = dtog(bno, &sblock);
        if (cginit==0 &&
-           bno<cgdmin(cg,&sblock) || bno >= FRAG * sblock.fs_size) {
+           bno<cgdmin(cg,&sblock) || 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 == BSIZE) {
+       if (size == sblock.fs_bsize) {
                if (duped(bno, size)) {
                        printf("%ld dup block; inode=%u, class=%s\n",
                            bno, ino, s);
                if (duped(bno, size)) {
                        printf("%ld dup block; inode=%u, class=%s\n",
                            bno, ino, s);
-                       ndup += FRAG;
+                       ndup += sblock.fs_frag;
                }
        } else {
                }
        } else {
-               for (n = 0; n < size / FSIZE; n++) {
-                       if (duped(bno + n, FSIZE)) {
+               for (n = 0; n < size / sblock.fs_fsize; n++) {
+                       if (duped(bno + n, sblock.fs_fsize)) {
                                printf("%ld dup frag; inode=%u, class=%s\n",
                                    bno, ino, s);
                                ndup++;
                                printf("%ld dup frag; inode=%u, class=%s\n",
                                    bno, ino, s);
                                ndup++;
@@ -395,19 +391,19 @@ duped(bno, size)
 {
        if(dflg)
                return(0);
 {
        if(dflg)
                return(0);
-       if (size != FSIZE && size != BSIZE)
+       if (size != sblock.fs_fsize && size != sblock.fs_bsize)
                printf("bad size %d to duped\n", size);
                printf("bad size %d to duped\n", size);
-       if (size == FSIZE) {
+       if (size == sblock.fs_fsize) {
                if (isset(bmap, bno))
                        return(1);
                setbit(bmap, bno);
                return (0);
        }
                if (isset(bmap, bno))
                        return(1);
                setbit(bmap, bno);
                return (0);
        }
-       if (bno % FRAG != 0)
+       if (bno % sblock.fs_frag != 0)
                printf("bad bno %d to duped\n", bno);
                printf("bad bno %d to duped\n", bno);
-       if (isblock(bmap, bno/FRAG))
+       if (isblock(&sblock, bmap, bno/sblock.fs_frag))
                return (1);
                return (1);
-       setblock(bmap, bno/FRAG);
+       setblock(&sblock, bmap, bno/sblock.fs_frag);
        return(0);
 }
 
        return(0);
 }
 
@@ -423,18 +419,13 @@ makecg()
        sblock.fs_cstotal.cs_nffree = 0;
        sblock.fs_cstotal.cs_nifree = 0;
        sblock.fs_cstotal.cs_ndir = 0;
        sblock.fs_cstotal.cs_nffree = 0;
        sblock.fs_cstotal.cs_nifree = 0;
        sblock.fs_cstotal.cs_ndir = 0;
-       for (i = 0; i < howmany(cssize(&sblock), BSIZE); i++) {
-               sblock.fs_csp[i] = (struct csum *)calloc(1, BSIZE);
-               bread(csaddr(&sblock) + (i * FRAG),
-                     (char *)sblock.fs_csp[i], BSIZE);
-       }
        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;
        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(c);
+               cs = &sblock.fs_cs(&sblock, c);
                cgrp.cg_time = time(0);
                cgrp.cg_magic = CG_MAGIC;
                cgrp.cg_cgx = c;
                cgrp.cg_time = time(0);
                cgrp.cg_magic = CG_MAGIC;
                cgrp.cg_cgx = c;
@@ -448,9 +439,9 @@ makecg()
                cgrp.cg_rotor = dmin;
                cgrp.cg_frotor = dmin;
                cgrp.cg_irotor = 0;
                cgrp.cg_rotor = dmin;
                cgrp.cg_frotor = dmin;
                cgrp.cg_irotor = 0;
-               for (i = 0; i < FRAG; i++)
+               for (i = 0; i < sblock.fs_frag; i++)
                        cgrp.cg_frsum[i] = 0;
                        cgrp.cg_frsum[i] = 0;
-               bread(cgimin(c, &sblock), (char *)itab,
+               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];
                      sblock.fs_ipg * sizeof(struct dinode));
                for (i = 0; i < sblock.fs_ipg; i++) {
                        dp = &itab[i];
@@ -473,29 +464,30 @@ makecg()
                        for (i = 0; i < NRPOS; i++)
                                cgrp.cg_b[s][i] = 0;
                if (c == 0) {
                        for (i = 0; i < NRPOS; i++)
                                cgrp.cg_b[s][i] = 0;
                if (c == 0) {
-                       dmin += howmany(cssize(&sblock), BSIZE) * FRAG;
+                       dmin += howmany(sblock.fs_cssize, sblock.fs_bsize) *
+                           sblock.fs_frag;
                }
                for (d = 0; d < dmin; d++)
                        clrbit(cgrp.cg_free, d);
                }
                for (d = 0; d < dmin; d++)
                        clrbit(cgrp.cg_free, d);
-               for (; (d + FRAG) <= dmax - dbase; d += FRAG) {
+               for (; (d + sblock.fs_frag) <= dmax - dbase; d += sblock.fs_frag) {
                        j = 0;
                        j = 0;
-                       for (i = 0; i < FRAG; i++) {
+                       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 (!isset(bmap, dbase+d+i)) {
                                        setbit(cgrp.cg_free, d+i);
                                        j++;
                                } else
                                        clrbit(cgrp.cg_free, d+i);
                        }
-                       if (j == FRAG) {
+                       if (j == sblock.fs_frag) {
                                cgrp.cg_cs.cs_nbfree++;
                                cgrp.cg_cs.cs_nbfree++;
-                               s = d * NSPF;
+                               s = d * NSPF(&sblock);
                                cgrp.cg_b[s/sblock.fs_spc]
                                  [s%sblock.fs_nsect*NRPOS/sblock.fs_nsect]++;
                        } else if (j > 0) {
                                cgrp.cg_cs.cs_nffree += j;
                                blk = ((cgrp.cg_free[d / NBBY] >> (d % NBBY)) &
                                cgrp.cg_b[s/sblock.fs_spc]
                                  [s%sblock.fs_nsect*NRPOS/sblock.fs_nsect]++;
                        } else if (j > 0) {
                                cgrp.cg_cs.cs_nffree += j;
                                blk = ((cgrp.cg_free[d / NBBY] >> (d % NBBY)) &
-                                      (0xff >> (NBBY - FRAG)));
-                               fragacct(blk, cgrp.cg_frsum, 1);
+                                      (0xff >> (NBBY - sblock.fs_frag)));
+                               fragacct(&sblock, blk, cgrp.cg_frsum, 1);
                        }
                }
                for (j = d; d < dmax - dbase; d++) {
                        }
                }
                for (j = d; d < dmax - dbase; d++) {
@@ -507,32 +499,35 @@ makecg()
                }
                if (j != d) {
                        blk = ((cgrp.cg_free[j / NBBY] >> (j % NBBY)) &
                }
                if (j != d) {
                        blk = ((cgrp.cg_free[j / NBBY] >> (j % NBBY)) &
-                              (0xff >> (NBBY - FRAG)));
-                       fragacct(blk, cgrp.cg_frsum, 1);
+                              (0xff >> (NBBY - sblock.fs_frag)));
+                       fragacct(&sblock, blk, cgrp.cg_frsum, 1);
                }
                }
-               for (; d < MAXBPG; d++)
+               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;
                        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(cgtod(c, &sblock), &cgrp, sblock.fs_cgsize);
+               bwrite(fsbtodb(&sblock, cgtod(c, &sblock)), &cgrp,
+                       sblock.fs_cgsize);
        }
        }
-       for (i = 0; i < howmany(cssize(&sblock), BSIZE); i++) {
-               bwrite(csaddr(&sblock) + (i * FRAG),
-                      (char *)sblock.fs_csp[i], BSIZE);
+       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;
        }
        sblock.fs_ronly = 0;
        sblock.fs_fmod = 0;
-       bwrite(SBLOCK, (char *)&sblock, sizeof(sblock));
+       bwrite(SBLOCK, (char *)&sblock, MAXBSIZE);
 }
 
 /*
  * update the frsum fields to reflect addition or deletion 
  * of some frags
  */
 }
 
 /*
  * update the frsum fields to reflect addition or deletion 
  * of some frags
  */
-fragacct(fragmap, fraglist, cnt)
+fragacct(fs, fragmap, fraglist, cnt)
+       struct fs *fs;
        int fragmap;
        long fraglist[];
        int cnt;
        int fragmap;
        long fraglist[];
        int cnt;
@@ -541,14 +536,14 @@ fragacct(fragmap, fraglist, cnt)
        register int field, subfield;
        register int siz, pos;
 
        register int field, subfield;
        register int siz, pos;
 
-       inblk = (int)(fragtbl[fragmap] << 1);
+       inblk = (int)(fragtbl[fs->fs_frag][fragmap] << 1);
        fragmap <<= 1;
        fragmap <<= 1;
-       for (siz = 1; siz < FRAG; siz++) {
+       for (siz = 1; siz < fs->fs_frag; siz++) {
                if (((1 << siz) & inblk) == 0)
                        continue;
                field = around[siz];
                subfield = inside[siz];
                if (((1 << siz) & inblk) == 0)
                        continue;
                field = around[siz];
                subfield = inside[siz];
-               for (pos = siz; pos <= FRAG; pos++) {
+               for (pos = siz; pos <= fs->fs_frag; pos++) {
                        if ((fragmap & field) == subfield) {
                                fraglist[siz] += cnt;
                                pos += siz;
                        if ((fragmap & field) == subfield) {
                                fraglist[siz] += cnt;
                                pos += siz;
@@ -561,12 +556,36 @@ fragacct(fragmap, fraglist, cnt)
        }
 }
 
        }
 }
 
+getsb(fs, file)
+       register struct fs *fs;
+       char *file;
+{
+       int i;
+
+       if (bread(SBLOCK, fs, MAXBSIZE)) {
+               printf("bad super block");
+               perror(file);
+               nerror |= 04;
+               return;
+       }
+       if (fs->fs_magic != FS_MAGIC) {
+               printf("%s: bad magic number\n", file);
+               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;
 {
 bwrite(blk, buf, size)
        char *buf;
        daddr_t blk;
        register size;
 {
-       if (lseek(fi, blk * FSIZE, 0) < 0) {
+       if (lseek(fi, blk * DEV_BSIZE, 0) < 0) {
                perror("FS SEEK");
                return(1);
        }
                perror("FS SEEK");
                return(1);
        }
@@ -574,6 +593,7 @@ bwrite(blk, buf, size)
                perror("FS WRITE");
                return(1);
        }
                perror("FS WRITE");
                return(1);
        }
+       return (0);
 }
 
 bread(bno, buf, cnt)
 }
 
 bread(bno, buf, cnt)
@@ -582,13 +602,68 @@ bread(bno, buf, cnt)
 {
        register i;
 
 {
        register i;
 
-       lseek(fi, bno * FSIZE, 0);
+       lseek(fi, bno * DEV_BSIZE, 0);
        if ((i = read(fi, buf, cnt)) != cnt) {
                if (sflg) {
                        printf("No Update\n");
                        sflg = 0;
                }
        if ((i = read(fi, buf, cnt)) != cnt) {
                if (sflg) {
                        printf("No Update\n");
                        sflg = 0;
                }
-               for(i=0; i<BSIZE; i++)
+               for(i=0; i<sblock.fs_bsize; i++)
                        buf[i] = 0;
                        buf[i] = 0;
+               return (1);
+       }
+       return (0);
+}
+
+/*
+ * block operations
+ */
+
+isblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       unsigned char mask;
+
+       switch (fs->fs_frag) {
+       case 8:
+               return (cp[h] == 0xff);
+       case 4:
+               mask = 0x0f << ((h & 0x1) << 2);
+               return ((cp[h >> 1] & mask) == mask);
+       case 2:
+               mask = 0x03 << ((h & 0x3) << 1);
+               return ((cp[h >> 2] & mask) == mask);
+       case 1:
+               mask = 0x01 << (h & 0x7);
+               return ((cp[h >> 3] & mask) == mask);
+       default:
+               fprintf(stderr, "isblock bad fs_frag %d\n", fs->fs_frag);
+               return;
+       }
+}
+
+setblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       switch (fs->fs_frag) {
+       case 8:
+               cp[h] = 0xff;
+               return;
+       case 4:
+               cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
+               return;
+       case 2:
+               cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
+               return;
+       case 1:
+               cp[h >> 3] |= (0x01 << (h & 0x7));
+               return;
+       default:
+               fprintf(stderr, "setblock bad fs_frag %d\n", fs->fs_frag);
+               return;
        }
 }
        }
 }
index 28ddd01..1a78f5e 100644 (file)
@@ -1,11 +1,13 @@
-static char *sccsid = "@(#)ncheck.c    1.3 (Berkeley) %G%";
+static char *sccsid = "@(#)ncheck.c    1.4 (Berkeley) %G%";
 /*
  * ncheck -- obtain file names from reading filesystem
  */
 
 /*
  * ncheck -- obtain file names from reading filesystem
  */
 
-#define        NB      500
-#define        HSIZE   2503
-#define        NDIR    (BSIZE/sizeof(struct direct))
+#define        NB              500
+#define        HSIZE           2503
+#define        NDIR(fs)        ((fs)->fs_bsize/sizeof(struct direct))
+#define        MAXNDIR         (MAXBSIZE/sizeof(struct direct))
+#define        MAXNINDIR       (MAXBSIZE/sizeof(daddr_t))
 
 #include <stdio.h>
 #include "../h/param.h"
 
 #include <stdio.h>
 #include "../h/param.h"
@@ -92,7 +94,7 @@ check(file)
        nhent = 0;
        printf("%s:\n", file);
        sync();
        nhent = 0;
        printf("%s:\n", file);
        sync();
-       bread(SBLOCK, (char *)&sblock, sizeof(sblock));
+       bread(SBLOCK, (char *)&sblock, MAXBSIZE);
        if (sblock.fs_magic != FS_MAGIC) {
                printf("%s: not a file system\n", file);
                nerror++;
        if (sblock.fs_magic != FS_MAGIC) {
                printf("%s: not a file system\n", file);
                nerror++;
@@ -107,7 +109,7 @@ check(file)
        }
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
        }
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
-               bread(cgimin(c, &sblock), (char *)itab,
+               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]);
                    sblock.fs_ipg * sizeof (struct dinode));
                for(j=0; j<sblock.fs_ipg; j++) {
                        pass1(&itab[j]);
@@ -117,7 +119,7 @@ check(file)
        ilist[nxfile+1] = 0;
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
        ilist[nxfile+1] = 0;
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
-               bread(cgimin(c, &sblock), (char *)itab,
+               bread(fsbtodb(&sblock, cgimin(c, &sblock)), (char *)itab,
                    sblock.fs_ipg * sizeof (struct dinode));
                for(j=0; j<sblock.fs_ipg; j++) {
                        pass2(&itab[j]);
                    sblock.fs_ipg * sizeof (struct dinode));
                for(j=0; j<sblock.fs_ipg; j++) {
                        pass2(&itab[j]);
@@ -126,7 +128,7 @@ check(file)
        }
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
        }
        ino = 0;
        for (c = 0; c < sblock.fs_ncg; c++) {
-               bread(cgimin(c, &sblock), (char *)itab,
+               bread(fsbtodb(&sblock, cgimin(c, &sblock)), (char *)itab,
                    sblock.fs_ipg * sizeof (struct dinode));
                for(j=0; j<sblock.fs_ipg; j++) {
                        pass3(&itab[j]);
                    sblock.fs_ipg * sizeof (struct dinode));
                for(j=0; j<sblock.fs_ipg; j++) {
                        pass3(&itab[j]);
@@ -152,7 +154,7 @@ pass1(ip)
 pass2(ip)
        register struct dinode *ip;
 {
 pass2(ip)
        register struct dinode *ip;
 {
-       struct direct dbuf[NDIR];
+       struct direct dbuf[MAXNDIR];
        long doff;
        struct direct *dp;
        register i, j;
        long doff;
        struct direct *dp;
        register i, j;
@@ -171,8 +173,8 @@ pass2(ip)
                d = bmap(i);
                if(d == 0)
                        break;
                d = bmap(i);
                if(d == 0)
                        break;
-               bread(d, (char *)dbuf, sizeof(dbuf));
-               for(j=0; j<NDIR; j++) {
+               bread(fsbtodb(&sblock, d), (char *)dbuf, sizeof(dbuf));
+               for(j=0; j < NDIR(&sblock); j++) {
                        if(doff >= ip->di_size)
                                break;
                        doff += sizeof(struct direct);
                        if(doff >= ip->di_size)
                                break;
                        doff += sizeof(struct direct);
@@ -195,7 +197,7 @@ pass2(ip)
 pass3(ip)
        register struct dinode *ip;
 {
 pass3(ip)
        register struct dinode *ip;
 {
-       struct direct dbuf[NDIR];
+       struct direct dbuf[MAXNDIR];
        long doff;
        struct direct *dp;
        register i, j;
        long doff;
        struct direct *dp;
        register i, j;
@@ -213,8 +215,8 @@ pass3(ip)
                d = bmap(i);
                if(d == 0)
                        break;
                d = bmap(i);
                if(d == 0)
                        break;
-               bread(d, (char *)dbuf, sizeof(dbuf));
-               for(j=0; j<NDIR; j++) {
+               bread(fsbtodb(&sblock, d), (char *)dbuf, sizeof(dbuf));
+               for(j=0; j < NDIR(&sblock); j++) {
                        if(doff >= ip->di_size)
                                break;
                        doff += sizeof(struct direct);
                        if(doff >= ip->di_size)
                                break;
                        doff += sizeof(struct direct);
@@ -301,10 +303,10 @@ bread(bno, buf, cnt)
 {
        register i;
 
 {
        register i;
 
-       lseek(fi, bno*FSIZE, 0);
+       lseek(fi, bno * DEV_BSIZE, 0);
        if (read(fi, buf, cnt) != cnt) {
                fprintf(stderr, "ncheck: read error %d\n", bno);
        if (read(fi, buf, cnt) != cnt) {
                fprintf(stderr, "ncheck: read error %d\n", bno);
-               for(i=0; i<BSIZE; i++)
+               for(i=0; i < cnt; i++)
                        buf[i] = 0;
        }
 }
                        buf[i] = 0;
        }
 }
@@ -313,15 +315,15 @@ daddr_t
 bmap(i)
        int i;
 {
 bmap(i)
        int i;
 {
-       daddr_t ibuf[NINDIR];
+       daddr_t ibuf[MAXNINDIR];
 
        if(i < NDADDR)
                return(gip->di_db[i]);
        i -= NDADDR;
 
        if(i < NDADDR)
                return(gip->di_db[i]);
        i -= NDADDR;
-       if(i > NINDIR) {
+       if(i > NINDIR(&sblock)) {
                fprintf(stderr, "ncheck: %u - huge directory\n", ino);
                return((daddr_t)0);
        }
                fprintf(stderr, "ncheck: %u - huge directory\n", ino);
                return((daddr_t)0);
        }
-       bread(gip->di_ib[i], (char *)ibuf, sizeof(ibuf));
+       bread(fsbtodb(&sblock, gip->di_ib[i]), (char *)ibuf, sizeof(ibuf));
        return(ibuf[i]);
 }
        return(ibuf[i]);
 }
index 23b0fd7..58738b0 100644 (file)
@@ -1,13 +1,13 @@
-static char *sccsid = "@(#)mkfs.c      1.9 (Berkeley) %G%";
+static char *sccsid = "@(#)mkfs.c      1.10 (Berkeley) %G%";
 
 /*
  * make file system for cylinder-group style file systems
  *
  * usage: mkfs fs proto
 
 /*
  * make file system for cylinder-group style file systems
  *
  * usage: mkfs fs proto
- * or: mkfs size [ nsect ntrak cpg ]
+ * or: mkfs size [ bsize frag nsect ntrak cpg ]
  */
 
  */
 
-#define        NDIRECT (BSIZE/sizeof(struct direct))
+#define        NDIRECT(fs)     ((fs)->fs_bsize/sizeof(struct direct))
 #define        MAXFN   500
 
 #ifndef STANDALONE
 #define        MAXFN   500
 
 #ifndef STANDALONE
@@ -31,7 +31,7 @@ int   fin;
 int    fsi;
 int    fso;
 char   *charp;
 int    fsi;
 int    fso;
 char   *charp;
-char   buf[BSIZE];
+char   buf[MAXBSIZE];
 #ifndef STANDALONE
 struct exec head;
 #endif
 #ifndef STANDALONE
 struct exec head;
 #endif
@@ -39,20 +39,17 @@ char        string[50];
 
 union {
        struct fs fs;
 
 union {
        struct fs fs;
-       char pad[BSIZE];
+       char pad[MAXBSIZE];
 } fsun;
 #define        sblock  fsun.fs
 struct csum *fscs;
 
 union {
        struct cg cg;
 } fsun;
 #define        sblock  fsun.fs
 struct csum *fscs;
 
 union {
        struct cg cg;
-       char pad[BSIZE];
+       char pad[MAXBSIZE];
 } cgun;
 #define        acg     cgun.cg
 
 } cgun;
 #define        acg     cgun.cg
 
-#define        howmany(x, y)   (((x)+((y)-1))/(y))
-#define        roundup(x, y)   ((((x)+((y)-1))/(y))*(y))
-
 char   *fsys;
 char   *proto;
 int    error;
 char   *fsys;
 char   *proto;
 int    error;
@@ -63,7 +60,8 @@ daddr_t       alloc();
 struct dinode zino[MAXIPG];
 
 main(argc, argv)
 struct dinode zino[MAXIPG];
 
 main(argc, argv)
-char *argv[];
+       int argc;
+       char *argv[];
 {
        int f, c;
        long i,n;
 {
        int f, c;
        long i,n;
@@ -72,7 +70,7 @@ char *argv[];
 #ifndef STANDALONE
        time(&utime);
        if(argc < 2) {
 #ifndef STANDALONE
        time(&utime);
        if(argc < 2) {
-               printf("usage: mkfs sblock proto/size [ nsect ntrak cpg ]\n");
+               printf("usage: mkfs sblock proto/size [ bsize frag nsect ntrak cpg ]\n");
                exit(1);
        }
        fsys = argv[0];
                exit(1);
        }
        fsys = argv[0];
@@ -122,15 +120,20 @@ char *argv[];
                }
                read(f, (char *)&head, sizeof head);
                c = head.a_text + head.a_data;
                }
                read(f, (char *)&head, sizeof head);
                c = head.a_text + head.a_data;
-               if (c > BSIZE)
+               if (c > MAXBSIZE)
                        printf("%s: too big\n", string);
                else {
                        read(f, buf, c);
                        printf("%s: too big\n", string);
                else {
                        read(f, buf, c);
-                       wtfs(BBLOCK, BSIZE, buf);
+                       wtfs(BBLOCK, MAXBSIZE, buf);
                }
                close(f);
 noinit:
                }
                close(f);
 noinit:
-               n = sblock.fs_size = getnum();
+               n = getnum();
+               sblock.fs_bsize = MAXBSIZE;
+               sblock.fs_frag = MAXFRAG;
+               sblock.fs_fsize = MAXBSIZE / MAXFRAG;
+               sblock.fs_rotdelay = ROTDELAY;
+               sblock.fs_minfree = MINFREE;
                sblock.fs_ntrak = getnum();
                sblock.fs_nsect = getnum();
                sblock.fs_cpg = getnum();
                sblock.fs_ntrak = getnum();
                sblock.fs_nsect = getnum();
                sblock.fs_cpg = getnum();
@@ -146,52 +149,74 @@ noinit:
                        }
                        n = n*10 + (c-'0');
                }
                        }
                        n = n*10 + (c-'0');
                }
-               sblock.fs_size = n;
                if (argc > 2)
                if (argc > 2)
-                       sblock.fs_nsect = atoi(argv[2]);
+                       sblock.fs_bsize = atoi(argv[2]);
                else
                else
-                       sblock.fs_nsect = 32;
+                       sblock.fs_bsize = MAXBSIZE;
                if (argc > 3)
                if (argc > 3)
-                       sblock.fs_ntrak = atoi(argv[3]);
+                       sblock.fs_fsize = atoi(argv[3]);
+               else
+                       sblock.fs_fsize = MAXBSIZE / MAXFRAG;
+               if (argc > 4)
+                       sblock.fs_nsect = atoi(argv[4]);
+               else
+                       sblock.fs_nsect = 32;
+               if (argc > 5)
+                       sblock.fs_ntrak = atoi(argv[5]);
                else
                        sblock.fs_ntrak = 19;
                else
                        sblock.fs_ntrak = 19;
+               sblock.fs_frag = sblock.fs_bsize / sblock.fs_fsize;
+               sblock.fs_rotdelay = ROTDELAY;
+               sblock.fs_minfree = MINFREE;
        }
        /*
         * Now have size for file system and nsect and ntrak.
         * (And, if coming from prototype, cpg).
         * Determine number of cylinders occupied by file system.
         */
        }
        /*
         * Now have size for file system and nsect and ntrak.
         * (And, if coming from prototype, cpg).
         * Determine number of cylinders occupied by file system.
         */
+       if (sblock.fs_fsize < DEV_BSIZE) {
+               printf("fragment size %d is too small, minimum is %d\n",
+                   sblock.fs_fsize, DEV_BSIZE);
+               exit(1);
+       }
+       if (sblock.fs_bsize < MINBSIZE) {
+               printf("block size %d is too small, minimum is %d\n",
+                   sblock.fs_bsize, MINBSIZE);
+               exit(1);
+       }
+       sblock.fs_size = n = dbtofsb(&sblock, n);
        if (sblock.fs_ntrak <= 0)
                printf("preposterous ntrak %d\n", sblock.fs_ntrak), exit(1);
        if (sblock.fs_nsect <= 0)
                printf("preposterous nsect %d\n", sblock.fs_nsect), exit(1);
        if (sblock.fs_size <= 0)
                printf("preposterous size %d\n", sblock.fs_size), exit(1);
        if (sblock.fs_ntrak <= 0)
                printf("preposterous ntrak %d\n", sblock.fs_ntrak), exit(1);
        if (sblock.fs_nsect <= 0)
                printf("preposterous nsect %d\n", sblock.fs_nsect), exit(1);
        if (sblock.fs_size <= 0)
                printf("preposterous size %d\n", sblock.fs_size), exit(1);
-       if (sblock.fs_ntrak * sblock.fs_nsect > MAXBPG * NSPB) {
+       if (sblock.fs_ntrak * sblock.fs_nsect > MAXBPG(&sblock) * NSPB(&sblock)) {
                printf("cylinder too large (%d sectors)\n", 
                    sblock.fs_ntrak * sblock.fs_nsect);
                printf("maximum cylinder size: %d sectors\n",
                printf("cylinder too large (%d sectors)\n", 
                    sblock.fs_ntrak * sblock.fs_nsect);
                printf("maximum cylinder size: %d sectors\n",
-                   MAXBPG * NSPB);
+                   MAXBPG(&sblock) * NSPB(&sblock));
                exit(1);
        }
                exit(1);
        }
-       sblock.fs_ncyl = n * NSPF / (sblock.fs_nsect * sblock.fs_ntrak);
-       if (n * NSPF > sblock.fs_ncyl * sblock.fs_nsect * sblock.fs_ntrak) {
+       sblock.fs_ncyl = n * NSPF(&sblock) / (sblock.fs_nsect * sblock.fs_ntrak);
+       if (n * NSPF(&sblock) > sblock.fs_ncyl * sblock.fs_nsect * sblock.fs_ntrak) {
                printf("%d sector(s) in last cylinder unused\n",
                printf("%d sector(s) in last cylinder unused\n",
-                   n * NSPF - sblock.fs_ncyl * sblock.fs_nsect * sblock.fs_ntrak);
+                   n * NSPF(&sblock) - sblock.fs_ncyl * sblock.fs_nsect * sblock.fs_ntrak);
                sblock.fs_ncyl++;
        }
        sblock.fs_magic = FS_MAGIC;
        /*
         * Validate specified/determined cpg.
         */
                sblock.fs_ncyl++;
        }
        sblock.fs_magic = FS_MAGIC;
        /*
         * Validate specified/determined cpg.
         */
-#define        CGTOOBIG(fs)    ((fs).fs_nsect*(fs).fs_ntrak*(fs).fs_cpg/NSPB > MAXBPG)
-       if (argc > 4 || fin) {
+#define        CGTOOBIG(fs) \
+   ((fs).fs_nsect * (fs).fs_ntrak * (fs).fs_cpg/NSPB(&sblock) > MAXBPG(&sblock))
+       if (argc > 6 || fin) {
                if (fin == NULL)
                if (fin == NULL)
-                       sblock.fs_cpg = atoi(argv[4]);
+                       sblock.fs_cpg = atoi(argv[6]);
                if (CGTOOBIG(sblock)) {
                        printf("cylinder group too large (%d blocks); ",
                if (CGTOOBIG(sblock)) {
                        printf("cylinder group too large (%d blocks); ",
-                           sblock.fs_cpg * sblock.fs_nsect * sblock.fs_ntrak / NSPB);
-                       printf("max: %d blocks\n", MAXBPG);
+                           sblock.fs_cpg * sblock.fs_nsect * sblock.fs_ntrak / NSPB(&sblock));
+                       printf("max: %d blocks\n", MAXBPG(&sblock));
                        exit(1);
                }
                if (sblock.fs_cpg > MAXCPG) {
                        exit(1);
                }
                if (sblock.fs_cpg > MAXCPG) {
@@ -210,39 +235,41 @@ noinit:
        sblock.fs_ncg = sblock.fs_ncyl / sblock.fs_cpg;
        if (sblock.fs_ncyl % sblock.fs_cpg)
                sblock.fs_ncg++;
        sblock.fs_ncg = sblock.fs_ncyl / sblock.fs_cpg;
        if (sblock.fs_ncyl % sblock.fs_cpg)
                sblock.fs_ncg++;
-       if ((sblock.fs_nsect*sblock.fs_ntrak*sblock.fs_cpg) % NSPF) {
+       if ((sblock.fs_nsect*sblock.fs_ntrak*sblock.fs_cpg) % NSPF(&sblock)) {
                printf("mkfs: nsect %d, ntrak %d, cpg %d is not tolerable\n",
                    sblock.fs_nsect, sblock.fs_ntrak, sblock.fs_cpg);
                printf("as this would would have cyl groups whose size\n");
                printf("mkfs: nsect %d, ntrak %d, cpg %d is not tolerable\n",
                    sblock.fs_nsect, sblock.fs_ntrak, sblock.fs_cpg);
                printf("as this would would have cyl groups whose size\n");
-               printf("is not a multiple of %d; choke!\n", FSIZE);
+               printf("is not a multiple of %d; choke!\n", sblock.fs_fsize);
                exit(1);
        }
        fscs = (struct csum *)
                exit(1);
        }
        fscs = (struct csum *)
-           calloc(1, roundup(sblock.fs_ncg * sizeof (struct csum), BSIZE));
+           calloc(1, roundup(sblock.fs_ncg * sizeof (struct csum),
+               sblock.fs_bsize));
        /*
         * Compute number of inode blocks per cylinder group.
         * Start with one inode per NBPI bytes; adjust as necessary.
         */
        /*
         * Compute number of inode blocks per cylinder group.
         * Start with one inode per NBPI bytes; adjust as necessary.
         */
-       n = ((n * BSIZE) / NBPI) / INOPB;
+       n = ((n * sblock.fs_fsize) / NBPI) / INOPB(&sblock);
        if (n <= 0)
                n = 1;
        if (n <= 0)
                n = 1;
-       if (n > 65500/INOPB)
-               n = 65500/INOPB;
-       sblock.fs_ipg = ((n / sblock.fs_ncg) + 1) * INOPB;
-       if (sblock.fs_ipg < INOPB)
-               sblock.fs_ipg = INOPB;
+       sblock.fs_ipg = ((n / sblock.fs_ncg) + 1) * INOPB(&sblock);
+       if (sblock.fs_ipg < INOPB(&sblock))
+               sblock.fs_ipg = INOPB(&sblock);
        if (sblock.fs_ipg > MAXIPG)
                sblock.fs_ipg = MAXIPG;
        if (sblock.fs_ipg > MAXIPG)
                sblock.fs_ipg = MAXIPG;
-       while (sblock.fs_ipg * sblock.fs_ncyl > 65500)
-               sblock.fs_ipg -= INOPB;
        sblock.fs_spc = sblock.fs_ntrak * sblock.fs_nsect;
        sblock.fs_spc = sblock.fs_ntrak * sblock.fs_nsect;
-       sblock.fs_fpg = (sblock.fs_cpg * sblock.fs_spc) / (FSIZE / 512);
-       if (cgdmin(0,&sblock) >= sblock.fs_fpg)
+       sblock.fs_fpg = (sblock.fs_cpg * sblock.fs_spc) /
+                       (sblock.fs_fsize / SECTSIZE);
+       if (cgdmin(0,&sblock) >= sblock.fs_fpg) {
                printf("inode blocks/cyl group (%d) >= data blocks (%d)\n",
                printf("inode blocks/cyl group (%d) >= data blocks (%d)\n",
-                   cgdmin(0,&sblock)/FRAG, sblock.fs_fpg/FRAG), exit(1);
+                   cgdmin(0,&sblock) / sblock.fs_frag,
+                   sblock.fs_fpg / sblock.fs_frag);
+               exit(1);
+       }
        sblock.fs_cstotal.cs_nifree = sblock.fs_ipg * sblock.fs_ncg;
        sblock.fs_cgsize = cgsize(&sblock);
        sblock.fs_cstotal.cs_nifree = sblock.fs_ipg * sblock.fs_ncg;
        sblock.fs_cgsize = cgsize(&sblock);
-       sblock.fs_cssize = cssize(&sblock);
+       sblock.fs_csaddr = cgdmin(0, &sblock);
+       sblock.fs_cssize = sblock.fs_ncg * sizeof(struct csum);
        sblock.fs_sblkno = SBLOCK;
        sblock.fs_fmod = 0;
        sblock.fs_ronly = 0;
        sblock.fs_sblkno = SBLOCK;
        sblock.fs_fmod = 0;
        sblock.fs_ronly = 0;
@@ -251,12 +278,15 @@ noinit:
         * Dump out information about file system.
         */
        printf("%s:\t%d sectors in %d cylinders of %d tracks, %d sectors\n",
         * Dump out information about file system.
         */
        printf("%s:\t%d sectors in %d cylinders of %d tracks, %d sectors\n",
-           fsys, sblock.fs_size*NSPF, sblock.fs_ncyl, sblock.fs_ntrak, sblock.fs_nsect);
+           fsys, sblock.fs_size*NSPF(&sblock), sblock.fs_ncyl,
+           sblock.fs_ntrak, sblock.fs_nsect);
        printf("\t%.1fMb in %d cyl groups (%d c/g, %.2fMb/g, %d i/g)\n",
        printf("\t%.1fMb in %d cyl groups (%d c/g, %.2fMb/g, %d i/g)\n",
-           (float)sblock.fs_size*FSIZE*1e-6, sblock.fs_ncg, sblock.fs_cpg,
-           (float)sblock.fs_fpg*FSIZE*1e-6, sblock.fs_ipg);
+           (float)sblock.fs_size * sblock.fs_fsize * 1e-6, sblock.fs_ncg,
+           sblock.fs_cpg, (float)sblock.fs_fpg * sblock.fs_fsize * 1e-6,
+           sblock.fs_ipg);
 /*
 /*
-       printf("%7d size (%d blocks)\n", sblock.fs_size, sblock.fs_size/FRAG);
+       printf("%7d size (%d blocks)\n",
+               sblock.fs_size, sblock.fs_size / sblock.fs_frag);
        printf("%7d cylinder groups\n", sblock.fs_ncg);
        printf("%7d cylinder group block size\n", sblock.fs_cgsize);
        printf("%7d tracks\n", sblock.fs_ntrak);
        printf("%7d cylinder groups\n", sblock.fs_ncg);
        printf("%7d cylinder group block size\n", sblock.fs_cgsize);
        printf("%7d tracks\n", sblock.fs_ntrak);
@@ -264,13 +294,13 @@ noinit:
        printf("%7d sectors per cylinder\n", sblock.fs_spc);
        printf("%7d cylinders\n", sblock.fs_ncyl);
        printf("%7d cylinders per group\n", sblock.fs_cpg);
        printf("%7d sectors per cylinder\n", sblock.fs_spc);
        printf("%7d cylinders\n", sblock.fs_ncyl);
        printf("%7d cylinders per group\n", sblock.fs_cpg);
-       printf("%7d blocks per group\n", sblock.fs_fpg/FRAG);
+       printf("%7d blocks per group\n", sblock.fs_fpg/sblock.fs_frag);
        printf("%7d inodes per group\n", sblock.fs_ipg);
        if (sblock.fs_ncyl % sblock.fs_cpg) {
                printf("%7d cylinders in last group\n",
                    i = sblock.fs_ncyl % sblock.fs_cpg);
                printf("%7d blocks in last group\n",
        printf("%7d inodes per group\n", sblock.fs_ipg);
        if (sblock.fs_ncyl % sblock.fs_cpg) {
                printf("%7d cylinders in last group\n",
                    i = sblock.fs_ncyl % sblock.fs_cpg);
                printf("%7d blocks in last group\n",
-                   i * sblock.fs_spc / NSPB);
+                   i * sblock.fs_spc / NSPB(&sblock));
        }
 */
        /*
        }
 */
        /*
@@ -285,29 +315,39 @@ noinit:
        sblock.fs_cgrotor = 0;
        for (i = 0; i < NRPOS; i++)
                sblock.fs_postbl[i] = -1;
        sblock.fs_cgrotor = 0;
        for (i = 0; i < NRPOS; i++)
                sblock.fs_postbl[i] = -1;
-       for (i = 0; i < sblock.fs_spc; i += (NSPF * FRAG))
+       for (i = 0; i < sblock.fs_spc; i += (NSPF(&sblock) * sblock.fs_frag))
                /* void */;
                /* void */;
-       for (i -= (NSPF * FRAG); i >= 0; i -= (NSPF * FRAG)) {
+       for (i -= (NSPF(&sblock) * sblock.fs_frag);
+            i >= 0;
+            i -= (NSPF(&sblock) * sblock.fs_frag)) {
                c = i % sblock.fs_nsect * NRPOS / sblock.fs_nsect;
                c = i % sblock.fs_nsect * NRPOS / sblock.fs_nsect;
-               sblock.fs_rotbl[i / (NSPF * FRAG)] = sblock.fs_postbl[c];
-               sblock.fs_postbl[c] = i / (NSPF * FRAG);
+               sblock.fs_rotbl[i / (NSPF(&sblock) * sblock.fs_frag)] =
+                       sblock.fs_postbl[c];
+               sblock.fs_postbl[c] = i / (NSPF(&sblock) * sblock.fs_frag);
        }
        for (c = 0; c < sblock.fs_ncg; c++)
                initcg(c);
        }
        for (c = 0; c < sblock.fs_ncg; c++)
                initcg(c);
-       printf("\tsuper-block backups (for fsck -b#) at %d+k*%d (%d .. %d)\n",
-           SBLOCK, sblock.fs_fpg, SBLOCK+sblock.fs_fpg,
-           SBLOCK+(sblock.fs_ncg-1)*sblock.fs_fpg);
+       if (sblock.fs_ncg == 1)
+               printf("Warning, no super-block backups with only one cylinder group\n");
+       else
+               printf("\tsuper-block backups (for fsck -b#) at %d+k*%d (%d .. %d)\n",
+                   SBLOCK, fsbtodb(&sblock, sblock.fs_fpg),
+                   SBLOCK + fsbtodb(&sblock, sblock.fs_fpg),
+                   SBLOCK + fsbtodb(&sblock, (sblock.fs_ncg - 1) *
+                       sblock.fs_fpg));
        /*
         * Now construct the initial file system, and
         * then write out the super-block.
         */
        cfile((struct inode *)0);
        sblock.fs_time = utime;
        /*
         * Now construct the initial file system, and
         * then write out the super-block.
         */
        cfile((struct inode *)0);
        sblock.fs_time = utime;
-       wtfs(SBLOCK, BSIZE, (char *)&sblock);
-       for (i = 0; i < cssize(&sblock); i += BSIZE)
-               wtfs(csaddr(&sblock) + i/BSIZE, BSIZE, ((char *)fscs)+i);
+       wtfs(SBLOCK, MAXBSIZE, (char *)&sblock);
+       for (i = 0; i < sblock.fs_cssize; i += sblock.fs_bsize)
+               wtfs(fsbtodb(&sblock, sblock.fs_csaddr + i / sblock.fs_fsize),
+                       sblock.fs_bsize, ((char *)fscs) + i);
        for (c = 0; c < sblock.fs_ncg; c++)
        for (c = 0; c < sblock.fs_ncg; c++)
-               wtfs(cgsblock(c, &sblock), BSIZE, (char *)&sblock);
+               wtfs(fsbtodb(&sblock, cgsblock(c, &sblock)),
+                       MAXBSIZE, (char *)&sblock);
 #ifndef STANDALONE
        exit(error);
 #endif
 #ifndef STANDALONE
        exit(error);
 #endif
@@ -348,46 +388,47 @@ initcg(c)
        acg.cg_rotor = dmin;
        acg.cg_frotor = dmin;
        acg.cg_irotor = 0;
        acg.cg_rotor = dmin;
        acg.cg_frotor = dmin;
        acg.cg_irotor = 0;
-       for (i = 0; i < FRAG; i++) {
+       for (i = 0; i < sblock.fs_frag; i++) {
                acg.cg_frsum[i] = 0;
        }
        for (i = 0; i < sblock.fs_ipg; ) {
                acg.cg_frsum[i] = 0;
        }
        for (i = 0; i < sblock.fs_ipg; ) {
-               for (j = INOPB; j > 0; j--) {
+               for (j = INOPB(&sblock); j > 0; j--) {
                        clrbit(acg.cg_iused, i);
                        i++;
                }
                        clrbit(acg.cg_iused, i);
                        i++;
                }
-               acg.cg_cs.cs_nifree += INOPB;
+               acg.cg_cs.cs_nifree += INOPB(&sblock);
        }
        while (i < MAXIPG) {
                clrbit(acg.cg_iused, i);
                i++;
        }
        }
        while (i < MAXIPG) {
                clrbit(acg.cg_iused, i);
                i++;
        }
-       lseek(fso, cgimin(c,&sblock)*FSIZE, 0);
+       lseek(fso, fsbtodb(&sblock, cgimin(c,&sblock)) * DEV_BSIZE, 0);
        if (write(fso, (char *)zino, sblock.fs_ipg * sizeof (struct dinode)) !=
            sblock.fs_ipg * sizeof (struct dinode))
        if (write(fso, (char *)zino, sblock.fs_ipg * sizeof (struct dinode)) !=
            sblock.fs_ipg * sizeof (struct dinode))
-               printf("write error %D\n", tell(fso) / BSIZE);
+               printf("write error %D\n", tell(fso) / sblock.fs_bsize);
        for (i = 0; i < MAXCPG; i++)
                for (j = 0; j < NRPOS; j++)
                        acg.cg_b[i][j] = 0;
        if (c == 0) {
        for (i = 0; i < MAXCPG; i++)
                for (j = 0; j < NRPOS; j++)
                        acg.cg_b[i][j] = 0;
        if (c == 0) {
-               dmin += howmany(cssize(&sblock), BSIZE) * FRAG;
+               dmin += howmany(sblock.fs_cssize, sblock.fs_bsize) *
+                       sblock.fs_frag;
        }
        }
-       for (d = 0; d < dmin; d += FRAG)
-               clrblock(acg.cg_free, d/FRAG);
-       while ((d+FRAG) <= dmax - cbase) {
-               setblock(acg.cg_free, d/FRAG);
+       for (d = 0; d < dmin; d += sblock.fs_frag)
+               clrblock(&sblock, acg.cg_free, d/sblock.fs_frag);
+       while ((d+sblock.fs_frag) <= dmax - cbase) {
+               setblock(&sblock, acg.cg_free, d/sblock.fs_frag);
                acg.cg_cs.cs_nbfree++;
                acg.cg_cs.cs_nbfree++;
-               s = d * NSPF;
-               acg.cg_b[s/sblock.fs_spc]
-                   [s%sblock.fs_nsect*NRPOS/sblock.fs_nsect]++;
-               d += FRAG;
+               s = d * NSPF(&sblock);
+               acg.cg_b[s / sblock.fs_spc]
+                   [s % sblock.fs_nsect * NRPOS / sblock.fs_nsect]++;
+               d += sblock.fs_frag;
        }
        if (d < dmax - cbase)
                for (; d < dmax - cbase; d++) {
                        setbit(acg.cg_free, d);
                        acg.cg_cs.cs_nffree++;
                }
        }
        if (d < dmax - cbase)
                for (; d < dmax - cbase; d++) {
                        setbit(acg.cg_free, d);
                        acg.cg_cs.cs_nffree++;
                }
-       for (; d < MAXBPG; d++)
+       for (; d < MAXBPG(&sblock); d++)
                clrbit(acg.cg_free, d);
        sblock.fs_dsize += acg.cg_ndblk - dmin;
        sblock.fs_cstotal.cs_ndir += acg.cg_cs.cs_ndir;
                clrbit(acg.cg_free, d);
        sblock.fs_dsize += acg.cg_ndblk - dmin;
        sblock.fs_cstotal.cs_ndir += acg.cg_cs.cs_ndir;
@@ -395,16 +436,17 @@ initcg(c)
        sblock.fs_cstotal.cs_nbfree += acg.cg_cs.cs_nbfree;
        sblock.fs_cstotal.cs_nifree += acg.cg_cs.cs_nifree;
        *cs = acg.cg_cs;
        sblock.fs_cstotal.cs_nbfree += acg.cg_cs.cs_nbfree;
        sblock.fs_cstotal.cs_nifree += acg.cg_cs.cs_nifree;
        *cs = acg.cg_cs;
-       wtfs(cgtod(c, &sblock), BSIZE, (char *)&acg);
+       wtfs(fsbtodb(&sblock, cgtod(c, &sblock)),
+               sblock.fs_bsize, (char *)&acg);
 }
 
 cfile(par)
 }
 
 cfile(par)
-struct inode *par;
+       struct inode *par;
 {
        struct inode in;
        int dbc, ibc;
 {
        struct inode in;
        int dbc, ibc;
-       char db[BSIZE];
-       daddr_t ib[NINDIR];
+       char db[MAXBSIZE];
+       daddr_t ib[MAXBSIZE / sizeof(daddr_t)];
        int i, f, c;
 
        /*
        int i, f, c;
 
        /*
@@ -437,9 +479,9 @@ struct inode *par;
 
        ino++;
        in.i_number = ino;
 
        ino++;
        in.i_number = ino;
-       for(i=0; i<BSIZE; i++)
+       for(i=0; i<sblock.fs_bsize; i++)
                db[i] = 0;
                db[i] = 0;
-       for(i=0; i<NINDIR; i++)
+       for(i=0; i<NINDIR(&sblock); i++)
                ib[i] = (daddr_t)0;
        in.i_nlink = 1;
        in.i_size = 0;
                ib[i] = (daddr_t)0;
        in.i_nlink = 1;
        in.i_size = 0;
@@ -468,9 +510,10 @@ struct inode *par;
                        error = 1;
                        break;
                }
                        error = 1;
                        break;
                }
-               while((i=read(f, db, BSIZE)) > 0) {
+               while((i = read(f, db, sblock.fs_bsize)) > 0) {
                        in.i_size += i;
                        in.i_size += i;
-                       newblk(&dbc, db, &ibc, ib, ibc < NDADDR ? i : BSIZE, 0);
+                       newblk(&dbc, db, &ibc, ib,
+                               ibc < NDADDR ? i : sblock.fs_bsize, 0);
                }
                close(f);
                break;
                }
                close(f);
                break;
@@ -504,23 +547,25 @@ struct inode *par;
                        getstr();
                        if(string[0]=='$' && string[1]=='\0')
                                break;
                        getstr();
                        if(string[0]=='$' && string[1]=='\0')
                                break;
-                       if (in.i_size >= BSIZE * NDADDR) {
+                       if (in.i_size >= sblock.fs_bsize * NDADDR) {
                                printf("can't handle direct of > %d entries\n",
                                printf("can't handle direct of > %d entries\n",
-                                   NDIRECT * NDADDR);
+                                   NDIRECT(&sblock) * NDADDR);
                                exit(1);
                        }
                        entry(ino+1, string, &dbc, db, &ibc, ib);
                        in.i_size += sizeof(struct direct);
                        cfile(&in);
                }
                                exit(1);
                        }
                        entry(ino+1, string, &dbc, db, &ibc, ib);
                        in.i_size += sizeof(struct direct);
                        cfile(&in);
                }
-               newblk(&dbc, db, &ibc, ib, roundup(dbc, FSIZE), IFDIR);
+               newblk(&dbc, db, &ibc, ib, roundup(dbc, sblock.fs_fsize),
+                       IFDIR);
                break;
        }
        iput(&in, &ibc, ib);
 }
 
 gmode(c, s, m0, m1, m2, m3)
                break;
        }
        iput(&in, &ibc, ib);
 }
 
 gmode(c, s, m0, m1, m2, m3)
-char c, *s;
+       char c, *s;
+       int m0, m1, m2, m3;
 {
        int i;
 
 {
        int i;
 
@@ -583,13 +628,13 @@ loop:
 }
 
 rdfs(bno, size, bf)
 }
 
 rdfs(bno, size, bf)
-daddr_t bno;
-int size;
-char *bf;
+       daddr_t bno;
+       int size;
+       char *bf;
 {
        int n;
 
 {
        int n;
 
-       lseek(fsi, bno*FSIZE, 0);
+       lseek(fsi, bno * DEV_BSIZE, 0);
        n = read(fsi, bf, size);
        if(n != size) {
                printf("read error: %ld\n", bno);
        n = read(fsi, bf, size);
        if(n != size) {
                printf("read error: %ld\n", bno);
@@ -598,13 +643,13 @@ char *bf;
 }
 
 wtfs(bno, size, bf)
 }
 
 wtfs(bno, size, bf)
-daddr_t bno;
-int size;
-char *bf;
+       daddr_t bno;
+       int size;
+       char *bf;
 {
        int n;
 
 {
        int n;
 
-       lseek(fso, bno*FSIZE, 0);
+       lseek(fso, bno * DEV_BSIZE, 0);
        n = write(fso, bf, size);
        if(n != size) {
                printf("write error: %D\n", bno);
        n = write(fso, bf, size);
        if(n != size) {
                printf("write error: %D\n", bno);
@@ -621,18 +666,19 @@ alloc(size, mode)
        daddr_t d;
 
        c = 0;
        daddr_t d;
 
        c = 0;
-       rdfs(cgtod(0,&sblock), sblock.fs_cgsize, (char *)&acg);
+       rdfs(fsbtodb(&sblock, cgtod(0,&sblock)),
+               sblock.fs_cgsize, (char *)&acg);
        if (acg.cg_cs.cs_nbfree == 0) {
                printf("first cylinder group ran out of space\n");
                return (0);
        }
        if (acg.cg_cs.cs_nbfree == 0) {
                printf("first cylinder group ran out of space\n");
                return (0);
        }
-       for (d = 0; d < acg.cg_ndblk; d += FRAG)
-               if (isblock(acg.cg_free, d/FRAG))
+       for (d = 0; d < acg.cg_ndblk; d += sblock.fs_frag)
+               if (isblock(&sblock, acg.cg_free, d / sblock.fs_frag))
                        goto goth;
        printf("internal error: can't find block in cyl 0\n");
        return (0);
 goth:
                        goto goth;
        printf("internal error: can't find block in cyl 0\n");
        return (0);
 goth:
-       clrblock(acg.cg_free, d/FRAG);
+       clrblock(&sblock, acg.cg_free, d / sblock.fs_frag);
        acg.cg_cs.cs_nbfree--;
        sblock.fs_cstotal.cs_nbfree--;
        fscs[0].cs_nbfree--;
        acg.cg_cs.cs_nbfree--;
        sblock.fs_cstotal.cs_nbfree--;
        fscs[0].cs_nbfree--;
@@ -641,40 +687,42 @@ goth:
                sblock.fs_cstotal.cs_ndir++;
                fscs[0].cs_ndir++;
        }
                sblock.fs_cstotal.cs_ndir++;
                fscs[0].cs_ndir++;
        }
-       s = d * NSPF;
-       acg.cg_b[s/sblock.fs_spc][s%sblock.fs_nsect*NRPOS/sblock.fs_nsect]--;
-       if (size != BSIZE) {
-               frag = howmany(size, FSIZE);
-               fscs[0].cs_nffree += FRAG - frag;
-               sblock.fs_cstotal.cs_nffree += FRAG - frag;
-               acg.cg_cs.cs_nffree += FRAG - frag;
-               acg.cg_frsum[FRAG - frag]++;
-               for (i = frag; i < FRAG; i++)
+       s = d * NSPF(&sblock);
+       acg.cg_b[s / sblock.fs_spc]
+               [s % sblock.fs_nsect * NRPOS / sblock.fs_nsect]--;
+       if (size != sblock.fs_bsize) {
+               frag = howmany(size, sblock.fs_fsize);
+               fscs[0].cs_nffree += sblock.fs_frag - frag;
+               sblock.fs_cstotal.cs_nffree += sblock.fs_frag - frag;
+               acg.cg_cs.cs_nffree += sblock.fs_frag - frag;
+               acg.cg_frsum[sblock.fs_frag - frag]++;
+               for (i = frag; i < sblock.fs_frag; i++)
                        setbit(acg.cg_free, d+i);
        }
                        setbit(acg.cg_free, d+i);
        }
-       wtfs(cgtod(0,&sblock), sblock.fs_cgsize, (char *)&acg);
+       wtfs(fsbtodb(&sblock, cgtod(0,&sblock)),
+               roundup(sblock.fs_cgsize, DEV_BSIZE), (char *)&acg);
        return (d);
 }
 
 entry(inum, str, adbc, db, aibc, ib)
        return (d);
 }
 
 entry(inum, str, adbc, db, aibc, ib)
-ino_t inum;
-char *str;
-int *adbc, *aibc;
-char *db;
-daddr_t *ib;
+       ino_t inum;
+       char *str;
+       int *adbc, *aibc;
+       char *db;
+       daddr_t *ib;
 {
        struct direct *dp;
        int i;
 
 {
        struct direct *dp;
        int i;
 
-       if (*adbc == NDIRECT)
-               newblk(adbc, db, aibc, ib, BSIZE, 0);
+       if (*adbc == NDIRECT(&sblock))
+               newblk(adbc, db, aibc, ib, sblock.fs_bsize, 0);
        dp = (struct direct *)db;
        dp += *adbc;
        (*adbc)++;
        dp->d_ino = inum;
        dp = (struct direct *)db;
        dp += *adbc;
        (*adbc)++;
        dp->d_ino = inum;
-       for(i=0; i<DIRSIZ; i++)
+       for(i=0; i < DIRSIZ; i++)
                dp->d_name[i] = 0;
                dp->d_name[i] = 0;
-       for(i=0; i<DIRSIZ; i++)
+       for(i=0; i < DIRSIZ; i++)
                if((dp->d_name[i] = str[i]) == 0)
                        break;
 }
                if((dp->d_name[i] = str[i]) == 0)
                        break;
 }
@@ -690,13 +738,13 @@ newblk(adbc, db, aibc, ib, size, mode)
        daddr_t bno;
 
        bno = alloc(size, mode);
        daddr_t bno;
 
        bno = alloc(size, mode);
-       wtfs(bno, size, db);
-       for(i=0; i<size; i++)
+       wtfs(fsbtodb(&sblock, bno), size, db);
+       for(i = 0; i < size; i++)
                db[i] = 0;
        *adbc = 0;
        ib[*aibc] = bno;
        (*aibc)++;
                db[i] = 0;
        *adbc = 0;
        ib[*aibc] = bno;
        (*aibc)++;
-       if(*aibc >= NINDIR) {
+       if(*aibc >= NINDIR(&sblock)) {
                printf("indirect block full\n");
                error = 1;
                *aibc = 0;
                printf("indirect block full\n");
                error = 1;
                *aibc = 0;
@@ -716,18 +764,20 @@ getch()
 }
 
 iput(ip, aibc, ib)
 }
 
 iput(ip, aibc, ib)
-struct inode *ip;
-int *aibc;
-daddr_t *ib;
+       struct inode *ip;
+       int *aibc;
+       daddr_t *ib;
 {
        struct dinode *dp;
        daddr_t d;
        int i, c = ip->i_number / sblock.fs_ipg;
 
 {
        struct dinode *dp;
        daddr_t d;
        int i, c = ip->i_number / sblock.fs_ipg;
 
-       rdfs(cgtod(c,&sblock), sblock.fs_cgsize, (char *)&acg);
+       rdfs(fsbtodb(&sblock, cgtod(c,&sblock)),
+               sblock.fs_cgsize, (char *)&acg);
        acg.cg_cs.cs_nifree--;
        setbit(acg.cg_iused, ip->i_number);
        acg.cg_cs.cs_nifree--;
        setbit(acg.cg_iused, ip->i_number);
-       wtfs(cgtod(c,&sblock), sblock.fs_cgsize, (char *)&acg);
+       wtfs(fsbtodb(&sblock, cgtod(c,&sblock)),
+               roundup(sblock.fs_cgsize, DEV_BSIZE), (char *)&acg);
        sblock.fs_cstotal.cs_nifree--;
        fscs[0].cs_nifree--;
        if(ip->i_number >= sblock.fs_ipg) {
        sblock.fs_cstotal.cs_nifree--;
        fscs[0].cs_nifree--;
        if(ip->i_number >= sblock.fs_ipg) {
@@ -741,20 +791,98 @@ daddr_t *ib;
                return;
        }
        d = itod(ip->i_number,&sblock);
                return;
        }
        d = itod(ip->i_number,&sblock);
-       rdfs(d, BSIZE, buf);
-       for(i=0; i<*aibc; i++) {
+       rdfs(fsbtodb(&sblock, d), sblock.fs_bsize, buf);
+       for(i = 0; i < *aibc; i++) {
                if(i >= NDADDR)
                        break;
                ip->i_db[i] = ib[i];
        }
        if(*aibc >= NDADDR) {
                if(i >= NDADDR)
                        break;
                ip->i_db[i] = ib[i];
        }
        if(*aibc >= NDADDR) {
-               ip->i_ib[0] = alloc(BSIZE, 0);
-               for(i=0; i<NINDIR-NDADDR; i++) {
+               ip->i_ib[0] = alloc(sblock.fs_bsize, 0);
+               for(i=0; i<NINDIR(&sblock)-NDADDR; i++) {
                        ib[i] = ib[i+NDADDR];
                        ib[i+NDADDR] = (daddr_t)0;
                }
                        ib[i] = ib[i+NDADDR];
                        ib[i+NDADDR] = (daddr_t)0;
                }
-               wtfs(ip->i_ib[0], (char *)ib);
+               wtfs(fsbtodb(&sblock, ip->i_ib[0]), sblock.fs_bsize,
+                       (char *)ib);
+       }
+       ((struct dinode *)buf + itoo(ip->i_number, &sblock))->di_ic = ip->i_ic;
+       wtfs(fsbtodb(&sblock, d), sblock.fs_bsize, buf);
+}
+
+/*
+ * block operations
+ */
+
+isblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       unsigned char mask;
+
+       switch (fs->fs_frag) {
+       case 8:
+               return (cp[h] == 0xff);
+       case 4:
+               mask = 0x0f << ((h & 0x1) << 2);
+               return ((cp[h >> 1] & mask) == mask);
+       case 2:
+               mask = 0x03 << ((h & 0x3) << 1);
+               return ((cp[h >> 2] & mask) == mask);
+       case 1:
+               mask = 0x01 << (h & 0x7);
+               return ((cp[h >> 3] & mask) == mask);
+       default:
+               fprintf(stderr, "isblock bad fs_frag %d\n", fs->fs_frag);
+               return;
+       }
+}
+
+clrblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       switch ((fs)->fs_frag) {
+       case 8:
+               cp[h] = 0;
+               return;
+       case 4:
+               cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
+               return;
+       case 2:
+               cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
+               return;
+       case 1:
+               cp[h >> 3] &= ~(0x01 << (h & 0x7));
+               return;
+       default:
+               fprintf(stderr, "clrblock bad fs_frag %d\n", fs->fs_frag);
+               return;
+       }
+}
+
+setblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       switch (fs->fs_frag) {
+       case 8:
+               cp[h] = 0xff;
+               return;
+       case 4:
+               cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
+               return;
+       case 2:
+               cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
+               return;
+       case 1:
+               cp[h >> 3] |= (0x01 << (h & 0x7));
+               return;
+       default:
+               fprintf(stderr, "setblock bad fs_frag %d\n", fs->fs_frag);
+               return;
        }
        }
-       ((struct dinode *)buf+itoo(ip->i_number))->di_ic = ip->i_ic;
-       wtfs(d, BSIZE, buf);
 }
 }
index 87a866f..0d4f5da 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1981 Regents of the University of California */
 
 /* Copyright (c) 1981 Regents of the University of California */
 
-char version[] = "@(#)main.c 1.7 %G%";
+char version[] = "@(#)main.c 1.8 %G%";
 
 /*     Modified to include h option (recursively extract all files within
  *     a subtree) and m option (recreate the heirarchical structure of
 
 /*     Modified to include h option (recursively extract all files within
  *     a subtree) and m option (recreate the heirarchical structure of
@@ -36,8 +36,8 @@ struct odirect {
        char    d_name[DIRSIZ];
 };
 
        char    d_name[DIRSIZ];
 };
 
-#define        MWORD(m,i) (m[(unsigned)(i-1)/MLEN])
-#define        MBIT(i) (1<<((unsigned)(i-1)%MLEN))
+#define        MWORD(m,i) (m[(unsigned)(i-1)/NBBY])
+#define        MBIT(i) (1<<((unsigned)(i-1)%NBBY))
 #define        BIS(i,w)        (MWORD(w,i) |=  MBIT(i))
 #define        BIC(i,w)        (MWORD(w,i) &= ~MBIT(i))
 #define        BIT(i,w)        (MWORD(w,i) & MBIT(i))
 #define        BIS(i,w)        (MWORD(w,i) |=  MBIT(i))
 #define        BIC(i,w)        (MWORD(w,i) &= ~MBIT(i))
 #define        BIT(i,w)        (MWORD(w,i) & MBIT(i))
@@ -89,9 +89,17 @@ struct xtrlist {
 } *xtrlist[MAXINO];
 int xtrcnt = 0;
 
 } *xtrlist[MAXINO];
 int xtrcnt = 0;
 
-short  dumpmap[MSIZ];
-short  clrimap[MSIZ];
-char   clearedbuf[BSIZE];
+#ifdef STANDALONE
+#define msiz 8192
+char   dumpmap[msiz];
+char   clrimap[msiz];
+#else
+int    msiz;
+char   *dumpmap;
+char   *clrimap;
+#endif
+
+char   clearedbuf[MAXBSIZE];
 
 extern char *ctime();
 ino_t search();
 
 extern char *ctime();
 ino_t search();
@@ -197,8 +205,8 @@ doit(command, argc, argv)
                mt = open(mbuf, 0);
        } while (mt == -1);
        magtape = mbuf;
                mt = open(mbuf, 0);
        } while (mt == -1);
        magtape = mbuf;
-       blkclr(clearedbuf, BSIZE);
 #endif
 #endif
+       blkclr(clearedbuf, MAXBSIZE);
        switch(command) {
 #ifndef STANDALONE
        case 't':
        switch(command) {
 #ifndef STANDALONE
        case 't':
@@ -212,12 +220,12 @@ doit(command, argc, argv)
        case 'x':
                extractfiles(argc, argv);
                return;
        case 'x':
                extractfiles(argc, argv);
                return;
+#endif
        case 'r':
        case 'R':
                restorfiles(command, argv);
                return;
        }
        case 'r':
        case 'R':
                restorfiles(command, argv);
                return;
        }
-#endif
 }
 
 #ifndef STANDALONE
 }
 
 #ifndef STANDALONE
@@ -228,6 +236,7 @@ extractfiles(argc, argv)
        char    *ststore();
        register struct xtrlist *xp;
        struct xtrlist **xpp;
        char    *ststore();
        register struct xtrlist *xp;
        struct xtrlist **xpp;
+       struct fs *fs;
        ino_t   d;
        int     xtrfile(), xtrskip(), xtrcvtdir(), xtrcvtskip(), null();
        int     mode;
        ino_t   d;
        int     xtrfile(), xtrskip(), xtrcvtdir(), xtrcvtskip(), null();
        int     mode;
@@ -240,6 +249,10 @@ extractfiles(argc, argv)
        if (checkvol(&spcl, 1) == 0) {
                fprintf(stderr, "Tape is not volume 1 of the dump\n");
        }
        if (checkvol(&spcl, 1) == 0) {
                fprintf(stderr, "Tape is not volume 1 of the dump\n");
        }
+       fs = getfs(dev);
+       msiz = roundup(howmany(fs->fs_ipg * fs->fs_ncg, NBBY), TP_BSIZE);
+       clrimap = (char *)calloc(msiz, sizeof(char));
+       dumpmap = (char *)calloc(msiz, sizeof(char));
        pass1(1);  /* This sets the various maps on the way by */
        while (argc--) {
                if ((d = psearch(*argv)) == 0 || BIT(d,dumpmap) == 0) {
        pass1(1);  /* This sets the various maps on the way by */
        while (argc--) {
                if ((d = psearch(*argv)) == 0 || BIT(d,dumpmap) == 0) {
@@ -423,24 +436,26 @@ restorfiles(command, argv)
        char mount[BUFSIZ + 1];
        char *ptr[2];
 
        char mount[BUFSIZ + 1];
        char *ptr[2];
 
-#ifndef STANDALONE
        mount[0] = '\0';
        strcpy(mount, "MOUNT=");
        mount[0] = '\0';
        strcpy(mount, "MOUNT=");
+#ifndef STANDALONE
        strncat(mount, *argv, BUFSIZ);
        strncat(mount, *argv, BUFSIZ);
+#else
+       fprintf(stderr, "Disk? ");
+       gets(&mount[6]);
+#endif
        ptr[0] = mount;
        ptr[1] = 0;
        xmount(ptr);
        ptr[0] = mount;
        ptr[1] = 0;
        xmount(ptr);
+       mounted++;
        iput(u.u_cdir); /* release root inode */
        iput(u.u_rdir); /* release root inode */
        iput(u.u_cdir); /* release root inode */
        iput(u.u_rdir); /* release root inode */
-       mounted++;
-#else
-       do {
-               fprintf(stderr, "Disk? ");
-               gets(mount);
-               fi = open(mount, 2);
-       } while (fi == -1);
-#endif
+       fs = getfs(dev);
+       maxi = fs->fs_ipg * fs->fs_ncg;
 #ifndef STANDALONE
 #ifndef STANDALONE
+       msiz = roundup(howmany(maxi, NBBY), TP_BSIZE);
+       clrimap = (char *)calloc(msiz, sizeof(char));
+       dumpmap = (char *)calloc(msiz, sizeof(char));
        if (command == 'R') {
                fprintf(stderr, "Enter starting volume number: ");
                if (gets(tbf) == EOF) {
        if (command == 'R') {
                fprintf(stderr, "Enter starting volume number: ");
                if (gets(tbf) == EOF) {
@@ -460,8 +475,6 @@ restorfiles(command, argv)
                                                        *argv);
 #endif
        while (getchar() != '\n');
                                                        *argv);
 #endif
        while (getchar() != '\n');
-       fs = getfs(dev);
-       maxi = fs->fs_ipg * fs->fs_ncg;
        if (readhdr(&spcl) == 0) {
                fprintf(stderr, "Missing volume record\n");
                done(1);
        if (readhdr(&spcl) == 0) {
                fprintf(stderr, "Missing volume record\n");
                done(1);
@@ -813,30 +826,32 @@ getfile(f1, f2, size)
        long    size;
 {
        register int i;
        long    size;
 {
        register int i;
-       char buf[BLKING * FRAG][TP_BSIZE];
+       char buf[MAXBSIZE / TP_BSIZE][TP_BSIZE];
        union u_spcl addrblk;
        union u_spcl addrblk;
+       register struct fs *fs;
 #      define addrblock addrblk.s_spcl
 
        addrblock = spcl;
 #      define addrblock addrblk.s_spcl
 
        addrblock = spcl;
+       fs = getfs(dev);
        for (;;) {
                for (i = 0; i < addrblock.c_count; i++) {
                        if (addrblock.c_addr[i]) {
                                readtape(&buf[curblk++][0]);
        for (;;) {
                for (i = 0; i < addrblock.c_count; i++) {
                        if (addrblock.c_addr[i]) {
                                readtape(&buf[curblk++][0]);
-                               if (curblk == BLKING * FRAG) {
+                               if (curblk == BLKING(fs) * fs->fs_frag) {
                                        (*f1)(buf, size > TP_BSIZE ?
                                        (*f1)(buf, size > TP_BSIZE ?
-                                            (long) (BLKING * FRAG * TP_BSIZE) :
+                                            (long) (BLKING(fs) * fs->fs_frag * TP_BSIZE) :
                                             (curblk - 1) * TP_BSIZE + size);
                                        curblk = 0;
                                }
                                             (curblk - 1) * TP_BSIZE + size);
                                        curblk = 0;
                                }
-                       }
-                       else {
+                       } else {
                                if (curblk > 0) {
                                        (*f1)(buf, size > TP_BSIZE ?
                                             (long) (curblk * TP_BSIZE) :
                                             (curblk - 1) * TP_BSIZE + size);
                                        curblk = 0;
                                }
                                if (curblk > 0) {
                                        (*f1)(buf, size > TP_BSIZE ?
                                             (long) (curblk * TP_BSIZE) :
                                             (curblk - 1) * TP_BSIZE + size);
                                        curblk = 0;
                                }
-                               (*f2)(clearedbuf, size > TP_BSIZE ? (long) TP_BSIZE : size);
+                               (*f2)(clearedbuf, size > TP_BSIZE ?
+                                       (long) TP_BSIZE : size);
                        }
                        if ((size -= TP_BSIZE) <= 0) {
 eloop:
                        }
                        if ((size -= TP_BSIZE) <= 0) {
 eloop:
@@ -892,7 +907,8 @@ xtrcvtdir(buf, size)
        struct odirect *buf;
        long size;
 {
        struct odirect *buf;
        long size;
 {
-       struct direct cvtbuf[BLKING * FRAG * TP_BSIZE / sizeof(struct odirect)];
+       struct direct
+               cvtbuf[MAXBSIZE / sizeof(struct odirect)];
        struct odirect *odp, *edp;
        struct direct *dp;
 
        struct odirect *odp, *edp;
        struct direct *dp;
 
@@ -942,7 +958,8 @@ rstrcvtdir(buf, size)
        struct odirect *buf;
        long size;
 {
        struct odirect *buf;
        long size;
 {
-       struct direct cvtbuf[BLKING * FRAG * TP_BSIZE / sizeof(struct odirect)];
+       struct direct
+               cvtbuf[MAXBSIZE / sizeof(struct odirect)];
        struct odirect *odp, *edp;
        struct direct *dp;
 
        struct odirect *odp, *edp;
        struct direct *dp;
 
@@ -1113,7 +1130,7 @@ checktype(b, t)
  * read a bit mask from the tape into m.
  */
 readbits(m)
  * read a bit mask from the tape into m.
  */
 readbits(m)
-       short   *m;
+       char    *m;
 {
        register int i;
 
 {
        register int i;
 
@@ -1121,7 +1138,7 @@ readbits(m)
 
        while (i--) {
                readtape((char *) m);
 
        while (i--) {
                readtape((char *) m);
-               m += (TP_BSIZE/(MLEN/BITS));
+               m += (TP_BSIZE/(NBBY/BITS));
        }
        while (gethead(&spcl) == 0)
                ;
        }
        while (gethead(&spcl) == 0)
                ;
@@ -1195,7 +1212,7 @@ iexist(dev, ino)
        if ((unsigned)ino >= fs->fs_ipg*fs->fs_ncg)
                return (0);
        cg = itog(ino, fs);
        if ((unsigned)ino >= fs->fs_ipg*fs->fs_ncg)
                return (0);
        cg = itog(ino, fs);
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return(0);
        cgp = bp->b_un.b_cg;
        if (bp->b_flags & B_ERROR)
                return(0);
        cgp = bp->b_un.b_cg;
index f123894..7b21844 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1981 Regents of the University of California */
 
 /* Copyright (c) 1981 Regents of the University of California */
 
-static char vers[] = "@(#)ffs_alloc.c 1.10 %G%";
+static char vers[] = "@(#)ffs_alloc.c 1.11 %G%";
 
 /*     alloc.c 4.8     81/03/08        */
 
 
 /*     alloc.c 4.8     81/03/08        */
 
@@ -22,7 +22,7 @@ extern daddr_t                fragextend();
 extern daddr_t         blkpref();
 extern daddr_t         mapsearch();
 extern int             inside[], around[];
 extern daddr_t         blkpref();
 extern daddr_t         mapsearch();
 extern int             inside[], around[];
-extern unsigned char   fragtbl[];
+extern unsigned char   *fragtbl[];
 
 struct buf *
 alloc(dev, ip, bpref, size)
 
 struct buf *
 alloc(dev, ip, bpref, size)
@@ -36,14 +36,14 @@ alloc(dev, ip, bpref, size)
        register struct buf *bp;
        int cg;
        
        register struct buf *bp;
        int cg;
        
-       if ((unsigned)size > BSIZE || size % FSIZE != 0)
-               panic("alloc: bad size");
        fs = getfs(dev);
        fs = getfs(dev);
-       if (size == BSIZE && fs->fs_cstotal.cs_nbfree == 0)
+       if ((unsigned)size > fs->fs_bsize || size % fs->fs_fsize != 0)
+               panic("alloc: bad size");
+       if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
                goto nospace;
        if (u.u_uid != 0 &&
                goto nospace;
        if (u.u_uid != 0 &&
-           fs->fs_cstotal.cs_nbfree * FRAG + fs->fs_cstotal.cs_nffree <
-             fs->fs_dsize * minfree / 100)
+           fs->fs_cstotal.cs_nbfree * fs->fs_frag + fs->fs_cstotal.cs_nffree <
+             fs->fs_dsize * fs->fs_minfree / 100)
                goto nospace;
        if (bpref >= fs->fs_size)
                bpref = 0;
                goto nospace;
        if (bpref >= fs->fs_size)
                bpref = 0;
@@ -54,7 +54,7 @@ alloc(dev, ip, bpref, size)
        bno = (daddr_t)hashalloc(dev, fs, cg, (long)bpref, size, alloccg);
        if (bno == 0)
                goto nospace;
        bno = (daddr_t)hashalloc(dev, fs, cg, (long)bpref, size, alloccg);
        if (bno == 0)
                goto nospace;
-       bp = getblk(dev, bno, size);
+       bp = getblk(dev, fsbtodb(fs, bno), size);
        clrbuf(bp);
        return (bp);
 nospace:
        clrbuf(bp);
        return (bp);
 nospace:
@@ -76,13 +76,13 @@ realloccg(dev, bprev, bpref, osize, nsize)
        caddr_t cp;
        int cg;
        
        caddr_t cp;
        int cg;
        
-       if ((unsigned)osize > BSIZE || osize % FSIZE != 0 ||
-           (unsigned)nsize > BSIZE || nsize % FSIZE != 0)
-               panic("realloccg: bad size");
        fs = getfs(dev);
        fs = getfs(dev);
+       if ((unsigned)osize > fs->fs_bsize || osize % fs->fs_fsize != 0 ||
+           (unsigned)nsize > fs->fs_bsize || nsize % fs->fs_fsize != 0)
+               panic("realloccg: bad size");
        if (u.u_uid != 0 &&
        if (u.u_uid != 0 &&
-           fs->fs_cstotal.cs_nbfree * FRAG + fs->fs_cstotal.cs_nffree <
-             fs->fs_dsize * minfree / 100)
+           fs->fs_cstotal.cs_nbfree * fs->fs_frag + fs->fs_cstotal.cs_nffree <
+             fs->fs_dsize * fs->fs_minfree / 100)
                goto nospace;
        if (bprev == 0)
                panic("realloccg: bad bprev");
                goto nospace;
        if (bprev == 0)
                panic("realloccg: bad bprev");
@@ -90,7 +90,7 @@ realloccg(dev, bprev, bpref, osize, nsize)
                cg = dtog(bprev, fs);
        bno = fragextend(dev, fs, cg, (long)bprev, osize, nsize);
        if (bno != 0) {
                cg = dtog(bprev, fs);
        bno = fragextend(dev, fs, cg, (long)bprev, osize, nsize);
        if (bno != 0) {
-               bp = bread(dev, bno, osize);
+               bp = bread(dev, fsbtodb(fs, bno), osize);
                bp->b_bcount = nsize;
                blkclr(bp->b_un.b_addr + osize, nsize - osize);
                return (bp);
                bp->b_bcount = nsize;
                blkclr(bp->b_un.b_addr + osize, nsize - osize);
                return (bp);
@@ -102,8 +102,8 @@ realloccg(dev, bprev, bpref, osize, nsize)
                /*
                 * make a new copy
                 */
                /*
                 * make a new copy
                 */
-               obp = bread(dev, bprev, osize);
-               bp = getblk(dev, bno, nsize);
+               obp = bread(dev, fsbtodb(fs, bprev), osize);
+               bp = getblk(dev, fsbtodb(fs, bno), nsize);
                cp = bp->b_un.b_addr;
                bp->b_un.b_addr = obp->b_un.b_addr;
                obp->b_un.b_addr = cp;
                cp = bp->b_un.b_addr;
                bp->b_un.b_addr = obp->b_un.b_addr;
                obp->b_un.b_addr = cp;
@@ -172,10 +172,10 @@ dirpref(dev)
        minndir = fs->fs_ipg;
        mincg = 0;
        for (cg = 0; cg < fs->fs_ncg; cg++)
        minndir = fs->fs_ipg;
        mincg = 0;
        for (cg = 0; cg < fs->fs_ncg; cg++)
-               if (fs->fs_cs(cg).cs_ndir < minndir &&
-                   fs->fs_cs(cg).cs_nifree >= avgifree) {
+               if (fs->fs_cs(fs, cg).cs_ndir < minndir &&
+                   fs->fs_cs(fs, cg).cs_nifree >= avgifree) {
                        mincg = cg;
                        mincg = cg;
-                       minndir = fs->fs_cs(cg).cs_ndir;
+                       minndir = fs->fs_cs(fs, cg).cs_ndir;
                }
        return (fs->fs_ipg * mincg);
 }
                }
        return (fs->fs_ipg * mincg);
 }
@@ -193,14 +193,14 @@ blkpref(dev)
        fs = getfs(dev);
        avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
        for (cg = fs->fs_cgrotor + 1; cg < fs->fs_ncg; cg++)
        fs = getfs(dev);
        avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
        for (cg = fs->fs_cgrotor + 1; cg < fs->fs_ncg; cg++)
-               if (fs->fs_cs(cg).cs_nbfree >= avgbfree) {
+               if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
                        fs->fs_cgrotor = cg;
                        fs->fs_cgrotor = cg;
-                       return (fs->fs_fpg * cg + FRAG);
+                       return (fs->fs_fpg * cg + fs->fs_frag);
                }
        for (cg = 0; cg <= fs->fs_cgrotor; cg++)
                }
        for (cg = 0; cg <= fs->fs_cgrotor; cg++)
-               if (fs->fs_cs(cg).cs_nbfree >= avgbfree) {
+               if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
                        fs->fs_cgrotor = cg;
                        fs->fs_cgrotor = cg;
-                       return (fs->fs_fpg * cg + FRAG);
+                       return (fs->fs_fpg * cg + fs->fs_frag);
                }
        return (0);
 }
                }
        return (0);
 }
@@ -264,18 +264,18 @@ fragextend(dev, fs, cg, bprev, osize, nsize)
        int frags, bbase;
        int i;
 
        int frags, bbase;
        int i;
 
-       frags = nsize / FSIZE;
-       bbase = bprev % FRAG;
-       if (bbase > (bprev + frags - 1) % FRAG) {
+       frags = nsize / fs->fs_fsize;
+       bbase = bprev % fs->fs_frag;
+       if (bbase > (bprev + frags - 1) % fs->fs_frag) {
                /* cannot extend across a block boundry */
                return (0);
        }
                /* cannot extend across a block boundry */
                return (0);
        }
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
        bno = bprev % fs->fs_fpg;
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
        bno = bprev % fs->fs_fpg;
-       for (i = osize / FSIZE; i < frags; i++) {
+       for (i = osize / fs->fs_fsize; i < frags; i++) {
                if (isclr(cgp->cg_free, bno + i))
                        break;
        }
                if (isclr(cgp->cg_free, bno + i))
                        break;
        }
@@ -286,17 +286,17 @@ fragextend(dev, fs, cg, bprev, osize, nsize)
                 * increase the count on the remaining fragment (if any)
                 * allocate the extended piece
                 */
                 * increase the count on the remaining fragment (if any)
                 * allocate the extended piece
                 */
-               for (i = frags; i < FRAG - bbase; i++)
+               for (i = frags; i < fs->fs_frag - bbase; i++)
                        if (isclr(cgp->cg_free, bno + i))
                                break;
                        if (isclr(cgp->cg_free, bno + i))
                                break;
-               cgp->cg_frsum[i - osize / FSIZE]--;
+               cgp->cg_frsum[i - osize / fs->fs_fsize]--;
                if (i != frags)
                        cgp->cg_frsum[i - frags]++;
                if (i != frags)
                        cgp->cg_frsum[i - frags]++;
-               for (i = osize / FSIZE; i < frags; i++) {
+               for (i = osize / fs->fs_fsize; i < frags; i++) {
                        clrbit(cgp->cg_free, bno + i);
                        cgp->cg_cs.cs_nffree--;
                        fs->fs_cstotal.cs_nffree--;
                        clrbit(cgp->cg_free, bno + i);
                        cgp->cg_cs.cs_nffree--;
                        fs->fs_cstotal.cs_nffree--;
-                       fs->fs_cs(cg).cs_nffree--;
+                       fs->fs_cs(fs, cg).cs_nffree--;
                }
                fs->fs_fmod++;
                bdwrite(bp);
                }
                fs->fs_fmod++;
                bdwrite(bp);
@@ -320,13 +320,13 @@ alloccg(dev, fs, cg, bpref, size)
        int allocsiz;
        register int i;
 
        int allocsiz;
        register int i;
 
-       if (fs->fs_cs(cg).cs_nbfree == 0 && size == BSIZE)
+       if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
                return (0);
                return (0);
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
-       if (size == BSIZE) {
+       if (size == fs->fs_bsize) {
                bno = alloccgblk(fs, cgp, bpref);
                bdwrite(bp);
                return (bno);
                bno = alloccgblk(fs, cgp, bpref);
                bdwrite(bp);
                return (bno);
@@ -336,11 +336,11 @@ alloccg(dev, fs, cg, bpref, size)
         * allocsiz is the size which will be allocated, hacking
         * it down to a smaller size if necessary
         */
         * allocsiz is the size which will be allocated, hacking
         * it down to a smaller size if necessary
         */
-       frags = size / FSIZE;
-       for (allocsiz = frags; allocsiz < FRAG; allocsiz++)
+       frags = size / fs->fs_fsize;
+       for (allocsiz = frags; allocsiz < fs->fs_frag; allocsiz++)
                if (cgp->cg_frsum[allocsiz] != 0)
                        break;
                if (cgp->cg_frsum[allocsiz] != 0)
                        break;
-       if (allocsiz == FRAG) {
+       if (allocsiz == fs->fs_frag) {
                /*
                 * no fragments were available, so a block will be 
                 * allocated, and hacked up
                /*
                 * no fragments were available, so a block will be 
                 * allocated, and hacked up
@@ -351,12 +351,12 @@ alloccg(dev, fs, cg, bpref, size)
                }
                bno = alloccgblk(fs, cgp, bpref);
                bpref = bno % fs->fs_fpg;
                }
                bno = alloccgblk(fs, cgp, bpref);
                bpref = bno % fs->fs_fpg;
-               for (i = frags; i < FRAG; i++)
+               for (i = frags; i < fs->fs_frag; i++)
                        setbit(cgp->cg_free, bpref + i);
                        setbit(cgp->cg_free, bpref + i);
-               i = FRAG - frags;
+               i = fs->fs_frag - frags;
                cgp->cg_cs.cs_nffree += i;
                fs->fs_cstotal.cs_nffree += i;
                cgp->cg_cs.cs_nffree += i;
                fs->fs_cstotal.cs_nffree += i;
-               fs->fs_cs(cg).cs_nffree += i;
+               fs->fs_cs(fs, cg).cs_nffree += i;
                cgp->cg_frsum[i]++;
                bdwrite(bp);
                return (bno);
                cgp->cg_frsum[i]++;
                bdwrite(bp);
                return (bno);
@@ -368,7 +368,7 @@ alloccg(dev, fs, cg, bpref, size)
                clrbit(cgp->cg_free, bno + i);
        cgp->cg_cs.cs_nffree -= frags;
        fs->fs_cstotal.cs_nffree -= frags;
                clrbit(cgp->cg_free, bno + i);
        cgp->cg_cs.cs_nffree -= frags;
        fs->fs_cstotal.cs_nffree -= frags;
-       fs->fs_cs(cg).cs_nffree -= frags;
+       fs->fs_cs(fs, cg).cs_nffree -= frags;
        cgp->cg_frsum[allocsiz]--;
        if (frags != allocsiz)
                cgp->cg_frsum[allocsiz - frags]++;
        cgp->cg_frsum[allocsiz]--;
        if (frags != allocsiz)
                cgp->cg_frsum[allocsiz - frags]++;
@@ -390,12 +390,12 @@ alloccgblk(fs, cgp, bpref)
        if (bpref == 0) {
                bpref = cgp->cg_rotor;
        } else {
        if (bpref == 0) {
                bpref = cgp->cg_rotor;
        } else {
-               bpref &= ~(FRAG - 1);
+               bpref &= ~(fs->fs_frag - 1);
                bpref %= fs->fs_fpg;
                /*
                 * if the requested block is available, use it
                 */
                bpref %= fs->fs_fpg;
                /*
                 * if the requested block is available, use it
                 */
-               if (isblock(cgp->cg_free, bpref/FRAG)) {
+               if (isblock(fs, cgp->cg_free, bpref/fs->fs_frag)) {
                        bno = bpref;
                        goto gotit;
                }
                        bno = bpref;
                        goto gotit;
                }
@@ -403,12 +403,12 @@ alloccgblk(fs, cgp, bpref)
                 * check for a block available on the same cylinder
                 * beginning with one which is rotationally optimal
                 */
                 * check for a block available on the same cylinder
                 * beginning with one which is rotationally optimal
                 */
-               i = bpref * NSPF;
+               i = bpref * NSPF(fs);
                cylno = i / fs->fs_spc;
                cylbp = cgp->cg_b[cylno];
                cylno = i / fs->fs_spc;
                cylbp = cgp->cg_b[cylno];
-               pos = (i + (ROTDELAY == 0) ?
-                       0 : 1 + ROTDELAY * HZ * fs->fs_nsect / (NSPF * 1000)) %
-                       fs->fs_nsect * NRPOS / fs->fs_nsect;
+               pos = (i + (fs->fs_rotdelay == 0) ? 0 :
+                      1 + fs->fs_rotdelay * HZ * fs->fs_nsect /
+                      (NSPF(fs) * 1000)) % fs->fs_nsect * NRPOS / fs->fs_nsect;
                for (i = pos; i < NRPOS; i++)
                        if (cylbp[i] > 0)
                                break;
                for (i = pos; i < NRPOS; i++)
                        if (cylbp[i] > 0)
                                break;
@@ -417,26 +417,26 @@ alloccgblk(fs, cgp, bpref)
                                if (cylbp[i] > 0)
                                        break;
                if (cylbp[i] > 0) {
                                if (cylbp[i] > 0)
                                        break;
                if (cylbp[i] > 0) {
-                       bpref = cylno * fs->fs_spc / (NSPF * FRAG);
+                       bpref = cylno * fs->fs_spc / NSPB(fs);
                        for (j = fs->fs_postbl[i]; j > -1; j = fs->fs_rotbl[j]) {
                        for (j = fs->fs_postbl[i]; j > -1; j = fs->fs_rotbl[j]) {
-                               if (isblock(cgp->cg_free, bpref + j)) {
-                                       bno = (bpref + j) * FRAG;
+                               if (isblock(fs, cgp->cg_free, bpref + j)) {
+                                       bno = (bpref + j) * fs->fs_frag;
                                        goto gotit;
                                }
                        }
                        panic("alloccgblk: can't find blk in cyl");
                }
        }
                                        goto gotit;
                                }
                        }
                        panic("alloccgblk: can't find blk in cyl");
                }
        }
-       bno = mapsearch(fs, cgp, bpref, FRAG);
+       bno = mapsearch(fs, cgp, bpref, fs->fs_frag);
        if (bno == 0)
                return (0);
        cgp->cg_rotor = bno;
 gotit:
        if (bno == 0)
                return (0);
        cgp->cg_rotor = bno;
 gotit:
-       clrblock(cgp->cg_free, bno/FRAG);
+       clrblock(fs, cgp->cg_free, bno/fs->fs_frag);
        cgp->cg_cs.cs_nbfree--;
        fs->fs_cstotal.cs_nbfree--;
        cgp->cg_cs.cs_nbfree--;
        fs->fs_cstotal.cs_nbfree--;
-       fs->fs_cs(cgp->cg_cgx).cs_nbfree--;
-       i = bno * NSPF;
+       fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--;
+       i = bno * NSPF(fs);
        cgp->cg_b[i/fs->fs_spc][i%fs->fs_nsect*NRPOS/fs->fs_nsect]--;
        fs->fs_fmod++;
        return (cgp->cg_cgx * fs->fs_fpg + bno);
        cgp->cg_b[i/fs->fs_spc][i%fs->fs_nsect*NRPOS/fs->fs_nsect]--;
        fs->fs_fmod++;
        return (cgp->cg_cgx * fs->fs_fpg + bno);
@@ -454,9 +454,9 @@ ialloccg(dev, fs, cg, ipref, mode)
        register struct cg *cgp;
        int i;
 
        register struct cg *cgp;
        int i;
 
-       if (fs->fs_cs(cg).cs_nifree == 0)
+       if (fs->fs_cs(fs, cg).cs_nifree == 0)
                return (0);
                return (0);
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
@@ -481,12 +481,12 @@ gotit:
        setbit(cgp->cg_iused, ipref);
        cgp->cg_cs.cs_nifree--;
        fs->fs_cstotal.cs_nifree--;
        setbit(cgp->cg_iused, ipref);
        cgp->cg_cs.cs_nifree--;
        fs->fs_cstotal.cs_nifree--;
-       fs->fs_cs(cg).cs_nifree--;
+       fs->fs_cs(fs, cg).cs_nifree--;
        fs->fs_fmod++;
        if ((mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir++;
                fs->fs_cstotal.cs_ndir++;
        fs->fs_fmod++;
        if ((mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir++;
                fs->fs_cstotal.cs_ndir++;
-               fs->fs_cs(cg).cs_ndir++;
+               fs->fs_cs(fs, cg).cs_ndir++;
        }
        bdwrite(bp);
        return (cg * fs->fs_ipg + ipref);
        }
        bdwrite(bp);
        return (cg * fs->fs_ipg + ipref);
@@ -503,63 +503,63 @@ fre(dev, bno, size)
        int cg, blk, frags, bbase;
        register int i;
 
        int cg, blk, frags, bbase;
        register int i;
 
-       if ((unsigned)size > BSIZE || size % FSIZE != 0)
-               panic("free: bad size");
        fs = getfs(dev);
        fs = getfs(dev);
+       if ((unsigned)size > fs->fs_bsize || size % fs->fs_fsize != 0)
+               panic("free: bad size");
        cg = dtog(bno, fs);
        if (badblock(fs, bno))
                return;
        cg = dtog(bno, fs);
        if (badblock(fs, bno))
                return;
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return;
        cgp = bp->b_un.b_cg;
        bno %= fs->fs_fpg;
        if (bp->b_flags & B_ERROR)
                return;
        cgp = bp->b_un.b_cg;
        bno %= fs->fs_fpg;
-       if (size == BSIZE) {
-               if (isblock(cgp->cg_free, bno/FRAG))
+       if (size == fs->fs_bsize) {
+               if (isblock(fs, cgp->cg_free, bno/fs->fs_frag))
                        panic("free: freeing free block");
                        panic("free: freeing free block");
-               setblock(cgp->cg_free, bno/FRAG);
+               setblock(fs, cgp->cg_free, bno/fs->fs_frag);
                cgp->cg_cs.cs_nbfree++;
                fs->fs_cstotal.cs_nbfree++;
                cgp->cg_cs.cs_nbfree++;
                fs->fs_cstotal.cs_nbfree++;
-               fs->fs_cs(cg).cs_nbfree++;
-               i = bno * NSPF;
+               fs->fs_cs(fs, cg).cs_nbfree++;
+               i = bno * NSPF(fs);
                cgp->cg_b[i/fs->fs_spc][i%fs->fs_nsect*NRPOS/fs->fs_nsect]++;
        } else {
                cgp->cg_b[i/fs->fs_spc][i%fs->fs_nsect*NRPOS/fs->fs_nsect]++;
        } else {
-               bbase = bno - (bno % FRAG);
+               bbase = bno - (bno % fs->fs_frag);
                /*
                 * decrement the counts associated with the old frags
                 */
                blk = ((cgp->cg_free[bbase / NBBY] >> (bbase % NBBY)) &
                /*
                 * decrement the counts associated with the old frags
                 */
                blk = ((cgp->cg_free[bbase / NBBY] >> (bbase % NBBY)) &
-                      (0xff >> (NBBY - FRAG)));
-               fragacct(blk, cgp->cg_frsum, -1);
+                      (0xff >> (NBBY - fs->fs_frag)));
+               fragacct(fs, blk, cgp->cg_frsum, -1);
                /*
                 * deallocate the fragment
                 */
                /*
                 * deallocate the fragment
                 */
-               frags = size / FSIZE;
+               frags = size / fs->fs_fsize;
                for (i = 0; i < frags; i++) {
                        if (isset(cgp->cg_free, bno + i))
                                panic("free: freeing free frag");
                        setbit(cgp->cg_free, bno + i);
                        cgp->cg_cs.cs_nffree++;
                        fs->fs_cstotal.cs_nffree++;
                for (i = 0; i < frags; i++) {
                        if (isset(cgp->cg_free, bno + i))
                                panic("free: freeing free frag");
                        setbit(cgp->cg_free, bno + i);
                        cgp->cg_cs.cs_nffree++;
                        fs->fs_cstotal.cs_nffree++;
-                       fs->fs_cs(cg).cs_nffree++;
+                       fs->fs_cs(fs, cg).cs_nffree++;
                }
                /*
                 * add back in counts associated with the new frags
                 */
                blk = ((cgp->cg_free[bbase / NBBY] >> (bbase % NBBY)) &
                }
                /*
                 * add back in counts associated with the new frags
                 */
                blk = ((cgp->cg_free[bbase / NBBY] >> (bbase % NBBY)) &
-                      (0xff >> (NBBY - FRAG)));
-               fragacct(blk, cgp->cg_frsum, 1);
+                      (0xff >> (NBBY - fs->fs_frag)));
+               fragacct(fs, blk, cgp->cg_frsum, 1);
                /*
                 * if a complete block has been reassembled, account for it
                 */
                /*
                 * if a complete block has been reassembled, account for it
                 */
-               if (isblock(cgp->cg_free, bbase / FRAG)) {
-                       cgp->cg_cs.cs_nffree -= FRAG;
-                       fs->fs_cstotal.cs_nffree -= FRAG;
-                       fs->fs_cs(cg).cs_nffree -= FRAG;
+               if (isblock(fs, cgp->cg_free, bbase / fs->fs_frag)) {
+                       cgp->cg_cs.cs_nffree -= fs->fs_frag;
+                       fs->fs_cstotal.cs_nffree -= fs->fs_frag;
+                       fs->fs_cs(fs, cg).cs_nffree -= fs->fs_frag;
                        cgp->cg_cs.cs_nbfree++;
                        fs->fs_cstotal.cs_nbfree++;
                        cgp->cg_cs.cs_nbfree++;
                        fs->fs_cstotal.cs_nbfree++;
-                       fs->fs_cs(cg).cs_nbfree++;
-                       i = bbase * NSPF;
+                       fs->fs_cs(fs, cg).cs_nbfree++;
+                       i = bbase * NSPF(fs);
                        cgp->cg_b[i / fs->fs_spc]
                                 [i % fs->fs_nsect * NRPOS / fs->fs_nsect]++;
                }
                        cgp->cg_b[i / fs->fs_spc]
                                 [i % fs->fs_nsect * NRPOS / fs->fs_nsect]++;
                }
@@ -582,7 +582,7 @@ ifree(dev, ino, mode)
        if ((unsigned)ino >= fs->fs_ipg*fs->fs_ncg)
                panic("ifree: range");
        cg = itog(ino, fs);
        if ((unsigned)ino >= fs->fs_ipg*fs->fs_ncg)
                panic("ifree: range");
        cg = itog(ino, fs);
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return;
        cgp = bp->b_un.b_cg;
        if (bp->b_flags & B_ERROR)
                return;
        cgp = bp->b_un.b_cg;
@@ -592,11 +592,11 @@ ifree(dev, ino, mode)
        clrbit(cgp->cg_iused, ino);
        cgp->cg_cs.cs_nifree++;
        fs->fs_cstotal.cs_nifree++;
        clrbit(cgp->cg_iused, ino);
        cgp->cg_cs.cs_nifree++;
        fs->fs_cstotal.cs_nifree++;
-       fs->fs_cs(cg).cs_nifree++;
+       fs->fs_cs(fs, cg).cs_nifree++;
        if ((mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir--;
                fs->fs_cstotal.cs_ndir--;
        if ((mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir--;
                fs->fs_cstotal.cs_ndir--;
-               fs->fs_cs(cg).cs_ndir--;
+               fs->fs_cs(fs, cg).cs_ndir--;
        }
        fs->fs_fmod++;
        bdwrite(bp);
        }
        fs->fs_fmod++;
        bdwrite(bp);
@@ -627,12 +627,13 @@ mapsearch(fs, cgp, bpref, allocsiz)
        else
                start = cgp->cg_frotor / NBBY;
        len = roundup(fs->fs_fpg - 1, NBBY) / NBBY - start;
        else
                start = cgp->cg_frotor / NBBY;
        len = roundup(fs->fs_fpg - 1, NBBY) / NBBY - start;
-       loc = scanc(len, &cgp->cg_free[start], fragtbl, 1 << (allocsiz - 1));
+       loc = scanc(len, &cgp->cg_free[start], fragtbl[fs->fs_frag],
+               1 << (allocsiz - 1));
        if (loc == 0) {
                len = start - 1;
                start = (cgdmin(cgp->cg_cgx, fs) -
                         cgbase(cgp->cg_cgx, fs)) / NBBY;
        if (loc == 0) {
                len = start - 1;
                start = (cgdmin(cgp->cg_cgx, fs) -
                         cgbase(cgp->cg_cgx, fs)) / NBBY;
-               loc = scanc(len, &cgp->cg_free[start], fragtbl,
+               loc = scanc(len, &cgp->cg_free[start], fragtbl[fs->fs_frag],
                        1 << (allocsiz - 1));
                if (loc == 0) {
                        panic("alloccg: map corrupted");
                        1 << (allocsiz - 1));
                if (loc == 0) {
                        panic("alloccg: map corrupted");
@@ -645,12 +646,13 @@ mapsearch(fs, cgp, bpref, allocsiz)
         * found the byte in the map
         * sift through the bits to find the selected frag
         */
         * found the byte in the map
         * sift through the bits to find the selected frag
         */
-       for (i = 0; i < NBBY; i += FRAG) {
-               blk = (cgp->cg_free[bno / NBBY] >> i) & (0xff >> NBBY - FRAG);
+       for (i = 0; i < NBBY; i += fs->fs_frag) {
+               blk = (cgp->cg_free[bno / NBBY] >> i) &
+                     (0xff >> NBBY - fs->fs_frag);
                blk <<= 1;
                field = around[allocsiz];
                subfield = inside[allocsiz];
                blk <<= 1;
                field = around[allocsiz];
                subfield = inside[allocsiz];
-               for (pos = 0; pos <= FRAG - allocsiz; pos++) {
+               for (pos = 0; pos <= fs->fs_frag - allocsiz; pos++) {
                        if ((blk & field) == subfield) {
                                return (bno + i + pos);
                        }
                        if ((blk & field) == subfield) {
                                return (bno + i + pos);
                        }
@@ -666,7 +668,8 @@ mapsearch(fs, cgp, bpref, allocsiz)
  * update the frsum fields to reflect addition or deletion 
  * of some frags
  */
  * update the frsum fields to reflect addition or deletion 
  * of some frags
  */
-fragacct(fragmap, fraglist, cnt)
+fragacct(fs, fragmap, fraglist, cnt)
+       struct fs *fs;
        int fragmap;
        long fraglist[];
        int cnt;
        int fragmap;
        long fraglist[];
        int cnt;
@@ -675,14 +678,14 @@ fragacct(fragmap, fraglist, cnt)
        register int field, subfield;
        register int siz, pos;
 
        register int field, subfield;
        register int siz, pos;
 
-       inblk = (int)(fragtbl[fragmap]) << 1;
+       inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1;
        fragmap <<= 1;
        fragmap <<= 1;
-       for (siz = 1; siz < FRAG; siz++) {
+       for (siz = 1; siz < fs->fs_frag; siz++) {
                if (((1 << siz) & inblk) == 0)
                        continue;
                field = around[siz];
                subfield = inside[siz];
                if (((1 << siz) & inblk) == 0)
                        continue;
                field = around[siz];
                subfield = inside[siz];
-               for (pos = siz; pos <= FRAG; pos++) {
+               for (pos = siz; pos <= fs->fs_frag; pos++) {
                        if ((fragmap & field) == subfield) {
                                fraglist[siz] += cnt;
                                pos += siz;
                        if ((fragmap & field) == subfield) {
                                fraglist[siz] += cnt;
                                pos += siz;
@@ -805,16 +808,17 @@ update()
                                continue;
                        if (fs->fs_ronly != 0)
                                panic("update: rofs mod");
                                continue;
                        if (fs->fs_ronly != 0)
                                panic("update: rofs mod");
-                       bp = getblk(mp->m_dev, SBLOCK, BSIZE);
+                       bp = getblk(mp->m_dev, SBLOCK, MAXBSIZE);
                        fs->fs_fmod = 0;
                        fs->fs_time = TIME;
                        if (bp->b_un.b_fs != fs)
                                panic("update: bad b_fs");
                        bwrite(bp);
                        fs->fs_fmod = 0;
                        fs->fs_time = TIME;
                        if (bp->b_un.b_fs != fs)
                                panic("update: bad b_fs");
                        bwrite(bp);
-                       blks = howmany(cssize(fs), BSIZE);
+                       blks = howmany(fs->fs_cssize, fs->fs_bsize);
                        for (i = 0; i < blks; i++) {
                        for (i = 0; i < blks; i++) {
-                               bp = getblk(mp->m_dev, csaddr(fs) + (i * FRAG),
-                                       BSIZE);
+                               bp = getblk(mp->m_dev,
+                                   fsbtodb(fs, fs->fs_csaddr + (i * fs->fs_frag)),
+                                   fs->fs_bsize);
                                bwrite(bp);
                        }
                }
                                bwrite(bp);
                        }
                }
@@ -836,3 +840,78 @@ update()
         */
        bflush(NODEV);
 }
         */
        bflush(NODEV);
 }
+
+/*
+ * block macros
+ */
+
+isblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       unsigned char mask;
+
+       switch (fs->fs_frag) {
+       case 8:
+               return (cp[h] == 0xff);
+       case 4:
+               mask = 0x0f << ((h & 0x1) << 2);
+               return ((cp[h >> 1] & mask) == mask);
+       case 2:
+               mask = 0x03 << ((h & 0x3) << 1);
+               return ((cp[h >> 2] & mask) == mask);
+       case 1:
+               mask = 0x01 << (h & 0x7);
+               return ((cp[h >> 3] & mask) == mask);
+       default:
+               panic("isblock bad fs_frag");
+               return;
+       }
+}
+clrblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       switch ((fs)->fs_frag) {
+       case 8:
+               cp[h] = 0;
+               return;
+       case 4:
+               cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
+               return;
+       case 2:
+               cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
+               return;
+       case 1:
+               cp[h >> 3] &= ~(0x01 << (h & 0x7));
+               return;
+       default:
+               panic("clrblock bad fs_frag");
+               return;
+       }
+}
+setblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       switch (fs->fs_frag) {
+       case 8:
+               cp[h] = 0xff;
+               return;
+       case 4:
+               cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
+               return;
+       case 2:
+               cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
+               return;
+       case 1:
+               cp[h >> 3] |= (0x01 << (h & 0x7));
+               return;
+       default:
+               panic("setblock bad fs_frag");
+               return;
+       }
+}
index 04d888a..9d991cb 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1981 Regents of the University of California */
 
 /* Copyright (c) 1981 Regents of the University of California */
 
-/* @(#)ffs_tables.c 1.2 %G% */
+/* @(#)ffs_tables.c 1.3 %G% */
 
 #include "../h/param.h"
 
 
 #include "../h/param.h"
 
@@ -68,17 +68,89 @@ int inside[9] = {
 };
 
 /*
 };
 
 /*
- * given a block map bit pattern, this table tells whether a
+ * given a block map bit pattern, the frag tables tell whether a
  * particular size fragment is available. 
  * particular size fragment is available. 
+ *
  * used as:
  * used as:
- * if ((1 << (size - 1)) & fragtbl[map]) {
+ * if ((1 << (size - 1)) & fragtbl[fs->fs_frag][map] {
  *     at least one fragment of the indicated size is available
  * }
  *     at least one fragment of the indicated size is available
  * }
- * This table is used by the scanc instruction on the VAX to
+ *
+ * These tables are used by the scanc instruction on the VAX to
  * quickly find an appropriate fragment.
  */
  * quickly find an appropriate fragment.
  */
-#if FRAG == 4
-unsigned char fragtbl[256] = {
+
+unsigned char fragtbl1[256] = {
+       0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+       0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
+};
+
+unsigned char fragtbl2[256] = {
+       0x0, 0x1, 0x1, 0x2, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x2, 0x3, 0x3, 0x2,
+       0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x2, 0x3, 0x3, 0x2, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x2, 0x3, 0x3, 0x2,
+       0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x1, 0x3,
+       0x1, 0x1, 0x1, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x2, 0x3, 0x3, 0x2, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x2, 0x3, 0x3, 0x2,
+       0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3,
+       0x2, 0x3, 0x3, 0x2, 0x3, 0x3, 0x3, 0x3,
+       0x3, 0x3, 0x3, 0x3, 0x2, 0x3, 0x3, 0x2,
+};
+
+unsigned char fragtbl4[256] = {
        0x0, 0x1, 0x1, 0x2, 0x1, 0x1, 0x2, 0x4,
        0x1, 0x1, 0x1, 0x3, 0x2, 0x3, 0x4, 0x8,
        0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x3, 0x5,
        0x0, 0x1, 0x1, 0x2, 0x1, 0x1, 0x2, 0x4,
        0x1, 0x1, 0x1, 0x3, 0x2, 0x3, 0x4, 0x8,
        0x1, 0x1, 0x1, 0x3, 0x1, 0x1, 0x3, 0x5,
@@ -112,10 +184,8 @@ unsigned char fragtbl[256] = {
        0x8, 0x9, 0x9, 0xa, 0x9, 0x9, 0xa, 0xc,
        0x9, 0x9, 0x9, 0xb, 0xa, 0xb, 0xc, 0x8,
 };
        0x8, 0x9, 0x9, 0xa, 0x9, 0x9, 0xa, 0xc,
        0x9, 0x9, 0x9, 0xb, 0xa, 0xb, 0xc, 0x8,
 };
-#endif
 
 
-#if FRAG == 8
-unsigned char fragtbl[256] = {
+unsigned char fragtbl8[256] = {
        0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x04,
        0x01, 0x01, 0x01, 0x03, 0x02, 0x03, 0x04, 0x08,
        0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
        0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x04,
        0x01, 0x01, 0x01, 0x03, 0x02, 0x03, 0x04, 0x08,
        0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
@@ -149,4 +219,10 @@ unsigned char fragtbl[256] = {
        0x08, 0x09, 0x09, 0x0a, 0x09, 0x09, 0x0a, 0x0c,
        0x10, 0x11, 0x11, 0x12, 0x20, 0x21, 0x40, 0x80,
 };
        0x08, 0x09, 0x09, 0x0a, 0x09, 0x09, 0x0a, 0x0c,
        0x10, 0x11, 0x11, 0x12, 0x20, 0x21, 0x40, 0x80,
 };
-#endif
+
+/*
+ * the actual fragtbl array
+ */
+unsigned char *fragtbl[MAXFRAG + 1] = {
+       0, fragtbl1, fragtbl2, 0, fragtbl4, 0, 0, 0, fragtbl8,
+};
index 99adbe1..1d4dfa9 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1981 Regents of the University of California */
 
 /* Copyright (c) 1981 Regents of the University of California */
 
-/*     fs.h    1.8     %G%     */
+/*     fs.h    1.9     %G%     */
 
 /*
  * Each disk drive contains some number of file systems.
 
 /*
  * Each disk drive contains some number of file systems.
  * For file system fs and a cylinder group number cg:
  *     [BBLOCK]        Boot sector and bad block information
  *     [SBLOCK]        Super-block
  * For file system fs and a cylinder group number cg:
  *     [BBLOCK]        Boot sector and bad block information
  *     [SBLOCK]        Super-block
- *     [CBLOCK]        Cylinder group block
- *     [IBLOCK..IBLOCK+fs.fs_ipg/INOPB)
+ *     [CBLOCK(fs)]    Cylinder group block
+ *     [IBLOCK(fs)..IBLOCK(fs)+fs.fs_ipg/INOPB(fs))
  *                     Inode blocks
  *                     Inode blocks
- *     [IBLOCK+fs.fs_ipg/INOPB..fs.fs_fpg/FRAG)
+ *     [IBLOCK(fs)+fs.fs_ipg/INOPB(fs)..fs.fs_fpg/fs.fs_frag)
  *                     Data blocks
  *                     Data blocks
- * The beginning of data blocks for cg in fs is also given by cgdmin(cg,fs).
+ * The beginning of data blocks for cg in fs is also given by
+ * the ``cgdmin(cg,fs)'' macro.
+ *
+ * The boot and super blocks are given in absolute disk addresses.
+ */
+#define        BBLOCK          ((daddr_t)(0 * (MAXBSIZE / DEV_BSIZE)))
+#define        SBLOCK          ((daddr_t)(1 * (MAXBSIZE / DEV_BSIZE)))
+/*
+ * The cylinder group and inode blocks are given in file system
+ * addresses, and hence must be converted to disk addresses by
+ * the ``fsbtodb(fs, bno)'' macro.
  */
  */
-#define        BBLOCK  ((daddr_t)(0*FRAG))
-#define        SBLOCK  ((daddr_t)(1*FRAG))
-#define        CBLOCK  ((daddr_t)(2*FRAG))
-#define        IBLOCK  ((daddr_t)(3*FRAG))
+#define        CBLOCK(fs)      ((daddr_t)(dbtofsb(fs, 2 * (MAXBSIZE / DEV_BSIZE))))
+#define        IBLOCK(fs)      ((daddr_t)(CBLOCK(fs) + (fs)->fs_frag))
 
 /*
 
 /*
- * Addresses stored in inodes are capable of addressing fragments of `blocks.'
- * File system blocks of size BSIZE can be broken into FRAG pieces,
- * each of which is addressible; these pieces may be sectors, or some
- * multiple of a sector size (e.g. 1k byte units).
+ * Addresses stored in inodes are capable of addressing fragments
+ * of `blocks'. File system blocks of at most size MAXBSIZE can 
+ * be optionally broken into 2, 4, or 8 pieces, each of which is
+ * addressible; these pieces may be DEV_BSIZE, or some multiple of
+ * a DEV_BSIZE unit.
  *
  *
- * Large files consist of exclusively large (BSIZE) data blocks.  To avoid
- * undue fragmentation, the last data block of a small file may be
- * allocated as only as many pieces
- * of a large block as are necessary.  The file system format retains
- * only a single pointer to such a fragment, which is a piece of a single
- * BSIZE block which has been divided.  The size of such a fragment is
- * determinable from information in the inode.
+ * Large files consist of exclusively large data blocks.  To avoid
+ * undue wasted disk space, the last data block of a small file may be
+ * allocated as only as many fragments of a large block as are
+ * necessary.  The file system format retains only a single pointer
+ * to such a fragment, which is a piece of a single large block that
+ * has been divided.  The size of such a fragment is determinable from
+ * information in the inode, using the ``blksize(fs, ip, lbn)'' macro.
  *
  * The file system records space availability at the fragment level;
  * to determine block availability, aligned fragments are examined.
  *
  * The file system records space availability at the fragment level;
  * to determine block availability, aligned fragments are examined.
 /*
  * Information per cylinder group summarized in blocks allocated
  * from first cylinder group data blocks.  These blocks have to be
 /*
  * Information per cylinder group summarized in blocks allocated
  * from first cylinder group data blocks.  These blocks have to be
- * specially noticed in mkfs, icheck and fsck.
+ * read in from fs_csaddr (size fs_cssize) in addition to the
+ * super block.
+ * N.B. sizeof(struct csum) must be a power of two in order for
+ * the ``fs_cs'' macro to work (see below).
  */
 struct csum {
        long    cs_ndir;        /* number of directories */
  */
 struct csum {
        long    cs_ndir;        /* number of directories */
@@ -65,8 +77,6 @@ struct csum {
        long    cs_nifree;      /* number of free inodes */
        long    cs_nffree;      /* number of free frags */
 };
        long    cs_nifree;      /* number of free inodes */
        long    cs_nffree;      /* number of free frags */
 };
-#define        cssize(fs)      ((fs)->fs_ncg*sizeof(struct csum))
-#define        csaddr(fs)      (cgdmin(0, fs))
 
 /*
  * Each file system has a number of inodes statically allocated.
 
 /*
  * Each file system has a number of inodes statically allocated.
@@ -75,17 +85,28 @@ struct csum {
  */
 #define        NBPI    2048
 
  */
 #define        NBPI    2048
 
-#define        DESCPG  16                      /* desired fs_cpg */
-#define        MAXCPG  32                      /* maximum fs_cpg */
-/* MAXCPG is limited only to dimension an array in (struct cg); */
-/* it can be made larger as long as that structures size remains sane. */
+/*
+ * MINBSIZE is the smallest allowable block size.
+ * In order to insure that it is possible to create files of size
+ * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
+ * MINBSIZE must be big enough to hold a cylinder group block,
+ * thus changes to (struct cg) must keep its size within MINBSIZE.
+ * MAXCPG is limited only to dimension an array in (struct cg);
+ * it can be made larger as long as that structures size remains
+ * within the bounds dictated by MINBSIZE.
+ * Note that super blocks are always of size MAXBSIZE,
+ * and that MAXBSIZE must be >= MINBSIZE.
+ */
+#define MINBSIZE       4096
+#define        DESCPG          16      /* desired fs_cpg */
+#define        MAXCPG          32      /* maximum fs_cpg */
  
 /*
  * Super block for a file system.
  *
  
 /*
  * Super block for a file system.
  *
- * The super block is nominally located at disk block 1 although
- * this is naive due to bad blocks.  Inode 0 can't be used for normal
- * purposes, historically bad blocks were linked to inode 1,
+ * The super block is nominally located at disk block SBLOCK.
+ * Inode 0 can't be used for normal purposes,
+ * historically bad blocks were linked to inode 1,
  * thus the root inode is 2. (inode 1 is no longer used for
  * this purpose, however numerous dump tapes make this
  * assumption, so we are stuck with it)
  * thus the root inode is 2. (inode 1 is no longer used for
  * this purpose, however numerous dump tapes make this
  * assumption, so we are stuck with it)
@@ -101,7 +122,13 @@ struct     fs
        long    fs_size;                /* number of blocks in fs */
        long    fs_dsize;               /* number of data blocks in fs */
        long    fs_ncg;                 /* number of cylinder groups */
        long    fs_size;                /* number of blocks in fs */
        long    fs_dsize;               /* number of data blocks in fs */
        long    fs_ncg;                 /* number of cylinder groups */
+       long    fs_bsize;               /* size of basic blocks in fs */
+       long    fs_fsize;               /* size of frag blocks in fs */
+       long    fs_frag;                /* number of frags in a block in fs */
+       short   fs_minfree;             /* minimum percentage of free blocks */
+       short   fs_rotdelay;            /* num of ms for optimal next block */
 /* sizes determined by number of cylinder groups and their sizes */
 /* sizes determined by number of cylinder groups and their sizes */
+       daddr_t fs_csaddr;              /* blk addr of cyl grp summary area */
        long    fs_cssize;              /* size of cyl grp summary area */
        long    fs_cgsize;              /* cylinder group size */
 /* these fields should be derived from the hardware */
        long    fs_cssize;              /* size of cyl grp summary area */
        long    fs_cgsize;              /* cylinder group size */
 /* these fields should be derived from the hardware */
@@ -113,7 +140,7 @@ struct      fs
 /* these fields can be computed from the others */
        short   fs_cpg;                 /* cylinders per group */
        short   fs_ipg;                 /* inodes per group */
 /* these fields can be computed from the others */
        short   fs_cpg;                 /* cylinders per group */
        short   fs_ipg;                 /* inodes per group */
-       long    fs_fpg;                 /* blocks per group*FRAG */
+       long    fs_fpg;                 /* blocks per group * fs_frag */
 /* this data must be re-computed after crashes */
        struct  csum fs_cstotal;        /* cylinder summary information */
 /* these fields are cleared at mount time */
 /* this data must be re-computed after crashes */
        struct  csum fs_cstotal;        /* cylinder summary information */
 /* these fields are cleared at mount time */
@@ -127,8 +154,14 @@ struct     fs
        short   fs_rotbl[1];            /* list of blocks for each rotation */
 /* actually longer */
 };
        short   fs_rotbl[1];            /* list of blocks for each rotation */
 /* actually longer */
 };
-#define fs_cs(indx) fs_csp[(indx) / (BSIZE / sizeof(struct csum))] \
-                         [(indx) % (BSIZE / sizeof(struct csum))]
+
+/*
+ * convert cylinder group to base address of its global summary info.
+ * N.B. This macro assumes that sizeof(struct csum) is a power of two.
+ */
+#define fs_cs(fs, indx) \
+       fs_csp[(indx) / ((fs)->fs_bsize / sizeof(struct csum))] \
+       [(indx) % ((fs)->fs_bsize / sizeof(struct csum))]
 
 /*
  * Cylinder group macros to locate things in cylinder groups.
 
 /*
  * Cylinder group macros to locate things in cylinder groups.
@@ -139,32 +172,32 @@ struct    fs
 
 /* cylinder group to spare super block address */
 #define        cgsblock(c,fs)  \
 
 /* cylinder group to spare super block address */
 #define        cgsblock(c,fs)  \
-       (cgbase(c,fs) + SBLOCK)
+       (cgbase(c,fs) + dbtofsb(fs, SBLOCK))
 
 /* convert cylinder group to index of its cg block */
 #define        cgtod(c,fs)     \
 
 /* convert cylinder group to index of its cg block */
 #define        cgtod(c,fs)     \
-       (cgbase(c,fs) + CBLOCK)
+       (cgbase(c,fs) + CBLOCK(fs))
 
 /* give address of first inode block in cylinder group */
 #define        cgimin(c,fs)    \
 
 /* give address of first inode block in cylinder group */
 #define        cgimin(c,fs)    \
-       (cgbase(c,fs) + IBLOCK)
+       (cgbase(c,fs) + IBLOCK(fs))
 
 /* give address of first data block in cylinder group */
 
 /* give address of first data block in cylinder group */
-#define        cgdmin(c,fs)    (cgimin(c,fs) + (fs)->fs_ipg / INOPF)
+#define        cgdmin(c,fs)    (cgimin(c,fs) + (fs)->fs_ipg / INOPF(fs))
 
 /* turn inode number into cylinder group number */
 #define        itog(x,fs)      ((x)/(fs)->fs_ipg)
 
 
 /* turn inode number into cylinder group number */
 #define        itog(x,fs)      ((x)/(fs)->fs_ipg)
 
-/* turn inode number into disk block address */
-#define        itod(x,fs)      ((daddr_t)(cgimin(itog(x,fs),fs)+FRAG*((x)%(fs)->fs_ipg/INOPB)))
+/* turn inode number into file system block address */
+#define        itod(x,fs)      ((daddr_t)(cgimin(itog(x,fs),fs)+(fs)->fs_frag*((x)%(fs)->fs_ipg/INOPB(fs))))
 
 
-/* turn inode number into disk block offset */
-#define        itoo(x)         ((x)%INOPB)
+/* turn inode number into file system block offset */
+#define        itoo(x,fs)      ((x)%INOPB(fs))
 
 
-/* give cylinder group number for a disk block */
+/* give cylinder group number for a file system block */
 #define        dtog(d,fs)      ((d)/(fs)->fs_fpg)
 
 #define        dtog(d,fs)      ((d)/(fs)->fs_fpg)
 
-/* give cylinder group block number for a disk block */
+/* give cylinder group block number for a file system block */
 #define        dtogd(d,fs)     ((d)%(fs)->fs_fpg)
 
 /*
 #define        dtogd(d,fs)     ((d)%(fs)->fs_fpg)
 
 /*
@@ -186,7 +219,8 @@ struct      fs
  * Its size is derived from the size of blocks and the (struct cg) size,
  * by the number of remaining bits.
  */
  * Its size is derived from the size of blocks and the (struct cg) size,
  * by the number of remaining bits.
  */
-#define        MAXBPG  (NBBY*(BSIZE-(sizeof (struct cg)))/FRAG)
+#define        MAXBPG(fs) \
+       (NBBY*((fs)->fs_bsize-(sizeof (struct cg)))/(fs)->fs_frag)
 
 #define        CG_MAGIC        0x092752
 struct cg {
 
 #define        CG_MAGIC        0x092752
 struct cg {
@@ -200,7 +234,7 @@ struct      cg {
        long    cg_rotor;               /* position of last used block */
        long    cg_frotor;              /* position of last used frag */
        long    cg_irotor;              /* position of last used inode */
        long    cg_rotor;               /* position of last used block */
        long    cg_frotor;              /* position of last used frag */
        long    cg_irotor;              /* position of last used inode */
-       long    cg_frsum[FRAG];         /* counts of available frags */
+       long    cg_frsum[MAXFRAG];      /* counts of available frags */
        short   cg_b[MAXCPG][NRPOS];    /* positions of free blocks */
        char    cg_iused[MAXIPG/NBBY];  /* used inode map */
        char    cg_free[1];             /* free block map */
        short   cg_b[MAXCPG][NRPOS];    /* positions of free blocks */
        char    cg_iused[MAXIPG/NBBY];  /* used inode map */
        char    cg_free[1];             /* free block map */
index 33f4d4c..813fba5 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1981 Regents of the University of California */
 
 /* Copyright (c) 1981 Regents of the University of California */
 
-static char vers[] = "@(#)lfs_alloc.c 1.10 %G%";
+static char vers[] = "@(#)lfs_alloc.c 1.11 %G%";
 
 /*     alloc.c 4.8     81/03/08        */
 
 
 /*     alloc.c 4.8     81/03/08        */
 
@@ -22,7 +22,7 @@ extern daddr_t                fragextend();
 extern daddr_t         blkpref();
 extern daddr_t         mapsearch();
 extern int             inside[], around[];
 extern daddr_t         blkpref();
 extern daddr_t         mapsearch();
 extern int             inside[], around[];
-extern unsigned char   fragtbl[];
+extern unsigned char   *fragtbl[];
 
 struct buf *
 alloc(dev, ip, bpref, size)
 
 struct buf *
 alloc(dev, ip, bpref, size)
@@ -36,14 +36,14 @@ alloc(dev, ip, bpref, size)
        register struct buf *bp;
        int cg;
        
        register struct buf *bp;
        int cg;
        
-       if ((unsigned)size > BSIZE || size % FSIZE != 0)
-               panic("alloc: bad size");
        fs = getfs(dev);
        fs = getfs(dev);
-       if (size == BSIZE && fs->fs_cstotal.cs_nbfree == 0)
+       if ((unsigned)size > fs->fs_bsize || size % fs->fs_fsize != 0)
+               panic("alloc: bad size");
+       if (size == fs->fs_bsize && fs->fs_cstotal.cs_nbfree == 0)
                goto nospace;
        if (u.u_uid != 0 &&
                goto nospace;
        if (u.u_uid != 0 &&
-           fs->fs_cstotal.cs_nbfree * FRAG + fs->fs_cstotal.cs_nffree <
-             fs->fs_dsize * minfree / 100)
+           fs->fs_cstotal.cs_nbfree * fs->fs_frag + fs->fs_cstotal.cs_nffree <
+             fs->fs_dsize * fs->fs_minfree / 100)
                goto nospace;
        if (bpref >= fs->fs_size)
                bpref = 0;
                goto nospace;
        if (bpref >= fs->fs_size)
                bpref = 0;
@@ -54,7 +54,7 @@ alloc(dev, ip, bpref, size)
        bno = (daddr_t)hashalloc(dev, fs, cg, (long)bpref, size, alloccg);
        if (bno == 0)
                goto nospace;
        bno = (daddr_t)hashalloc(dev, fs, cg, (long)bpref, size, alloccg);
        if (bno == 0)
                goto nospace;
-       bp = getblk(dev, bno, size);
+       bp = getblk(dev, fsbtodb(fs, bno), size);
        clrbuf(bp);
        return (bp);
 nospace:
        clrbuf(bp);
        return (bp);
 nospace:
@@ -76,13 +76,13 @@ realloccg(dev, bprev, bpref, osize, nsize)
        caddr_t cp;
        int cg;
        
        caddr_t cp;
        int cg;
        
-       if ((unsigned)osize > BSIZE || osize % FSIZE != 0 ||
-           (unsigned)nsize > BSIZE || nsize % FSIZE != 0)
-               panic("realloccg: bad size");
        fs = getfs(dev);
        fs = getfs(dev);
+       if ((unsigned)osize > fs->fs_bsize || osize % fs->fs_fsize != 0 ||
+           (unsigned)nsize > fs->fs_bsize || nsize % fs->fs_fsize != 0)
+               panic("realloccg: bad size");
        if (u.u_uid != 0 &&
        if (u.u_uid != 0 &&
-           fs->fs_cstotal.cs_nbfree * FRAG + fs->fs_cstotal.cs_nffree <
-             fs->fs_dsize * minfree / 100)
+           fs->fs_cstotal.cs_nbfree * fs->fs_frag + fs->fs_cstotal.cs_nffree <
+             fs->fs_dsize * fs->fs_minfree / 100)
                goto nospace;
        if (bprev == 0)
                panic("realloccg: bad bprev");
                goto nospace;
        if (bprev == 0)
                panic("realloccg: bad bprev");
@@ -90,7 +90,7 @@ realloccg(dev, bprev, bpref, osize, nsize)
                cg = dtog(bprev, fs);
        bno = fragextend(dev, fs, cg, (long)bprev, osize, nsize);
        if (bno != 0) {
                cg = dtog(bprev, fs);
        bno = fragextend(dev, fs, cg, (long)bprev, osize, nsize);
        if (bno != 0) {
-               bp = bread(dev, bno, osize);
+               bp = bread(dev, fsbtodb(fs, bno), osize);
                bp->b_bcount = nsize;
                blkclr(bp->b_un.b_addr + osize, nsize - osize);
                return (bp);
                bp->b_bcount = nsize;
                blkclr(bp->b_un.b_addr + osize, nsize - osize);
                return (bp);
@@ -102,8 +102,8 @@ realloccg(dev, bprev, bpref, osize, nsize)
                /*
                 * make a new copy
                 */
                /*
                 * make a new copy
                 */
-               obp = bread(dev, bprev, osize);
-               bp = getblk(dev, bno, nsize);
+               obp = bread(dev, fsbtodb(fs, bprev), osize);
+               bp = getblk(dev, fsbtodb(fs, bno), nsize);
                cp = bp->b_un.b_addr;
                bp->b_un.b_addr = obp->b_un.b_addr;
                obp->b_un.b_addr = cp;
                cp = bp->b_un.b_addr;
                bp->b_un.b_addr = obp->b_un.b_addr;
                obp->b_un.b_addr = cp;
@@ -172,10 +172,10 @@ dirpref(dev)
        minndir = fs->fs_ipg;
        mincg = 0;
        for (cg = 0; cg < fs->fs_ncg; cg++)
        minndir = fs->fs_ipg;
        mincg = 0;
        for (cg = 0; cg < fs->fs_ncg; cg++)
-               if (fs->fs_cs(cg).cs_ndir < minndir &&
-                   fs->fs_cs(cg).cs_nifree >= avgifree) {
+               if (fs->fs_cs(fs, cg).cs_ndir < minndir &&
+                   fs->fs_cs(fs, cg).cs_nifree >= avgifree) {
                        mincg = cg;
                        mincg = cg;
-                       minndir = fs->fs_cs(cg).cs_ndir;
+                       minndir = fs->fs_cs(fs, cg).cs_ndir;
                }
        return (fs->fs_ipg * mincg);
 }
                }
        return (fs->fs_ipg * mincg);
 }
@@ -193,14 +193,14 @@ blkpref(dev)
        fs = getfs(dev);
        avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
        for (cg = fs->fs_cgrotor + 1; cg < fs->fs_ncg; cg++)
        fs = getfs(dev);
        avgbfree = fs->fs_cstotal.cs_nbfree / fs->fs_ncg;
        for (cg = fs->fs_cgrotor + 1; cg < fs->fs_ncg; cg++)
-               if (fs->fs_cs(cg).cs_nbfree >= avgbfree) {
+               if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
                        fs->fs_cgrotor = cg;
                        fs->fs_cgrotor = cg;
-                       return (fs->fs_fpg * cg + FRAG);
+                       return (fs->fs_fpg * cg + fs->fs_frag);
                }
        for (cg = 0; cg <= fs->fs_cgrotor; cg++)
                }
        for (cg = 0; cg <= fs->fs_cgrotor; cg++)
-               if (fs->fs_cs(cg).cs_nbfree >= avgbfree) {
+               if (fs->fs_cs(fs, cg).cs_nbfree >= avgbfree) {
                        fs->fs_cgrotor = cg;
                        fs->fs_cgrotor = cg;
-                       return (fs->fs_fpg * cg + FRAG);
+                       return (fs->fs_fpg * cg + fs->fs_frag);
                }
        return (0);
 }
                }
        return (0);
 }
@@ -264,18 +264,18 @@ fragextend(dev, fs, cg, bprev, osize, nsize)
        int frags, bbase;
        int i;
 
        int frags, bbase;
        int i;
 
-       frags = nsize / FSIZE;
-       bbase = bprev % FRAG;
-       if (bbase > (bprev + frags - 1) % FRAG) {
+       frags = nsize / fs->fs_fsize;
+       bbase = bprev % fs->fs_frag;
+       if (bbase > (bprev + frags - 1) % fs->fs_frag) {
                /* cannot extend across a block boundry */
                return (0);
        }
                /* cannot extend across a block boundry */
                return (0);
        }
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
        bno = bprev % fs->fs_fpg;
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
        bno = bprev % fs->fs_fpg;
-       for (i = osize / FSIZE; i < frags; i++) {
+       for (i = osize / fs->fs_fsize; i < frags; i++) {
                if (isclr(cgp->cg_free, bno + i))
                        break;
        }
                if (isclr(cgp->cg_free, bno + i))
                        break;
        }
@@ -286,17 +286,17 @@ fragextend(dev, fs, cg, bprev, osize, nsize)
                 * increase the count on the remaining fragment (if any)
                 * allocate the extended piece
                 */
                 * increase the count on the remaining fragment (if any)
                 * allocate the extended piece
                 */
-               for (i = frags; i < FRAG - bbase; i++)
+               for (i = frags; i < fs->fs_frag - bbase; i++)
                        if (isclr(cgp->cg_free, bno + i))
                                break;
                        if (isclr(cgp->cg_free, bno + i))
                                break;
-               cgp->cg_frsum[i - osize / FSIZE]--;
+               cgp->cg_frsum[i - osize / fs->fs_fsize]--;
                if (i != frags)
                        cgp->cg_frsum[i - frags]++;
                if (i != frags)
                        cgp->cg_frsum[i - frags]++;
-               for (i = osize / FSIZE; i < frags; i++) {
+               for (i = osize / fs->fs_fsize; i < frags; i++) {
                        clrbit(cgp->cg_free, bno + i);
                        cgp->cg_cs.cs_nffree--;
                        fs->fs_cstotal.cs_nffree--;
                        clrbit(cgp->cg_free, bno + i);
                        cgp->cg_cs.cs_nffree--;
                        fs->fs_cstotal.cs_nffree--;
-                       fs->fs_cs(cg).cs_nffree--;
+                       fs->fs_cs(fs, cg).cs_nffree--;
                }
                fs->fs_fmod++;
                bdwrite(bp);
                }
                fs->fs_fmod++;
                bdwrite(bp);
@@ -320,13 +320,13 @@ alloccg(dev, fs, cg, bpref, size)
        int allocsiz;
        register int i;
 
        int allocsiz;
        register int i;
 
-       if (fs->fs_cs(cg).cs_nbfree == 0 && size == BSIZE)
+       if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize)
                return (0);
                return (0);
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
-       if (size == BSIZE) {
+       if (size == fs->fs_bsize) {
                bno = alloccgblk(fs, cgp, bpref);
                bdwrite(bp);
                return (bno);
                bno = alloccgblk(fs, cgp, bpref);
                bdwrite(bp);
                return (bno);
@@ -336,11 +336,11 @@ alloccg(dev, fs, cg, bpref, size)
         * allocsiz is the size which will be allocated, hacking
         * it down to a smaller size if necessary
         */
         * allocsiz is the size which will be allocated, hacking
         * it down to a smaller size if necessary
         */
-       frags = size / FSIZE;
-       for (allocsiz = frags; allocsiz < FRAG; allocsiz++)
+       frags = size / fs->fs_fsize;
+       for (allocsiz = frags; allocsiz < fs->fs_frag; allocsiz++)
                if (cgp->cg_frsum[allocsiz] != 0)
                        break;
                if (cgp->cg_frsum[allocsiz] != 0)
                        break;
-       if (allocsiz == FRAG) {
+       if (allocsiz == fs->fs_frag) {
                /*
                 * no fragments were available, so a block will be 
                 * allocated, and hacked up
                /*
                 * no fragments were available, so a block will be 
                 * allocated, and hacked up
@@ -351,12 +351,12 @@ alloccg(dev, fs, cg, bpref, size)
                }
                bno = alloccgblk(fs, cgp, bpref);
                bpref = bno % fs->fs_fpg;
                }
                bno = alloccgblk(fs, cgp, bpref);
                bpref = bno % fs->fs_fpg;
-               for (i = frags; i < FRAG; i++)
+               for (i = frags; i < fs->fs_frag; i++)
                        setbit(cgp->cg_free, bpref + i);
                        setbit(cgp->cg_free, bpref + i);
-               i = FRAG - frags;
+               i = fs->fs_frag - frags;
                cgp->cg_cs.cs_nffree += i;
                fs->fs_cstotal.cs_nffree += i;
                cgp->cg_cs.cs_nffree += i;
                fs->fs_cstotal.cs_nffree += i;
-               fs->fs_cs(cg).cs_nffree += i;
+               fs->fs_cs(fs, cg).cs_nffree += i;
                cgp->cg_frsum[i]++;
                bdwrite(bp);
                return (bno);
                cgp->cg_frsum[i]++;
                bdwrite(bp);
                return (bno);
@@ -368,7 +368,7 @@ alloccg(dev, fs, cg, bpref, size)
                clrbit(cgp->cg_free, bno + i);
        cgp->cg_cs.cs_nffree -= frags;
        fs->fs_cstotal.cs_nffree -= frags;
                clrbit(cgp->cg_free, bno + i);
        cgp->cg_cs.cs_nffree -= frags;
        fs->fs_cstotal.cs_nffree -= frags;
-       fs->fs_cs(cg).cs_nffree -= frags;
+       fs->fs_cs(fs, cg).cs_nffree -= frags;
        cgp->cg_frsum[allocsiz]--;
        if (frags != allocsiz)
                cgp->cg_frsum[allocsiz - frags]++;
        cgp->cg_frsum[allocsiz]--;
        if (frags != allocsiz)
                cgp->cg_frsum[allocsiz - frags]++;
@@ -390,12 +390,12 @@ alloccgblk(fs, cgp, bpref)
        if (bpref == 0) {
                bpref = cgp->cg_rotor;
        } else {
        if (bpref == 0) {
                bpref = cgp->cg_rotor;
        } else {
-               bpref &= ~(FRAG - 1);
+               bpref &= ~(fs->fs_frag - 1);
                bpref %= fs->fs_fpg;
                /*
                 * if the requested block is available, use it
                 */
                bpref %= fs->fs_fpg;
                /*
                 * if the requested block is available, use it
                 */
-               if (isblock(cgp->cg_free, bpref/FRAG)) {
+               if (isblock(fs, cgp->cg_free, bpref/fs->fs_frag)) {
                        bno = bpref;
                        goto gotit;
                }
                        bno = bpref;
                        goto gotit;
                }
@@ -403,12 +403,12 @@ alloccgblk(fs, cgp, bpref)
                 * check for a block available on the same cylinder
                 * beginning with one which is rotationally optimal
                 */
                 * check for a block available on the same cylinder
                 * beginning with one which is rotationally optimal
                 */
-               i = bpref * NSPF;
+               i = bpref * NSPF(fs);
                cylno = i / fs->fs_spc;
                cylbp = cgp->cg_b[cylno];
                cylno = i / fs->fs_spc;
                cylbp = cgp->cg_b[cylno];
-               pos = (i + (ROTDELAY == 0) ?
-                       0 : 1 + ROTDELAY * HZ * fs->fs_nsect / (NSPF * 1000)) %
-                       fs->fs_nsect * NRPOS / fs->fs_nsect;
+               pos = (i + (fs->fs_rotdelay == 0) ? 0 :
+                      1 + fs->fs_rotdelay * HZ * fs->fs_nsect /
+                      (NSPF(fs) * 1000)) % fs->fs_nsect * NRPOS / fs->fs_nsect;
                for (i = pos; i < NRPOS; i++)
                        if (cylbp[i] > 0)
                                break;
                for (i = pos; i < NRPOS; i++)
                        if (cylbp[i] > 0)
                                break;
@@ -417,26 +417,26 @@ alloccgblk(fs, cgp, bpref)
                                if (cylbp[i] > 0)
                                        break;
                if (cylbp[i] > 0) {
                                if (cylbp[i] > 0)
                                        break;
                if (cylbp[i] > 0) {
-                       bpref = cylno * fs->fs_spc / (NSPF * FRAG);
+                       bpref = cylno * fs->fs_spc / NSPB(fs);
                        for (j = fs->fs_postbl[i]; j > -1; j = fs->fs_rotbl[j]) {
                        for (j = fs->fs_postbl[i]; j > -1; j = fs->fs_rotbl[j]) {
-                               if (isblock(cgp->cg_free, bpref + j)) {
-                                       bno = (bpref + j) * FRAG;
+                               if (isblock(fs, cgp->cg_free, bpref + j)) {
+                                       bno = (bpref + j) * fs->fs_frag;
                                        goto gotit;
                                }
                        }
                        panic("alloccgblk: can't find blk in cyl");
                }
        }
                                        goto gotit;
                                }
                        }
                        panic("alloccgblk: can't find blk in cyl");
                }
        }
-       bno = mapsearch(fs, cgp, bpref, FRAG);
+       bno = mapsearch(fs, cgp, bpref, fs->fs_frag);
        if (bno == 0)
                return (0);
        cgp->cg_rotor = bno;
 gotit:
        if (bno == 0)
                return (0);
        cgp->cg_rotor = bno;
 gotit:
-       clrblock(cgp->cg_free, bno/FRAG);
+       clrblock(fs, cgp->cg_free, bno/fs->fs_frag);
        cgp->cg_cs.cs_nbfree--;
        fs->fs_cstotal.cs_nbfree--;
        cgp->cg_cs.cs_nbfree--;
        fs->fs_cstotal.cs_nbfree--;
-       fs->fs_cs(cgp->cg_cgx).cs_nbfree--;
-       i = bno * NSPF;
+       fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--;
+       i = bno * NSPF(fs);
        cgp->cg_b[i/fs->fs_spc][i%fs->fs_nsect*NRPOS/fs->fs_nsect]--;
        fs->fs_fmod++;
        return (cgp->cg_cgx * fs->fs_fpg + bno);
        cgp->cg_b[i/fs->fs_spc][i%fs->fs_nsect*NRPOS/fs->fs_nsect]--;
        fs->fs_fmod++;
        return (cgp->cg_cgx * fs->fs_fpg + bno);
@@ -454,9 +454,9 @@ ialloccg(dev, fs, cg, ipref, mode)
        register struct cg *cgp;
        int i;
 
        register struct cg *cgp;
        int i;
 
-       if (fs->fs_cs(cg).cs_nifree == 0)
+       if (fs->fs_cs(fs, cg).cs_nifree == 0)
                return (0);
                return (0);
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
        if (bp->b_flags & B_ERROR)
                return (0);
        cgp = bp->b_un.b_cg;
@@ -481,12 +481,12 @@ gotit:
        setbit(cgp->cg_iused, ipref);
        cgp->cg_cs.cs_nifree--;
        fs->fs_cstotal.cs_nifree--;
        setbit(cgp->cg_iused, ipref);
        cgp->cg_cs.cs_nifree--;
        fs->fs_cstotal.cs_nifree--;
-       fs->fs_cs(cg).cs_nifree--;
+       fs->fs_cs(fs, cg).cs_nifree--;
        fs->fs_fmod++;
        if ((mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir++;
                fs->fs_cstotal.cs_ndir++;
        fs->fs_fmod++;
        if ((mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir++;
                fs->fs_cstotal.cs_ndir++;
-               fs->fs_cs(cg).cs_ndir++;
+               fs->fs_cs(fs, cg).cs_ndir++;
        }
        bdwrite(bp);
        return (cg * fs->fs_ipg + ipref);
        }
        bdwrite(bp);
        return (cg * fs->fs_ipg + ipref);
@@ -503,63 +503,63 @@ fre(dev, bno, size)
        int cg, blk, frags, bbase;
        register int i;
 
        int cg, blk, frags, bbase;
        register int i;
 
-       if ((unsigned)size > BSIZE || size % FSIZE != 0)
-               panic("free: bad size");
        fs = getfs(dev);
        fs = getfs(dev);
+       if ((unsigned)size > fs->fs_bsize || size % fs->fs_fsize != 0)
+               panic("free: bad size");
        cg = dtog(bno, fs);
        if (badblock(fs, bno))
                return;
        cg = dtog(bno, fs);
        if (badblock(fs, bno))
                return;
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return;
        cgp = bp->b_un.b_cg;
        bno %= fs->fs_fpg;
        if (bp->b_flags & B_ERROR)
                return;
        cgp = bp->b_un.b_cg;
        bno %= fs->fs_fpg;
-       if (size == BSIZE) {
-               if (isblock(cgp->cg_free, bno/FRAG))
+       if (size == fs->fs_bsize) {
+               if (isblock(fs, cgp->cg_free, bno/fs->fs_frag))
                        panic("free: freeing free block");
                        panic("free: freeing free block");
-               setblock(cgp->cg_free, bno/FRAG);
+               setblock(fs, cgp->cg_free, bno/fs->fs_frag);
                cgp->cg_cs.cs_nbfree++;
                fs->fs_cstotal.cs_nbfree++;
                cgp->cg_cs.cs_nbfree++;
                fs->fs_cstotal.cs_nbfree++;
-               fs->fs_cs(cg).cs_nbfree++;
-               i = bno * NSPF;
+               fs->fs_cs(fs, cg).cs_nbfree++;
+               i = bno * NSPF(fs);
                cgp->cg_b[i/fs->fs_spc][i%fs->fs_nsect*NRPOS/fs->fs_nsect]++;
        } else {
                cgp->cg_b[i/fs->fs_spc][i%fs->fs_nsect*NRPOS/fs->fs_nsect]++;
        } else {
-               bbase = bno - (bno % FRAG);
+               bbase = bno - (bno % fs->fs_frag);
                /*
                 * decrement the counts associated with the old frags
                 */
                blk = ((cgp->cg_free[bbase / NBBY] >> (bbase % NBBY)) &
                /*
                 * decrement the counts associated with the old frags
                 */
                blk = ((cgp->cg_free[bbase / NBBY] >> (bbase % NBBY)) &
-                      (0xff >> (NBBY - FRAG)));
-               fragacct(blk, cgp->cg_frsum, -1);
+                      (0xff >> (NBBY - fs->fs_frag)));
+               fragacct(fs, blk, cgp->cg_frsum, -1);
                /*
                 * deallocate the fragment
                 */
                /*
                 * deallocate the fragment
                 */
-               frags = size / FSIZE;
+               frags = size / fs->fs_fsize;
                for (i = 0; i < frags; i++) {
                        if (isset(cgp->cg_free, bno + i))
                                panic("free: freeing free frag");
                        setbit(cgp->cg_free, bno + i);
                        cgp->cg_cs.cs_nffree++;
                        fs->fs_cstotal.cs_nffree++;
                for (i = 0; i < frags; i++) {
                        if (isset(cgp->cg_free, bno + i))
                                panic("free: freeing free frag");
                        setbit(cgp->cg_free, bno + i);
                        cgp->cg_cs.cs_nffree++;
                        fs->fs_cstotal.cs_nffree++;
-                       fs->fs_cs(cg).cs_nffree++;
+                       fs->fs_cs(fs, cg).cs_nffree++;
                }
                /*
                 * add back in counts associated with the new frags
                 */
                blk = ((cgp->cg_free[bbase / NBBY] >> (bbase % NBBY)) &
                }
                /*
                 * add back in counts associated with the new frags
                 */
                blk = ((cgp->cg_free[bbase / NBBY] >> (bbase % NBBY)) &
-                      (0xff >> (NBBY - FRAG)));
-               fragacct(blk, cgp->cg_frsum, 1);
+                      (0xff >> (NBBY - fs->fs_frag)));
+               fragacct(fs, blk, cgp->cg_frsum, 1);
                /*
                 * if a complete block has been reassembled, account for it
                 */
                /*
                 * if a complete block has been reassembled, account for it
                 */
-               if (isblock(cgp->cg_free, bbase / FRAG)) {
-                       cgp->cg_cs.cs_nffree -= FRAG;
-                       fs->fs_cstotal.cs_nffree -= FRAG;
-                       fs->fs_cs(cg).cs_nffree -= FRAG;
+               if (isblock(fs, cgp->cg_free, bbase / fs->fs_frag)) {
+                       cgp->cg_cs.cs_nffree -= fs->fs_frag;
+                       fs->fs_cstotal.cs_nffree -= fs->fs_frag;
+                       fs->fs_cs(fs, cg).cs_nffree -= fs->fs_frag;
                        cgp->cg_cs.cs_nbfree++;
                        fs->fs_cstotal.cs_nbfree++;
                        cgp->cg_cs.cs_nbfree++;
                        fs->fs_cstotal.cs_nbfree++;
-                       fs->fs_cs(cg).cs_nbfree++;
-                       i = bbase * NSPF;
+                       fs->fs_cs(fs, cg).cs_nbfree++;
+                       i = bbase * NSPF(fs);
                        cgp->cg_b[i / fs->fs_spc]
                                 [i % fs->fs_nsect * NRPOS / fs->fs_nsect]++;
                }
                        cgp->cg_b[i / fs->fs_spc]
                                 [i % fs->fs_nsect * NRPOS / fs->fs_nsect]++;
                }
@@ -582,7 +582,7 @@ ifree(dev, ino, mode)
        if ((unsigned)ino >= fs->fs_ipg*fs->fs_ncg)
                panic("ifree: range");
        cg = itog(ino, fs);
        if ((unsigned)ino >= fs->fs_ipg*fs->fs_ncg)
                panic("ifree: range");
        cg = itog(ino, fs);
-       bp = bread(dev, cgtod(cg, fs), BSIZE);
+       bp = bread(dev, fsbtodb(fs, cgtod(cg, fs)), fs->fs_bsize);
        if (bp->b_flags & B_ERROR)
                return;
        cgp = bp->b_un.b_cg;
        if (bp->b_flags & B_ERROR)
                return;
        cgp = bp->b_un.b_cg;
@@ -592,11 +592,11 @@ ifree(dev, ino, mode)
        clrbit(cgp->cg_iused, ino);
        cgp->cg_cs.cs_nifree++;
        fs->fs_cstotal.cs_nifree++;
        clrbit(cgp->cg_iused, ino);
        cgp->cg_cs.cs_nifree++;
        fs->fs_cstotal.cs_nifree++;
-       fs->fs_cs(cg).cs_nifree++;
+       fs->fs_cs(fs, cg).cs_nifree++;
        if ((mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir--;
                fs->fs_cstotal.cs_ndir--;
        if ((mode & IFMT) == IFDIR) {
                cgp->cg_cs.cs_ndir--;
                fs->fs_cstotal.cs_ndir--;
-               fs->fs_cs(cg).cs_ndir--;
+               fs->fs_cs(fs, cg).cs_ndir--;
        }
        fs->fs_fmod++;
        bdwrite(bp);
        }
        fs->fs_fmod++;
        bdwrite(bp);
@@ -627,12 +627,13 @@ mapsearch(fs, cgp, bpref, allocsiz)
        else
                start = cgp->cg_frotor / NBBY;
        len = roundup(fs->fs_fpg - 1, NBBY) / NBBY - start;
        else
                start = cgp->cg_frotor / NBBY;
        len = roundup(fs->fs_fpg - 1, NBBY) / NBBY - start;
-       loc = scanc(len, &cgp->cg_free[start], fragtbl, 1 << (allocsiz - 1));
+       loc = scanc(len, &cgp->cg_free[start], fragtbl[fs->fs_frag],
+               1 << (allocsiz - 1));
        if (loc == 0) {
                len = start - 1;
                start = (cgdmin(cgp->cg_cgx, fs) -
                         cgbase(cgp->cg_cgx, fs)) / NBBY;
        if (loc == 0) {
                len = start - 1;
                start = (cgdmin(cgp->cg_cgx, fs) -
                         cgbase(cgp->cg_cgx, fs)) / NBBY;
-               loc = scanc(len, &cgp->cg_free[start], fragtbl,
+               loc = scanc(len, &cgp->cg_free[start], fragtbl[fs->fs_frag],
                        1 << (allocsiz - 1));
                if (loc == 0) {
                        panic("alloccg: map corrupted");
                        1 << (allocsiz - 1));
                if (loc == 0) {
                        panic("alloccg: map corrupted");
@@ -645,12 +646,13 @@ mapsearch(fs, cgp, bpref, allocsiz)
         * found the byte in the map
         * sift through the bits to find the selected frag
         */
         * found the byte in the map
         * sift through the bits to find the selected frag
         */
-       for (i = 0; i < NBBY; i += FRAG) {
-               blk = (cgp->cg_free[bno / NBBY] >> i) & (0xff >> NBBY - FRAG);
+       for (i = 0; i < NBBY; i += fs->fs_frag) {
+               blk = (cgp->cg_free[bno / NBBY] >> i) &
+                     (0xff >> NBBY - fs->fs_frag);
                blk <<= 1;
                field = around[allocsiz];
                subfield = inside[allocsiz];
                blk <<= 1;
                field = around[allocsiz];
                subfield = inside[allocsiz];
-               for (pos = 0; pos <= FRAG - allocsiz; pos++) {
+               for (pos = 0; pos <= fs->fs_frag - allocsiz; pos++) {
                        if ((blk & field) == subfield) {
                                return (bno + i + pos);
                        }
                        if ((blk & field) == subfield) {
                                return (bno + i + pos);
                        }
@@ -666,7 +668,8 @@ mapsearch(fs, cgp, bpref, allocsiz)
  * update the frsum fields to reflect addition or deletion 
  * of some frags
  */
  * update the frsum fields to reflect addition or deletion 
  * of some frags
  */
-fragacct(fragmap, fraglist, cnt)
+fragacct(fs, fragmap, fraglist, cnt)
+       struct fs *fs;
        int fragmap;
        long fraglist[];
        int cnt;
        int fragmap;
        long fraglist[];
        int cnt;
@@ -675,14 +678,14 @@ fragacct(fragmap, fraglist, cnt)
        register int field, subfield;
        register int siz, pos;
 
        register int field, subfield;
        register int siz, pos;
 
-       inblk = (int)(fragtbl[fragmap]) << 1;
+       inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1;
        fragmap <<= 1;
        fragmap <<= 1;
-       for (siz = 1; siz < FRAG; siz++) {
+       for (siz = 1; siz < fs->fs_frag; siz++) {
                if (((1 << siz) & inblk) == 0)
                        continue;
                field = around[siz];
                subfield = inside[siz];
                if (((1 << siz) & inblk) == 0)
                        continue;
                field = around[siz];
                subfield = inside[siz];
-               for (pos = siz; pos <= FRAG; pos++) {
+               for (pos = siz; pos <= fs->fs_frag; pos++) {
                        if ((fragmap & field) == subfield) {
                                fraglist[siz] += cnt;
                                pos += siz;
                        if ((fragmap & field) == subfield) {
                                fraglist[siz] += cnt;
                                pos += siz;
@@ -805,16 +808,17 @@ update()
                                continue;
                        if (fs->fs_ronly != 0)
                                panic("update: rofs mod");
                                continue;
                        if (fs->fs_ronly != 0)
                                panic("update: rofs mod");
-                       bp = getblk(mp->m_dev, SBLOCK, BSIZE);
+                       bp = getblk(mp->m_dev, SBLOCK, MAXBSIZE);
                        fs->fs_fmod = 0;
                        fs->fs_time = TIME;
                        if (bp->b_un.b_fs != fs)
                                panic("update: bad b_fs");
                        bwrite(bp);
                        fs->fs_fmod = 0;
                        fs->fs_time = TIME;
                        if (bp->b_un.b_fs != fs)
                                panic("update: bad b_fs");
                        bwrite(bp);
-                       blks = howmany(cssize(fs), BSIZE);
+                       blks = howmany(fs->fs_cssize, fs->fs_bsize);
                        for (i = 0; i < blks; i++) {
                        for (i = 0; i < blks; i++) {
-                               bp = getblk(mp->m_dev, csaddr(fs) + (i * FRAG),
-                                       BSIZE);
+                               bp = getblk(mp->m_dev,
+                                   fsbtodb(fs, fs->fs_csaddr + (i * fs->fs_frag)),
+                                   fs->fs_bsize);
                                bwrite(bp);
                        }
                }
                                bwrite(bp);
                        }
                }
@@ -836,3 +840,78 @@ update()
         */
        bflush(NODEV);
 }
         */
        bflush(NODEV);
 }
+
+/*
+ * block macros
+ */
+
+isblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       unsigned char mask;
+
+       switch (fs->fs_frag) {
+       case 8:
+               return (cp[h] == 0xff);
+       case 4:
+               mask = 0x0f << ((h & 0x1) << 2);
+               return ((cp[h >> 1] & mask) == mask);
+       case 2:
+               mask = 0x03 << ((h & 0x3) << 1);
+               return ((cp[h >> 2] & mask) == mask);
+       case 1:
+               mask = 0x01 << (h & 0x7);
+               return ((cp[h >> 3] & mask) == mask);
+       default:
+               panic("isblock bad fs_frag");
+               return;
+       }
+}
+clrblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       switch ((fs)->fs_frag) {
+       case 8:
+               cp[h] = 0;
+               return;
+       case 4:
+               cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
+               return;
+       case 2:
+               cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
+               return;
+       case 1:
+               cp[h >> 3] &= ~(0x01 << (h & 0x7));
+               return;
+       default:
+               panic("clrblock bad fs_frag");
+               return;
+       }
+}
+setblock(fs, cp, h)
+       struct fs *fs;
+       unsigned char *cp;
+       int h;
+{
+       switch (fs->fs_frag) {
+       case 8:
+               cp[h] = 0xff;
+               return;
+       case 4:
+               cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
+               return;
+       case 2:
+               cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
+               return;
+       case 1:
+               cp[h >> 3] |= (0x01 << (h & 0x7));
+               return;
+       default:
+               panic("setblock bad fs_frag");
+               return;
+       }
+}