work on libata support
[psensor.git] / src / lib / hdd_atasmart.c
1 /*
2  * Copyright (C) 2010-2011 jeanfi@gmail.com
3  *
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.
8  *
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.
13  *
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
17  * 02110-1301 USA
18  */
19 #include <locale.h>
20 #include <libintl.h>
21 #define _(str) gettext(str)
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <atasmart.h>
27
28 #include "pio.h"
29 #include "hdd.h"
30 #include "log.h"
31
32 static int filter_sd(const char *p)
33 {
34         return strlen(p) == 8 && !strncmp(p, "/dev/sd", 7);
35 }
36
37 static struct psensor *
38 create_sensor(char *id, char *name, int values_max_length)
39 {
40         return psensor_create(id,
41                               strdup(name),
42                               SENSOR_TYPE_HDD_TEMP,
43                               values_max_length);
44 }
45
46 struct psensor **hdd_psensor_list_add(struct psensor **sensors,
47                                       int values_max_length)
48 {
49         char **paths, **tmp;
50         SkDisk *disk;
51         struct psensor *sensor, **tmp_sensors, **result;
52
53         log_debug("hdd_psensor_list_add");
54
55         paths = dir_list("/dev", filter_sd);
56
57         result = sensors;
58         tmp = paths;
59         while (*tmp) {
60                 log_debug("hdd_psensor_list_add open %s", tmp);
61
62                 if (!sk_disk_open(*tmp, &disk)) {
63                         char *id = malloc(strlen("hdd at") + strlen(*tmp) + 1);
64                         strcpy(id, "hdd at");
65                         strcat(id, *tmp);
66
67                         sensor = create_sensor(id, *tmp, values_max_length);
68
69                         tmp_sensors = psensor_list_add(result, sensor);
70
71                         if (result != sensors)
72                                 free(result);
73
74                         result = tmp_sensors;
75                 } else {
76                         log_err("Failed to open %s", *tmp);
77                 }
78
79                 tmp++;
80         }
81
82         paths_free(paths);
83
84         return result;
85 }
86
87 void hdd_psensor_list_update(struct psensor **sensors)
88 {
89 }