X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fhdd_atasmart.c;h=d7b2351c4bd927a94233b4649e47e794f7b90685;hb=2b51051578ef29b031d0927388c4d62baa3c525e;hp=cb5200f66f9a651bac152d9e8934dc840d061590;hpb=e98cd07e815b1fd4c2772c42f046ad26d64988ac;p=psensor.git diff --git a/src/lib/hdd_atasmart.c b/src/lib/hdd_atasmart.c index cb5200f..d7b2351 100644 --- a/src/lib/hdd_atasmart.c +++ b/src/lib/hdd_atasmart.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 jeanfi@gmail.com + * Copyright (C) 2010-2012 jeanfi@gmail.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -35,18 +35,23 @@ static int filter_sd(const char *p) } static struct psensor * -create_sensor(char *id, char *name, int values_max_length) +create_sensor(char *id, char *name, SkDisk *disk, int values_max_length) { - return psensor_create(id, - strdup(name), - SENSOR_TYPE_HDD_TEMP, - values_max_length); + struct psensor *s; + s = psensor_create(id, + strdup(name), + SENSOR_TYPE_HDD_TEMP_ATASMART, + values_max_length); + + s->disk = disk; + + return s; } struct psensor **hdd_psensor_list_add(struct psensor **sensors, int values_max_length) { - char **paths, **tmp; + char **paths, **tmp, *id; SkDisk *disk; struct psensor *sensor, **tmp_sensors, **result; @@ -57,14 +62,17 @@ struct psensor **hdd_psensor_list_add(struct psensor **sensors, result = sensors; tmp = paths; while (*tmp) { - log_debug("hdd_psensor_list_add open %s", tmp); + log_debug("hdd_psensor_list_add open %s", *tmp); if (!sk_disk_open(*tmp, &disk)) { - char *id = malloc(strlen("hdd at") + strlen(*tmp) + 1); + id = malloc(strlen("hdd at") + strlen(*tmp) + 1); strcpy(id, "hdd at"); strcat(id, *tmp); - sensor = create_sensor(id, *tmp, values_max_length); + sensor = create_sensor(id, + *tmp, + disk, + values_max_length); tmp_sensors = psensor_list_add(result, sensor); @@ -86,4 +94,31 @@ struct psensor **hdd_psensor_list_add(struct psensor **sensors, void hdd_psensor_list_update(struct psensor **sensors) { + struct psensor **cur, *s; + uint64_t kelvin; + int ret; + double c; + + cur = sensors; + while (*cur) { + s = *cur; + if (s->type == SENSOR_TYPE_HDD_TEMP_ATASMART) { + ret = sk_disk_smart_read_data(s->disk); + + if (!ret) { + ret = sk_disk_smart_get_temperature(s->disk, + &kelvin); + + if (!ret) { + c = (kelvin - 273150) / 1000; + psensor_set_current_value(s, c); + log_debug("hdd atasmart: %s %.2f", + s->id, + c); + } + } + } + + cur++; + } }