#!/bin/bash
dev_name="$1"
test -z "$dev_name" && exit 2
test -b "/dev/${dev_name}" || exit 2
test -d "/sys/block/${dev_name}" || exit 2
majmin=$(<"/sys/block/${dev_name}/dev")
cryptsetup isLuks "/dev/${dev_name}" ||
exit 1 # not correct with external LUKS header
dmsetup table |
awk -v dev="$majmin" '$4 == "crypt" && $8 == dev { name=$1;sub(":$","",name); print name }'