122057Sdist /* 239976Smckusick * Copyright (c) 1980, 1986 The Regents of the University of California. 339976Smckusick * All rights reserved. 422057Sdist * 539976Smckusick * Redistribution and use in source and binary forms are permitted 639976Smckusick * provided that the above copyright notice and this paragraph are 739976Smckusick * duplicated in all such forms and that any documentation, 839976Smckusick * advertising materials, and other materials related to such 939976Smckusick * distribution and use acknowledge that the software was developed 1039976Smckusick * by the University of California, Berkeley. The name of the 1139976Smckusick * University may not be used to endorse or promote products derived 1239976Smckusick * from this software without specific prior written permission. 1339976Smckusick * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1439976Smckusick * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1539976Smckusick * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1639976Smckusick * 17*40023Smckusick * @(#)fsck.h 5.12 (Berkeley) 02/07/90 1822057Sdist */ 1916260Smckusick 20*40023Smckusick #define MAXDUP 10 /* limit on dup blks (per inode) */ 21*40023Smckusick #define MAXBAD 10 /* limit on bad blks (per inode) */ 22*40023Smckusick #define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ 23*40023Smckusick #define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ 2416260Smckusick 2516260Smckusick #ifndef BUFSIZ 2616260Smckusick #define BUFSIZ 1024 2716260Smckusick #endif 2816260Smckusick 2917936Smckusick #define USTATE 01 /* inode not allocated */ 3017936Smckusick #define FSTATE 02 /* inode is file */ 3117936Smckusick #define DSTATE 03 /* inode is directory */ 3217936Smckusick #define DFOUND 04 /* directory found during descent */ 3317936Smckusick #define DCLEAR 05 /* directory is to be cleared */ 3417936Smckusick #define FCLEAR 06 /* file is to be cleared */ 3516260Smckusick 3634225Smckusick /* 3734225Smckusick * buffer cache structure. 3834225Smckusick */ 3916260Smckusick struct bufarea { 4034225Smckusick struct bufarea *b_next; /* free list queue */ 4134225Smckusick struct bufarea *b_prev; /* free list queue */ 4216260Smckusick daddr_t b_bno; 4316260Smckusick int b_size; 4421540Smckusick int b_errs; 4534225Smckusick int b_flags; 4616260Smckusick union { 4734225Smckusick char *b_buf; /* buffer space */ 4834225Smckusick daddr_t *b_indir; /* indirect block */ 4934225Smckusick struct fs *b_fs; /* super block */ 5034225Smckusick struct cg *b_cg; /* cylinder group */ 5139973Smckusick struct dinode *b_dinode; /* inode block */ 5216260Smckusick } b_un; 5316260Smckusick char b_dirty; 5416260Smckusick }; 5516260Smckusick 5634225Smckusick #define B_INUSE 1 5716260Smckusick 5834225Smckusick #define MINBUFS 5 /* minimum number of buffers required */ 5939973Smckusick struct bufarea bufhead; /* head of list of other blks in filesys */ 6039973Smckusick struct bufarea sblk; /* file system superblock */ 6139973Smckusick struct bufarea cgblk; /* cylinder group blocks */ 6239973Smckusick struct bufarea *getdatablk(); 6316260Smckusick 6439973Smckusick #define dirty(bp) (bp)->b_dirty = 1 6539973Smckusick #define initbarea(bp) \ 6639973Smckusick (bp)->b_dirty = 0; \ 6739973Smckusick (bp)->b_bno = (daddr_t)-1; \ 6839973Smckusick (bp)->b_flags = 0; 6934225Smckusick 7016260Smckusick #define sbdirty() sblk.b_dirty = 1 7116260Smckusick #define cgdirty() cgblk.b_dirty = 1 7234225Smckusick #define sblock (*sblk.b_un.b_fs) 7334225Smckusick #define cgrp (*cgblk.b_un.b_cg) 7416260Smckusick 7517930Smckusick enum fixstate {DONTKNOW, NOFIX, FIX}; 7617930Smckusick 7716260Smckusick struct inodesc { 7817930Smckusick enum fixstate id_fix; /* policy on fixing errors */ 7916260Smckusick int (*id_func)(); /* function to be applied to blocks of inode */ 8016260Smckusick ino_t id_number; /* inode number described */ 8116260Smckusick ino_t id_parent; /* for DATA nodes, their parent */ 8216260Smckusick daddr_t id_blkno; /* current block number being examined */ 8316260Smckusick int id_numfrags; /* number of frags contained in block */ 8416260Smckusick long id_filesize; /* for DATA nodes, the size of the directory */ 8516260Smckusick int id_loc; /* for DATA nodes, current location in dir */ 8616260Smckusick int id_entryno; /* for DATA nodes, current entry number */ 8739973Smckusick struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 8817930Smckusick char *id_name; /* for DATA nodes, name to find or enter */ 8917930Smckusick char id_type; /* type of descriptor, DATA or ADDR */ 9016260Smckusick }; 9116260Smckusick /* file types */ 9216260Smckusick #define DATA 1 9316260Smckusick #define ADDR 2 9416260Smckusick 9521743Smckusick /* 9621759Smckusick * Linked list of duplicate blocks. 9721759Smckusick * 9821759Smckusick * The list is composed of two parts. The first part of the 9921759Smckusick * list (from duplist through the node pointed to by muldup) 10021759Smckusick * contains a single copy of each duplicate block that has been 10121759Smckusick * found. The second part of the list (from muldup to the end) 10221759Smckusick * contains duplicate blocks that have been found more than once. 10321759Smckusick * To check if a block has been found as a duplicate it is only 10421759Smckusick * necessary to search from duplist through muldup. To find the 10521759Smckusick * total number of times that a block has been found as a duplicate 10621759Smckusick * the entire list must be searched for occurences of the block 10721759Smckusick * in question. The following diagram shows a sample list where 10821759Smckusick * w (found twice), x (found once), y (found three times), and z 10921759Smckusick * (found once) are duplicate block numbers: 11021759Smckusick * 11121759Smckusick * w -> y -> x -> z -> y -> w -> y 11221759Smckusick * ^ ^ 11321759Smckusick * | | 11421759Smckusick * duplist muldup 11521743Smckusick */ 11621743Smckusick struct dups { 11721743Smckusick struct dups *next; 11821743Smckusick daddr_t dup; 11921743Smckusick }; 12021743Smckusick struct dups *duplist; /* head of dup list */ 12121743Smckusick struct dups *muldup; /* end of unique duplicate dup block numbers */ 12216260Smckusick 12321759Smckusick /* 12421759Smckusick * Linked list of inodes with zero link counts. 12521759Smckusick */ 12621759Smckusick struct zlncnt { 12721759Smckusick struct zlncnt *next; 12821759Smckusick ino_t zlncnt; 12921759Smckusick }; 13021759Smckusick struct zlncnt *zlnhead; /* head of zero link count list */ 13116260Smckusick 132*40023Smckusick /* 133*40023Smckusick * Inode cache data structures. 134*40023Smckusick */ 135*40023Smckusick struct inoinfo { 136*40023Smckusick struct inoinfo *i_nexthash; /* next entry in hash chain */ 137*40023Smckusick ino_t i_number; /* inode number of this entry */ 138*40023Smckusick ino_t i_parent; /* inode number of parent */ 139*40023Smckusick ino_t i_dotdot; /* inode number of `..' */ 140*40023Smckusick size_t i_isize; /* size of inode */ 141*40023Smckusick u_int i_numblks; /* size of block array in bytes */ 142*40023Smckusick daddr_t i_blks[1]; /* actually longer */ 143*40023Smckusick } **inphead, **inpsort; 144*40023Smckusick long numdirs, listmax, inplast; 145*40023Smckusick 14639973Smckusick char *devname; /* name of device being checked */ 14730518Smckusick long dev_bsize; /* computed value of DEV_BSIZE */ 14830609Skarels long secsize; /* actual disk sector size */ 14916260Smckusick char nflag; /* assume a no response */ 15016260Smckusick char yflag; /* assume a yes response */ 15116260Smckusick int bflag; /* location of alternate super block */ 15216260Smckusick int debug; /* output debugging info */ 15334139Smckusick int cvtflag; /* convert to old file system format */ 15416260Smckusick char preen; /* just fix normal inconsistencies */ 15516260Smckusick char hotroot; /* checking root device */ 15630859Skarels char havesb; /* superblock has been read */ 15739973Smckusick int fsmodified; /* 1 => write done to file system */ 15839973Smckusick int fsreadfd; /* file descriptor for reading file system */ 15939973Smckusick int fswritefd; /* file descriptor for writing file system */ 16016260Smckusick 16139973Smckusick daddr_t maxfsblock; /* number of blocks in the file system */ 16216260Smckusick char *blockmap; /* ptr to primary blk allocation map */ 16339973Smckusick ino_t maxino; /* number of inodes in file system */ 16439973Smckusick ino_t lastino; /* last inode in use */ 16516260Smckusick char *statemap; /* ptr to inode state table */ 16616260Smckusick short *lncntp; /* ptr to link count table */ 16716260Smckusick 16816260Smckusick char pathname[BUFSIZ]; /* current pathname */ 16939973Smckusick char *pathp; /* ptr to current position in pathname */ 17039973Smckusick char *endpathname; /* ptr to current end of pathname */ 17116260Smckusick 17217930Smckusick ino_t lfdir; /* lost & found directory inode number */ 17317930Smckusick char *lfname; /* lost & found directory name */ 17436827Smckusick int lfmode; /* lost & found directory creation mode */ 17516260Smckusick 17639973Smckusick daddr_t n_blks; /* number of blocks in use */ 17739973Smckusick daddr_t n_files; /* number of files in use */ 17816260Smckusick 17939973Smckusick #define clearinode(dp) (*(dp) = zino) 18016260Smckusick struct dinode zino; 18116260Smckusick 18239973Smckusick #define setbmap(blkno) setbit(blockmap, blkno) 18339973Smckusick #define testbmap(blkno) isset(blockmap, blkno) 18439973Smckusick #define clrbmap(blkno) clrbit(blockmap, blkno) 18516260Smckusick 18639973Smckusick #define STOP 0x01 18739973Smckusick #define SKIP 0x02 18839973Smckusick #define KEEPON 0x04 18939973Smckusick #define ALTERED 0x08 19039973Smckusick #define FOUND 0x10 19116260Smckusick 19239973Smckusick time_t time(); 19339973Smckusick struct dinode *ginode(); 194*40023Smckusick struct inoinfo *getinoinfo(); 19539973Smckusick struct bufarea *getblk(); 19639973Smckusick ino_t allocino(); 19739973Smckusick int findino(); 198