fstests: use _require_symlinks on all necessary tests
[xfstests-dev.git] / tests / generic / 568
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2019 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/568
6 #
7 # Test that fallocating an unaligned range allocates all blocks
8 # touched by that range
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         rm -f "$TEST_DIR/falloctest-$seq"
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31 _supported_fs generic
32 _supported_os Linux
33 _require_xfs_io_command "falloc"
34
35 testfile="$TEST_DIR/falloctest-$seq"
36
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"
40
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.
44
45 allocated_size_before=$(($(stat -c '%b * %B' "$testfile")))
46
47 $XFS_IO_PROG -c "pwrite $((block_size - 1)) 2" "$testfile" \
48         | _filter_xfs_io | sed -e "s/$((block_size - 1))/block_size - 1/"
49
50 allocated_size_after=$(($(stat -c '%b * %B' "$testfile")))
51
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."
55 else
56         echo "OK: File did not grow."
57 fi
58
59 status=0
60 exit