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
21 #include <sys/types.h>
26 #include <linux/ext2_fs.h>
30 blk_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 };
33 ext2fs_block_bitmap bad_block_map, touched_map;
34 ext2fs_inode_bitmap bad_inode_map;
35 badblocks_list test_badblocks;
37 int first_no_comma = 1;
40 static void test_read_blk(unsigned long block, int count, errcode_t err)
50 printf("%lu-%lu", block, block+count-1);
54 for (i=0; i < count; i++, block++) {
55 if (ext2fs_test_block_bitmap(touched_map, block)) {
56 printf("\nDuplicate block?!? --- %lu\n", block);
60 ext2fs_mark_block_bitmap(touched_map, block);
65 * Setup the variables for doing the inode scan test.
67 static void setup(void)
71 struct ext2_super_block param;
73 initialize_ext2_error_table();
75 memset(¶m, 0, sizeof(param));
76 param.s_blocks_count = 12000;
79 test_io_cb_read_blk = test_read_blk;
81 retval = ext2fs_initialize("test fs", 0, ¶m,
82 test_io_manager, &test_fs);
84 com_err("setup", retval,
85 "While initializing filesystem");
88 retval = ext2fs_allocate_tables(test_fs);
90 com_err("setup", retval,
91 "While allocating tables for test filesystem");
94 retval = ext2fs_allocate_block_bitmap(test_fs, "bad block map",
97 com_err("setup", retval,
98 "While allocating bad_block bitmap");
101 retval = ext2fs_allocate_block_bitmap(test_fs, "touched map",
104 com_err("setup", retval,
105 "While allocating touched block bitmap");
108 retval = ext2fs_allocate_inode_bitmap(test_fs, "bad inode map",
111 com_err("setup", retval,
112 "While allocating bad inode bitmap");
116 retval = badblocks_list_create(&test_badblocks, 5);
118 com_err("setup", retval, "while creating badblocks list");
121 for (i=0; test_vec[i]; i++) {
122 retval = badblocks_list_add(test_badblocks, test_vec[i]);
124 com_err("setup", retval,
125 "while adding test vector %d", i);
128 ext2fs_mark_block_bitmap(bad_block_map, test_vec[i]);
130 test_fs->badblocks = test_badblocks;
134 * Iterate using inode_scan
136 static void iterate(void)
138 struct ext2_inode inode;
139 ext2_inode_scan scan;
143 retval = ext2fs_open_inode_scan(test_fs, 8, &scan);
145 com_err("iterate", retval, "While opening inode scan");
148 printf("Reading blocks: ");
149 retval = ext2fs_get_next_inode(scan, &ino, &inode);
151 com_err("iterate", retval, "while reading first inode");
155 retval = ext2fs_get_next_inode(scan, &ino, &inode);
156 if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) {
157 ext2fs_mark_inode_bitmap(bad_inode_map, ino);
161 com_err("iterate", retval,
162 "while getting next inode");
167 ext2fs_close_inode_scan(scan);
171 * Verify the touched map
173 static void check_map(void)
178 for (i=0; test_vec[i]; i++) {
179 if (ext2fs_test_block_bitmap(touched_map, test_vec[i])) {
180 printf("Bad block was touched --- %d\n", test_vec[i]);
184 ext2fs_mark_block_bitmap(touched_map, test_vec[i]);
186 for (i = 0; i < test_fs->group_desc_count; i++) {
187 for (j=0, blk = test_fs->group_desc[i].bg_inode_table;
188 j < test_fs->inode_blocks_per_group;
190 if (!ext2fs_test_block_bitmap(touched_map, blk) &&
191 !ext2fs_test_block_bitmap(bad_block_map, blk)) {
192 printf("Missing block --- %lu\n", blk);
197 printf("Bad inodes: ");
198 for (i=1; i <= test_fs->super->s_inodes_count; i++) {
199 if (ext2fs_test_inode_bitmap(bad_inode_map, i)) {
211 int main(int argc, char **argv)
217 printf("Inode scan tested OK!\n");