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