diff --git a/driveAtlas.sh b/driveAtlas.sh index a950193..37fd8b4 100644 --- a/driveAtlas.sh +++ b/driveAtlas.sh @@ -520,12 +520,29 @@ declare -A CHASSIS_TYPES=( # Core Functions #------------------------------------------------------------------------------ +# Cache for lspci output (populated on first call) +LSPCI_CACHE="" + +#------------------------------------------------------------------------------ +# get_storage_controllers +# +# Returns a formatted list of storage controllers found via lspci. +# Uses cached output if available to avoid redundant lspci calls. +# +# Output Format: " PCI_ADDR: DESCRIPTION" (one per line) +#------------------------------------------------------------------------------ get_storage_controllers() { - # Returns a formatted list of storage controllers (HBAs, SATA, NVMe) - lspci 2>/dev/null | grep -iE "SAS|SATA|RAID|Mass storage|NVMe" | while read -r line; do - pci_addr=$(echo "$line" | awk '{print $1}') + # Cache lspci output on first call + if [[ -z "$LSPCI_CACHE" ]]; then + LSPCI_CACHE="$(lspci 2>/dev/null | grep -iE "SAS|SATA|RAID|Mass storage|NVMe")" + fi + + # Format and return cached output + echo "$LSPCI_CACHE" | while read -r line; do + [[ -z "$line" ]] && continue + pci_addr="$(echo "$line" | awk '{print $1}')" # Get short description (strip PCI address) - desc=$(echo "$line" | sed 's/^[0-9a-f:.]\+ //') + desc="$(echo "$line" | sed 's/^[0-9a-f:.]\+ //')" echo " $pci_addr: $desc" done }