From 484e761dab70e30bc3b922d9fd9c29e7a2afc557 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sat, 6 Jun 2020 09:01:15 +0200 Subject: [PATCH] src/tools/disks/smart.rs: try to get correct wearout for ATA devices --- src/tools/disks/smart.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/tools/disks/smart.rs b/src/tools/disks/smart.rs index 5092e7ac..7a6da303 100644 --- a/src/tools/disks/smart.rs +++ b/src/tools/disks/smart.rs @@ -102,6 +102,7 @@ pub fn get_smart_data( // ATA devices if let Some(list) = output["ata_smart_attributes"]["table"].as_array() { + let wearout_id = lookup_vendor_wearout_id(disk); for item in list { let id = match item["id"].as_u64() { Some(id) => id, @@ -138,6 +139,10 @@ pub fn get_smart_data( None => continue, // skip attributes without threshold entry }; + if id == wearout_id { + wearout = Some(normalized); + } + attributes.push(SmartAttribute { name, value: raw_value, @@ -184,3 +189,34 @@ pub fn get_smart_data( Ok(SmartData { status, wearout, attributes }) } + +fn lookup_vendor_wearout_id(disk: &super::Disk) -> u64 { + + static VENDOR_MAP: &[(&str, u64)] = &[ + ("kingston", 231), + ("samsung", 177), + ("intel", 233), + ("sandisk", 233), + ("crucial", 202), + ]; + + let result = 233; // default + let model = match disk.model() { + Some(model) => { + if let Some(model) = model.to_str() { + model.to_lowercase() + } else { + return result; + } + } + None => return result, + }; + + for (vendor, attr_id) in VENDOR_MAP { + if model.contains(vendor) { + return *attr_id; + } + } + + result +}