1 /* $NetBSD: fsck.h,v 1.15 2005/06/27 02:48:28 christos 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /* 40 * Copyright (c) 1980, 1986, 1993 41 * The Regents of the University of California. All rights reserved. 42 * 43 * Redistribution and use in source and binary forms, with or without 44 * modification, are permitted provided that the following conditions 45 * are met: 46 * 1. Redistributions of source code must retain the above copyright 47 * notice, this list of conditions and the following disclaimer. 48 * 2. Redistributions in binary form must reproduce the above copyright 49 * notice, this list of conditions and the following disclaimer in the 50 * documentation and/or other materials provided with the distribution. 51 * 3. Neither the name of the University nor the names of its contributors 52 * may be used to endorse or promote products derived from this software 53 * without specific prior written permission. 54 * 55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 65 * SUCH DAMAGE. 66 * 67 * @(#)fsck.h 8.1 (Berkeley) 6/5/93 68 */ 69 70 #ifdef KS_DEBUG 71 #include <err.h> 72 #define debug_printf warn 73 #else 74 #define debug_printf 75 #endif 76 77 #define MAXDUP 10 /* limit on dup blks (per inode) */ 78 #define MAXBAD 10 /* limit on bad blks (per inode) */ 79 #define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ 80 #define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ 81 82 #ifndef BUFSIZ 83 #define BUFSIZ 1024 84 #endif 85 86 #define USTATE 01 /* inode not allocated */ 87 #define FSTATE 02 /* inode is file */ 88 #define DSTATE 03 /* inode is directory */ 89 #define DFOUND 04 /* directory found during descent */ 90 #define DCLEAR 05 /* directory is to be cleared */ 91 #define FCLEAR 06 /* file is to be cleared */ 92 93 /* 94 * buffer cache structure. 95 */ 96 struct ubufarea { 97 struct ubufarea *b_next; /* free list queue */ 98 struct ubufarea *b_prev; /* free list queue */ 99 daddr_t b_bno; 100 int b_size; 101 int b_errs; 102 int b_flags; 103 union { 104 char *b_buf; /* buffer space */ 105 /* XXX ondisk32 */ 106 int32_t *b_indir; /* indirect block */ 107 struct lfs *b_fs; /* super block */ 108 struct cg *b_cg;/* cylinder group */ 109 struct ufs1_dinode *b_dinode; /* inode block */ 110 } b_un; 111 char b_dirty; 112 }; 113 #define B_INUSE 1 114 115 #define MINBUFS 5 /* minimum number of buffers required */ 116 117 #define dirty(bp) (bp)->b_dirty = 1 118 #define initbarea(bp) \ 119 (bp)->b_dirty = 0; \ 120 (bp)->b_bno = (daddr_t)-1; \ 121 (bp)->b_flags = 0; 122 123 enum fixstate { 124 DONTKNOW, NOFIX, FIX, IGNORE 125 }; 126 127 struct inodesc { 128 enum fixstate id_fix; /* policy on fixing errors */ 129 int (*id_func) (struct inodesc *); /* function to be applied to 130 * blocks of inode */ 131 ino_t id_number; /* inode number described */ 132 ino_t id_parent; /* for DATA nodes, their parent */ 133 daddr_t id_blkno; /* current block number being examined */ 134 daddr_t id_lblkno; /* current logical block number */ 135 int id_numfrags; /* number of frags contained in block */ 136 quad_t id_filesize; /* for DATA nodes, the size of the directory */ 137 int id_loc; /* for DATA nodes, current location in dir */ 138 int id_entryno; /* for DATA nodes, current entry number */ 139 struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 140 const char *id_name; /* for DATA nodes, name to find or enter */ 141 char id_type; /* type of descriptor, DATA or ADDR */ 142 }; 143 /* file types */ 144 #define DATA 1 145 #define ADDR 2 146 147 /* 148 * Linked list of duplicate blocks. 149 * 150 * The list is composed of two parts. The first part of the 151 * list (from duplist through the node pointed to by muldup) 152 * contains a single copy of each duplicate block that has been 153 * found. The second part of the list (from muldup to the end) 154 * contains duplicate blocks that have been found more than once. 155 * To check if a block has been found as a duplicate it is only 156 * necessary to search from duplist through muldup. To find the 157 * total number of times that a block has been found as a duplicate 158 * the entire list must be searched for occurrences of the block 159 * in question. The following diagram shows a sample list where 160 * w (found twice), x (found once), y (found three times), and z 161 * (found once) are duplicate block numbers: 162 * 163 * w -> y -> x -> z -> y -> w -> y 164 * ^ ^ 165 * | | 166 * duplist muldup 167 */ 168 struct dups { 169 struct dups *next; 170 daddr_t dup; 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 /* 180 * Inode cache data structures. 181 */ 182 struct inoinfo { 183 struct inoinfo *i_nexthash; /* next entry in hash chain */ 184 struct inoinfo *i_child, *i_sibling, *i_parentp; 185 ino_t i_number; /* inode number of this entry */ 186 ino_t i_parent; /* inode number of parent */ 187 ino_t i_dotdot; /* inode number of `..' */ 188 size_t i_isize; /* size of inode */ 189 u_int i_numblks; /* size of block array in bytes */ 190 /* XXX ondisk32 */ 191 int32_t i_blks[1]; /* actually longer */ 192 } **inphead, **inpsort; 193 194 #ifndef VERBOSE_BLOCKMAP 195 #define setbmap(blkno) setbit(blockmap, blkno) 196 #define testbmap(blkno) isset(blockmap, blkno) 197 #define clrbmap(blkno) clrbit(blockmap, blkno) 198 #else 199 #define setbmap(blkno,ino) if(blkno > maxfsblock)raise(1); else blockmap[blkno] = ino 200 #define testbmap(blkno) blockmap[blkno] 201 #define clrbmap(blkno) blockmap[blkno] = 0 202 #endif 203 204 #define STOP 0x01 205 #define SKIP 0x02 206 #define KEEPON 0x04 207 #define ALTERED 0x08 208 #define FOUND 0x10 209 210 ino_t allocino(ino_t, int); 211 int ino_to_fsba(struct lfs *, ino_t); 212 struct ufs1_dinode *ginode(ino_t); 213 struct inoinfo *getinoinfo(ino_t); 214 daddr_t lfs_ino_daddr(ino_t); 215 void clearinode(ino_t); 216 void reset_maxino(ino_t); 217 218 #include "fsck_vars.h" 219