2005-06-27 05:25:35 +04:00
|
|
|
/* $NetBSD: pass5.c,v 1.46 2005/06/27 01:25:35 christos 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[] = "@(#)pass5.c 8.9 (Berkeley) 4/28/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
2005-06-27 05:25:35 +04:00
|
|
|
__RCSID("$NetBSD: pass5.c,v 1.46 2005/06/27 01:25:35 christos 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>
|
1994-04-25 22:28:42 +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/ffs/fs.h>
|
1998-03-18 20:01:23 +03:00
|
|
|
#include <ufs/ffs/ffs_extern.h>
|
|
|
|
#include <ufs/ufs/ufs_bswap.h>
|
1997-09-16 20:44:43 +04:00
|
|
|
|
|
|
|
#include <err.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <string.h>
|
1998-03-18 20:01:23 +03:00
|
|
|
#include <malloc.h>
|
1996-09-23 20:18:31 +04:00
|
|
|
|
1996-09-28 02:45:10 +04:00
|
|
|
#include "fsutil.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "fsck.h"
|
1994-12-05 23:15:31 +03:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2005-01-20 18:29:40 +03:00
|
|
|
void print_bmap(u_char *,u_int32_t);
|
1998-03-18 20:01:23 +03:00
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
2003-04-02 14:39:19 +04:00
|
|
|
pass5(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2004-01-09 22:12:31 +03:00
|
|
|
int c, blk, frags, basesize, sumsize, mapsize, cssize;
|
1999-11-15 22:18:24 +03:00
|
|
|
int inomapsize, blkmapsize;
|
1998-03-18 20:01:23 +03:00
|
|
|
struct fs *fs = sblock;
|
2003-01-25 00:55:02 +03:00
|
|
|
daddr_t dbase, dmax;
|
|
|
|
daddr_t d;
|
1999-11-15 22:18:24 +03:00
|
|
|
long i, j, k;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct csum *cs;
|
2003-04-02 14:39:19 +04:00
|
|
|
struct csum_total cstotal;
|
2001-01-26 20:37:16 +03:00
|
|
|
struct inodesc idesc[4];
|
1993-03-21 12:45:37 +03:00
|
|
|
char buf[MAXBSIZE];
|
1997-09-14 18:36:29 +04:00
|
|
|
struct cg *newcg = (struct cg *)buf;
|
2004-01-09 22:12:31 +03:00
|
|
|
struct ocg *ocg = (struct ocg *)buf;
|
2003-09-19 12:35:15 +04:00
|
|
|
struct cg *cg = cgrp, *ncg;
|
2003-04-02 14:39:19 +04:00
|
|
|
struct inostat *info;
|
2003-09-19 12:35:15 +04:00
|
|
|
u_int32_t ncgsize;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
inoinfo(WINO)->ino_state = USTATE;
|
1994-09-23 18:26:58 +04:00
|
|
|
memset(newcg, 0, (size_t)fs->fs_cgsize);
|
1993-03-21 12:45:37 +03:00
|
|
|
newcg->cg_niblk = fs->fs_ipg;
|
1994-12-28 03:03:49 +03:00
|
|
|
if (cvtlevel >= 3) {
|
1994-06-08 22:57:30 +04:00
|
|
|
if (fs->fs_maxcontig < 2 && fs->fs_contigsumsize > 0) {
|
|
|
|
if (preen)
|
|
|
|
pwarn("DELETING CLUSTERING MAPS\n");
|
|
|
|
if (preen || reply("DELETE CLUSTERING MAPS")) {
|
|
|
|
fs->fs_contigsumsize = 0;
|
|
|
|
doinglevel1 = 1;
|
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fs->fs_maxcontig > 1) {
|
2005-06-27 05:25:35 +04:00
|
|
|
const char *doit = NULL;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
if (fs->fs_contigsumsize < 1) {
|
|
|
|
doit = "CREAT";
|
|
|
|
} else if (fs->fs_contigsumsize < fs->fs_maxcontig &&
|
|
|
|
fs->fs_contigsumsize < FS_MAXCONTIG) {
|
|
|
|
doit = "EXPAND";
|
|
|
|
}
|
|
|
|
if (doit) {
|
|
|
|
i = fs->fs_contigsumsize;
|
|
|
|
fs->fs_contigsumsize =
|
|
|
|
MIN(fs->fs_maxcontig, FS_MAXCONTIG);
|
|
|
|
if (CGSIZE(fs) > fs->fs_bsize) {
|
|
|
|
pwarn("CANNOT %s CLUSTER MAPS\n", doit);
|
|
|
|
fs->fs_contigsumsize = i;
|
|
|
|
} else if (preen ||
|
|
|
|
reply("CREATE CLUSTER MAPS")) {
|
|
|
|
if (preen)
|
|
|
|
pwarn("%sING CLUSTER MAPS\n",
|
|
|
|
doit);
|
2003-09-19 12:35:15 +04:00
|
|
|
ncgsize = fragroundup(fs, CGSIZE(fs));
|
|
|
|
ncg = realloc(cgrp, ncgsize);
|
|
|
|
if (ncg == NULL)
|
1999-11-15 22:18:24 +03:00
|
|
|
errx(EEXIT,
|
|
|
|
"cannot reallocate cg space");
|
2003-09-19 12:35:15 +04:00
|
|
|
cg = cgrp = ncg;
|
|
|
|
fs->fs_cgsize = ncgsize;
|
1994-06-08 22:57:30 +04:00
|
|
|
doinglevel1 = 1;
|
|
|
|
sbdirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
basesize = &newcg->cg_space[0] - (u_char *)(&newcg->cg_firstfield);
|
2003-04-04 19:02:40 +04:00
|
|
|
cssize = (u_char *)&cstotal.cs_spare[0] - (u_char *)&cstotal.cs_ndir;
|
2004-01-09 22:12:31 +03:00
|
|
|
sumsize = 0;
|
2003-04-02 14:39:19 +04:00
|
|
|
if (is_ufs2) {
|
|
|
|
newcg->cg_iusedoff = basesize;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We reserve the space for the old rotation summary
|
|
|
|
* tables for the benefit of old kernels, but do not
|
|
|
|
* maintain them in modern kernels. In time, they can
|
|
|
|
* go away.
|
|
|
|
*/
|
|
|
|
newcg->cg_old_btotoff = basesize;
|
|
|
|
newcg->cg_old_boff = newcg->cg_old_btotoff +
|
|
|
|
fs->fs_old_cpg * sizeof(int32_t);
|
|
|
|
newcg->cg_iusedoff = newcg->cg_old_boff +
|
|
|
|
fs->fs_old_cpg * fs->fs_old_nrpos * sizeof(u_int16_t);
|
|
|
|
memset(&newcg->cg_space[0], 0, newcg->cg_iusedoff - basesize);
|
|
|
|
}
|
|
|
|
inomapsize = howmany(fs->fs_ipg, CHAR_BIT);
|
|
|
|
newcg->cg_freeoff = newcg->cg_iusedoff + inomapsize;
|
|
|
|
blkmapsize = howmany(fs->fs_fpg, CHAR_BIT);
|
|
|
|
newcg->cg_nextfreeoff = newcg->cg_freeoff + blkmapsize;
|
|
|
|
if (fs->fs_contigsumsize > 0) {
|
|
|
|
newcg->cg_clustersumoff = newcg->cg_nextfreeoff -
|
|
|
|
sizeof(u_int32_t);
|
2004-01-09 22:12:31 +03:00
|
|
|
if (isappleufs) {
|
|
|
|
/* Apple PR2216969 gives rationale for this change.
|
|
|
|
* I believe they were mistaken, but we need to
|
|
|
|
* duplicate it for compatibility. -- dbj@NetBSD.org
|
|
|
|
*/
|
|
|
|
newcg->cg_clustersumoff += sizeof(u_int32_t);
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
newcg->cg_clustersumoff =
|
|
|
|
roundup(newcg->cg_clustersumoff, sizeof(u_int32_t));
|
|
|
|
newcg->cg_clusteroff = newcg->cg_clustersumoff +
|
|
|
|
(fs->fs_contigsumsize + 1) * sizeof(u_int32_t);
|
|
|
|
newcg->cg_nextfreeoff = newcg->cg_clusteroff +
|
|
|
|
howmany(fragstoblks(fs, fs->fs_fpg), CHAR_BIT);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
newcg->cg_magic = CG_MAGIC;
|
|
|
|
mapsize = newcg->cg_nextfreeoff - newcg->cg_iusedoff;
|
2004-01-09 22:12:31 +03:00
|
|
|
if (!is_ufs2 && ((fs->fs_old_flags & FS_FLAGS_UPDATED) == 0)) {
|
|
|
|
switch ((int)fs->fs_old_postblformat) {
|
|
|
|
|
|
|
|
case FS_42POSTBLFMT:
|
|
|
|
basesize = (char *)(&ocg->cg_btot[0]) -
|
|
|
|
(char *)(&ocg->cg_firstfield);
|
|
|
|
sumsize = &ocg->cg_iused[0] - (u_int8_t *)(&ocg->cg_btot[0]);
|
|
|
|
mapsize = &ocg->cg_free[howmany(fs->fs_fpg, NBBY)] -
|
|
|
|
(u_char *)&ocg->cg_iused[0];
|
|
|
|
blkmapsize = howmany(fs->fs_fpg, NBBY);
|
|
|
|
inomapsize = &ocg->cg_free[0] - (u_char *)&ocg->cg_iused[0];
|
|
|
|
ocg->cg_magic = CG_MAGIC;
|
|
|
|
newcg->cg_magic = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FS_DYNAMICPOSTBLFMT:
|
|
|
|
sumsize = newcg->cg_iusedoff - newcg->cg_old_btotoff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
errx(EEXIT, "UNKNOWN ROTATIONAL TABLE FORMAT %d",
|
|
|
|
fs->fs_old_postblformat);
|
|
|
|
}
|
|
|
|
}
|
1994-09-23 18:26:58 +04:00
|
|
|
memset(&idesc[0], 0, sizeof idesc);
|
2001-01-26 20:37:16 +03:00
|
|
|
for (i = 0; i < 4; i++) {
|
1993-03-21 12:45:37 +03:00
|
|
|
idesc[i].id_type = ADDR;
|
2003-04-02 14:39:19 +04:00
|
|
|
if (!is_ufs2 && doinglevel2)
|
1994-06-08 22:57:30 +04:00
|
|
|
idesc[i].id_fix = FIX;
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
memset(&cstotal, 0, sizeof(struct csum_total));
|
|
|
|
dmax = blknum(fs, fs->fs_size + fs->fs_frag - 1);
|
|
|
|
for (d = fs->fs_size; d < dmax; d++)
|
|
|
|
setbmap(d);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (c = 0; c < fs->fs_ncg; c++) {
|
2002-05-06 07:17:43 +04:00
|
|
|
if (got_siginfo) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: phase 5: cyl group %d of %d (%d%%)\n",
|
|
|
|
cdevname(), c, fs->fs_ncg,
|
|
|
|
c * 100 / fs->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 5",
|
|
|
|
c, fs->fs_ncg);
|
2005-01-13 22:56:02 +03:00
|
|
|
#endif /* PROGRESS */
|
1993-03-21 12:45:37 +03:00
|
|
|
getblk(&cgblk, cgtod(fs, c), fs->fs_cgsize);
|
1998-03-18 20:01:23 +03:00
|
|
|
memcpy(cg, cgblk.b_un.b_cg, fs->fs_cgsize);
|
|
|
|
if((doswap && !needswap) || (!doswap && needswap))
|
2003-04-02 14:39:19 +04:00
|
|
|
ffs_cg_swap(cgblk.b_un.b_cg, cg, sblock);
|
2004-01-09 22:12:31 +03:00
|
|
|
if (!doinglevel1 && !cg_chkmagic(cg, 0))
|
1999-11-15 22:18:24 +03:00
|
|
|
pfatal("CG %d: PASS5: BAD MAGIC NUMBER\n", c);
|
1998-03-18 20:01:23 +03:00
|
|
|
if(doswap)
|
|
|
|
cgdirty();
|
2001-01-26 20:37:16 +03:00
|
|
|
/*
|
|
|
|
* While we have the disk head where we want it,
|
|
|
|
* write back the superblock to the spare at this
|
|
|
|
* cylinder group.
|
|
|
|
*/
|
|
|
|
if ((cvtlevel && sblk.b_dirty) || doswap) {
|
|
|
|
bwrite(fswritefd, sblk.b_un.b_buf,
|
|
|
|
fsbtodb(sblock, cgsblock(sblock, c)),
|
|
|
|
sblock->fs_sbsize);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Read in the current alternate superblock,
|
|
|
|
* and compare it to the master. If it's
|
|
|
|
* wrong, fix it up.
|
|
|
|
*/
|
|
|
|
getblk(&asblk, cgsblock(sblock, c), sblock->fs_sbsize);
|
|
|
|
if (asblk.b_errs)
|
|
|
|
pfatal("CG %d: UNABLE TO READ ALTERNATE "
|
|
|
|
"SUPERBLK\n", c);
|
|
|
|
else {
|
|
|
|
memmove(altsblock, asblk.b_un.b_fs,
|
|
|
|
sblock->fs_sbsize);
|
|
|
|
if (needswap)
|
2001-08-17 06:18:46 +04:00
|
|
|
ffs_sb_swap(asblk.b_un.b_fs, altsblock);
|
2001-01-26 20:37:16 +03:00
|
|
|
}
|
2004-01-09 22:12:31 +03:00
|
|
|
sb_oldfscompat_write(sblock, sblocksave);
|
2001-01-26 20:37:16 +03:00
|
|
|
if ((asblk.b_errs || cmpsblks(sblock, altsblock)) &&
|
|
|
|
dofix(&idesc[3],
|
|
|
|
"ALTERNATE SUPERBLK(S) ARE INCORRECT")) {
|
|
|
|
bwrite(fswritefd, sblk.b_un.b_buf,
|
|
|
|
fsbtodb(sblock, cgsblock(sblock, c)),
|
|
|
|
sblock->fs_sbsize);
|
|
|
|
}
|
2004-01-09 22:12:31 +03:00
|
|
|
sb_oldfscompat_read(sblock, 0);
|
2001-01-26 20:37:16 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
dbase = cgbase(fs, c);
|
|
|
|
dmax = dbase + fs->fs_fpg;
|
|
|
|
if (dmax > fs->fs_size)
|
|
|
|
dmax = fs->fs_size;
|
2004-01-09 22:12:31 +03:00
|
|
|
if (is_ufs2 || (fs->fs_old_flags & FS_FLAGS_UPDATED))
|
|
|
|
newcg->cg_time = cg->cg_time;
|
2003-04-02 14:39:19 +04:00
|
|
|
newcg->cg_old_time = cg->cg_old_time;
|
1993-03-21 12:45:37 +03:00
|
|
|
newcg->cg_cgx = c;
|
|
|
|
newcg->cg_ndblk = dmax - dbase;
|
2003-04-02 14:39:19 +04:00
|
|
|
if (!is_ufs2) {
|
2004-01-09 22:12:31 +03:00
|
|
|
if (c == fs->fs_ncg - 1) {
|
|
|
|
/* Avoid fighting old fsck for this value. Its never used
|
|
|
|
* outside of this check anyway.
|
|
|
|
*/
|
|
|
|
if ((fs->fs_old_flags & FS_FLAGS_UPDATED) == 0)
|
|
|
|
newcg->cg_old_ncyl = fs->fs_old_ncyl % fs->fs_old_cpg;
|
|
|
|
else
|
|
|
|
newcg->cg_old_ncyl = howmany(newcg->cg_ndblk,
|
|
|
|
fs->fs_fpg / fs->fs_old_cpg);
|
|
|
|
} else
|
2003-04-02 14:39:19 +04:00
|
|
|
newcg->cg_old_ncyl = fs->fs_old_cpg;
|
|
|
|
newcg->cg_old_niblk = fs->fs_ipg;
|
|
|
|
newcg->cg_niblk = 0;
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
if (fs->fs_contigsumsize > 0)
|
|
|
|
newcg->cg_nclusterblks = newcg->cg_ndblk / fs->fs_frag;
|
1993-03-21 12:45:37 +03:00
|
|
|
newcg->cg_cs.cs_ndir = 0;
|
|
|
|
newcg->cg_cs.cs_nffree = 0;
|
|
|
|
newcg->cg_cs.cs_nbfree = 0;
|
|
|
|
newcg->cg_cs.cs_nifree = fs->fs_ipg;
|
2001-01-09 14:20:00 +03:00
|
|
|
if (cg->cg_rotor >= 0 && cg->cg_rotor < newcg->cg_ndblk)
|
1993-03-21 12:45:37 +03:00
|
|
|
newcg->cg_rotor = cg->cg_rotor;
|
|
|
|
else
|
|
|
|
newcg->cg_rotor = 0;
|
2001-01-09 14:20:00 +03:00
|
|
|
if (cg->cg_frotor >= 0 && cg->cg_frotor < newcg->cg_ndblk)
|
1993-03-21 12:45:37 +03:00
|
|
|
newcg->cg_frotor = cg->cg_frotor;
|
|
|
|
else
|
|
|
|
newcg->cg_frotor = 0;
|
2003-04-04 17:45:21 +04:00
|
|
|
if (cg->cg_irotor >= 0 && cg->cg_irotor < fs->fs_ipg)
|
1993-03-21 12:45:37 +03:00
|
|
|
newcg->cg_irotor = cg->cg_irotor;
|
|
|
|
else
|
|
|
|
newcg->cg_irotor = 0;
|
2003-04-02 14:39:19 +04:00
|
|
|
if (!is_ufs2) {
|
|
|
|
newcg->cg_initediblk = 0;
|
|
|
|
} else {
|
|
|
|
if ((unsigned)cg->cg_initediblk > fs->fs_ipg)
|
|
|
|
newcg->cg_initediblk = fs->fs_ipg;
|
|
|
|
else
|
|
|
|
newcg->cg_initediblk = cg->cg_initediblk;
|
|
|
|
}
|
1994-09-23 18:26:58 +04:00
|
|
|
memset(&newcg->cg_frsum[0], 0, sizeof newcg->cg_frsum);
|
2004-01-09 22:12:31 +03:00
|
|
|
memset(&old_cg_blktot(newcg, 0)[0], 0, (size_t)(sumsize));
|
2003-04-02 14:39:19 +04:00
|
|
|
memset(cg_inosused(newcg, 0), 0, (size_t)(mapsize));
|
2004-01-09 22:12:31 +03:00
|
|
|
if (!is_ufs2 && ((fs->fs_old_flags & FS_FLAGS_UPDATED) == 0) &&
|
|
|
|
fs->fs_old_postblformat == FS_42POSTBLFMT)
|
|
|
|
ocg->cg_magic = CG_MAGIC;
|
1993-03-21 12:45:37 +03:00
|
|
|
j = fs->fs_ipg * c;
|
|
|
|
for (i = 0; i < fs->fs_ipg; j++, i++) {
|
2003-04-02 14:39:19 +04:00
|
|
|
info = inoinfo(j);
|
|
|
|
switch (info->ino_state) {
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
case USTATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DSTATE:
|
|
|
|
case DCLEAR:
|
|
|
|
case DFOUND:
|
|
|
|
newcg->cg_cs.cs_ndir++;
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case FSTATE:
|
|
|
|
case FCLEAR:
|
|
|
|
newcg->cg_cs.cs_nifree--;
|
1998-03-18 20:01:23 +03:00
|
|
|
setbit(cg_inosused(newcg, 0), i);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (j < ROOTINO)
|
|
|
|
break;
|
1997-09-16 20:44:43 +04:00
|
|
|
errx(EEXIT, "BAD STATE %d FOR INODE I=%ld",
|
2003-04-02 14:39:19 +04:00
|
|
|
info->ino_state, (long)j);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c == 0)
|
|
|
|
for (i = 0; i < ROOTINO; i++) {
|
1998-03-18 20:01:23 +03:00
|
|
|
setbit(cg_inosused(newcg, 0), i);
|
1993-03-21 12:45:37 +03:00
|
|
|
newcg->cg_cs.cs_nifree--;
|
|
|
|
}
|
|
|
|
for (i = 0, d = dbase;
|
|
|
|
d < dmax;
|
|
|
|
d += fs->fs_frag, i += fs->fs_frag) {
|
|
|
|
frags = 0;
|
|
|
|
for (j = 0; j < fs->fs_frag; j++) {
|
|
|
|
if (testbmap(d + j))
|
|
|
|
continue;
|
1998-03-18 20:01:23 +03:00
|
|
|
setbit(cg_blksfree(newcg, 0), i + j);
|
1993-03-21 12:45:37 +03:00
|
|
|
frags++;
|
|
|
|
}
|
|
|
|
if (frags == fs->fs_frag) {
|
|
|
|
newcg->cg_cs.cs_nbfree++;
|
2004-01-09 22:12:31 +03:00
|
|
|
if (sumsize) {
|
|
|
|
j = old_cbtocylno(fs, i);
|
|
|
|
old_cg_blktot(newcg, 0)[j]++;
|
|
|
|
old_cg_blks(fs, newcg, j, 0)[old_cbtorpos(fs, i)]++;
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
if (fs->fs_contigsumsize > 0)
|
1998-03-18 20:01:23 +03:00
|
|
|
setbit(cg_clustersfree(newcg, 0),
|
2002-04-10 21:29:30 +04:00
|
|
|
fragstoblks(fs, i));
|
1993-03-21 12:45:37 +03:00
|
|
|
} else if (frags > 0) {
|
|
|
|
newcg->cg_cs.cs_nffree += frags;
|
1998-03-18 20:01:23 +03:00
|
|
|
blk = blkmap(fs, cg_blksfree(newcg, 0), i);
|
|
|
|
ffs_fragacct(fs, blk, newcg->cg_frsum, 1, 0);
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fs->fs_contigsumsize > 0) {
|
1998-03-18 20:01:23 +03:00
|
|
|
int32_t *sump = cg_clustersum(newcg, 0);
|
|
|
|
u_char *mapp = cg_clustersfree(newcg, 0);
|
1994-06-08 22:57:30 +04:00
|
|
|
int map = *mapp++;
|
|
|
|
int bit = 1;
|
|
|
|
int run = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < newcg->cg_nclusterblks; i++) {
|
|
|
|
if ((map & bit) != 0) {
|
|
|
|
run++;
|
|
|
|
} else if (run != 0) {
|
|
|
|
if (run > fs->fs_contigsumsize)
|
|
|
|
run = fs->fs_contigsumsize;
|
|
|
|
sump[run]++;
|
|
|
|
run = 0;
|
|
|
|
}
|
|
|
|
if ((i & (NBBY - 1)) != (NBBY - 1)) {
|
|
|
|
bit <<= 1;
|
|
|
|
} else {
|
|
|
|
map = *mapp++;
|
|
|
|
bit = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (run != 0) {
|
|
|
|
if (run > fs->fs_contigsumsize)
|
|
|
|
run = fs->fs_contigsumsize;
|
|
|
|
sump[run]++;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cstotal.cs_nffree += newcg->cg_cs.cs_nffree;
|
|
|
|
cstotal.cs_nbfree += newcg->cg_cs.cs_nbfree;
|
|
|
|
cstotal.cs_nifree += newcg->cg_cs.cs_nifree;
|
|
|
|
cstotal.cs_ndir += newcg->cg_cs.cs_ndir;
|
|
|
|
cs = &fs->fs_cs(fs, c);
|
1998-08-25 23:18:12 +04:00
|
|
|
if (memcmp(&newcg->cg_cs, cs, sizeof *cs) != 0) {
|
2004-10-08 20:42:55 +04:00
|
|
|
if (debug) {
|
|
|
|
printf("cg %d: nffree: %d/%d nbfree %d/%d"
|
|
|
|
" nifree %d/%d ndir %d/%d\n",
|
|
|
|
c, cs->cs_nffree,newcg->cg_cs.cs_nffree,
|
|
|
|
cs->cs_nbfree,newcg->cg_cs.cs_nbfree,
|
|
|
|
cs->cs_nifree,newcg->cg_cs.cs_nifree,
|
|
|
|
cs->cs_ndir,newcg->cg_cs.cs_ndir);
|
|
|
|
}
|
1998-03-18 20:01:23 +03:00
|
|
|
if (dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
|
2003-04-02 14:39:19 +04:00
|
|
|
memmove(cs, &newcg->cg_cs, sizeof *cs);
|
|
|
|
sbdirty();
|
1998-03-18 20:01:23 +03:00
|
|
|
} else
|
|
|
|
markclean = 0;
|
1998-08-25 23:18:12 +04:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
if (doinglevel1) {
|
1997-09-16 20:44:43 +04:00
|
|
|
memmove(cg, newcg, (size_t)fs->fs_cgsize);
|
1993-03-21 12:45:37 +03:00
|
|
|
cgdirty();
|
|
|
|
continue;
|
|
|
|
}
|
2004-01-09 22:12:31 +03:00
|
|
|
if ((memcmp(newcg, cg, basesize) != 0) ||
|
|
|
|
(memcmp(&old_cg_blktot(newcg, 0)[0],
|
|
|
|
&old_cg_blktot(cg, 0)[0], sumsize) != 0)) {
|
2003-04-02 14:39:19 +04:00
|
|
|
if (dofix(&idesc[2], "SUMMARY INFORMATION BAD")) {
|
|
|
|
memmove(cg, newcg, (size_t)basesize);
|
2004-01-09 22:12:31 +03:00
|
|
|
memmove(&old_cg_blktot(cg, 0)[0],
|
|
|
|
&old_cg_blktot(newcg, 0)[0], (size_t)sumsize);
|
2003-04-02 14:39:19 +04:00
|
|
|
cgdirty();
|
1999-11-15 22:18:24 +03:00
|
|
|
} else
|
|
|
|
markclean = 0;
|
1998-08-25 23:18:12 +04:00
|
|
|
}
|
1999-11-15 22:18:24 +03:00
|
|
|
if (usedsoftdep) {
|
|
|
|
for (i = 0; i < inomapsize; i++) {
|
|
|
|
j = cg_inosused(newcg, 0)[i];
|
|
|
|
if ((cg_inosused(cg, 0)[i] & j) == j)
|
|
|
|
continue;
|
|
|
|
for (k = 0; k < NBBY; k++) {
|
|
|
|
if ((j & (1 << k)) == 0)
|
|
|
|
continue;
|
|
|
|
if (cg_inosused(cg, 0)[i] & (1 << k))
|
|
|
|
continue;
|
1999-11-28 23:03:17 +03:00
|
|
|
pwarn("ALLOCATED INODE %ld "
|
|
|
|
"MARKED FREE\n",
|
1999-11-15 22:18:24 +03:00
|
|
|
c * fs->fs_ipg + i * 8 + k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 0; i < blkmapsize; i++) {
|
|
|
|
j = cg_blksfree(cg, 0)[i];
|
|
|
|
if ((cg_blksfree(newcg, 0)[i] & j) == j)
|
|
|
|
continue;
|
|
|
|
for (k = 0; k < NBBY; k++) {
|
|
|
|
if ((j & (1 << k)) == 0)
|
|
|
|
continue;
|
|
|
|
if (cg_inosused(cg, 0)[i] & (1 << k))
|
|
|
|
continue;
|
2000-07-14 06:43:44 +04:00
|
|
|
pwarn("ALLOCATED FRAG %ld "
|
|
|
|
"MARKED FREE\n",
|
1999-11-15 22:18:24 +03:00
|
|
|
c * fs->fs_fpg + i * 8 + k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (memcmp(cg_inosused(newcg, 0), cg_inosused(cg, 0), mapsize)
|
|
|
|
!= 0 && dofix(&idesc[1], "BLK(S) MISSING IN BIT MAPS")) {
|
|
|
|
memmove(cg_inosused(cg, 0), cg_inosused(newcg, 0),
|
|
|
|
(size_t)mapsize);
|
|
|
|
cgdirty();
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2003-04-04 19:02:40 +04:00
|
|
|
if (memcmp(&cstotal, &fs->fs_cstotal, cssize) != 0) {
|
2004-10-08 20:42:55 +04:00
|
|
|
if (debug) {
|
|
|
|
printf("total: nffree: %lld/%lld nbfree %lld/%lld"
|
|
|
|
" nifree %lld/%lld ndir %lld/%lld\n",
|
2004-10-10 00:08:44 +04:00
|
|
|
(long long int)fs->fs_cstotal.cs_nffree,
|
|
|
|
(long long int)cstotal.cs_nffree,
|
|
|
|
(long long int)fs->fs_cstotal.cs_nbfree,
|
|
|
|
(long long int)cstotal.cs_nbfree,
|
|
|
|
(long long int)fs->fs_cstotal.cs_nifree,
|
|
|
|
(long long int)cstotal.cs_nifree,
|
|
|
|
(long long int)fs->fs_cstotal.cs_ndir,
|
|
|
|
(long long int)cstotal.cs_ndir);
|
2004-10-08 20:42:55 +04:00
|
|
|
}
|
2001-01-26 20:37:16 +03:00
|
|
|
if (dofix(&idesc[0], "FREE BLK COUNT(S) WRONG IN SUPERBLK")) {
|
2003-04-04 19:02:40 +04:00
|
|
|
memmove(&fs->fs_cstotal, &cstotal, sizeof cstotal);
|
2001-01-26 20:37:16 +03:00
|
|
|
fs->fs_ronly = 0;
|
|
|
|
fs->fs_fmod = 0;
|
|
|
|
sbdirty();
|
1998-03-18 20:01:23 +03:00
|
|
|
} else
|
|
|
|
markclean = 0;
|
1998-08-25 23:18:12 +04:00
|
|
|
}
|
2005-01-13 22:56:02 +03:00
|
|
|
#ifdef PROGRESS
|
2005-01-13 18:22:35 +03:00
|
|
|
if (preen)
|
|
|
|
progress_add(fs->fs_ncg);
|
|
|
|
else
|
|
|
|
progress_done();
|
2005-01-13 22:56:02 +03:00
|
|
|
#endif /* PROGRESS */
|
1998-03-18 20:01:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-01-19 20:33:58 +03:00
|
|
|
print_bmap(u_char *map, u_int32_t size)
|
1998-03-18 20:01:23 +03:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < size) {
|
|
|
|
printf("%u: ",i);
|
|
|
|
for (j = 0; j < 16; j++, i++)
|
|
|
|
printf("%2x ", (u_int)map[i] & 0xff);
|
|
|
|
printf("\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|