8483e640b255c6786005d203a881bcdb340ce6ed
[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 #ifdef  AFS_OSF_ENV
118 /*
119  * struct direct -> struct dirent
120 */
121 #define direct  dirent
122 #endif /* AFS_OSF_ENV */
123
124 enum fixstate { DONTKNOW, NOFIX, FIX };
125
126 struct inodesc {
127     enum fixstate id_fix;       /* policy on fixing errors */
128     int (*id_func) ();          /* function to be applied to blocks of inode */
129     ino_t id_number;            /* inode number described */
130     ino_t id_parent;            /* for DATA nodes, their parent */
131     daddr_t id_blkno;           /* current block number being examined */
132     int id_numfrags;            /* number of frags contained in block */
133     OFF_T id_filesize;          /* for DATA nodes, the size of the directory */
134     int id_loc;                 /* for DATA nodes, current location in dir */
135     int id_entryno;             /* for DATA nodes, current entry number */
136     struct direct *id_dirp;     /* for DATA nodes, ptr to current entry */
137     char *id_name;              /* for DATA nodes, name to find or enter */
138     char id_type;               /* type of descriptor, DATA or ADDR */
139 };
140 /* file types */
141 #define DATA    1
142 #define ADDR    2
143
144 /*
145  * Linked list of duplicate blocks.
146  *
147  * The list is composed of two parts. The first part of the
148  * list (from duplist through the node pointed to by muldup)
149  * contains a single copy of each duplicate block that has been
150  * found. The second part of the list (from muldup to the end)
151  * contains duplicate blocks that have been found more than once.
152  * To check if a block has been found as a duplicate it is only
153  * necessary to search from duplist through muldup. To find the
154  * total number of times that a block has been found as a duplicate
155  * the entire list must be searched for occurences of the block
156  * in question. The following diagram shows a sample list where
157  * w (found twice), x (found once), y (found three times), and z
158  * (found once) are duplicate block numbers:
159  *
160  *    w -> y -> x -> z -> y -> w -> y
161  *    ^              ^
162  *    |              |
163  * duplist        muldup
164  */
165 struct dups {
166     struct dups *next;
167     daddr_t dup;
168 };
169 struct dups *duplist;           /* head of dup list */
170 struct dups *muldup;            /* end of unique duplicate dup block numbers */
171
172 /*
173  * Linked list of inodes with zero link counts.
174  */
175 struct zlncnt {
176     struct zlncnt *next;
177     ino_t zlncnt;
178 };
179 struct zlncnt *zlnhead;         /* head of zero link count list */
180
181 char *devname;                  /* name of device being checked */
182 long dev_bsize;                 /* computed value of DEV_BSIZE */
183 long secsize;                   /* actual disk sector size */
184 char nflag;                     /* assume a no response */
185 char yflag;                     /* assume a yes response */
186 int bflag;                      /* location of alternate super block */
187 int qflag;                      /* less verbose flag */
188 int debug;                      /* output debugging info */
189 int cvtflag;                    /* convert to old file system format */
190 char preen;                     /* just fix normal inconsistencies */
191
192 char hotroot;                   /* checking root device */
193 char havesb;                    /* superblock has been read */
194 int fsmodified;                 /* 1 => write done to file system */
195 int fsreadfd;                   /* file descriptor for reading file system */
196 int fswritefd;                  /* file descriptor for writing file system */
197
198 daddr_t maxfsblock;             /* number of blocks in the file system */
199 char *blockmap;                 /* ptr to primary blk allocation map */
200 ino_t maxino;                   /* number of inodes in file system */
201 ino_t lastino;                  /* last inode in use */
202 char *statemap;                 /* ptr to inode state table */
203 short *lncntp;                  /* ptr to link count table */
204
205 char pathname[BUFSIZ];          /* current pathname */
206 char *pathp;                    /* ptr to current position in pathname */
207 char *endpathname;              /* ptr to current end of pathname */
208
209 ino_t lfdir;                    /* lost & found directory inode number */
210 char *lfname;                   /* lost & found directory name */
211 int lfmode;                     /* lost & found directory creation mode */
212
213 daddr_t n_blks;                 /* number of blocks in use */
214 daddr_t n_files;                /* number of files in use */
215
216 #define clearinode(dp)  (*(dp) = zino)
217 struct dinode zino;
218
219 /* only change i_gen if this is a VFS but not VICE fsck */
220 #ifdef VICE
221 #define zapino(x)       (*(x) = zino)
222 #else
223 #define zapino(x)       zino.di_gen = (x)->di_gen+1; (*(x) = zino)
224 #endif /* VICE */
225
226 int isconvert;                  /* converting */
227
228 #ifdef VICE
229 int nViceFiles;                 /* number of vice files seen */
230 #if     defined(AFS_SUN_ENV)
231 int iscorrupt;                  /* known to be corrupt/inconsistent */
232 #endif
233 #ifdef  AFS_SUN_ENV
234 char fixstate;                  /* is FsSTATE to be fixed */
235 char rebflg;                    /* needs reboot if set */
236 int isdirty;                    /* 1 => write pending to file system */
237 #endif /* AFS_SUN_ENV */
238 #ifdef  AFS_SUN5_ENV
239 #define FSTYPE_MAX      8
240 char *fstype;
241                                 /* remount okay if clear */
242 char fflag;                     /* force fsck to check a mounted fs */
243 char mountedfs;                 /* checking mounted device */
244 int oflag;
245 int mflag;
246 int exitstat;
247 int pflag;
248 int fsflag;
249 int rflag;                      /* check raw file systems */
250 #include <sys/sysmacros.h>
251 FILE *logfile;                  /* additional place for log message, for non-root file systems */
252 #else /* AFS_SUN5_ENV */
253 #ifdef  AFS_OSF_ENV
254 FILE *logfile;                  /* additional place for log message, for non-root file systems */
255 char fflag;                     /* force fsck to check a mounted fs */
256 #else /* AFS_OSF_ENV */
257 struct _iobuf *logfile;         /* additional place for log message, for non-root file systems */
258 #endif /* AFS_OSF_ENV */
259 #endif /* AFS_SUN5_ENV */
260 #endif /* VICE */
261
262 #define setbmap(blkno)  setbit(blockmap, blkno)
263 #define testbmap(blkno) isset(blockmap, blkno)
264 #define clrbmap(blkno)  clrbit(blockmap, blkno)
265
266 #define STOP    0x01
267 #define SKIP    0x02
268 #define KEEPON  0x04
269 #define ALTERED 0x08
270 #define FOUND   0x10
271
272 #include <time.h>               /* for time() */
273 struct dinode *ginode();
274 struct bufarea *getblk();
275 ino_t allocino();
276 int findino();
277
278 /* global variables to be reset in new fork by "setup" */
279 struct bufarea *mlk_pbp;
280 ino_t mlk_startinum;
281
282 #ifdef AFS_SUN_ENV
283 int setup();
284 struct mntent *mntdup();
285 #endif
286
287 #if     defined(AFS_HPUX_ENV)
288 int pclean;
289 #endif
290
291 #ifdef  AFS_HPUX_ENV
292 char fflag;                     /* force fsck to check a mounted fs */
293 int pclean;
294 int mflag;
295 #define BLK     ((dp->di_mode & IFMT) == IFBLK)
296 #define CHR     ((dp->di_mode & IFMT) == IFCHR)
297 #define LNK     ((dp->di_mode & IFMT) == IFLNK)
298 #ifdef IC_FASTLINK
299 #define FASTLNK (LNK && (dp->di_flags & IC_FASTLINK))
300 #else
301 #define FASTLNK (0)
302 #endif
303 #if defined(ACLS) && defined(AFS_HPUX_ENV)
304 daddr_t n_cont;                 /* number of continuation inodes seen */
305 #define CONT    ((dp->di_mode & IFMT) == IFCONT)        /* continuation inode */
306 #define SPECIAL (BLK || CHR || CONT)
307 #else
308 #define SPECIAL (BLK || CHR)
309 #endif
310 #endif /* AFS_HPUX_ENV */
311
312 #if defined(AFS_HPUX110_ENV)
313 /* For backward compatibility */
314 #define cg_link         cg_unused[0]
315 #define cg_rlink        cg_unused[1]
316 #define fs_link         fs_unused[0]
317 #define fs_rlink        fs_unused[1]
318 #endif /* AFS_HPUX110_ENV */
319
320 #ifdef AFS_SUN59_ENV
321 /* diskaddr_t is longlong */
322 int bread(int fd, char *buf, diskaddr_t blk, long size);
323 int bwrite(int fd, char *buf,  diskaddr_t blk, long size);
324 #endif