• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2TMPDIR=${TMPDIR:-"/tmp"}
3OUT=$test_name.log
4
5FSCK_OPT="-fyvD"
6SKIP_GUNZIP="true"
7
8NAMELEN=250
9SRC=$TMPDIR/$test_name.tmp
10SUB=subdir
11BASE=$SRC/$SUB/$(yes | tr -d '\n' | dd bs=$NAMELEN count=1 2> /dev/null)
12TMPFILE=${TMPFILE:-"$TMPDIR/image"}
13BSIZE=1024
14
15> $OUT
16mkdir -p $SRC/$SUB
17# calculate the number of files needed to create the directory extent tree
18# deep enough to exceed the in-inode index and spill into an index block.
19#
20# dirents per block * extents per block * (index blocks > i_blocks)
21NUM=$(((BSIZE / (NAMELEN + 8)) * (BSIZE / 12) * 2))
22# Create source files. Unfortunately hard links will be copied as links,
23# and blocks with only NULs will be turned into holes.
24if [ ! -f $BASE.1 ]; then
25	for N in $(seq $NUM); do
26		echo "foo" > $BASE.$N
27	done >> $OUT
28fi
29
30# make filesystem with enough inodes and blocks to hold all the test files
31> $TMPFILE
32NUM=$((NUM * 7 / 3))
33echo "mke2fs -b $BSIZE -O dir_index,extent -E no_copy_xattrs -d$SRC -N$NUM $TMPFILE $NUM" >> $OUT
34$MKE2FS -b $BSIZE -O dir_index,extent -E no_copy_xattrs -d$SRC -N$NUM $TMPFILE $NUM >> $OUT 2>&1
35rm -r $SRC
36
37# Run e2fsck to convert dir to htree before deleting the files, as mke2fs
38# doesn't do this.  Run second e2fsck to verify there is no corruption yet.
39(
40	EXP1=$test_dir/expect.pre.1
41	EXP2=$test_dir/expect.pre.2
42	OUT1=$test_name.pre.1.log
43	OUT2=$test_name.pre.2.log
44	DESCRIPTION="$(cat $test_dir/name) setup"
45	. $cmd_dir/run_e2fsck
46)
47
48# generate a list of filenames for debugfs to delete, one from each leaf block
49DELETE_LIST=$TMPDIR/delete.$$
50$DEBUGFS -c -R "htree subdir" $TMPFILE 2>> $OUT |
51	grep -A2 "Reading directory block" |
52	awk '/yyyyy/ { print "rm '$SUB'/"$4 }' > $DELETE_LIST
53$DEBUGFS -w -f $DELETE_LIST $TMPFILE >> $OUT 2>&1
54rm $DELETE_LIST
55
56. $cmd_dir/run_e2fsck
57