2013-01-22 13:39:11 +04:00
|
|
|
/* $NetBSD: pass1.c,v 1.51 2013/01/22 09:39:11 dholland Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 22:57:30 +04:00
|
|
|
* Copyright (c) 1980, 1986, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 14:04:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-09-14 18:36:29 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1997-09-16 20:44:43 +04:00
|
|
|
static char sccsid[] = "@(#)pass1.c 8.6 (Berkeley) 4/28/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2013-01-22 13:39:11 +04:00
|
|
|
__RCSID("$NetBSD: pass1.c,v 1.51 2013/01/22 09:39:11 dholland Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2004-05-25 18:54:55 +04:00
|
|
|
#include <sys/stat.h>
|
1994-04-25 22:23:19 +04:00
|
|
|
#include <sys/time.h>
|
1997-09-16 20:44:43 +04:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ufs/dir.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
2003-04-02 14:39:19 +04:00
|
|
|
#include <ufs/ufs/ufs_bswap.h>
|
|
|
|
#include <ufs/ffs/ffs_extern.h>
|
1994-12-05 23:15:31 +03:00
|
|
|
|
1997-09-16 20:44:43 +04:00
|
|
|
#include <err.h>
|
1997-09-20 10:16:23 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <string.h>
|
1994-12-05 23:15:31 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "fsck.h"
|
1994-12-05 23:15:31 +03:00
|
|
|
#include "extern.h"
|
1996-09-28 02:45:10 +04:00
|
|
|
#include "fsutil.h"
|
2008-02-24 00:41:47 +03:00
|
|
|
#include "exitvalues.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-01-25 00:55:02 +03:00
|
|
|
static daddr_t badblk;
|
|
|
|
static daddr_t dupblk;
|
2005-01-20 18:29:40 +03:00
|
|
|
static void checkinode(ino_t, struct inodesc *);
|
2003-04-02 14:39:19 +04:00
|
|
|
static ino_t lastino;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
2005-01-19 20:33:58 +03:00
|
|
|
pass1(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2011-08-14 16:32:01 +04:00
|
|
|
ino_t inumber, inosused, ninosused, ii;
|
2008-10-09 19:50:46 +04:00
|
|
|
size_t inospace;
|
2003-04-02 14:39:19 +04:00
|
|
|
int c;
|
|
|
|
daddr_t i, cgd;
|
1994-06-08 22:57:30 +04:00
|
|
|
struct inodesc idesc;
|
2003-04-02 14:39:19 +04:00
|
|
|
struct cg *cgp = cgrp;
|
|
|
|
struct inostat *info;
|
|
|
|
uint8_t *cp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set file system reserved blocks in used block map.
|
|
|
|
*/
|
1998-03-18 20:01:23 +03:00
|
|
|
for (c = 0; c < sblock->fs_ncg; c++) {
|
|
|
|
cgd = cgdmin(sblock, c);
|
1996-01-19 00:55:27 +03:00
|
|
|
if (c == 0)
|
1998-03-18 20:01:23 +03:00
|
|
|
i = cgbase(sblock, c);
|
1996-01-19 00:55:27 +03:00
|
|
|
else
|
1998-03-18 20:01:23 +03:00
|
|
|
i = cgsblock(sblock, c);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (; i < cgd; i++)
|
|
|
|
setbmap(i);
|
|
|
|
}
|
1998-03-18 20:01:23 +03:00
|
|
|
i = sblock->fs_csaddr;
|
|
|
|
cgd = i + howmany(sblock->fs_cssize, sblock->fs_fsize);
|
1996-01-19 00:55:27 +03:00
|
|
|
for (; i < cgd; i++)
|
|
|
|
setbmap(i);
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Find all allocated blocks.
|
|
|
|
*/
|
1994-09-23 18:26:58 +04:00
|
|
|
memset(&idesc, 0, sizeof(struct inodesc));
|
1993-03-21 12:45:37 +03:00
|
|
|
idesc.id_func = pass1check;
|
|
|
|
n_files = n_blks = 0;
|
1998-03-18 20:01:23 +03:00
|
|
|
for (c = 0; c < sblock->fs_ncg; c++) {
|
2003-04-02 14:39:19 +04:00
|
|
|
inumber = c * sblock->fs_ipg;
|
|
|
|
setinodebuf(inumber);
|
|
|
|
getblk(&cgblk, cgtod(sblock, c), sblock->fs_cgsize);
|
|
|
|
memcpy(cgp, cgblk.b_un.b_cg, sblock->fs_cgsize);
|
|
|
|
if((doswap && !needswap) || (!doswap && needswap))
|
|
|
|
ffs_cg_swap(cgblk.b_un.b_cg, cgp, sblock);
|
|
|
|
if (is_ufs2)
|
|
|
|
inosused = cgp->cg_initediblk;
|
|
|
|
else
|
|
|
|
inosused = sblock->fs_ipg;
|
2002-05-06 07:17:43 +04:00
|
|
|
if (got_siginfo) {
|
2013-01-07 02:06:00 +04:00
|
|
|
fprintf(stderr,
|
|
|
|
"%s: phase 1: cyl group %d of %d (%d%%)\n",
|
2002-05-06 07:17:43 +04:00
|
|
|
cdevname(), c, sblock->fs_ncg,
|
|
|
|
c * 100 / sblock->fs_ncg);
|
|
|
|
got_siginfo = 0;
|
|
|
|
}
|
2005-01-13 22:56:02 +03:00
|
|
|
#ifdef PROGRESS
|
2005-01-13 18:22:35 +03:00
|
|
|
progress_bar(cdevname(), preen ? NULL : "phase 1",
|
|
|
|
c, sblock->fs_ncg);
|
2005-01-13 22:56:02 +03:00
|
|
|
#endif /* PROGRESS */
|
2003-04-02 14:39:19 +04: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.
|
|
|
|
*/
|
|
|
|
if (preen && usedsoftdep) {
|
|
|
|
if (!cg_chkmagic(cgp, 0))
|
|
|
|
pfatal("CG %d: BAD MAGIC NUMBER\n", c);
|
|
|
|
cp = &cg_inosused(cgp, 0)[(inosused - 1) / CHAR_BIT];
|
|
|
|
for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) {
|
|
|
|
if (*cp == 0)
|
|
|
|
continue;
|
|
|
|
for (i = 1 << (CHAR_BIT - 1); i > 0; i >>= 1) {
|
|
|
|
if (*cp & i)
|
|
|
|
break;
|
|
|
|
inosused--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-10-16 07:09:26 +04:00
|
|
|
#ifdef notdef
|
2003-04-02 14:39:19 +04:00
|
|
|
if (inosused < 0)
|
|
|
|
inosused = 0;
|
2006-10-16 07:09:26 +04:00
|
|
|
#endif
|
2003-04-02 14:39:19 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Allocate inoinfo structures for the allocated inodes.
|
|
|
|
*/
|
|
|
|
inostathead[c].il_numalloced = inosused;
|
|
|
|
if (inosused == 0) {
|
|
|
|
inostathead[c].il_stat = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-09 19:50:46 +04:00
|
|
|
inospace = inosused * sizeof(*info);
|
|
|
|
if (inospace / sizeof(*info) != inosused) {
|
|
|
|
pfatal("too many inodes %llu\n", (unsigned long long)
|
|
|
|
inosused);
|
|
|
|
exit(FSCK_EXIT_CHECK_FAILED);
|
|
|
|
}
|
|
|
|
info = malloc(inospace);
|
2003-04-02 14:39:19 +04:00
|
|
|
if (info == NULL) {
|
2008-10-09 19:50:46 +04:00
|
|
|
pfatal("cannot alloc %zu bytes for inoinfo\n",
|
|
|
|
inospace);
|
2008-02-24 00:41:47 +03:00
|
|
|
exit(FSCK_EXIT_CHECK_FAILED);
|
2003-04-02 14:39:19 +04:00
|
|
|
}
|
2008-10-09 19:50:46 +04:00
|
|
|
(void)memset(info, 0, inospace);
|
2003-04-02 14:39:19 +04:00
|
|
|
inostathead[c].il_stat = info;
|
|
|
|
/*
|
|
|
|
* Scan the allocated inodes.
|
|
|
|
*/
|
2011-08-14 16:32:01 +04:00
|
|
|
for (ii = 0; ii < inosused; ii++, inumber++) {
|
2013-01-22 13:39:11 +04:00
|
|
|
if (inumber < UFS_ROOTINO) {
|
2003-04-02 14:39:19 +04:00
|
|
|
(void)getnextinode(inumber);
|
1993-03-21 12:45:37 +03:00
|
|
|
continue;
|
2003-04-02 14:39:19 +04:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
checkinode(inumber, &idesc);
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
lastino += 1;
|
2011-08-14 16:32:01 +04:00
|
|
|
if (inosused < (ino_t)sblock->fs_ipg || inumber == lastino)
|
2003-04-02 14:39:19 +04:00
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-08-14 16:32:01 +04:00
|
|
|
if (lastino < (c * (ino_t)sblock->fs_ipg))
|
2008-10-09 19:50:46 +04:00
|
|
|
ninosused = 0;
|
2003-04-02 14:39:19 +04:00
|
|
|
else
|
2008-10-09 19:50:46 +04:00
|
|
|
ninosused = lastino - (c * sblock->fs_ipg);
|
|
|
|
inostathead[c].il_numalloced = ninosused;
|
|
|
|
if (ninosused == 0) {
|
2003-04-02 14:39:19 +04:00
|
|
|
free(inostathead[c].il_stat);
|
|
|
|
inostathead[c].il_stat = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-09 19:50:46 +04:00
|
|
|
if (ninosused != inosused) {
|
|
|
|
struct inostat *ninfo;
|
|
|
|
size_t ninospace = ninosused * sizeof(*ninfo);
|
|
|
|
if (ninospace / sizeof(*info) != ninosused) {
|
|
|
|
pfatal("too many inodes %llu\n",
|
|
|
|
(unsigned long long)ninosused);
|
|
|
|
exit(FSCK_EXIT_CHECK_FAILED);
|
|
|
|
}
|
2008-10-13 03:26:12 +04:00
|
|
|
ninfo = realloc(info, ninospace);
|
2008-10-09 19:50:46 +04:00
|
|
|
if (ninfo == NULL) {
|
|
|
|
pfatal("cannot realloc %zu bytes to %zu "
|
|
|
|
"for inoinfo\n", inospace, ninospace);
|
|
|
|
exit(FSCK_EXIT_CHECK_FAILED);
|
|
|
|
}
|
|
|
|
if (ninosused > inosused)
|
|
|
|
(void)memset(&ninfo[inosused], 0, ninospace - inospace);
|
|
|
|
inostathead[c].il_stat = ninfo;
|
2003-04-02 14:39:19 +04:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
2005-01-13 22:56:02 +03:00
|
|
|
#ifdef PROGRESS
|
Improve the progress bar displayed by fsck_ffs -p -P.
The progress bar will now travel from 0 to 20% during pass 1, from 20%
to 95% during pass 2, and from 95% to 100% during passes 3, 4, and 5.
Previously, the progress bar was not displayed at all during pass 1,
slowly traveled from 0 to about 50% during pass 2, and then very rapidly
traveled from 50% to 100% during passes 3, 4, and 5.
Note that fsck_ffs is the only user of fsck/progress.{c,h}.
2006-11-15 00:01:46 +03:00
|
|
|
if (!preen)
|
2005-01-13 18:22:35 +03:00
|
|
|
progress_done();
|
2005-01-13 22:56:02 +03:00
|
|
|
#endif /* PROGRESS */
|
1994-06-08 22:57:30 +04:00
|
|
|
freeinodebuf();
|
1998-03-18 20:01:23 +03:00
|
|
|
do_blkswap = 0; /* has been done */
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
|
1996-09-23 20:18:31 +04:00
|
|
|
static void
|
2005-01-19 20:33:58 +03:00
|
|
|
checkinode(ino_t inumber, struct inodesc *idesc)
|
1994-06-08 22:57:30 +04:00
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
union dinode *dp;
|
1994-06-08 22:57:30 +04:00
|
|
|
struct zlncnt *zlnp;
|
2003-04-02 14:39:19 +04:00
|
|
|
daddr_t ndb;
|
|
|
|
int j;
|
1994-06-08 22:57:30 +04:00
|
|
|
mode_t mode;
|
2003-04-02 14:39:19 +04:00
|
|
|
u_int64_t size, kernmaxfilesize;
|
|
|
|
int64_t blocks;
|
2004-01-03 13:07:02 +03:00
|
|
|
char symbuf[MAXBSIZE];
|
2003-04-02 14:39:19 +04:00
|
|
|
struct inostat *info;
|
2011-03-06 20:08:10 +03:00
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
dp = getnextinode(inumber);
|
2003-04-02 14:39:19 +04:00
|
|
|
info = inoinfo(inumber);
|
|
|
|
mode = iswap16(DIP(dp, mode)) & IFMT;
|
|
|
|
size = iswap64(DIP(dp, size));
|
2011-03-06 20:08:10 +03:00
|
|
|
uid = iswap32(DIP(dp, uid));
|
|
|
|
gid = iswap32(DIP(dp, gid));
|
1994-06-08 22:57:30 +04:00
|
|
|
if (mode == 0) {
|
2003-04-02 14:39:19 +04:00
|
|
|
if ((is_ufs2 &&
|
|
|
|
(memcmp(dp->dp2.di_db, ufs2_zino.di_db,
|
2013-01-22 13:39:11 +04:00
|
|
|
UFS_NDADDR * sizeof(int64_t)) ||
|
2003-04-02 14:39:19 +04:00
|
|
|
memcmp(dp->dp2.di_ib, ufs2_zino.di_ib,
|
2013-01-22 13:39:11 +04:00
|
|
|
UFS_NIADDR * sizeof(int64_t))))
|
2003-04-02 14:39:19 +04:00
|
|
|
||
|
|
|
|
(!is_ufs2 &&
|
|
|
|
(memcmp(dp->dp1.di_db, ufs1_zino.di_db,
|
2013-01-22 13:39:11 +04:00
|
|
|
UFS_NDADDR * sizeof(int32_t)) ||
|
2003-04-02 14:39:19 +04:00
|
|
|
memcmp(dp->dp1.di_ib, ufs1_zino.di_ib,
|
2013-01-22 13:39:11 +04:00
|
|
|
UFS_NIADDR * sizeof(int32_t)))) ||
|
2003-04-02 14:39:19 +04:00
|
|
|
mode || size) {
|
2005-08-19 06:07:18 +04:00
|
|
|
pfatal("PARTIALLY ALLOCATED INODE I=%llu",
|
|
|
|
(unsigned long long)inumber);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (reply("CLEAR") == 1) {
|
|
|
|
dp = ginode(inumber);
|
|
|
|
clearinode(dp);
|
|
|
|
inodirty();
|
1998-03-18 20:01:23 +03:00
|
|
|
} else
|
|
|
|
markclean = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
info->ino_state = USTATE;
|
1994-06-08 22:57:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastino = inumber;
|
2003-04-02 14:39:19 +04:00
|
|
|
/* This should match the file size limit in ffs_mountfs(). */
|
|
|
|
if (is_ufs2)
|
|
|
|
kernmaxfilesize = sblock->fs_maxfilesize;
|
|
|
|
else
|
|
|
|
kernmaxfilesize = (u_int64_t)0x80000000 * sblock->fs_bsize - 1;
|
|
|
|
if (size > kernmaxfilesize || size + sblock->fs_bsize - 1 < size ||
|
1998-03-18 20:01:23 +03:00
|
|
|
(mode == IFDIR && size > MAXDIRSIZE)) {
|
1994-06-08 22:57:30 +04:00
|
|
|
if (debug)
|
2001-01-05 05:02:57 +03:00
|
|
|
printf("bad size %llu:",(unsigned long long)size);
|
1994-06-08 22:57:30 +04:00
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
if (!preen && mode == IFMT && reply("HOLD BAD BLOCK") == 1) {
|
|
|
|
dp = ginode(inumber);
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(dp, size, iswap64(sblock->fs_fsize));
|
1998-03-18 20:01:23 +03:00
|
|
|
size = sblock->fs_fsize;
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(dp, mode, iswap16(IFREG|0600));
|
1994-06-08 22:57:30 +04:00
|
|
|
inodirty();
|
|
|
|
}
|
1998-03-18 20:01:23 +03:00
|
|
|
ndb = howmany(size, sblock->fs_bsize);
|
1994-06-08 22:57:30 +04:00
|
|
|
if (ndb < 0) {
|
|
|
|
if (debug)
|
2003-04-02 14:39:19 +04:00
|
|
|
printf("bad size %llu ndb %lld:",
|
|
|
|
(unsigned long long)size, (long long)ndb);
|
1994-06-08 22:57:30 +04:00
|
|
|
goto unknown;
|
|
|
|
}
|
|
|
|
if (mode == IFBLK || mode == IFCHR)
|
|
|
|
ndb++;
|
|
|
|
if (mode == IFLNK) {
|
|
|
|
/*
|
|
|
|
* Note that the old fastlink format always had di_blocks set
|
|
|
|
* to 0. Other than that we no longer use the `spare' field
|
|
|
|
* (which is now the extended uid) for sanity checking, the
|
|
|
|
* new format is the same as the old. We simply ignore the
|
|
|
|
* conversion altogether. - mycroft, 19MAY1994
|
|
|
|
*/
|
2003-04-02 14:39:19 +04:00
|
|
|
if (!is_ufs2 && doinglevel2 &&
|
2013-01-22 13:39:11 +04:00
|
|
|
size > 0 && size < UFS1_MAXSYMLINKLEN &&
|
2003-04-02 14:39:19 +04:00
|
|
|
DIP(dp, blocks) != 0) {
|
1994-06-08 22:57:30 +04:00
|
|
|
if (bread(fsreadfd, symbuf,
|
2003-04-02 14:39:19 +04:00
|
|
|
fsbtodb(sblock, iswap32(DIP(dp, db[0]))),
|
1994-06-29 15:01:35 +04:00
|
|
|
(long)secsize) != 0)
|
2008-02-24 00:41:47 +03:00
|
|
|
errexit("cannot read symlink");
|
1994-06-08 22:57:30 +04:00
|
|
|
if (debug) {
|
1998-03-18 20:01:23 +03:00
|
|
|
symbuf[size] = 0;
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("convert symlink %llu(%s) "
|
|
|
|
"of size %lld\n",
|
|
|
|
(unsigned long long)inumber, symbuf,
|
1998-03-18 20:01:23 +03:00
|
|
|
(unsigned long long)size);
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
dp = ginode(inumber);
|
2003-04-02 14:39:19 +04:00
|
|
|
memmove(dp->dp1.di_db, symbuf, (long)size);
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(dp, blocks, 0);
|
1994-06-08 22:57:30 +04:00
|
|
|
inodirty();
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Fake ndb value so direct/indirect block checks below
|
|
|
|
* will detect any garbage after symlink string.
|
|
|
|
*/
|
2004-01-03 13:11:41 +03:00
|
|
|
if ((sblock->fs_maxsymlinklen < 0) ||
|
2011-08-14 16:32:01 +04:00
|
|
|
(size < (uint64_t)sblock->fs_maxsymlinklen) ||
|
2002-09-29 00:11:05 +04:00
|
|
|
(isappleufs && (size < APPLEUFS_MAXSYMLINKLEN)) ||
|
2003-04-02 14:39:19 +04:00
|
|
|
(sblock->fs_maxsymlinklen == 0 && DIP(dp, blocks) == 0)) {
|
|
|
|
if (is_ufs2)
|
|
|
|
ndb = howmany(size, sizeof(int64_t));
|
|
|
|
else
|
|
|
|
ndb = howmany(size, sizeof(int32_t));
|
2013-01-22 13:39:11 +04:00
|
|
|
if (ndb > UFS_NDADDR) {
|
|
|
|
j = ndb - UFS_NDADDR;
|
1994-06-08 22:57:30 +04:00
|
|
|
for (ndb = 1; j > 1; j--)
|
1998-03-18 20:01:23 +03:00
|
|
|
ndb *= NINDIR(sblock);
|
2013-01-22 13:39:11 +04:00
|
|
|
ndb += UFS_NDADDR;
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-22 13:39:11 +04:00
|
|
|
if (ndb < UFS_NDADDR) {
|
|
|
|
for (j = ndb; j < UFS_NDADDR; j++)
|
2003-04-02 14:39:19 +04:00
|
|
|
if (DIP(dp, db[j]) != 0) {
|
|
|
|
if (debug) {
|
|
|
|
if (!is_ufs2)
|
|
|
|
printf("bad direct addr ix %d: %d [ndb %lld]\n",
|
|
|
|
j, iswap32(dp->dp1.di_db[j]),
|
|
|
|
(long long)ndb);
|
|
|
|
else
|
|
|
|
printf("bad direct addr ix %d: %lld [ndb %lld]\n",
|
2003-04-03 02:27:09 +04:00
|
|
|
j, (long long)iswap64(dp->dp2.di_db[j]),
|
2003-04-02 14:39:19 +04:00
|
|
|
(long long)ndb);
|
|
|
|
}
|
|
|
|
goto unknown;
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
2005-12-06 02:59:43 +03:00
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
|
2013-01-22 13:39:11 +04:00
|
|
|
for (j = 0, ndb -= UFS_NDADDR; ndb > 0; j++)
|
1998-03-18 20:01:23 +03:00
|
|
|
ndb /= NINDIR(sblock);
|
2003-04-02 14:39:19 +04:00
|
|
|
|
2013-01-22 13:39:11 +04:00
|
|
|
for (; j < UFS_NIADDR; j++)
|
2003-04-02 14:39:19 +04:00
|
|
|
if (DIP(dp, ib[j]) != 0) {
|
|
|
|
if (debug) {
|
|
|
|
if (!is_ufs2)
|
|
|
|
printf("bad indirect addr: %d\n",
|
|
|
|
iswap32(dp->dp1.di_ib[j]));
|
|
|
|
else
|
|
|
|
printf("bad indirect addr: %lld\n",
|
|
|
|
(long long)iswap64(dp->dp2.di_ib[j]));
|
|
|
|
}
|
|
|
|
goto unknown;
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
if (ftypeok(dp) == 0)
|
|
|
|
goto unknown;
|
|
|
|
n_files++;
|
2003-04-02 14:39:19 +04:00
|
|
|
info->ino_linkcnt = iswap16(DIP(dp, nlink));
|
|
|
|
if (info->ino_linkcnt <= 0) {
|
1994-06-08 22:57:30 +04:00
|
|
|
zlnp = (struct zlncnt *)malloc(sizeof *zlnp);
|
|
|
|
if (zlnp == NULL) {
|
1998-03-18 20:01:23 +03:00
|
|
|
markclean = 0;
|
1994-06-08 22:57:30 +04:00
|
|
|
pfatal("LINK COUNT TABLE OVERFLOW");
|
1999-11-15 22:18:24 +03:00
|
|
|
if (reply("CONTINUE") == 0) {
|
2011-06-09 23:57:50 +04:00
|
|
|
ckfini(1);
|
2008-02-24 00:41:47 +03:00
|
|
|
exit(FSCK_EXIT_CHECK_FAILED);
|
1999-11-15 22:18:24 +03:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
} else {
|
|
|
|
zlnp->zlncnt = inumber;
|
|
|
|
zlnp->next = zlnhead;
|
|
|
|
zlnhead = zlnp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mode == IFDIR) {
|
1998-03-18 20:01:23 +03:00
|
|
|
if (size == 0)
|
2003-04-02 14:39:19 +04:00
|
|
|
info->ino_state = DCLEAR;
|
1994-06-08 22:57:30 +04:00
|
|
|
else
|
2003-04-02 14:39:19 +04:00
|
|
|
info->ino_state = DSTATE;
|
1994-06-08 22:57:30 +04:00
|
|
|
cacheino(dp, inumber);
|
2003-04-02 14:39:19 +04:00
|
|
|
countdirs++;
|
1994-06-08 22:57:30 +04:00
|
|
|
} else
|
2003-04-02 14:39:19 +04:00
|
|
|
info->ino_state = FSTATE;
|
|
|
|
info->ino_type = IFTODT(mode);
|
|
|
|
if (!is_ufs2 && doinglevel2 &&
|
|
|
|
(iswap16(dp->dp1.di_ouid) != (u_short)-1 ||
|
|
|
|
iswap16(dp->dp1.di_ogid) != (u_short)-1)) {
|
1994-06-08 22:57:30 +04:00
|
|
|
dp = ginode(inumber);
|
2003-04-02 14:39:19 +04:00
|
|
|
dp->dp1.di_uid = iswap32(iswap16(dp->dp1.di_ouid));
|
|
|
|
dp->dp1.di_ouid = iswap16(-1);
|
|
|
|
dp->dp1.di_gid = iswap32(iswap16(dp->dp1.di_ogid));
|
|
|
|
dp->dp1.di_ogid = iswap16(-1);
|
1994-06-08 22:57:30 +04:00
|
|
|
inodirty();
|
|
|
|
}
|
|
|
|
badblk = dupblk = 0;
|
|
|
|
idesc->id_number = inumber;
|
2011-03-06 20:08:10 +03:00
|
|
|
idesc->id_uid = iswap32(DIP(dp, uid));
|
|
|
|
idesc->id_gid = iswap32(DIP(dp, gid));
|
2004-05-25 18:54:55 +04:00
|
|
|
if (iswap32(DIP(dp, flags)) & SF_SNAPSHOT)
|
|
|
|
idesc->id_type = SNAP;
|
|
|
|
else
|
|
|
|
idesc->id_type = ADDR;
|
1994-06-08 22:57:30 +04:00
|
|
|
(void)ckinode(dp, idesc);
|
2005-06-09 00:34:06 +04:00
|
|
|
#ifdef notyet
|
|
|
|
if (is_ufs2 && iswap32(dp->dp2.di_extsize) > 0) {
|
|
|
|
int ret, offset;
|
|
|
|
idesc->id_type = ADDR;
|
|
|
|
ndb = howmany(iswap32(dp->dp2.di_extsize), sblock->fs_bsize);
|
2013-01-22 13:39:11 +04:00
|
|
|
for (j = 0; j < UFS_NXADDR; j++) {
|
2005-06-09 00:34:06 +04:00
|
|
|
if (--ndb == 0 &&
|
|
|
|
(offset = blkoff(sblock, iswap32(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 = iswap64(dp->dp2.di_extb[j]);
|
|
|
|
ret = (*idesc->id_func)(idesc);
|
|
|
|
if (ret & STOP)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
1998-03-18 20:01:23 +03:00
|
|
|
idesc->id_entryno *= btodb(sblock->fs_fsize);
|
2003-04-02 14:39:19 +04:00
|
|
|
if (is_ufs2)
|
|
|
|
blocks = iswap64(dp->dp2.di_blocks);
|
|
|
|
else
|
|
|
|
blocks = iswap32(dp->dp1.di_blocks);
|
|
|
|
if (blocks != idesc->id_entryno) {
|
2005-08-19 06:07:18 +04:00
|
|
|
pwarn("INCORRECT BLOCK COUNT I=%llu (%lld should be %lld)",
|
|
|
|
(unsigned long long)inumber, (long long)blocks,
|
|
|
|
(long long)idesc->id_entryno);
|
1994-06-08 22:57:30 +04:00
|
|
|
if (preen)
|
|
|
|
printf(" (CORRECTED)\n");
|
1998-03-18 20:01:23 +03:00
|
|
|
else if (reply("CORRECT") == 0) {
|
|
|
|
markclean = 0;
|
1994-06-08 22:57:30 +04:00
|
|
|
return;
|
1998-03-18 20:01:23 +03:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
dp = ginode(inumber);
|
2003-04-02 14:39:19 +04:00
|
|
|
if (is_ufs2)
|
|
|
|
dp->dp2.di_blocks = iswap64(idesc->id_entryno);
|
|
|
|
else
|
|
|
|
dp->dp1.di_blocks = iswap32((int32_t)idesc->id_entryno);
|
1994-06-08 22:57:30 +04:00
|
|
|
inodirty();
|
|
|
|
}
|
2011-03-06 20:08:10 +03:00
|
|
|
if (idesc->id_type != SNAP)
|
|
|
|
update_uquot(inumber, idesc->id_uid, idesc->id_gid,
|
|
|
|
idesc->id_entryno, 1);
|
1994-06-08 22:57:30 +04:00
|
|
|
return;
|
|
|
|
unknown:
|
2005-08-19 06:07:18 +04:00
|
|
|
pfatal("UNKNOWN FILE TYPE I=%llu", (unsigned long long)inumber);
|
2003-04-02 14:39:19 +04:00
|
|
|
info->ino_state = FCLEAR;
|
1994-06-08 22:57:30 +04:00
|
|
|
if (reply("CLEAR") == 1) {
|
2003-04-02 14:39:19 +04:00
|
|
|
info->ino_state = USTATE;
|
1994-06-08 22:57:30 +04:00
|
|
|
dp = ginode(inumber);
|
|
|
|
clearinode(dp);
|
|
|
|
inodirty();
|
1998-03-18 20:01:23 +03:00
|
|
|
} else
|
|
|
|
markclean = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
int
|
2005-01-19 20:33:58 +03:00
|
|
|
pass1check(struct inodesc *idesc)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
int res = KEEPON;
|
|
|
|
int anyout, nfrags;
|
2003-01-25 00:55:02 +03:00
|
|
|
daddr_t blkno = idesc->id_blkno;
|
1997-09-14 18:36:29 +04:00
|
|
|
struct dups *dlp;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct dups *new;
|
|
|
|
|
2004-05-25 18:54:55 +04:00
|
|
|
if (idesc->id_type == SNAP) {
|
|
|
|
if (blkno == BLK_NOCOPY || blkno == BLK_SNAP)
|
|
|
|
return (KEEPON);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) {
|
|
|
|
blkerror(idesc->id_number, "BAD", blkno);
|
|
|
|
if (badblk++ >= MAXBAD) {
|
2005-08-19 06:07:18 +04:00
|
|
|
pwarn("EXCESSIVE BAD BLKS I=%llu",
|
|
|
|
(unsigned long long)idesc->id_number);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (preen)
|
|
|
|
printf(" (SKIPPING)\n");
|
1999-11-15 22:18:24 +03:00
|
|
|
else if (reply("CONTINUE") == 0) {
|
|
|
|
markclean = 0;
|
2011-06-09 23:57:50 +04:00
|
|
|
ckfini(1);
|
2008-02-24 00:41:47 +03:00
|
|
|
exit(FSCK_EXIT_CHECK_FAILED);
|
1999-11-15 22:18:24 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03: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) {
|
2005-08-19 06:07:18 +04:00
|
|
|
pwarn("EXCESSIVE DUP BLKS I=%llu",
|
|
|
|
(unsigned long long)idesc->id_number);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (preen)
|
|
|
|
printf(" (SKIPPING)\n");
|
1999-11-15 22:18:24 +03:00
|
|
|
else if (reply("CONTINUE") == 0) {
|
|
|
|
markclean = 0;
|
2011-06-09 23:57:50 +04:00
|
|
|
ckfini(1);
|
2008-02-24 00:41:47 +03:00
|
|
|
exit(FSCK_EXIT_CHECK_FAILED);
|
1999-11-15 22:18:24 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
return (STOP);
|
|
|
|
}
|
|
|
|
new = (struct dups *)malloc(sizeof(struct dups));
|
|
|
|
if (new == NULL) {
|
1998-03-18 20:01:23 +03:00
|
|
|
markclean = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
pfatal("DUP TABLE OVERFLOW.");
|
1999-11-15 22:18:24 +03:00
|
|
|
if (reply("CONTINUE") == 0) {
|
|
|
|
markclean = 0;
|
2011-06-09 23:57:50 +04:00
|
|
|
ckfini(1);
|
2008-02-24 00:41:47 +03:00
|
|
|
exit(FSCK_EXIT_CHECK_FAILED);
|
1999-11-15 22:18:24 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03: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);
|
|
|
|
}
|