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