2 * Copyright (c) 1980, 1986 The Regents of the University of California.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 * @(#)fsck.h 5.10 (Berkeley) 2/1/90
23 #define MAXDUP 5000 /* limit on dup blks (per inode) */
24 #define MAXBAD 5000 /* limit on bad blks (per inode) */
26 #define MAXDUP 10 /* limit on dup blks (per inode) */
27 #define MAXBAD 10 /* limit on bad blks (per inode) */
29 #define MAXBUFSPACE 128*1024 /* maximum space to allocate to buffers */
35 #define USTATE 01 /* inode not allocated */
36 #define FSTATE 02 /* inode is file */
37 #define DSTATE 03 /* inode is directory */
38 #define DFOUND 04 /* directory found during descent */
39 #define DCLEAR 05 /* directory is to be cleared */
40 #define FCLEAR 06 /* file is to be cleared */
42 #define VSTATE 07 /* inode is a AFS file system inode */
47 #if defined(ACLS) && defined(AFS_HPUX_ENV)
48 #define CSTATE 8 /* inode is a continuation inode */
49 #define CRSTATE 16 /* continuation inode has been referenced */
50 #define HASCINODE 32 /* has continuation inode associated with it */
52 #define STATE (USTATE|FSTATE|DSTATE|DCLEAR|CSTATE|CRSTATE|VSTATE)
54 #define STATE (USTATE|FSTATE|DSTATE|DCLEAR|CSTATE|CRSTATE)
60 /* The following define is in order to utilize one vfsck for SunOS 4.1 & 4.1.1; note
61 * that the ic_flags and size.val[0] will be zero except for AFS inodes in 4.1.1...
63 #define VICEINODE ((dp->di_vicemagic == VICEMAGIC) \
64 && (dp->di_mode & IFMT) == IFREG)
65 #define OLDVICEINODE (!dp->di_ic.ic_uid && (dp->di_ic.ic_gid== 0xfffffffe))
67 #define VICEINODE (IS_DVICEMAGIC(dp) && (dp->di_mode & IFMT) == IFREG)
70 #if defined(AFS_SUN5_ENV)
71 #define OFF_T offset_t
72 #define UOFF_T u_offset_t
76 #endif /* AFS_SUN5_ENV */
79 * buffer cache structure.
82 struct bufarea *b_next; /* free list queue */
83 struct bufarea *b_prev; /* free list queue */
89 char *b_buf; /* buffer space */
90 daddr_t *b_indir; /* indirect block */
91 struct fs *b_fs; /* super block */
92 struct cg *b_cg; /* cylinder group */
93 struct dinode *b_dinode; /* inode block */
100 #define MINBUFS 5 /* minimum number of buffers required */
101 struct bufarea bufhead; /* head of list of other blks in filesys */
102 struct bufarea sblk; /* file system superblock */
103 struct bufarea cgblk; /* cylinder group blocks */
104 struct bufarea *getdatablk();
106 #define dirty(bp) (bp)->b_dirty = 1
107 #define initbarea(bp) \
109 (bp)->b_bno = (daddr_t)-1; \
112 #define sbdirty() sblk.b_dirty = 1
113 #define cgdirty() cgblk.b_dirty = 1
114 #define sblock (*sblk.b_un.b_fs)
115 #define cgrp (*cgblk.b_un.b_cg)
117 enum fixstate { DONTKNOW, NOFIX, FIX };
120 enum fixstate id_fix; /* policy on fixing errors */
121 int (*id_func) (); /* function to be applied to blocks of inode */
122 ino_t id_number; /* inode number described */
123 ino_t id_parent; /* for DATA nodes, their parent */
124 daddr_t id_blkno; /* current block number being examined */
125 int id_numfrags; /* number of frags contained in block */
126 OFF_T id_filesize; /* for DATA nodes, the size of the directory */
127 int id_loc; /* for DATA nodes, current location in dir */
128 int id_entryno; /* for DATA nodes, current entry number */
129 struct direct *id_dirp; /* for DATA nodes, ptr to current entry */
130 char *id_name; /* for DATA nodes, name to find or enter */
131 char id_type; /* type of descriptor, DATA or ADDR */
138 * Linked list of duplicate blocks.
140 * The list is composed of two parts. The first part of the
141 * list (from duplist through the node pointed to by muldup)
142 * contains a single copy of each duplicate block that has been
143 * found. The second part of the list (from muldup to the end)
144 * contains duplicate blocks that have been found more than once.
145 * To check if a block has been found as a duplicate it is only
146 * necessary to search from duplist through muldup. To find the
147 * total number of times that a block has been found as a duplicate
148 * the entire list must be searched for occurences of the block
149 * in question. The following diagram shows a sample list where
150 * w (found twice), x (found once), y (found three times), and z
151 * (found once) are duplicate block numbers:
153 * w -> y -> x -> z -> y -> w -> y
162 struct dups *duplist; /* head of dup list */
163 struct dups *muldup; /* end of unique duplicate dup block numbers */
166 * Linked list of inodes with zero link counts.
172 struct zlncnt *zlnhead; /* head of zero link count list */
174 char *devname; /* name of device being checked */
175 long dev_bsize; /* computed value of DEV_BSIZE */
176 long secsize; /* actual disk sector size */
177 char nflag; /* assume a no response */
178 char yflag; /* assume a yes response */
179 int bflag; /* location of alternate super block */
180 int qflag; /* less verbose flag */
181 int debug; /* output debugging info */
182 int cvtflag; /* convert to old file system format */
183 char preen; /* just fix normal inconsistencies */
185 char hotroot; /* checking root device */
186 char havesb; /* superblock has been read */
187 int fsmodified; /* 1 => write done to file system */
188 int fsreadfd; /* file descriptor for reading file system */
189 int fswritefd; /* file descriptor for writing file system */
191 daddr_t maxfsblock; /* number of blocks in the file system */
192 char *blockmap; /* ptr to primary blk allocation map */
193 ino_t maxino; /* number of inodes in file system */
194 ino_t lastino; /* last inode in use */
195 char *statemap; /* ptr to inode state table */
196 short *lncntp; /* ptr to link count table */
198 char pathname[BUFSIZ]; /* current pathname */
199 char *pathp; /* ptr to current position in pathname */
200 char *endpathname; /* ptr to current end of pathname */
202 ino_t lfdir; /* lost & found directory inode number */
203 char *lfname; /* lost & found directory name */
204 int lfmode; /* lost & found directory creation mode */
206 daddr_t n_blks; /* number of blocks in use */
207 daddr_t n_files; /* number of files in use */
209 #define clearinode(dp) (*(dp) = zino)
212 /* only change i_gen if this is a VFS but not VICE fsck */
214 #define zapino(x) (*(x) = zino)
216 #define zapino(x) zino.di_gen = (x)->di_gen+1; (*(x) = zino)
219 int isconvert; /* converting */
222 int nViceFiles; /* number of vice files seen */
223 #if defined(AFS_SUN_ENV)
224 int iscorrupt; /* known to be corrupt/inconsistent */
227 char fixstate; /* is FsSTATE to be fixed */
228 char rebflg; /* needs reboot if set */
229 int isdirty; /* 1 => write pending to file system */
230 #endif /* AFS_SUN_ENV */
234 /* remount okay if clear */
235 char fflag; /* force fsck to check a mounted fs */
236 char mountedfs; /* checking mounted device */
242 int rflag; /* check raw file systems */
243 #include <sys/sysmacros.h>
244 FILE *logfile; /* additional place for log message, for non-root file systems */
245 #else /* AFS_SUN5_ENV */
246 struct _iobuf *logfile; /* additional place for log message, for non-root file systems */
247 #endif /* AFS_SUN5_ENV */
250 #define setbmap(blkno) setbit(blockmap, blkno)
251 #define testbmap(blkno) isset(blockmap, blkno)
252 #define clrbmap(blkno) clrbit(blockmap, blkno)
260 #include <time.h> /* for time() */
261 struct dinode *ginode();
262 struct bufarea *getblk();
266 /* global variables to be reset in new fork by "setup" */
267 struct bufarea *mlk_pbp;
272 struct mntent *mntdup();
275 #if defined(AFS_HPUX_ENV)
280 char fflag; /* force fsck to check a mounted fs */
283 #define BLK ((dp->di_mode & IFMT) == IFBLK)
284 #define CHR ((dp->di_mode & IFMT) == IFCHR)
285 #define LNK ((dp->di_mode & IFMT) == IFLNK)
287 #define FASTLNK (LNK && (dp->di_flags & IC_FASTLINK))
291 #if defined(ACLS) && defined(AFS_HPUX_ENV)
292 daddr_t n_cont; /* number of continuation inodes seen */
293 #define CONT ((dp->di_mode & IFMT) == IFCONT) /* continuation inode */
294 #define SPECIAL (BLK || CHR || CONT)
296 #define SPECIAL (BLK || CHR)
298 #endif /* AFS_HPUX_ENV */
300 #if defined(AFS_HPUX110_ENV)
301 /* For backward compatibility */
302 #define cg_link cg_unused[0]
303 #define cg_rlink cg_unused[1]
304 #define fs_link fs_unused[0]
305 #define fs_rlink fs_unused[1]
306 #endif /* AFS_HPUX110_ENV */
309 /* diskaddr_t is longlong */
310 int bread(int fd, char *buf, diskaddr_t blk, long size);
311 int bwrite(int fd, char *buf, diskaddr_t blk, long size);