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.4 (Berkeley) 05/09/95 8 */ 9 10 #include <unistd.h> 11 #include <stdlib.h> 12 #include <stdio.h> 13 14 #define MAXDUP 10 /* limit on dup blks (per inode) */ 15 #define MAXBAD 10 /* limit on bad blks (per inode) */ 16 #define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ 17 #define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ 18 19 #ifndef BUFSIZ 20 #define BUFSIZ 1024 21 #endif 22 23 #define USTATE 01 /* inode not allocated */ 24 #define FSTATE 02 /* inode is file */ 25 #define DSTATE 03 /* inode is directory */ 26 #define DFOUND 04 /* directory found during descent */ 27 #define DCLEAR 05 /* directory is to be cleared */ 28 #define FCLEAR 06 /* file is to be cleared */ 29 30 /* 31 * buffer cache structure. 32 */ 33 struct bufarea { 34 struct bufarea *b_next; /* free list queue */ 35 struct bufarea *b_prev; /* free list queue */ 36 ufs_daddr_t b_bno; 37 int b_size; 38 int b_errs; 39 int b_flags; 40 union { 41 char *b_buf; /* buffer space */ 42 ufs_daddr_t *b_indir; /* indirect block */ 43 struct fs *b_fs; /* super block */ 44 struct cg *b_cg; /* cylinder group */ 45 struct dinode *b_dinode; /* inode block */ 46 } b_un; 47 char b_dirty; 48 }; 49 50 #define B_INUSE 1 51 52 #define MINBUFS 5 /* minimum number of buffers required */ 53 struct bufarea bufhead; /* head of list of other blks in filesys */ 54 struct bufarea sblk; /* file system superblock */ 55 struct bufarea cgblk; /* cylinder group blocks */ 56 struct bufarea *pdirbp; /* current directory contents */ 57 struct bufarea *pbp; /* current inode block */ 58 59 #define dirty(bp) (bp)->b_dirty = 1 60 #define initbarea(bp) \ 61 (bp)->b_dirty = 0; \ 62 (bp)->b_bno = (ufs_daddr_t)-1; \ 63 (bp)->b_flags = 0; 64 65 #define sbdirty() sblk.b_dirty = 1 66 #define cgdirty() cgblk.b_dirty = 1 67 #define sblock (*sblk.b_un.b_fs) 68 #define cgrp (*cgblk.b_un.b_cg) 69 70 enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE}; 71 72 struct inodesc { 73 enum fixstate id_fix; /* policy on fixing errors */ 74 int (*id_func)(); /* function to be applied to blocks of inode */ 75 ino_t id_number; /* inode number described */ 76 ino_t id_parent; /* for DATA nodes, their parent */ 77 ufs_daddr_t id_blkno; /* current block number being examined */ 78 int id_numfrags; /* number of frags contained in block */ 79 quad_t id_filesize; /* for DATA nodes, the size of the directory */ 80 int id_loc; /* for DATA nodes, current location in dir */ 81 int id_entryno; /* for DATA nodes, current entry number */ 82 struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 83 char *id_name; /* for DATA nodes, name to find or enter */ 84 char id_type; /* type of descriptor, DATA or ADDR */ 85 }; 86 /* file types */ 87 #define DATA 1 88 #define ADDR 2 89 90 /* 91 * Linked list of duplicate blocks. 92 * 93 * The list is composed of two parts. The first part of the 94 * list (from duplist through the node pointed to by muldup) 95 * contains a single copy of each duplicate block that has been 96 * found. The second part of the list (from muldup to the end) 97 * contains duplicate blocks that have been found more than once. 98 * To check if a block has been found as a duplicate it is only 99 * necessary to search from duplist through muldup. To find the 100 * total number of times that a block has been found as a duplicate 101 * the entire list must be searched for occurences of the block 102 * in question. The following diagram shows a sample list where 103 * w (found twice), x (found once), y (found three times), and z 104 * (found once) are duplicate block numbers: 105 * 106 * w -> y -> x -> z -> y -> w -> y 107 * ^ ^ 108 * | | 109 * duplist muldup 110 */ 111 struct dups { 112 struct dups *next; 113 ufs_daddr_t dup; 114 }; 115 struct dups *duplist; /* head of dup list */ 116 struct dups *muldup; /* end of unique duplicate dup block numbers */ 117 118 /* 119 * Linked list of inodes with zero link counts. 120 */ 121 struct zlncnt { 122 struct zlncnt *next; 123 ino_t zlncnt; 124 }; 125 struct zlncnt *zlnhead; /* head of zero link count list */ 126 127 /* 128 * Inode cache data structures. 129 */ 130 struct inoinfo { 131 struct inoinfo *i_nexthash; /* next entry in hash chain */ 132 ino_t i_number; /* inode number of this entry */ 133 ino_t i_parent; /* inode number of parent */ 134 ino_t i_dotdot; /* inode number of `..' */ 135 size_t i_isize; /* size of inode */ 136 u_int i_numblks; /* size of block array in bytes */ 137 ufs_daddr_t i_blks[1]; /* actually longer */ 138 } **inphead, **inpsort; 139 long numdirs, listmax, inplast; 140 141 char *cdevname; /* name of device being checked */ 142 long dev_bsize; /* computed value of DEV_BSIZE */ 143 long secsize; /* actual disk sector size */ 144 char nflag; /* assume a no response */ 145 char yflag; /* assume a yes response */ 146 int bflag; /* location of alternate super block */ 147 int debug; /* output debugging info */ 148 int cvtlevel; /* convert to newer file system format */ 149 int doinglevel1; /* converting to new cylinder group format */ 150 int doinglevel2; /* converting to new inode format */ 151 int newinofmt; /* filesystem has new inode format */ 152 char preen; /* just fix normal inconsistencies */ 153 char hotroot; /* checking root device */ 154 char havesb; /* superblock has been read */ 155 int fsmodified; /* 1 => write done to file system */ 156 int fsreadfd; /* file descriptor for reading file system */ 157 int fswritefd; /* file descriptor for writing file system */ 158 159 ufs_daddr_t maxfsblock; /* number of blocks in the file system */ 160 char *blockmap; /* ptr to primary blk allocation map */ 161 ino_t maxino; /* number of inodes in file system */ 162 ino_t lastino; /* last inode in use */ 163 char *statemap; /* ptr to inode state table */ 164 u_char *typemap; /* ptr to inode type table */ 165 short *lncntp; /* ptr to link count table */ 166 167 ino_t lfdir; /* lost & found directory inode number */ 168 char *lfname; /* lost & found directory name */ 169 int lfmode; /* lost & found directory creation mode */ 170 171 ufs_daddr_t n_blks; /* number of blocks in use */ 172 ufs_daddr_t n_files; /* number of files in use */ 173 174 #define clearinode(dp) (*(dp) = zino) 175 struct dinode zino; 176 177 #define setbmap(blkno) setbit(blockmap, blkno) 178 #define testbmap(blkno) isset(blockmap, blkno) 179 #define clrbmap(blkno) clrbit(blockmap, blkno) 180 181 #define STOP 0x01 182 #define SKIP 0x02 183 #define KEEPON 0x04 184 #define ALTERED 0x08 185 #define FOUND 0x10 186 187 #define EEXIT 8 /* Standard error exit. */ 188 189 struct fstab; 190 191 void adjust __P((struct inodesc *, int lcnt)); 192 ufs_daddr_t allocblk __P((long frags)); 193 ino_t allocdir __P((ino_t parent, ino_t request, int mode)); 194 ino_t allocino __P((ino_t request, int type)); 195 void blkerror __P((ino_t ino, char *type, ufs_daddr_t blk)); 196 char *blockcheck __P((char *name)); 197 int bread __P((int fd, char *buf, ufs_daddr_t blk, long size)); 198 void bufinit __P((void)); 199 void bwrite __P((int fd, char *buf, ufs_daddr_t blk, long size)); 200 void cacheino __P((struct dinode *dp, ino_t inumber)); 201 void catch __P((int)); 202 void catchquit __P((int)); 203 int changeino __P((ino_t dir, char *name, ino_t newnum)); 204 int checkfstab __P((int preen, int maxrun, 205 int (*docheck)(struct fstab *), 206 int (*chkit)(char *, char *, long, int))); 207 int chkrange __P((ufs_daddr_t blk, int cnt)); 208 void ckfini __P((int markclean)); 209 int ckinode __P((struct dinode *dp, struct inodesc *)); 210 void clri __P((struct inodesc *, char *type, int flag)); 211 void direrror __P((ino_t ino, char *errmesg)); 212 int dirscan __P((struct inodesc *)); 213 int dofix __P((struct inodesc *, char *msg)); 214 void ffs_clrblock __P((struct fs *, u_char *, ufs_daddr_t)); 215 void ffs_fragacct __P((struct fs *, int, int32_t [], int)); 216 int ffs_isblock __P((struct fs *, u_char *, ufs_daddr_t)); 217 void ffs_setblock __P((struct fs *, u_char *, ufs_daddr_t)); 218 void fileerror __P((ino_t cwd, ino_t ino, char *errmesg)); 219 int findino __P((struct inodesc *)); 220 int findname __P((struct inodesc *)); 221 void flush __P((int fd, struct bufarea *bp)); 222 void freeblk __P((ufs_daddr_t blkno, long frags)); 223 void freeino __P((ino_t ino)); 224 void freeinodebuf __P((void)); 225 int ftypeok __P((struct dinode *dp)); 226 void getblk __P((struct bufarea *bp, ufs_daddr_t blk, long size)); 227 struct bufarea *getdatablk __P((ufs_daddr_t blkno, long size)); 228 struct inoinfo *getinoinfo __P((ino_t inumber)); 229 struct dinode *getnextinode __P((ino_t inumber)); 230 void getpathname __P((char *namebuf, ino_t curdir, ino_t ino)); 231 struct dinode *ginode __P((ino_t inumber)); 232 void inocleanup __P((void)); 233 void inodirty __P((void)); 234 int linkup __P((ino_t orphan, ino_t parentdir)); 235 int makeentry __P((ino_t parent, ino_t ino, char *name)); 236 void panic __P((const char *fmt, ...)); 237 void pass1 __P((void)); 238 void pass1b __P((void)); 239 int pass1check __P((struct inodesc *)); 240 void pass2 __P((void)); 241 void pass3 __P((void)); 242 void pass4 __P((void)); 243 int pass4check __P((struct inodesc *)); 244 void pass5 __P((void)); 245 void pfatal __P((const char *fmt, ...)); 246 void pinode __P((ino_t ino)); 247 void propagate __P((void)); 248 void pwarn __P((const char *fmt, ...)); 249 int reply __P((char *question)); 250 void resetinodebuf __P((void)); 251 int setup __P((char *dev)); 252 void voidquit __P((int)); 253