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