From 3423bbc17f5521de8ff80e76d91ce13657b1cea2 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Thu, 8 Apr 2021 01:36:49 +0800 Subject: [PATCH] kdump-lib.sh: introduce a helper to get underlying crypt device Signed-off-by: Kairui Song Acked-by: Pingfan Liu --- kdump-lib.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kdump-lib.sh b/kdump-lib.sh index 4dcd134..ecb2721 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -958,3 +958,20 @@ kdump_get_arch_recommend_size() echo $result return 0 } + +# Print all underlying crypt devices of a block device +# print nothing if device is not on top of a crypt device +# $1: the block device to be checked in maj:min format +get_luks_crypt_dev() +{ + [[ -b /dev/block/$1 ]] || return 1 + + local _type=$(eval "$(blkid -u filesystem,crypto -o export -- /dev/block/$1); echo \$TYPE") + [[ $_type == "crypto_LUKS" ]] && echo $1 + + for _x in /sys/dev/block/$1/slaves/*; do + [[ -f $_x/dev ]] || continue + [[ $_x/subsystem -ef /sys/class/block ]] || continue + get_luks_crypt_dev "$(< "$_x/dev")" + done +}