statemap[inp->i_child->i_number] == DSTATE)
statemap[inp->i_child->i_number] != state)
static struct direct *fsck_readdir __P((struct inodesc *));static struct bufarea *getdirblk __P((daddr_t, long));static int lftempname __P((char *, ino_t));static int mkentry __P((struct inodesc *));static int chgino __P((struct  inodesc *));/* * Propagate connected state through the tree. */voidpropagate(){	register struct inoinfo **inpp, *inp, *pinp;	struct inoinfo **inpend;	/*	 * Create a list of children for each directory.	 */	inpend = &inpsort[inplast];	for (inpp = inpsort; inpp < inpend; inpp++) {		inp = *inpp;		if (inp->i_parent == 0 ||		    inp->i_number == ROOTINO)			continue;		pinp = getinoinfo(inp->i_parent);		inp->i_parentp = pinp;		inp->i_sibling = pinp->i_child;		pinp->i_child = inp;	}	inp = getinoinfo(ROOTINO);	while (inp) {		statemap[inp->i_number] = DFOUND;		if (inp->i_child &&		    statemap[inp->i_child->i_number] == DSTATE)			inp = inp->i_child;		else if (inp->i_sibling)			inp = inp->i_sibling;		else			inp = inp->i_parentp;	}}/* * Scan each entry in a directory block. */intdirscan(idesc)	register struct inodesc *idesc;{	register struct direct *dp;	register struct bufarea *bp;	int dsize, n;	long blksiz;	char dbuf[DIRBLKSIZ];	if (idesc->id_type != DATA)		errexit("wrong type to dirscan %d\n", idesc->id_type);	if (idesc->id_entryno == 0 &&	    (idesc->id_filesize & (DIRBLKSIZ - 1)) != 0)		idesc->id_filesize = roundup(idesc->id_filesize, DIRBLKSIZ);	blksiz = idesc->id_numfrags * sblock.fs_fsize;	if (chkrange(idesc->id_blkno, idesc->id_numfrags)) {		idesc->id_filesize -= blksiz;		return (SKIP);	}	idesc->id_loc = 0;	for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) {		dsize = dp->d_reclen;		memcpy(dbuf, dp, (size_t)dsize);#		if (BYTE_ORDER == LITTLE_ENDIAN)			if (!newinofmt) {				struct direct *tdp = (struct direct *)dbuf;				u_char tmp;				tmp = tdp->d_namlen;				tdp->d_namlen = tdp->d_type;				tdp->d_type = tmp;			}#		endif		idesc->id_dirp = (struct direct *)dbuf;		if ((n = (*idesc->id_func)(idesc)) & ALTERED) {#			if (BYTE_ORDER == LITTLE_ENDIAN)				if (!newinofmt && !doinglevel2) {					struct direct *tdp;					u_char tmp;					tdp = (struct direct *)dbuf;					tmp = tdp->d_namlen;					tdp->d_namlen = tdp->d_type;					tdp->d_type = tmp;				}#			endif			bp = getdirblk(idesc->id_blkno, blksiz);			memcpy(bp->b_un.b_buf + idesc->id_loc - dsize, dbuf,			    (size_t)dsize);			dirty(bp);			sbdirty();		}		if (n & STOP) 			return (n);	}	return (idesc->id_filesize > 0 ? KEEPON : STOP);}/* * get next entry in a directory. */static struct direct *fsck_readdir(idesc)	register struct inodesc *idesc;{	register struct direct *dp, *ndp;	register struct bufarea *bp;	long size, blksiz, fix, dploc;	blksiz = idesc->id_numfrags * sblock.fs_fsize;	bp = getdirblk(idesc->id_blkno, blksiz);	if (idesc->id_loc % DIRBLKSIZ == 0 && idesc->id_filesize > 0 &&	    idesc->id_loc < blksiz) {		dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);		if (dircheck(idesc, dp))			goto dpok;		if (idesc->id_fix == IGNORE)			return (0);		fix = dofix(idesc, "DIRECTORY CORRUPTED");		bp = getdirblk(idesc->id_blkno, blksiz);		dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);		dp->d_reclen = DIRBLKSIZ;		dp->d_ino = 0;		dp->d_type = 0;		dp->d_namlen = 0;		dp->d_name[0] = '\0';		if (fix)			dirty(bp);		idesc->id_loc += DIRBLKSIZ;		idesc->id_filesize -= DIRBLKSIZ;		return (dp);	}dpok:	if (idesc->id_filesize <= 0 || idesc->id_loc >= blksiz)		return NULL;	dploc = idesc->id_loc;	dp = (struct direct *)(bp->b_un.b_buf + dploc);	idesc->id_loc += dp->d_reclen;	idesc->id_filesize -= dp->d_reclen;	if ((idesc->id_loc % DIRBLKSIZ) == 0)		return (dp);	ndp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);	if (idesc->id_loc < blksiz && idesc->id_filesize > 0 &&	    dircheck(idesc, ndp) == 0) {		size = DIRBLKSIZ - (idesc->id_loc % DIRBLKSIZ);		idesc->id_loc += size;		idesc->id_filesize -= size;		if (idesc->id_fix == IGNORE)			return (0);		fix = dofix(idesc, "DIRECTORY CORRUPTED");		bp = getdirblk(idesc->id_blkno, blksiz);		dp = (struct direct *)(bp->b_un.b_buf + dploc);		dp->d_reclen += size;		if (fix)			dirty(bp);	}	return (dp);}