xref: /netbsd/sbin/fsck_lfs/fsck.h (revision 913768d6)
1 /* $NetBSD: fsck.h,v 1.27 2020/04/03 19:36:33 joerg Exp $	 */
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Konrad E. Schroder <perseant@hhhh.org>.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1980, 1986, 1993
34  *	The Regents of the University of California.  All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. Neither the name of the University nor the names of its contributors
45  *    may be used to endorse or promote products derived from this software
46  *    without specific prior written permission.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  *
60  *	@(#)fsck.h	8.1 (Berkeley) 6/5/93
61  */
62 
63 #ifdef KS_DEBUG
64 #include <err.h>
65 #define debug_printf warn
66 #else
67 #define debug_printf
68 #endif
69 
70 #define	MAXDUP		10	/* limit on dup blks (per inode) */
71 #define	MAXBAD		10	/* limit on bad blks (per inode) */
72 
73 #ifndef BUFSIZ
74 #define BUFSIZ 1024
75 #endif
76 
77 #define	USTATE	01		/* inode not allocated */
78 #define	FSTATE	02		/* inode is file */
79 #define	DSTATE	03		/* inode is directory */
80 #define	DFOUND	04		/* directory found during descent */
81 #define	DCLEAR	05		/* directory is to be cleared */
82 #define	FCLEAR	06		/* file is to be cleared */
83 
84 #define EEXIT	8		/* Standard error exit */
85 
86 enum fixstate {
87 	DONTKNOW, NOFIX, FIX, IGNORE
88 };
89 
90 struct inodesc {
91 	enum fixstate id_fix;	/* policy on fixing errors */
92 	int (*id_func) (struct inodesc *);	/* function to be applied to
93 						 * blocks of inode */
94 	ino_t id_number;	/* inode number described */
95 	ino_t id_parent;	/* for DATA nodes, their parent */
96 	daddr_t id_blkno;	/* current block number being examined */
97 	daddr_t id_lblkno;	/* current logical block number */
98 	int id_numfrags;	/* number of frags contained in block */
99 	off_t id_filesize;	/* for DATA nodes, the size of the directory */
100 	int id_loc;		/* for DATA nodes, current location in dir */
101 	long long id_entryno;	/* for DATA nodes, current entry number */
102 	LFS_DIRHEADER *id_dirp;	/* for DATA nodes, ptr to current entry */
103 	const char *id_name;	/* for DATA nodes, name to find or enter */
104 	char id_type;		/* type of descriptor, DATA or ADDR */
105 };
106 /* file types */
107 #define	DATA	1
108 #define	ADDR	2
109 
110 /*
111  * Linked list of duplicate blocks.
112  *
113  * The list is composed of two parts. The first part of the
114  * list (from duplist through the node pointed to by muldup)
115  * contains a single copy of each duplicate block that has been
116  * found. The second part of the list (from muldup to the end)
117  * contains duplicate blocks that have been found more than once.
118  * To check if a block has been found as a duplicate it is only
119  * necessary to search from duplist through muldup. To find the
120  * total number of times that a block has been found as a duplicate
121  * the entire list must be searched for occurrences of the block
122  * in question. The following diagram shows a sample list where
123  * w (found twice), x (found once), y (found three times), and z
124  * (found once) are duplicate block numbers:
125  *
126  *    w -> y -> x -> z -> y -> w -> y
127  *    ^		     ^
128  *    |		     |
129  * duplist	  muldup
130  */
131 struct dups {
132 	struct dups *next;
133 	daddr_t dup;
134 };
135 /*
136  * Linked list of inodes with zero link counts.
137  */
138 struct zlncnt {
139 	struct zlncnt *next;
140 	ino_t zlncnt;
141 };
142 /*
143  * Inode cache data structures.
144  */
145 extern struct inoinfo {
146 	struct inoinfo *i_nexthash;	/* next entry in hash chain */
147 	struct inoinfo *i_child, *i_sibling, *i_parentp;
148 	ino_t i_number;		/* inode number of this entry */
149 	ino_t i_parent;		/* inode number of parent */
150 	ino_t i_dotdot;		/* inode number of `..' */
151 	size_t i_isize;		/* size of inode */
152 	u_int i_numblks;	/* size of block array in bytes */
153 	daddr_t i_blks[1];	/* actually longer */
154 }     **inphead, **inpsort;
155 
156 #ifndef VERBOSE_BLOCKMAP
157 #define	setbmap(blkno)	setbit(blockmap, blkno)
158 #define	testbmap(blkno)	isset(blockmap, blkno)
159 #define	clrbmap(blkno)	clrbit(blockmap, blkno)
160 #else
161 #define	setbmap(blkno,ino)	if(blkno > maxfsblock)raise(1); else blockmap[blkno] = ino
162 #define	testbmap(blkno)		blockmap[blkno]
163 #define	clrbmap(blkno)		blockmap[blkno] = 0
164 #endif
165 
166 extern int	Uflag;			/* resolve user names */
167 
168 #define	STOP	0x01
169 #define	SKIP	0x02
170 #define	KEEPON	0x04
171 #define	ALTERED	0x08
172 #define	FOUND	0x10
173 
174 ino_t allocino(ino_t, int);
175 int ino_to_fsba(struct lfs *, ino_t);
176 union lfs_dinode *ginode(ino_t);
177 struct inoinfo *getinoinfo(ino_t);
178 daddr_t lfs_ino_daddr(ino_t);
179 void clearinode(ino_t);
180 void reset_maxino(ino_t);
181 
182 #include "fsck_vars.h"
183