pass2.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 2003 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 <sys/sysmacros.h>
#define _KERNEL
#include <string.h>
#include "fsck.h"
#define MINDIRSIZE (sizeof (struct dirtemplate))
int pass2check(), blksort();
pass2()
{
int found;
int dirtype;
struct shadowclientinfo *sci;
switch (statemap[UFSROOTINO]) {
case USTATE:
pfatal("ROOT INODE UNALLOCATED");
if (reply("ALLOCATE") == 0)
errexit("");
errexit("CANNOT ALLOCATE ROOT INODE\n");
break;
case DCLEAR:
if (reply("REALLOCATE")) {
printf("pass2: DCLEAR\n");
0755) != UFSROOTINO)
errexit("CANNOT ALLOCATE ROOT INODE\n");
break;
}
if (reply("CONTINUE") == 0)
errexit("");
break;
case FSTATE:
case FCLEAR:
case SSTATE:
case SCLEAR:
pfatal("ROOT INODE NOT DIRECTORY");
if (reply("REALLOCATE")) {
0755) != UFSROOTINO)
errexit("CANNOT ALLOCATE ROOT INODE\n");
break;
}
if (reply("FIX") == 0)
errexit("");
inodirty();
break;
case DSTATE:
break;
default:
}
/*
* Sort the directory list into disk block order.
*/
/*
* Check the integrity of each directory.
*/
continue;
continue;
inodirty();
}
}
pwarn("DIRECTORY %s: LENGTH %lld NOT MULTIPLE OF %d",
if (preen)
printf(" (ADJUSTED)\n");
inodirty();
}
}
/*
* Make sure we mark attrdirs as DFOUND, since the won't
* be located during normal scan of standard directories.
*/
if (dpattr &&
}
}
}
}
}
/*
* Now that the parents of all directories have been found,
* make another pass to verify the value of `..'
*/
continue;
continue;
continue;
if (reply("FIX") == 0)
continue;
found = 0;
/*
* See if this is an attrdir that we located in pass1.
* i.e. it was on an i_oeftflag of some other inode.
* if it isn't found then we have an orphaned attrdir
* that needs to be tossed into lost+found.
*/
found = 1;
}
}
}
/*
* is it an orphaned attrdir?
*/
/*
* Throw it into lost+found
*/
pwarn("Unable to move attrdir"
" I=%d to lost+found\n",
}
inodirty();
}
continue;
}
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
iscorrupt = 1;
continue;
}
continue;
"BAD INODE NUMBER FOR '..'");
if (reply("FIX") == 0)
continue;
}
/*
* Mark all the directories that can be found from the root.
*/
propagate();
}
{
char *errmsg;
int isattr = 0;
int dirtype = 0;
int breakout = 0;
int dontreconnect = 0;
/*
* check for "."
*/
if (idesc->id_entryno != 0)
goto chk1;
}
goto chk1;
}
pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
iscorrupt = 1;
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
iscorrupt = 1;
} else {
idesc->id_entryno++;
}
chk1:
goto chk2;
if (idesc->id_entryno == 0) {
goto chk2;
idesc->id_entryno++;
} else {
"I OUT OF RANGE");
n = reply("REMOVE");
}
}
goto chk2;
}
pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
iscorrupt = 1;
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
iscorrupt = 1;
/*
* We know the parent, so fix now.
*/
/*
* Always know parent of root inode, so fix now.
*/
}
idesc->id_entryno++;
chk2:
}
}
}
idesc->id_entryno++;
n = 0;
n = reply("REMOVE");
} else {
case USTATE:
break;
n = reply("REMOVE");
break;
case DCLEAR:
case FCLEAR:
case SCLEAR:
break;
"ZERO LENGTH ATTRIBUTE DIRECTORY" :
"ZERO LENGTH DIRECTORY";
errmsg = "ZERO LENGTH ACL";
else
break;
goto again;
case DSTATE:
/* fall through */
case DFOUND:
"IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
namebuf);
if (preen)
printf(" (IGNORED)\n");
break;
}
/* fall through */
case FSTATE:
/*
* For extended attribute directories .. may point
* to a file. In this situation we don't want
* to decrement link count as it was already
* decremented when entry was seen and decremented
* in the directory it actually lives in.
*/
n = 0;
if (dp->di_oeftflag != 0) {
/*
* is it really an attrdir?
* if so then don't do anything.
*/
dontreconnect = 1;
} else {
dontreconnect = 0;
}
/*
* Lets see if we have an orphaned attrdir
* that thinks it belongs to this file?
* Only re-connect it, if the current
* attrdir is 0 or not an attrdir.
*/
(dontreconnect == 0)) {
"Attribute directory not attached"
" to file");
dp->di_oeftflag =
inodirty();
}
}
if (n != 0)
/*
* don't screw up links counts for directories.
* If we aren't careful we can perform
* an extra decrement, since the .. of
* an attrdir could be either a file or a
* directory. If its a file then its link
* should be correct after it is seen when the
* directory it lives in scanned.
*/
breakout = 1;
breakout = 1;
} else {
"File should NOT be marked as "
"extended attribute");
IFATTRDIR) {
inodirty();
if (
!= 0) {
pdirp->di_oeftflag = 0;
inodirty();
}
} else
inodirty();
}
} else {
(isattr == 0)) {
"File should BE marked as "
"extended attribute");
inodirty();
}
}
}
}
if (breakout == 0 || dontreconnect == 0) {
if (n != 0)
}
break;
case SSTATE:
errmsg = "ACL IN DIRECTORY";
n = reply("REMOVE");
break;
default:
errexit("BAD STATE %d FOR INODE I=%d",
}
}
if (n == 0)
}
/*
* Routine to sort disk blocks.
*/
{
}