generic: test adding filesystem-level fscrypt key via key_id
[xfstests-dev.git] / tests / generic / 045
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. 045
6 #
7 # Test for NULL files problem
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "exit \$status" 0 1 2 3 15
17
18 # get standard environment, filters and checks
19 . ./common/rc
20 . ./common/filter
21
22 # real QA test starts here
23 _supported_fs generic
24 _supported_os Linux
25
26 _require_scratch
27 _require_scratch_shutdown
28 _require_xfs_io_command "fiemap"
29 _scratch_mkfs >/dev/null 2>&1
30 _require_metadata_journaling $SCRATCH_DEV
31 _scratch_mount
32
33 # create files
34 i=1;
35 while [ $i -lt 1000 ]
36 do
37         file=$SCRATCH_MNT/$i
38         $XFS_IO_PROG -f -c "pwrite -b 64k -S 0xff 0 64k" $file > /dev/null
39         if [ $? -ne 0 ]
40         then
41                 echo error creating/writing file $file
42                 exit
43         fi
44         $XFS_IO_PROG -c "truncate 32k" $file > /dev/null
45         if [ $? -ne 0 ]
46         then
47                 echo error truncating file $file
48                 exit
49         fi
50         let i=$i+1
51 done
52
53 # give the system a chance to write something out
54 sleep 10
55
56 _scratch_shutdown
57
58 _scratch_unmount
59 _scratch_mount
60 _scratch_unmount
61 if [ ! _check_scratch_fs ]
62 then
63         echo error detected in filesystem
64         exit
65 fi
66 _scratch_mount
67
68 # check file size and contents
69 i=1;
70 while [ $i -lt 1000 ]
71 do
72         file=$SCRATCH_MNT/$i
73         # if file does not exist, the create was not logged, skip it
74         if [ -e $file ]
75         then
76                 # if file size is zero it cannot be corrupt, skip it
77                 if [ -s $file ]
78                 then
79                         # if file has non-zero size but no extents then it's contents will be NULLs, bad.
80                         num_extents=`_count_extents $file`
81                         num_holes=`_count_holes $file`
82                         if [ $num_extents -eq 0 ]; then
83                                 echo corrupt file $file - non-zero size but no extents
84                         elif [ $num_holes -ne 0 ]; then
85                                 echo corrupt file $file - contains holes
86                         else
87                                 rm -f $file
88                         fi
89                 else
90                         rm -f $file
91                 fi
92         fi
93         let i=$i+1
94 done
95
96 status=0
97 exit