blob: ec0618c2728881860354d52081c7bfc49be8ccfd [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2
3
4get_magic_word() {
5 dd if=$1 bs=4 count=1 2>/dev/null | od -A n -N 4 -t x1 | tr -d ' '
6}
7
8get_post_padding_word() {
9 local rootfs_length="$(stat -c%s "$1")"
10 [ "$rootfs_length" -ge 4 ] || return
11 rootfs_length=$((rootfs_length-4))
12
13 # the JFFS2 end marker must be on a 4K boundary (often 64K or 256K)
14 local unaligned_bytes=$((rootfs_length%4096))
15 [ "$unaligned_bytes" = 0 ] || return
16
17 # skip rootfs data except the potential EOF marker
18 dd if="$1" bs=1 skip="$rootfs_length" 2>/dev/null | od -A n -N 4 -t x1 | tr -d ' '
19}
20
21get_fs_type() {
22 local magic_word="$(get_magic_word "$1")"
23
24 case "$magic_word" in
25 "3118"*)
26 echo "ubifs"
27 ;;
28 "68737173")
29 local post_padding_word="$(get_post_padding_word "$1")"
30
31 case "$post_padding_word" in
32 "deadc0de")
33 echo "squashfs-jffs2"
34 ;;
35 *)
36 echo "squashfs"
37 ;;
38 esac
39 ;;
40 *)
41 echo "unknown"
42 ;;
43 esac
44}
45
46round_up() {
47 echo "$(((($1 + ($2 - 1))/ $2) * $2))"
48}