2017-04-15 10:13:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Corrupt primary superblock and restore it using backup superblock.
|
|
|
|
|
2023-04-19 15:08:41 +00:00
|
|
|
source "$TEST_TOP/common" || exit
|
2017-04-15 10:13:08 +00:00
|
|
|
|
|
|
|
check_prereq btrfs-select-super
|
|
|
|
check_prereq btrfs
|
|
|
|
|
|
|
|
setup_root_helper
|
|
|
|
prepare_test_dev
|
|
|
|
|
|
|
|
FIRST_SUPERBLOCK_OFFSET=65536
|
|
|
|
|
|
|
|
test_superblock_restore()
|
|
|
|
{
|
2024-06-12 23:39:06 +00:00
|
|
|
local seek
|
|
|
|
|
2019-06-05 17:09:38 +00:00
|
|
|
run_check_mkfs_test_dev
|
2017-04-15 10:13:08 +00:00
|
|
|
|
|
|
|
# Corrupt superblock checksum
|
|
|
|
run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_DEV" \
|
|
|
|
seek="$FIRST_SUPERBLOCK_OFFSET" bs=1 count=4 conv=notrunc
|
|
|
|
|
|
|
|
# Run btrfs check to detect corruption
|
|
|
|
run_mayfail "$TOP/btrfs" check "$TEST_DEV" && \
|
|
|
|
_fail "btrfs check should detect corruption"
|
|
|
|
|
|
|
|
# Copy backup superblock to primary
|
2020-03-01 03:33:44 +00:00
|
|
|
run_check "$INTERNAL_BIN/btrfs-select-super" -s 1 "$TEST_DEV"
|
2017-04-15 10:13:08 +00:00
|
|
|
|
|
|
|
# Perform btrfs check
|
|
|
|
run_check "$TOP/btrfs" check "$TEST_DEV"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_superblock_restore
|