bin/wakey.zsh: Quote arguments to `notify-send' for other shells.
[profile] / bin / check-blkdev-size
1 #! /bin/bash
2
3 set -e -o pipefail
4
5 case $# in 1) ;; *) echo >&2 "usage: $0 DEV"; exit 127 ;; esac
6 dev=$1
7
8 typeset -i sz; sz=$(blockdev --getsize64 "$dev")
9 k=$(gorp -fhex 256)
10
11 ## Figure out a useful block size.
12 typeset -i bsz=1 nb=$sz
13 for i in 2 3 5 7; do
14 while :; do
15 case $((nb%i)) in
16 0) bsz=$((bsz*i)) nb=$((nb/i)) ;;
17 *) break ;;
18 esac
19 if (( bsz >= 65536 )); then break 2; fi
20 done
21 done
22 echo >&2 "$0: using $nb blocks of size $bsz"
23
24 ## Write the initial stream.
25 echo >&2 "$0: writing pseudorandom pattern..."
26 rspit salsa20/8 -H$k -z$sz -pT | \
27 dd status=none iflag=fullblock oflag=direct bs=$bsz count=$nb of="$dev"
28 echo >&2 "$0: writing pseudorandom pattern... done"
29
30 ## Read the stream back, and check against the reference.
31 echo >&2 "$0: checking pseudorandom pattern..."
32 cmp <(rspit salsa20/8 -H$k -z$sz -pT) \
33 <(dd status=none iflag=direct bs=$bsz count=$nb if="$dev")
34 echo >&2 "$0: checking pseudorandom pattern... done"
35 echo >&2 "$0: all ok"