2 # Test zstd compression support on a prebuilt btrfs image
4 source "$TEST_TOP/common"
7 check_global_prereq md5sum
9 # Extract the test image
10 image=$(extract_image compress.raw.xz)
16 run_check_stdout "$TOP/btrfs" inspect-internal dump-tree "$image" \
18 || _fail "btrfs inspect-internal dump-tree didn't print $string"
21 # Check that there are blocks of each compression type
22 check_dump_tree "$image" "extent compression 1 (zlib)"
23 check_dump_tree "$image" "extent compression 2 (lzo)"
24 check_dump_tree "$image" "extent compression 3 (zstd)"
26 # Check that the filesystem has incompat COMPRESS_ZSTD
27 run_check_stdout "$TOP/btrfs" inspect-internal dump-super -f "$image" \
28 | grep -q COMPRESS_ZSTD \
29 || _fail "btrfs inspect-internal dump-super no incompat COMPRESS_ZSTD"
31 # Create a temporary directory and restore the filesystem
32 restore_tmp=$(mktemp --tmpdir -d btrfs-progs-022-zstd-compression.XXXXXXXXXX)
33 run_check "$TOP/btrfs" restore "$image" "$restore_tmp"
36 num_files=$(ls -1 "$restore_tmp" | wc -l)
37 [ "$num_files" == 3 ] || _fail "number of files does not match"
43 md5=$(run_check_stdout md5sum "$file" | cut -d ' ' -f 1)
44 [ "$md5" == "$expect_md5" ] \
45 || _fail "$file digest $md5 does not match $expect_md5"
48 # Each should be 200K of zeros
49 expect_md5=$(dd if=/dev/zero bs=1K count=200 status=none | md5sum | cut -d ' ' -f 1)
50 check_md5 "$restore_tmp/zlib" "$expect_md5"
51 check_md5 "$restore_tmp/lzo" "$expect_md5"
52 check_md5 "$restore_tmp/zstd" "$expect_md5"
55 rm -r -- "$restore_tmp"