X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fhdd_atasmart.c;h=cb5200f66f9a651bac152d9e8934dc840d061590;hb=e98cd07e815b1fd4c2772c42f046ad26d64988ac;hp=592fcbd60a3d72635cca01ad658a7c0f8c2d7978;hpb=6259a669b55df9a091cb490c34f9d800e2b92443;p=psensor.git diff --git a/src/lib/hdd_atasmart.c b/src/lib/hdd_atasmart.c index 592fcbd..cb5200f 100644 --- a/src/lib/hdd_atasmart.c +++ b/src/lib/hdd_atasmart.c @@ -21,18 +21,67 @@ #define _(str) gettext(str) #include +#include + #include +#include "pio.h" #include "hdd.h" #include "log.h" +static int filter_sd(const char *p) +{ + return strlen(p) == 8 && !strncmp(p, "/dev/sd", 7); +} + +static struct psensor * +create_sensor(char *id, char *name, int values_max_length) +{ + return psensor_create(id, + strdup(name), + SENSOR_TYPE_HDD_TEMP, + values_max_length); +} + struct psensor **hdd_psensor_list_add(struct psensor **sensors, int values_max_length) { + char **paths, **tmp; + SkDisk *disk; + struct psensor *sensor, **tmp_sensors, **result; log_debug("hdd_psensor_list_add"); - return sensors; + paths = dir_list("/dev", filter_sd); + + result = sensors; + tmp = paths; + while (*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); + strcpy(id, "hdd at"); + strcat(id, *tmp); + + sensor = create_sensor(id, *tmp, values_max_length); + + tmp_sensors = psensor_list_add(result, sensor); + + if (result != sensors) + free(result); + + result = tmp_sensors; + } else { + log_err("Failed to open %s", *tmp); + } + + tmp++; + } + + paths_free(paths); + + return result; } void hdd_psensor_list_update(struct psensor **sensors)