summaryrefslogtreecommitdiffstats
path: root/tests/f_extent_htree/script
blob: fb24a63c7b0a5588fc13267ccd80883bc8eb66f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
TMPDIR=${TMPDIR:-"/tmp"}
OUT=$test_name.log

FSCK_OPT="-fyvD"
SKIP_GUNZIP="true"

NAMELEN=250
SRC=$TMPDIR/$test_name.tmp
SUB=subdir
BASE=$SRC/$SUB/$(yes | tr -d '\n' | dd bs=$NAMELEN count=1 2> /dev/null)
TMPFILE=${TMPFILE:-"$TMPDIR/image"}
BSIZE=1024

> $OUT
mkdir -p $SRC/$SUB
# calculate the number of files needed to create the directory extent tree
# deep enough to exceed the in-inode index and spill into an index block.
#
# dirents per block * extents per block * (index blocks > i_blocks)
NUM=$(((BSIZE / (NAMELEN + 8)) * (BSIZE / 12) * 2))
# Create source files. Unfortunately hard links will be copied as links,
# and blocks with only NULs will be turned into holes.
if [ ! -f $BASE.1 ]; then
	for N in $(seq $NUM); do
		echo "foo" > $BASE.$N
	done >> $OUT
fi

# make filesystem with enough inodes and blocks to hold all the test files
> $TMPFILE
NUM=$((NUM * 7 / 3))
echo "mke2fs -b $BSIZE -O dir_index,extent -E no_copy_xattrs -d$SRC -N$NUM $TMPFILE $NUM" >> $OUT
$MKE2FS -b $BSIZE -O dir_index,extent -E no_copy_xattrs -d$SRC -N$NUM $TMPFILE $NUM >> $OUT 2>&1
rm -r $SRC

# Run e2fsck to convert dir to htree before deleting the files, as mke2fs
# doesn't do this.  Run second e2fsck to verify there is no corruption yet.
(
	EXP1=$test_dir/expect.pre.1
	EXP2=$test_dir/expect.pre.2
	OUT1=$test_name.pre.1.log
	OUT2=$test_name.pre.2.log
	DESCRIPTION="$(cat $test_dir/name) setup"
	. $cmd_dir/run_e2fsck
)

# generate a list of filenames for debugfs to delete, one from each leaf block
DELETE_LIST=$TMPDIR/delete.$$
$DEBUGFS -c -R "htree subdir" $TMPFILE 2>> $OUT |
	grep -A2 "Reading directory block" |
	awk '/yyyyy/ { print "rm '$SUB'/"$4 }' > $DELETE_LIST
$DEBUGFS -w -f $DELETE_LIST $TMPFILE >> $OUT 2>&1
rm $DELETE_LIST

. $cmd_dir/run_e2fsck