functions.sh 931 B

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