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