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)
36 static int filter_sd(const char *p)
38 return strlen(p) == 8 && !strncmp(p, "/dev/sd", 7);
41 static struct psensor *
42 create_sensor(char *id, char *name, SkDisk *disk, int values_max_length)
45 s = psensor_create(id,
47 SENSOR_TYPE_HDD_TEMP_ATASMART,
55 static void analyze_disk(const char *dname)
59 log_debug("analyze_disk(hdd_atasmart): %s", dname);
61 f = open(dname, O_RDONLY|O_NOCTTY|O_NONBLOCK|O_CLOEXEC);
66 log_debug("Could not open file %s: %s", dname, strerror(errno));
70 struct psensor **hdd_psensor_list_add(struct psensor **sensors,
71 int values_max_length)
73 char **paths, **tmp, *id;
75 struct psensor *sensor, **tmp_sensors, **result;
77 log_debug("hdd_psensor_list_add(hdd_atasmart)");
79 paths = dir_list("/dev", filter_sd);
84 log_debug("hdd_psensor_list_add(hdd_atasmart) open %s", *tmp);
86 if (!sk_disk_open(*tmp, &disk)) {
87 id = malloc(strlen("hdd at") + strlen(*tmp) + 1);
91 sensor = create_sensor(id,
96 tmp_sensors = psensor_list_add(result, sensor);
98 if (result != sensors)
101 result = tmp_sensors;
103 log_err("sk_disk_open %s failure", *tmp);
115 void hdd_psensor_list_update(struct psensor **sensors)
117 struct psensor **cur, *s;
125 if (s->type == SENSOR_TYPE_HDD_TEMP_ATASMART) {
126 ret = sk_disk_smart_read_data(s->disk);
129 ret = sk_disk_smart_get_temperature(s->disk,
133 c = (kelvin - 273150) / 1000;
134 psensor_set_current_value(s, c);
135 log_debug("hdd_psensor_list_update(hdd_atasmart): %s %.2f",