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)"
|
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
|
# 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_SIZE=()
|
||||||
declare -A LSBLK_MOUNTS=()
|
declare -A LSBLK_MOUNTS=()
|
||||||
log_info "Caching block device information..."
|
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
|
[[ -z "$name" ]] && continue
|
||||||
LSBLK_SIZE[$name]="$size"
|
LSBLK_SIZE["$name"]="$size"
|
||||||
# Accumulate mount points for parent device
|
done < <(lsblk -dn -o NAME,SIZE 2>/dev/null)
|
||||||
parent="${name%%[0-9]}" # Strip partition number
|
|
||||||
if [[ -n "$mounts" ]]; then
|
# Get mount points (including partitions) and map back to parent device
|
||||||
if [[ -n "${LSBLK_MOUNTS[$parent]}" ]]; then
|
while read -r name mounts; do
|
||||||
LSBLK_MOUNTS[$parent]+=",${mounts}"
|
[[ -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
|
else
|
||||||
LSBLK_MOUNTS[$parent]="$mounts"
|
parent="$name"
|
||||||
fi
|
fi
|
||||||
|
if [[ -n "${LSBLK_MOUNTS[$parent]:-}" ]]; then
|
||||||
|
LSBLK_MOUNTS["$parent"]+=",${mounts}"
|
||||||
|
else
|
||||||
|
LSBLK_MOUNTS["$parent"]="$mounts"
|
||||||
fi
|
fi
|
||||||
done < <(lsblk -rn -o NAME,SIZE,MOUNTPOINT 2>/dev/null)
|
done < <(lsblk -rn -o NAME,MOUNTPOINT 2>/dev/null | grep -v '^ ')
|
||||||
|
|
||||||
# Parallel SMART data collection for faster execution
|
# Parallel SMART data collection for faster execution
|
||||||
# Collect SMART data in background jobs, store in temp files
|
# Collect SMART data in background jobs, store in temp files
|
||||||
|
|||||||
Reference in New Issue
Block a user