fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 046
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. 046
6 #
7 # Test for NULL files problem
8 #
9 . ./common/preamble
10 _begin_fstest shutdown metadata log auto
11
12 # Import common functions.
13 . ./common/filter
14
15 # real QA test starts here
16 _supported_fs generic
17
18 _require_scratch
19 _require_scratch_shutdown
20 _require_xfs_io_command "fiemap"
21 _scratch_mkfs >/dev/null 2>&1
22 _require_metadata_journaling $SCRATCH_DEV
23 _scratch_mount
24
25 # create files
26 i=1;
27 while [ $i -lt 1000 ]
28 do
29         file=$SCRATCH_MNT/$i
30         $XFS_IO_PROG -f -c "pwrite -b 32k -S 0xff 0 32k" $file > /dev/null
31         if [ $? -ne 0 ]
32         then
33                 echo error creating/writing file $file
34                 exit
35         fi
36         $XFS_IO_PROG -c "truncate 64k" $file > /dev/null
37         if [ $? -ne 0 ]
38         then
39                 echo error truncating file $file
40                 exit
41         fi
42         let i=$i+1
43 done
44
45 # give the system a chance to write something out
46 sleep 10
47
48 _scratch_shutdown
49
50 _scratch_unmount
51 _scratch_mount
52 _scratch_unmount
53 if [ ! _check_scratch_fs ]
54 then
55         echo error detected in filesystem
56         exit
57 fi
58 _scratch_mount
59
60 # check file size and contents
61 i=1;
62 while [ $i -lt 1000 ]
63 do
64         file=$SCRATCH_MNT/$i
65         # if file does not exist, the create was not logged, skip it
66         if [ -e $file ]
67         then
68                 # if file size is zero it cannot be corrupt, skip it
69                 if [ -s $file ]
70                 then
71                         # if file has non-zero size but no extents then it's contents will be NULLs, bad.
72                         num_extents=`_count_extents $file`
73                         if [ $num_extents -eq 0 ]; then
74                                 echo corrupt file $file - non-zero size but no extents
75                         else
76                                 rm -f $file
77                         fi
78                 else
79                         rm -f $file
80                 fi
81         fi
82         let i=$i+1
83 done
84
85 status=0
86 exit