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 #if defined(AFS_SUN56_ENV)
64 #define VICEINODE ((dp->di_vicemagic == VICEMAGIC) \
65 && (dp->di_mode & IFMT) == IFREG)
66 #define OLDVICEINODE (!dp->di_ic.ic_uid && (dp->di_ic.ic_gid== 0xfffffffe))
68 #define VICEINODE (((dp->di_ic.ic_gen == VICEMAGIC) || \
69 (dp->di_ic.ic_flags || dp->di_ic.ic_size.val[0])) \
70 && (dp->di_mode & IFMT) == IFREG)
71 #endif /* AFS_SUN56_ENV */
73 #define VICEINODE (IS_DVICEMAGIC(dp) && (dp->di_mode & IFMT) == IFREG)
76 #if defined(AFS_SUN56_ENV)
77 #define OFF_T offset_t
78 #define UOFF_T u_offset_t
82 #endif /* AFS_SUN56_ENV */
85 * buffer cache structure.
88 struct bufarea *b_next; /* free list queue */
89 struct bufarea *b_prev; /* free list queue */
95 char *b_buf; /* buffer space */
96 daddr_t *b_indir; /* indirect block */
97 struct fs *b_fs; /* super block */
98 struct cg *b_cg; /* cylinder group */
99 struct dinode *b_dinode; /* inode block */
106 #define MINBUFS 5 /* minimum number of buffers required */
107 struct bufarea bufhead; /* head of list of other blks in filesys */
108 struct bufarea sblk; /* file system superblock */
109 struct bufarea cgblk; /* cylinder group blocks */
110 struct bufarea *getdatablk();
112 #define dirty(bp) (bp)->b_dirty = 1
113 #define initbarea(bp) \
115 (bp)->b_bno = (daddr_t)-1; \
118 #define sbdirty() sblk.b_dirty = 1
119 #define cgdirty() cgblk.b_dirty = 1
120 #define sblock (*sblk.b_un.b_fs)
121 #define cgrp (*cgblk.b_un.b_cg)
125 * struct direct -> struct dirent
127 #define direct dirent
128 #endif /* AFS_OSF_ENV */
130 enum fixstate { DONTKNOW, NOFIX, FIX };
133 enum fixstate id_fix; /* policy on fixing errors */
134 int (*id_func) (); /* function to be applied to blocks of inode */
135 ino_t id_number; /* inode number described */
136 ino_t id_parent; /* for DATA nodes, their parent */
137 daddr_t id_blkno; /* current block number being examined */
138 int id_numfrags; /* number of frags contained in block */
139 OFF_T id_filesize; /* for DATA nodes, the size of the directory */
140 int id_loc; /* for DATA nodes, current location in dir */
141 int id_entryno; /* for DATA nodes, current entry number */
142 struct direct *id_dirp; /* for DATA nodes, ptr to current entry */
143 char *id_name; /* for DATA nodes, name to find or enter */
144 char id_type; /* type of descriptor, DATA or ADDR */
151 * Linked list of duplicate blocks.
153 * The list is composed of two parts. The first part of the
154 * list (from duplist through the node pointed to by muldup)
155 * contains a single copy of each duplicate block that has been
156 * found. The second part of the list (from muldup to the end)
157 * contains duplicate blocks that have been found more than once.
158 * To check if a block has been found as a duplicate it is only
159 * necessary to search from duplist through muldup. To find the
160 * total number of times that a block has been found as a duplicate
161 * the entire list must be searched for occurences of the block
162 * in question. The following diagram shows a sample list where
163 * w (found twice), x (found once), y (found three times), and z
164 * (found once) are duplicate block numbers:
166 * w -> y -> x -> z -> y -> w -> y
175 struct dups *duplist; /* head of dup list */
176 struct dups *muldup; /* end of unique duplicate dup block numbers */
179 * Linked list of inodes with zero link counts.
185 struct zlncnt *zlnhead; /* head of zero link count list */
187 char *devname; /* name of device being checked */
188 long dev_bsize; /* computed value of DEV_BSIZE */
189 long secsize; /* actual disk sector size */
190 char nflag; /* assume a no response */
191 char yflag; /* assume a yes response */
192 int bflag; /* location of alternate super block */
193 int qflag; /* less verbose flag */
194 int debug; /* output debugging info */
195 int cvtflag; /* convert to old file system format */
196 char preen; /* just fix normal inconsistencies */
197 #if defined(AFS_DEC_ENV)
198 char only_when_needed; /* check filesystems only when needed */
201 char hotroot; /* checking root device */
202 char havesb; /* superblock has been read */
203 int fsmodified; /* 1 => write done to file system */
204 int fsreadfd; /* file descriptor for reading file system */
205 int fswritefd; /* file descriptor for writing file system */
207 daddr_t maxfsblock; /* number of blocks in the file system */
208 char *blockmap; /* ptr to primary blk allocation map */
209 ino_t maxino; /* number of inodes in file system */
210 ino_t lastino; /* last inode in use */
211 char *statemap; /* ptr to inode state table */
212 short *lncntp; /* ptr to link count table */
214 char pathname[BUFSIZ]; /* current pathname */
215 char *pathp; /* ptr to current position in pathname */
216 char *endpathname; /* ptr to current end of pathname */
218 ino_t lfdir; /* lost & found directory inode number */
219 char *lfname; /* lost & found directory name */
220 int lfmode; /* lost & found directory creation mode */
222 daddr_t n_blks; /* number of blocks in use */
223 daddr_t n_files; /* number of files in use */
225 #define clearinode(dp) (*(dp) = zino)
228 /* only change i_gen if this is a VFS but not VICE fsck */
230 #define zapino(x) (*(x) = zino)
232 #define zapino(x) zino.di_gen = (x)->di_gen+1; (*(x) = zino)
235 int isconvert; /* converting */
238 int nViceFiles; /* number of vice files seen */
239 #if defined(AFS_SUN_ENV) || defined(AFS_DEC_ENV)
240 int iscorrupt; /* known to be corrupt/inconsistent */
243 char fixstate; /* is FsSTATE to be fixed */
244 char rebflg; /* needs reboot if set */
245 int isdirty; /* 1 => write pending to file system */
246 #endif /* AFS_SUN_ENV */
250 /* remount okay if clear */
251 char fflag; /* force fsck to check a mounted fs */
252 char mountedfs; /* checking mounted device */
258 int rflag; /* check raw file systems */
259 #include <sys/sysmacros.h>
260 FILE *logfile; /* additional place for log message, for non-root file systems */
261 #else /* AFS_SUN5_ENV */
263 FILE *logfile; /* additional place for log message, for non-root file systems */
264 char fflag; /* force fsck to check a mounted fs */
265 #else /* AFS_OSF_ENV */
266 struct _iobuf *logfile; /* additional place for log message, for non-root file systems */
267 #endif /* AFS_OSF_ENV */
268 #endif /* AFS_SUN5_ENV */
271 #define setbmap(blkno) setbit(blockmap, blkno)
272 #define testbmap(blkno) isset(blockmap, blkno)
273 #define clrbmap(blkno) clrbit(blockmap, blkno)
281 #include <time.h> /* for time() */
282 struct dinode *ginode();
283 struct bufarea *getblk();
287 /* global variables to be reset in new fork by "setup" */
288 struct bufarea *mlk_pbp;
293 struct mntent *mntdup();
296 #if defined(AFS_HPUX_ENV)
301 char fflag; /* force fsck to check a mounted fs */
304 #define BLK ((dp->di_mode & IFMT) == IFBLK)
305 #define CHR ((dp->di_mode & IFMT) == IFCHR)
306 #define LNK ((dp->di_mode & IFMT) == IFLNK)
308 #define FASTLNK (LNK && (dp->di_flags & IC_FASTLINK))
312 #if defined(ACLS) && defined(AFS_HPUX_ENV)
313 daddr_t n_cont; /* number of continuation inodes seen */
314 #define CONT ((dp->di_mode & IFMT) == IFCONT) /* continuation inode */
315 #define SPECIAL (BLK || CHR || CONT)
317 #define SPECIAL (BLK || CHR)
319 #endif /* AFS_HPUX_ENV */
321 #if defined(AFS_HPUX110_ENV)
322 /* For backward compatibility */
323 #define cg_link cg_unused[0]
324 #define cg_rlink cg_unused[1]
325 #define fs_link fs_unused[0]
326 #define fs_rlink fs_unused[1]
327 #endif /* AFS_HPUX110_ENV */