1*17930Smckusick /* @(#)fsck.h 3.2 (Berkeley) 02/07/85 */ 216260Smckusick 316260Smckusick /* RECONSTRUCT ONLY BAD CG IN PASS 6 */ 416260Smckusick 516260Smckusick #define MAXDUP 10 /* limit on dup blks (per inode) */ 616260Smckusick #define MAXBAD 10 /* limit on bad blks (per inode) */ 716260Smckusick #define DUPTBLSIZE 100 /* num of dup blocks to remember */ 816260Smckusick #define MAXLNCNT 500 /* num zero link cnts to remember */ 916260Smckusick 1016260Smckusick typedef int (*SIG_TYP)(); 1116260Smckusick 1216260Smckusick #ifndef BUFSIZ 1316260Smckusick #define BUFSIZ 1024 1416260Smckusick #endif 1516260Smckusick 1616260Smckusick #define USTATE 0 /* inode not allocated */ 1716260Smckusick #define FSTATE 01 /* inode is file */ 1816260Smckusick #define DSTATE 02 /* inode is directory */ 1916260Smckusick #define CLEAR 03 /* inode is to be cleared */ 2016260Smckusick 2116260Smckusick typedef struct dinode DINODE; 2216260Smckusick typedef struct direct DIRECT; 2316260Smckusick 24*17930Smckusick #define ALLOC(dip) (((dip)->di_mode & IFMT) != 0) 25*17930Smckusick #define DIRCT(dip) (((dip)->di_mode & IFMT) == IFDIR) 26*17930Smckusick #define SPECIAL(dip) \ 27*17930Smckusick (((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR) 2816260Smckusick 29*17930Smckusick #define MAXNINDIR (MAXBSIZE / sizeof (daddr_t)) 30*17930Smckusick #define MAXINOPB (MAXBSIZE / sizeof (struct dinode)) 31*17930Smckusick #define SPERB (MAXBSIZE / sizeof(short)) 32*17930Smckusick 3316260Smckusick struct bufarea { 3416260Smckusick struct bufarea *b_next; /* must be first */ 3516260Smckusick daddr_t b_bno; 3616260Smckusick int b_size; 3716260Smckusick union { 3816260Smckusick char b_buf[MAXBSIZE]; /* buffer space */ 3916260Smckusick short b_lnks[SPERB]; /* link counts */ 4016260Smckusick daddr_t b_indir[MAXNINDIR]; /* indirect block */ 4116260Smckusick struct fs b_fs; /* super block */ 4216260Smckusick struct cg b_cg; /* cylinder group */ 4316260Smckusick struct dinode b_dinode[MAXINOPB]; /* inode block */ 4416260Smckusick } b_un; 4516260Smckusick char b_dirty; 4616260Smckusick }; 4716260Smckusick 4816260Smckusick typedef struct bufarea BUFAREA; 4916260Smckusick 5016260Smckusick BUFAREA inoblk; /* inode blocks */ 5116260Smckusick BUFAREA fileblk; /* other blks in filesys */ 5216260Smckusick BUFAREA sblk; /* file system superblock */ 5316260Smckusick BUFAREA cgblk; /* cylinder group blocks */ 5416260Smckusick 5516260Smckusick #define initbarea(x) (x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1 5616260Smckusick #define dirty(x) (x)->b_dirty = 1 5716260Smckusick #define inodirty() inoblk.b_dirty = 1 5816260Smckusick #define sbdirty() sblk.b_dirty = 1 5916260Smckusick #define cgdirty() cgblk.b_dirty = 1 6016260Smckusick 6116260Smckusick #define dirblk fileblk.b_un 6216260Smckusick #define sblock sblk.b_un.b_fs 6316260Smckusick #define cgrp cgblk.b_un.b_cg 6416260Smckusick 6516260Smckusick struct filecntl { 6616260Smckusick int rfdes; 6716260Smckusick int wfdes; 6816260Smckusick int mod; 6916260Smckusick } dfile; /* file descriptors for filesys */ 7016260Smckusick 71*17930Smckusick enum fixstate {DONTKNOW, NOFIX, FIX}; 72*17930Smckusick 7316260Smckusick struct inodesc { 74*17930Smckusick enum fixstate id_fix; /* policy on fixing errors */ 7516260Smckusick int (*id_func)(); /* function to be applied to blocks of inode */ 7616260Smckusick ino_t id_number; /* inode number described */ 7716260Smckusick ino_t id_parent; /* for DATA nodes, their parent */ 7816260Smckusick daddr_t id_blkno; /* current block number being examined */ 7916260Smckusick int id_numfrags; /* number of frags contained in block */ 8016260Smckusick long id_filesize; /* for DATA nodes, the size of the directory */ 8116260Smckusick int id_loc; /* for DATA nodes, current location in dir */ 8216260Smckusick int id_entryno; /* for DATA nodes, current entry number */ 83*17930Smckusick DIRECT *id_dirp; /* for DATA nodes, ptr to current entry */ 84*17930Smckusick char *id_name; /* for DATA nodes, name to find or enter */ 85*17930Smckusick char id_type; /* type of descriptor, DATA or ADDR */ 8616260Smckusick }; 8716260Smckusick /* file types */ 8816260Smckusick #define DATA 1 8916260Smckusick #define ADDR 2 9016260Smckusick 9116260Smckusick 9216260Smckusick daddr_t duplist[DUPTBLSIZE]; /* dup block table */ 9316260Smckusick daddr_t *enddup; /* next entry in dup table */ 9416260Smckusick daddr_t *muldup; /* multiple dups part of table */ 9516260Smckusick 9616260Smckusick ino_t badlncnt[MAXLNCNT]; /* table of inos with zero link cnts */ 9716260Smckusick ino_t *badlnp; /* next entry in table */ 9816260Smckusick 9916260Smckusick char rawflg; 10016260Smckusick char *devname; 10116260Smckusick char nflag; /* assume a no response */ 10216260Smckusick char yflag; /* assume a yes response */ 10316260Smckusick int bflag; /* location of alternate super block */ 10416260Smckusick int debug; /* output debugging info */ 10516260Smckusick char preen; /* just fix normal inconsistencies */ 10616260Smckusick char hotroot; /* checking root device */ 10716260Smckusick char fixcg; /* corrupted free list bit maps */ 10816260Smckusick 10916260Smckusick char *blockmap; /* ptr to primary blk allocation map */ 11016260Smckusick char *freemap; /* ptr to secondary blk allocation map */ 11116260Smckusick char *statemap; /* ptr to inode state table */ 11216260Smckusick short *lncntp; /* ptr to link count table */ 11316260Smckusick 11416260Smckusick char pathname[BUFSIZ]; /* current pathname */ 11516260Smckusick char *pathp; /* pointer to pathname position */ 11616260Smckusick char *endpathname; 11716260Smckusick 118*17930Smckusick daddr_t fmax; /* number of blocks in the volume */ 11916260Smckusick ino_t imax; /* number of inodes */ 12016260Smckusick ino_t lastino; /* hiwater mark of inodes */ 121*17930Smckusick ino_t lfdir; /* lost & found directory inode number */ 122*17930Smckusick char *lfname; /* lost & found directory name */ 12316260Smckusick 12416260Smckusick off_t maxblk; /* largest logical blk in file */ 12516260Smckusick off_t bmapsz; /* num chars in blockmap */ 12616260Smckusick 12716260Smckusick daddr_t n_ffree; /* number of small free blocks */ 12816260Smckusick daddr_t n_bfree; /* number of large free blocks */ 12916260Smckusick daddr_t n_blks; /* number of blocks used */ 13016260Smckusick daddr_t n_files; /* number of files seen */ 13116260Smckusick daddr_t n_index; 13216260Smckusick daddr_t n_bad; 13316260Smckusick 13416260Smckusick daddr_t badblk; 13516260Smckusick daddr_t dupblk; 13616260Smckusick 13716260Smckusick int inosumbad; 13816260Smckusick int offsumbad; 13916260Smckusick int frsumbad; 14016260Smckusick int sbsumbad; 14116260Smckusick 14216260Smckusick #define zapino(x) (*(x) = zino) 14316260Smckusick struct dinode zino; 14416260Smckusick 14516260Smckusick #define setbmap(x) setbit(blockmap, x) 14616260Smckusick #define getbmap(x) isset(blockmap, x) 14716260Smckusick #define clrbmap(x) clrbit(blockmap, x) 14816260Smckusick 14916260Smckusick #define setfmap(x) setbit(freemap, x) 15016260Smckusick #define getfmap(x) isset(freemap, x) 15116260Smckusick #define clrfmap(x) clrbit(freemap, x) 15216260Smckusick 15316260Smckusick #define ALTERED 010 15416260Smckusick #define KEEPON 04 15516260Smckusick #define SKIP 02 15616260Smckusick #define STOP 01 15716260Smckusick 15816260Smckusick time_t time(); 15916260Smckusick DINODE *ginode(); 16016260Smckusick BUFAREA *getblk(); 16116260Smckusick int findino(); 162