122057Sdist /* 239976Smckusick * Copyright (c) 1980, 1986 The Regents of the University of California. 339976Smckusick * All rights reserved. 422057Sdist * 542701Sbostic * %sccs.include.redist.c% 639976Smckusick * 7*44997Smckusick * @(#)fsck.h 5.17 (Berkeley) 07/27/90 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 { 3034225Smckusick struct bufarea *b_next; /* free list queue */ 3134225Smckusick struct bufarea *b_prev; /* free list queue */ 3216260Smckusick daddr_t b_bno; 3316260Smckusick int b_size; 3421540Smckusick int b_errs; 3534225Smckusick int b_flags; 3616260Smckusick union { 3734225Smckusick char *b_buf; /* buffer space */ 3834225Smckusick daddr_t *b_indir; /* indirect block */ 3934225Smckusick struct fs *b_fs; /* super block */ 4034225Smckusick struct cg *b_cg; /* cylinder group */ 4139973Smckusick struct dinode *b_dinode; /* inode block */ 4216260Smckusick } b_un; 4316260Smckusick 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; \ 5939973Smckusick (bp)->b_bno = (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 67*44997Smckusick 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 */ 7416260Smckusick daddr_t id_blkno; /* current block number being examined */ 7516260Smckusick int id_numfrags; /* number of frags contained in block */ 7616260Smckusick long 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; 11021743Smckusick 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 */ 13440023Smckusick daddr_t i_blks[1]; /* actually longer */ 13540023Smckusick } **inphead, **inpsort; 13640023Smckusick long numdirs, listmax, inplast; 13740023Smckusick 13839973Smckusick char *devname; /* 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 */ 14534139Smckusick int cvtflag; /* convert to old file system format */ 14616260Smckusick char preen; /* just fix normal inconsistencies */ 14716260Smckusick char hotroot; /* checking root device */ 14830859Skarels char havesb; /* superblock has been read */ 14939973Smckusick int fsmodified; /* 1 => write done to file system */ 15039973Smckusick int fsreadfd; /* file descriptor for reading file system */ 15139973Smckusick int fswritefd; /* file descriptor for writing file system */ 15216260Smckusick 15339973Smckusick daddr_t maxfsblock; /* number of blocks in the file system */ 15416260Smckusick char *blockmap; /* ptr to primary blk allocation map */ 15539973Smckusick ino_t maxino; /* number of inodes in file system */ 15639973Smckusick ino_t lastino; /* last inode in use */ 15716260Smckusick char *statemap; /* ptr to inode state table */ 15816260Smckusick short *lncntp; /* ptr to link count table */ 15916260Smckusick 16017930Smckusick ino_t lfdir; /* lost & found directory inode number */ 16117930Smckusick char *lfname; /* lost & found directory name */ 16236827Smckusick int lfmode; /* lost & found directory creation mode */ 16316260Smckusick 16439973Smckusick daddr_t n_blks; /* number of blocks in use */ 16539973Smckusick daddr_t n_files; /* number of files in use */ 16616260Smckusick 16739973Smckusick #define clearinode(dp) (*(dp) = zino) 16816260Smckusick struct dinode zino; 16916260Smckusick 17039973Smckusick #define setbmap(blkno) setbit(blockmap, blkno) 17139973Smckusick #define testbmap(blkno) isset(blockmap, blkno) 17239973Smckusick #define clrbmap(blkno) clrbit(blockmap, blkno) 17316260Smckusick 17439973Smckusick #define STOP 0x01 17539973Smckusick #define SKIP 0x02 17639973Smckusick #define KEEPON 0x04 17739973Smckusick #define ALTERED 0x08 17839973Smckusick #define FOUND 0x10 17916260Smckusick 18039973Smckusick time_t time(); 18139973Smckusick struct dinode *ginode(); 18240023Smckusick struct inoinfo *getinoinfo(); 18344934Smckusick void getblk(); 18439973Smckusick ino_t allocino(); 18539973Smckusick int findino(); 186