e2fsprogs/e2fsck/pass4.c

81 lines
2.1 KiB
C
Raw Normal View History

1997-04-26 21:21:57 +08:00
/*
* pass4.c -- pass #4 of e2fsck: Check reference counts
*
* Copyright (C) 1993 Theodore Ts'o. This file may be redistributed
* under the terms of the GNU Public License.
*
*/
#include "e2fsck.h"
void pass4(ext2_filsys fs)
{
1997-04-26 21:34:30 +08:00
ino_t i;
1997-04-26 21:21:57 +08:00
struct ext2_inode inode;
struct resource_track rtrack;
init_resource_track(&rtrack);
#ifdef MTRACE
mtrace_print("Pass 4");
#endif
if (!preen)
1997-04-26 21:34:30 +08:00
printf("Pass 4: Checking reference counts\n");
1997-04-26 21:21:57 +08:00
for (i=1; i <= fs->super->s_inodes_count; i++) {
if (i == EXT2_BAD_INO ||
1997-04-26 22:48:50 +08:00
(i > EXT2_ROOT_INO && i < EXT2_FIRST_INODE(fs->super)))
1997-04-26 21:21:57 +08:00
continue;
1997-04-26 21:34:30 +08:00
if (!(ext2fs_test_inode_bitmap(inode_used_map, i)))
1997-04-26 21:21:57 +08:00
continue;
if (inode_count[i] == 0) {
/*
* Inode isn't attached to the filesystem;
* prompt to reconnect.
*/
1997-04-26 21:34:30 +08:00
printf("Unattached inode %lu\n", i);
1997-04-26 21:58:21 +08:00
preenhalt(fs);
1997-04-26 21:21:57 +08:00
if (ask("Connect to /lost+found", 1)) {
if (reconnect_file(fs, i))
ext2fs_unmark_valid(fs);
1997-04-29 22:53:37 +08:00
} else {
/*
* If we don't attach the inode, then
* skip the i_links_test since there's
* no point in trying to force
* i_links_count to zero.
*/
1997-04-26 21:21:57 +08:00
ext2fs_unmark_valid(fs);
1997-04-29 22:53:37 +08:00
continue;
}
1997-04-26 21:21:57 +08:00
}
if (inode_count[i] != inode_link_info[i]) {
1997-04-26 21:34:30 +08:00
e2fsck_read_inode(fs, i, &inode, "pass4");
1997-04-26 21:21:57 +08:00
if (inode_link_info[i] != inode.i_links_count) {
printf("WARNING: PROGRAMMING BUG IN E2FSCK!\n");
1997-04-29 22:53:37 +08:00
printf("\tOR SOME BONEHEAD (YOU) IS CHECKING "
"A MOUNTED (LIVE) FILESYSTEM.\n");
1997-04-26 21:58:21 +08:00
printf("inode_link_info[%ld] is %u, "
1997-04-26 21:21:57 +08:00
"inode.i_links_count is %d. "
"They should be the same!\n",
i, inode_link_info[i],
inode.i_links_count);
}
1997-04-26 21:34:30 +08:00
printf("Inode %lu has ref count %d, expecting %d.\n",
1997-04-26 21:21:57 +08:00
i, inode.i_links_count, inode_count[i]);
if (ask("Set i_nlinks to count", 1)) {
inode.i_links_count = inode_count[i];
1997-04-26 21:34:30 +08:00
e2fsck_write_inode(fs, i, &inode, "pass4");
1997-04-26 21:21:57 +08:00
} else
ext2fs_unmark_valid(fs);
}
}
free(inode_link_info); inode_link_info = 0;
free(inode_count); inode_count = 0;
if (tflag > 1) {
printf("Pass 4: ");
print_resource_track(&rtrack);
}
}