blob: 290e1b9531fd643a5d57338aebe4e60594f1406f [file] [log] [blame]
Theodore Ts'o3839e651997-04-26 13:21:57 +00001/*
2 * pass4.c -- pass #4 of e2fsck: Check reference counts
3 *
4 * Copyright (C) 1993 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
6 *
7 */
8
9#include "e2fsck.h"
10
11void pass4(ext2_filsys fs)
12{
13 int i;
14 struct ext2_inode inode;
15 struct resource_track rtrack;
16
17 init_resource_track(&rtrack);
18
19#ifdef MTRACE
20 mtrace_print("Pass 4");
21#endif
22
23 if (!preen)
24 printf("Pass 4: Check 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))
28 continue;
29 if (!(ext2fs_test_inode_bitmap(fs, inode_used_map, i)))
30 continue;
31 if (inode_count[i] == 0) {
32 /*
33 * Inode isn't attached to the filesystem;
34 * prompt to reconnect.
35 */
36 printf("Unattached inode %d\n", i);
37 preenhalt();
38 if (ask("Connect to /lost+found", 1)) {
39 if (reconnect_file(fs, i))
40 ext2fs_unmark_valid(fs);
41 } else
42 ext2fs_unmark_valid(fs);
43 }
44 if (inode_count[i] != inode_link_info[i]) {
45 ext2fs_read_inode(fs, i, &inode);
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 %d, "
49 "inode.i_links_count is %d. "
50 "They should be the same!\n",
51 i, inode_link_info[i],
52 inode.i_links_count);
53 }
54 printf("Inode %d 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 ext2fs_write_inode(fs, i, &inode);
59 } else
60 ext2fs_unmark_valid(fs);
61 }
62 }
63 free(inode_link_info); inode_link_info = 0;
64 free(inode_count); inode_count = 0;
65 if (tflag > 1) {
66 printf("Pass 4: ");
67 print_resource_track(&rtrack);
68 }
69}
70