2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc. All Rights Reserved.
5 # FS QA Test No. generic/568
7 # Test that fallocating an unaligned range allocates all blocks
8 # touched by that range
11 seqres="$RESULT_DIR/$seq"
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
23 rm -f "$TEST_DIR/falloctest-$seq"
26 # get standard environment, filters and checks
30 # real QA test starts here
33 _require_xfs_io_command "falloc"
35 testfile="$TEST_DIR/falloctest-$seq"
37 # Fallocate 2 bytes across a block boundary
38 block_size=$(_get_file_block_size "$TEST_DIR")
39 $XFS_IO_PROG -f -c "falloc $((block_size - 1)) 2" "$testfile"
41 # Both the first blocks should be allocated now. Check that by
42 # inquiring whether the file grows when we write to the two bytes we
43 # have just fallocated.
45 allocated_size_before=$(($(stat -c '%b * %B' "$testfile")))
47 $XFS_IO_PROG -c "pwrite $((block_size - 1)) 2" "$testfile" \
48 | _filter_xfs_io | sed -e "s/$((block_size - 1))/block_size - 1/"
50 allocated_size_after=$(($(stat -c '%b * %B' "$testfile")))
52 if [ $allocated_size_after -gt $allocated_size_before ]; then
53 echo "ERROR: File grew from ${allocated_size_before} B to" \
54 "${allocated_size_after} B when writing to the fallocated range."
56 echo "OK: File did not grow."