summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2005-12-10 14:37:10 -0500
committerTheodore Ts'o <tytso@mit.edu>2005-12-10 14:37:10 -0500
commitbc47952f10ff5ed2c61536f2713d54b6807795cd (patch)
tree05ef9cf7f4fd442c814dd5b82c4099b53fbde4b3 /lib
parent4c02c41c0d5619313b0920e4be12e41f8ef73a9c (diff)
downloade2fsprogs-bc47952f10ff5ed2c61536f2713d54b6807795cd.tar.gz
Add ext2fs_read_bb_FILE test to confirm proper detection of invalid block #'s
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib')
-rw-r--r--lib/ext2fs/ChangeLog6
-rw-r--r--lib/ext2fs/tst_badblocks.c64
2 files changed, 70 insertions, 0 deletions
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index babd1349..a4295fb5 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -1,3 +1,9 @@
+2005-12-10 Theodore Ts'o <tytso@mit.edu>
+
+ * tst_badblocks.c (file_test_invalid): Add test which confirms
+ proper detection of invalid block numbers in
+ ext2fs_read_bb_FILE().
+
2005-11-20 Theodore Ts'o <tytso@mit.edu>
* bitops.h: We no longer have the sparc assembly code in the
diff --git a/lib/ext2fs/tst_badblocks.c b/lib/ext2fs/tst_badblocks.c
index a42e4cd8..687db0cf 100644
--- a/lib/ext2fs/tst_badblocks.c
+++ b/lib/ext2fs/tst_badblocks.c
@@ -63,6 +63,7 @@ blk_t test5a[] = {
static int test_fail = 0;
+static int test_expected_fail = 0;
static errcode_t create_test_list(blk_t *vec, badblocks_list *ret)
{
@@ -202,6 +203,67 @@ int file_test(badblocks_list bb)
return 0;
}
+static void invalid_proc(ext2_filsys fs, blk_t blk)
+{
+ if (blk == 34500) {
+ printf("Expected invalid block\n");
+ test_expected_fail++;
+ } else {
+ printf("Invalid block #: %d\n", blk);
+ test_fail++;
+ }
+}
+
+int file_test_invalid(badblocks_list bb)
+{
+ badblocks_list new_bb = 0;
+ errcode_t retval;
+ ext2_filsys fs;
+ FILE *f;
+
+ fs = malloc(sizeof(struct struct_ext2_filsys));
+ memset(fs, 0, sizeof(struct struct_ext2_filsys));
+ fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
+ fs->super = malloc(SUPERBLOCK_SIZE);
+ memset(fs->super, 0, SUPERBLOCK_SIZE);
+ fs->super->s_first_data_block = 1;
+ fs->super->s_blocks_count = 100;
+
+ f = tmpfile();
+ if (!f) {
+ fprintf(stderr, "Error opening temp file: %s\n",
+ error_message(errno));
+ return 1;
+ }
+ retval = ext2fs_write_bb_FILE(bb, 0, f);
+ if (retval) {
+ com_err("file_test", retval, "while writing bad blocks");
+ return 1;
+ }
+ fprintf(f, "34500\n");
+
+ rewind(f);
+ test_expected_fail = 0;
+ retval = ext2fs_read_bb_FILE(fs, f, &new_bb, invalid_proc);
+ if (retval) {
+ com_err("file_test", retval, "while reading bad blocks");
+ return 1;
+ }
+ fclose(f);
+ if (!test_expected_fail) {
+ printf("Expected test failure didn't happen!\n");
+ test_fail++;
+ }
+
+
+ if (ext2fs_badblocks_equal(bb, new_bb)) {
+ printf("Block bitmap matched after reading and writing.\n");
+ } else {
+ printf("Block bitmap NOT matched.\n");
+ test_fail++;
+ }
+ return 0;
+}
int main(int argc, char **argv)
{
@@ -275,6 +337,8 @@ int main(int argc, char **argv)
}
file_test(bb4);
+
+ file_test_invalid(bb4);
if (test_fail == 0)
printf("ext2fs library badblocks tests checks out OK!\n");