2 * pass4.c -- pass #4 of e2fsck: Check reference counts
4 * Copyright (C) 1993 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
11 void pass4(ext2_filsys fs)
14 struct ext2_inode inode;
15 struct resource_track rtrack;
17 init_resource_track(&rtrack);
20 mtrace_print("Pass 4");
24 printf("Pass 4: Checking reference counts\n");
25 for (i=1; i <= fs->super->s_inodes_count; i++) {
26 if (i == EXT2_BAD_INO ||
27 (i > EXT2_ROOT_INO && i < EXT2_FIRST_INO))
29 if (!(ext2fs_test_inode_bitmap(inode_used_map, i)))
31 if (inode_count[i] == 0) {
33 * Inode isn't attached to the filesystem;
34 * prompt to reconnect.
36 printf("Unattached inode %lu\n", i);
38 if (ask("Connect to /lost+found", 1)) {
39 if (reconnect_file(fs, i))
40 ext2fs_unmark_valid(fs);
42 ext2fs_unmark_valid(fs);
44 if (inode_count[i] != inode_link_info[i]) {
45 e2fsck_read_inode(fs, i, &inode, "pass4");
46 if (inode_link_info[i] != inode.i_links_count) {
47 printf("WARNING: PROGRAMMING BUG IN E2FSCK!\n");
48 printf("inode_link_info[%d] is %lu, "
49 "inode.i_links_count is %d. "
50 "They should be the same!\n",
51 i, inode_link_info[i],
54 printf("Inode %lu has ref count %d, expecting %d.\n",
55 i, inode.i_links_count, inode_count[i]);
56 if (ask("Set i_nlinks to count", 1)) {
57 inode.i_links_count = inode_count[i];
58 e2fsck_write_inode(fs, i, &inode, "pass4");
60 ext2fs_unmark_valid(fs);
63 free(inode_link_info); inode_link_info = 0;
64 free(inode_count); inode_count = 0;
67 print_resource_track(&rtrack);