summaryrefslogtreecommitdiffstats
path: root/tests/ts/cramfs/fsck-bad-header
blob: 95d8274ff419472285261ec8264e436f3f27d0ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash

#
# Copyright (C) 2007 Karel Zak <kzak@redhat.com>
#
# This file is part of util-linux.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
TS_TOPDIR="${0%/*}/../.."
TS_DESC="fsck bad header"

. $TS_TOPDIR/functions.sh
ts_init "$*"

ts_check_test_command "$TS_CMD_MKCRAMFS"
ts_check_test_command "$TS_CMD_FSCKCRAMFS"
ts_check_prog "dd"

function num2binary()
{
	local num=$1
	local endian=$2

	test "$num" -ge 0 -a "$num" -le 4294967295 || return 1
	test "$endian" = "be" -o "$endian" = "le" || return 1

	# how to do that easier?
	if test "$endian" = "be"; then
		echo -en "$(printf "%08x" "$1" | sed 's/\(..\)/\\x\1/g')"
	else
		echo -en "$(printf "%08x" "$1" | sed 's/^\(..\)\(..\)\(..\)\(..\)$/\\x\4\\x\3\\x\2\\x\1/')"
	fi
}

function fsck_loop_sizes()
{
	local endian=$1  # be, le
	local seek=$2    # 4 for nopad, 516 for pad
	shift 2          # the rest are sizes to loop over

	for size in "$@"; do
		ts_log_both  "## size: $size"
		cp -a "$IMAGE_FILE" "$IMAGE_FILE.tmp"
		num2binary "$size" $endian |
			dd of="$IMAGE_FILE.tmp" bs=1 seek="$seek" count=4 conv=notrunc &> /dev/null
		$TS_CMD_FSCKCRAMFS "$IMAGE_FILE.tmp" >> $TS_OUTPUT 2>> $TS_ERRLOG
		ts_log "ret: $?
"
	done
	rm -f "$IMAGE_FILE"
}


IMAGE_SOURCE="$TS_OUTDIR/${TS_TESTNAME}-data"
IMAGE_FILE="$TS_OUTDIR/${TS_TESTNAME}-cramfs.img"

mkdir -p "${IMAGE_SOURCE}/subdir" &> /dev/null

ts_init_subtest "nopad-4K-be"
$TS_CMD_MKCRAMFS -N big -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
fsck_loop_sizes be 4  0 75 76 4095 4096 4097 4294967295
rm -f "$IMAGE_FILE"
ts_finalize_subtest

ts_init_subtest "nopad-4K-le"
$TS_CMD_MKCRAMFS -N little -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
fsck_loop_sizes le 4  0 75 76 4095 4096 4097 4294967295
ts_finalize_subtest

ts_init_subtest "pad-4K-be"
$TS_CMD_MKCRAMFS -p -N big -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
fsck_loop_sizes be 516  76 587 588 4095 4096 4097 4294967295
ts_finalize_subtest

ts_init_subtest "pad-4K-le"
$TS_CMD_MKCRAMFS -p -N little -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
fsck_loop_sizes le 516  76 587 588 4095 4096 4097 4294967295
ts_finalize_subtest

ts_init_subtest "pad-64K-be"
$TS_CMD_MKCRAMFS -p -N big -b 65536 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
fsck_loop_sizes be 516  76 587 588 65535 65536 65537 4294967295
ts_finalize_subtest

ts_init_subtest "pad-64K-le"
$TS_CMD_MKCRAMFS -p -N little -b 65536 $IMAGE_SOURCE $IMAGE_FILE &> /dev/null
fsck_loop_sizes le 516  76 587 588 65535 65536 65537 4294967295
ts_finalize_subtest

rm -rf "$IMAGE_SOURCE" "$IMAGE_FILE.tmp"

ts_finalize