add firewall check for bad entry in state map
[unix-history] / usr / src / sbin / fsck / fsck.h
CommitLineData
76797561
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 *
6 * @(#)fsck.h 5.1 (Berkeley) %G%
7 */
e12c24e6
KM
8
9#define MAXDUP 10 /* limit on dup blks (per inode) */
10#define MAXBAD 10 /* limit on bad blks (per inode) */
e12c24e6
KM
11
12typedef int (*SIG_TYP)();
13
14#ifndef BUFSIZ
15#define BUFSIZ 1024
16#endif
17
993a756c
KM
18#define USTATE 01 /* inode not allocated */
19#define FSTATE 02 /* inode is file */
20#define DSTATE 03 /* inode is directory */
21#define DFOUND 04 /* directory found during descent */
22#define DCLEAR 05 /* directory is to be cleared */
23#define FCLEAR 06 /* file is to be cleared */
e12c24e6
KM
24
25typedef struct dinode DINODE;
26typedef struct direct DIRECT;
27
7718c0e6
KM
28#define ALLOC(dip) (((dip)->di_mode & IFMT) != 0)
29#define DIRCT(dip) (((dip)->di_mode & IFMT) == IFDIR)
30#define SPECIAL(dip) \
31 (((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR)
32
33#define MAXNINDIR (MAXBSIZE / sizeof (daddr_t))
34#define MAXINOPB (MAXBSIZE / sizeof (struct dinode))
35#define SPERB (MAXBSIZE / sizeof(short))
e12c24e6
KM
36
37struct bufarea {
38 struct bufarea *b_next; /* must be first */
39 daddr_t b_bno;
40 int b_size;
49505034 41 int b_errs;
e12c24e6
KM
42 union {
43 char b_buf[MAXBSIZE]; /* buffer space */
44 short b_lnks[SPERB]; /* link counts */
45 daddr_t b_indir[MAXNINDIR]; /* indirect block */
46 struct fs b_fs; /* super block */
47 struct cg b_cg; /* cylinder group */
48 struct dinode b_dinode[MAXINOPB]; /* inode block */
49 } b_un;
50 char b_dirty;
51};
52
53typedef struct bufarea BUFAREA;
54
55BUFAREA inoblk; /* inode blocks */
56BUFAREA fileblk; /* other blks in filesys */
57BUFAREA sblk; /* file system superblock */
58BUFAREA cgblk; /* cylinder group blocks */
59
60#define initbarea(x) (x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1
61#define dirty(x) (x)->b_dirty = 1
62#define inodirty() inoblk.b_dirty = 1
63#define sbdirty() sblk.b_dirty = 1
64#define cgdirty() cgblk.b_dirty = 1
65
66#define dirblk fileblk.b_un
67#define sblock sblk.b_un.b_fs
68#define cgrp cgblk.b_un.b_cg
69
70struct filecntl {
71 int rfdes;
72 int wfdes;
73 int mod;
74} dfile; /* file descriptors for filesys */
75
7718c0e6
KM
76enum fixstate {DONTKNOW, NOFIX, FIX};
77
e12c24e6 78struct inodesc {
7718c0e6 79 enum fixstate id_fix; /* policy on fixing errors */
e12c24e6
KM
80 int (*id_func)(); /* function to be applied to blocks of inode */
81 ino_t id_number; /* inode number described */
82 ino_t id_parent; /* for DATA nodes, their parent */
83 daddr_t id_blkno; /* current block number being examined */
84 int id_numfrags; /* number of frags contained in block */
85 long id_filesize; /* for DATA nodes, the size of the directory */
86 int id_loc; /* for DATA nodes, current location in dir */
87 int id_entryno; /* for DATA nodes, current entry number */
7718c0e6
KM
88 DIRECT *id_dirp; /* for DATA nodes, ptr to current entry */
89 char *id_name; /* for DATA nodes, name to find or enter */
90 char id_type; /* type of descriptor, DATA or ADDR */
e12c24e6
KM
91};
92/* file types */
93#define DATA 1
94#define ADDR 2
95
62e6c152 96/*
82dc9a9e
KM
97 * Linked list of duplicate blocks.
98 *
99 * The list is composed of two parts. The first part of the
100 * list (from duplist through the node pointed to by muldup)
101 * contains a single copy of each duplicate block that has been
102 * found. The second part of the list (from muldup to the end)
103 * contains duplicate blocks that have been found more than once.
104 * To check if a block has been found as a duplicate it is only
105 * necessary to search from duplist through muldup. To find the
106 * total number of times that a block has been found as a duplicate
107 * the entire list must be searched for occurences of the block
108 * in question. The following diagram shows a sample list where
109 * w (found twice), x (found once), y (found three times), and z
110 * (found once) are duplicate block numbers:
111 *
112 * w -> y -> x -> z -> y -> w -> y
113 * ^ ^
114 * | |
115 * duplist muldup
62e6c152
KM
116 */
117struct dups {
118 struct dups *next;
119 daddr_t dup;
120};
121struct dups *duplist; /* head of dup list */
122struct dups *muldup; /* end of unique duplicate dup block numbers */
e12c24e6 123
82dc9a9e
KM
124/*
125 * Linked list of inodes with zero link counts.
126 */
127struct zlncnt {
128 struct zlncnt *next;
129 ino_t zlncnt;
130};
131struct zlncnt *zlnhead; /* head of zero link count list */
e12c24e6
KM
132
133char rawflg;
134char *devname;
135char nflag; /* assume a no response */
136char yflag; /* assume a yes response */
137int bflag; /* location of alternate super block */
138int debug; /* output debugging info */
139char preen; /* just fix normal inconsistencies */
e12c24e6 140char hotroot; /* checking root device */
e12c24e6
KM
141
142char *blockmap; /* ptr to primary blk allocation map */
e12c24e6
KM
143char *statemap; /* ptr to inode state table */
144short *lncntp; /* ptr to link count table */
145
e12c24e6
KM
146char pathname[BUFSIZ]; /* current pathname */
147char *pathp; /* pointer to pathname position */
148char *endpathname;
149
7718c0e6 150daddr_t fmax; /* number of blocks in the volume */
e12c24e6
KM
151ino_t imax; /* number of inodes */
152ino_t lastino; /* hiwater mark of inodes */
7718c0e6
KM
153ino_t lfdir; /* lost & found directory inode number */
154char *lfname; /* lost & found directory name */
e12c24e6
KM
155
156off_t maxblk; /* largest logical blk in file */
157off_t bmapsz; /* num chars in blockmap */
158
e12c24e6
KM
159daddr_t n_blks; /* number of blocks used */
160daddr_t n_files; /* number of files seen */
e12c24e6
KM
161
162#define zapino(x) (*(x) = zino)
163struct dinode zino;
164
165#define setbmap(x) setbit(blockmap, x)
166#define getbmap(x) isset(blockmap, x)
167#define clrbmap(x) clrbit(blockmap, x)
168
e12c24e6
KM
169#define ALTERED 010
170#define KEEPON 04
171#define SKIP 02
172#define STOP 01
173
174time_t time();
175DINODE *ginode();
176BUFAREA *getblk();
177int findino();