• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3FSCK_OPT="-fyvD"
4. $cmd_dir/run_e2fsck
5rm -f $TMPFILE
6
7exit 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
15TMPDIR=${TMPDIR:-"/tmp"}
16OUT=$test_name.log
17
18FSCK_OPT="-fyvD"
19SKIP_GUNZIP="true"
20
21NAMELEN=250
22SRC=$TMPDIR/$test_name.tmp
23SUB=subdir
24BASE=$SRC/$SUB/$(yes | tr -d '\n' | dd bs=$NAMELEN count=1 2> /dev/null)
25TMPFILE=${TMPFILE:-"$TMPDIR/image"}
26BSIZE=1024
27
28> $OUT
29mkdir -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)
34NUM=$(((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.
37if [ ! -f $BASE.1 ]; then
38	for N in $(seq $NUM); do
39		echo "foo" > $BASE.$N
40	done >> $OUT
41fi
42
43# make filesystem with enough inodes and blocks to hold all the test files
44> $TMPFILE
45NUM=$((NUM * 5 / 3))
46echo "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
48rm -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
62DELETE_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
67rm $DELETE_LIST
68cp $TMPFILE $TMPFILE.sav
69
70. $cmd_dir/run_e2fsck
71