pass4.c revision 77a343ab1b2bc518f178bc7b473e770e3da2bb79
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "fsck.h"
void
pass4(void)
{
int n, was_dir;
int need_rescan;
int scan_pass = 0;
/*
* If we clear a directory, it may have produced orphans which
* we need to go pick up. So, do this until done. It can be
* proven that the loop terminates because at most there can
* be lastino directories, and we only rescan if we clear a
* directory.
*/
do {
if (debug)
need_rescan = 0;
| INZLINK)) {
case FZLINK:
case DZLINK:
/*
* INZLINK gets set if the inode claimed zero
* links when we first looked at it in pass 1.
* If lncntp[] also claims it has zero links,
* it really is unreferenced. However, we
* could have found a link to it during one of
* the other passes, so we have to check the
* final count in lncntp[].
*/
if (was_dir &&
need_rescan = 1;
break;
}
/* FALLTHROUGH */
case FSTATE:
case DFOUND:
case SSTATE:
/*
* adjust() will clear the inode if
* the link count goes to zero. If
* it isn't cleared, we need to note
* that we've adjusted the count
* already, so we don't do it again
* on a rescan.
*/
if (was_dir &&
need_rescan = 1;
} else {
}
}
break;
case DSTATE:
need_rescan = 1;
break;
case DCLEAR:
break;
}
/* FALLTHROUGH */
case FCLEAR:
break;
case SCLEAR:
break;
case USTATE:
break;
default:
errexit("BAD STATE 0x%x FOR INODE I=%d",
}
}
} while (need_rescan);
}
int
{
int cylno;
if (debug)
(void) printf(
"pass4check: skipping inode %d lbn %d with truncto %d\n",
idesc->id_truncto);
return (KEEPON);
}
/*
* The block's in use. Remove our reference
* from it.
*
* If it wasn't a dup, or everybody's done with
* it, then this is the last reference and it's
* safe to actually deallocate the on-disk block.
*
* We depend on pass 5 resolving the on-disk bitmap
* effects.
*/
DB_DECR)) {
if (debug)
(void) printf("p4c marking %d avail\n",
cg_frag);
n_blks--;
/*
* Do the same for the on-disk bitmap, so
* that we don't need another pass to figure
* out what's really being used. We'll let
* accounting.
*/
if (reply("REPAIR") == 0)
errexit("Program terminated.");
}
cgdirty();
}
}
}
return (res);
}