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>
28 blk_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 };
31 ext2fs_block_bitmap bad_block_map, touched_map;
32 ext2fs_inode_bitmap bad_inode_map;
33 badblocks_list test_badblocks;
35 int first_no_comma = 1;
38 static void test_read_blk(unsigned long block, int count, errcode_t err)
48 printf("%lu-%lu", block, block+count-1);
52 for (i=0; i < count; i++, block++) {
53 if (ext2fs_test_block_bitmap(touched_map, block)) {
54 printf("\nDuplicate block?!? --- %lu\n", block);
58 ext2fs_mark_block_bitmap(touched_map, block);
63 * Setup the variables for doing the inode scan test.
65 static void setup(void)
69 struct ext2_super_block param;
71 initialize_ext2_error_table();
73 memset(¶m, 0, sizeof(param));
74 param.s_blocks_count = 12000;
77 test_io_cb_read_blk = test_read_blk;
79 retval = ext2fs_initialize("test fs", 0, ¶m,
80 test_io_manager, &test_fs);
82 com_err("setup", retval,
83 "While initializing filesystem");
86 retval = ext2fs_allocate_tables(test_fs);
88 com_err("setup", retval,
89 "While allocating tables for test filesystem");
92 retval = ext2fs_allocate_block_bitmap(test_fs, "bad block map",
95 com_err("setup", retval,
96 "While allocating bad_block bitmap");
99 retval = ext2fs_allocate_block_bitmap(test_fs, "touched map",
102 com_err("setup", retval,
103 "While allocating touched block bitmap");
106 retval = ext2fs_allocate_inode_bitmap(test_fs, "bad inode map",
109 com_err("setup", retval,
110 "While allocating bad inode bitmap");
114 retval = ext2fs_badblocks_list_create(&test_badblocks, 5);
116 com_err("setup", retval, "while creating badblocks list");
119 for (i=0; test_vec[i]; i++) {
120 retval = ext2fs_badblocks_list_add(test_badblocks, test_vec[i]);
122 com_err("setup", retval,
123 "while adding test vector %d", i);
126 ext2fs_mark_block_bitmap(bad_block_map, test_vec[i]);
128 test_fs->badblocks = test_badblocks;
132 * Iterate using inode_scan
134 static void iterate(void)
136 struct ext2_inode inode;
137 ext2_inode_scan scan;
141 retval = ext2fs_open_inode_scan(test_fs, 8, &scan);
143 com_err("iterate", retval, "While opening inode scan");
146 printf("Reading blocks: ");
147 retval = ext2fs_get_next_inode(scan, &ino, &inode);
149 com_err("iterate", retval, "while reading first inode");
153 retval = ext2fs_get_next_inode(scan, &ino, &inode);
154 if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) {
155 ext2fs_mark_inode_bitmap(bad_inode_map, ino);
159 com_err("iterate", retval,
160 "while getting next inode");
165 ext2fs_close_inode_scan(scan);
169 * Verify the touched map
171 static void check_map(void)
176 for (i=0; test_vec[i]; i++) {
177 if (ext2fs_test_block_bitmap(touched_map, test_vec[i])) {
178 printf("Bad block was touched --- %u\n", test_vec[i]);
182 ext2fs_mark_block_bitmap(touched_map, test_vec[i]);
184 for (i = 0; i < test_fs->group_desc_count; i++) {
185 for (j=0, blk = test_fs->group_desc[i].bg_inode_table;
186 j < test_fs->inode_blocks_per_group;
188 if (!ext2fs_test_block_bitmap(touched_map, blk) &&
189 !ext2fs_test_block_bitmap(bad_block_map, blk)) {
190 printf("Missing block --- %lu\n", blk);
195 printf("Bad inodes: ");
196 for (i=1; i <= test_fs->super->s_inodes_count; i++) {
197 if (ext2fs_test_inode_bitmap(bad_inode_map, i)) {
209 int main(int argc, char **argv)
215 printf("Inode scan tested OK!\n");