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.
21 #include <sys/types.h>
29 blk64_t test_vec
[] = { 8, 12, 24, 34, 43, 44, 100, 0 };
32 ext2fs_block_bitmap bad_block_map
, touched_map
;
33 ext2fs_inode_bitmap bad_inode_map
;
34 badblocks_list test_badblocks
;
36 int first_no_comma
= 1;
39 static void iscan_test_read_blk64(unsigned long long block
, int count
, errcode_t err
)
49 printf("%llu-%llu", block
, block
+count
-1);
51 printf("%llu", block
);
53 for (i
=0; i
< count
; i
++, block
++) {
54 if (ext2fs_test_block_bitmap2(touched_map
, block
)) {
55 printf("\nDuplicate block?!? --- %llu\n", block
);
59 ext2fs_mark_block_bitmap2(touched_map
, block
);
63 static void iscan_test_read_blk(unsigned long block
, int count
, errcode_t err
)
65 iscan_test_read_blk64(block
, count
, err
);
69 * Setup the variables for doing the inode scan test.
71 static void setup(void)
75 struct ext2_super_block param
;
77 initialize_ext2_error_table();
79 memset(¶m
, 0, sizeof(param
));
80 ext2fs_blocks_count_set(¶m
, 12000);
83 test_io_cb_read_blk
= iscan_test_read_blk
;
84 test_io_cb_read_blk64
= iscan_test_read_blk64
;
86 retval
= ext2fs_initialize("test fs", EXT2_FLAG_64BITS
, ¶m
,
87 test_io_manager
, &test_fs
);
89 com_err("setup", retval
,
90 "While initializing filesystem");
93 retval
= ext2fs_allocate_tables(test_fs
);
95 com_err("setup", retval
,
96 "While allocating tables for test filesystem");
99 retval
= ext2fs_allocate_block_bitmap(test_fs
, "bad block map",
102 com_err("setup", retval
,
103 "While allocating bad_block bitmap");
106 retval
= ext2fs_allocate_block_bitmap(test_fs
, "touched map",
109 com_err("setup", retval
,
110 "While allocating touched block bitmap");
113 retval
= ext2fs_allocate_inode_bitmap(test_fs
, "bad inode map",
116 com_err("setup", retval
,
117 "While allocating bad inode bitmap");
121 retval
= ext2fs_badblocks_list_create(&test_badblocks
, 5);
123 com_err("setup", retval
, "while creating badblocks list");
126 for (i
=0; test_vec
[i
]; i
++) {
127 retval
= ext2fs_badblocks_list_add(test_badblocks
, test_vec
[i
]);
129 com_err("setup", retval
,
130 "while adding test vector %d", i
);
133 ext2fs_mark_block_bitmap2(bad_block_map
, test_vec
[i
]);
135 test_fs
->badblocks
= test_badblocks
;
139 * Iterate using inode_scan
141 static void iterate(void)
143 struct ext2_inode inode
;
144 ext2_inode_scan scan
;
148 retval
= ext2fs_open_inode_scan(test_fs
, 8, &scan
);
150 com_err("iterate", retval
, "While opening inode scan");
153 printf("Reading blocks: ");
154 retval
= ext2fs_get_next_inode(scan
, &ino
, &inode
);
156 com_err("iterate", retval
, "while reading first inode");
160 retval
= ext2fs_get_next_inode(scan
, &ino
, &inode
);
161 if (retval
== EXT2_ET_BAD_BLOCK_IN_INODE_TABLE
) {
162 ext2fs_mark_inode_bitmap2(bad_inode_map
, ino
);
166 com_err("iterate", retval
,
167 "while getting next inode");
172 ext2fs_close_inode_scan(scan
);
176 * Verify the touched map
178 static void check_map(void)
183 for (i
=0; test_vec
[i
]; i
++) {
184 if (ext2fs_test_block_bitmap2(touched_map
, test_vec
[i
])) {
185 printf("Bad block was touched --- %llu\n",
186 (unsigned long long) test_vec
[i
]);
190 ext2fs_mark_block_bitmap2(touched_map
, test_vec
[i
]);
192 for (i
= 0; i
< test_fs
->group_desc_count
; i
++) {
193 for (j
=0, blk
= ext2fs_inode_table_loc(test_fs
, i
);
194 j
< test_fs
->inode_blocks_per_group
;
196 if (!ext2fs_test_block_bitmap2(touched_map
, blk
) &&
197 !ext2fs_test_block_bitmap2(bad_block_map
, blk
)) {
198 printf("Missing block --- %llu\n",
199 (unsigned long long) blk
);
204 printf("Bad inodes: ");
205 for (i
=1; i
<= test_fs
->super
->s_inodes_count
; i
++) {
206 if (ext2fs_test_inode_bitmap2(bad_inode_map
, i
)) {
218 int main(int argc
, char **argv
)
224 printf("Inode scan tested OK!\n");