mkfs_ext2_test.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/sh
  2. # Disabling features we do not match exactly:
  3. system_mke2fs='/sbin/mke2fs -O ^resize_inode'
  4. bbox_mke2fs='./busybox mke2fs'
  5. gen_image() { # params: mke2fs_invocation image_name
  6. >$2
  7. dd seek=$((kilobytes-1)) bs=1K count=1 </dev/zero of=$2 >/dev/null 2>&1 || exit 1
  8. $1 -F $2 $kilobytes >$2.raw_out 2>&1 || return 1
  9. cat $2.raw_out \
  10. | grep -v '^mke2fs [0-9]*\.[0-9]*\.[0-9]* ' \
  11. | grep -v '^Maximum filesystem' \
  12. | grep -v '^Writing inode tables' \
  13. | grep -v '^Writing superblocks and filesystem accounting information' \
  14. | grep -v '^This filesystem will be automatically checked every' \
  15. | grep -v '^180 days, whichever comes first' \
  16. | sed 's/blocks* unused./blocks unused/' \
  17. | sed 's/block groups*/block groups/' \
  18. | sed 's/ *$//' \
  19. | sed 's/blocks (.*%) reserved/blocks reserved/' \
  20. | grep -v '^$' \
  21. >$2.out
  22. }
  23. test_mke2fs() {
  24. echo Testing $kilobytes
  25. gen_image "$system_mke2fs" image_std || return 1
  26. gen_image "$bbox_mke2fs" image_bb || return 1
  27. diff -ua image_bb.out image_std.out >image.out.diff || {
  28. cat image.out.diff
  29. return 1
  30. }
  31. e2fsck -f -n image_bb >image_bb_e2fsck.out 2>&1 || {
  32. echo "e2fsck error on image_bb"
  33. cat image_bb_e2fsck.out
  34. exit 1
  35. }
  36. }
  37. # -:bbox +:standard
  38. # kilobytes=60 is the minimal allowed size
  39. kilobytes=60
  40. while true; do
  41. test_mke2fs || exit 1
  42. kilobytes=$((kilobytes+1))
  43. test $kilobytes = 200 && break
  44. done
  45. # Transition from one block group to two
  46. # fails in [8378..8410] range unless -O ^resize_inode
  47. kilobytes=$((1 * 8*1024 - 50))
  48. while true; do
  49. test_mke2fs || exit 1
  50. kilobytes=$((kilobytes+1))
  51. test $kilobytes = $((1 * 8*1024 + 300)) && break
  52. done
  53. # Transition from 2 block groups to 3
  54. # works
  55. kilobytes=$((2 * 8*1024 - 50))
  56. while true; do
  57. test_mke2fs || exit 1
  58. kilobytes=$((kilobytes+1))
  59. test $kilobytes = $((2 * 8*1024 + 400)) && break
  60. done
  61. # Transition from 3 block groups to 4
  62. # fails in [24825..24922] range unless -O ^resize_inode
  63. kilobytes=$((3 * 8*1024 - 50))
  64. while true; do
  65. test_mke2fs || exit 1
  66. kilobytes=$((kilobytes+1))
  67. test $kilobytes = $((3 * 8*1024 + 500)) && break
  68. done
  69. # Transition from 4 block groups to 5
  70. # works
  71. kilobytes=$((4 * 8*1024 - 50))
  72. while true; do
  73. test_mke2fs || exit 1
  74. kilobytes=$((kilobytes+1))
  75. test $kilobytes = $((4 * 8*1024 + 600)) && break
  76. done
  77. # Transition from 5 block groups to 6
  78. # fails in [41230..41391] range unless -O ^resize_inode
  79. kilobytes=$((5 * 8*1024 - 50))
  80. while true; do
  81. test_mke2fs || exit 1
  82. kilobytes=$((kilobytes+1))
  83. test $kilobytes = $((5 * 8*1024 + 700)) && break
  84. done
  85. exit
  86. # Random sizes
  87. while true; do
  88. kilobytes=$(( (RANDOM*RANDOM) % 5000000 + 60))
  89. test_mke2fs || exit 1
  90. done