summaryrefslogtreecommitdiff
path: root/src/initrd/squashfs-size
diff options
context:
space:
mode:
Diffstat (limited to 'src/initrd/squashfs-size')
-rwxr-xr-xsrc/initrd/squashfs-size88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/initrd/squashfs-size b/src/initrd/squashfs-size
new file mode 100755
index 0000000..74b67d7
--- /dev/null
+++ b/src/initrd/squashfs-size
@@ -0,0 +1,88 @@
1#!/bin/sh
2
3squashfs_size_ratio()
4{
5 local fn="$1"
6 #FSIZE="$(stat -c "%s" "$fn")"
7 word5() { echo $5; }
8 FSIZE="$(word5 `ls -l "$fn"`)"
9 echo $(( $FSIZE * 3367 / 1000 ))
10}
11
12squashfs_size_magicdb()
13{
14
15 get()
16 {
17 local len=$1
18 local off=$2
19 local fn="$3"
20 #local OUT=( $(od -t d$len -N$len -j $off "$fn") )
21 #echo "${OUT[1]}"
22 od -t u$len -N$len -j $off "$fn" | head -n1 | sed 's/.* //'
23 }
24
25# getReversedEndian()
26# {
27# local len=$1
28# local off=$2
29# local fn="$3"
30# #local B=( $(od -t x$len -N$len -j $off "$fn") )
31# #B="${B[1]}"
32# local B="$(od -t x$len -N$len -j $off "$fn" | head -n1 | cut -d' ' -f2)"
33# local D=
34# local C=$(( $len * 2 ))
35# while [ $C -gt 0 ]
36# do
37# C=$(( $C - 2 ))
38# D="$D${B:$C:2}"
39# done
40# D="0x$D"
41# echo $D
42# }
43 getReversedEndian()
44 {
45 local len=$1
46 local off=$2
47 local fn="$3"
48 local D=
49 local C=$len
50 while [ $C -gt 0 ]
51 do
52 C=$(( $C - 1 ))
53 D="$(od -t x1 -N1 -j $(($off+$C)) "$fn" | head -n1 | cut -d' ' -f2)$D"
54 done
55 D=$((0x$D))
56 echo $D
57 }
58
59
60 local fn="$1"
61
62 local M=$(get 4 0 "$fn")
63 local N=$(getReversedEndian 4 0 "$fn")
64 if [ $M -eq 1936814952 ]
65 then
66 # Proper endian.
67 local get=get
68 elif [ $N -eq 1936814952 ]
69 then
70 # Reversed endian.
71 local get=getReversedEndian
72 else
73 error not squashfs
74 fi
75
76 local T=$($get 2 28 "$fn")
77 if [ $T -lt 3 ]
78 then
79 local BC=$($get 4 8 "$fn")
80 else
81 local BC=$($get 8 63 "$fn")
82 fi
83
84 echo $BC
85}
86
87
88squashfs_size_ratio "$1"