summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-04-14 05:13:13 +0200
committerLennart Poettering <lennart@poettering.net>2009-04-14 05:13:13 +0200
commit9787a002edbb78fc07b19f2c613afc8f90a26ba3 (patch)
treef848a6bf32864f12d75fd95a8aa29c8d805e099c
parent22c58c34d9b19fcbead4e9b6edfdf7012166a980 (diff)
add new API sk_disk_smart_get_power_cycle()
-rw-r--r--atasmart.c52
-rw-r--r--atasmart.h3
2 files changed, 51 insertions, 4 deletions
diff --git a/atasmart.c b/atasmart.c
index ffc5fab..f1cf4ea 100644
--- a/atasmart.c
+++ b/atasmart.c
@@ -1645,6 +1645,40 @@ int sk_disk_smart_get_power_on(SkDisk *d, uint64_t *mseconds) {
return 0;
}
+static void power_cycle_cb(SkDisk *d, const SkSmartAttributeParsedData *a, struct attr_helper *ah) {
+
+ if (a->pretty_unit != SK_SMART_ATTRIBUTE_UNIT_NONE)
+ return;
+
+ if (!strcmp(a->name, "power-cycle-count")) {
+
+ if (!ah->found || a->pretty_value > *ah->value)
+ *ah->value = a->pretty_value;
+
+ ah->found = TRUE;
+ }
+}
+
+int sk_disk_smart_get_power_cycle(SkDisk *d, uint64_t *count) {
+ struct attr_helper ah;
+
+ assert(d);
+ assert(count);
+
+ ah.found = FALSE;
+ ah.value = count;
+
+ if (sk_disk_smart_parse_attributes(d, (SkSmartAttributeParseCallback) power_cycle_cb, &ah) < 0)
+ return -1;
+
+ if (!ah.found) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ return 0;
+}
+
static void reallocated_cb(SkDisk *d, const SkSmartAttributeParsedData *a, struct attr_helper *ah) {
if (a->pretty_unit != SK_SMART_ATTRIBUTE_UNIT_SECTORS)
@@ -1919,7 +1953,7 @@ int sk_disk_dump(SkDisk *d) {
const SkSmartParsedData *spd;
SkBool good;
char pretty[32];
- uint64_t value;
+ uint64_t value, power_on;
ret = sk_disk_smart_status(d, &good);
printf("SMART Disk Health Good: %s\n",
@@ -1962,10 +1996,20 @@ int sk_disk_dump(SkDisk *d) {
print_value(pretty, sizeof(pretty), value, SK_SMART_ATTRIBUTE_UNIT_SECTORS),
value > 0 ? ENDHIGHLIGHT : "");
- if (sk_disk_smart_get_power_on(d, &value) < 0)
+ if (sk_disk_smart_get_power_on(d, &power_on) < 0) {
printf("Powered On: %s\n", strerror(errno));
- else
- printf("Powered On: %s\n", print_value(pretty, sizeof(pretty), value, SK_SMART_ATTRIBUTE_UNIT_MSECONDS));
+ power_on = 0;
+ } else
+ printf("Powered On: %s\n", print_value(pretty, sizeof(pretty), power_on, SK_SMART_ATTRIBUTE_UNIT_MSECONDS));
+
+ if (sk_disk_smart_get_power_cycle(d, &value) < 0)
+ printf("Power Cycles: %s\n", strerror(errno));
+ else {
+ printf("Power Cycles: %llu\n", (unsigned long long) value);
+
+ if (value > 0 && power_on > 0)
+ printf("Average Powered On Per Power Cycle: %s\n", print_value(pretty, sizeof(pretty), power_on/value, SK_SMART_ATTRIBUTE_UNIT_MSECONDS));
+ }
if (sk_disk_smart_get_temperature(d, &value) < 0)
printf("Temperature: %s\n", strerror(errno));
diff --git a/atasmart.h b/atasmart.h
index 38590ff..747ef01 100644
--- a/atasmart.h
+++ b/atasmart.h
@@ -213,6 +213,9 @@ int sk_disk_smart_self_test(SkDisk *d, SkSmartSelfTest test);
/* High level API to get the power on time */
int sk_disk_smart_get_power_on(SkDisk *d, uint64_t *mseconds);
+/* High level API to get the power cycle count */
+int sk_disk_smart_get_power_cycle(SkDisk *d, uint64_t *count);
+
/* High level API to get the number of bad sectors (i.e. pending and reallocated) */
int sk_disk_smart_get_bad(SkDisk *d, uint64_t *sectors);