Modify existing test cases, and add a new one.
[xfstests-dev.git] / 140
1 #! /bin/sh
2 # FSQA Test No. 140
3 #
4 # Test for NULL files problem
5 #
6 #-----------------------------------------------------------------------
7 #  Copyright (c) 2006 Silicon Graphics, Inc.  All Rights Reserved.
8 #-----------------------------------------------------------------------
9 #
10 # creator
11 owner=lachlan@sgi.com
12
13 seq=`basename $0`
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     _cleanup_testdir
24 }
25
26 # get standard environment, filters and checks
27 . ./common.rc
28 . ./common.filter
29
30 # real QA test starts here
31 _supported_fs xfs
32 _supported_os Linux IRIX
33
34 _setup_testdir
35 _require_scratch
36 _scratch_mkfs_xfs >/dev/null 2>&1
37 _scratch_mount
38
39 # create files
40 i=1;
41 while [ $i -lt 1000 ]
42 do
43         file=$SCRATCH_MNT/$i
44         xfs_io -f -c "pwrite -b 32k -S 0xff 0 32k" $file > /dev/null
45         if [ $? -ne 0 ]
46         then
47                 echo error creating/writing file $file
48                 exit
49         fi
50         xfs_io -c "truncate 64k" $file > /dev/null
51         if [ $? -ne 0 ]
52         then
53                 echo error truncating file $file
54                 exit
55         fi
56         i=`expr $i + 1`
57 done
58
59 # give the system a chance to write something out
60 sleep 10
61
62 src/godown $SCRATCH_MNT
63
64 umount $SCRATCH_MNT
65 _scratch_mount
66 umount $SCRATCH_MNT
67 if [ ! _check_scratch_fs ]
68 then
69         echo error detected in filesystem
70         exit
71 fi
72 _scratch_mount
73
74 # check file size and contents
75 i=1;
76 while [ $i -lt 1000 ]
77 do
78         file=$SCRATCH_MNT/$i
79         # if file does not exist, the create was not logged, skip it
80         if [ -e $file ]
81         then
82                 # if file size is zero it cannot be corrupt, skip it
83                 if [ -s $file ]
84                 then
85                         # if file has non-zero size but no extents then it's contents will be NULLs, bad.
86                         if xfs_bmap $file | grep 'no extents' > /dev/null
87                         then
88                                 echo corrupt file $file - non-zero size but no extents
89                         else
90                                 rm -f $file
91                         fi
92                 else
93                         rm -f $file
94                 fi
95         fi
96         i=`expr $i + 1`
97 done
98
99 status=0
100 exit