btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / xfs / 166
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2007 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FSQA Test No. 166
6 #
7 # ->page-mkwrite test - unwritten extents and mmap
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "exit \$status" 0 1 2 3 15
17 rm -f $seqres.full
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22
23 # assumes 1st, 3rd and 5th blocks are single written blocks,
24 # the others are unwritten.
25 _filter_blocks()
26 {
27         $AWK_PROG '
28 /^ +[0-9]/ {
29         if (!written_size) {
30                 written_size = $6
31                 unwritten1 = ((1048576/512) / 2) - written_size
32                 unwritten2 = ((1048576/512) / 2) - 2 * written_size
33         }
34
35         # is the extent unwritten?
36         unwritten_ext = 0;
37         if ($7 >= 10000)
38                 unwritten_ext = 1;
39
40         size = "RIGHT"
41         flags = "GOOD"
42         if (unwritten_ext) {
43                 if (unwritten1) {
44                         if ($6 != unwritten1)
45                                 size = "WRONG"
46                         unwritten1 = 0;
47                 } else if ($6 != unwritten2) {
48                         size = "WRONG"
49                 }
50         } else {
51                 if ($6 != written_size)
52                         size = "WRONG"
53         }
54         print $1, "[AA..BB]", "XX..YY", "AG", "(AA..BB)", size, flags
55 }'
56 }
57
58 # real QA test starts here
59 _supported_fs xfs
60
61 _require_scratch
62 _require_xfs_io_command "falloc"
63
64 _scratch_mkfs_xfs >/dev/null 2>&1
65 _scratch_mount
66
67 TEST_FILE=$SCRATCH_MNT/test_file
68 TEST_PROG=$here/src/unwritten_mmap
69 FILE_SIZE=1048576
70
71 rm -f $TEST_FILE
72 $TEST_PROG $FILE_SIZE $TEST_FILE
73
74 xfs_bmap -vp $TEST_FILE >> $seqres.full
75 xfs_bmap -vp $TEST_FILE | _filter_blocks
76
77 status=0
78 exit