From 8387b514f133d5450e72f58866222d313201a64b Mon Sep 17 00:00:00 2001 From: Kairui Song Date: May 20 2021 08:08:05 +0000 Subject: kdump-lib.sh: introduce a helper to get all crypt dev used by kdump Resolves: bz1951415 Upstream: fedora Conflict: None commit 1c70cf51c7678499e2d48eec10ad24b839fe9f64 Author: Kairui Song Date: Tue May 18 16:13:16 2021 +0800 kdump-lib.sh: introduce a helper to get all crypt dev used by kdump Signed-off-by: Kairui Song Acked-by: Pingfan Liu Signed-off-by: Kairui Song --- diff --git a/kdump-lib.sh b/kdump-lib.sh index cd1e392..1c68e6a 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -956,3 +956,24 @@ get_luks_crypt_dev() get_luks_crypt_dev "$(< "$_x/dev")" done } + +# kdump_get_maj_min +# Prints the major and minor of a device node. +# Example: +# $ get_maj_min /dev/sda2 +# 8:2 +kdump_get_maj_min() { + local _majmin + _majmin="$(stat -L -c '%t:%T' "$1" 2> /dev/null)" + printf "%s" "$((0x${_majmin%:*})):$((0x${_majmin#*:}))" +} + +get_all_kdump_crypt_dev() +{ + local _dev _crypt + + for _dev in $(get_block_dump_target); do + _crypt=$(get_luks_crypt_dev $(kdump_get_maj_min "$_dev")) + [[ -n "$_crypt" ]] && echo $_crypt + done +}