1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1998-12-03 02:41:11 +00:00
|
|
|
#if 0
|
2002-08-25 13:10:45 +00:00
|
|
|
#ifndef lint
|
1997-03-11 12:20:21 +00:00
|
|
|
static const char sccsid[] = "@(#)pass2.c 8.9 (Berkeley) 4/28/95";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
2002-08-25 13:10:45 +00:00
|
|
|
#endif
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
1997-03-11 12:20:21 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ufs/dir.h>
|
2001-03-21 09:48:03 +00:00
|
|
|
#include <ufs/ffs/fs.h>
|
1997-03-12 17:01:11 +00:00
|
|
|
|
1997-03-11 12:20:21 +00:00
|
|
|
#include <err.h>
|
2002-07-31 12:01:14 +00:00
|
|
|
#include <stdint.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <string.h>
|
1997-03-11 12:20:21 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#include "fsck.h"
|
|
|
|
|
|
|
|
#define MINDIRSIZE (sizeof (struct dirtemplate))
|
|
|
|
|
2002-03-20 22:57:10 +00:00
|
|
|
static int blksort(const void *, const void *);
|
|
|
|
static int pass2check(struct inodesc *);
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1995-04-02 14:52:29 +00:00
|
|
|
void
|
2002-03-20 22:57:10 +00:00
|
|
|
pass2(void)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode *dp;
|
2002-03-20 17:55:10 +00:00
|
|
|
struct inoinfo **inpp, *inp;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct inoinfo **inpend;
|
|
|
|
struct inodesc curino;
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode dino;
|
|
|
|
int i;
|
1994-05-26 06:35:07 +00:00
|
|
|
char pathbuf[MAXPATHLEN + 1];
|
|
|
|
|
1998-12-03 02:27:35 +00:00
|
|
|
switch (inoinfo(ROOTINO)->ino_state) {
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
case USTATE:
|
|
|
|
pfatal("ROOT INODE UNALLOCATED");
|
1998-03-08 09:59:44 +00:00
|
|
|
if (reply("ALLOCATE") == 0) {
|
|
|
|
ckfini(0);
|
1997-03-11 12:20:21 +00:00
|
|
|
exit(EEXIT);
|
1998-03-08 09:59:44 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
|
1997-03-11 12:20:21 +00:00
|
|
|
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DCLEAR:
|
|
|
|
pfatal("DUPS/BAD IN ROOT INODE");
|
|
|
|
if (reply("REALLOCATE")) {
|
|
|
|
freeino(ROOTINO);
|
|
|
|
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
|
1997-03-11 12:20:21 +00:00
|
|
|
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-03-08 09:59:44 +00:00
|
|
|
if (reply("CONTINUE") == 0) {
|
|
|
|
ckfini(0);
|
1997-03-11 12:20:21 +00:00
|
|
|
exit(EEXIT);
|
1998-03-08 09:59:44 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FSTATE:
|
|
|
|
case FCLEAR:
|
|
|
|
pfatal("ROOT INODE NOT DIRECTORY");
|
|
|
|
if (reply("REALLOCATE")) {
|
|
|
|
freeino(ROOTINO);
|
|
|
|
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
|
1997-03-11 12:20:21 +00:00
|
|
|
errx(EEXIT, "CANNOT ALLOCATE ROOT INODE");
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-03-08 09:59:44 +00:00
|
|
|
if (reply("FIX") == 0) {
|
|
|
|
ckfini(0);
|
1997-03-11 12:20:21 +00:00
|
|
|
exit(EEXIT);
|
1998-03-08 09:59:44 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
dp = ginode(ROOTINO);
|
2002-06-21 06:18:05 +00:00
|
|
|
DIP(dp, di_mode) &= ~IFMT;
|
|
|
|
DIP(dp, di_mode) |= IFDIR;
|
1994-05-26 06:35:07 +00:00
|
|
|
inodirty();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSTATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1998-12-03 02:27:35 +00:00
|
|
|
errx(EEXIT, "BAD STATE %d FOR ROOT INODE",
|
|
|
|
inoinfo(ROOTINO)->ino_state);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(ROOTINO)->ino_state = DFOUND;
|
2002-05-12 23:44:15 +00:00
|
|
|
inoinfo(WINO)->ino_state = FSTATE;
|
|
|
|
inoinfo(WINO)->ino_type = DT_WHT;
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Sort the directory list into disk block order.
|
|
|
|
*/
|
|
|
|
qsort((char *)inpsort, (size_t)inplast, sizeof *inpsort, blksort);
|
|
|
|
/*
|
|
|
|
* Check the integrity of each directory.
|
|
|
|
*/
|
1997-03-11 12:20:21 +00:00
|
|
|
memset(&curino, 0, sizeof(struct inodesc));
|
1994-05-26 06:35:07 +00:00
|
|
|
curino.id_type = DATA;
|
|
|
|
curino.id_func = pass2check;
|
|
|
|
inpend = &inpsort[inplast];
|
|
|
|
for (inpp = inpsort; inpp < inpend; inpp++) {
|
2000-12-15 14:23:55 +00:00
|
|
|
if (got_siginfo) {
|
2002-07-31 12:01:14 +00:00
|
|
|
printf("%s: phase 2: dir %td of %d (%d%%)\n", cdevname,
|
2001-11-17 23:48:21 +00:00
|
|
|
inpp - inpsort, (int)inplast,
|
|
|
|
(int)((inpp - inpsort) * 100 / inplast));
|
2000-12-15 14:23:55 +00:00
|
|
|
got_siginfo = 0;
|
|
|
|
}
|
2004-02-28 07:50:42 +00:00
|
|
|
if (got_sigalarm) {
|
|
|
|
setproctitle("%s p2 %d%%", cdevname,
|
|
|
|
(int)((inpp - inpsort) * 100 / inplast));
|
|
|
|
got_sigalarm = 0;
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
inp = *inpp;
|
|
|
|
if (inp->i_isize == 0)
|
|
|
|
continue;
|
|
|
|
if (inp->i_isize < MINDIRSIZE) {
|
|
|
|
direrror(inp->i_number, "DIRECTORY TOO SHORT");
|
|
|
|
inp->i_isize = roundup(MINDIRSIZE, DIRBLKSIZ);
|
|
|
|
if (reply("FIX") == 1) {
|
|
|
|
dp = ginode(inp->i_number);
|
2002-06-21 06:18:05 +00:00
|
|
|
DIP(dp, di_size) = inp->i_isize;
|
1994-05-26 06:35:07 +00:00
|
|
|
inodirty();
|
|
|
|
}
|
|
|
|
} else if ((inp->i_isize & (DIRBLKSIZ - 1)) != 0) {
|
|
|
|
getpathname(pathbuf, inp->i_number, inp->i_number);
|
1998-03-08 09:59:44 +00:00
|
|
|
if (usedsoftdep)
|
2002-07-31 12:01:14 +00:00
|
|
|
pfatal("%s %s: LENGTH %jd NOT MULTIPLE OF %d",
|
|
|
|
"DIRECTORY", pathbuf,
|
|
|
|
(intmax_t)inp->i_isize, DIRBLKSIZ);
|
1998-03-08 09:59:44 +00:00
|
|
|
else
|
2002-07-31 12:01:14 +00:00
|
|
|
pwarn("%s %s: LENGTH %jd NOT MULTIPLE OF %d",
|
|
|
|
"DIRECTORY", pathbuf,
|
|
|
|
(intmax_t)inp->i_isize, DIRBLKSIZ);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (preen)
|
|
|
|
printf(" (ADJUSTED)\n");
|
|
|
|
inp->i_isize = roundup(inp->i_isize, DIRBLKSIZ);
|
|
|
|
if (preen || reply("ADJUST") == 1) {
|
|
|
|
dp = ginode(inp->i_number);
|
2002-06-21 06:18:05 +00:00
|
|
|
DIP(dp, di_size) =
|
|
|
|
roundup(inp->i_isize, DIRBLKSIZ);
|
1994-05-26 06:35:07 +00:00
|
|
|
inodirty();
|
|
|
|
}
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
dp = &dino;
|
|
|
|
memset(dp, 0, sizeof(struct ufs2_dinode));
|
|
|
|
DIP(dp, di_mode) = IFDIR;
|
|
|
|
DIP(dp, di_size) = inp->i_isize;
|
|
|
|
for (i = 0;
|
|
|
|
i < (inp->i_numblks<NDADDR ? inp->i_numblks : NDADDR);
|
|
|
|
i++)
|
|
|
|
DIP(dp, di_db[i]) = inp->i_blks[i];
|
|
|
|
if (inp->i_numblks > NDADDR)
|
|
|
|
for (i = 0; i < NIADDR; i++)
|
|
|
|
DIP(dp, di_ib[i]) = inp->i_blks[NDADDR + i];
|
1994-05-26 06:35:07 +00:00
|
|
|
curino.id_number = inp->i_number;
|
|
|
|
curino.id_parent = inp->i_parent;
|
|
|
|
(void)ckinode(dp, &curino);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now that the parents of all directories have been found,
|
|
|
|
* make another pass to verify the value of `..'
|
|
|
|
*/
|
|
|
|
for (inpp = inpsort; inpp < inpend; inpp++) {
|
|
|
|
inp = *inpp;
|
|
|
|
if (inp->i_parent == 0 || inp->i_isize == 0)
|
|
|
|
continue;
|
1998-12-03 02:27:35 +00:00
|
|
|
if (inoinfo(inp->i_parent)->ino_state == DFOUND &&
|
|
|
|
inoinfo(inp->i_number)->ino_state == DSTATE)
|
|
|
|
inoinfo(inp->i_number)->ino_state = DFOUND;
|
1994-05-26 06:35:07 +00:00
|
|
|
if (inp->i_dotdot == inp->i_parent ||
|
|
|
|
inp->i_dotdot == (ino_t)-1)
|
|
|
|
continue;
|
|
|
|
if (inp->i_dotdot == 0) {
|
|
|
|
inp->i_dotdot = inp->i_parent;
|
|
|
|
fileerror(inp->i_parent, inp->i_number, "MISSING '..'");
|
|
|
|
if (reply("FIX") == 0)
|
|
|
|
continue;
|
|
|
|
(void)makeentry(inp->i_number, inp->i_parent, "..");
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(inp->i_parent)->ino_linkcnt--;
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fileerror(inp->i_parent, inp->i_number,
|
|
|
|
"BAD INODE NUMBER FOR '..'");
|
|
|
|
if (reply("FIX") == 0)
|
|
|
|
continue;
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(inp->i_dotdot)->ino_linkcnt++;
|
|
|
|
inoinfo(inp->i_parent)->ino_linkcnt--;
|
1994-05-26 06:35:07 +00:00
|
|
|
inp->i_dotdot = inp->i_parent;
|
|
|
|
(void)changeino(inp->i_number, "..", inp->i_parent);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Mark all the directories that can be found from the root.
|
|
|
|
*/
|
|
|
|
propagate();
|
|
|
|
}
|
|
|
|
|
1997-03-11 12:20:21 +00:00
|
|
|
static int
|
2002-03-20 22:57:10 +00:00
|
|
|
pass2check(struct inodesc *idesc)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-03-20 17:55:10 +00:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
|
|
|
struct inoinfo *inp;
|
1994-05-26 06:35:07 +00:00
|
|
|
int n, entrysize, ret = 0;
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode *dp;
|
2002-07-30 13:01:25 +00:00
|
|
|
const char *errmsg;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct direct proto;
|
|
|
|
char namebuf[MAXPATHLEN + 1];
|
|
|
|
char pathbuf[MAXPATHLEN + 1];
|
|
|
|
|
1995-05-30 06:12:45 +00:00
|
|
|
/*
|
1994-05-26 06:35:07 +00:00
|
|
|
* check for "."
|
|
|
|
*/
|
|
|
|
if (idesc->id_entryno != 0)
|
|
|
|
goto chk1;
|
|
|
|
if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) {
|
|
|
|
if (dirp->d_ino != idesc->id_number) {
|
|
|
|
direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
|
|
|
|
dirp->d_ino = idesc->id_number;
|
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
}
|
2002-05-12 23:44:15 +00:00
|
|
|
if (dirp->d_type != DT_DIR) {
|
1994-05-26 06:35:07 +00:00
|
|
|
direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'");
|
|
|
|
dirp->d_type = DT_DIR;
|
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
}
|
|
|
|
goto chk1;
|
|
|
|
}
|
|
|
|
direrror(idesc->id_number, "MISSING '.'");
|
|
|
|
proto.d_ino = idesc->id_number;
|
2002-05-12 23:44:15 +00:00
|
|
|
proto.d_type = DT_DIR;
|
1994-05-26 06:35:07 +00:00
|
|
|
proto.d_namlen = 1;
|
|
|
|
(void)strcpy(proto.d_name, ".");
|
|
|
|
entrysize = DIRSIZ(0, &proto);
|
|
|
|
if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) {
|
|
|
|
pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
|
|
|
|
dirp->d_name);
|
|
|
|
} else if (dirp->d_reclen < entrysize) {
|
|
|
|
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
|
|
|
|
} else if (dirp->d_reclen < 2 * entrysize) {
|
|
|
|
proto.d_reclen = dirp->d_reclen;
|
1997-03-11 12:20:21 +00:00
|
|
|
memmove(dirp, &proto, (size_t)entrysize);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
} else {
|
|
|
|
n = dirp->d_reclen - entrysize;
|
|
|
|
proto.d_reclen = entrysize;
|
1997-03-11 12:20:21 +00:00
|
|
|
memmove(dirp, &proto, (size_t)entrysize);
|
1994-05-26 06:35:07 +00:00
|
|
|
idesc->id_entryno++;
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(dirp->d_ino)->ino_linkcnt--;
|
1994-05-26 06:35:07 +00:00
|
|
|
dirp = (struct direct *)((char *)(dirp) + entrysize);
|
1997-03-11 12:20:21 +00:00
|
|
|
memset(dirp, 0, (size_t)n);
|
1994-05-26 06:35:07 +00:00
|
|
|
dirp->d_reclen = n;
|
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
}
|
|
|
|
chk1:
|
|
|
|
if (idesc->id_entryno > 1)
|
|
|
|
goto chk2;
|
|
|
|
inp = getinoinfo(idesc->id_number);
|
|
|
|
proto.d_ino = inp->i_parent;
|
2002-05-12 23:44:15 +00:00
|
|
|
proto.d_type = DT_DIR;
|
1994-05-26 06:35:07 +00:00
|
|
|
proto.d_namlen = 2;
|
|
|
|
(void)strcpy(proto.d_name, "..");
|
|
|
|
entrysize = DIRSIZ(0, &proto);
|
|
|
|
if (idesc->id_entryno == 0) {
|
|
|
|
n = DIRSIZ(0, dirp);
|
|
|
|
if (dirp->d_reclen < n + entrysize)
|
|
|
|
goto chk2;
|
|
|
|
proto.d_reclen = dirp->d_reclen - n;
|
|
|
|
dirp->d_reclen = n;
|
|
|
|
idesc->id_entryno++;
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(dirp->d_ino)->ino_linkcnt--;
|
1994-05-26 06:35:07 +00:00
|
|
|
dirp = (struct direct *)((char *)(dirp) + n);
|
1997-03-11 12:20:21 +00:00
|
|
|
memset(dirp, 0, (size_t)proto.d_reclen);
|
1994-05-26 06:35:07 +00:00
|
|
|
dirp->d_reclen = proto.d_reclen;
|
|
|
|
}
|
|
|
|
if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) {
|
|
|
|
inp->i_dotdot = dirp->d_ino;
|
2002-05-12 23:44:15 +00:00
|
|
|
if (dirp->d_type != DT_DIR) {
|
1994-05-26 06:35:07 +00:00
|
|
|
direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'");
|
|
|
|
dirp->d_type = DT_DIR;
|
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
}
|
|
|
|
goto chk2;
|
|
|
|
}
|
|
|
|
if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) {
|
|
|
|
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
|
|
|
|
pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
|
|
|
|
dirp->d_name);
|
|
|
|
inp->i_dotdot = (ino_t)-1;
|
|
|
|
} else if (dirp->d_reclen < entrysize) {
|
|
|
|
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
|
|
|
|
pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
|
|
|
|
inp->i_dotdot = (ino_t)-1;
|
|
|
|
} else if (inp->i_parent != 0) {
|
|
|
|
/*
|
|
|
|
* We know the parent, so fix now.
|
|
|
|
*/
|
|
|
|
inp->i_dotdot = inp->i_parent;
|
|
|
|
fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
|
|
|
|
proto.d_reclen = dirp->d_reclen;
|
1997-03-11 12:20:21 +00:00
|
|
|
memmove(dirp, &proto, (size_t)entrysize);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
}
|
|
|
|
idesc->id_entryno++;
|
|
|
|
if (dirp->d_ino != 0)
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(dirp->d_ino)->ino_linkcnt--;
|
1994-05-26 06:35:07 +00:00
|
|
|
return (ret|KEEPON);
|
|
|
|
chk2:
|
|
|
|
if (dirp->d_ino == 0)
|
|
|
|
return (ret|KEEPON);
|
|
|
|
if (dirp->d_namlen <= 2 &&
|
|
|
|
dirp->d_name[0] == '.' &&
|
|
|
|
idesc->id_entryno >= 2) {
|
|
|
|
if (dirp->d_namlen == 1) {
|
|
|
|
direrror(idesc->id_number, "EXTRA '.' ENTRY");
|
|
|
|
dirp->d_ino = 0;
|
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
return (KEEPON | ret);
|
|
|
|
}
|
|
|
|
if (dirp->d_name[1] == '.') {
|
|
|
|
direrror(idesc->id_number, "EXTRA '..' ENTRY");
|
|
|
|
dirp->d_ino = 0;
|
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
return (KEEPON | ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
idesc->id_entryno++;
|
|
|
|
n = 0;
|
|
|
|
if (dirp->d_ino > maxino) {
|
|
|
|
fileerror(idesc->id_number, dirp->d_ino, "I OUT OF RANGE");
|
|
|
|
n = reply("REMOVE");
|
2002-05-12 23:44:15 +00:00
|
|
|
} else if (((dirp->d_ino == WINO && dirp->d_type != DT_WHT) ||
|
1997-03-11 12:20:21 +00:00
|
|
|
(dirp->d_ino != WINO && dirp->d_type == DT_WHT))) {
|
|
|
|
fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY");
|
|
|
|
dirp->d_ino = WINO;
|
|
|
|
dirp->d_type = DT_WHT;
|
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
1994-05-26 06:35:07 +00:00
|
|
|
} else {
|
|
|
|
again:
|
1998-12-03 02:27:35 +00:00
|
|
|
switch (inoinfo(dirp->d_ino)->ino_state) {
|
1994-05-26 06:35:07 +00:00
|
|
|
case USTATE:
|
|
|
|
if (idesc->id_entryno <= 2)
|
|
|
|
break;
|
|
|
|
fileerror(idesc->id_number, dirp->d_ino, "UNALLOCATED");
|
|
|
|
n = reply("REMOVE");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DCLEAR:
|
|
|
|
case FCLEAR:
|
|
|
|
if (idesc->id_entryno <= 2)
|
|
|
|
break;
|
1998-12-03 02:27:35 +00:00
|
|
|
if (inoinfo(dirp->d_ino)->ino_state == FCLEAR)
|
1994-05-26 06:35:07 +00:00
|
|
|
errmsg = "DUP/BAD";
|
1998-03-08 09:59:44 +00:00
|
|
|
else if (!preen && !usedsoftdep)
|
1994-05-26 06:35:07 +00:00
|
|
|
errmsg = "ZERO LENGTH DIRECTORY";
|
|
|
|
else {
|
|
|
|
n = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fileerror(idesc->id_number, dirp->d_ino, errmsg);
|
|
|
|
if ((n = reply("REMOVE")) == 1)
|
|
|
|
break;
|
|
|
|
dp = ginode(dirp->d_ino);
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(dirp->d_ino)->ino_state =
|
2002-06-21 06:18:05 +00:00
|
|
|
(DIP(dp, di_mode) & IFMT) == IFDIR ? DSTATE : FSTATE;
|
|
|
|
inoinfo(dirp->d_ino)->ino_linkcnt = DIP(dp, di_nlink);
|
1994-05-26 06:35:07 +00:00
|
|
|
goto again;
|
|
|
|
|
|
|
|
case DSTATE:
|
1998-12-03 02:27:35 +00:00
|
|
|
if (inoinfo(idesc->id_number)->ino_state == DFOUND)
|
|
|
|
inoinfo(dirp->d_ino)->ino_state = DFOUND;
|
2002-08-25 13:10:45 +00:00
|
|
|
/* FALLTHROUGH */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
case DFOUND:
|
|
|
|
inp = getinoinfo(dirp->d_ino);
|
|
|
|
if (inp->i_parent != 0 && idesc->id_entryno > 2) {
|
|
|
|
getpathname(pathbuf, idesc->id_number,
|
|
|
|
idesc->id_number);
|
|
|
|
getpathname(namebuf, dirp->d_ino, dirp->d_ino);
|
2001-11-17 22:46:36 +00:00
|
|
|
pwarn("%s%s%s %s %s\n", pathbuf,
|
|
|
|
(strcmp(pathbuf, "/") == 0 ? "" : "/"),
|
|
|
|
dirp->d_name,
|
1994-05-26 06:35:07 +00:00
|
|
|
"IS AN EXTRANEOUS HARD LINK TO DIRECTORY",
|
|
|
|
namebuf);
|
2001-03-21 09:48:03 +00:00
|
|
|
if (cursnapshot != 0)
|
|
|
|
break;
|
1998-03-08 09:59:44 +00:00
|
|
|
if (preen) {
|
|
|
|
printf(" (REMOVED)\n");
|
1998-12-03 02:27:35 +00:00
|
|
|
n = 1;
|
|
|
|
break;
|
1998-03-08 09:59:44 +00:00
|
|
|
}
|
1998-12-03 02:27:35 +00:00
|
|
|
if ((n = reply("REMOVE")) == 1)
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (idesc->id_entryno > 2)
|
|
|
|
inp->i_parent = idesc->id_number;
|
2002-08-25 13:10:45 +00:00
|
|
|
/* FALLTHROUGH */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
case FSTATE:
|
2002-05-12 23:44:15 +00:00
|
|
|
if (dirp->d_type != inoinfo(dirp->d_ino)->ino_type) {
|
1994-05-26 06:35:07 +00:00
|
|
|
fileerror(idesc->id_number, dirp->d_ino,
|
|
|
|
"BAD TYPE VALUE");
|
1998-12-03 02:27:35 +00:00
|
|
|
dirp->d_type = inoinfo(dirp->d_ino)->ino_type;
|
1994-05-26 06:35:07 +00:00
|
|
|
if (reply("FIX") == 1)
|
|
|
|
ret |= ALTERED;
|
|
|
|
}
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(dirp->d_ino)->ino_linkcnt--;
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1997-03-11 12:20:21 +00:00
|
|
|
errx(EEXIT, "BAD STATE %d FOR INODE I=%d",
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(dirp->d_ino)->ino_state, dirp->d_ino);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n == 0)
|
|
|
|
return (ret|KEEPON);
|
|
|
|
dirp->d_ino = 0;
|
|
|
|
return (ret|KEEPON|ALTERED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine to sort disk blocks.
|
|
|
|
*/
|
1997-03-11 12:20:21 +00:00
|
|
|
static int
|
2002-03-20 22:57:10 +00:00
|
|
|
blksort(const void *arg1, const void *arg2)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
|
2002-07-30 13:01:25 +00:00
|
|
|
return ((*(struct inoinfo * const *)arg1)->i_blks[0] -
|
|
|
|
(*(struct inoinfo * const *)arg2)->i_blks[0]);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|