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 Library
8 * General Public License, version 2.
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 iscan_test_read_blk64(unsigned long long block, int count, errcode_t err)
48 printf("%llu-%llu", block, block+count-1);
50 printf("%llu", block);
52 for (i=0; i < count; i++, block++) {
53 if (ext2fs_test_block_bitmap2(touched_map, block)) {
54 printf("\nDuplicate block?!? --- %llu\n", block);
58 ext2fs_mark_block_bitmap2(touched_map, block);
62 static void iscan_test_read_blk(unsigned long block, int count, errcode_t err)
64 iscan_test_read_blk64(block, count, err);
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 ext2fs_blocks_count_set(¶m, 12000);
82 test_io_cb_read_blk = iscan_test_read_blk;
83 test_io_cb_read_blk64 = iscan_test_read_blk64;
85 retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, ¶m,
86 test_io_manager, &test_fs);
88 com_err("setup", retval,
89 "While initializing filesystem");
92 retval = ext2fs_allocate_tables(test_fs);
94 com_err("setup", retval,
95 "While allocating tables for test filesystem");
98 retval = ext2fs_allocate_block_bitmap(test_fs, "bad block map",
101 com_err("setup", retval,
102 "While allocating bad_block bitmap");
105 retval = ext2fs_allocate_block_bitmap(test_fs, "touched map",
108 com_err("setup", retval,
109 "While allocating touched block bitmap");
112 retval = ext2fs_allocate_inode_bitmap(test_fs, "bad inode map",
115 com_err("setup", retval,
116 "While allocating bad inode bitmap");
120 retval = ext2fs_badblocks_list_create(&test_badblocks, 5);
122 com_err("setup", retval, "while creating badblocks list");
125 for (i=0; test_vec[i]; i++) {
126 retval = ext2fs_badblocks_list_add(test_badblocks, test_vec[i]);
128 com_err("setup", retval,
129 "while adding test vector %d", i);
132 ext2fs_mark_block_bitmap2(bad_block_map, test_vec[i]);
134 test_fs->badblocks = test_badblocks;
138 * Iterate using inode_scan
140 static void iterate(void)
142 struct ext2_inode inode;
143 ext2_inode_scan scan;
147 retval = ext2fs_open_inode_scan(test_fs, 8, &scan);
149 com_err("iterate", retval, "While opening inode scan");
152 printf("Reading blocks: ");
153 retval = ext2fs_get_next_inode(scan, &ino, &inode);
155 com_err("iterate", retval, "while reading first inode");
159 retval = ext2fs_get_next_inode(scan, &ino, &inode);
160 if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) {
161 ext2fs_mark_inode_bitmap2(bad_inode_map, ino);
165 com_err("iterate", retval,
166 "while getting next inode");
171 ext2fs_close_inode_scan(scan);
175 * Verify the touched map
177 static void check_map(void)
182 for (i=0; test_vec[i]; i++) {
183 if (ext2fs_test_block_bitmap2(touched_map, test_vec[i])) {
184 printf("Bad block was touched --- %u\n", test_vec[i]);
188 ext2fs_mark_block_bitmap2(touched_map, test_vec[i]);
190 for (i = 0; i < test_fs->group_desc_count; i++) {
191 for (j=0, blk = ext2fs_inode_table_loc(test_fs, i);
192 j < test_fs->inode_blocks_per_group;
194 if (!ext2fs_test_block_bitmap2(touched_map, blk) &&
195 !ext2fs_test_block_bitmap2(bad_block_map, blk)) {
196 printf("Missing block --- %llu\n", blk);
201 printf("Bad inodes: ");
202 for (i=1; i <= test_fs->super->s_inodes_count; i++) {
203 if (ext2fs_test_inode_bitmap2(bad_inode_map, i)) {
215 int main(int argc, char **argv)
221 printf("Inode scan tested OK!\n");