reindent-20030715
[openafs.git] / src / vfsck / fsck.h
1 /*
2  * Copyright (c) 1980, 1986 The Regents of the University of California.
3  * All rights reserved.
4  *
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.
16  *
17  *      @(#)fsck.h      5.10 (Berkeley) 2/1/90
18  */
19
20
21
22 #ifdef  AFS_HPUX_ENV
23 #define MAXDUP          5000    /* limit on dup blks (per inode) */
24 #define MAXBAD          5000    /* limit on bad blks (per inode) */
25 #else
26 #define MAXDUP          10      /* limit on dup blks (per inode) */
27 #define MAXBAD          10      /* limit on bad blks (per inode) */
28 #endif
29 #define MAXBUFSPACE     128*1024        /* maximum space to allocate to buffers */
30
31 #ifndef BUFSIZ
32 #define BUFSIZ 1024
33 #endif
34
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 */
41 #ifdef VICE
42 #define VSTATE  07              /* inode is a AFS file system inode */
43 #endif /* VICE */
44 #ifdef  AFS_HPUX_ENV
45 #define ACLS    1
46 #endif
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 */
51 #ifdef  VICE
52 #define STATE   (USTATE|FSTATE|DSTATE|DCLEAR|CSTATE|CRSTATE|VSTATE)
53 #else
54 #define STATE   (USTATE|FSTATE|DSTATE|DCLEAR|CSTATE|CRSTATE)
55 #endif
56 #endif /* ACLS */
57
58 #ifdef VICE
59 #ifdef  AFS_SUN_ENV
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...
62  */
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))
67 #else
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 */
72 #else
73 #define VICEINODE       (IS_DVICEMAGIC(dp) && (dp->di_mode & IFMT) == IFREG)
74 #endif
75 #endif
76 #if     defined(AFS_SUN56_ENV)
77 #define         OFF_T           offset_t
78 #define         UOFF_T          u_offset_t
79 #else
80 #define         OFF_T           long
81 #define         UOFF_T          long
82 #endif /* AFS_SUN56_ENV */
83
84 /*
85  * buffer cache structure.
86  */
87 struct bufarea {
88     struct bufarea *b_next;     /* free list queue */
89     struct bufarea *b_prev;     /* free list queue */
90     daddr_t b_bno;
91     int b_size;
92     int b_errs;
93     int b_flags;
94     union {
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 */
100     } b_un;
101     char b_dirty;
102 };
103
104 #define B_INUSE 1
105
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();
111
112 #define dirty(bp)       (bp)->b_dirty = 1
113 #define initbarea(bp) \
114         (bp)->b_dirty = 0; \
115         (bp)->b_bno = (daddr_t)-1; \
116         (bp)->b_flags = 0;
117
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)
122
123 #ifdef  AFS_OSF_ENV
124 /*
125  * struct direct -> struct dirent
126 */
127 #define direct  dirent
128 #endif /* AFS_OSF_ENV */
129
130 enum fixstate { DONTKNOW, NOFIX, FIX };
131
132 struct inodesc {
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 */
145 };
146 /* file types */
147 #define DATA    1
148 #define ADDR    2
149
150 /*
151  * Linked list of duplicate blocks.
152  * 
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:
165  *
166  *    w -> y -> x -> z -> y -> w -> y
167  *    ^              ^
168  *    |              |
169  * duplist        muldup
170  */
171 struct dups {
172     struct dups *next;
173     daddr_t dup;
174 };
175 struct dups *duplist;           /* head of dup list */
176 struct dups *muldup;            /* end of unique duplicate dup block numbers */
177
178 /*
179  * Linked list of inodes with zero link counts.
180  */
181 struct zlncnt {
182     struct zlncnt *next;
183     ino_t zlncnt;
184 };
185 struct zlncnt *zlnhead;         /* head of zero link count list */
186
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 */
199 #endif
200
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 */
206
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 */
213
214 char pathname[BUFSIZ];          /* current pathname */
215 char *pathp;                    /* ptr to current position in pathname */
216 char *endpathname;              /* ptr to current end of pathname */
217
218 ino_t lfdir;                    /* lost & found directory inode number */
219 char *lfname;                   /* lost & found directory name */
220 int lfmode;                     /* lost & found directory creation mode */
221
222 daddr_t n_blks;                 /* number of blocks in use */
223 daddr_t n_files;                /* number of files in use */
224
225 #define clearinode(dp)  (*(dp) = zino)
226 struct dinode zino;
227
228 /* only change i_gen if this is a VFS but not VICE fsck */
229 #ifdef VICE
230 #define zapino(x)       (*(x) = zino)
231 #else
232 #define zapino(x)       zino.di_gen = (x)->di_gen+1; (*(x) = zino)
233 #endif /* VICE */
234
235 int isconvert;                  /* converting */
236
237 #ifdef VICE
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 */
241 #endif
242 #ifdef  AFS_SUN_ENV
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 */
247 #ifdef  AFS_SUN5_ENV
248 #define FSTYPE_MAX      8
249 char *fstype;
250                                 /* remount okay if clear */
251 char fflag;                     /* force fsck to check a mounted fs */
252 char mountedfs;                 /* checking mounted device */
253 int oflag;
254 int mflag;
255 int exitstat;
256 int pflag;
257 int fsflag;
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 */
262 #ifdef  AFS_OSF_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 */
269 #endif /* VICE */
270
271 #define setbmap(blkno)  setbit(blockmap, blkno)
272 #define testbmap(blkno) isset(blockmap, blkno)
273 #define clrbmap(blkno)  clrbit(blockmap, blkno)
274
275 #define STOP    0x01
276 #define SKIP    0x02
277 #define KEEPON  0x04
278 #define ALTERED 0x08
279 #define FOUND   0x10
280
281 #include <time.h>               /* for time() */
282 struct dinode *ginode();
283 struct bufarea *getblk();
284 ino_t allocino();
285 int findino();
286
287 /* global variables to be reset in new fork by "setup" */
288 struct bufarea *mlk_pbp;
289 ino_t mlk_startinum;
290
291 #ifdef AFS_SUN_ENV
292 int setup();
293 struct mntent *mntdup();
294 #endif
295
296 #if     defined(AFS_HPUX_ENV)
297 int pclean;
298 #endif
299
300 #ifdef  AFS_HPUX_ENV
301 char fflag;                     /* force fsck to check a mounted fs */
302 int pclean;
303 int mflag;
304 #define BLK     ((dp->di_mode & IFMT) == IFBLK)
305 #define CHR     ((dp->di_mode & IFMT) == IFCHR)
306 #define LNK     ((dp->di_mode & IFMT) == IFLNK)
307 #ifdef IC_FASTLINK
308 #define FASTLNK (LNK && (dp->di_flags & IC_FASTLINK))
309 #else
310 #define FASTLNK (0)
311 #endif
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)
316 #else
317 #define SPECIAL (BLK || CHR)
318 #endif
319 #endif /* AFS_HPUX_ENV */
320
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 */