From 58897b1f3a76262a49eed3f7b0f418a4bb3df943 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Thu, 5 Feb 2026 19:54:41 -0500 Subject: [PATCH] Fix lsblk caching to properly parse SIZE and MOUNTPOINT Split lsblk queries into two separate calls: 1. lsblk -dn for disk sizes (whole disk only, simpler parsing) 2. lsblk -rn for mount points (handles partition-to-parent mapping) This fixes issues where: - SIZE was empty due to delimiter confusion - Mount points with spaces caused parsing errors Co-Authored-By: Claude Opus 4.5 --- driveAtlas.sh | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/driveAtlas.sh b/driveAtlas.sh index 06ac9bd..9d9ed12 100644 --- a/driveAtlas.sh +++ b/driveAtlas.sh @@ -919,23 +919,34 @@ done all_bays="$(printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^[0-9]+$' | sort -n; printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^m2-' | sort)" # Cache lsblk data to reduce redundant calls -# Single call gets all info we need: size and mount points +# Get device sizes (whole disk only) declare -A LSBLK_SIZE=() declare -A LSBLK_MOUNTS=() log_info "Caching block device information..." -while IFS='|' read -r name size mounts; do + +# Get sizes for whole disks only +while read -r name size; do [[ -z "$name" ]] && continue - LSBLK_SIZE[$name]="$size" - # Accumulate mount points for parent device - parent="${name%%[0-9]}" # Strip partition number - if [[ -n "$mounts" ]]; then - if [[ -n "${LSBLK_MOUNTS[$parent]}" ]]; then - LSBLK_MOUNTS[$parent]+=",${mounts}" - else - LSBLK_MOUNTS[$parent]="$mounts" - fi + LSBLK_SIZE["$name"]="$size" +done < <(lsblk -dn -o NAME,SIZE 2>/dev/null) + +# Get mount points (including partitions) and map back to parent device +while read -r name mounts; do + [[ -z "$name" || -z "$mounts" ]] && continue + # Strip partition suffix (sda1 -> sda, nvme0n1p1 -> nvme0n1) + if [[ "$name" =~ ^(nvme[0-9]+n[0-9]+)p[0-9]+$ ]]; then + parent="${BASH_REMATCH[1]}" + elif [[ "$name" =~ ^([a-z]+)[0-9]+$ ]]; then + parent="${BASH_REMATCH[1]}" + else + parent="$name" fi -done < <(lsblk -rn -o NAME,SIZE,MOUNTPOINT 2>/dev/null) + if [[ -n "${LSBLK_MOUNTS[$parent]:-}" ]]; then + LSBLK_MOUNTS["$parent"]+=",${mounts}" + else + LSBLK_MOUNTS["$parent"]="$mounts" + fi +done < <(lsblk -rn -o NAME,MOUNTPOINT 2>/dev/null | grep -v '^ ') # Parallel SMART data collection for faster execution # Collect SMART data in background jobs, store in temp files