diff options
Diffstat (limited to 'modules')
-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() |