blob: df22963f25f9cec8c84aef3f3379f1a10dd80a93 [file] [log] [blame]
Denys Vlasenkoe8405612009-10-18 20:57:52 +02001#!/bin/sh
2
Denys Vlasenko1d6e4472009-10-21 14:14:51 +02003# Disabling features we do not match exactly:
Denys Vlasenko149a32a2009-10-22 12:12:17 +02004system_mke2fs='/sbin/mke2fs -O ^resize_inode'
Denys Vlasenko82d64332009-10-20 17:04:55 +02005bbox_mke2fs='./busybox mke2fs'
6
7gen_image() { # params: mke2fs_invocation image_name
Denys Vlasenko05647b52009-10-20 00:06:03 +02008 >$2
9 dd seek=$((kilobytes-1)) bs=1K count=1 </dev/zero of=$2 >/dev/null 2>&1 || exit 1
10 $1 -F $2 $kilobytes >$2.raw_out 2>&1 || return 1
11 cat $2.raw_out \
12 | grep -v '^mke2fs [0-9]*\.[0-9]*\.[0-9]* ' \
13 | grep -v '^Maximum filesystem' \
14 | grep -v '^Writing inode tables' \
15 | grep -v '^Writing superblocks and filesystem accounting information' \
16 | grep -v '^This filesystem will be automatically checked every' \
17 | grep -v '^180 days, whichever comes first' \
Denys Vlasenko05647b52009-10-20 00:06:03 +020018 | sed 's/blocks* unused./blocks unused/' \
19 | sed 's/block groups*/block groups/' \
20 | sed 's/ *$//' \
21 | sed 's/blocks (.*%) reserved/blocks reserved/' \
22 | grep -v '^$' \
23 >$2.out
24}
25
Denys Vlasenkoe8405612009-10-18 20:57:52 +020026test_mke2fs() {
27 echo Testing $kilobytes
28
Denys Vlasenko82d64332009-10-20 17:04:55 +020029 gen_image "$system_mke2fs" image_std || return 1
30 gen_image "$bbox_mke2fs" image_bb || return 1
Denys Vlasenkoe8405612009-10-18 20:57:52 +020031
32 diff -ua image_bb.out image_std.out >image.out.diff || {
33 cat image.out.diff
34 return 1
35 }
Denys Vlasenko05647b52009-10-20 00:06:03 +020036
Denys Vlasenko82d64332009-10-20 17:04:55 +020037 e2fsck -f -n image_bb >image_bb_e2fsck.out 2>&1 || {
Denys Vlasenko95484c82009-10-20 13:34:16 +020038 echo "e2fsck error on image_bb"
Denys Vlasenko82d64332009-10-20 17:04:55 +020039 cat image_bb_e2fsck.out
Denys Vlasenko95484c82009-10-20 13:34:16 +020040 exit 1
41 }
Denys Vlasenkoe8405612009-10-18 20:57:52 +020042}
43
Denys Vlasenko82d64332009-10-20 17:04:55 +020044# -:bbox +:standard
45
Denys Vlasenkoc708a6d2009-10-20 17:47:23 +020046# kilobytes=60 is the minimal allowed size
Denys Vlasenkocbeb4522009-10-20 16:21:29 +020047kilobytes=60
Denys Vlasenko95484c82009-10-20 13:34:16 +020048while true; do
Denys Vlasenko82d64332009-10-20 17:04:55 +020049 test_mke2fs || exit 1
Denys Vlasenko08dfafc2017-07-15 19:18:58 +020050 kilobytes=$((kilobytes+1))
Denys Vlasenkoc708a6d2009-10-20 17:47:23 +020051 test $kilobytes = 200 && break
52done
53
54# Transition from one block group to two
Denys Vlasenko1d6e4472009-10-21 14:14:51 +020055# fails in [8378..8410] range unless -O ^resize_inode
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020056kilobytes=$((1 * 8*1024 - 50))
Denys Vlasenkoc708a6d2009-10-20 17:47:23 +020057while true; do
Denys Vlasenko1d6e4472009-10-21 14:14:51 +020058 test_mke2fs || exit 1
Denys Vlasenko08dfafc2017-07-15 19:18:58 +020059 kilobytes=$((kilobytes+1))
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020060 test $kilobytes = $((1 * 8*1024 + 300)) && break
Denys Vlasenkoc708a6d2009-10-20 17:47:23 +020061done
62
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020063# Transition from 2 block groups to 3
Denys Vlasenkoc708a6d2009-10-20 17:47:23 +020064# works
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020065kilobytes=$((2 * 8*1024 - 50))
Denys Vlasenkoc708a6d2009-10-20 17:47:23 +020066while true; do
67 test_mke2fs || exit 1
Denys Vlasenko08dfafc2017-07-15 19:18:58 +020068 kilobytes=$((kilobytes+1))
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020069 test $kilobytes = $((2 * 8*1024 + 400)) && break
70done
71
72# Transition from 3 block groups to 4
Denys Vlasenko1d6e4472009-10-21 14:14:51 +020073# fails in [24825..24922] range unless -O ^resize_inode
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020074kilobytes=$((3 * 8*1024 - 50))
75while true; do
Denys Vlasenko1d6e4472009-10-21 14:14:51 +020076 test_mke2fs || exit 1
Denys Vlasenko08dfafc2017-07-15 19:18:58 +020077 kilobytes=$((kilobytes+1))
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020078 test $kilobytes = $((3 * 8*1024 + 500)) && break
79done
80
81# Transition from 4 block groups to 5
82# works
83kilobytes=$((4 * 8*1024 - 50))
84while true; do
85 test_mke2fs || exit 1
Denys Vlasenko08dfafc2017-07-15 19:18:58 +020086 kilobytes=$((kilobytes+1))
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020087 test $kilobytes = $((4 * 8*1024 + 600)) && break
88done
89
90# Transition from 5 block groups to 6
Denys Vlasenko1d6e4472009-10-21 14:14:51 +020091# fails in [41230..41391] range unless -O ^resize_inode
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020092kilobytes=$((5 * 8*1024 - 50))
93while true; do
Denys Vlasenko1d6e4472009-10-21 14:14:51 +020094 test_mke2fs || exit 1
Denys Vlasenko08dfafc2017-07-15 19:18:58 +020095 kilobytes=$((kilobytes+1))
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +020096 test $kilobytes = $((5 * 8*1024 + 700)) && break
Denys Vlasenko95484c82009-10-20 13:34:16 +020097done
98exit
99
Denys Vlasenko5e1dbd52009-10-20 22:12:11 +0200100# Random sizes
Denys Vlasenkoe8405612009-10-18 20:57:52 +0200101while true; do
Denys Vlasenko1d6e4472009-10-21 14:14:51 +0200102 kilobytes=$(( (RANDOM*RANDOM) % 5000000 + 60))
Denys Vlasenkoe8405612009-10-18 20:57:52 +0200103 test_mke2fs || exit 1
104done