summaryrefslogtreecommitdiffstats
path: root/tests/f_large_dir/script
blob: e3235836f99792baacd6aef165b5f6e0ce886caf (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
OUT=$test_name.log
EXP=$test_dir/expect
E2FSCK=../e2fsck/e2fsck

NAMELEN=255
DIRENT_SZ=8
BLOCKSZ=1024
INODESZ=128
DIRENT_PER_LEAF=$((BLOCKSZ / (NAMELEN + DIRENT_SZ)))
HEADER=32
INDEX_SZ=8
INDEX_L1=$(((BLOCKSZ - HEADER) / INDEX_SZ))
INDEX_L2=$(((BLOCKSZ - DIRENT_SZ) / INDEX_SZ))
DIRBLK=$((2 + INDEX_L1 * INDEX_L2))
ENTRIES=$((DIRBLK * DIRENT_PER_LEAF))
EXT4_LINK_MAX=65000
if [ $ENTRIES -lt $((EXT4_LINK_MAX + 10)) ]; then
	ENTRIES=$((EXT4_LINK_MAX + 10))
	DIRBLK=$((ENTRIES / DIRENT_PER_LEAF + 3))
fi
# directory leaf blocks plus inode count and 25% for the rest of the fs
FSIZE=$(((DIRBLK + EXT4_LINK_MAX * ((BLOCKSZ + INODESZ) / BLOCKSZ)) * 5 / 4))

$MKE2FS -b 1024 -O large_dir,uninit_bg -N $((ENTRIES + 50)) \
	-I $INODESZ -F $TMPFILE $FSIZE > $OUT.new 2>&1
RC=$?
if [ $RC -eq 0 ]; then
{
	# First some initial fs setup to create indexed dir
	echo "mkdir /foo"
	echo "cd /foo"
	touch $TMPFILE.tmp
	echo "write $TMPFILE.tmp foofile"
	i=0
	while test $i -lt $DIRENT_PER_LEAF ; do
		printf "mkdir d%0254u\n" $i
		i=$((i + 1));
	done
	echo "expand ./"
	printf "mkdir d%0254u\n" $i
} | $DEBUGFS -w $TMPFILE > /dev/null 2>> $OUT.new
	RC=$?
	# e2fsck should optimize the dir to become indexed
	$E2FSCK -yfD $TMPFILE >> $OUT.new 2>&1
	status=$?
	echo Exit status is $status >> $OUT.new
fi

if [ $RC -eq 0 ]; then
{
	START=$SECONDS
	i=$(($DIRENT_PER_LEAF+1))
	last=$i
	echo "cd /foo"
	while test $i -lt $ENTRIES ; do
	    ELAPSED=$((SECONDS - START))
	    if test $((i % 5000)) -eq 0 -a $ELAPSED -gt 10; then
		RATE=$(((i - last) / ELAPSED))
		echo "$test_name: $i/$ENTRIES links, ${ELAPSED}s @ $RATE/s" >&2
		START=$SECONDS
		last=$i
	    fi
	    if test $i -lt $((EXT4_LINK_MAX + 10)); then
		printf "mkdir d%0254u\n" $i
	    else
		printf "ln foofile f%0254u\n" $i
	    fi
	    i=$((i + 1))
	done
} | $DEBUGFS -w $TMPFILE > /dev/null 2>> $OUT.new
	RC=$?
fi

if [ $RC -eq 0 ]; then
	$E2FSCK -yfD $TMPFILE >> $OUT.new 2>&1
	status=$?
	echo Exit status is $status >> $OUT.new
	sed -f $cmd_dir/filter.sed -e "s;$TMPFILE;test.img;" $OUT.new > $OUT
	rm -f $OUT.new

	cmp -s $OUT $EXP
	RC=$?
fi
if [ $RC -eq 0 ]; then
	echo "$test_name: $test_description: ok"
	touch $test_name.ok
else
	echo "$test_name: $test_description: failed"
	diff -u $EXP $OUT > $test_name.failed
fi