3 source $TOP/tests/common
5 # Check file list for leaf corruption, no regular/preallocated
7 # Corrupted leaf is 20832256, which contains inode 1862~1872
9 # 1862, ref from leaf 20828160 key 24(DIR_ITEM)
10 # 1863, ref from leaf 605388 item key 11(DIR_ITEM)
11 # 1864, no ref to rebuild, no need to rebuild
12 # 1865, ref from leaf 19767296 key 23(DIR_ITEM)
13 # 1866-1868 no ref to rebuild, all refs in corrupted leaf
14 # 1869, ref from leaf 4976640 key 22(DIR_ITEM)
15 # 1870 no ref to rebuild, all refs in corrupted leaf
16 # 1871, ref from leaf 19746816 key 38(DIR_ITEM)
17 # 1872, ref from leaf 19767296 key 14(DIR_ITEM)
21 # SIZE: file size, only checked for regular file
22 # MODE: raw file mode, get from stat
24 leaf_no_data_ext_list=(
25 1862 0 40700 "install.d"
26 1862 0 40700 "install.d"
28 1865 0 40700 "iptables"
30 1871 0 100700 "machine-id"
31 1872 0 100700 "adjtime"
34 generate_leaf_corrupt_no_data_ext()
37 echo "generating leaf_corrupt_no_data_ext.btrfs-image" >> $RESULTS
38 tar xJf ./no_data_extent.tar.xz || \
39 _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image"
40 btrfs-image -r test.img.btrfs-image $dest || \
41 _fail "failed to extract leaf_corrupt_no_data_ext.btrfs-image"
43 # leaf at 20832256 contains no regular data extent, clear its csum to
45 dd if=/dev/zero of=$dest bs=1 count=32 conv=notrunc seek=20832256 \
57 # Check whether the inode exists
58 exists=$($SUDO_HELPER find $path -inum $ino)
59 if [ -z "$exists" ]; then
60 _fail "inode $ino not recovered correctly"
64 found_mode=$(printf "%o" 0x$($SUDO_HELPER stat $exists -c %f))
65 if [ $found_mode -ne $mode ]; then
67 _fail "inode $ino modes not recovered"
71 found_size=$($SUDO_HELPER stat $exists -c %s)
72 if [ $mode -ne 41700 -a $found_size -ne $size ]; then
73 _fail "inode $ino size not recovered correctly"
77 if [ "$(basename $exists)" != "$name" ]; then
78 _fail "inode $ino name not recovered correctly"
84 # Check salvaged data in the recovered image
85 check_leaf_corrupt_no_data_ext()
88 mkdir -p $TEST_MNT || _fail "failed to create mount point"
89 $SUDO_HELPER mount $image -o ro $TEST_MNT
92 while [ $i -lt ${#leaf_no_data_ext_list[@]} ]; do
93 check_inode $TEST_MNT/lost+found \
94 ${leaf_no_data_ext_list[i]} \
95 ${leaf_no_data_ext_list[i + 1]} \
96 ${leaf_no_data_ext_list[i + 2]} \
97 ${leaf_no_data_ext_list[i + 3]} \
98 ${leaf_no_data_ext_list[i + 4]}
101 $SUDO_HELPER umount $TEST_MNT
106 generate_leaf_corrupt_no_data_ext test.img
108 check_leaf_corrupt_no_data_ext test.img
111 rm test.img.btrfs-image
112 # Not used, its function is the same as generate_leaf_corrupt_no_data_ext()