3 # Corrupt primary superblock and restore it using backup superblock.
5 source "$TEST_TOP/common"
7 check_prereq btrfs-select-super
13 FIRST_SUPERBLOCK_OFFSET=65536
15 test_superblock_restore()
17 run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$TEST_DEV"
19 # Corrupt superblock checksum
20 run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_DEV" \
21 seek="$FIRST_SUPERBLOCK_OFFSET" bs=1 count=4 conv=notrunc
23 # Run btrfs check to detect corruption
24 run_mayfail "$TOP/btrfs" check "$TEST_DEV" && \
25 _fail "btrfs check should detect corruption"
27 # Copy backup superblock to primary
28 run_check "$TOP/btrfs-select-super" -s 1 "$TEST_DEV"
31 run_check "$TOP/btrfs" check "$TEST_DEV"
34 test_superblock_restore