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