1 /* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)fsck.h 8.1 (Berkeley) 06/05/93 8 */ 9 10 #define MAXDUP 10 /* limit on dup blks (per inode) */ 11 #define MAXBAD 10 /* limit on bad blks (per inode) */ 12 #define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ 13 #define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ 14 15 #ifndef BUFSIZ 16 #define BUFSIZ 1024 17 #endif 18 19 #define USTATE 01 /* inode not allocated */ 20 #define FSTATE 02 /* inode is file */ 21 #define DSTATE 03 /* inode is directory */ 22 #define DFOUND 04 /* directory found during descent */ 23 #define DCLEAR 05 /* directory is to be cleared */ 24 #define FCLEAR 06 /* file is to be cleared */ 25 26 /* 27 * buffer cache structure. 28 */ 29 struct bufarea { 30 struct bufarea *b_next; /* free list queue */ 31 struct bufarea *b_prev; /* free list queue */ 32 daddr_t b_bno; 33 int b_size; 34 int b_errs; 35 int b_flags; 36 union { 37 char *b_buf; /* buffer space */ 38 daddr_t *b_indir; /* indirect block */ 39 struct fs *b_fs; /* super block */ 40 struct cg *b_cg; /* cylinder group */ 41 struct dinode *b_dinode; /* inode block */ 42 } b_un; 43 char b_dirty; 44 }; 45 46 #define B_INUSE 1 47 48 #define MINBUFS 5 /* minimum number of buffers required */ 49 struct bufarea bufhead; /* head of list of other blks in filesys */ 50 struct bufarea sblk; /* file system superblock */ 51 struct bufarea cgblk; /* cylinder group blocks */ 52 struct bufarea *pdirbp; /* current directory contents */ 53 struct bufarea *pbp; /* current inode block */ 54 struct bufarea *getdatablk(); 55 56 #define dirty(bp) (bp)->b_dirty = 1 57 #define initbarea(bp) \ 58 (bp)->b_dirty = 0; \ 59 (bp)->b_bno = (daddr_t)-1; \ 60 (bp)->b_flags = 0; 61 62 #define sbdirty() sblk.b_dirty = 1 63 #define cgdirty() cgblk.b_dirty = 1 64 #define sblock (*sblk.b_un.b_fs) 65 #define cgrp (*cgblk.b_un.b_cg) 66 67 enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE}; 68 69 struct inodesc { 70 enum fixstate id_fix; /* policy on fixing errors */ 71 int (*id_func)(); /* function to be applied to blocks of inode */ 72 ino_t id_number; /* inode number described */ 73 ino_t id_parent; /* for DATA nodes, their parent */ 74 daddr_t id_blkno; /* current block number being examined */ 75 int id_numfrags; /* number of frags contained in block */ 76 quad_t id_filesize; /* for DATA nodes, the size of the directory */ 77 int id_loc; /* for DATA nodes, current location in dir */ 78 int id_entryno; /* for DATA nodes, current entry number */ 79 struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 80 char *id_name; /* for DATA nodes, name to find or enter */ 81 char id_type; /* type of descriptor, DATA or ADDR */ 82 }; 83 /* file types */ 84 #define DATA 1 85 #define ADDR 2 86 87 /* 88 * Linked list of duplicate blocks. 89 * 90 * The list is composed of two parts. The first part of the 91 * list (from duplist through the node pointed to by muldup) 92 * contains a single copy of each duplicate block that has been 93 * found. The second part of the list (from muldup to the end) 94 * contains duplicate blocks that have been found more than once. 95 * To check if a block has been found as a duplicate it is only 96 * necessary to search from duplist through muldup. To find the 97 * total number of times that a block has been found as a duplicate 98 * the entire list must be searched for occurences of the block 99 * in question. The following diagram shows a sample list where 100 * w (found twice), x (found once), y (found three times), and z 101 * (found once) are duplicate block numbers: 102 * 103 * w -> y -> x -> z -> y -> w -> y 104 * ^ ^ 105 * | | 106 * duplist muldup 107 */ 108 struct dups { 109 struct dups *next; 110 daddr_t dup; 111 }; 112 struct dups *duplist; /* head of dup list */ 113 struct dups *muldup; /* end of unique duplicate dup block numbers */ 114 115 /* 116 * Linked list of inodes with zero link counts. 117 */ 118 struct zlncnt { 119 struct zlncnt *next; 120 ino_t zlncnt; 121 }; 122 struct zlncnt *zlnhead; /* head of zero link count list */ 123 124 /* 125 * Inode cache data structures. 126 */ 127 struct inoinfo { 128 struct inoinfo *i_nexthash; /* next entry in hash chain */ 129 ino_t i_number; /* inode number of this entry */ 130 ino_t i_parent; /* inode number of parent */ 131 ino_t i_dotdot; /* inode number of `..' */ 132 size_t i_isize; /* size of inode */ 133 u_int i_numblks; /* size of block array in bytes */ 134 daddr_t i_blks[1]; /* actually longer */ 135 } **inphead, **inpsort; 136 long numdirs, listmax, inplast; 137 138 char *cdevname; /* name of device being checked */ 139 long dev_bsize; /* computed value of DEV_BSIZE */ 140 long secsize; /* actual disk sector size */ 141 char nflag; /* assume a no response */ 142 char yflag; /* assume a yes response */ 143 int bflag; /* location of alternate super block */ 144 int debug; /* output debugging info */ 145 int cvtlevel; /* convert to newer file system format */ 146 int doinglevel1; /* converting to new cylinder group format */ 147 int doinglevel2; /* converting to new inode format */ 148 int newinofmt; /* filesystem has new inode format */ 149 char preen; /* just fix normal inconsistencies */ 150 char hotroot; /* checking root device */ 151 char havesb; /* superblock has been read */ 152 int fsmodified; /* 1 => write done to file system */ 153 int fsreadfd; /* file descriptor for reading file system */ 154 int fswritefd; /* file descriptor for writing file system */ 155 156 daddr_t maxfsblock; /* number of blocks in the file system */ 157 char *blockmap; /* ptr to primary blk allocation map */ 158 ino_t maxino; /* number of inodes in file system */ 159 ino_t lastino; /* last inode in use */ 160 char *statemap; /* ptr to inode state table */ 161 char *typemap; /* ptr to inode type table */ 162 short *lncntp; /* ptr to link count table */ 163 164 ino_t lfdir; /* lost & found directory inode number */ 165 char *lfname; /* lost & found directory name */ 166 int lfmode; /* lost & found directory creation mode */ 167 168 daddr_t n_blks; /* number of blocks in use */ 169 daddr_t n_files; /* number of files in use */ 170 171 #define clearinode(dp) (*(dp) = zino) 172 struct dinode zino; 173 174 #define setbmap(blkno) setbit(blockmap, blkno) 175 #define testbmap(blkno) isset(blockmap, blkno) 176 #define clrbmap(blkno) clrbit(blockmap, blkno) 177 178 #define STOP 0x01 179 #define SKIP 0x02 180 #define KEEPON 0x04 181 #define ALTERED 0x08 182 #define FOUND 0x10 183 184 time_t time(); 185 struct dinode *ginode(); 186 struct inoinfo *getinoinfo(); 187 void getblk(); 188 ino_t allocino(); 189 int findino(); 190