1*0986c204Sderaadt /* $OpenBSD: fsck.h,v 1.13 2021/01/27 05:03:23 deraadt Exp $ */ 25ff4e0c8Sdownsj /* $NetBSD: fsck.h,v 1.1 1997/06/11 11:21:47 bouyer Exp $ */ 38c424e8eSdownsj 48c424e8eSdownsj /* 55ff4e0c8Sdownsj * Copyright (c) 1997 Manuel Bouyer. 68c424e8eSdownsj * Copyright (c) 1980, 1986, 1993 78c424e8eSdownsj * The Regents of the University of California. All rights reserved. 88c424e8eSdownsj * 98c424e8eSdownsj * Redistribution and use in source and binary forms, with or without 108c424e8eSdownsj * modification, are permitted provided that the following conditions 118c424e8eSdownsj * are met: 128c424e8eSdownsj * 1. Redistributions of source code must retain the above copyright 138c424e8eSdownsj * notice, this list of conditions and the following disclaimer. 148c424e8eSdownsj * 2. Redistributions in binary form must reproduce the above copyright 158c424e8eSdownsj * notice, this list of conditions and the following disclaimer in the 168c424e8eSdownsj * documentation and/or other materials provided with the distribution. 171ef0d710Smillert * 3. Neither the name of the University nor the names of its contributors 188c424e8eSdownsj * may be used to endorse or promote products derived from this software 198c424e8eSdownsj * without specific prior written permission. 208c424e8eSdownsj * 218c424e8eSdownsj * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 228c424e8eSdownsj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 238c424e8eSdownsj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 248c424e8eSdownsj * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 258c424e8eSdownsj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 268c424e8eSdownsj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 278c424e8eSdownsj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 288c424e8eSdownsj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 298c424e8eSdownsj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 308c424e8eSdownsj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 318c424e8eSdownsj * SUCH DAMAGE. 328c424e8eSdownsj * 338c424e8eSdownsj * @(#)fsck.h 8.1 (Berkeley) 6/5/93 348c424e8eSdownsj */ 358c424e8eSdownsj 368c424e8eSdownsj #define MAXDUP 10 /* limit on dup blks (per inode) */ 378c424e8eSdownsj #define MAXBAD 10 /* limit on bad blks (per inode) */ 388c424e8eSdownsj #define MAXBUFSPACE 80*1024 /* maximum space to allocate to buffers */ 398c424e8eSdownsj #define INOBUFSIZE 128*1024 /* size of buffer to read inodes in pass1 */ 408c424e8eSdownsj 418c424e8eSdownsj #define USTATE 01 /* inode not allocated */ 428c424e8eSdownsj #define FSTATE 02 /* inode is file */ 438c424e8eSdownsj #define DSTATE 03 /* inode is directory */ 448c424e8eSdownsj #define DFOUND 04 /* directory found during descent */ 458c424e8eSdownsj #define DCLEAR 05 /* directory is to be cleared */ 468c424e8eSdownsj #define FCLEAR 06 /* file is to be cleared */ 478c424e8eSdownsj 488c424e8eSdownsj /* 498c424e8eSdownsj * buffer cache structure. 508c424e8eSdownsj */ 518c424e8eSdownsj struct bufarea { 528c424e8eSdownsj struct bufarea *b_next; /* free list queue */ 538c424e8eSdownsj struct bufarea *b_prev; /* free list queue */ 54b6d2e2d5Sderaadt daddr32_t b_bno; 558c424e8eSdownsj int b_size; 568c424e8eSdownsj int b_errs; 578c424e8eSdownsj int b_flags; 588c424e8eSdownsj union { 598c424e8eSdownsj char *b_buf; /* buffer space */ 60b6d2e2d5Sderaadt daddr32_t *b_indir; /* indirect block */ 6165348f21Sjasoni struct ext2fs *b_fs; /* super block */ 628c424e8eSdownsj struct ext2_gd *b_cgd; /* cylinder group descriptor */ 638c424e8eSdownsj struct ext2fs_dinode *b_dinode; /* inode block */ 648c424e8eSdownsj } b_un; 658c424e8eSdownsj char b_dirty; 668c424e8eSdownsj }; 678c424e8eSdownsj 688c424e8eSdownsj #define B_INUSE 1 698c424e8eSdownsj 708c424e8eSdownsj #define MINBUFS 5 /* minimum number of buffers required */ 71*0986c204Sderaadt extern struct bufarea bufhead; /* head of list of other blks in filesys */ 72*0986c204Sderaadt extern struct bufarea sblk; /* file system superblock */ 73*0986c204Sderaadt extern struct bufarea asblk; /* first alternate superblock */ 74*0986c204Sderaadt extern struct bufarea *pdirbp; /* current directory contents */ 75*0986c204Sderaadt extern struct bufarea *pbp; /* current inode block */ 76*0986c204Sderaadt extern struct bufarea *getdatablk(daddr32_t, long); 77*0986c204Sderaadt extern struct m_ext2fs sblock; 788c424e8eSdownsj 798c424e8eSdownsj #define dirty(bp) (bp)->b_dirty = 1 808c424e8eSdownsj #define initbarea(bp) \ 818c424e8eSdownsj (bp)->b_dirty = 0; \ 82b6d2e2d5Sderaadt (bp)->b_bno = (daddr32_t)-1; \ 838c424e8eSdownsj (bp)->b_flags = 0; 848c424e8eSdownsj 8565348f21Sjasoni #define sbdirty() copyback_sb(&sblk); sblk.b_dirty = 1 868c424e8eSdownsj 878c424e8eSdownsj enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE}; 888c424e8eSdownsj 898c424e8eSdownsj struct inodesc { 908c424e8eSdownsj enum fixstate id_fix; /* policy on fixing errors */ 918c424e8eSdownsj int (*id_func) /* function to be applied to blocks of inode */ 92c72b5b24Smillert (struct inodesc *); 938c424e8eSdownsj ino_t id_number; /* inode number described */ 948c424e8eSdownsj ino_t id_parent; /* for DATA nodes, their parent */ 95b6d2e2d5Sderaadt daddr32_t id_blkno; /* current block number being examined */ 968c424e8eSdownsj int id_numfrags; /* number of frags contained in block */ 978c424e8eSdownsj quad_t id_filesize; /* for DATA nodes, the size of the directory */ 988c424e8eSdownsj int id_loc; /* for DATA nodes, current location in dir */ 998c424e8eSdownsj int id_entryno; /* for DATA nodes, current entry number */ 1008c424e8eSdownsj struct ext2fs_direct *id_dirp; /* for DATA nodes, ptr to current entry */ 1018c424e8eSdownsj char *id_name; /* for DATA nodes, name to find or enter */ 1028c424e8eSdownsj char id_type; /* type of descriptor, DATA or ADDR */ 1038c424e8eSdownsj }; 1048c424e8eSdownsj /* file types */ 1058c424e8eSdownsj #define DATA 1 1068c424e8eSdownsj #define ADDR 2 1078c424e8eSdownsj 1088c424e8eSdownsj /* 1098c424e8eSdownsj * Linked list of duplicate blocks. 1108c424e8eSdownsj * 1118c424e8eSdownsj * The list is composed of two parts. The first part of the 1128c424e8eSdownsj * list (from duplist through the node pointed to by muldup) 1138c424e8eSdownsj * contains a single copy of each duplicate block that has been 1148c424e8eSdownsj * found. The second part of the list (from muldup to the end) 1158c424e8eSdownsj * contains duplicate blocks that have been found more than once. 1168c424e8eSdownsj * To check if a block has been found as a duplicate it is only 1178c424e8eSdownsj * necessary to search from duplist through muldup. To find the 1188c424e8eSdownsj * total number of times that a block has been found as a duplicate 119ed5470abSdavid * the entire list must be searched for occurrences of the block 1208c424e8eSdownsj * in question. The following diagram shows a sample list where 1218c424e8eSdownsj * w (found twice), x (found once), y (found three times), and z 1228c424e8eSdownsj * (found once) are duplicate block numbers: 1238c424e8eSdownsj * 1248c424e8eSdownsj * w -> y -> x -> z -> y -> w -> y 1258c424e8eSdownsj * ^ ^ 1268c424e8eSdownsj * | | 1278c424e8eSdownsj * duplist muldup 1288c424e8eSdownsj */ 1298c424e8eSdownsj struct dups { 1308c424e8eSdownsj struct dups *next; 131b6d2e2d5Sderaadt daddr32_t dup; 1328c424e8eSdownsj }; 133*0986c204Sderaadt extern struct dups *duplist; /* head of dup list */ 134*0986c204Sderaadt extern struct dups *muldup; /* end of unique duplicate dup block numbers */ 1358c424e8eSdownsj 1368c424e8eSdownsj /* 1378c424e8eSdownsj * Linked list of inodes with zero link counts. 1388c424e8eSdownsj */ 1398c424e8eSdownsj struct zlncnt { 1408c424e8eSdownsj struct zlncnt *next; 1418c424e8eSdownsj ino_t zlncnt; 1428c424e8eSdownsj }; 143*0986c204Sderaadt extern struct zlncnt *zlnhead; /* head of zero link count list */ 1448c424e8eSdownsj 1458c424e8eSdownsj /* 1468c424e8eSdownsj * Inode cache data structures. 1478c424e8eSdownsj */ 148*0986c204Sderaadt extern struct inoinfo { 1498c424e8eSdownsj struct inoinfo *i_nexthash; /* next entry in hash chain */ 1508c424e8eSdownsj struct inoinfo *i_child, *i_sibling, *i_parentp; 1518c424e8eSdownsj ino_t i_number; /* inode number of this entry */ 1528c424e8eSdownsj ino_t i_parent; /* inode number of parent */ 1538c424e8eSdownsj ino_t i_dotdot; /* inode number of `..' */ 154935730fbSniallo u_int64_t i_isize; /* size of inode */ 1558c424e8eSdownsj u_int i_numblks; /* size of block array in bytes */ 156b6d2e2d5Sderaadt daddr32_t i_blks[1]; /* actually longer */ 1578c424e8eSdownsj } **inphead, **inpsort; 158*0986c204Sderaadt extern long numdirs, listmax, inplast; 1598c424e8eSdownsj 160*0986c204Sderaadt extern long secsize; /* actual disk sector size */ 161*0986c204Sderaadt extern char nflag; /* assume a no response */ 162*0986c204Sderaadt extern char yflag; /* assume a yes response */ 163*0986c204Sderaadt extern int bflag; /* location of alternate super block */ 164*0986c204Sderaadt extern int debug; /* output debugging info */ 165*0986c204Sderaadt extern int preen; /* just fix normal inconsistencies */ 166*0986c204Sderaadt extern char havesb; /* superblock has been read */ 167*0986c204Sderaadt extern char skipclean; /* skip clean file systems if preening */ 168*0986c204Sderaadt extern int fsmodified; /* 1 => write done to file system */ 169*0986c204Sderaadt extern int fsreadfd; /* file descriptor for reading file system */ 170*0986c204Sderaadt extern int fswritefd; /* file descriptor for writing file system */ 171*0986c204Sderaadt extern int rerun; /* rerun fsck. Only used in non-preen mode */ 1728c424e8eSdownsj 173*0986c204Sderaadt extern daddr32_t maxfsblock; /* number of blocks in the file system */ 174*0986c204Sderaadt extern char *blockmap; /* ptr to primary blk allocation map */ 175*0986c204Sderaadt extern ino_t maxino; /* number of inodes in file system */ 176*0986c204Sderaadt extern ino_t lastino; /* last inode in use */ 177*0986c204Sderaadt extern char *statemap; /* ptr to inode state table */ 178*0986c204Sderaadt extern u_char *typemap; /* ptr to inode type table */ 179*0986c204Sderaadt extern int16_t *lncntp; /* ptr to link count table */ 1808c424e8eSdownsj 181*0986c204Sderaadt extern ino_t lfdir; /* lost & found directory inode number */ 182*0986c204Sderaadt extern char *lfname; /* lost & found directory name */ 183*0986c204Sderaadt extern int lfmode; /* lost & found directory creation mode */ 1848c424e8eSdownsj 185*0986c204Sderaadt extern daddr32_t n_blks; /* number of blocks in use */ 186*0986c204Sderaadt extern daddr32_t n_files; /* number of files in use */ 1878c424e8eSdownsj 1888c424e8eSdownsj #define clearinode(dp) (*(dp) = zino) 189*0986c204Sderaadt extern struct ext2fs_dinode zino; 1908c424e8eSdownsj 1918c424e8eSdownsj #define setbmap(blkno) setbit(blockmap, blkno) 1928c424e8eSdownsj #define testbmap(blkno) isset(blockmap, blkno) 1938c424e8eSdownsj #define clrbmap(blkno) clrbit(blockmap, blkno) 1948c424e8eSdownsj 1958c424e8eSdownsj #define STOP 0x01 1968c424e8eSdownsj #define SKIP 0x02 1978c424e8eSdownsj #define KEEPON 0x04 1988c424e8eSdownsj #define ALTERED 0x08 1998c424e8eSdownsj #define FOUND 0x10 2008c424e8eSdownsj 201c72b5b24Smillert struct ext2fs_dinode *ginode(ino_t); 202c72b5b24Smillert struct inoinfo *getinoinfo(ino_t); 203b6d2e2d5Sderaadt void getblk(struct bufarea *, daddr32_t, long); 204c72b5b24Smillert ino_t allocino(ino_t, int); 205c72b5b24Smillert void copyback_sb(struct bufarea*); 206b6d2e2d5Sderaadt daddr32_t cgoverhead(int); /* overhead per cg */ 207