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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user