1995-05-30 06:12:45 +00:00
|
|
|
/*
|
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
|
2003-05-03 18:41:59 +00:00
|
|
|
#ifndef lint
|
1997-03-11 12:20:21 +00:00
|
|
|
static const char sccsid[] = "@(#)pass1.c 8.6 (Berkeley) 4/28/95";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
2003-05-03 18:41:59 +00:00
|
|
|
#endif
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2000-07-06 02:03:11 +00:00
|
|
|
#include <sys/stat.h>
|
2001-03-21 09:48:03 +00:00
|
|
|
#include <sys/sysctl.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>
|
|
|
|
#include <ufs/ffs/fs.h>
|
1997-03-11 12:20:21 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
2002-09-25 04:06:37 +00:00
|
|
|
#include <limits.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"
|
|
|
|
|
2002-06-21 06:18:05 +00:00
|
|
|
static ufs2_daddr_t badblk;
|
|
|
|
static ufs2_daddr_t dupblk;
|
1998-12-03 02:27:35 +00:00
|
|
|
static ino_t lastino; /* last inode in use */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2009-02-04 01:02:56 +00:00
|
|
|
static int checkinode(ino_t inumber, struct inodesc *, int rebuildcg);
|
1995-04-02 14:52:29 +00:00
|
|
|
|
|
|
|
void
|
2002-03-20 22:57:10 +00:00
|
|
|
pass1(void)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1998-12-03 02:27:35 +00:00
|
|
|
struct inostat *info;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct inodesc idesc;
|
2009-02-04 01:02:56 +00:00
|
|
|
ino_t inumber, inosused, mininos;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t i, cgd;
|
|
|
|
u_int8_t *cp;
|
2009-02-04 01:02:56 +00:00
|
|
|
int c, rebuildcg;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
/*
|
2002-08-21 18:11:48 +00:00
|
|
|
* Set file system reserved blocks in used block map.
|
1994-05-26 06:35:07 +00:00
|
|
|
*/
|
|
|
|
for (c = 0; c < sblock.fs_ncg; c++) {
|
|
|
|
cgd = cgdmin(&sblock, c);
|
|
|
|
if (c == 0) {
|
|
|
|
i = cgbase(&sblock, c);
|
|
|
|
} else
|
|
|
|
i = cgsblock(&sblock, c);
|
|
|
|
for (; i < cgd; i++)
|
|
|
|
setbmap(i);
|
|
|
|
}
|
2000-12-09 15:27:35 +00:00
|
|
|
i = sblock.fs_csaddr;
|
|
|
|
cgd = i + howmany(sblock.fs_cssize, sblock.fs_fsize);
|
|
|
|
for (; i < cgd; i++)
|
|
|
|
setbmap(i);
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
/*
|
|
|
|
* Find all allocated blocks.
|
|
|
|
*/
|
1997-03-11 12:20:21 +00:00
|
|
|
memset(&idesc, 0, sizeof(struct inodesc));
|
1994-05-26 06:35:07 +00:00
|
|
|
idesc.id_func = pass1check;
|
|
|
|
n_files = n_blks = 0;
|
|
|
|
for (c = 0; c < sblock.fs_ncg; c++) {
|
1998-12-03 02:27:35 +00:00
|
|
|
inumber = c * sblock.fs_ipg;
|
|
|
|
setinodebuf(inumber);
|
2002-06-21 06:18:05 +00:00
|
|
|
getblk(&cgblk, cgtod(&sblock, c), sblock.fs_cgsize);
|
2009-02-04 01:02:56 +00:00
|
|
|
rebuildcg = 0;
|
|
|
|
if (!check_cgmagic(c, &cgrp))
|
|
|
|
rebuildcg = 1;
|
|
|
|
if (!rebuildcg && sblock.fs_magic == FS_UFS2_MAGIC) {
|
2002-06-21 06:18:05 +00:00
|
|
|
inosused = cgrp.cg_initediblk;
|
2010-01-07 01:10:49 +00:00
|
|
|
if (inosused > sblock.fs_ipg) {
|
2012-09-27 23:30:58 +00:00
|
|
|
pfatal("%s (%ju > %d) %s %d\nReset to %d\n",
|
|
|
|
"Too many initialized inodes",
|
|
|
|
(uintmax_t)inosused,
|
2010-01-07 01:10:49 +00:00
|
|
|
sblock.fs_ipg, "in cylinder group", c,
|
|
|
|
sblock.fs_ipg);
|
2008-02-26 03:08:22 +00:00
|
|
|
inosused = sblock.fs_ipg;
|
2010-01-07 01:10:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-06-21 06:18:05 +00:00
|
|
|
inosused = sblock.fs_ipg;
|
2010-01-07 01:10:49 +00:00
|
|
|
}
|
2000-12-15 14:23:55 +00:00
|
|
|
if (got_siginfo) {
|
|
|
|
printf("%s: phase 1: cyl group %d of %d (%d%%)\n",
|
|
|
|
cdevname, c, sblock.fs_ncg,
|
|
|
|
c * 100 / sblock.fs_ncg);
|
|
|
|
got_siginfo = 0;
|
|
|
|
}
|
2004-02-28 07:50:42 +00:00
|
|
|
if (got_sigalarm) {
|
|
|
|
setproctitle("%s p1 %d%%", cdevname,
|
|
|
|
c * 100 / sblock.fs_ncg);
|
|
|
|
got_sigalarm = 0;
|
|
|
|
}
|
1998-12-03 02:27:35 +00:00
|
|
|
/*
|
|
|
|
* If we are using soft updates, then we can trust the
|
|
|
|
* cylinder group inode allocation maps to tell us which
|
|
|
|
* inodes are allocated. We will scan the used inode map
|
|
|
|
* to find the inodes that are really in use, and then
|
|
|
|
* read only those inodes in from disk.
|
|
|
|
*/
|
2009-02-04 01:02:56 +00:00
|
|
|
if ((preen || inoopt) && usedsoftdep && !rebuildcg) {
|
2002-09-25 04:06:37 +00:00
|
|
|
cp = &cg_inosused(&cgrp)[(inosused - 1) / CHAR_BIT];
|
|
|
|
for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) {
|
1998-12-03 02:27:35 +00:00
|
|
|
if (*cp == 0)
|
|
|
|
continue;
|
2002-09-25 04:06:37 +00:00
|
|
|
for (i = 1 << (CHAR_BIT - 1); i > 0; i >>= 1) {
|
1998-12-03 02:27:35 +00:00
|
|
|
if (*cp & i)
|
|
|
|
break;
|
|
|
|
inosused--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (inosused < 0)
|
|
|
|
inosused = 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Allocate inoinfo structures for the allocated inodes.
|
|
|
|
*/
|
|
|
|
inostathead[c].il_numalloced = inosused;
|
|
|
|
if (inosused == 0) {
|
|
|
|
inostathead[c].il_stat = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
info = calloc((unsigned)inosused, sizeof(struct inostat));
|
|
|
|
if (info == NULL)
|
2004-01-26 15:05:30 +00:00
|
|
|
errx(EEXIT, "cannot alloc %u bytes for inoinfo",
|
1998-12-03 02:27:35 +00:00
|
|
|
(unsigned)(sizeof(struct inostat) * inosused));
|
|
|
|
inostathead[c].il_stat = info;
|
|
|
|
/*
|
|
|
|
* Scan the allocated inodes.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < inosused; i++, inumber++) {
|
|
|
|
if (inumber < ROOTINO) {
|
2009-02-04 01:02:56 +00:00
|
|
|
(void)getnextinode(inumber, rebuildcg);
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
1998-12-03 02:27:35 +00:00
|
|
|
}
|
2009-02-04 01:02:56 +00:00
|
|
|
/*
|
|
|
|
* NULL return indicates probable end of allocated
|
|
|
|
* inodes during cylinder group rebuild attempt.
|
|
|
|
* We always keep trying until we get to the minimum
|
|
|
|
* valid number for this cylinder group.
|
|
|
|
*/
|
|
|
|
if (checkinode(inumber, &idesc, rebuildcg) == 0 &&
|
|
|
|
i > cgrp.cg_initediblk)
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2009-02-04 01:02:56 +00:00
|
|
|
/*
|
|
|
|
* This optimization speeds up future runs of fsck
|
|
|
|
* by trimming down the number of inodes in cylinder
|
|
|
|
* groups that formerly had many inodes but now have
|
|
|
|
* fewer in use.
|
|
|
|
*/
|
|
|
|
mininos = roundup(inosused + INOPB(&sblock), INOPB(&sblock));
|
|
|
|
if (inoopt && !preen && !rebuildcg &&
|
|
|
|
sblock.fs_magic == FS_UFS2_MAGIC &&
|
|
|
|
cgrp.cg_initediblk > 2 * INOPB(&sblock) &&
|
|
|
|
mininos < cgrp.cg_initediblk) {
|
|
|
|
i = cgrp.cg_initediblk;
|
|
|
|
if (mininos < 2 * INOPB(&sblock))
|
|
|
|
cgrp.cg_initediblk = 2 * INOPB(&sblock);
|
|
|
|
else
|
|
|
|
cgrp.cg_initediblk = mininos;
|
|
|
|
pwarn("CYLINDER GROUP %d: RESET FROM %ju TO %d %s\n",
|
|
|
|
c, i, cgrp.cg_initediblk, "VALID INODES");
|
|
|
|
cgdirty();
|
|
|
|
}
|
|
|
|
if (inosused < sblock.fs_ipg)
|
1998-12-03 02:27:35 +00:00
|
|
|
continue;
|
2009-02-04 01:02:56 +00:00
|
|
|
lastino += 1;
|
|
|
|
if (lastino < (c * sblock.fs_ipg))
|
|
|
|
inosused = 0;
|
|
|
|
else
|
|
|
|
inosused = lastino - (c * sblock.fs_ipg);
|
|
|
|
if (rebuildcg && inosused > cgrp.cg_initediblk &&
|
|
|
|
sblock.fs_magic == FS_UFS2_MAGIC) {
|
|
|
|
cgrp.cg_initediblk = roundup(inosused, INOPB(&sblock));
|
|
|
|
pwarn("CYLINDER GROUP %d: FOUND %d VALID INODES\n", c,
|
|
|
|
cgrp.cg_initediblk);
|
|
|
|
}
|
1998-12-03 02:27:35 +00:00
|
|
|
/*
|
|
|
|
* If we were not able to determine in advance which inodes
|
|
|
|
* were in use, then reduce the size of the inoinfo structure
|
|
|
|
* to the size necessary to describe the inodes that we
|
|
|
|
* really found.
|
|
|
|
*/
|
2009-02-04 01:02:56 +00:00
|
|
|
if (inumber == lastino)
|
|
|
|
continue;
|
1998-12-03 02:27:35 +00:00
|
|
|
inostathead[c].il_numalloced = inosused;
|
|
|
|
if (inosused == 0) {
|
|
|
|
free(inostathead[c].il_stat);
|
|
|
|
inostathead[c].il_stat = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
info = calloc((unsigned)inosused, sizeof(struct inostat));
|
|
|
|
if (info == NULL)
|
2004-01-26 15:05:30 +00:00
|
|
|
errx(EEXIT, "cannot alloc %u bytes for inoinfo",
|
1998-12-03 02:27:35 +00:00
|
|
|
(unsigned)(sizeof(struct inostat) * inosused));
|
|
|
|
memmove(info, inostathead[c].il_stat, inosused * sizeof(*info));
|
|
|
|
free(inostathead[c].il_stat);
|
|
|
|
inostathead[c].il_stat = info;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
freeinodebuf();
|
|
|
|
}
|
|
|
|
|
2009-02-04 01:02:56 +00:00
|
|
|
static int
|
|
|
|
checkinode(ino_t inumber, struct inodesc *idesc, int rebuildcg)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-06-21 06:18:05 +00:00
|
|
|
union dinode *dp;
|
|
|
|
off_t kernmaxfilesize;
|
|
|
|
ufs2_daddr_t ndb;
|
1994-05-26 06:35:07 +00:00
|
|
|
mode_t mode;
|
2002-09-24 05:18:17 +00:00
|
|
|
int j, ret, offset;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2009-02-04 01:02:56 +00:00
|
|
|
if ((dp = getnextinode(inumber, rebuildcg)) == NULL)
|
|
|
|
return (0);
|
2002-06-21 06:18:05 +00:00
|
|
|
mode = DIP(dp, di_mode) & IFMT;
|
1994-05-26 06:35:07 +00:00
|
|
|
if (mode == 0) {
|
2002-06-21 06:18:05 +00:00
|
|
|
if ((sblock.fs_magic == FS_UFS1_MAGIC &&
|
|
|
|
(memcmp(dp->dp1.di_db, ufs1_zino.di_db,
|
|
|
|
NDADDR * sizeof(ufs1_daddr_t)) ||
|
|
|
|
memcmp(dp->dp1.di_ib, ufs1_zino.di_ib,
|
|
|
|
NIADDR * sizeof(ufs1_daddr_t)) ||
|
|
|
|
dp->dp1.di_mode || dp->dp1.di_size)) ||
|
|
|
|
(sblock.fs_magic == FS_UFS2_MAGIC &&
|
|
|
|
(memcmp(dp->dp2.di_db, ufs2_zino.di_db,
|
|
|
|
NDADDR * sizeof(ufs2_daddr_t)) ||
|
|
|
|
memcmp(dp->dp2.di_ib, ufs2_zino.di_ib,
|
|
|
|
NIADDR * sizeof(ufs2_daddr_t)) ||
|
|
|
|
dp->dp2.di_mode || dp->dp2.di_size))) {
|
2001-11-17 23:48:21 +00:00
|
|
|
pfatal("PARTIALLY ALLOCATED INODE I=%lu",
|
|
|
|
(u_long)inumber);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (reply("CLEAR") == 1) {
|
|
|
|
dp = ginode(inumber);
|
|
|
|
clearinode(dp);
|
|
|
|
inodirty();
|
|
|
|
}
|
|
|
|
}
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(inumber)->ino_state = USTATE;
|
2009-02-04 01:02:56 +00:00
|
|
|
return (1);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
lastino = inumber;
|
2001-01-31 15:16:56 +00:00
|
|
|
/* This should match the file size limit in ffs_mountfs(). */
|
2002-06-26 18:34:51 +00:00
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC)
|
|
|
|
kernmaxfilesize = (off_t)0x40000000 * sblock.fs_bsize - 1;
|
|
|
|
else
|
|
|
|
kernmaxfilesize = sblock.fs_maxfilesize;
|
2002-06-21 06:18:05 +00:00
|
|
|
if (DIP(dp, di_size) > kernmaxfilesize ||
|
|
|
|
DIP(dp, di_size) > sblock.fs_maxfilesize ||
|
|
|
|
(mode == IFDIR && DIP(dp, di_size) > MAXDIRSIZE)) {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (debug)
|
2002-07-31 12:01:14 +00:00
|
|
|
printf("bad size %ju:", (uintmax_t)DIP(dp, di_size));
|
1994-05-26 06:35:07 +00:00
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
if (!preen && mode == IFMT && reply("HOLD BAD BLOCK") == 1) {
|
|
|
|
dp = ginode(inumber);
|
2004-09-01 05:48:06 +00:00
|
|
|
DIP_SET(dp, di_size, sblock.fs_fsize);
|
|
|
|
DIP_SET(dp, di_mode, IFREG|0600);
|
1994-05-26 06:35:07 +00:00
|
|
|
inodirty();
|
|
|
|
}
|
2000-07-12 06:19:22 +00:00
|
|
|
if ((mode == IFBLK || mode == IFCHR || mode == IFIFO ||
|
2002-06-21 06:18:05 +00:00
|
|
|
mode == IFSOCK) && DIP(dp, di_size) != 0) {
|
2000-07-12 06:19:22 +00:00
|
|
|
if (debug)
|
2002-07-31 12:01:14 +00:00
|
|
|
printf("bad special-file size %ju:",
|
|
|
|
(uintmax_t)DIP(dp, di_size));
|
2000-07-12 06:19:22 +00:00
|
|
|
goto unknown;
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
if ((mode == IFBLK || mode == IFCHR) &&
|
|
|
|
(dev_t)DIP(dp, di_rdev) == NODEV) {
|
2001-02-15 22:26:21 +00:00
|
|
|
if (debug)
|
|
|
|
printf("bad special-file rdev NODEV:");
|
|
|
|
goto unknown;
|
|
|
|
}
|
2002-06-21 06:18:05 +00:00
|
|
|
ndb = howmany(DIP(dp, di_size), sblock.fs_bsize);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (ndb < 0) {
|
|
|
|
if (debug)
|
2002-07-31 12:01:14 +00:00
|
|
|
printf("bad size %ju ndb %ju:",
|
|
|
|
(uintmax_t)DIP(dp, di_size), (uintmax_t)ndb);
|
1994-05-26 06:35:07 +00:00
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
if (mode == IFBLK || mode == IFCHR)
|
|
|
|
ndb++;
|
|
|
|
if (mode == IFLNK) {
|
|
|
|
/*
|
|
|
|
* Fake ndb value so direct/indirect block checks below
|
|
|
|
* will detect any garbage after symlink string.
|
|
|
|
*/
|
2002-06-21 06:18:05 +00:00
|
|
|
if (DIP(dp, di_size) < (off_t)sblock.fs_maxsymlinklen) {
|
|
|
|
if (sblock.fs_magic == FS_UFS1_MAGIC)
|
|
|
|
ndb = howmany(DIP(dp, di_size),
|
|
|
|
sizeof(ufs1_daddr_t));
|
|
|
|
else
|
|
|
|
ndb = howmany(DIP(dp, di_size),
|
|
|
|
sizeof(ufs2_daddr_t));
|
1994-05-26 06:35:07 +00:00
|
|
|
if (ndb > NDADDR) {
|
|
|
|
j = ndb - NDADDR;
|
|
|
|
for (ndb = 1; j > 1; j--)
|
|
|
|
ndb *= NINDIR(&sblock);
|
|
|
|
ndb += NDADDR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-26 16:40:25 +00:00
|
|
|
for (j = ndb; ndb < NDADDR && j < NDADDR; j++)
|
2002-06-21 06:18:05 +00:00
|
|
|
if (DIP(dp, di_db[j]) != 0) {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (debug)
|
2002-07-31 12:01:14 +00:00
|
|
|
printf("bad direct addr[%d]: %ju\n", j,
|
|
|
|
(uintmax_t)DIP(dp, di_db[j]));
|
1994-05-26 06:35:07 +00:00
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
for (j = 0, ndb -= NDADDR; ndb > 0; j++)
|
|
|
|
ndb /= NINDIR(&sblock);
|
|
|
|
for (; j < NIADDR; j++)
|
2002-06-21 06:18:05 +00:00
|
|
|
if (DIP(dp, di_ib[j]) != 0) {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (debug)
|
2002-07-31 12:01:14 +00:00
|
|
|
printf("bad indirect addr: %ju\n",
|
|
|
|
(uintmax_t)DIP(dp, di_ib[j]));
|
1994-05-26 06:35:07 +00:00
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
if (ftypeok(dp) == 0)
|
|
|
|
goto unknown;
|
|
|
|
n_files++;
|
2002-06-21 06:18:05 +00:00
|
|
|
inoinfo(inumber)->ino_linkcnt = DIP(dp, di_nlink);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (mode == IFDIR) {
|
2002-06-21 06:18:05 +00:00
|
|
|
if (DIP(dp, di_size) == 0)
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(inumber)->ino_state = DCLEAR;
|
2004-10-08 20:44:47 +00:00
|
|
|
else if (DIP(dp, di_nlink) <= 0)
|
|
|
|
inoinfo(inumber)->ino_state = DZLINK;
|
1994-05-26 06:35:07 +00:00
|
|
|
else
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(inumber)->ino_state = DSTATE;
|
1994-05-26 06:35:07 +00:00
|
|
|
cacheino(dp, inumber);
|
1998-12-03 02:27:35 +00:00
|
|
|
countdirs++;
|
2004-10-08 20:44:47 +00:00
|
|
|
} else if (DIP(dp, di_nlink) <= 0)
|
|
|
|
inoinfo(inumber)->ino_state = FZLINK;
|
|
|
|
else
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(inumber)->ino_state = FSTATE;
|
|
|
|
inoinfo(inumber)->ino_type = IFTODT(mode);
|
1994-05-26 06:35:07 +00:00
|
|
|
badblk = dupblk = 0;
|
|
|
|
idesc->id_number = inumber;
|
2002-06-21 06:18:05 +00:00
|
|
|
if (DIP(dp, di_flags) & SF_SNAPSHOT)
|
2000-07-06 02:03:11 +00:00
|
|
|
idesc->id_type = SNAP;
|
|
|
|
else
|
|
|
|
idesc->id_type = ADDR;
|
1994-05-26 06:35:07 +00:00
|
|
|
(void)ckinode(dp, idesc);
|
2002-09-24 05:18:17 +00:00
|
|
|
if (sblock.fs_magic == FS_UFS2_MAGIC && dp->dp2.di_extsize > 0) {
|
|
|
|
idesc->id_type = ADDR;
|
|
|
|
ndb = howmany(dp->dp2.di_extsize, sblock.fs_bsize);
|
|
|
|
for (j = 0; j < NXADDR; j++) {
|
|
|
|
if (--ndb == 0 &&
|
|
|
|
(offset = blkoff(&sblock, dp->dp2.di_extsize)) != 0)
|
|
|
|
idesc->id_numfrags = numfrags(&sblock,
|
|
|
|
fragroundup(&sblock, offset));
|
|
|
|
else
|
|
|
|
idesc->id_numfrags = sblock.fs_frag;
|
|
|
|
if (dp->dp2.di_extb[j] == 0)
|
|
|
|
continue;
|
|
|
|
idesc->id_blkno = dp->dp2.di_extb[j];
|
|
|
|
ret = (*idesc->id_func)(idesc);
|
|
|
|
if (ret & STOP)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-09-16 11:27:47 +00:00
|
|
|
if (sblock.fs_magic == FS_UFS2_MAGIC)
|
|
|
|
eascan(idesc, &dp->dp2);
|
1994-05-26 06:35:07 +00:00
|
|
|
idesc->id_entryno *= btodb(sblock.fs_fsize);
|
2002-06-21 06:18:05 +00:00
|
|
|
if (DIP(dp, di_blocks) != idesc->id_entryno) {
|
2002-07-31 12:01:14 +00:00
|
|
|
pwarn("INCORRECT BLOCK COUNT I=%lu (%ju should be %ju)",
|
|
|
|
(u_long)inumber, (uintmax_t)DIP(dp, di_blocks),
|
|
|
|
(uintmax_t)idesc->id_entryno);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (preen)
|
|
|
|
printf(" (CORRECTED)\n");
|
|
|
|
else if (reply("CORRECT") == 0)
|
2009-02-04 01:02:56 +00:00
|
|
|
return (1);
|
2001-03-21 09:48:03 +00:00
|
|
|
if (bkgrdflag == 0) {
|
|
|
|
dp = ginode(inumber);
|
2004-09-01 05:48:06 +00:00
|
|
|
DIP_SET(dp, di_blocks, idesc->id_entryno);
|
2001-03-21 09:48:03 +00:00
|
|
|
inodirty();
|
|
|
|
} else {
|
|
|
|
cmd.value = idesc->id_number;
|
2002-06-21 06:18:05 +00:00
|
|
|
cmd.size = idesc->id_entryno - DIP(dp, di_blocks);
|
2001-03-21 09:48:03 +00:00
|
|
|
if (debug)
|
2002-07-31 12:01:14 +00:00
|
|
|
printf("adjblkcnt ino %ju amount %lld\n",
|
|
|
|
(uintmax_t)cmd.value, (long long)cmd.size);
|
2001-03-21 09:48:03 +00:00
|
|
|
if (sysctl(adjblkcnt, MIBSIZE, 0, 0,
|
|
|
|
&cmd, sizeof cmd) == -1)
|
|
|
|
rwerror("ADJUST INODE BLOCK COUNT", cmd.value);
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2009-02-04 01:02:56 +00:00
|
|
|
return (1);
|
1994-05-26 06:35:07 +00:00
|
|
|
unknown:
|
2001-11-17 23:48:21 +00:00
|
|
|
pfatal("UNKNOWN FILE TYPE I=%lu", (u_long)inumber);
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(inumber)->ino_state = FCLEAR;
|
1994-05-26 06:35:07 +00:00
|
|
|
if (reply("CLEAR") == 1) {
|
1998-12-03 02:27:35 +00:00
|
|
|
inoinfo(inumber)->ino_state = USTATE;
|
1994-05-26 06:35:07 +00:00
|
|
|
dp = ginode(inumber);
|
|
|
|
clearinode(dp);
|
|
|
|
inodirty();
|
|
|
|
}
|
2009-02-04 01:02:56 +00:00
|
|
|
return (1);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
1995-04-02 14:52:29 +00:00
|
|
|
int
|
2002-03-20 22:57:10 +00:00
|
|
|
pass1check(struct inodesc *idesc)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
int res = KEEPON;
|
|
|
|
int anyout, nfrags;
|
2002-06-21 06:18:05 +00:00
|
|
|
ufs2_daddr_t blkno = idesc->id_blkno;
|
2002-03-20 17:55:10 +00:00
|
|
|
struct dups *dlp;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct dups *new;
|
|
|
|
|
2000-07-06 02:03:11 +00:00
|
|
|
if (idesc->id_type == SNAP) {
|
|
|
|
if (blkno == BLK_NOCOPY)
|
|
|
|
return (KEEPON);
|
|
|
|
if (idesc->id_number == cursnapshot) {
|
|
|
|
if (blkno == blkstofrags(&sblock, idesc->id_lbn))
|
|
|
|
return (KEEPON);
|
|
|
|
if (blkno == BLK_SNAP) {
|
|
|
|
blkno = blkstofrags(&sblock, idesc->id_lbn);
|
|
|
|
idesc->id_entryno -= idesc->id_numfrags;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (blkno == BLK_SNAP)
|
|
|
|
return (KEEPON);
|
|
|
|
}
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) {
|
|
|
|
blkerror(idesc->id_number, "BAD", blkno);
|
|
|
|
if (badblk++ >= MAXBAD) {
|
|
|
|
pwarn("EXCESSIVE BAD BLKS I=%lu",
|
2001-11-17 23:48:21 +00:00
|
|
|
(u_long)idesc->id_number);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (preen)
|
|
|
|
printf(" (SKIPPING)\n");
|
1998-03-08 09:59:44 +00:00
|
|
|
else 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
|
|
|
return (STOP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
|
|
|
|
if (anyout && chkrange(blkno, 1)) {
|
|
|
|
res = SKIP;
|
|
|
|
} else if (!testbmap(blkno)) {
|
|
|
|
n_blks++;
|
|
|
|
setbmap(blkno);
|
|
|
|
} else {
|
|
|
|
blkerror(idesc->id_number, "DUP", blkno);
|
|
|
|
if (dupblk++ >= MAXDUP) {
|
|
|
|
pwarn("EXCESSIVE DUP BLKS I=%lu",
|
2001-11-17 23:48:21 +00:00
|
|
|
(u_long)idesc->id_number);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (preen)
|
|
|
|
printf(" (SKIPPING)\n");
|
1998-03-08 09:59:44 +00:00
|
|
|
else 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
|
|
|
return (STOP);
|
|
|
|
}
|
|
|
|
new = (struct dups *)malloc(sizeof(struct dups));
|
|
|
|
if (new == NULL) {
|
|
|
|
pfatal("DUP TABLE OVERFLOW.");
|
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
|
|
|
return (STOP);
|
|
|
|
}
|
|
|
|
new->dup = blkno;
|
|
|
|
if (muldup == 0) {
|
|
|
|
duplist = muldup = new;
|
|
|
|
new->next = 0;
|
|
|
|
} else {
|
|
|
|
new->next = muldup->next;
|
|
|
|
muldup->next = new;
|
|
|
|
}
|
|
|
|
for (dlp = duplist; dlp != muldup; dlp = dlp->next)
|
|
|
|
if (dlp->dup == blkno)
|
|
|
|
break;
|
|
|
|
if (dlp == muldup && dlp->dup != blkno)
|
|
|
|
muldup = new;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* count the number of blocks found in id_entryno
|
|
|
|
*/
|
|
|
|
idesc->id_entryno++;
|
|
|
|
}
|
|
|
|
return (res);
|
|
|
|
}
|