pass5.c revision 77a343ab1b2bc518f178bc7b473e770e3da2bb79
/*
* Copyright 2006 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "fsck.h"
void
pass5(void)
{
int excessdirs;
int inomapsize, blkmapsize;
diskaddr_t d;
uint64_t i, j;
union { /* keep lint happy about alignment */
} u;
pfatal("UNSUPPORTED ROTATIONAL TABLE FORMAT %d\n",
errexit("Program terminated.");
/* NOTREACHED */
}
/* LINTED this subtraction can't overflow and is int32-aligned */
/*
* 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 could
* theoretically go away, if we wanted to deal with
* changing the on-disk format.
*/
/*
* Note that we don't use any of the cg_*() macros until
* after cg_sanity() has approved of what we've got.
*/
/*
* If the last fragments in the file system don't make up a
* full file system block, mark the bits in the blockmap
* that correspond to those missing fragments as "allocated",
* so that the last block doesn't get counted as a free block
* and those missing fragments don't get counted as free frags.
*/
setbmap(i);
/*
* The cg summaries are not always updated when using
* logging. Since we're really concerned with getting a
* sane filesystem, rather than in trying to debug UFS
* corner cases, logically we would just always recompute
* them. However, it is disconcerting to users to be asked
* about updating the summaries when, from their point of
* view, there's been no indication of a problem up to this
* point. So, only do it if we find a discrepancy.
*/
update_csums = -1;
update_bitmaps = 0;
/*
* cg_sanity() will catch i/o errors for us.
*/
if (reply("REPAIR") == 0)
errexit("Program terminated.");
}
/*
* If the on-disk timestamp is in the future, then it
* by definition is wrong. Otherwise, if it's in
* the past, then use that value so that we don't
* declare a spurious mismatch.
*/
else
else
else
else
else
/* LINTED macro is int32-aligned per newcg->cg_btotoff above */
case USTATE:
break;
case DSTATE:
case DCLEAR:
case DFOUND:
case DZLINK:
/* FALLTHROUGH */
case FSTATE:
case FCLEAR:
case FZLINK:
case SSTATE:
case SCLEAR:
break;
default:
if (j < UFSROOTINO)
break;
errexit("BAD STATE 0x%x FOR INODE I=%d",
statemap[j], (int)j);
}
}
if (c == 0) {
for (i = 0; i < UFSROOTINO; i++) {
}
}
/*
* Count up what fragments and blocks are free, and
* reflect the relevant section of blockmap[] into
* newcg's map.
*/
for (i = 0, d = dbase;
d < dmax;
frags = 0;
if (testbmap(d + j))
continue;
frags++;
}
/* LINTED macro is int32-aligned per above */
/* LINTED cg_blks(newcg) is aligned */
} else if (frags > 0) {
}
}
/*
* Note that, just like the kernel, we dynamically
* allocated an array to hold the csums and stuffed
* the pointer into the in-core superblock's fs_u.fs_csp
* field. This means that the fs_u field contains a
* random value when the disk version is examined, but
* fs_cs() gives us a valid pointer nonetheless.
* We need to compare the recalculated summaries to
* both the superblock version and the on disk version.
* If either is bad, copy the calculated version over
* the corrupt values.
*/
sizeof (*cs)) != 0);
sizeof (struct csum)) != 0);
/*
* Has the user told us what to do yet? If not, find out.
*/
if (preen) {
update_csums = 1;
(void) printf("CORRECTING BAD CG SUMMARIES"
" FOR CG %d\n", c);
} else if (update_csums == -1) {
update_csums = (reply(
"CORRECT BAD CG SUMMARIES FOR CG %d",
c) == 1);
}
}
sizeof (*cs));
sbdirty();
(void) printf("CORRECTED SUPERBLOCK SUMMARIES FOR"
" CG %d\n", c);
}
sizeof (struct csum));
/* LINTED per cg_sanity() */
/* LINTED macro aligned as above */
cgdirty();
(void) printf("CORRECTED SUMMARIES FOR CG %d\n", c);
}
if (excessdirs < 0) {
pfatal("LOST %d DIRECTORIES IN CG %d\n",
-excessdirs, c);
excessdirs = 0;
}
if (excessdirs > 0) {
if (!verbose)
(void) printf("DIR BITMAP WRONG ");
if (preen || update_bitmaps ||
(void *)cg_inosused(newcg),
cgdirty();
if (preen ||
(!verbose && update_bitmaps))
(void) printf("(CORRECTED)\n");
update_bitmaps = 1;
}
}
}
if (!verbose)
(void) printf("FILE BITMAP WRONG ");
cgdirty();
if (preen ||
(!verbose && update_bitmaps))
(void) printf("(CORRECTED)\n");
update_bitmaps = 1;
}
}
if (!verbose)
(void) printf("FRAG BITMAP WRONG ");
cgdirty();
if (preen ||
(!verbose && update_bitmaps))
(void) printf("(CORRECTED)\n");
update_bitmaps = 1;
}
}
/*
* Fixing one set of problems often shows up more in the
* same cg. Just to make sure, go back and check it
* again if we found something this time through.
*/
if (cgisdirty()) {
cgflush();
c--;
}
}
sizeof (struct csum)) != 0)) {
sbdirty();
} else {
iscorrupt = 1;
}
}
}
/*
* Compare two allocation bitmaps, reporting any discrepancies.
*
* If a mismatch is found, if the bit is set in map1, it's considered
* to be an indication that the corresponding resource is supposed
* to be free, but isn't. Otherwise, it's considered marked as allocated
* but not found to be so. In other words, if the two maps being compared
* use a set bit to indicate something is free, pass the on-disk map
* first. Otherwise, pass the calculated map first.
*/
static int
int mapsize, /* size of above two maps */
int startvalue, /* resource value for first element in map */
char *name, /* name of resource found in maps */
int skip, /* number of entries to skip before starting to free */
int limit) /* limit on number of entries to free */
{
long i, j, k, l, m, n, size;
int mismatch;
mismatch = 0;
for (i = 0; i < mapsize; i++) {
j = *map1++;
k = *map2++;
if (j == k)
continue;
if ((j & l) == (k & l))
continue;
n = startvalue + i * NBBY + m;
if ((j & l) != 0) {
if (astart == -1) {
continue;
}
if (aend + 1 == n) {
aend = n;
continue;
}
if (verbose) {
"ALLOCATED %s %d WAS MARKED FREE ON DISK\n",
else
"ALLOCATED %sS %d-%d WERE MARKED FREE ON DISK\n",
}
mismatch = 1;
} else {
if (ustart == -1) {
continue;
}
if (uend + 1 == n) {
uend = n;
continue;
}
continue;
}
if (skip > 0) {
skip = 0;
}
if (verbose) {
if (size == 1)
"UNALLOCATED %s %d WAS MARKED USED ON DISK\n",
else
"UNALLOCATED %sS %d-%ld WERE MARKED USED ON DISK\n",
}
mismatch = 1;
if (limit <= 0)
return (mismatch);
}
}
}
if (astart != -1) {
if (verbose) {
"ALLOCATED %s %d WAS MARKED FREE ON DISK\n",
else
"ALLOCATED %sS %d-%d WERE MARKED FREE ON DISK\n",
}
mismatch = 1;
}
if (ustart != -1) {
return (mismatch);
if (skip > 0) {
}
if (verbose) {
if (size == 1)
"UNALLOCATED %s %d WAS MARKED USED ON DISK\n",
else
"UNALLOCATED %sS %d-%ld WERE MARKED USED ON DISK\n",
}
mismatch = 1;
}
return (mismatch);
}