diff options
author | Simon Rettberg | 2022-07-25 16:43:13 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-07-25 16:43:13 +0200 |
commit | 6a4d33088b57eb58eb5d33f055fac4a8985252cb (patch) | |
tree | 35504e0a2a4caf47dbe0f2bc1af421848fb75a51 | |
parent | [download] Increase default retry timeout, add --slx-time option (diff) | |
download | slx-tools-6a4d33088b57eb58eb5d33f055fac4a8985252cb.tar.gz slx-tools-6a4d33088b57eb58eb5d33f055fac4a8985252cb.tar.xz slx-tools-6a4d33088b57eb58eb5d33f055fac4a8985252cb.zip |
[dev] Add dev_swap_version: Returns version number of a swap partition
-rw-r--r-- | modules/dev.inc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/dev.inc b/modules/dev.inc index ce58075..7c6e1e7 100644 --- a/modules/dev.inc +++ b/modules/dev.inc @@ -183,6 +183,27 @@ dev_get_type() { return 1 } +# Get version of given swap partition. $1 will be checked for the +# swap signature, and if found, the version number will be returned. +# old-style swap will be reported as version 1, +# new-style as 1 + <version_field>. +dev_swap_version() { + local sig version + sig="$( dd if="$1" bs=1 count=10 skip=4086 2> /dev/null )" + if [ "$sig" = "SWAP-SPACE" ]; then + echo 1 + return 0 + elif [ "$sig" = "SWAPSPACE2" ]; then + version="$( __read_le "$1" 1024 4 )" + # I think there is only '1' currently, but try to be clever... + if [ "$version" -gt 0 ] && [ "$version" -lt 8 ]; then + echo $(( 1 + version )) + return 0 + fi + fi + return 1 +} + # stdin = binary data, stdout = raw, unformatted hex # __hex2bin() |