| 1 | #!/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="mkfs checksums" |
| 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_MOUNT" |
| 26 | ts_check_test_command "$TS_CMD_UMOUNT" |
| 27 | ts_check_test_command "$TS_CMD_BLKID" |
| 28 | ts_check_test_command "$TS_HELPER_MD5" |
| 29 | ts_check_test_command "$TS_HELPER_SYSINFO" |
| 30 | |
| 31 | ts_skip_nonroot |
| 32 | ts_check_losetup |
| 33 | |
| 34 | ORIGPWD=$(pwd) |
| 35 | IMAGE_NAME="${TS_TESTNAME}-loop.img" |
| 36 | IMAGE_PATH="$TS_OUTDIR/$IMAGE_NAME" |
| 37 | IMAGE_SRC="$TS_OUTDIR/${TS_TESTNAME}-data" |
| 38 | LABEL="testCramfs" |
| 39 | |
| 40 | BYTE_ORDER=$($TS_HELPER_SYSINFO byte-order) |
| 41 | PAGE_SIZE=$($TS_HELPER_SYSINFO pagesize) |
| 42 | case "${BYTE_ORDER}:${PAGE_SIZE}" in |
| 43 | LE:4096) |
| 44 | MD5_EXP="a6667acb1cb0685d9eb5b9cd3724766c" ;; |
| 45 | LE:16384 | LE:65536) |
| 46 | MD5_EXP="b60133682603b0118592b55f1dba017c" ;; |
| 47 | BE:4096) |
| 48 | MD5_EXP="eaf05031dc8ec97c91ba5c773635cc89" ;; |
| 49 | BE:8192 | BE:65536) |
| 50 | MD5_EXP="5859f87b185b1187fca3b2b00c809c03" ;; |
| 51 | *) |
| 52 | echo "warning ${TS_NS}: unknown checksum for ${BYTE_ORDER}:${PAGE_SIZE}" |
| 53 | MD5_EXP="unknown" ;; |
| 54 | esac |
| 55 | |
| 56 | ts_log "create mountpoint dir" |
| 57 | |
| 58 | [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT |
| 59 | |
| 60 | ts_log "generate data" |
| 61 | rm -rf "$IMAGE_SRC" |
| 62 | mkdir -m 755 -p $IMAGE_SRC |
| 63 | |
| 64 | umask 133 |
| 65 | |
| 66 | for d in `seq 0 110`; do |
| 67 | DIRNAME="$IMAGE_SRC/$(printf "dir-%03d" $d)" |
| 68 | mkdir -m 755 $DIRNAME |
| 69 | for f in `seq 0 10`; do |
| 70 | FILENAME="$DIRNAME/$(printf "data.%03d" $f)" |
| 71 | printf "data in %03d-%03d" $d $f >> $FILENAME |
| 72 | done |
| 73 | done |
| 74 | |
| 75 | chgrp -R 0 "$IMAGE_SRC" |
| 76 | |
| 77 | ts_cd "$IMAGE_SRC" |
| 78 | |
| 79 | ts_log "list checksums from original data" |
| 80 | find . -type f -exec md5sum {} \; | sort >> $TS_OUTPUT |
| 81 | echo >> $TS_OUTPUT |
| 82 | |
| 83 | ts_log "create cramfs image" |
| 84 | $TS_CMD_MKCRAMFS -n $LABEL $IMAGE_SRC $IMAGE_PATH >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 85 | [ -s "$IMAGE_PATH" ] || ts_die "Cannot create $IMAGE_PATH" |
| 86 | |
| 87 | ts_cd "$TS_OUTDIR" |
| 88 | |
| 89 | ts_log "count MD5 from the image" |
| 90 | MD5_OUT=$("$TS_HELPER_MD5" < "$IMAGE_NAME") >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 91 | if [ "$MD5_EXP" != "$MD5_OUT" -a "$MD5_EXP" != "unknown" ]; then |
| 92 | ts_log "is $MD5_OUT, should be $MD5_EXP" |
| 93 | fi |
| 94 | echo >> $TS_OUTPUT |
| 95 | |
| 96 | ts_log "create loop device from image" |
| 97 | DEVICE=$($TS_CMD_LOSETUP --show -f $IMAGE_PATH) |
| 98 | ts_register_loop_device "$DEVICE" |
| 99 | |
| 100 | ts_log "check the image" |
| 101 | ts_device_has "TYPE" "cramfs" $DEVICE |
| 102 | [ "$?" == "0" ] || ts_die "Cannot find cramfs on $DEVICE" |
| 103 | |
| 104 | ts_log "mount the image" |
| 105 | ts_mount "cramfs" -r -L $LABEL $TS_MOUNTPOINT |
| 106 | |
| 107 | # check it |
| 108 | ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts" |
| 109 | |
| 110 | ts_cd "$TS_MOUNTPOINT" |
| 111 | |
| 112 | ts_log "list the image" |
| 113 | export TZ='GMT-1' |
| 114 | ls -laR --time-style=long-iso . | sed 's:\. : :g' >> $TS_OUTPUT |
| 115 | echo >> $TS_OUTPUT |
| 116 | |
| 117 | ts_log "list checksums from new data" |
| 118 | find . -type f -exec md5sum {} \; | sort >> $TS_OUTPUT |
| 119 | echo >> $TS_OUTPUT |
| 120 | |
| 121 | ts_cd "$ORIGPWD" |
| 122 | |
| 123 | ts_log "umount the image" |
| 124 | ts_finalize |
| 125 |