Whamcloud - gitweb
LU-7381 e2fsck: fix e2fsck -fD directory truncation
[tools/e2fsprogs.git] / tests / f_extent_htree / script
1 #!/bin/bash
2
3 FSCK_OPT="-fyvD"
4 . $cmd_dir/run_e2fsck
5
6 exit $?
7 # This script depends on "mke2fs -d", which is only in master and not maint,
8 # to populate the file directory tree poorly (namely that there are no
9 # contiguous blocks in the directory leaf and the extent tree is large).
10
11 # Once the "mke2fs -d" option is available on the "maint" branch, the
12 # above few lines should be deleted, along with the "image.gz" file.
13
14 TMPDIR=${TMPDIR:-"/tmp"}
15 OUT=$test_name.log
16
17 FSCK_OPT="-fyvD"
18 SKIP_GUNZIP="true"
19
20 NAMELEN=250
21 SRC=$TMPDIR/$test_name.tmp
22 SUB=subdir
23 BASE=$SRC/$SUB/$(yes | tr -d '\n' | dd bs=$NAMELEN count=1 2> /dev/null)
24 TMPFILE=${TMPFILE:-"$TMPDIR/image"}
25 BSIZE=1024
26
27 > $OUT
28 mkdir -p $SRC/$SUB
29 # calculate the number of files needed to create the directory extent tree
30 # deep enough to exceed the in-inode index and spill into an index block.
31 #
32 # dirents per block * extents per block * (index blocks > i_blocks)
33 NUM=$(((BSIZE / (NAMELEN + 8)) * (BSIZE / 12) * 2))
34 # Create source files. Unfortunately hard links will be copied as links,
35 # and blocks with only NULs will be turned into holes.
36 if [ ! -f $BASE.1 ]; then
37         for N in $(seq $NUM); do
38                 echo "foo" > $BASE.$N
39         done >> $OUT
40 fi
41
42 # make filesystem with enough inodes and blocks to hold all the test files
43 > $TMPFILE
44 NUM=$((NUM * 5 / 3))
45 echo "mke2fs -b $BSIZE -O dir_index,extent -d$SRC -N$NUM $TMPFILE $NUM" >> $OUT
46 $MKE2FS -b $BSIZE -O dir_index,extent -d$SRC -N$NUM $TMPFILE $NUM >> $OUT 2>&1
47 rm -r $SRC
48
49 # Run e2fsck to convert dir to htree before deleting the files, as mke2fs
50 # doesn't do this.  Run second e2fsck to verify there is no corruption yet.
51 (
52         EXP1=$test_dir/expect.pre.1
53         EXP2=$test_dir/expect.pre.2
54         OUT1=$test_name.pre.1.log
55         OUT2=$test_name.pre.2.log
56         DESCRIPTION="$(cat $test_dir/name) setup"
57         . $cmd_dir/run_e2fsck
58 )
59
60 # generate a list of filenames for debugfs to delete, one from each leaf block
61 DELETE_LIST=$TMPDIR/delete.$$
62 $DEBUGFS -c -R "htree subdir" $TMPFILE 2>> $OUT |
63         grep -A2 "Reading directory block" |
64         awk '/yyyyy/ { print "rm '$SUB'/"$4 }' > $DELETE_LIST
65 $DEBUGFS -w -f $DELETE_LIST $TMPFILE >> $OUT 2>&1
66 rm $DELETE_LIST
67 cp $TMPFILE $TMPFILE.sav
68
69 . $cmd_dir/run_e2fsck