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