diff --git a/driveAtlas.sh b/driveAtlas.sh index 3f7be16..1742343 100644 --- a/driveAtlas.sh +++ b/driveAtlas.sh @@ -243,28 +243,33 @@ get_storage_controllers() { done } +#------------------------------------------------------------------------------ +# build_drive_map +# +# Builds a global associative array mapping physical bay numbers to device names. +# Uses PCI paths from SERVER_MAPPINGS to resolve current device assignments. +# +# Sets: DRIVE_MAP (global associative array) +# Keys: Bay identifiers (1, 2, ..., m2-1, m2-2, etc.) +# Values: Device names (sda, nvme0n1, etc.) +#------------------------------------------------------------------------------ build_drive_map() { - local host=$(hostname) - declare -A drive_map + local host="$(hostname)" + local mapping="${SERVER_MAPPINGS[$host]}" - local mapping=${SERVER_MAPPINGS[$host]} + # Declare global array directly instead of copying from local + declare -g -A DRIVE_MAP=() if [[ -n "$mapping" ]]; then while read -r path slot; do [[ -z "$path" || -z "$slot" ]] && continue if [[ -L "/dev/disk/by-path/$path" ]]; then - local drive=$(readlink -f "/dev/disk/by-path/$path" | sed 's/.*\///') - drive_map[$slot]=$drive + local drive="$(readlink -f "/dev/disk/by-path/$path" | sed 's/.*\///')" + DRIVE_MAP[$slot]="$drive" fi done <<< "$mapping" fi - - # Make drive_map available globally - declare -g -A DRIVE_MAP=() - for key in "${!drive_map[@]}"; do - DRIVE_MAP[$key]=${drive_map[$key]} - done } get_drive_smart_info() {