1#!/bin/sh
2
3# Use this script if you need to regenerate the digest values
4# in test.sh, or if you don't care about digests and you just
5# want to see some fsck results. Should be run as root.
6
7set -e
8
9. ./test-gen.lib
10
11test_cleanup () {
12	umount mnt 2>/dev/null || true
13	rm -rf mnt fout lsout
14}
15
16fail () {
17	echo FAILED
18	test_cleanup
19	gen_cleanup
20	exit 1
21}
22
23pass () {
24	md5=`calc_digest`
25	echo PASSED
26	echo $@ $md5
27	test_cleanup
28	gen_cleanup
29}
30
31# dtest-mount - Exercise the -d directory option of genext2fs
32# Creates an image with a file of given size, verifies it
33# and returns the command line with which to invoke dtest()
34# Usage: dtest-mount file-size number-of-blocks 
35dtest_mount () {
36	size=$1; blocks=$2
37	echo Testing with file of size $size
38	dgen $size $blocks
39	/sbin/e2fsck -fn ext2.img || fail
40	mkdir -p mnt
41	mount -t ext2 -o ro,loop ext2.img mnt || fail
42	if (! [ -f mnt/file.$size ]) || \
43	      [ $size != "`ls -al mnt | grep file.$size |
44	                                awk '{print $5}'`" ] ; then
45		fail
46	fi
47	pass dtest $size $blocks
48}
49
50# ftest-mount - Exercise the -f spec-file option of genext2fs
51# Creates an image with the devices mentioned in the given spec 
52# file, verifies it, and returns the command line with which to
53# invoke ftest()
54# Usage: ftest-mount spec-file number-of-blocks 
55ftest_mount () {
56	fname=$1; blocks=$2 
57	echo Testing with devices file $fname
58	fgen $fname $blocks
59	/sbin/e2fsck -fn ext2.img || fail
60	mkdir -p mnt
61	mount -t ext2 -o ro,loop ext2.img mnt || fail
62	[ -d mnt/dev ] || fail
63	# Exclude those devices that have interpolated
64	# minor numbers, as being too hard to match.
65	egrep -v "(hda|hdb|tty|loop|ram|ubda)" $fname | \
66		grep '^[^	#]*	[bc]' | \
67		awk '{print $1,$4,$5,$6","$7}'| \
68		sort -d -k3.6 > fout
69	ls -aln mnt/dev | \
70		egrep -v "(hda|hdb|tty|loop|ram|ubda)" | \
71		grep ^[bc] | \
72		awk '{ print "/dev/"$10,$3,$4,$5$6}' | \
73		sort -d -k3.6 > lsout
74	diff fout lsout || fail
75	pass ftest $fname $blocks
76}
77
78dtest_mount 0 4096 
79dtest_mount 0 8193
80dtest_mount 0 8194
81dtest_mount 1 4096 
82dtest_mount 12288 4096 
83dtest_mount 274432 4096 
84dtest_mount 8388608 9000 
85dtest_mount 16777216 20000
86
87ftest_mount device_table.txt 4096 
88