xref: /aosp_15_r20/external/e2fsprogs/tests/f_detect_junk/script (revision 6a54128f25917bfc36a8a6e9d722c04a0b4641b6)
1*6a54128fSAndroid Build Coastguard Worker#!/bin/bash
2*6a54128fSAndroid Build Coastguard Worker
3*6a54128fSAndroid Build Coastguard Workerif [ "$(grep -c 'define HAVE_MAGIC_H' ../lib/config.h)" -eq 0 ]; then
4*6a54128fSAndroid Build Coastguard Worker	echo "$test_name: skipped (no magic)"
5*6a54128fSAndroid Build Coastguard Worker	exit 0
6*6a54128fSAndroid Build Coastguard Workerfi
7*6a54128fSAndroid Build Coastguard Worker
8*6a54128fSAndroid Build Coastguard WorkerFSCK_OPT=-fn
9*6a54128fSAndroid Build Coastguard WorkerIMAGE=$test_dir/image.bz2
10*6a54128fSAndroid Build Coastguard Worker
11*6a54128fSAndroid Build Coastguard Workerbzip2 -d < $IMAGE > $TMPFILE
12*6a54128fSAndroid Build Coastguard Worker$DD if=/dev/zero of=$TMPFILE conv=notrunc oflag=append bs=1024k count=16 > /dev/null 2>&1
13*6a54128fSAndroid Build Coastguard Worker
14*6a54128fSAndroid Build Coastguard Worker# Run fsck to fix things?
15*6a54128fSAndroid Build Coastguard Workerif [ -x $DEBUGFS_EXE ]; then
16*6a54128fSAndroid Build Coastguard Worker	EXP=$test_dir/expect
17*6a54128fSAndroid Build Coastguard Workerelse
18*6a54128fSAndroid Build Coastguard Worker	EXP=$test_dir/expect.nodebugfs
19*6a54128fSAndroid Build Coastguard Workerfi
20*6a54128fSAndroid Build Coastguard WorkerOUT=$test_name.log
21*6a54128fSAndroid Build Coastguard Workerrm -f $test_name.failed $test_name.ok
22*6a54128fSAndroid Build Coastguard Worker
23*6a54128fSAndroid Build Coastguard Workerecho "*** e2fsck" > $OUT
24*6a54128fSAndroid Build Coastguard Worker$FSCK $FSCK_OPT $TMPFILE >> $OUT 2>&1
25*6a54128fSAndroid Build Coastguard Workerecho "*** debugfs" >> $OUT
26*6a54128fSAndroid Build Coastguard Workertest -x $DEBUGFS_EXE && $DEBUGFS -R 'quit' $TMPFILE >> $OUT 2>&1
27*6a54128fSAndroid Build Coastguard Workerecho "*** tune2fs" >> $OUT
28*6a54128fSAndroid Build Coastguard Worker$TUNE2FS -i 0 $TMPFILE >> $OUT 2>&1
29*6a54128fSAndroid Build Coastguard Workerecho "*** mke2fs" >> $OUT
30*6a54128fSAndroid Build Coastguard Worker$MKE2FS -n $TMPFILE >> $OUT 2>&1
31*6a54128fSAndroid Build Coastguard Worker
32*6a54128fSAndroid Build Coastguard Workersed -f $cmd_dir/filter.sed < $OUT > $OUT.new
33*6a54128fSAndroid Build Coastguard Workermv $OUT.new $OUT
34*6a54128fSAndroid Build Coastguard Worker
35*6a54128fSAndroid Build Coastguard Worker# Figure out what happened
36*6a54128fSAndroid Build Coastguard Workerif cmp -s $EXP $OUT; then
37*6a54128fSAndroid Build Coastguard Worker	echo "$test_name: $test_description: ok"
38*6a54128fSAndroid Build Coastguard Worker	touch $test_name.ok
39*6a54128fSAndroid Build Coastguard Workerelse
40*6a54128fSAndroid Build Coastguard Worker	echo "$test_name: $test_description: failed"
41*6a54128fSAndroid Build Coastguard Worker	diff -u $EXP $OUT >> $test_name.failed
42*6a54128fSAndroid Build Coastguard Workerfi
43*6a54128fSAndroid Build Coastguard Workerunset EXP OUT FSCK_OPT IMAGE
44