Home | History | Annotate | Line # | Download | only in fsck_ext2fs
pass4.c revision 1.2
      1 /*	$NetBSD: pass4.c,v 1.2 1997/09/14 14:27:29 lukem Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Manuel Bouyer.
      5  * Copyright (c) 1980, 1986, 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the University of
     19  *	California, Berkeley and its contributors.
     20  * 4. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 #ifndef lint
     39 #if 0
     40 static char sccsid[] = "@(#)pass4.c	8.1 (Berkeley) 6/5/93";
     41 #else
     42 __RCSID("$NetBSD: pass4.c,v 1.2 1997/09/14 14:27:29 lukem Exp $");
     43 #endif
     44 #endif /* not lint */
     45 
     46 #include <sys/param.h>
     47 #include <sys/time.h>
     48 #include <ufs/ext2fs/ext2fs_dinode.h>
     49 #include <ufs/ext2fs/ext2fs.h>
     50 #include <stdlib.h>
     51 #include <string.h>
     52 
     53 #include "fsutil.h"
     54 #include "fsck.h"
     55 #include "extern.h"
     56 
     57 void
     58 pass4()
     59 {
     60 	ino_t inumber;
     61 	struct zlncnt *zlnp;
     62 	struct ext2fs_dinode *dp;
     63 	struct inodesc idesc;
     64 	int n;
     65 
     66 	memset(&idesc, 0, sizeof(struct inodesc));
     67 	idesc.id_type = ADDR;
     68 	idesc.id_func = pass4check;
     69 	for (inumber = EXT2_ROOTINO; inumber <= lastino; inumber++) {
     70 		if (inumber < EXT2_FIRSTINO && inumber > EXT2_ROOTINO)
     71 			continue;
     72 		idesc.id_number = inumber;
     73 		switch (statemap[inumber]) {
     74 
     75 		case FSTATE:
     76 		case DFOUND:
     77 			n = lncntp[inumber];
     78 			if (n)
     79 				adjust(&idesc, (short)n);
     80 			else {
     81 				for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
     82 					if (zlnp->zlncnt == inumber) {
     83 						zlnp->zlncnt = zlnhead->zlncnt;
     84 						zlnp = zlnhead;
     85 						zlnhead = zlnhead->next;
     86 						free((char *)zlnp);
     87 						clri(&idesc, "UNREF", 1);
     88 						break;
     89 					}
     90 			}
     91 			break;
     92 
     93 		case DSTATE:
     94 			clri(&idesc, "UNREF", 1);
     95 			break;
     96 
     97 		case DCLEAR:
     98 			dp = ginode(inumber);
     99 			if (dp->e2di_size == 0) {
    100 				clri(&idesc, "ZERO LENGTH", 1);
    101 				break;
    102 			}
    103 			/* fall through */
    104 		case FCLEAR:
    105 			clri(&idesc, "BAD/DUP", 1);
    106 			break;
    107 
    108 		case USTATE:
    109 			break;
    110 
    111 		default:
    112 			errexit("BAD STATE %d FOR INODE I=%d\n",
    113 			    statemap[inumber], inumber);
    114 		}
    115 	}
    116 }
    117 
    118 int
    119 pass4check(idesc)
    120 	struct inodesc *idesc;
    121 {
    122 	struct dups *dlp;
    123 	int nfrags, res = KEEPON;
    124 	daddr_t blkno = idesc->id_blkno;
    125 
    126 	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
    127 		if (chkrange(blkno, 1)) {
    128 			res = SKIP;
    129 		} else if (testbmap(blkno)) {
    130 			for (dlp = duplist; dlp; dlp = dlp->next) {
    131 				if (dlp->dup != blkno)
    132 					continue;
    133 				dlp->dup = duplist->dup;
    134 				dlp = duplist;
    135 				duplist = duplist->next;
    136 				free((char *)dlp);
    137 				break;
    138 			}
    139 			if (dlp == 0) {
    140 				clrbmap(blkno);
    141 				n_blks--;
    142 			}
    143 		}
    144 	}
    145 	return (res);
    146 }
    147