generic: test for creating duplicate filenames in encrypted dir
[xfstests-dev.git] / tests / generic / 018
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2009 Eric Sandeen.  All Rights Reserved.
4 #
5 # FS QA Test No. generic/018
6 #
7 # Basic defragmentation sanity tests
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 "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/defrag
28
29 # real QA test starts here
30 _supported_fs generic
31
32 # We require scratch so that we'll have free contiguous space
33 _require_scratch
34 _scratch_mkfs >/dev/null 2>&1
35 _scratch_mount
36
37 _require_defrag
38
39 fragfile=$SCRATCH_MNT/fragfile.$$
40
41 rm -f $fragfile
42
43 # Craft some fragmented files, defrag them, check the result.
44 bsize=$(_get_file_block_size $SCRATCH_MNT)
45
46 echo "zero-length file:" | tee -a $seqres.full
47 touch $fragfile
48 _defrag --before 0 --after 0 $fragfile
49
50 echo "Sparse file (no blocks):" | tee -a $seqres.full
51 $XFS_IO_PROG -f -c "truncate 1m" $fragfile
52 _defrag --before 0 --after 0 $fragfile
53
54 echo "Contiguous file:" | tee -a $seqres.full
55 $XFS_IO_PROG -f -c "pwrite -b $((4 * bsize)) 0 $((4 * bsize))" $fragfile \
56                                         > /dev/null
57 _defrag --before 1 --after 1 $fragfile
58
59 echo "Write backwards sync, but contiguous - should defrag to 1 extent" | tee -a $seqres.full
60 for i in `seq 9 -1 0`; do
61         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
62                                         > /dev/null
63 done
64
65 # Accept fewer fragments than we might expect; we don't have perfect control.
66 _defrag --max_before 10 --min_before 5 --after 1 $fragfile
67
68 echo "Write backwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
69 for i in `seq 31 -2 0`; do
70         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
71                                         > /dev/null
72 done
73 _defrag --before 16 --after 16 $fragfile
74
75 echo "Write forwards sync leaving holes - defrag should do nothing" | tee -a $seqres.full
76 for i in `seq 0 2 31`; do
77         $XFS_IO_PROG -fs -c "pwrite -b $bsize $((i * bsize)) $bsize" $fragfile \
78                                         > /dev/null
79 done
80 _defrag --before 16 --after 16 $fragfile
81
82 rm -f $seqres.full
83 status=0
84 exit