| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | # |
| 4 | # Copyright (C) 2007 Karel Zak <[email protected]> |
| 5 | # |
| 6 | # This file is part of util-linux. |
| 7 | # |
| 8 | # This file is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # This file is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | TS_TOPDIR="${0%/*}/../.." |
| 19 | TS_DESC="fsck bad header" |
| 20 | |
| 21 | . "$TS_TOPDIR"/functions.sh |
| 22 | ts_init "$*" |
| 23 | |
| 24 | ts_check_test_command "$TS_CMD_MKCRAMFS" |
| 25 | ts_check_test_command "$TS_CMD_FSCKCRAMFS" |
| 26 | ts_check_prog "dd" |
| 27 | |
| 28 | function num2binaryscip-shell shell util-linux 2.42.2-1 num2binary().() |
| 29 | { |
| 30 | local num=$1 |
| 31 | local endian=$2 |
| 32 | |
| 33 | testscip-shell system . . test. "$num" -ge 0 -a "$num" -le 4294967295 || return 1 |
| 34 | testscip-shell system . . test. "$endian" = "be" -o "$endian" = "le" || return 1 |
| 35 | |
| 36 | # how to do that easier? |
| 37 | if testscip-shell system . . test. "$endian" = "be"; then |
| 38 | echoscip-shell system . . echo. -en "$(printfscip-shell system . . printf. "%08x" "$1" | sedscip-shell system . . sed. 's/\(..\)/\\x\1/g')" |
| 39 | else |
| 40 | echoscip-shell system . . echo. -en "$(printfscip-shell system . . printf. "%08x" "$1" | sedscip-shell system . . sed. 's/^\(..\)\(..\)\(..\)\(..\)$/\\x\4\\x\3\\x\2\\x\1/')" |
| 41 | fi |
| 42 | } |
| 43 | |
| 44 | function fsck_loop_sizesscip-shell shell util-linux 2.42.2-1 fsck_loop_sizes().() |
| 45 | { |
| 46 | local endian=$1 # be, le |
| 47 | local seek=$2 # 4 for nopad, 516 for pad |
| 48 | shift 2 # the rest are sizes to loop over |
| 49 | |
| 50 | for size in "$@"; do |
| 51 | ts_log_both "## size: $size" |
| 52 | cpscip-shell system . . cp. -a "$IMAGE_FILE" "$IMAGE_FILE.tmp" |
| 53 | num2binaryscip-shell shell util-linux 2.42.2-1 num2binary(). "$size" $endian | |
| 54 | ddscip-shell system . . dd. of="$IMAGE_FILE.tmp" bs=1 seek="$seek" count=4 conv=notrunc &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 55 | $TS_CMD_FSCKCRAMFS "$IMAGE_FILE.tmp" >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 56 | ts_log "ret: $? |
| 57 | " |
| 58 | done |
| 59 | rmscip-shell system . . rm. -f "$IMAGE_FILE" |
| 60 | } |
| 61 | |
| 62 | |
| 63 | IMAGE_SOURCE="$TS_OUTDIR/${TS_TESTNAME}-data" |
| 64 | IMAGE_FILE="$TS_OUTDIR/${TS_TESTNAME}-cramfs.img" |
| 65 | |
| 66 | mkdirscip-shell system . . mkdir. -p "${IMAGE_SOURCE}/subdir" &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 67 | |
| 68 | ts_init_subtest "nopad-4K-be" |
| 69 | $TS_CMD_MKCRAMFS -N big -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 70 | fsck_loop_sizesscip-shell shell util-linux 2.42.2-1 fsck_loop_sizes(). be 4 0 75 76 4095 4096 4097 4294967295 |
| 71 | rmscip-shell system . . rm. -f "$IMAGE_FILE" |
| 72 | ts_finalize_subtest |
| 73 | |
| 74 | ts_init_subtest "nopad-4K-le" |
| 75 | $TS_CMD_MKCRAMFS -N little -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 76 | fsck_loop_sizesscip-shell shell util-linux 2.42.2-1 fsck_loop_sizes(). le 4 0 75 76 4095 4096 4097 4294967295 |
| 77 | ts_finalize_subtest |
| 78 | |
| 79 | ts_init_subtest "pad-4K-be" |
| 80 | $TS_CMD_MKCRAMFS -p -N big -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 81 | fsck_loop_sizesscip-shell shell util-linux 2.42.2-1 fsck_loop_sizes(). be 516 76 587 588 4095 4096 4097 4294967295 |
| 82 | ts_finalize_subtest |
| 83 | |
| 84 | ts_init_subtest "pad-4K-le" |
| 85 | $TS_CMD_MKCRAMFS -p -N little -b 4096 $IMAGE_SOURCE $IMAGE_FILE &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 86 | fsck_loop_sizesscip-shell shell util-linux 2.42.2-1 fsck_loop_sizes(). le 516 76 587 588 4095 4096 4097 4294967295 |
| 87 | ts_finalize_subtest |
| 88 | |
| 89 | ts_init_subtest "pad-64K-be" |
| 90 | $TS_CMD_MKCRAMFS -p -N big -b 65536 $IMAGE_SOURCE $IMAGE_FILE &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 91 | fsck_loop_sizesscip-shell shell util-linux 2.42.2-1 fsck_loop_sizes(). be 516 76 587 588 65535 65536 65537 4294967295 |
| 92 | ts_finalize_subtest |
| 93 | |
| 94 | ts_init_subtest "pad-64K-le" |
| 95 | $TS_CMD_MKCRAMFS -p -N little -b 65536 $IMAGE_SOURCE $IMAGE_FILE &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 96 | fsck_loop_sizesscip-shell shell util-linux 2.42.2-1 fsck_loop_sizes(). le 516 76 587 588 65535 65536 65537 4294967295 |
| 97 | ts_finalize_subtest |
| 98 | |
| 99 | rmscip-shell system . . rm. -rf "$IMAGE_SOURCE" "$IMAGE_FILE.tmp" |
| 100 | |
| 101 | ts_finalize |
| 102 |