386BSD 0.1 development
[unix-history] / usr / src / sbin / fsck / fsck.h
index 43f2f3d..310bd21 100644 (file)
@@ -1,15 +1,42 @@
 /*
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1980, 1986 The Regents of the University of California.
+ * All rights reserved.
  *
  *
- *     @(#)fsck.h      5.2 (Berkeley) %G%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)fsck.h      5.17 (Berkeley) 7/27/90
  */
 
 #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) */
-
-typedef        int     (*SIG_TYP)();
+#define        MAXBUFSPACE     40*1024 /* maximum space to allocate to buffers */
+#define        INOBUFSIZE      56*1024 /* size of buffer to read inodes in pass1 */
 
 #ifndef BUFSIZ
 #define BUFSIZ 1024
 
 #ifndef BUFSIZ
 #define BUFSIZ 1024
@@ -22,58 +49,48 @@ typedef     int     (*SIG_TYP)();
 #define        DCLEAR  05              /* directory is to be cleared */
 #define        FCLEAR  06              /* file is to be cleared */
 
 #define        DCLEAR  05              /* directory is to be cleared */
 #define        FCLEAR  06              /* file is to be cleared */
 
-typedef struct dinode  DINODE;
-typedef struct direct  DIRECT;
-
-#define        ALLOC(dip)      (((dip)->di_mode & IFMT) != 0)
-#define        DIRCT(dip)      (((dip)->di_mode & IFMT) == IFDIR)
-#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;
        int     b_errs;
        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;
 };
 
-typedef struct bufarea BUFAREA;
+#define        B_INUSE 1
+
+#define        MINBUFS         5       /* minimum number of buffers required */
+struct bufarea bufhead;                /* head of list of other blks in filesys */
+struct bufarea sblk;           /* file system superblock */
+struct bufarea cgblk;          /* cylinder group blocks */
+struct bufarea *pdirbp;                /* current directory contents */
+struct bufarea *pbp;           /* current inode block */
+struct bufarea *getdatablk();
 
 
-BUFAREA        inoblk;                 /* inode blocks */
-BUFAREA        fileblk;                /* other blks in filesys */
-BUFAREA        sblk;                   /* file system superblock */
-BUFAREA        cgblk;                  /* cylinder group blocks */
+#define        dirty(bp)       (bp)->b_dirty = 1
+#define        initbarea(bp) \
+       (bp)->b_dirty = 0; \
+       (bp)->b_bno = (daddr_t)-1; \
+       (bp)->b_flags = 0;
 
 
-#define        initbarea(x)    (x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1
-#define        dirty(x)        (x)->b_dirty = 1
-#define        inodirty()      inoblk.b_dirty = 1
 #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        sblock          (*sblk.b_un.b_fs)
+#define        cgrp            (*cgblk.b_un.b_cg)
 
 
-#define        dirblk          fileblk.b_un
-#define        sblock          sblk.b_un.b_fs
-#define        cgrp            cgblk.b_un.b_cg
-
-struct filecntl {
-       int     rfdes;
-       int     wfdes;
-       int     mod;
-} dfile;                       /* file descriptors for filesys */
-
-enum fixstate {DONTKNOW, NOFIX, FIX};
+enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
 
 struct inodesc {
        enum fixstate id_fix;   /* policy on fixing errors */
 
 struct inodesc {
        enum fixstate id_fix;   /* policy on fixing errors */
@@ -85,7 +102,7 @@ struct inodesc {
        long id_filesize;       /* for DATA nodes, the size of the directory */
        int id_loc;             /* for DATA nodes, current location in dir */
        int id_entryno;         /* for DATA nodes, current entry number */
        long id_filesize;       /* for DATA nodes, the size of the directory */
        int id_loc;             /* for DATA nodes, current location in dir */
        int id_entryno;         /* for DATA nodes, current entry number */
-       DIRECT *id_dirp;        /* for DATA nodes, ptr to current entry */
+       struct direct *id_dirp; /* for DATA nodes, ptr to current entry */
        char *id_name;          /* for DATA nodes, name to find or enter */
        char id_type;           /* type of descriptor, DATA or ADDR */
 };
        char *id_name;          /* for DATA nodes, name to find or enter */
        char id_type;           /* type of descriptor, DATA or ADDR */
 };
@@ -130,49 +147,65 @@ struct zlncnt {
 };
 struct zlncnt *zlnhead;                /* head of zero link count list */
 
 };
 struct zlncnt *zlnhead;                /* head of zero link count list */
 
-char   rawflg;
-char   *devname;
+/*
+ * Inode cache data structures.
+ */
+struct inoinfo {
+       struct  inoinfo *i_nexthash;    /* next entry in hash chain */
+       ino_t   i_number;               /* inode number of this entry */
+       ino_t   i_parent;               /* inode number of parent */
+       ino_t   i_dotdot;               /* inode number of `..' */
+       size_t  i_isize;                /* size of inode */
+       u_int   i_numblks;              /* size of block array in bytes */
+       daddr_t i_blks[1];              /* actually longer */
+} **inphead, **inpsort;
+long numdirs, listmax, inplast;
+
+char   *devname;               /* name of device being checked */
+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 */
+int    fsmodified;             /* 1 => write done to file system */
+int    fsreadfd;               /* file descriptor for reading file system */
+int    fswritefd;              /* file descriptor for writing file system */
 
 
+daddr_t        maxfsblock;             /* number of blocks in the file system */
 char   *blockmap;              /* ptr to primary blk allocation map */
 char   *blockmap;              /* ptr to primary blk allocation map */
+ino_t  maxino;                 /* number of inodes in file system */
+ino_t  lastino;                /* last inode in use */
 char   *statemap;              /* ptr to inode state table */
 short  *lncntp;                /* ptr to link count table */
 
 char   *statemap;              /* ptr to inode state table */
 short  *lncntp;                /* ptr to link count table */
 
-char   pathname[BUFSIZ];       /* current pathname */
-char   *pathp;                 /* pointer to pathname position */
-char   *endpathname;
-
-daddr_t        fmax;                   /* number of blocks in the volume */
-ino_t  imax;                   /* number of inodes */
-ino_t  lastino;                /* hiwater mark of inodes */
 ino_t  lfdir;                  /* lost & found directory inode number */
 char   *lfname;                /* lost & found directory name */
 ino_t  lfdir;                  /* lost & found directory inode number */
 char   *lfname;                /* lost & found directory name */
+int    lfmode;                 /* lost & found directory creation mode */
 
 
-off_t  maxblk;                 /* largest logical blk in file */
-off_t  bmapsz;                 /* num chars in blockmap */
-
-daddr_t        n_blks;                 /* number of blocks used */
-daddr_t        n_files;                /* number of files seen */
+daddr_t        n_blks;                 /* number of blocks in use */
+daddr_t        n_files;                /* number of files in use */
 
 
-#define        zapino(x)       (*(x) = zino)
+#define        clearinode(dp)  (*(dp) = zino)
 struct dinode zino;
 
 struct dinode zino;
 
-#define        setbmap(x)      setbit(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        STOP    01
-
-time_t time();
-DINODE *ginode();
-BUFAREA        *getblk();
-int    findino();
+#define        setbmap(blkno)  setbit(blockmap, blkno)
+#define        testbmap(blkno) isset(blockmap, blkno)
+#define        clrbmap(blkno)  clrbit(blockmap, blkno)
+
+#define        STOP    0x01
+#define        SKIP    0x02
+#define        KEEPON  0x04
+#define        ALTERED 0x08
+#define        FOUND   0x10
+
+time_t time();
+struct dinode *ginode();
+struct inoinfo *getinoinfo();
+void getblk();
+ino_t allocino();
+int findino();