From 00cd931fad5000091dcf06f7cef81504233082b8 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Tue, 4 Oct 2016 23:55:39 +0200 Subject: [PATCH] Add partial support for SCSI smart attributes SCSI disks report information in a different way. --- cmdline/device.c | 12 ++++++------ cmdline/portable.h | 10 ++++++++++ cmdline/support.c | 24 +++++++++++++++++------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/cmdline/device.c b/cmdline/device.c index a421cea2..4279e63c 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -656,15 +656,15 @@ static void state_smart(unsigned n, tommy_list* low) double afr; uint64_t flag; - if (devinfo->smart[194] != SMART_UNASSIGNED) - printf("%7" PRIu64, devinfo->smart[194] & mask16); - else if (devinfo->smart[190] != SMART_UNASSIGNED) - printf("%7" PRIu64, devinfo->smart[190] & mask16); + if (devinfo->smart[SMART_TEMPERATURE_CELSIUS] != SMART_UNASSIGNED) + printf("%7" PRIu64, devinfo->smart[SMART_TEMPERATURE_CELSIUS] & mask16); + else if (devinfo->smart[SMART_AIRFLOW_TEMPERATURE_CELSIUS] != SMART_UNASSIGNED) + printf("%7" PRIu64, devinfo->smart[SMART_AIRFLOW_TEMPERATURE_CELSIUS] & mask16); else printf(" -"); - if (devinfo->smart[9] != SMART_UNASSIGNED) - printf("%7" PRIu64, (devinfo->smart[9] & mask32) / 24); + if (devinfo->smart[SMART_POWER_ON_HOURS] != SMART_UNASSIGNED) + printf("%7" PRIu64, (devinfo->smart[SMART_POWER_ON_HOURS] & mask32) / 24); else printf(" -"); diff --git a/cmdline/portable.h b/cmdline/portable.h index f2cc0011..f98d58a2 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -400,6 +400,16 @@ int exit_sync_needed; */ int randomize(void* ptr, size_t size); +/** + * Standard SMART attributes. + */ +#define SMART_START_STOP_COUNT 4 +#define SMART_REALLOCATED_SECTOR_COUNT 5 +#define SMART_POWER_ON_HOURS 9 +#define SMART_AIRFLOW_TEMPERATURE_CELSIUS 190 +#define SMART_LOAD_CYCLE_COUNT 193 +#define SMART_TEMPERATURE_CELSIUS 194 + /** * Additional SMART attributes. */ diff --git a/cmdline/support.c b/cmdline/support.c index 22fdd7ab..51d79b4b 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -1382,13 +1382,7 @@ int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* sm if (*s == 0) { inside = 0; - } else if (smatch(s, "ID#") == 0) { - inside = 1; - } else if (smatch(s, "No Errors Logged") == 0) { - smart[SMART_ERROR] = 0; - } else if (sscanf(s, "ATA Error Count: %" SCNu64, &raw) == 1) { - smart[SMART_ERROR] = raw; - } else if (sscanf(s, "Serial Number: %63s", serial) == 1) { + /* common */ } else if (smatch(s, "Rotation Rate: Solid State") == 0) { smart[SMART_ROTATION_RATE] = 0; } else if (sscanf(s, "Rotation Rate: %" SCNu64, &smart[SMART_ROTATION_RATE]) == 1) { @@ -1400,6 +1394,22 @@ int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* sm smart[SMART_SIZE] += attr[i] - '0'; } } + /* SCSI */ + } else if (sscanf(s, "Serial number: %63s", serial) == 1) { /* note "n" of "number" lower case */ + } else if (sscanf(s, "Elements in grown defect list: %" SCNu64, &smart[SMART_REALLOCATED_SECTOR_COUNT]) == 1) { + } else if (sscanf(s, "Current Drive Temperature: %" SCNu64, &smart[SMART_TEMPERATURE_CELSIUS]) == 1) { + } else if (sscanf(s, "Drive Trip Temperature: %" SCNu64, &smart[SMART_AIRFLOW_TEMPERATURE_CELSIUS]) == 1) { + } else if (sscanf(s, "Accumulated start-stop cycles: %" SCNu64, &smart[SMART_START_STOP_COUNT]) == 1) { + } else if (sscanf(s, "Accumulated load-unload cycles: %" SCNu64, &smart[SMART_LOAD_CYCLE_COUNT]) == 1) { + } else if (sscanf(s, " number of hours powered up = %" SCNu64, &smart[SMART_POWER_ON_HOURS]) == 1) { + /* ATA */ + } else if (sscanf(s, "Serial Number: %63s", serial) == 1) { + } else if (smatch(s, "ID#") == 0) { + inside = 1; + } else if (smatch(s, "No Errors Logged") == 0) { + smart[SMART_ERROR] = 0; + } else if (sscanf(s, "ATA Error Count: %" SCNu64, &raw) == 1) { + smart[SMART_ERROR] = raw; } else if (inside) { if (sscanf(s, "%u %*s %*s %*s %*s %*s %*s %*s %*s %" SCNu64, &id, &raw) != 2) { /* LCOV_EXCL_START */