1if ! test -x $DEBUGFS_EXE; then 2 echo "$test_name: $test_description: skipped (no debugfs)" 3 return 0 4fi 5 6FSCK_OPT=-fy 7OUT=$test_name.log 8if [ -f $test_dir/expect.gz ]; then 9 EXP=$test_name.tmp 10 gunzip < $test_dir/expect.gz > $EXP 11else 12 EXP=$test_dir/expect 13fi 14 15cat > $TMPFILE.conf << ENDL 16[fs_types] 17ext4 = { 18 base_features = sparse_super,filetype,resize_inode,dir_index,ext_attr,^has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize,64bit 19 blocksize = 1024 20 inode_size = 256 21 inode_ratio = 16384 22} 23ENDL 24MKE2FS_CONFIG=$TMPFILE.conf $MKE2FS -F -o Linux -b 1024 -O ^bigalloc -T ext4 $TMPFILE 65536 > $OUT.new 2>&1 25rm -f $TMPFILE.conf 26 27$FSCK -fy -N test_filesys $TMPFILE >> $OUT.new 2>&1 28status=$? 29echo Exit status is $status >> $OUT.new 30 31echo "debugfs write files" >> $OUT.new 32make_file() { 33 name="$1" 34 start="$2" 35 flag="$3" 36 37 cat << ENDL 38write /dev/null $name 39sif /$name size 40960 40eo /$name 41set_bmap $flag 10 $((start + 10)) 42set_bmap $flag 13 $((start + 13)) 43set_bmap $flag 26 $((start + 26)) 44set_bmap $flag 29 $((start + 29)) 45ec 46sif /$name blocks 8 47setb $((start + 10)) 48setb $((start + 13)) 49setb $((start + 26)) 50setb $((start + 29)) 51ENDL 52} 53 54#Files we create: 55# a: fallocate a 40k file 56# b*: falloc sparse file starting at b* 57# c*: falloc spare file ending at c* 58# d: midcluster to midcluster, surrounding sparse 59# e: partial middle cluster alloc 60# f: one big file 61# g*: falloc sparse init file starting at g* 62# h*: falloc sparse init file ending at h* 63# i: midcluster to midcluster, surrounding sparse init 64# j: partial middle cluster alloc 65# k: one big init file 66base=5000 67cat > $TMPFILE.cmd << ENDL 68write /dev/null a 69sif /a size 40960 70fallocate /a 0 39 71ENDL 72echo "ex /a" >> $TMPFILE.cmd2 73 74make_file sample $base --uninit >> $TMPFILE.cmd 75echo "ex /sample" >> $TMPFILE.cmd2 76base=10000 77 78for i in 8 9 10 11 12 13 14 15; do 79 make_file b$i $(($base + (40 * ($i - 8)))) --uninit >> $TMPFILE.cmd 80 echo "fallocate /b$i $i 39" >> $TMPFILE.cmd 81 echo "ex /b$i" >> $TMPFILE.cmd2 82done 83 84for i in 24 25 26 27 28 29 30 31; do 85 make_file c$i $(($base + 320 + (40 * ($i - 24)))) --uninit >> $TMPFILE.cmd 86 echo "fallocate /c$i 0 $i" >> $TMPFILE.cmd 87 echo "ex /c$i" >> $TMPFILE.cmd2 88done 89 90make_file d $(($base + 640)) --uninit >> $TMPFILE.cmd 91echo "fallocate /d 4 35" >> $TMPFILE.cmd 92echo "ex /d" >> $TMPFILE.cmd2 93 94make_file e $(($base + 680)) --uninit >> $TMPFILE.cmd 95echo "fallocate /e 19 20" >> $TMPFILE.cmd 96echo "ex /e" >> $TMPFILE.cmd2 97 98cat >> $TMPFILE.cmd << ENDL 99write /dev/null f 100sif /f size 1024 101eo /f 102set_bmap --uninit 0 9000 103ec 104sif /f blocks 2 105setb 9000 106fallocate /f 0 8999 107ENDL 108echo "ex /f" >> $TMPFILE.cmd2 109 110# Now do it again, but with initialized blocks 111base=20000 112for i in 8 9 10 11 12 13 14 15; do 113 make_file g$i $(($base + (40 * ($i - 8)))) >> $TMPFILE.cmd 114 echo "fallocate /g$i $i 39" >> $TMPFILE.cmd 115 echo "ex /g$i" >> $TMPFILE.cmd2 116done 117 118for i in 24 25 26 27 28 29 30 31; do 119 make_file h$i $(($base + 320 + (40 * ($i - 24)))) >> $TMPFILE.cmd 120 echo "fallocate /h$i 0 $i" >> $TMPFILE.cmd 121 echo "ex /h$i" >> $TMPFILE.cmd2 122done 123 124make_file i $(($base + 640)) >> $TMPFILE.cmd 125echo "fallocate /i 4 35" >> $TMPFILE.cmd 126echo "ex /i" >> $TMPFILE.cmd2 127 128make_file j $(($base + 680)) >> $TMPFILE.cmd 129echo "fallocate /j 19 20" >> $TMPFILE.cmd 130echo "ex /j" >> $TMPFILE.cmd2 131 132cat >> $TMPFILE.cmd << ENDL 133write /dev/null k 134sif /k size 1024 135eo /k 136set_bmap 0 19000 137ec 138sif /k blocks 2 139setb 19000 140fallocate /k 0 8999 141sif /k size 9216000 142ENDL 143echo "ex /k" >> $TMPFILE.cmd2 144 145$DEBUGFS -w -f $TMPFILE.cmd $TMPFILE > /dev/null 2>&1 146$DEBUGFS -f $TMPFILE.cmd2 $TMPFILE >> $OUT.new 2>&1 147 148$FSCK -fy -N test_filesys $TMPFILE >> $OUT.new 2>&1 149status=$? 150echo Exit status is $status >> $OUT.new 151sed -f $cmd_dir/filter.sed $OUT.new > $OUT 152rm -f $TMPFILE $TMPFILE.cmd $TMPFILE.cmd2 $OUT.new 153 154cmp -s $OUT $EXP 155status=$? 156 157if [ "$status" = 0 ] ; then 158 echo "$test_name: $test_description: ok" 159 touch $test_name.ok 160else 161 echo "$test_name: $test_description: failed" 162 diff $DIFF_OPTS $EXP $OUT > $test_name.failed 163fi 164rm -f $EXP 165 166unset IMAGE FSCK_OPT OUT EXP 167