diff options
-rw-r--r-- | hardinfo/udisks2_util.c | 34 | ||||
-rw-r--r-- | includes/udisks2_util.h | 11 | ||||
-rw-r--r-- | modules/devices/storage.c | 29 |
3 files changed, 69 insertions, 5 deletions
diff --git a/hardinfo/udisks2_util.c b/hardinfo/udisks2_util.c index e3cf255a..83f1abc9 100644 --- a/hardinfo/udisks2_util.c +++ b/hardinfo/udisks2_util.c @@ -474,7 +474,7 @@ gchar* get_udisks2_smart_attributes(udiskd* dsk, const char *drivepath){ GError *error = NULL; const char* aidenf; guint8 aid; - gint16 avalue, aworst, athreshold; + gint16 avalue, aworst, athreshold, pretty_unit; gint64 pretty; udisksa *lastp = NULL, *p; @@ -505,13 +505,43 @@ gchar* get_udisks2_smart_attributes(udiskd* dsk, const char *drivepath){ // id(y), identifier(s), flags(q), value(i), worst(i), threshold(i), // pretty(x), pretty_unit(i), expansion(a{sv}) - while (g_variant_iter_loop (iter, "(ysqiiixia{sv})", &aid, &aidenf, NULL, &avalue, &aworst, &athreshold, NULL, NULL, NULL)){ + // pretty_unit = 0 (unknown), 1 (dimensionless), 2 (milliseconds), 3 (sectors), 4 (millikelvin). + while (g_variant_iter_loop (iter, "(ysqiiixia{sv})", &aid, &aidenf, NULL, &avalue, + &aworst, &athreshold, &pretty, &pretty_unit, NULL)){ p = udisksa_new(); p->id = aid; p->identifier = g_strdup(aidenf); p->value = avalue; p->worst = aworst; p->threshold = athreshold; + switch (pretty_unit){ + case 1: + p->interpreted_unit = UDSK_INTPVAL_DIMENSIONLESS; + p->interpreted = pretty; + break; + case 2: + if (pretty > 1000*60*60){ // > 1h + p->interpreted_unit = UDSK_INTPVAL_HOURS; + p->interpreted = pretty / (1000*60*60); + } + else{ + p->interpreted_unit = UDSK_INTPVAL_MILISECONDS; + p->interpreted = pretty; + } + break; + case 3: + p->interpreted_unit = UDSK_INTPVAL_SECTORS; + p->interpreted = pretty; + break; + case 4: + p->interpreted_unit = UDSK_INTPVAL_CELSIUS; + p->interpreted = (pretty - 273150) / 1000; //mK to °C + break; + default: + p->interpreted_unit = UDSK_INTPVAL_SKIP; + p->interpreted = -1; + break; + } p->next = NULL; if (lastp == NULL) diff --git a/includes/udisks2_util.h b/includes/udisks2_util.h index 8f97f740..a64ca3e2 100644 --- a/includes/udisks2_util.h +++ b/includes/udisks2_util.h @@ -10,12 +10,23 @@ typedef struct udiskp { struct udiskp* next; } udiskp; +enum{ + UDSK_INTPVAL_SKIP = 0, + UDSK_INTPVAL_DIMENSIONLESS = 1, + UDSK_INTPVAL_MILISECONDS = 2, + UDSK_INTPVAL_HOURS = 3, + UDSK_INTPVAL_SECTORS = 4, + UDSK_INTPVAL_CELSIUS = 5, +}; + typedef struct udisksa { guint8 id; gchar *identifier; gint value; gint worst; gint threshold; + gint64 interpreted; + guint8 interpreted_unit; // enum struct udisksa* next; } udisksa; diff --git a/modules/devices/storage.c b/modules/devices/storage.c index d9c8e043..ff1c24de 100644 --- a/modules/devices/storage.c +++ b/modules/devices/storage.c @@ -317,17 +317,40 @@ gboolean __scan_udisks2_devices(void) { if (disk->smart_attributes != NULL) { moreinfo = h_strdup_cprintf(_("[S.M.A.R.T. Attributes]\n" - "Attribute=Normalized Value / Worst / Threshold\n"), + "Attribute=Value / Normalized / Worst / Threshold\n"), moreinfo); attrib = disk->smart_attributes; while (attrib != NULL){ tmp = g_strdup(""); + + switch (attrib->interpreted_unit){ + case UDSK_INTPVAL_SKIP: + tmp = h_strdup_cprintf("-", tmp); + break; + case UDSK_INTPVAL_MILISECONDS: + tmp = h_strdup_cprintf("%ld ms", tmp, attrib->interpreted); + break; + case UDSK_INTPVAL_HOURS: + tmp = h_strdup_cprintf("%ld h", tmp, attrib->interpreted); + break; + case UDSK_INTPVAL_CELSIUS: + tmp = h_strdup_cprintf("%ld°C", tmp, attrib->interpreted); + break; + case UDSK_INTPVAL_SECTORS: + tmp = h_strdup_cprintf(ngettext("%ld sector", "%ld sectors", attrib->interpreted), tmp, attrib->interpreted); + break; + case UDSK_INTPVAL_DIMENSIONLESS: + default: + tmp = h_strdup_cprintf("%ld", tmp, attrib->interpreted); + break; + } + if (attrib->value != -1) - tmp = h_strdup_cprintf("%3d", tmp, attrib->value); + tmp = h_strdup_cprintf(" / %3d", tmp, attrib->value); else - tmp = h_strdup_cprintf("???", tmp); + tmp = h_strdup_cprintf(" / ???", tmp); if (attrib->worst != -1) tmp = h_strdup_cprintf(" / %3d", tmp, attrib->worst); |