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