122057Sdist /* 222057Sdist * Copyright (c) 1980 Regents of the University of California. 322057Sdist * All rights reserved. The Berkeley software License Agreement 422057Sdist * specifies the terms and conditions for redistribution. 522057Sdist * 6*36827Smckusick * @(#)fsck.h 5.8 (Berkeley) 02/17/89 722057Sdist */ 816260Smckusick 934225Smckusick #define MAXDUP 10 /* limit on dup blks (per inode) */ 1034225Smckusick #define MAXBAD 10 /* limit on bad blks (per inode) */ 1134225Smckusick #define MAXBUFSPACE 128*1024 /* maximum space to allocate to buffers */ 1216260Smckusick 1316260Smckusick typedef int (*SIG_TYP)(); 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 2616260Smckusick typedef struct dinode DINODE; 2716260Smckusick typedef struct direct DIRECT; 2816260Smckusick 2917930Smckusick #define ALLOC(dip) (((dip)->di_mode & IFMT) != 0) 3017930Smckusick #define DIRCT(dip) (((dip)->di_mode & IFMT) == IFDIR) 3117930Smckusick #define SPECIAL(dip) \ 3217930Smckusick (((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR) 3316260Smckusick 3434225Smckusick /* 3534225Smckusick * buffer cache structure. 3634225Smckusick */ 3716260Smckusick struct bufarea { 3834225Smckusick struct bufarea *b_next; /* free list queue */ 3934225Smckusick struct bufarea *b_prev; /* free list queue */ 4016260Smckusick daddr_t b_bno; 4116260Smckusick int b_size; 4221540Smckusick int b_errs; 4334225Smckusick int b_flags; 4416260Smckusick union { 4534225Smckusick char *b_buf; /* buffer space */ 4634225Smckusick daddr_t *b_indir; /* indirect block */ 4734225Smckusick struct fs *b_fs; /* super block */ 4834225Smckusick struct cg *b_cg; /* cylinder group */ 4934225Smckusick struct dinode *b_dinode; /* inode block */ 5016260Smckusick } b_un; 5116260Smckusick char b_dirty; 5216260Smckusick }; 5316260Smckusick 5434225Smckusick #define B_INUSE 1 5516260Smckusick typedef struct bufarea BUFAREA; 5616260Smckusick 5734225Smckusick #define MINBUFS 5 /* minimum number of buffers required */ 5834225Smckusick BUFAREA bufhead; /* head of list of other blks in filesys */ 5916260Smckusick BUFAREA sblk; /* file system superblock */ 6016260Smckusick BUFAREA cgblk; /* cylinder group blocks */ 6134225Smckusick BUFAREA *getdatablk(); 6216260Smckusick 6316260Smckusick #define dirty(x) (x)->b_dirty = 1 6434225Smckusick #define initbarea(x) \ 6534225Smckusick (x)->b_dirty = 0; \ 6634225Smckusick (x)->b_bno = (daddr_t)-1; \ 6734225Smckusick (x)->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 7416260Smckusick struct filecntl { 7516260Smckusick int rfdes; 7616260Smckusick int wfdes; 7716260Smckusick int mod; 7816260Smckusick } dfile; /* file descriptors for filesys */ 7916260Smckusick 8017930Smckusick enum fixstate {DONTKNOW, NOFIX, FIX}; 8117930Smckusick 8216260Smckusick struct inodesc { 8317930Smckusick enum fixstate id_fix; /* policy on fixing errors */ 8416260Smckusick int (*id_func)(); /* function to be applied to blocks of inode */ 8516260Smckusick ino_t id_number; /* inode number described */ 8616260Smckusick ino_t id_parent; /* for DATA nodes, their parent */ 8716260Smckusick daddr_t id_blkno; /* current block number being examined */ 8816260Smckusick int id_numfrags; /* number of frags contained in block */ 8916260Smckusick long id_filesize; /* for DATA nodes, the size of the directory */ 9016260Smckusick int id_loc; /* for DATA nodes, current location in dir */ 9116260Smckusick int id_entryno; /* for DATA nodes, current entry number */ 9217930Smckusick DIRECT *id_dirp; /* for DATA nodes, ptr to current entry */ 9317930Smckusick char *id_name; /* for DATA nodes, name to find or enter */ 9417930Smckusick char id_type; /* type of descriptor, DATA or ADDR */ 9516260Smckusick }; 9616260Smckusick /* file types */ 9716260Smckusick #define DATA 1 9816260Smckusick #define ADDR 2 9916260Smckusick 10021743Smckusick /* 10121759Smckusick * Linked list of duplicate blocks. 10221759Smckusick * 10321759Smckusick * The list is composed of two parts. The first part of the 10421759Smckusick * list (from duplist through the node pointed to by muldup) 10521759Smckusick * contains a single copy of each duplicate block that has been 10621759Smckusick * found. The second part of the list (from muldup to the end) 10721759Smckusick * contains duplicate blocks that have been found more than once. 10821759Smckusick * To check if a block has been found as a duplicate it is only 10921759Smckusick * necessary to search from duplist through muldup. To find the 11021759Smckusick * total number of times that a block has been found as a duplicate 11121759Smckusick * the entire list must be searched for occurences of the block 11221759Smckusick * in question. The following diagram shows a sample list where 11321759Smckusick * w (found twice), x (found once), y (found three times), and z 11421759Smckusick * (found once) are duplicate block numbers: 11521759Smckusick * 11621759Smckusick * w -> y -> x -> z -> y -> w -> y 11721759Smckusick * ^ ^ 11821759Smckusick * | | 11921759Smckusick * duplist muldup 12021743Smckusick */ 12121743Smckusick struct dups { 12221743Smckusick struct dups *next; 12321743Smckusick daddr_t dup; 12421743Smckusick }; 12521743Smckusick struct dups *duplist; /* head of dup list */ 12621743Smckusick struct dups *muldup; /* end of unique duplicate dup block numbers */ 12716260Smckusick 12821759Smckusick /* 12921759Smckusick * Linked list of inodes with zero link counts. 13021759Smckusick */ 13121759Smckusick struct zlncnt { 13221759Smckusick struct zlncnt *next; 13321759Smckusick ino_t zlncnt; 13421759Smckusick }; 13521759Smckusick struct zlncnt *zlnhead; /* head of zero link count list */ 13616260Smckusick 13716260Smckusick char rawflg; 13816260Smckusick char *devname; 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 */ 14916260Smckusick 15016260Smckusick char *blockmap; /* ptr to primary blk allocation map */ 15116260Smckusick char *statemap; /* ptr to inode state table */ 15216260Smckusick short *lncntp; /* ptr to link count table */ 15316260Smckusick 15416260Smckusick char pathname[BUFSIZ]; /* current pathname */ 15516260Smckusick char *pathp; /* pointer to pathname position */ 15616260Smckusick char *endpathname; 15716260Smckusick 15817930Smckusick daddr_t fmax; /* number of blocks in the volume */ 15916260Smckusick ino_t imax; /* number of inodes */ 16016260Smckusick ino_t lastino; /* hiwater mark of inodes */ 16117930Smckusick ino_t lfdir; /* lost & found directory inode number */ 16217930Smckusick char *lfname; /* lost & found directory name */ 163*36827Smckusick int lfmode; /* lost & found directory creation mode */ 16416260Smckusick 16516260Smckusick off_t maxblk; /* largest logical blk in file */ 16616260Smckusick off_t bmapsz; /* num chars in blockmap */ 16716260Smckusick 16816260Smckusick daddr_t n_blks; /* number of blocks used */ 16916260Smckusick daddr_t n_files; /* number of files seen */ 17016260Smckusick 17116260Smckusick #define zapino(x) (*(x) = zino) 17216260Smckusick struct dinode zino; 17316260Smckusick 17416260Smckusick #define setbmap(x) setbit(blockmap, x) 17516260Smckusick #define getbmap(x) isset(blockmap, x) 17616260Smckusick #define clrbmap(x) clrbit(blockmap, x) 17716260Smckusick 17830354Smckusick #define FOUND 020 17916260Smckusick #define ALTERED 010 18016260Smckusick #define KEEPON 04 18116260Smckusick #define SKIP 02 18216260Smckusick #define STOP 01 18316260Smckusick 18416260Smckusick time_t time(); 18516260Smckusick DINODE *ginode(); 18616260Smckusick BUFAREA *getblk(); 18716260Smckusick int findino(); 188