1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2 /* All Rights Reserved */ 3 4 /* 5 * Copyright (c) 1980, 1986, 1990 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that: (1) source distributions retain this entire copyright 10 * notice and comment, and (2) distributions including binaries display 11 * the following acknowledgement: ``This product includes software 12 * developed by the University of California, Berkeley and its contributors'' 13 * in the documentation or other materials provided with the distribution 14 * and in all advertising materials mentioning features or use of this 15 * software. Neither the name of the University nor the names of its 16 * contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21 */ 22 23 /* 24 * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 #ifndef _FSCK_FSCK_H 29 #define _FSCK_FSCK_H 30 31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */ 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 #define MAXDUP 10 /* limit on dup blks (per inode) */ 38 #define MAXBAD 10 /* limit on bad blks (per inode) */ 39 #define MaxCPG 100000 /* sanity limit on # of cylinders / group */ 40 #define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ 41 #define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ 42 43 #ifndef BUFSIZ 44 #define BUFSIZ 1024 45 #endif 46 47 #define USTATE 01 /* inode not allocated */ 48 #define FSTATE 02 /* inode is file */ 49 #define DSTATE 03 /* inode is directory */ 50 #define DFOUND 04 /* directory found during descent */ 51 #define DCLEAR 05 /* directory is to be cleared */ 52 #define FCLEAR 06 /* file is to be cleared */ 53 #define SSTATE 07 /* inode is a shadow */ 54 #define SCLEAR 10 /* shadow is to be cleared */ 55 56 /* 57 * buffer cache structure. 58 */ 59 struct bufarea { 60 struct bufarea *b_next; /* free list queue */ 61 struct bufarea *b_prev; /* free list queue */ 62 diskaddr_t b_bno; 63 int b_size; 64 int b_errs; 65 int b_flags; 66 int b_cnt; /* reference cnt */ 67 union { 68 char *b_buf; /* buffer space */ 69 daddr32_t *b_indir; /* indirect block */ 70 struct fs *b_fs; /* super block */ 71 struct cg *b_cg; /* cylinder group */ 72 struct dinode *b_dinode; /* inode block */ 73 } b_un; 74 char b_dirty; 75 }; 76 77 #define B_INUSE 1 78 79 #define MINBUFS 5 /* minimum number of buffers required */ 80 struct bufarea bufhead; /* head of list of other blks in filesys */ 81 struct bufarea sblk; /* file system superblock */ 82 struct bufarea cgblk; /* cylinder group blocks */ 83 struct bufarea *pbp; /* pointer to inode data in buffer pool */ 84 struct bufarea *pdirbp; /* pointer to directory data in buffer pool */ 85 struct bufarea *getdatablk(daddr32_t, int); 86 87 #define dirty(bp) (bp)->b_dirty = isdirty = 1 88 #define initbarea(bp) \ 89 (bp)->b_dirty = 0; \ 90 (bp)->b_bno = -1LL; \ 91 (bp)->b_flags = 0; \ 92 (bp)->b_cnt = 0; 93 94 #define sbdirty() sblk.b_dirty = isdirty = 1 95 #define cgdirty() cgblk.b_dirty = isdirty = 1 96 #define sblock (*sblk.b_un.b_fs) 97 #define cgrp (*cgblk.b_un.b_cg) 98 99 enum fixstate {DONTKNOW, NOFIX, FIX}; 100 101 struct inodesc { 102 enum fixstate id_fix; /* policy on fixing errors */ 103 int (*id_func)(); /* function to be applied to blocks of inode */ 104 ino_t id_number; /* inode number described */ 105 ino_t id_parent; /* for DATA nodes, their parent */ 106 ino_t id_client; /* base file for attribute */ 107 daddr32_t id_blkno; /* current block number being examined */ 108 int id_numfrags; /* number of frags contained in block */ 109 offset_t id_filesize; /* for DATA nodes, the size of the directory */ 110 uint_t id_loc; /* for DATA nodes, current location in dir */ 111 uint_t id_entryno; /* for DATA nodes, current entry number */ 112 int id_hasholes; /* for DATA inode, 1 == dir has holes */ 113 int id_llbna; /* for DATA nodes, last logical block alloc'd */ 114 struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 115 char *id_name; /* for DATA nodes, name to find or enter */ 116 char id_type; /* type of descriptor, DATA or ADDR */ 117 }; 118 /* file types */ 119 #define DATA 1 120 #define ADDR 2 121 #define ACL 3 122 123 /* 124 * Linked list of duplicate blocks. 125 * 126 * The list is composed of two parts. The first part of the 127 * list (from duplist through the node pointed to by muldup) 128 * contains a single copy of each duplicate block that has been 129 * found. The second part of the list (from muldup to the end) 130 * contains duplicate blocks that have been found more than once. 131 * To check if a block has been found as a duplicate it is only 132 * necessary to search from duplist through muldup. To find the 133 * total number of times that a block has been found as a duplicate 134 * the entire list must be searched for occurences of the block 135 * in question. The following diagram shows a sample list where 136 * w (found twice), x (found once), y (found three times), and z 137 * (found once) are duplicate block numbers: 138 * 139 * w -> y -> x -> z -> y -> w -> y 140 * ^ ^ 141 * | | 142 * duplist muldup 143 */ 144 struct dups { 145 struct dups *next; 146 daddr32_t dup; 147 }; 148 struct dups *duplist; /* head of dup list */ 149 struct dups *muldup; /* end of unique duplicate dup block numbers */ 150 151 /* 152 * Linked list of inodes with zero link counts. 153 */ 154 struct zlncnt { 155 struct zlncnt *next; 156 ino_t zlncnt; 157 }; 158 struct zlncnt *zlnhead; /* head of zero link count list */ 159 160 /* 161 * Inode cache data structures. 162 */ 163 struct inoinfo { 164 struct inoinfo *i_nexthash; /* next entry in hash chain */ 165 ino_t i_number; /* inode number of this entry */ 166 ino_t i_parent; /* inode number of parent */ 167 ino_t i_dotdot; /* inode number of `..' */ 168 ino_t i_extattr; /* inode of hidden attr dir */ 169 offset_t i_isize; /* size of inode */ 170 uint_t i_numblks; /* size of block array in bytes */ 171 daddr32_t i_blks[1]; /* actually longer */ 172 } **inphead, **inpsort; 173 int64_t numdirs, listmax, inplast; 174 175 /* 176 * Acl cache data structures. 177 */ 178 struct aclinfo { 179 struct aclinfo *i_nexthash; /* next entry in hash chain */ 180 ino_t i_number; /* inode number of this entry */ 181 offset_t i_isize; /* size of inode */ 182 uint_t i_numblks; /* size of block array in bytes */ 183 daddr32_t i_blks[1]; /* actually longer */ 184 } **aclphead, **aclpsort; 185 int64_t numacls, aclmax, aclplast; 186 187 /* 188 * shadowclients and shadowclientinfo are structures for keeping track of 189 * shadow inodes that exist, and which regular inodes use them (i.e. are 190 * their clients). 191 */ 192 193 struct shadowclients { 194 ino_t *client; /* an array of inode numbers */ 195 int nclients; /* how many inodes in the array are in use (valid) */ 196 struct shadowclients *next; /* link to more client inode numbers */ 197 }; 198 struct shadowclientinfo { 199 ino_t shadow; /* the shadow inode that this info is for */ 200 int totalClients; /* how many inodes total refer to this */ 201 struct shadowclients *clients; /* a linked list of wads of clients */ 202 struct shadowclientinfo *next; /* link to the next shadow inode */ 203 }; 204 /* global pointer to this shadow/client information */ 205 extern struct shadowclientinfo *shadowclientinfo; 206 extern struct shadowclientinfo *attrclientinfo; 207 /* granularity -- how many client inodes do we make space for at a time */ 208 /* initialized in setup.c; changable with adb should anyone ever have a need */ 209 extern int maxshadowclients; 210 void registershadowclients(ino_t, ino_t, struct shadowclientinfo **); 211 212 char *devname; /* name of device being checked */ 213 int dev_bsize; /* computed value of DEV_BSIZE */ 214 int secsize; /* actual disk sector size */ 215 char nflag; /* assume a no response */ 216 char yflag; /* assume a yes response */ 217 int bflag; /* location of alternate super block */ 218 int debug; /* output debugging info */ 219 int rflag; /* check raw file systems */ 220 int wflag; /* check only writable filesystems */ 221 int fflag; /* check regardless of clean flag (force) */ 222 int cvtflag; /* convert to old file system format */ 223 char preen; /* just fix normal inconsistencies */ 224 char mountedfs; /* checking mounted device */ 225 int exitstat; /* exit status (set to 8 if 'No' response) */ 226 char hotroot; /* checking root device */ 227 char havesb; /* superblock has been read */ 228 int fsmodified; /* 1 => write done to file system */ 229 int fsreadfd; /* file descriptor for reading file system */ 230 int fswritefd; /* file descriptor for writing file system */ 231 232 int iscorrupt; /* known to be corrupt/inconsistent */ 233 int isdirty; /* 1 => write pending to file system */ 234 int isconvert; /* converting */ 235 236 int dirholes; /* Found dirs with holes in indirect blks */ 237 238 int islog; /* logging file system */ 239 int islogok; /* log is okay */ 240 int ismdd; /* metadevice */ 241 int isreclaim; /* reclaiming is set in the superblock */ 242 int willreclaim; /* reclaim thread will run at mount */ 243 244 int errorlocked; /* set => mounted fs has been error-locked */ 245 /* implies fflag "force check flag" */ 246 char *elock_combuf; /* error lock comment buffer */ 247 char *elock_mountp; /* mount point; used to unlock error-lock */ 248 int pid; /* fsck's process id (put in lockfs comment) */ 249 int needs_reclaim; /* files were deleted, hence reclaim needed */ 250 int mountfd; /* fd of mount point */ 251 struct lockfs *lfp; /* current lockfs status */ 252 253 daddr32_t maxfsblock; /* number of blocks in the file system */ 254 char *blockmap; /* ptr to primary blk allocation map */ 255 ino_t maxino; /* number of inodes in file system */ 256 ino_t lastino; /* last inode in use */ 257 char *statemap; /* ptr to inode state table */ 258 short *lncntp; /* ptr to link count table */ 259 260 ino_t lfdir; /* lost & found directory inode number */ 261 char *lfname; /* lost & found directory name */ 262 int lfmode; /* lost & found directory creation mode */ 263 264 char *aclbuf; /* hold acl's for parsing */ 265 int64_t aclbufoff; /* offset into aclbuf */ 266 267 daddr32_t n_blks; /* number of blocks in use */ 268 daddr32_t n_files; /* number of files in use */ 269 270 #define clearinode(dp) (*(dp) = zino), (needs_reclaim = errorlocked) 271 struct dinode zino; 272 273 #define setbmap(blkno) setbit(blockmap, blkno) 274 #define testbmap(blkno) isset(blockmap, blkno) 275 #define clrbmap(blkno) clrbit(blockmap, blkno) 276 277 #define STOP 0x01 278 #define SKIP 0x02 279 #define KEEPON 0x04 280 #define ALTERED 0x08 281 #define FOUND 0x10 282 283 time_t time(); 284 struct dinode *ginode(ino_t); 285 struct inoinfo *getinoinfo(ino_t); 286 struct bufarea *getblk(struct bufarea *, daddr32_t, int); 287 ino_t allocino(ino_t, int); 288 int findino(struct inodesc *); 289 char *setup(char *); 290 struct bufarea *getdirblk(daddr32_t blkno, int size); 291 struct bufarea *getdatablk(daddr32_t blkno, int size); 292 daddr32_t allocblk(int frags); 293 extern int bread(int, char *, diskaddr_t, long); 294 extern int bwrite(int, char *, diskaddr_t, long); 295 extern int reply(char *); 296 extern int errexit(); 297 extern int pfatal(); 298 extern int pwarn(); 299 extern int mounted(char *); 300 extern int do_errorlock(int); 301 extern int printclean(void); 302 extern int bufinit(void); 303 extern int ckfini(void); 304 305 306 #ifdef __cplusplus 307 } 308 #endif 309 310 #endif /* _FSCK_FSCK_H */ 311