VerityBook/squashfs-size.sh

41 lines
795 B
Bash
Raw Permalink Normal View History

2018-09-11 11:37:47 +02:00
#!/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)
# super block is 96 bytes
# pad to 4096
echo $(((size+96+4095)/4096*4096))
2018-09-11 11:37:47 +02:00
}
squashfs_size