18fae3551SRodney W. Grimes /* 21c85e6a3SKirk McKusick * Copyright (c) 2002 Networks Associates Technology, Inc. 31c85e6a3SKirk McKusick * All rights reserved. 41c85e6a3SKirk McKusick * 51c85e6a3SKirk McKusick * This software was developed for the FreeBSD Project by Marshall 61c85e6a3SKirk McKusick * Kirk McKusick and Network Associates Laboratories, the Security 71c85e6a3SKirk McKusick * Research Division of Network Associates, Inc. under DARPA/SPAWAR 81c85e6a3SKirk McKusick * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS 9363c1852SKirk McKusick * research program. 101c85e6a3SKirk McKusick * 1160c97629SRobert Watson * Redistribution and use in source and binary forms, with or without 1260c97629SRobert Watson * modification, are permitted provided that the following conditions 1360c97629SRobert Watson * are met: 1460c97629SRobert Watson * 1. Redistributions of source code must retain the above copyright 1560c97629SRobert Watson * notice, this list of conditions and the following disclaimer. 1660c97629SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 1760c97629SRobert Watson * notice, this list of conditions and the following disclaimer in the 1860c97629SRobert Watson * documentation and/or other materials provided with the distribution. 1960c97629SRobert Watson * 2060c97629SRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2160c97629SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2260c97629SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2360c97629SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2460c97629SRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2560c97629SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2660c97629SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2760c97629SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2860c97629SRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2960c97629SRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3060c97629SRobert Watson * SUCH DAMAGE. 3160c97629SRobert Watson * 328fae3551SRodney W. Grimes * Copyright (c) 1980, 1986, 1993 338fae3551SRodney W. Grimes * The Regents of the University of California. All rights reserved. 348fae3551SRodney W. Grimes * 358fae3551SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 368fae3551SRodney W. Grimes * modification, are permitted provided that the following conditions 378fae3551SRodney W. Grimes * are met: 388fae3551SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 398fae3551SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 408fae3551SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 418fae3551SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 428fae3551SRodney W. Grimes * documentation and/or other materials provided with the distribution. 438fae3551SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 448fae3551SRodney W. Grimes * may be used to endorse or promote products derived from this software 458fae3551SRodney W. Grimes * without specific prior written permission. 468fae3551SRodney W. Grimes * 478fae3551SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 488fae3551SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 498fae3551SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 508fae3551SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 518fae3551SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 528fae3551SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 538fae3551SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 548fae3551SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 558fae3551SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 568fae3551SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 578fae3551SRodney W. Grimes * SUCH DAMAGE. 588fae3551SRodney W. Grimes * 59780a5c1eSPeter Wemm * @(#)fsck.h 8.4 (Berkeley) 5/9/95 6069205369SPeter Wemm * $FreeBSD$ 618fae3551SRodney W. Grimes */ 628fae3551SRodney W. Grimes 63d00690aeSPawel Jakub Dawidek #ifndef _FSCK_H_ 64d00690aeSPawel Jakub Dawidek #define _FSCK_H_ 65d00690aeSPawel Jakub Dawidek 66780a5c1eSPeter Wemm #include <unistd.h> 67780a5c1eSPeter Wemm #include <stdlib.h> 68780a5c1eSPeter Wemm #include <stdio.h> 69780a5c1eSPeter Wemm 70*2ec5c914SKirk McKusick #include <sys/queue.h> 71*2ec5c914SKirk McKusick 728fae3551SRodney W. Grimes #define MAXDUP 10 /* limit on dup blks (per inode) */ 738fae3551SRodney W. Grimes #define MAXBAD 10 /* limit on bad blks (per inode) */ 74*2ec5c914SKirk McKusick #define MINBUFS 10 /* minimum number of buffers required */ 75*2ec5c914SKirk McKusick #define MAXBUFS 40 /* maximum space to allocate to buffers */ 76*2ec5c914SKirk McKusick #define INOBUFSIZE 64*1024 /* size of buffer to read inodes in pass1 */ 778fae3551SRodney W. Grimes 781c85e6a3SKirk McKusick union dinode { 791c85e6a3SKirk McKusick struct ufs1_dinode dp1; 801c85e6a3SKirk McKusick struct ufs2_dinode dp2; 811c85e6a3SKirk McKusick }; 821c85e6a3SKirk McKusick #define DIP(dp, field) \ 831c85e6a3SKirk McKusick ((sblock.fs_magic == FS_UFS1_MAGIC) ? \ 841c85e6a3SKirk McKusick (dp)->dp1.field : (dp)->dp2.field) 851c85e6a3SKirk McKusick 86c3b2344bSScott Long #define DIP_SET(dp, field, val) do { \ 87c3b2344bSScott Long if (sblock.fs_magic == FS_UFS1_MAGIC) \ 88c3b2344bSScott Long (dp)->dp1.field = (val); \ 89c3b2344bSScott Long else \ 90c3b2344bSScott Long (dp)->dp2.field = (val); \ 91c3b2344bSScott Long } while (0) 92c3b2344bSScott Long 93d33e92f9SJulian Elischer /* 94d33e92f9SJulian Elischer * Each inode on the file system is described by the following structure. 95d33e92f9SJulian Elischer * The linkcnt is initially set to the value in the inode. Each time it 96d33e92f9SJulian Elischer * is found during the descent in passes 2, 3, and 4 the count is 97d33e92f9SJulian Elischer * decremented. Any inodes whose count is non-zero after pass 4 needs to 98d33e92f9SJulian Elischer * have its link count adjusted by the value remaining in ino_linkcnt. 99d33e92f9SJulian Elischer */ 100d33e92f9SJulian Elischer struct inostat { 101d33e92f9SJulian Elischer char ino_state; /* state of inode, see below */ 102d33e92f9SJulian Elischer char ino_type; /* type of inode */ 103d33e92f9SJulian Elischer short ino_linkcnt; /* number of links not found */ 104d33e92f9SJulian Elischer }; 105d33e92f9SJulian Elischer /* 106d33e92f9SJulian Elischer * Inode states. 107d33e92f9SJulian Elischer */ 108af6726e6SDon Lewis #define USTATE 0x1 /* inode not allocated */ 109af6726e6SDon Lewis #define FSTATE 0x2 /* inode is file */ 110af6726e6SDon Lewis #define FZLINK 0x3 /* inode is file with a link count of zero */ 111af6726e6SDon Lewis #define DSTATE 0x4 /* inode is directory */ 112af6726e6SDon Lewis #define DZLINK 0x5 /* inode is directory with a zero link count */ 113af6726e6SDon Lewis #define DFOUND 0x6 /* directory found during descent */ 114af6726e6SDon Lewis /* 0x7 UNUSED - see S_IS_DVALID() definition */ 115af6726e6SDon Lewis #define DCLEAR 0x8 /* directory is to be cleared */ 116af6726e6SDon Lewis #define FCLEAR 0x9 /* file is to be cleared */ 117af6726e6SDon Lewis /* DUNFOUND === (state == DSTATE || state == DZLINK) */ 118af6726e6SDon Lewis #define S_IS_DUNFOUND(state) (((state) & ~0x1) == DSTATE) 119af6726e6SDon Lewis /* DVALID === (state == DSTATE || state == DZLINK || state == DFOUND) */ 120af6726e6SDon Lewis #define S_IS_DVALID(state) (((state) & ~0x3) == DSTATE) 121af6726e6SDon Lewis #define INO_IS_DUNFOUND(ino) S_IS_DUNFOUND(inoinfo(ino)->ino_state) 122af6726e6SDon Lewis #define INO_IS_DVALID(ino) S_IS_DVALID(inoinfo(ino)->ino_state) 123d33e92f9SJulian Elischer /* 124d33e92f9SJulian Elischer * Inode state information is contained on per cylinder group lists 125d33e92f9SJulian Elischer * which are described by the following structure. 126d33e92f9SJulian Elischer */ 127d33e92f9SJulian Elischer struct inostatlist { 128d33e92f9SJulian Elischer long il_numalloced; /* number of inodes allocated in this cg */ 129d33e92f9SJulian Elischer struct inostat *il_stat;/* inostat info for this cylinder group */ 130d33e92f9SJulian Elischer } *inostathead; 1318fae3551SRodney W. Grimes 1328fae3551SRodney W. Grimes /* 1338fae3551SRodney W. Grimes * buffer cache structure. 1348fae3551SRodney W. Grimes */ 1358fae3551SRodney W. Grimes struct bufarea { 136*2ec5c914SKirk McKusick TAILQ_ENTRY(bufarea) b_list; /* buffer list */ 1371c85e6a3SKirk McKusick ufs2_daddr_t b_bno; 1388fae3551SRodney W. Grimes int b_size; 1398fae3551SRodney W. Grimes int b_errs; 1408fae3551SRodney W. Grimes int b_flags; 1418fae3551SRodney W. Grimes union { 1428fae3551SRodney W. Grimes char *b_buf; /* buffer space */ 1431c85e6a3SKirk McKusick ufs1_daddr_t *b_indir1; /* UFS1 indirect block */ 1441c85e6a3SKirk McKusick ufs2_daddr_t *b_indir2; /* UFS2 indirect block */ 1458fae3551SRodney W. Grimes struct fs *b_fs; /* super block */ 1468fae3551SRodney W. Grimes struct cg *b_cg; /* cylinder group */ 1471c85e6a3SKirk McKusick struct ufs1_dinode *b_dinode1; /* UFS1 inode block */ 1481c85e6a3SKirk McKusick struct ufs2_dinode *b_dinode2; /* UFS2 inode block */ 1498fae3551SRodney W. Grimes } b_un; 1508fae3551SRodney W. Grimes char b_dirty; 1518fae3551SRodney W. Grimes }; 152c3b2344bSScott Long 1531c85e6a3SKirk McKusick #define IBLK(bp, i) \ 1541c85e6a3SKirk McKusick ((sblock.fs_magic == FS_UFS1_MAGIC) ? \ 1551c85e6a3SKirk McKusick (bp)->b_un.b_indir1[i] : (bp)->b_un.b_indir2[i]) 1568fae3551SRodney W. Grimes 157c3b2344bSScott Long #define IBLK_SET(bp, i, val) do { \ 158c3b2344bSScott Long if (sblock.fs_magic == FS_UFS1_MAGIC) \ 159c3b2344bSScott Long (bp)->b_un.b_indir1[i] = (val); \ 160c3b2344bSScott Long else \ 161c3b2344bSScott Long (bp)->b_un.b_indir2[i] = (val); \ 162c3b2344bSScott Long } while (0) 163c3b2344bSScott Long 164*2ec5c914SKirk McKusick /* 165*2ec5c914SKirk McKusick * Buffer flags 166*2ec5c914SKirk McKusick */ 167*2ec5c914SKirk McKusick #define B_INUSE 0x00000001 /* Buffer is in use */ 1688fae3551SRodney W. Grimes 1698fae3551SRodney W. Grimes struct bufarea sblk; /* file system superblock */ 1708fae3551SRodney W. Grimes struct bufarea cgblk; /* cylinder group blocks */ 1718fae3551SRodney W. Grimes struct bufarea *pdirbp; /* current directory contents */ 1728fae3551SRodney W. Grimes struct bufarea *pbp; /* current inode block */ 1738fae3551SRodney W. Grimes 174bf58d635SIan Dowse #define dirty(bp) do { \ 1757578c6abSKirk McKusick if (fswritefd < 0) \ 1767578c6abSKirk McKusick pfatal("SETTING DIRTY FLAG IN READ_ONLY MODE\n"); \ 1777578c6abSKirk McKusick else \ 178bf58d635SIan Dowse (bp)->b_dirty = 1; \ 179bf58d635SIan Dowse } while (0) 180bf58d635SIan Dowse #define initbarea(bp) do { \ 1818fae3551SRodney W. Grimes (bp)->b_dirty = 0; \ 1821c85e6a3SKirk McKusick (bp)->b_bno = (ufs2_daddr_t)-1; \ 183bf58d635SIan Dowse (bp)->b_flags = 0; \ 184bf58d635SIan Dowse } while (0) 1858fae3551SRodney W. Grimes 1867578c6abSKirk McKusick #define sbdirty() dirty(&sblk) 1877578c6abSKirk McKusick #define cgdirty() dirty(&cgblk) 1888fae3551SRodney W. Grimes #define sblock (*sblk.b_un.b_fs) 1898fae3551SRodney W. Grimes #define cgrp (*cgblk.b_un.b_cg) 1908fae3551SRodney W. Grimes 1918fae3551SRodney W. Grimes enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE}; 192142d8d2fSKirk McKusick ino_t cursnapshot; 1938fae3551SRodney W. Grimes 1948fae3551SRodney W. Grimes struct inodesc { 1958fae3551SRodney W. Grimes enum fixstate id_fix; /* policy on fixing errors */ 196599304a4SPoul-Henning Kamp int (*id_func)(struct inodesc *); 197599304a4SPoul-Henning Kamp /* function to be applied to blocks of inode */ 1988fae3551SRodney W. Grimes ino_t id_number; /* inode number described */ 1998fae3551SRodney W. Grimes ino_t id_parent; /* for DATA nodes, their parent */ 2001c85e6a3SKirk McKusick ufs_lbn_t id_lbn; /* logical block number of current block */ 2011c85e6a3SKirk McKusick ufs2_daddr_t id_blkno; /* current block number being examined */ 2028fae3551SRodney W. Grimes int id_numfrags; /* number of frags contained in block */ 2031c85e6a3SKirk McKusick off_t id_filesize; /* for DATA nodes, the size of the directory */ 2041c85e6a3SKirk McKusick ufs2_daddr_t id_entryno;/* for DATA nodes, current entry number */ 2058fae3551SRodney W. Grimes int id_loc; /* for DATA nodes, current location in dir */ 2068fae3551SRodney W. Grimes struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 2078fae3551SRodney W. Grimes char *id_name; /* for DATA nodes, name to find or enter */ 2088fae3551SRodney W. Grimes char id_type; /* type of descriptor, DATA or ADDR */ 2098fae3551SRodney W. Grimes }; 2108fae3551SRodney W. Grimes /* file types */ 211142d8d2fSKirk McKusick #define DATA 1 /* a directory */ 212142d8d2fSKirk McKusick #define SNAP 2 /* a snapshot */ 213142d8d2fSKirk McKusick #define ADDR 3 /* anything but a directory or a snapshot */ 2148fae3551SRodney W. Grimes 2158fae3551SRodney W. Grimes /* 2168fae3551SRodney W. Grimes * Linked list of duplicate blocks. 2178fae3551SRodney W. Grimes * 2188fae3551SRodney W. Grimes * The list is composed of two parts. The first part of the 2198fae3551SRodney W. Grimes * list (from duplist through the node pointed to by muldup) 2208fae3551SRodney W. Grimes * contains a single copy of each duplicate block that has been 2218fae3551SRodney W. Grimes * found. The second part of the list (from muldup to the end) 2228fae3551SRodney W. Grimes * contains duplicate blocks that have been found more than once. 2238fae3551SRodney W. Grimes * To check if a block has been found as a duplicate it is only 2248fae3551SRodney W. Grimes * necessary to search from duplist through muldup. To find the 2258fae3551SRodney W. Grimes * total number of times that a block has been found as a duplicate 2264b85a12fSUlrich Spörlein * the entire list must be searched for occurrences of the block 2278fae3551SRodney W. Grimes * in question. The following diagram shows a sample list where 2288fae3551SRodney W. Grimes * w (found twice), x (found once), y (found three times), and z 2298fae3551SRodney W. Grimes * (found once) are duplicate block numbers: 2308fae3551SRodney W. Grimes * 2318fae3551SRodney W. Grimes * w -> y -> x -> z -> y -> w -> y 2328fae3551SRodney W. Grimes * ^ ^ 2338fae3551SRodney W. Grimes * | | 2348fae3551SRodney W. Grimes * duplist muldup 2358fae3551SRodney W. Grimes */ 2368fae3551SRodney W. Grimes struct dups { 2378fae3551SRodney W. Grimes struct dups *next; 2381c85e6a3SKirk McKusick ufs2_daddr_t dup; 2398fae3551SRodney W. Grimes }; 2408fae3551SRodney W. Grimes struct dups *duplist; /* head of dup list */ 2418fae3551SRodney W. Grimes struct dups *muldup; /* end of unique duplicate dup block numbers */ 2428fae3551SRodney W. Grimes 2438fae3551SRodney W. Grimes /* 2448fae3551SRodney W. Grimes * Inode cache data structures. 2458fae3551SRodney W. Grimes */ 2468fae3551SRodney W. Grimes struct inoinfo { 2478fae3551SRodney W. Grimes struct inoinfo *i_nexthash; /* next entry in hash chain */ 2488fae3551SRodney W. Grimes ino_t i_number; /* inode number of this entry */ 2498fae3551SRodney W. Grimes ino_t i_parent; /* inode number of parent */ 2508fae3551SRodney W. Grimes ino_t i_dotdot; /* inode number of `..' */ 2518fae3551SRodney W. Grimes size_t i_isize; /* size of inode */ 2528fae3551SRodney W. Grimes u_int i_numblks; /* size of block array in bytes */ 2531c85e6a3SKirk McKusick ufs2_daddr_t i_blks[1]; /* actually longer */ 2548fae3551SRodney W. Grimes } **inphead, **inpsort; 255e50342e6SKirk McKusick long numdirs, dirhash, listmax, inplast; 256d33e92f9SJulian Elischer long countdirs; /* number of directories we actually found */ 2578fae3551SRodney W. Grimes 2587578c6abSKirk McKusick #define MIBSIZE 3 /* size of fsck sysctl MIBs */ 2597578c6abSKirk McKusick int adjrefcnt[MIBSIZE]; /* MIB command to adjust inode reference cnt */ 2607578c6abSKirk McKusick int adjblkcnt[MIBSIZE]; /* MIB command to adjust inode block count */ 261a16baf37SXin LI int adjndir[MIBSIZE]; /* MIB command to adjust number of directories */ 262a16baf37SXin LI int adjnbfree[MIBSIZE]; /* MIB command to adjust number of free blocks */ 263a16baf37SXin LI int adjnifree[MIBSIZE]; /* MIB command to adjust number of free inodes */ 264a16baf37SXin LI int adjnffree[MIBSIZE]; /* MIB command to adjust number of free frags */ 265a16baf37SXin LI int adjnumclusters[MIBSIZE]; /* MIB command to adjust number of free clusters */ 2667578c6abSKirk McKusick int freefiles[MIBSIZE]; /* MIB command to free a set of files */ 2677578c6abSKirk McKusick int freedirs[MIBSIZE]; /* MIB command to free a set of directories */ 2687578c6abSKirk McKusick int freeblks[MIBSIZE]; /* MIB command to free a set of data blocks */ 2697578c6abSKirk McKusick struct fsck_cmd cmd; /* sysctl file system update commands */ 2707578c6abSKirk McKusick char snapname[BUFSIZ]; /* when doing snapshots, the name of the file */ 2718fae3551SRodney W. Grimes char *cdevname; /* name of device being checked */ 2728fae3551SRodney W. Grimes long dev_bsize; /* computed value of DEV_BSIZE */ 2738fae3551SRodney W. Grimes long secsize; /* actual disk sector size */ 2746f100596SKonstantin Belousov u_int real_dev_bsize; /* actual disk sector size, not overriden */ 2758fae3551SRodney W. Grimes char nflag; /* assume a no response */ 2768fae3551SRodney W. Grimes char yflag; /* assume a yes response */ 2777578c6abSKirk McKusick int bkgrdflag; /* use a snapshot to run on an active system */ 2788fae3551SRodney W. Grimes int bflag; /* location of alternate super block */ 2798fae3551SRodney W. Grimes int debug; /* output debugging info */ 2808d3dfc26SDag-Erling Smørgrav int Eflag; /* zero out empty data blocks */ 281910b491eSKirk McKusick int inoopt; /* trim out unused inodes */ 282111a5220SDavid E. O'Brien char ckclean; /* only do work if not cleanly unmounted */ 2838fae3551SRodney W. Grimes int cvtlevel; /* convert to newer file system format */ 28415fca934SKirk McKusick int bkgrdcheck; /* determine if background check is possible */ 285c0ed8991SXin LI int bkgrdsumadj; /* whether the kernel have ability to adjust superblock summary */ 286b1897c19SJulian Elischer char usedsoftdep; /* just fix soft dependency inconsistencies */ 2878fae3551SRodney W. Grimes char preen; /* just fix normal inconsistencies */ 288d33e92f9SJulian Elischer char rerun; /* rerun fsck. Only used in non-preen mode */ 289d33e92f9SJulian Elischer int returntosingle; /* 1 => return to single user mode on exit */ 290d33e92f9SJulian Elischer char resolved; /* cleared if unresolved changes => not clean */ 2918fae3551SRodney W. Grimes char havesb; /* superblock has been read */ 2929ea6f4f0SAdrian Chadd char skipclean; /* skip clean file systems if preening */ 2938fae3551SRodney W. Grimes int fsmodified; /* 1 => write done to file system */ 2948fae3551SRodney W. Grimes int fsreadfd; /* file descriptor for reading file system */ 2958fae3551SRodney W. Grimes int fswritefd; /* file descriptor for writing file system */ 2968fae3551SRodney W. Grimes 2971c85e6a3SKirk McKusick ufs2_daddr_t maxfsblock; /* number of blocks in the file system */ 2988fae3551SRodney W. Grimes char *blockmap; /* ptr to primary blk allocation map */ 2998fae3551SRodney W. Grimes ino_t maxino; /* number of inodes in file system */ 3008fae3551SRodney W. Grimes 3018fae3551SRodney W. Grimes ino_t lfdir; /* lost & found directory inode number */ 302599304a4SPoul-Henning Kamp const char *lfname; /* lost & found directory name */ 3038fae3551SRodney W. Grimes int lfmode; /* lost & found directory creation mode */ 3048fae3551SRodney W. Grimes 3051c85e6a3SKirk McKusick ufs2_daddr_t n_blks; /* number of blocks in use */ 3061c85e6a3SKirk McKusick ino_t n_files; /* number of files in use */ 3078fae3551SRodney W. Grimes 308fd02a3b5SUlf Lilleengen volatile sig_atomic_t got_siginfo; /* received a SIGINFO */ 309fd02a3b5SUlf Lilleengen volatile sig_atomic_t got_sigalarm; /* received a SIGALRM */ 3106db798caSIan Dowse 3111c85e6a3SKirk McKusick #define clearinode(dp) \ 3121c85e6a3SKirk McKusick if (sblock.fs_magic == FS_UFS1_MAGIC) { \ 3131c85e6a3SKirk McKusick (dp)->dp1 = ufs1_zino; \ 3141c85e6a3SKirk McKusick } else { \ 3151c85e6a3SKirk McKusick (dp)->dp2 = ufs2_zino; \ 3161c85e6a3SKirk McKusick } 3171c85e6a3SKirk McKusick struct ufs1_dinode ufs1_zino; 3181c85e6a3SKirk McKusick struct ufs2_dinode ufs2_zino; 3198fae3551SRodney W. Grimes 3208fae3551SRodney W. Grimes #define setbmap(blkno) setbit(blockmap, blkno) 3218fae3551SRodney W. Grimes #define testbmap(blkno) isset(blockmap, blkno) 3228fae3551SRodney W. Grimes #define clrbmap(blkno) clrbit(blockmap, blkno) 3238fae3551SRodney W. Grimes 3248fae3551SRodney W. Grimes #define STOP 0x01 3258fae3551SRodney W. Grimes #define SKIP 0x02 3268fae3551SRodney W. Grimes #define KEEPON 0x04 3278fae3551SRodney W. Grimes #define ALTERED 0x08 3288fae3551SRodney W. Grimes #define FOUND 0x10 3298fae3551SRodney W. Grimes 330780a5c1eSPeter Wemm #define EEXIT 8 /* Standard error exit. */ 331780a5c1eSPeter Wemm 332780a5c1eSPeter Wemm struct fstab; 333780a5c1eSPeter Wemm 334d33e92f9SJulian Elischer 335b70cd7eeSWarner Losh void adjust(struct inodesc *, int lcnt); 3361c85e6a3SKirk McKusick ufs2_daddr_t allocblk(long frags); 337b70cd7eeSWarner Losh ino_t allocdir(ino_t parent, ino_t request, int mode); 338b70cd7eeSWarner Losh ino_t allocino(ino_t request, int type); 339599304a4SPoul-Henning Kamp void blkerror(ino_t ino, const char *type, ufs2_daddr_t blk); 340b70cd7eeSWarner Losh char *blockcheck(char *name); 341aef8d244SPawel Jakub Dawidek int blread(int fd, char *buf, ufs2_daddr_t blk, long size); 342b70cd7eeSWarner Losh void bufinit(void); 3434a835375SDavid E. O'Brien void blwrite(int fd, char *buf, ufs2_daddr_t blk, ssize_t size); 3448d3dfc26SDag-Erling Smørgrav void blerase(int fd, ufs2_daddr_t blk, long size); 3451c85e6a3SKirk McKusick void cacheino(union dinode *dp, ino_t inumber); 346b70cd7eeSWarner Losh void catch(int); 347b70cd7eeSWarner Losh void catchquit(int); 348599304a4SPoul-Henning Kamp int changeino(ino_t dir, const char *name, ino_t newnum); 349910b491eSKirk McKusick int check_cgmagic(int cg, struct cg *cgp); 3501c85e6a3SKirk McKusick int chkrange(ufs2_daddr_t blk, int cnt); 351b70cd7eeSWarner Losh void ckfini(int markclean); 3521c85e6a3SKirk McKusick int ckinode(union dinode *dp, struct inodesc *); 353599304a4SPoul-Henning Kamp void clri(struct inodesc *, const char *type, int flag); 354b70cd7eeSWarner Losh int clearentry(struct inodesc *); 355599304a4SPoul-Henning Kamp void direrror(ino_t ino, const char *errmesg); 356b70cd7eeSWarner Losh int dirscan(struct inodesc *); 357599304a4SPoul-Henning Kamp int dofix(struct inodesc *, const char *msg); 35851869213SPoul-Henning Kamp int eascan(struct inodesc *, struct ufs2_dinode *dp); 359599304a4SPoul-Henning Kamp void fileerror(ino_t cwd, ino_t ino, const char *errmesg); 360b70cd7eeSWarner Losh int findino(struct inodesc *); 361b70cd7eeSWarner Losh int findname(struct inodesc *); 362b70cd7eeSWarner Losh void flush(int fd, struct bufarea *bp); 3631c85e6a3SKirk McKusick void freeblk(ufs2_daddr_t blkno, long frags); 364b70cd7eeSWarner Losh void freeino(ino_t ino); 365b70cd7eeSWarner Losh void freeinodebuf(void); 3661c85e6a3SKirk McKusick int ftypeok(union dinode *dp); 3671c85e6a3SKirk McKusick void getblk(struct bufarea *bp, ufs2_daddr_t blk, long size); 3681c85e6a3SKirk McKusick struct bufarea *getdatablk(ufs2_daddr_t blkno, long size); 369b70cd7eeSWarner Losh struct inoinfo *getinoinfo(ino_t inumber); 370910b491eSKirk McKusick union dinode *getnextinode(ino_t inumber, int rebuildcg); 371b70cd7eeSWarner Losh void getpathname(char *namebuf, ino_t curdir, ino_t ino); 3721c85e6a3SKirk McKusick union dinode *ginode(ino_t inumber); 373b70cd7eeSWarner Losh void infohandler(int sig); 3741660ae87SScott Long void alarmhandler(int sig); 375b70cd7eeSWarner Losh void inocleanup(void); 376b70cd7eeSWarner Losh void inodirty(void); 377b70cd7eeSWarner Losh struct inostat *inoinfo(ino_t inum); 378b70cd7eeSWarner Losh int linkup(ino_t orphan, ino_t parentdir, char *name); 379599304a4SPoul-Henning Kamp int makeentry(ino_t parent, ino_t ino, const char *name); 380b70cd7eeSWarner Losh void panic(const char *fmt, ...) __printflike(1, 2); 381b70cd7eeSWarner Losh void pass1(void); 382b70cd7eeSWarner Losh void pass1b(void); 383b70cd7eeSWarner Losh int pass1check(struct inodesc *); 384b70cd7eeSWarner Losh void pass2(void); 385b70cd7eeSWarner Losh void pass3(void); 386b70cd7eeSWarner Losh void pass4(void); 387b70cd7eeSWarner Losh int pass4check(struct inodesc *); 388b70cd7eeSWarner Losh void pass5(void); 389b70cd7eeSWarner Losh void pfatal(const char *fmt, ...) __printflike(1, 2); 390b70cd7eeSWarner Losh void pinode(ino_t ino); 391b70cd7eeSWarner Losh void propagate(void); 392b70cd7eeSWarner Losh void pwarn(const char *fmt, ...) __printflike(1, 2); 393b70cd7eeSWarner Losh int readsb(int listerr); 394599304a4SPoul-Henning Kamp int reply(const char *question); 395599304a4SPoul-Henning Kamp void rwerror(const char *mesg, ufs2_daddr_t blk); 396b70cd7eeSWarner Losh void sblock_init(void); 397b70cd7eeSWarner Losh void setinodebuf(ino_t); 398b70cd7eeSWarner Losh int setup(char *dev); 399aef8d244SPawel Jakub Dawidek void gjournal_check(const char *filesys); 400113db2ddSJeff Roberson int suj_check(const char *filesys); 401d2404f04SKirk McKusick void update_maps(struct cg *, struct cg*, int); 402d00690aeSPawel Jakub Dawidek 403d00690aeSPawel Jakub Dawidek #endif /* !_FSCK_H_ */ 404