1: /* 2: * Copyright (c) 1980 Regents of the University of California. 3: * All rights reserved. The Berkeley software License Agreement 4: * specifies the terms and conditions for redistribution. 5: * 6: * @(#)fsck.h 5.1 (Berkeley) 6/5/85 7: */ 8: 9: #define MAXDUP 10 /* limit on dup blks (per inode) */ 10: #define MAXBAD 10 /* limit on bad blks (per inode) */ 11: 12: #define STEPSIZE 7 /* default step for freelist spacing */ 13: #define CYLSIZE 400 /* default cyl size for spacing */ 14: #define MAXCYL 500 /* maximum cylinder size */ 15: 16: typedef int (*SIG_TYP)(); 17: 18: #ifndef BUFSIZ 19: #define BUFSIZ 1024 20: #endif 21: 22: #define USTATE 01 /* inode not allocated */ 23: #define FSTATE 02 /* inode is file */ 24: #define DSTATE 03 /* inode is directory */ 25: #define DFOUND 04 /* directory found during descent */ 26: #define DCLEAR 05 /* directory is to be cleared */ 27: #define FCLEAR 06 /* file is to be cleared */ 28: 29: #define BITSPB 8 /* number bits per byte */ 30: #define BITSHIFT 3 /* log2(BITSPB) */ 31: #define BITMASK 07 /* BITSPB-1 */ 32: #define LSTATE 4 /* bits per inode state */ 33: #define STATEPB (BITSPB/LSTATE) /* inode states per byte */ 34: #define SMASK 017 /* mask for inode state */ 35: 36: typedef struct dinode DINODE; 37: typedef struct direct DIRECT; 38: 39: #define ALLOC(dip) (((dip)->di_mode & IFMT) != 0) 40: #define DIRCT(dip) (((dip)->di_mode & IFMT) == IFDIR) 41: #define SPECIAL(dip) \ 42: (((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR) 43: 44: #define MAXNINDIR (MAXBSIZE / sizeof (daddr_t)) 45: #define MAXINOPB (MAXBSIZE / sizeof (struct dinode)) 46: #define SPERB (MAXBSIZE / sizeof(short)) 47: 48: struct bufarea { 49: struct bufarea *b_next; /* must be first */ 50: daddr_t b_bno; 51: int b_size; 52: int b_errs; 53: union { 54: char b_buf[MAXBSIZE]; /* buffer space */ 55: short b_lnks[SPERB]; /* link counts */ 56: daddr_t b_indir[MAXNINDIR]; /* indirect block */ 57: struct fs b_fs; /* super block */ 58: struct fblk b_fb; /* free block */ 59: struct dinode b_dinode[MAXINOPB]; /* inode block */ 60: } b_un; 61: char b_dirty; 62: }; 63: 64: typedef struct bufarea BUFAREA; 65: 66: BUFAREA inoblk; /* inode blocks */ 67: BUFAREA fileblk; /* other blks in filesys */ 68: BUFAREA sblk; /* file system superblock */ 69: BUFAREA *poolhead; /* ptr to first buffer in pool */ 70: 71: #define initbarea(x) (x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1 72: #define dirty(x) (x)->b_dirty = 1 73: #define inodirty() inoblk.b_dirty = 1 74: #define fbdirty() fileblk.b_dirty = 1 75: #define sbdirty() sblk.b_dirty = 1 76: 77: #define dirblk fileblk.b_un 78: #define freeblk fileblk.b_un.b_fb 79: #define sblock sblk.b_un.b_fs 80: 81: struct filecntl { 82: int rfdes; 83: int wfdes; 84: int mod; 85: } dfile, sfile; /* file descriptors for filesys/scratch files */ 86: 87: enum fixstate {DONTKNOW, NOFIX, FIX}; 88: 89: struct inodesc { 90: enum fixstate id_fix; /* policy on fixing errors */ 91: int (*id_func)(); /* function to be applied to blocks of inode */ 92: ino_t id_number; /* inode number described */ 93: ino_t id_parent; /* for DATA nodes, their parent */ 94: daddr_t id_blkno; /* current block number being examined */ 95: long id_filesize; /* for DATA nodes, the size of the directory */ 96: off_t id_loc; /* for DATA nodes, current location in dir */ 97: u_long id_entryno; /* for DATA nodes, current entry number */ 98: DIRECT *id_dirp; /* for DATA nodes, ptr to current entry */ 99: char *id_name; /* for DATA nodes, name to find or enter */ 100: char id_type; /* type of descriptor, DATA or ADDR */ 101: }; 102: /* file types */ 103: #define DATA 1 104: #define ADDR 2 105: 106: /* 107: * Linked list of duplicate blocks. 108: * 109: * The list is composed of two parts. The first part of the 110: * list (from duplist through the node pointed to by muldup) 111: * contains a single copy of each duplicate block that has been 112: * found. The second part of the list (from muldup to the end) 113: * contains duplicate blocks that have been found more than once. 114: * To check if a block has been found as a duplicate it is only 115: * necessary to search from duplist through muldup. To find the 116: * total number of times that a block has been found as a duplicate 117: * the entire list must be searched for occurences of the block 118: * in question. The following diagram shows a sample list where 119: * w (found twice), x (found once), y (found three times), and z 120: * (found once) are duplicate block numbers: 121: * 122: * w -> y -> x -> z -> y -> w -> y 123: * ^ ^ 124: * | | 125: * duplist muldup 126: */ 127: 128: #define DUPTBLSIZE 100 129: 130: daddr_t duplist[DUPTBLSIZE]; /* head of dup list */ 131: daddr_t *enddup; /* next entry in dup table */ 132: daddr_t *muldup; /* multiple dups part of table */ 133: 134: /* 135: * List of inodes with zero link counts. 136: */ 137: 138: #define MAXLNCNT 50 139: 140: ino_t zlnlist[MAXLNCNT]; /* zero link count table */ 141: ino_t *zlnp; 142: 143: #define MAXDATA ((unsigned)56 * 1024) 144: #define MEMUNIT 64 145: #define NINOBLK 4 /* number of blocks of inodes to read at once */ 146: 147: char inobuf[NINOBLK*INOPB*sizeof (struct dinode)]; /* allocate now */ 148: daddr_t startib; 149: 150: unsigned int memsize; 151: char rawflg; 152: char *devname; 153: char nflag; /* assume a no response */ 154: char yflag; /* assume a yes response */ 155: char sflag; /* rebuild free list */ 156: int debug; /* output debugging info */ 157: char preen; /* just fix normal inconsistencies */ 158: char hotroot; /* checking root device */ 159: char fixfree; /* force rebuild of freelist */ 160: char *membase; /* base of memory we get */ 161: 162: char *blockmap; /* ptr to primary blk allocation map */ 163: char *freemap; /* ptr to secondary blk allocation map */ 164: char *statemap; /* ptr to inode state table */ 165: short *lncntp; /* ptr to link count table */ 166: 167: char pathname[MAXPATHLEN]; /* current pathname */ 168: char scrfile[80]; /* scratchfile name */ 169: int cylsize; /* num blocks per cylinder */ 170: int stepsize; /* num blocks for spacing purposes */ 171: char *pathp; /* pointer to pathname position */ 172: char *endpathname; 173: 174: daddr_t fmin; /* block number of the first data block */ 175: daddr_t fmax; /* number of blocks in the volume */ 176: ino_t imax; /* number of inodes */ 177: ino_t lastino; /* hiwater mark of inodes */ 178: ino_t lfdir; /* lost & found directory inode number */ 179: char *lfname; /* lost & found directory name */ 180: 181: off_t bmapsz; /* num chars in blockmap */ 182: daddr_t bmapblk; /* starting blk of block map */ 183: daddr_t smapblk; /* starting blk of state map */ 184: daddr_t lncntblk; /* starting blk of link cnt table */ 185: daddr_t fmapblk; /* starting blk of free map */ 186: 187: daddr_t n_blks; /* number of blocks used */ 188: daddr_t n_files; /* number of files seen */ 189: daddr_t n_free; /* number of free blocks */ 190: int badblk, dupblk; 191: 192: #define outrange(x) (x < fmin || x >= fmax) 193: #define zapino(x) (*(x) = zino) 194: struct dinode zino; 195: 196: #define setlncnt(x,n) dolncnt(x,0,n) 197: #define getlncnt(x) dolncnt(x,1,0) 198: #define declncnt(x) dolncnt(x,2,0) 199: #define inclncnt(x) dolncnt(x,3,0) 200: 201: #define setbmap(x) domap(x,0) 202: #define getbmap(x) domap(x,1) 203: #define clrbmap(x) domap(x,2) 204: 205: #define setfmap(x) domap(x,0+4) 206: #define getfmap(x) domap(x,1+4) 207: #define clrfmap(x) domap(x,2+4) 208: 209: #define setstate(x,y) dostate(x,y,0) 210: #define getstate(x) dostate(x,0,1) 211: 212: #define ALTERED 010 213: #define KEEPON 04 214: #define SKIP 02 215: #define STOP 01 216: 217: time_t time(); 218: DINODE *ginode(); 219: BUFAREA *getblk(); 220: int findino(); 221: daddr_t allocblk();