122057Sdist /* 261492Sbostic * Copyright (c) 1980, 1986, 1993 361492Sbostic * The Regents of the University of California. All rights reserved. 422057Sdist * 542701Sbostic * %sccs.include.redist.c% 639976Smckusick * 7*68548Smckusick * @(#)fsck.h 8.2 (Berkeley) 03/21/95 822057Sdist */ 916260Smckusick 1040023Smckusick #define MAXDUP 10 /* limit on dup blks (per inode) */ 1140023Smckusick #define MAXBAD 10 /* limit on bad blks (per inode) */ 1240023Smckusick #define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ 1340023Smckusick #define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ 1416260Smckusick 1516260Smckusick #ifndef BUFSIZ 1616260Smckusick #define BUFSIZ 1024 1716260Smckusick #endif 1816260Smckusick 1917936Smckusick #define USTATE 01 /* inode not allocated */ 2017936Smckusick #define FSTATE 02 /* inode is file */ 2117936Smckusick #define DSTATE 03 /* inode is directory */ 2217936Smckusick #define DFOUND 04 /* directory found during descent */ 2317936Smckusick #define DCLEAR 05 /* directory is to be cleared */ 2417936Smckusick #define FCLEAR 06 /* file is to be cleared */ 2516260Smckusick 2634225Smckusick /* 2734225Smckusick * buffer cache structure. 2834225Smckusick */ 2916260Smckusick struct bufarea { 30*68548Smckusick struct bufarea *b_next; /* free list queue */ 31*68548Smckusick struct bufarea *b_prev; /* free list queue */ 32*68548Smckusick ufs_daddr_t b_bno; 33*68548Smckusick int b_size; 34*68548Smckusick int b_errs; 35*68548Smckusick int b_flags; 3616260Smckusick union { 37*68548Smckusick char *b_buf; /* buffer space */ 38*68548Smckusick ufs_daddr_t *b_indir; /* indirect block */ 39*68548Smckusick struct fs *b_fs; /* super block */ 40*68548Smckusick struct cg *b_cg; /* cylinder group */ 41*68548Smckusick struct dinode *b_dinode; /* inode block */ 4216260Smckusick } b_un; 43*68548Smckusick char b_dirty; 4416260Smckusick }; 4516260Smckusick 4634225Smckusick #define B_INUSE 1 4716260Smckusick 4834225Smckusick #define MINBUFS 5 /* minimum number of buffers required */ 4939973Smckusick struct bufarea bufhead; /* head of list of other blks in filesys */ 5039973Smckusick struct bufarea sblk; /* file system superblock */ 5139973Smckusick struct bufarea cgblk; /* cylinder group blocks */ 5240650Smckusick struct bufarea *pdirbp; /* current directory contents */ 5340650Smckusick struct bufarea *pbp; /* current inode block */ 5439973Smckusick struct bufarea *getdatablk(); 5516260Smckusick 5639973Smckusick #define dirty(bp) (bp)->b_dirty = 1 5739973Smckusick #define initbarea(bp) \ 5839973Smckusick (bp)->b_dirty = 0; \ 59*68548Smckusick (bp)->b_bno = (ufs_daddr_t)-1; \ 6039973Smckusick (bp)->b_flags = 0; 6134225Smckusick 6216260Smckusick #define sbdirty() sblk.b_dirty = 1 6316260Smckusick #define cgdirty() cgblk.b_dirty = 1 6434225Smckusick #define sblock (*sblk.b_un.b_fs) 6534225Smckusick #define cgrp (*cgblk.b_un.b_cg) 6616260Smckusick 6744997Smckusick enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE}; 6817930Smckusick 6916260Smckusick struct inodesc { 7017930Smckusick enum fixstate id_fix; /* policy on fixing errors */ 7116260Smckusick int (*id_func)(); /* function to be applied to blocks of inode */ 7216260Smckusick ino_t id_number; /* inode number described */ 7316260Smckusick ino_t id_parent; /* for DATA nodes, their parent */ 74*68548Smckusick ufs_daddr_t id_blkno; /* current block number being examined */ 7516260Smckusick int id_numfrags; /* number of frags contained in block */ 7652982Smckusick quad_t id_filesize; /* for DATA nodes, the size of the directory */ 7716260Smckusick int id_loc; /* for DATA nodes, current location in dir */ 7816260Smckusick int id_entryno; /* for DATA nodes, current entry number */ 7939973Smckusick struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 8017930Smckusick char *id_name; /* for DATA nodes, name to find or enter */ 8117930Smckusick char id_type; /* type of descriptor, DATA or ADDR */ 8216260Smckusick }; 8316260Smckusick /* file types */ 8416260Smckusick #define DATA 1 8516260Smckusick #define ADDR 2 8616260Smckusick 8721743Smckusick /* 8821759Smckusick * Linked list of duplicate blocks. 8921759Smckusick * 9021759Smckusick * The list is composed of two parts. The first part of the 9121759Smckusick * list (from duplist through the node pointed to by muldup) 9221759Smckusick * contains a single copy of each duplicate block that has been 9321759Smckusick * found. The second part of the list (from muldup to the end) 9421759Smckusick * contains duplicate blocks that have been found more than once. 9521759Smckusick * To check if a block has been found as a duplicate it is only 9621759Smckusick * necessary to search from duplist through muldup. To find the 9721759Smckusick * total number of times that a block has been found as a duplicate 9821759Smckusick * the entire list must be searched for occurences of the block 9921759Smckusick * in question. The following diagram shows a sample list where 10021759Smckusick * w (found twice), x (found once), y (found three times), and z 10121759Smckusick * (found once) are duplicate block numbers: 10221759Smckusick * 10321759Smckusick * w -> y -> x -> z -> y -> w -> y 10421759Smckusick * ^ ^ 10521759Smckusick * | | 10621759Smckusick * duplist muldup 10721743Smckusick */ 10821743Smckusick struct dups { 10921743Smckusick struct dups *next; 110*68548Smckusick ufs_daddr_t dup; 11121743Smckusick }; 11221743Smckusick struct dups *duplist; /* head of dup list */ 11321743Smckusick struct dups *muldup; /* end of unique duplicate dup block numbers */ 11416260Smckusick 11521759Smckusick /* 11621759Smckusick * Linked list of inodes with zero link counts. 11721759Smckusick */ 11821759Smckusick struct zlncnt { 11921759Smckusick struct zlncnt *next; 12021759Smckusick ino_t zlncnt; 12121759Smckusick }; 12221759Smckusick struct zlncnt *zlnhead; /* head of zero link count list */ 12316260Smckusick 12440023Smckusick /* 12540023Smckusick * Inode cache data structures. 12640023Smckusick */ 12740023Smckusick struct inoinfo { 12840023Smckusick struct inoinfo *i_nexthash; /* next entry in hash chain */ 12940023Smckusick ino_t i_number; /* inode number of this entry */ 13040023Smckusick ino_t i_parent; /* inode number of parent */ 13140023Smckusick ino_t i_dotdot; /* inode number of `..' */ 13240023Smckusick size_t i_isize; /* size of inode */ 13340023Smckusick u_int i_numblks; /* size of block array in bytes */ 134*68548Smckusick ufs_daddr_t i_blks[1]; /* actually longer */ 13540023Smckusick } **inphead, **inpsort; 13640023Smckusick long numdirs, listmax, inplast; 13740023Smckusick 13861110Sbostic char *cdevname; /* name of device being checked */ 13930518Smckusick long dev_bsize; /* computed value of DEV_BSIZE */ 14030609Skarels long secsize; /* actual disk sector size */ 14116260Smckusick char nflag; /* assume a no response */ 14216260Smckusick char yflag; /* assume a yes response */ 14316260Smckusick int bflag; /* location of alternate super block */ 14416260Smckusick int debug; /* output debugging info */ 14554503Smckusick int cvtlevel; /* convert to newer file system format */ 14654503Smckusick int doinglevel1; /* converting to new cylinder group format */ 14754503Smckusick int doinglevel2; /* converting to new inode format */ 14854503Smckusick int newinofmt; /* filesystem has new inode format */ 14916260Smckusick char preen; /* just fix normal inconsistencies */ 15016260Smckusick char hotroot; /* checking root device */ 15130859Skarels char havesb; /* superblock has been read */ 15239973Smckusick int fsmodified; /* 1 => write done to file system */ 15339973Smckusick int fsreadfd; /* file descriptor for reading file system */ 15439973Smckusick int fswritefd; /* file descriptor for writing file system */ 15516260Smckusick 156*68548Smckusick ufs_daddr_t maxfsblock; /* number of blocks in the file system */ 15716260Smckusick char *blockmap; /* ptr to primary blk allocation map */ 15839973Smckusick ino_t maxino; /* number of inodes in file system */ 15939973Smckusick ino_t lastino; /* last inode in use */ 16016260Smckusick char *statemap; /* ptr to inode state table */ 16154503Smckusick char *typemap; /* ptr to inode type table */ 16216260Smckusick short *lncntp; /* ptr to link count table */ 16316260Smckusick 16417930Smckusick ino_t lfdir; /* lost & found directory inode number */ 16517930Smckusick char *lfname; /* lost & found directory name */ 16636827Smckusick int lfmode; /* lost & found directory creation mode */ 16716260Smckusick 168*68548Smckusick ufs_daddr_t n_blks; /* number of blocks in use */ 169*68548Smckusick ufs_daddr_t n_files; /* number of files in use */ 17016260Smckusick 17139973Smckusick #define clearinode(dp) (*(dp) = zino) 17216260Smckusick struct dinode zino; 17316260Smckusick 17439973Smckusick #define setbmap(blkno) setbit(blockmap, blkno) 17539973Smckusick #define testbmap(blkno) isset(blockmap, blkno) 17639973Smckusick #define clrbmap(blkno) clrbit(blockmap, blkno) 17716260Smckusick 17839973Smckusick #define STOP 0x01 17939973Smckusick #define SKIP 0x02 18039973Smckusick #define KEEPON 0x04 18139973Smckusick #define ALTERED 0x08 18239973Smckusick #define FOUND 0x10 18316260Smckusick 18439973Smckusick time_t time(); 18539973Smckusick struct dinode *ginode(); 18640023Smckusick struct inoinfo *getinoinfo(); 18744934Smckusick void getblk(); 18839973Smckusick ino_t allocino(); 18939973Smckusick int findino(); 190