generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 315
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 315
6 #
7 # fallocate/truncate tests with FALLOC_FL_KEEP_SIZE option.
8 # Verify if the disk space is released after truncating a file back
9 # to the old smaller size.  Before Linux 3.10, Btrfs/OCFS2 are test
10 # failed in this case.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=0        # success is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # real QA test starts here
32
33 # Modify as appropriate.
34 _supported_fs generic
35 _supported_os Linux
36 _require_test
37 _require_xfs_io_command "falloc" "-k"
38
39 rm -f $seqres.full
40
41 echo "Slience is golden"
42
43 # Check the current avaliable disk space on $TEST_DIR.
44 # 1024KiB at least
45 avail_begin=`df -P $TEST_DIR | awk 'END {print $4}'`
46 [ "$avail_begin" -ge 1024 ] || _notrun "Test device is too small ($avail_begin KiB)"
47
48 # Preallocate half size of the available disk space to a file
49 # starts from offset 0 with FALLOC_FL_KEEP_SIZE option on the
50 # test file system.
51 $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
52         $TEST_DIR/testfile.$seq >>$seqres.full 2>&1
53
54 # Verify the file size, it should keep unchanged as 0 in this case
55 fsize=`ls -l $TEST_DIR/testfile.$seq | awk '{print $5}'`
56 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
57
58 # Truncate the file size back to 0
59 truncate -s 0 $TEST_DIR/testfile.$seq
60 sync
61
62 # Preallocated disk space should be released
63 avail_done=`df -P $TEST_DIR | awk 'END {print $4}'`
64 _within_tolerance "df" $avail_done $avail_begin 1%
65 [ $? -eq 0 ] || _fail "Available disk space ($avail_done KiB) wanted ($avail_begin KiB)"
66
67 # success, all done
68 exit