must be sure to always convert b_bno to disk block (db) units
[unix-history] / usr / src / sbin / fsck / fsck.h
index 44e4bf3..14a6499 100644 (file)
@@ -1,9 +1,14 @@
-/* @(#)fsck.h  3.3 (Berkeley) %G% */
-
-#define        MAXDUP          10      /* limit on dup blks (per inode) */
-#define        MAXBAD          10      /* limit on bad blks (per inode) */
-#define        DUPTBLSIZE      100     /* num of dup blocks to remember */
-#define        MAXLNCNT        500     /* num zero link cnts to remember */
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)fsck.h      5.7 (Berkeley) %G%
+ */
+
+#define        MAXDUP          10       /* limit on dup blks (per inode) */
+#define        MAXBAD          10       /* limit on bad blks (per inode) */
+#define MAXBUFSPACE    128*1024 /* maximum space to allocate to buffers */
 
 typedef        int     (*SIG_TYP)();
 
 
 typedef        int     (*SIG_TYP)();
 
@@ -26,41 +31,45 @@ typedef struct direct       DIRECT;
 #define        SPECIAL(dip) \
        (((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR)
 
 #define        SPECIAL(dip) \
        (((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR)
 
-#define        MAXNINDIR       (MAXBSIZE / sizeof (daddr_t))
-#define        MAXINOPB        (MAXBSIZE / sizeof (struct dinode))
-#define        SPERB           (MAXBSIZE / sizeof(short))
-
+/*
+ * buffer cache structure.
+ */
 struct bufarea {
 struct bufarea {
-       struct bufarea  *b_next;                /* must be first */
+       struct bufarea  *b_next;                /* free list queue */
+       struct bufarea  *b_prev;                /* free list queue */
        daddr_t b_bno;
        int     b_size;
        daddr_t b_bno;
        int     b_size;
+       int     b_errs;
+       int     b_flags;
        union {
        union {
-               char    b_buf[MAXBSIZE];        /* buffer space */
-               short   b_lnks[SPERB];          /* link counts */
-               daddr_t b_indir[MAXNINDIR];     /* indirect block */
-               struct  fs b_fs;                /* super block */
-               struct  cg b_cg;                /* cylinder group */
-               struct dinode b_dinode[MAXINOPB]; /* inode block */
+               char    *b_buf;                 /* buffer space */
+               daddr_t *b_indir;               /* indirect block */
+               struct  fs *b_fs;               /* super block */
+               struct  cg *b_cg;               /* cylinder group */
+               struct dinode *b_dinode;        /* inode block */
        } b_un;
        char    b_dirty;
 };
 
        } b_un;
        char    b_dirty;
 };
 
+#define        B_INUSE 1
 typedef struct bufarea BUFAREA;
 
 typedef struct bufarea BUFAREA;
 
-BUFAREA        inoblk;                 /* inode blocks */
-BUFAREA        fileblk;                /* other blks in filesys */
+#define        MINBUFS         5       /* minimum number of buffers required */
+BUFAREA        bufhead;                /* head of list of other blks in filesys */
 BUFAREA        sblk;                   /* file system superblock */
 BUFAREA        cgblk;                  /* cylinder group blocks */
 BUFAREA        sblk;                   /* file system superblock */
 BUFAREA        cgblk;                  /* cylinder group blocks */
+BUFAREA        *getdatablk();
 
 
-#define        initbarea(x)    (x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1
 #define        dirty(x)        (x)->b_dirty = 1
 #define        dirty(x)        (x)->b_dirty = 1
-#define        inodirty()      inoblk.b_dirty = 1
+#define        initbarea(x) \
+       (x)->b_dirty = 0; \
+       (x)->b_bno = (daddr_t)-1; \
+       (x)->b_flags = 0;
+
 #define        sbdirty()       sblk.b_dirty = 1
 #define        cgdirty()       cgblk.b_dirty = 1
 #define        sbdirty()       sblk.b_dirty = 1
 #define        cgdirty()       cgblk.b_dirty = 1
-
-#define        dirblk          fileblk.b_un
-#define        sblock          sblk.b_un.b_fs
-#define        cgrp            cgblk.b_un.b_cg
+#define        sblock          (*sblk.b_un.b_fs)
+#define        cgrp            (*cgblk.b_un.b_cg)
 
 struct filecntl {
        int     rfdes;
 
 struct filecntl {
        int     rfdes;
@@ -88,22 +97,55 @@ struct inodesc {
 #define        DATA    1
 #define        ADDR    2
 
 #define        DATA    1
 #define        ADDR    2
 
-
-daddr_t        duplist[DUPTBLSIZE];    /* dup block table */
-daddr_t        *enddup;                /* next entry in dup table */
-daddr_t        *muldup;                /* multiple dups part of table */
-
-ino_t  badlncnt[MAXLNCNT];     /* table of inos with zero link cnts */
-ino_t  *badlnp;                /* next entry in table */
+/*
+ * Linked list of duplicate blocks.
+ * 
+ * The list is composed of two parts. The first part of the
+ * list (from duplist through the node pointed to by muldup)
+ * contains a single copy of each duplicate block that has been 
+ * found. The second part of the list (from muldup to the end)
+ * contains duplicate blocks that have been found more than once.
+ * To check if a block has been found as a duplicate it is only
+ * necessary to search from duplist through muldup. To find the 
+ * total number of times that a block has been found as a duplicate
+ * the entire list must be searched for occurences of the block
+ * in question. The following diagram shows a sample list where
+ * w (found twice), x (found once), y (found three times), and z
+ * (found once) are duplicate block numbers:
+ *
+ *    w -> y -> x -> z -> y -> w -> y
+ *    ^                     ^
+ *    |                     |
+ * duplist       muldup
+ */
+struct dups {
+       struct dups *next;
+       daddr_t dup;
+};
+struct dups *duplist;          /* head of dup list */
+struct dups *muldup;           /* end of unique duplicate dup block numbers */
+
+/*
+ * Linked list of inodes with zero link counts.
+ */
+struct zlncnt {
+       struct zlncnt *next;
+       ino_t zlncnt;
+};
+struct zlncnt *zlnhead;                /* head of zero link count list */
 
 char   rawflg;
 char   *devname;
 
 char   rawflg;
 char   *devname;
+long   dev_bsize;              /* computed value of DEV_BSIZE */
+long   secsize;                /* actual disk sector size */
 char   nflag;                  /* assume a no response */
 char   yflag;                  /* assume a yes response */
 int    bflag;                  /* location of alternate super block */
 int    debug;                  /* output debugging info */
 char   nflag;                  /* assume a no response */
 char   yflag;                  /* assume a yes response */
 int    bflag;                  /* location of alternate super block */
 int    debug;                  /* output debugging info */
+int    cvtflag;                /* convert to old file system format */
 char   preen;                  /* just fix normal inconsistencies */
 char   hotroot;                /* checking root device */
 char   preen;                  /* just fix normal inconsistencies */
 char   hotroot;                /* checking root device */
+char   havesb;                 /* superblock has been read */
 
 char   *blockmap;              /* ptr to primary blk allocation map */
 char   *statemap;              /* ptr to inode state table */
 
 char   *blockmap;              /* ptr to primary blk allocation map */
 char   *statemap;              /* ptr to inode state table */
@@ -132,6 +174,7 @@ struct      dinode zino;
 #define        getbmap(x)      isset(blockmap, x)
 #define        clrbmap(x)      clrbit(blockmap, x)
 
 #define        getbmap(x)      isset(blockmap, x)
 #define        clrbmap(x)      clrbit(blockmap, x)
 
+#define        FOUND   020
 #define        ALTERED 010
 #define        KEEPON  04
 #define        SKIP    02
 #define        ALTERED 010
 #define        KEEPON  04
 #define        SKIP    02