From: Darrick J. Wong Date: Sun, 3 Aug 2014 03:49:41 +0000 (-0400) Subject: tests: add regression tests for MMP blocks with bad checksums X-Git-Tag: v1.43-WIP-2015-05-18~251 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8a1ee12550f4ecd0bb7e75a60e25a57bcc5a0e9;p=thirdparty%2Fe2fsprogs.git tests: add regression tests for MMP blocks with bad checksums Add regression tests to examine how e2fsck deals with MMP blocks with (a) a bad magic number; and (b) an incorrect checksum. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- diff --git a/e2fsck/unix.c b/e2fsck/unix.c index d883c9e1a..f71afbc97 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1166,7 +1166,9 @@ check_error: ext2fs_mmp_clear(fs); retval = 0; } - } + } else + com_err(ctx->program_name, retval, "%s", + _("while reading MMP block")); return retval; } diff --git a/tests/m_mmp_bad_csum/expect b/tests/m_mmp_bad_csum/expect new file mode 100644 index 000000000..e15e7b440 --- /dev/null +++ b/tests/m_mmp_bad_csum/expect @@ -0,0 +1,9 @@ +Superblock MMP block checksum does not match MMP block. Fix? yes + +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +test_filesys: 11/128 files (0.0% non-contiguous), 19/512 blocks +Exit status is 0 diff --git a/tests/m_mmp_bad_csum/image.gz b/tests/m_mmp_bad_csum/image.gz new file mode 100644 index 000000000..c896ff60d Binary files /dev/null and b/tests/m_mmp_bad_csum/image.gz differ diff --git a/tests/m_mmp_bad_csum/name b/tests/m_mmp_bad_csum/name new file mode 100644 index 000000000..61c31d4a3 --- /dev/null +++ b/tests/m_mmp_bad_csum/name @@ -0,0 +1 @@ +mmp with bad csum (metadata_csum) diff --git a/tests/m_mmp_bad_csum/script b/tests/m_mmp_bad_csum/script new file mode 100644 index 000000000..d10129402 --- /dev/null +++ b/tests/m_mmp_bad_csum/script @@ -0,0 +1,30 @@ +# use current directory instead of /tmp becase tmpfs doesn't support DIO +rm -f $TMPFILE +TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) + +stat -f $TMPFILE | grep -q "Type: tmpfs" +if [ $? = 0 ]; then + rm -f $TMPFILE + echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" + return 0 +fi +gzip -dc < $test_dir/image.gz > $TMPFILE + +OUT=$test_dir.log +EXP=$test_dir/expect +$FSCK -fy $TMPFILE 2>&1 | sed -f $cmd_dir/filter.sed > $OUT +echo Exit status is $? >> $OUT + +rm -f $TMPFILE +cmp -s $OUT $EXP +status=$? + +if [ "$status" = 0 ] ; then + echo "$test_name: $test_description: ok" + touch $test_name.ok +else + echo "$test_name: $test_description: failed" + diff $DIFF_OPTS $EXP $OUT > $test_name.failed + rm -f $test_name.tmp +fi +unset OUT EXP diff --git a/tests/m_mmp_bad_magic/.log b/tests/m_mmp_bad_magic/.log new file mode 100644 index 000000000..b5dfb8970 --- /dev/null +++ b/tests/m_mmp_bad_magic/.log @@ -0,0 +1,9 @@ +Superblock has invalid MMP magic. Fix? yes + +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +test_filesys: 11/128 files (0.0% non-contiguous), 19/512 blocks +Exit status is 0 diff --git a/tests/m_mmp_bad_magic/expect b/tests/m_mmp_bad_magic/expect new file mode 100644 index 000000000..b5dfb8970 --- /dev/null +++ b/tests/m_mmp_bad_magic/expect @@ -0,0 +1,9 @@ +Superblock has invalid MMP magic. Fix? yes + +Pass 1: Checking inodes, blocks, and sizes +Pass 2: Checking directory structure +Pass 3: Checking directory connectivity +Pass 4: Checking reference counts +Pass 5: Checking group summary information +test_filesys: 11/128 files (0.0% non-contiguous), 19/512 blocks +Exit status is 0 diff --git a/tests/m_mmp_bad_magic/image.gz b/tests/m_mmp_bad_magic/image.gz new file mode 100644 index 000000000..2d57fbf5f Binary files /dev/null and b/tests/m_mmp_bad_magic/image.gz differ diff --git a/tests/m_mmp_bad_magic/name b/tests/m_mmp_bad_magic/name new file mode 100644 index 000000000..15a2d4d25 --- /dev/null +++ b/tests/m_mmp_bad_magic/name @@ -0,0 +1 @@ +mmp with bad magic (metadata_csum) diff --git a/tests/m_mmp_bad_magic/script b/tests/m_mmp_bad_magic/script new file mode 100644 index 000000000..d10129402 --- /dev/null +++ b/tests/m_mmp_bad_magic/script @@ -0,0 +1,30 @@ +# use current directory instead of /tmp becase tmpfs doesn't support DIO +rm -f $TMPFILE +TMPFILE=$(mktemp ./tmp-$test_name.XXXXXX) + +stat -f $TMPFILE | grep -q "Type: tmpfs" +if [ $? = 0 ]; then + rm -f $TMPFILE + echo "$test_name: $test_description: skipped for tmpfs (no O_DIRECT)" + return 0 +fi +gzip -dc < $test_dir/image.gz > $TMPFILE + +OUT=$test_dir.log +EXP=$test_dir/expect +$FSCK -fy $TMPFILE 2>&1 | sed -f $cmd_dir/filter.sed > $OUT +echo Exit status is $? >> $OUT + +rm -f $TMPFILE +cmp -s $OUT $EXP +status=$? + +if [ "$status" = 0 ] ; then + echo "$test_name: $test_description: ok" + touch $test_name.ok +else + echo "$test_name: $test_description: failed" + diff $DIFF_OPTS $EXP $OUT > $test_name.failed + rm -f $test_name.tmp +fi +unset OUT EXP