fsck.h revision 7585
11558Srgrimes/* 21558Srgrimes * Copyright (c) 1980, 1986, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * Redistribution and use in source and binary forms, with or without 61558Srgrimes * modification, are permitted provided that the following conditions 71558Srgrimes * are met: 81558Srgrimes * 1. Redistributions of source code must retain the above copyright 91558Srgrimes * notice, this list of conditions and the following disclaimer. 101558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111558Srgrimes * notice, this list of conditions and the following disclaimer in the 121558Srgrimes * documentation and/or other materials provided with the distribution. 131558Srgrimes * 3. All advertising materials mentioning features or use of this software 141558Srgrimes * must display the following acknowledgement: 151558Srgrimes * This product includes software developed by the University of 161558Srgrimes * California, Berkeley and its contributors. 171558Srgrimes * 4. Neither the name of the University nor the names of its contributors 181558Srgrimes * may be used to endorse or promote products derived from this software 191558Srgrimes * without specific prior written permission. 201558Srgrimes * 211558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311558Srgrimes * SUCH DAMAGE. 321558Srgrimes * 331558Srgrimes * @(#)fsck.h 8.1 (Berkeley) 6/5/93 341558Srgrimes */ 351558Srgrimes 361558Srgrimes#define MAXDUP 10 /* limit on dup blks (per inode) */ 371558Srgrimes#define MAXBAD 10 /* limit on bad blks (per inode) */ 381558Srgrimes#define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */ 391558Srgrimes#define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */ 401558Srgrimes 411558Srgrimes#ifndef BUFSIZ 421558Srgrimes#define BUFSIZ 1024 431558Srgrimes#endif 441558Srgrimes 451558Srgrimes#define USTATE 01 /* inode not allocated */ 461558Srgrimes#define FSTATE 02 /* inode is file */ 471558Srgrimes#define DSTATE 03 /* inode is directory */ 481558Srgrimes#define DFOUND 04 /* directory found during descent */ 491558Srgrimes#define DCLEAR 05 /* directory is to be cleared */ 501558Srgrimes#define FCLEAR 06 /* file is to be cleared */ 511558Srgrimes 521558Srgrimes/* 531558Srgrimes * buffer cache structure. 541558Srgrimes */ 551558Srgrimesstruct bufarea { 561558Srgrimes struct bufarea *b_next; /* free list queue */ 571558Srgrimes struct bufarea *b_prev; /* free list queue */ 581558Srgrimes daddr_t b_bno; 591558Srgrimes int b_size; 601558Srgrimes int b_errs; 611558Srgrimes int b_flags; 621558Srgrimes union { 631558Srgrimes char *b_buf; /* buffer space */ 641558Srgrimes daddr_t *b_indir; /* indirect block */ 651558Srgrimes struct fs *b_fs; /* super block */ 661558Srgrimes struct cg *b_cg; /* cylinder group */ 671558Srgrimes struct dinode *b_dinode; /* inode block */ 681558Srgrimes } b_un; 691558Srgrimes char b_dirty; 701558Srgrimes}; 711558Srgrimes 721558Srgrimes#define B_INUSE 1 731558Srgrimes 741558Srgrimes#define MINBUFS 5 /* minimum number of buffers required */ 751558Srgrimesstruct bufarea bufhead; /* head of list of other blks in filesys */ 761558Srgrimesstruct bufarea sblk; /* file system superblock */ 771558Srgrimesstruct bufarea cgblk; /* cylinder group blocks */ 781558Srgrimesstruct bufarea *pdirbp; /* current directory contents */ 791558Srgrimesstruct bufarea *pbp; /* current inode block */ 801558Srgrimesstruct bufarea *getdatablk(); 811558Srgrimes 821558Srgrimes#define dirty(bp) (bp)->b_dirty = 1 831558Srgrimes#define initbarea(bp) \ 841558Srgrimes (bp)->b_dirty = 0; \ 851558Srgrimes (bp)->b_bno = (daddr_t)-1; \ 861558Srgrimes (bp)->b_flags = 0; 871558Srgrimes 881558Srgrimes#define sbdirty() sblk.b_dirty = 1 891558Srgrimes#define cgdirty() cgblk.b_dirty = 1 901558Srgrimes#define sblock (*sblk.b_un.b_fs) 911558Srgrimes#define cgrp (*cgblk.b_un.b_cg) 921558Srgrimes 931558Srgrimesenum fixstate {DONTKNOW, NOFIX, FIX, IGNORE}; 941558Srgrimes 951558Srgrimesstruct inodesc { 961558Srgrimes enum fixstate id_fix; /* policy on fixing errors */ 971558Srgrimes int (*id_func)(); /* function to be applied to blocks of inode */ 981558Srgrimes ino_t id_number; /* inode number described */ 991558Srgrimes ino_t id_parent; /* for DATA nodes, their parent */ 1001558Srgrimes daddr_t id_blkno; /* current block number being examined */ 1011558Srgrimes int id_numfrags; /* number of frags contained in block */ 1021558Srgrimes quad_t id_filesize; /* for DATA nodes, the size of the directory */ 1031558Srgrimes int id_loc; /* for DATA nodes, current location in dir */ 1041558Srgrimes int id_entryno; /* for DATA nodes, current entry number */ 1051558Srgrimes struct direct *id_dirp; /* for DATA nodes, ptr to current entry */ 1061558Srgrimes char *id_name; /* for DATA nodes, name to find or enter */ 1071558Srgrimes char id_type; /* type of descriptor, DATA or ADDR */ 1081558Srgrimes}; 1091558Srgrimes/* file types */ 1101558Srgrimes#define DATA 1 1111558Srgrimes#define ADDR 2 1121558Srgrimes 1131558Srgrimes/* 1141558Srgrimes * Linked list of duplicate blocks. 1151558Srgrimes * 1161558Srgrimes * The list is composed of two parts. The first part of the 1171558Srgrimes * list (from duplist through the node pointed to by muldup) 1181558Srgrimes * contains a single copy of each duplicate block that has been 1191558Srgrimes * found. The second part of the list (from muldup to the end) 1201558Srgrimes * contains duplicate blocks that have been found more than once. 1211558Srgrimes * To check if a block has been found as a duplicate it is only 1221558Srgrimes * necessary to search from duplist through muldup. To find the 1231558Srgrimes * total number of times that a block has been found as a duplicate 1241558Srgrimes * the entire list must be searched for occurences of the block 1251558Srgrimes * in question. The following diagram shows a sample list where 1261558Srgrimes * w (found twice), x (found once), y (found three times), and z 1271558Srgrimes * (found once) are duplicate block numbers: 1281558Srgrimes * 1291558Srgrimes * w -> y -> x -> z -> y -> w -> y 1301558Srgrimes * ^ ^ 1311558Srgrimes * | | 1321558Srgrimes * duplist muldup 1331558Srgrimes */ 1341558Srgrimesstruct dups { 1351558Srgrimes struct dups *next; 1361558Srgrimes daddr_t dup; 1371558Srgrimes}; 1381558Srgrimesstruct dups *duplist; /* head of dup list */ 1391558Srgrimesstruct dups *muldup; /* end of unique duplicate dup block numbers */ 1401558Srgrimes 1411558Srgrimes/* 1421558Srgrimes * Linked list of inodes with zero link counts. 1431558Srgrimes */ 1441558Srgrimesstruct zlncnt { 1451558Srgrimes struct zlncnt *next; 1461558Srgrimes ino_t zlncnt; 1471558Srgrimes}; 1481558Srgrimesstruct zlncnt *zlnhead; /* head of zero link count list */ 1491558Srgrimes 1501558Srgrimes/* 1511558Srgrimes * Inode cache data structures. 1521558Srgrimes */ 1531558Srgrimesstruct inoinfo { 1541558Srgrimes struct inoinfo *i_nexthash; /* next entry in hash chain */ 1551558Srgrimes ino_t i_number; /* inode number of this entry */ 1561558Srgrimes ino_t i_parent; /* inode number of parent */ 1571558Srgrimes ino_t i_dotdot; /* inode number of `..' */ 1581558Srgrimes size_t i_isize; /* size of inode */ 1591558Srgrimes u_int i_numblks; /* size of block array in bytes */ 1601558Srgrimes daddr_t i_blks[1]; /* actually longer */ 1611558Srgrimes} **inphead, **inpsort; 1621558Srgrimeslong numdirs, listmax, inplast; 1631558Srgrimes 1641558Srgrimeschar *cdevname; /* name of device being checked */ 1651558Srgrimeslong dev_bsize; /* computed value of DEV_BSIZE */ 1661558Srgrimeslong secsize; /* actual disk sector size */ 1672153Sdgchar fflag; /* force fs check (ignore clean flag) */ 1681558Srgrimeschar nflag; /* assume a no response */ 1691558Srgrimeschar yflag; /* assume a yes response */ 1701558Srgrimesint bflag; /* location of alternate super block */ 1711558Srgrimesint debug; /* output debugging info */ 1721558Srgrimesint cvtlevel; /* convert to newer file system format */ 1731558Srgrimesint doinglevel1; /* converting to new cylinder group format */ 1741558Srgrimesint doinglevel2; /* converting to new inode format */ 1751558Srgrimesint newinofmt; /* filesystem has new inode format */ 1761558Srgrimeschar preen; /* just fix normal inconsistencies */ 1771558Srgrimeschar hotroot; /* checking root device */ 1781558Srgrimeschar havesb; /* superblock has been read */ 1791558Srgrimesint fsmodified; /* 1 => write done to file system */ 1801558Srgrimesint fsreadfd; /* file descriptor for reading file system */ 1811558Srgrimesint fswritefd; /* file descriptor for writing file system */ 1827585Sbdeint returntosingle; /* return to single user mode */ 1831558Srgrimes 1841558Srgrimesdaddr_t maxfsblock; /* number of blocks in the file system */ 1851558Srgrimeschar *blockmap; /* ptr to primary blk allocation map */ 1861558Srgrimesino_t maxino; /* number of inodes in file system */ 1871558Srgrimesino_t lastino; /* last inode in use */ 1881558Srgrimeschar *statemap; /* ptr to inode state table */ 1897585Sbdeunsigned char *typemap; /* ptr to inode type table */ 1901558Srgrimesshort *lncntp; /* ptr to link count table */ 1911558Srgrimes 1921558Srgrimesino_t lfdir; /* lost & found directory inode number */ 1931558Srgrimeschar *lfname; /* lost & found directory name */ 1941558Srgrimesint lfmode; /* lost & found directory creation mode */ 1951558Srgrimes 1961558Srgrimesdaddr_t n_blks; /* number of blocks in use */ 1971558Srgrimesdaddr_t n_files; /* number of files in use */ 1981558Srgrimes 1991558Srgrimes#define clearinode(dp) (*(dp) = zino) 2001558Srgrimesstruct dinode zino; 2011558Srgrimes 2021558Srgrimes#define setbmap(blkno) setbit(blockmap, blkno) 2031558Srgrimes#define testbmap(blkno) isset(blockmap, blkno) 2041558Srgrimes#define clrbmap(blkno) clrbit(blockmap, blkno) 2051558Srgrimes 2061558Srgrimes#define STOP 0x01 2071558Srgrimes#define SKIP 0x02 2081558Srgrimes#define KEEPON 0x04 2091558Srgrimes#define ALTERED 0x08 2101558Srgrimes#define FOUND 0x10 2111558Srgrimes 2127585Sbde/* dir.c */ 2137585Sbdevoid adjust __P((struct inodesc *idesc, short lcnt)); 2147585Sbdeint allocdir __P((ino_t parent, ino_t request, int mode)); 2157585Sbdeint changeino __P((ino_t dir, char *name, ino_t newnum)); 2167585Sbdevoid direrror __P((ino_t ino, char *errmesg)); 2177585Sbdeint dirscan __P((struct inodesc *idesc)); 2187585Sbdevoid fileerror __P((ino_t cwd, ino_t ino, char *errmesg)); 2197585Sbdeint linkup __P((ino_t orphan, ino_t parentdir)); 2207585Sbdeint makeentry __P((ino_t parent, ino_t ino, char *name)); 2217585Sbdevoid propagate __P((void)); 2227585Sbde 2237585Sbde/* ffs_subr.c */ 2247585Sbdevoid ffs_fragacct __P((struct fs *fs, int fragmap, long *fraglist, int cnt)); 2257585Sbde 2267585Sbde/* inode.c */ 2277585Sbdeino_t allocino __P((ino_t request, int type)); 2287585Sbdevoid blkerror __P((ino_t ino, char *type, daddr_t blk)); 2297585Sbdevoid cacheino __P((struct dinode *dp, ino_t inumber)); 2307585Sbdeint chkrange __P((daddr_t blk, int cnt)); 2317585Sbdeint ckinode __P((struct dinode *dp, struct inodesc *idesc)); 2327585Sbdevoid clri __P((struct inodesc *idesc, char *type, int flag)); 2337585Sbdeint findino __P((struct inodesc *idesc)); 2347585Sbdevoid freeino __P((ino_t ino)); 2357585Sbdevoid freeinodebuf __P((void)); 2367585Sbdestruct dinode * ginode __P((ino_t inumber)); 2377585Sbdestruct inoinfo * getinoinfo __P((ino_t inumber)); 2387585Sbdestruct dinode * getnextinode __P((ino_t inumber)); 2397585Sbdevoid inodirty __P((void)); 2407585Sbdevoid inocleanup __P((void)); 2417585Sbdevoid pinode __P((ino_t ino)); 2427585Sbdevoid resetinodebuf __P((void)); 2437585Sbdeint findname __P((struct inodesc *idesc)); 2447585Sbde 2457585Sbde/* pass1.c */ 2467585Sbdevoid pass1 __P((void)); 2477585Sbdeint pass1check __P((struct inodesc *idesc)); 2487585Sbde 2497585Sbde/* pass1b.c */ 2507585Sbdevoid pass1b __P((void)); 2517585Sbde 2527585Sbde/* pass2.c */ 2537585Sbdevoid pass2 __P((void)); 2547585Sbde 2557585Sbde/* pass3.c */ 2567585Sbdevoid pass3 __P((void)); 2577585Sbde 2587585Sbde/* pass4.c */ 2597585Sbdevoid pass4 __P((void)); 2607585Sbdeint pass4check __P((struct inodesc *idesc)); 2617585Sbde 2627585Sbde/* pass5.c */ 2637585Sbdevoid pass5 __P((void)); 2647585Sbde 2657585Sbde/* preen.c */ 2667585Sbdechar *blockcheck __P((char *name)); 2677585Sbdeint checkfstab __P((int preen, int maxrun,int (*docheck)(), int (*chkit)())); 2687585Sbde 2697585Sbde/* setup.c */ 2707585Sbdeint setup __P((char *dev)); 2717585Sbde 2727585Sbde/* utilities.c */ 2737585Sbdeint allocblk __P((long frags)); 2747585Sbdeint bread __P((int fd, char *buf, daddr_t blk, long size)); 2757585Sbdevoid bufinit __P((void)); 2767585Sbdevoid bwrite __P((int fd, char *buf, daddr_t blk, long size)); 2777585Sbdevoid catch __P((int)); 2787585Sbdevoid catchquit __P((int)); 2797585Sbdevoid ckfini __P((void)); 2807585Sbdeint dofix __P((struct inodesc *idesc, char *msg)); 2817585Sbde__dead void errexit __P((const char *s1, ...)) __dead2; 2827585Sbdevoid flush __P((int fd, struct bufarea *bp)); 2837585Sbdevoid freeblk __P((daddr_t blkno, long frags)); 2847585Sbdeint ftypeok __P((struct dinode *dp)); 2857585Sbdevoid getblk __P((struct bufarea *bp, daddr_t blk, long size)); 2867585Sbdestruct bufarea * getdatablk __P((daddr_t blkno, long size)); 2877585Sbdevoid getpathname __P((char *namebuf, ino_t curdir, ino_t ino)); 2887585Sbde__dead void panic __P((const char *, ...)) __dead2; 2897585Sbdevoid pfatal __P((const char *s1, ...)); 2907585Sbdevoid pwarn __P((const char *s1, ...)); 2917585Sbdeint reply __P((char *question)); 2927585Sbdevoid voidquit __P((int)); 293