VerityBook/squashfs-size.sh
Harald Hoyer 0e17648dc5 update
2018-09-11 11:37:59 +02:00

39 lines
744 B
Bash
Executable file

#!/bin/bash
getbyte () {
local IFS= LC_CTYPE=C res c
read -r -n 1 -d '' c
res=$?
# the single quote in the argument of the printf
# yields the numeric value of $c (ASCII since LC_CTYPE=C)
[[ -n $c ]] && c=$(printf '%u' "'$c") || c=0
printf "$c"
return $res
}
getword () {
local b1 b2 val
b1=$(getbyte) || return 1
b2=$(getbyte) || return 1
(( val = b2 * 256 + b1 ))
echo $val
return 0
}
getuint () {
local b1 b2 val
b1=$(getword) || return 1
b2=$(getword) || return 1
(( val = b2 * 256 * 256 + b1 ))
echo $val
return 0
}
squashfs_size() {
size=$(for i in {1..20}; do getword >/dev/null; done; getuint)
echo $(((size+4095)/4096*4096))
}
squashfs_size