generic/077: fall back to /usr if /lib/modules doesn't exist
[xfstests-dev.git] / tests / xfs / 179
1 #! /bin/bash
2 # FSQA Test No. 179
3 #
4 # Test for NULL files problem
5 # test inode size is on disk after fsync
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common/rc
37 . ./common/filter
38
39 # real QA test starts here
40 _supported_fs xfs
41 _supported_os Linux IRIX
42
43 _require_scratch
44 _scratch_mkfs_xfs >/dev/null 2>&1
45 _scratch_mount
46
47 _check_files()
48 {
49         # check file size and contents
50         i=1;
51         while [ $i -lt 1000 ]
52         do
53                 file=$SCRATCH_MNT/$i
54                 # if file is missing then fsync failed
55                 if [ -e $file ]
56                 then
57                         # if file size is not 32KB then fsync failed
58                         if [ `ls -l $file | tr -s ' ' | cut -d ' ' -f 5` -eq 32768 ]
59                         then
60                                 # if file has non-zero size but no extents then it's contents will be NULLs, bad.
61                                 if xfs_bmap $file | grep 'no extents' > /dev/null
62                                 then
63                                         echo corrupt file $file - non-zero size but no extents
64                                 else
65                                         rm -f $file
66                                 fi
67                         else
68                                 echo file $file has incorrect size - fsync failed
69                         fi
70                 else
71                         echo file $file missing - fsync failed
72                 fi
73                 let i=$i+1
74         done
75 }
76
77 # create files and fsync them
78 i=1;
79 while [ $i -lt 1000 ]
80 do
81         file=$SCRATCH_MNT/$i
82         xfs_io -f -c "pwrite -b 32k -S 0xff 0 32k" -c "fsync" $file > /dev/null
83         if [ $? -ne 0 ]
84         then
85                 echo error creating/writing file $file
86                 exit
87         fi
88         let i=$i+1
89 done
90
91 # shutdown immediately after, then remount and test
92 src/godown $SCRATCH_MNT
93 umount $SCRATCH_MNT
94 _scratch_mount
95 umount $SCRATCH_MNT
96 if [ ! _check_scratch_fs ]
97 then
98         echo error detected in filesystem
99         exit
100 fi
101 _scratch_mount
102 _check_files
103
104 status=0
105 exit