fstests: use _require_symlinks on all necessary tests
[xfstests-dev.git] / tests / generic / 047
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FSQA Test No. 047
6 #
7 # Test for NULL files problem
8 # test inode size is on disk after fsync
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 "exit \$status" 0 1 2 3 15
18
19 # get standard environment, filters and checks
20 . ./common/rc
21 . ./common/filter
22
23 # real QA test starts here
24 _supported_fs generic
25 _supported_os Linux
26
27 _require_scratch
28 _require_scratch_shutdown
29 _require_xfs_io_command "fiemap"
30 _scratch_mkfs >/dev/null 2>&1
31 _require_metadata_journaling $SCRATCH_DEV
32 _scratch_mount
33
34 _check_files()
35 {
36         # check file size and contents
37         i=1;
38         while [ $i -lt 1000 ]
39         do
40                 file=$SCRATCH_MNT/$i
41                 # if file is missing then fsync failed
42                 if [ -e $file ]
43                 then
44                         # if file size is not 32KB then fsync failed
45                         if [ `ls -l $file | tr -s ' ' | cut -d ' ' -f 5` -eq 32768 ]
46                         then
47                                 # if file has non-zero size but no extents then it's contents will be NULLs, bad.
48                                 num_extents=`_count_extents $file`
49                                 if [ $num_extents -eq 0 ]; then
50                                         echo corrupt file $file - non-zero size but no extents
51                                 else
52                                         rm -f $file
53                                 fi
54                         else
55                                 echo file $file has incorrect size - fsync failed
56                         fi
57                 else
58                         echo file $file missing - fsync failed
59                 fi
60                 let i=$i+1
61         done
62 }
63
64 # create files and fsync them
65 i=1;
66 while [ $i -lt 1000 ]
67 do
68         file=$SCRATCH_MNT/$i
69         $XFS_IO_PROG -f -c "pwrite -b 32k -S 0xff 0 32k" -c "fsync" $file > /dev/null
70         if [ $? -ne 0 ]
71         then
72                 echo error creating/writing file $file
73                 exit
74         fi
75         let i=$i+1
76 done
77
78 # shutdown immediately after, then remount and test
79 _scratch_shutdown
80 _scratch_unmount
81 _scratch_mount
82 _scratch_unmount
83 if [ ! _check_scratch_fs ]
84 then
85         echo error detected in filesystem
86         exit
87 fi
88 _scratch_mount
89 _check_files
90
91 status=0
92 exit