2 * Copyright (C) 2010-2012 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #define _(str) gettext(str)
32 static int filter_sd(const char *p)
34 return strlen(p) == 8 && !strncmp(p, "/dev/sd", 7);
37 static struct psensor *
38 create_sensor(char *id, char *name, SkDisk *disk, int values_max_length)
41 s = psensor_create(id,
43 SENSOR_TYPE_HDD_TEMP_ATASMART,
51 struct psensor **hdd_psensor_list_add(struct psensor **sensors,
52 int values_max_length)
54 char **paths, **tmp, *id;
56 struct psensor *sensor, **tmp_sensors, **result;
58 log_debug("hdd_psensor_list_add");
60 paths = dir_list("/dev", filter_sd);
65 log_debug("hdd_psensor_list_add open %s", *tmp);
67 if (!sk_disk_open(*tmp, &disk)) {
68 id = malloc(strlen("hdd at") + strlen(*tmp) + 1);
72 sensor = create_sensor(id,
77 tmp_sensors = psensor_list_add(result, sensor);
79 if (result != sensors)
84 log_err("Failed to open %s", *tmp);
95 void hdd_psensor_list_update(struct psensor **sensors)
97 struct psensor **cur, *s;
105 if (s->type == SENSOR_TYPE_HDD_TEMP_ATASMART) {
106 ret = sk_disk_smart_read_data(s->disk);
109 ret = sk_disk_smart_get_temperature(s->disk,
113 c = (kelvin - 273150) / 1000;
114 psensor_set_current_value(s, c);
115 log_debug("hdd atasmart: %s %.2f",