venus: Remove dedebug
[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 #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))
66 #else
67 #define VICEINODE       (IS_DVICEMAGIC(dp) && (dp->di_mode & IFMT) == IFREG)
68 #endif
69 #endif
70 #if     defined(AFS_SUN5_ENV)
71 #define         OFF_T           offset_t
72 #define         UOFF_T          u_offset_t
73 #else
74 #define         OFF_T           long
75 #define         UOFF_T          long
76 #endif /* AFS_SUN5_ENV */
77
78 /*
79  * buffer cache structure.
80  */
81 struct bufarea {
82     struct bufarea *b_next;     /* free list queue */
83     struct bufarea *b_prev;     /* free list queue */
84     daddr_t b_bno;
85     int b_size;
86     int b_errs;
87     int b_flags;
88     union {
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 */
94     } b_un;
95     char b_dirty;
96 };
97
98 #define B_INUSE 1
99
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();
105
106 #define dirty(bp)       (bp)->b_dirty = 1
107 #define initbarea(bp) \
108         (bp)->b_dirty = 0; \
109         (bp)->b_bno = (daddr_t)-1; \
110         (bp)->b_flags = 0;
111
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)
116
117 enum fixstate { DONTKNOW, NOFIX, FIX };
118
119 struct inodesc {
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 */
132 };
133 /* file types */
134 #define DATA    1
135 #define ADDR    2
136
137 /*
138  * Linked list of duplicate blocks.
139  *
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:
152  *
153  *    w -> y -> x -> z -> y -> w -> y
154  *    ^              ^
155  *    |              |
156  * duplist        muldup
157  */
158 struct dups {
159     struct dups *next;
160     daddr_t dup;
161 };
162 struct dups *duplist;           /* head of dup list */
163 struct dups *muldup;            /* end of unique duplicate dup block numbers */
164
165 /*
166  * Linked list of inodes with zero link counts.
167  */
168 struct zlncnt {
169     struct zlncnt *next;
170     ino_t zlncnt;
171 };
172 struct zlncnt *zlnhead;         /* head of zero link count list */
173
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 */
184
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 */
190
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 */
197
198 char pathname[BUFSIZ];          /* current pathname */
199 char *pathp;                    /* ptr to current position in pathname */
200 char *endpathname;              /* ptr to current end of pathname */
201
202 ino_t lfdir;                    /* lost & found directory inode number */
203 char *lfname;                   /* lost & found directory name */
204 int lfmode;                     /* lost & found directory creation mode */
205
206 daddr_t n_blks;                 /* number of blocks in use */
207 daddr_t n_files;                /* number of files in use */
208
209 #define clearinode(dp)  (*(dp) = zino)
210 struct dinode zino;
211
212 /* only change i_gen if this is a VFS but not VICE fsck */
213 #ifdef VICE
214 #define zapino(x)       (*(x) = zino)
215 #else
216 #define zapino(x)       zino.di_gen = (x)->di_gen+1; (*(x) = zino)
217 #endif /* VICE */
218
219 int isconvert;                  /* converting */
220
221 #ifdef VICE
222 int nViceFiles;                 /* number of vice files seen */
223 #if     defined(AFS_SUN_ENV)
224 int iscorrupt;                  /* known to be corrupt/inconsistent */
225 #endif
226 #ifdef  AFS_SUN_ENV
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 */
231 #ifdef  AFS_SUN5_ENV
232 #define FSTYPE_MAX      8
233 char *fstype;
234                                 /* remount okay if clear */
235 char fflag;                     /* force fsck to check a mounted fs */
236 char mountedfs;                 /* checking mounted device */
237 int oflag;
238 int mflag;
239 int exitstat;
240 int pflag;
241 int fsflag;
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 */
248 #endif /* VICE */
249
250 #define setbmap(blkno)  setbit(blockmap, blkno)
251 #define testbmap(blkno) isset(blockmap, blkno)
252 #define clrbmap(blkno)  clrbit(blockmap, blkno)
253
254 #define STOP    0x01
255 #define SKIP    0x02
256 #define KEEPON  0x04
257 #define ALTERED 0x08
258 #define FOUND   0x10
259
260 #include <time.h>               /* for time() */
261 struct dinode *ginode();
262 struct bufarea *getblk();
263 ino_t allocino();
264 int findino();
265
266 /* global variables to be reset in new fork by "setup" */
267 struct bufarea *mlk_pbp;
268 ino_t mlk_startinum;
269
270 #ifdef AFS_SUN_ENV
271 int setup();
272 struct mntent *mntdup();
273 #endif
274
275 #if     defined(AFS_HPUX_ENV)
276 int pclean;
277 #endif
278
279 #ifdef  AFS_HPUX_ENV
280 char fflag;                     /* force fsck to check a mounted fs */
281 int pclean;
282 int mflag;
283 #define BLK     ((dp->di_mode & IFMT) == IFBLK)
284 #define CHR     ((dp->di_mode & IFMT) == IFCHR)
285 #define LNK     ((dp->di_mode & IFMT) == IFLNK)
286 #ifdef IC_FASTLINK
287 #define FASTLNK (LNK && (dp->di_flags & IC_FASTLINK))
288 #else
289 #define FASTLNK (0)
290 #endif
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)
295 #else
296 #define SPECIAL (BLK || CHR)
297 #endif
298 #endif /* AFS_HPUX_ENV */
299
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 */
307
308 #ifdef AFS_SUN59_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);
312 #endif