2 * tst_inode.c --- this function tests the inode scan function
4 * Copyright (C) 1996 by Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
20 #include <sys/types.h>
25 #if EXT2_FLAT_INCLUDES
28 #include <linux/ext2_fs.h>
33 blk_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 };
36 ext2fs_block_bitmap bad_block_map, touched_map;
37 ext2fs_inode_bitmap bad_inode_map;
38 badblocks_list test_badblocks;
40 int first_no_comma = 1;
43 static void test_read_blk(unsigned long block, int count, errcode_t err)
53 printf("%lu-%lu", block, block+count-1);
57 for (i=0; i < count; i++, block++) {
58 if (ext2fs_test_block_bitmap(touched_map, block)) {
59 printf("\nDuplicate block?!? --- %lu\n", block);
63 ext2fs_mark_block_bitmap(touched_map, block);
68 * Setup the variables for doing the inode scan test.
70 static void setup(void)
74 struct ext2_super_block param;
76 initialize_ext2_error_table();
78 memset(¶m, 0, sizeof(param));
79 param.s_blocks_count = 12000;
82 test_io_cb_read_blk = test_read_blk;
84 retval = ext2fs_initialize("test fs", 0, ¶m,
85 test_io_manager, &test_fs);
87 com_err("setup", retval,
88 "While initializing filesystem");
91 retval = ext2fs_allocate_tables(test_fs);
93 com_err("setup", retval,
94 "While allocating tables for test filesystem");
97 retval = ext2fs_allocate_block_bitmap(test_fs, "bad block map",
100 com_err("setup", retval,
101 "While allocating bad_block bitmap");
104 retval = ext2fs_allocate_block_bitmap(test_fs, "touched map",
107 com_err("setup", retval,
108 "While allocating touched block bitmap");
111 retval = ext2fs_allocate_inode_bitmap(test_fs, "bad inode map",
114 com_err("setup", retval,
115 "While allocating bad inode bitmap");
119 retval = badblocks_list_create(&test_badblocks, 5);
121 com_err("setup", retval, "while creating badblocks list");
124 for (i=0; test_vec[i]; i++) {
125 retval = badblocks_list_add(test_badblocks, test_vec[i]);
127 com_err("setup", retval,
128 "while adding test vector %d", i);
131 ext2fs_mark_block_bitmap(bad_block_map, test_vec[i]);
133 test_fs->badblocks = test_badblocks;
137 * Iterate using inode_scan
139 static void iterate(void)
141 struct ext2_inode inode;
142 ext2_inode_scan scan;
146 retval = ext2fs_open_inode_scan(test_fs, 8, &scan);
148 com_err("iterate", retval, "While opening inode scan");
151 printf("Reading blocks: ");
152 retval = ext2fs_get_next_inode(scan, &ino, &inode);
154 com_err("iterate", retval, "while reading first inode");
158 retval = ext2fs_get_next_inode(scan, &ino, &inode);
159 if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) {
160 ext2fs_mark_inode_bitmap(bad_inode_map, ino);
164 com_err("iterate", retval,
165 "while getting next inode");
170 ext2fs_close_inode_scan(scan);
174 * Verify the touched map
176 static void check_map(void)
181 for (i=0; test_vec[i]; i++) {
182 if (ext2fs_test_block_bitmap(touched_map, test_vec[i])) {
183 printf("Bad block was touched --- %d\n", test_vec[i]);
187 ext2fs_mark_block_bitmap(touched_map, test_vec[i]);
189 for (i = 0; i < test_fs->group_desc_count; i++) {
190 for (j=0, blk = test_fs->group_desc[i].bg_inode_table;
191 j < test_fs->inode_blocks_per_group;
193 if (!ext2fs_test_block_bitmap(touched_map, blk) &&
194 !ext2fs_test_block_bitmap(bad_block_map, blk)) {
195 printf("Missing block --- %lu\n", blk);
200 printf("Bad inodes: ");
201 for (i=1; i <= test_fs->super->s_inodes_count; i++) {
202 if (ext2fs_test_inode_bitmap(bad_inode_map, i)) {
214 int main(int argc, char **argv)
220 printf("Inode scan tested OK!\n");