xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / generic / 624
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright 2021 Google LLC
4 #
5 # FS QA Test No. 624
6 #
7 # Test retrieving the Merkle tree and fs-verity descriptor of a verity file
8 # using FS_IOC_READ_VERITY_METADATA.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 . ./common/rc
26 . ./common/filter
27 . ./common/verity
28
29 rm -f $seqres.full
30
31 _supported_fs generic
32 _require_scratch_verity
33 _disable_fsverity_signatures
34 # For the output of this test to always be the same, it has to use a specific
35 # Merkle tree block size.
36 if [ $FSV_BLOCK_SIZE != 4096 ]; then
37         _notrun "4096-byte verity block size not supported on this platform"
38 fi
39
40 _scratch_mkfs_verity &>> $seqres.full
41 _scratch_mount
42
43 echo -e "\n# Creating a verity file"
44 fsv_file=$SCRATCH_MNT/file
45 # Always use the same file contents, so that the output of the test is always
46 # the same.  Also use a file that is large enough to have multiple Merkle tree
47 # levels, so that the test verifies that the blocks are returned in the expected
48 # order.  A 1 MB file with SHA-256 and a Merkle tree block size of 4096 will
49 # have 3 Merkle tree blocks (3*4096 bytes): two at level 0 and one at level 1.
50 head -c 1000000 /dev/zero > $fsv_file
51 merkle_tree_size=$((3 * FSV_BLOCK_SIZE))
52 fsverity_descriptor_size=256
53 _fsv_enable $fsv_file --salt=abcd
54 _require_fsverity_dump_metadata $fsv_file
55 _fsv_measure $fsv_file
56
57 echo -e "\n# Dumping Merkle tree"
58 _fsv_dump_merkle_tree $fsv_file | sha256sum
59
60 echo -e "\n# Dumping Merkle tree (in chunks)"
61 # The above test may get the whole tree in one read, so also try reading it in
62 # chunks.
63 for (( i = 0; i < merkle_tree_size; i += 997 )); do
64         _fsv_dump_merkle_tree $fsv_file --offset=$i --length=997
65 done | sha256sum
66
67 echo -e "\n# Dumping descriptor"
68 # Note that the hash that is printed here should be the same hash that was
69 # printed by _fsv_measure above.
70 _fsv_dump_descriptor $fsv_file | sha256sum
71
72 echo -e "\n# Dumping descriptor (in chunks)"
73 for (( i = 0; i < fsverity_descriptor_size; i += 13 )); do
74         _fsv_dump_descriptor $fsv_file --offset=$i --length=13
75 done | sha256sum
76
77 # success, all done
78 status=0
79 exit