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