122057Sdist /* 2*39976Smckusick * Copyright (c) 1980, 1986 The Regents of the University of California. 3*39976Smckusick * All rights reserved. 422057Sdist * 5*39976Smckusick * Redistribution and use in source and binary forms are permitted 6*39976Smckusick * provided that the above copyright notice and this paragraph are 7*39976Smckusick * duplicated in all such forms and that any documentation, 8*39976Smckusick * advertising materials, and other materials related to such 9*39976Smckusick * distribution and use acknowledge that the software was developed 10*39976Smckusick * by the University of California, Berkeley. The name of the 11*39976Smckusick * University may not be used to endorse or promote products derived 12*39976Smckusick * from this software without specific prior written permission. 13*39976Smckusick * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*39976Smckusick * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*39976Smckusick * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16*39976Smckusick * 17*39976Smckusick * @(#)fsck.h 5.10 (Berkeley) 02/01/90 1822057Sdist */ 1916260Smckusick 2034225Smckusick #define MAXDUP 10 /* limit on dup blks (per inode) */ 2134225Smckusick #define MAXBAD 10 /* limit on bad blks (per inode) */ 2234225Smckusick #define MAXBUFSPACE 128*1024 /* maximum space to allocate to buffers */ 2316260Smckusick 2416260Smckusick #ifndef BUFSIZ 2516260Smckusick #define BUFSIZ 1024 2616260Smckusick #endif 2716260Smckusick 2817936Smckusick #define USTATE 01 /* inode not allocated */ 2917936Smckusick #define FSTATE 02 /* inode is file */ 3017936Smckusick #define DSTATE 03 /* inode is directory */ 3117936Smckusick #define DFOUND 04 /* directory found during descent */ 3217936Smckusick #define DCLEAR 05 /* directory is to be cleared */ 3317936Smckusick #define FCLEAR 06 /* file is to be cleared */ 3416260Smckusick 3534225Smckusick /* 3634225Smckusick * buffer cache structure. 3734225Smckusick */ 3816260Smckusick struct bufarea { 3934225Smckusick struct bufarea *b_next; /* free list queue */ 4034225Smckusick struct bufarea *b_prev; /* free list queue */ 4116260Smckusick daddr_t b_bno; 4216260Smckusick int b_size; 4321540Smckusick int b_errs; 4434225Smckusick int b_flags; 4516260Smckusick union { 4634225Smckusick char *b_buf; /* buffer space */ 4734225Smckusick daddr_t *b_indir; /* indirect block */ 4834225Smckusick struct fs *b_fs; /* super block */ 4934225Smckusick struct cg *b_cg; /* cylinder group */ 5039973Smckusick struct dinode *b_dinode; /* inode block */ 5116260Smckusick } b_un; 5216260Smckusick char b_dirty; 5316260Smckusick }; 5416260Smckusick 5534225Smckusick #define B_INUSE 1 5616260Smckusick 5734225Smckusick #define MINBUFS 5 /* minimum number of buffers required */ 5839973Smckusick struct bufarea bufhead; /* head of list of other blks in filesys */ 5939973Smckusick struct bufarea sblk; /* file system superblock */ 6039973Smckusick struct bufarea cgblk; /* cylinder group blocks */ 6139973Smckusick struct bufarea *getdatablk(); 6216260Smckusick 6339973Smckusick #define dirty(bp) (bp)->b_dirty = 1 6439973Smckusick #define initbarea(bp) \ 6539973Smckusick (bp)->b_dirty = 0; \ 6639973Smckusick (bp)->b_bno = (daddr_t)-1; \ 6739973Smckusick (bp)->b_flags = 0; 6834225Smckusick 6916260Smckusick #define sbdirty() sblk.b_dirty = 1 7016260Smckusick #define cgdirty() cgblk.b_dirty = 1 7134225Smckusick #define sblock (*sblk.b_un.b_fs) 7234225Smckusick #define cgrp (*cgblk.b_un.b_cg) 7316260Smckusick 7417930Smckusick enum fixstate {DONTKNOW, NOFIX, FIX}; 7517930Smckusick 7616260Smckusick struct inodesc { 7717930Smckusick enum fixstate id_fix; /* policy on fixing errors */ 7816260Smckusick int (*id_func)(); /* function to be applied to blocks of inode */ 7916260Smckusick ino_t id_number; /* inode number described */ 8016260Smckusick ino_t id_parent; /* for DATA nodes, their parent */ 8116260Smckusick daddr_t id_blkno; /* current block number being examined */ 8216260Smckusick int id_numfrags; /* number of frags contained in block */ 8316260Smckusick long id_filesize; /* for DATA nodes, the size of the directory */ 8416260Smckusick int id_loc; /* for DATA nodes, current location in dir */ 8516260Smckusick int id_entryno; /* for DATA nodes, current entry number */ 8639973Smckusick struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 8717930Smckusick char *id_name; /* for DATA nodes, name to find or enter */ 8817930Smckusick char id_type; /* type of descriptor, DATA or ADDR */ 8916260Smckusick }; 9016260Smckusick /* file types */ 9116260Smckusick #define DATA 1 9216260Smckusick #define ADDR 2 9316260Smckusick 9421743Smckusick /* 9521759Smckusick * Linked list of duplicate blocks. 9621759Smckusick * 9721759Smckusick * The list is composed of two parts. The first part of the 9821759Smckusick * list (from duplist through the node pointed to by muldup) 9921759Smckusick * contains a single copy of each duplicate block that has been 10021759Smckusick * found. The second part of the list (from muldup to the end) 10121759Smckusick * contains duplicate blocks that have been found more than once. 10221759Smckusick * To check if a block has been found as a duplicate it is only 10321759Smckusick * necessary to search from duplist through muldup. To find the 10421759Smckusick * total number of times that a block has been found as a duplicate 10521759Smckusick * the entire list must be searched for occurences of the block 10621759Smckusick * in question. The following diagram shows a sample list where 10721759Smckusick * w (found twice), x (found once), y (found three times), and z 10821759Smckusick * (found once) are duplicate block numbers: 10921759Smckusick * 11021759Smckusick * w -> y -> x -> z -> y -> w -> y 11121759Smckusick * ^ ^ 11221759Smckusick * | | 11321759Smckusick * duplist muldup 11421743Smckusick */ 11521743Smckusick struct dups { 11621743Smckusick struct dups *next; 11721743Smckusick daddr_t dup; 11821743Smckusick }; 11921743Smckusick struct dups *duplist; /* head of dup list */ 12021743Smckusick struct dups *muldup; /* end of unique duplicate dup block numbers */ 12116260Smckusick 12221759Smckusick /* 12321759Smckusick * Linked list of inodes with zero link counts. 12421759Smckusick */ 12521759Smckusick struct zlncnt { 12621759Smckusick struct zlncnt *next; 12721759Smckusick ino_t zlncnt; 12821759Smckusick }; 12921759Smckusick struct zlncnt *zlnhead; /* head of zero link count list */ 13016260Smckusick 13139973Smckusick char *devname; /* name of device being checked */ 13230518Smckusick long dev_bsize; /* computed value of DEV_BSIZE */ 13330609Skarels long secsize; /* actual disk sector size */ 13416260Smckusick char nflag; /* assume a no response */ 13516260Smckusick char yflag; /* assume a yes response */ 13616260Smckusick int bflag; /* location of alternate super block */ 13716260Smckusick int debug; /* output debugging info */ 13834139Smckusick int cvtflag; /* convert to old file system format */ 13916260Smckusick char preen; /* just fix normal inconsistencies */ 14016260Smckusick char hotroot; /* checking root device */ 14130859Skarels char havesb; /* superblock has been read */ 14239973Smckusick int fsmodified; /* 1 => write done to file system */ 14339973Smckusick int fsreadfd; /* file descriptor for reading file system */ 14439973Smckusick int fswritefd; /* file descriptor for writing file system */ 14516260Smckusick 14639973Smckusick daddr_t maxfsblock; /* number of blocks in the file system */ 14716260Smckusick char *blockmap; /* ptr to primary blk allocation map */ 14839973Smckusick ino_t maxino; /* number of inodes in file system */ 14939973Smckusick ino_t lastino; /* last inode in use */ 15016260Smckusick char *statemap; /* ptr to inode state table */ 15116260Smckusick short *lncntp; /* ptr to link count table */ 15216260Smckusick 15316260Smckusick char pathname[BUFSIZ]; /* current pathname */ 15439973Smckusick char *pathp; /* ptr to current position in pathname */ 15539973Smckusick char *endpathname; /* ptr to current end of pathname */ 15616260Smckusick 15717930Smckusick ino_t lfdir; /* lost & found directory inode number */ 15817930Smckusick char *lfname; /* lost & found directory name */ 15936827Smckusick int lfmode; /* lost & found directory creation mode */ 16016260Smckusick 16139973Smckusick daddr_t n_blks; /* number of blocks in use */ 16239973Smckusick daddr_t n_files; /* number of files in use */ 16316260Smckusick 16439973Smckusick #define clearinode(dp) (*(dp) = zino) 16516260Smckusick struct dinode zino; 16616260Smckusick 16739973Smckusick #define setbmap(blkno) setbit(blockmap, blkno) 16839973Smckusick #define testbmap(blkno) isset(blockmap, blkno) 16939973Smckusick #define clrbmap(blkno) clrbit(blockmap, blkno) 17016260Smckusick 17139973Smckusick #define STOP 0x01 17239973Smckusick #define SKIP 0x02 17339973Smckusick #define KEEPON 0x04 17439973Smckusick #define ALTERED 0x08 17539973Smckusick #define FOUND 0x10 17616260Smckusick 17739973Smckusick time_t time(); 17839973Smckusick struct dinode *ginode(); 17939973Smckusick struct bufarea *getblk(); 18039973Smckusick ino_t allocino(); 18139973Smckusick int findino(); 182