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
32 _require_xfs_io_command "falloc"
34 testfile="$TEST_DIR/falloctest-$seq"
36 # Fallocate 2 bytes across a block boundary
37 block_size=$(_get_file_block_size "$TEST_DIR")
38 $XFS_IO_PROG -f -c "falloc $((block_size - 1)) 2" "$testfile"
40 # Both the first blocks should be allocated now. Check that by
41 # inquiring whether the file grows when we write to the two bytes we
42 # have just fallocated.
44 allocated_size_before=$(($(stat -c '%b * %B' "$testfile")))
46 $XFS_IO_PROG -c "pwrite $((block_size - 1)) 2" "$testfile" \
47 | _filter_xfs_io | sed -e "s/$((block_size - 1))/block_size - 1/"
49 allocated_size_after=$(($(stat -c '%b * %B' "$testfile")))
51 if [ $allocated_size_after -gt $allocated_size_before ]; then
52 echo "ERROR: File grew from ${allocated_size_before} B to" \
53 "${allocated_size_after} B when writing to the fallocated range."
55 echo "OK: File did not grow."