From a98bca79e95e4218c6b2bf3e2b2590746f5a606d Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 22 Mar 2020 19:16:51 +0000 Subject: [PATCH] bin/check-blkdev-size: Add script for checking suspicious block devices. I've had this lying around for a while. --- Makefile | 1 + bin/check-blkdev-size | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 bin/check-blkdev-size diff --git a/Makefile b/Makefile index 3b1d788..b32be23 100644 --- a/Makefile +++ b/Makefile @@ -225,6 +225,7 @@ SCRIPTLINKS += guest-console SCRIPTLINKS += hyperspec SCRIPTLINKS += datasyms SCRIPTLINKS += check-debsyms +SCRIPTLINKS += check-blkdev-size ## Random odds and ends. DOTLINKS += .infokey .sqliterc diff --git a/bin/check-blkdev-size b/bin/check-blkdev-size new file mode 100755 index 0000000..0f68a53 --- /dev/null +++ b/bin/check-blkdev-size @@ -0,0 +1,35 @@ +#! /bin/bash + +set -e -o pipefail + +case $# in 1) ;; *) echo >&2 "usage: $0 DEV"; exit 127 ;; esac +dev=$1 + +typeset -i sz; sz=$(blockdev --getsize64 "$dev") +k=$(gorp -fhex 256) + +## Figure out a useful block size. +typeset -i bsz=1 nb=$sz +for i in 2 3 5 7; do + while :; do + case $((nb%i)) in + 0) bsz=$((bsz*i)) nb=$((nb/i)) ;; + *) break ;; + esac + if (( bsz >= 65536 )); then break 2; fi + done +done +echo >&2 "$0: using $nb blocks of size $bsz" + +## Write the initial stream. +echo >&2 "$0: writing pseudorandom pattern..." +rspit salsa20/8 -H$k -z$sz -pT | \ + dd status=none iflag=fullblock oflag=direct bs=$bsz count=$nb of="$dev" +echo >&2 "$0: writing pseudorandom pattern... done" + +## Read the stream back, and check against the reference. +echo >&2 "$0: checking pseudorandom pattern..." +cmp <(rspit salsa20/8 -H$k -z$sz -pT) \ + <(dd status=none iflag=direct bs=$bsz count=$nb if="$dev") +echo >&2 "$0: checking pseudorandom pattern... done" +echo >&2 "$0: all ok" -- 2.11.0