pass4.c revision 1558
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
341558Srgrimes#ifndef lint
351558Srgrimesstatic char sccsid[] = "@(#)pass4.c	8.1 (Berkeley) 6/5/93";
361558Srgrimes#endif /* not lint */
371558Srgrimes
381558Srgrimes#include <sys/param.h>
391558Srgrimes#include <sys/time.h>
401558Srgrimes#include <ufs/ufs/dinode.h>
411558Srgrimes#include <ufs/ffs/fs.h>
421558Srgrimes#include <stdlib.h>
431558Srgrimes#include <string.h>
441558Srgrimes#include "fsck.h"
451558Srgrimes
461558Srgrimesint	pass4check();
471558Srgrimes
481558Srgrimespass4()
491558Srgrimes{
501558Srgrimes	register ino_t inumber;
511558Srgrimes	register struct zlncnt *zlnp;
521558Srgrimes	struct dinode *dp;
531558Srgrimes	struct inodesc idesc;
541558Srgrimes	int n;
551558Srgrimes
561558Srgrimes	bzero((char *)&idesc, sizeof(struct inodesc));
571558Srgrimes	idesc.id_type = ADDR;
581558Srgrimes	idesc.id_func = pass4check;
591558Srgrimes	for (inumber = ROOTINO; inumber <= lastino; inumber++) {
601558Srgrimes		idesc.id_number = inumber;
611558Srgrimes		switch (statemap[inumber]) {
621558Srgrimes
631558Srgrimes		case FSTATE:
641558Srgrimes		case DFOUND:
651558Srgrimes			n = lncntp[inumber];
661558Srgrimes			if (n)
671558Srgrimes				adjust(&idesc, (short)n);
681558Srgrimes			else {
691558Srgrimes				for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
701558Srgrimes					if (zlnp->zlncnt == inumber) {
711558Srgrimes						zlnp->zlncnt = zlnhead->zlncnt;
721558Srgrimes						zlnp = zlnhead;
731558Srgrimes						zlnhead = zlnhead->next;
741558Srgrimes						free((char *)zlnp);
751558Srgrimes						clri(&idesc, "UNREF", 1);
761558Srgrimes						break;
771558Srgrimes					}
781558Srgrimes			}
791558Srgrimes			break;
801558Srgrimes
811558Srgrimes		case DSTATE:
821558Srgrimes			clri(&idesc, "UNREF", 1);
831558Srgrimes			break;
841558Srgrimes
851558Srgrimes		case DCLEAR:
861558Srgrimes			dp = ginode(inumber);
871558Srgrimes			if (dp->di_size == 0) {
881558Srgrimes				clri(&idesc, "ZERO LENGTH", 1);
891558Srgrimes				break;
901558Srgrimes			}
911558Srgrimes			/* fall through */
921558Srgrimes		case FCLEAR:
931558Srgrimes			clri(&idesc, "BAD/DUP", 1);
941558Srgrimes			break;
951558Srgrimes
961558Srgrimes		case USTATE:
971558Srgrimes			break;
981558Srgrimes
991558Srgrimes		default:
1001558Srgrimes			errexit("BAD STATE %d FOR INODE I=%d",
1011558Srgrimes			    statemap[inumber], inumber);
1021558Srgrimes		}
1031558Srgrimes	}
1041558Srgrimes}
1051558Srgrimes
1061558Srgrimespass4check(idesc)
1071558Srgrimes	register struct inodesc *idesc;
1081558Srgrimes{
1091558Srgrimes	register struct dups *dlp;
1101558Srgrimes	int nfrags, res = KEEPON;
1111558Srgrimes	daddr_t blkno = idesc->id_blkno;
1121558Srgrimes
1131558Srgrimes	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
1141558Srgrimes		if (chkrange(blkno, 1)) {
1151558Srgrimes			res = SKIP;
1161558Srgrimes		} else if (testbmap(blkno)) {
1171558Srgrimes			for (dlp = duplist; dlp; dlp = dlp->next) {
1181558Srgrimes				if (dlp->dup != blkno)
1191558Srgrimes					continue;
1201558Srgrimes				dlp->dup = duplist->dup;
1211558Srgrimes				dlp = duplist;
1221558Srgrimes				duplist = duplist->next;
1231558Srgrimes				free((char *)dlp);
1241558Srgrimes				break;
1251558Srgrimes			}
1261558Srgrimes			if (dlp == 0) {
1271558Srgrimes				clrbmap(blkno);
1281558Srgrimes				n_blks--;
1291558Srgrimes			}
1301558Srgrimes		}
1311558Srgrimes	}
1321558Srgrimes	return (res);
1331558Srgrimes}
134