3 source "$TEST_TOP/common"
5 check_prereq btrfs-image
7 # Check file list for leaf corruption, no regular/preallocated
9 # Corrupted leaf is 20832256, which contains inode 1862~1872
11 # 1862, ref from leaf 20828160 key 24(DIR_ITEM)
12 # 1863, ref from leaf 605388 item key 11(DIR_ITEM)
13 # 1864, no ref to rebuild, no need to rebuild
14 # 1865, ref from leaf 19767296 key 23(DIR_ITEM)
15 # 1866-1868 no ref to rebuild, all refs in corrupted leaf
16 # 1869, ref from leaf 4976640 key 22(DIR_ITEM)
17 # 1870 no ref to rebuild, all refs in corrupted leaf
18 # 1871, ref from leaf 19746816 key 38(DIR_ITEM)
19 # 1872, ref from leaf 19767296 key 14(DIR_ITEM)
23 # SIZE: file size, only checked for regular file
24 # MODE: raw file mode, get from stat
26 leaf_no_data_ext_list=(
27 1862 0 40700 "install.d"
28 1862 0 40700 "install.d"
30 1865 0 40700 "iptables"
32 1871 0 100700 "machine-id"
33 1872 0 100700 "adjtime"
37 generate_leaf_corrupt_no_data_ext()
40 echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> "$RESULTS"
41 tar --no-same-owner -xJf ./no_data_extent.tar.xz || \
42 _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image"
43 "$TOP/btrfs-image" -r test.img.btrfs-image "$dest" || \
44 _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image"
46 # leaf at 4206592 and 20905984 contains no regular data
47 # extent, clear its csum to corrupt the leaf.
48 for x in 4206592 20905984; do
49 dd if=/dev/zero of="$dest" bs=1 count=32 conv=notrunc seek="$x" \
62 # Check whether the inode exists
63 exists=$($SUDO_HELPER find "$path" -inum "$ino")
64 if [ -z "$exists" ]; then
65 _fail "inode $ino not recovered correctly"
69 found_mode=$(printf "%o" 0x$($SUDO_HELPER stat "$exists" -c %f))
70 if [ "$found_mode" -ne "$mode" ]; then
72 _fail "inode $ino modes not recovered"
76 found_size=$($SUDO_HELPER stat "$exists" -c %s)
77 if [ $mode -ne 41700 -a "$found_size" -ne "$size" ]; then
78 _fail "inode $ino size not recovered correctly"
82 if [ "$(basename $exists)" != "$name" ]; then
83 _fail "inode $ino name not recovered correctly"
89 # Check salvaged data in the recovered image
90 check_leaf_corrupt_no_data_ext()
93 $SUDO_HELPER mount -o loop -t btrfs "$image" -o ro "$TEST_MNT"
96 while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do
97 check_inode "$TEST_MNT/lost+found" \
98 ${leaf_no_data_ext_list[i]} \
99 ${leaf_no_data_ext_list[i + 1]} \
100 ${leaf_no_data_ext_list[i + 2]} \
101 ${leaf_no_data_ext_list[i + 3]} \
102 ${leaf_no_data_ext_list[i + 4]}
105 $SUDO_HELPER umount "$TEST_MNT"
110 generate_leaf_corrupt_no_data_ext test.img
112 check_leaf_corrupt_no_data_ext test.img
115 rm test.img.btrfs-image
116 # Not used, its function is the same as generate_leaf_corrupt_no_data_ext()