projects
/
psensor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
avoid specific provider field
[psensor.git]
/
src
/
lib
/
hdd_atasmart.c
diff --git
a/src/lib/hdd_atasmart.c
b/src/lib/hdd_atasmart.c
index
cd8c72b
..
3c23509
100644
(file)
--- a/
src/lib/hdd_atasmart.c
+++ b/
src/lib/hdd_atasmart.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2010-201
2
jeanfi@gmail.com
+ * Copyright (C) 2010-201
4
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
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@
-16,12
+16,16
@@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
+#define _LARGEFILE_SOURCE 1
+#include "config.h"
+
#include <locale.h>
#include <libintl.h>
#define _(str) gettext(str)
#include <errno.h>
#include <fcntl.h>
#include <locale.h>
#include <libintl.h>
#define _(str) gettext(str)
#include <errno.h>
#include <fcntl.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
@@
-32,63
+36,84
@@
#include <atasmart.h>
#include <linux/fs.h>
#include <atasmart.h>
#include <linux/fs.h>
-#include "pio.h"
-#include "hdd.h"
-#include "log.h"
+#include <pio.h>
+#include <hdd.h>
+#include <plog.h>
+
+static const char *PROVIDER_NAME = "atasmart";
static int filter_sd(const char *p)
{
return strlen(p) == 8 && !strncmp(p, "/dev/sd", 7);
}
static int filter_sd(const char *p)
{
return strlen(p) == 8 && !strncmp(p, "/dev/sd", 7);
}
+static void provider_data_free(void *data)
+{
+ sk_disk_free((SkDisk *)data);
+}
+
+static SkDisk *get_disk(struct psensor *s)
+{
+ return (SkDisk *)s->provider_data;
+}
+
static struct psensor *
create_sensor(char *id, char *name, SkDisk *disk, int values_max_length)
{
struct psensor *s;
static struct psensor *
create_sensor(char *id, char *name, SkDisk *disk, int values_max_length)
{
struct psensor *s;
+ int t;
+
+ t = SENSOR_TYPE_ATASMART | SENSOR_TYPE_HDD | SENSOR_TYPE_TEMP;
+
s = psensor_create(id,
strdup(name),
s = psensor_create(id,
strdup(name),
- SENSOR_TYPE_HDD_TEMP_ATASMART,
+ strdup(_("Disk")),
+ t,
values_max_length);
values_max_length);
- s->disk = disk;
+ s->provider_data = disk;
+ s->provider_data_free_fct = &provider_data_free;
return s;
}
return s;
}
+/*
+ * Performs the same tests than sk_disk_open and outputs the result.
+ */
static void analyze_disk(const char *dname)
{
int f;
struct stat st;
uint64_t size;
static void analyze_disk(const char *dname)
{
int f;
struct stat st;
uint64_t size;
- log_
debug("analyze_disk(hdd_atasmart):
%s", dname);
+ log_
fct("Analyze
%s", dname);
f = open(dname, O_RDONLY|O_NOCTTY|O_NONBLOCK|O_CLOEXEC);
if (f < 0) {
f = open(dname, O_RDONLY|O_NOCTTY|O_NONBLOCK|O_CLOEXEC);
if (f < 0) {
- log_
debug
("Could not open file %s: %s", dname, strerror(errno));
+ log_
fct
("Could not open file %s: %s", dname, strerror(errno));
goto fail;
}
if (fstat(f, &st) < 0) {
goto fail;
}
if (fstat(f, &st) < 0) {
- log_
debug
("fstat fails %s: %s", dname, strerror(errno));
+ log_
fct
("fstat fails %s: %s", dname, strerror(errno));
goto fail;
}
if (!S_ISBLK(st.st_mode)) {
goto fail;
}
if (!S_ISBLK(st.st_mode)) {
- log_
debug
("!S_ISBLK fails %s", dname);
+ log_
fct
("!S_ISBLK fails %s", dname);
goto fail;
}
size = (uint64_t)-1;
/* So, it's a block device. Let's make sure the ioctls work */
if (ioctl(f, BLKGETSIZE64, &size) < 0) {
goto fail;
}
size = (uint64_t)-1;
/* So, it's a block device. Let's make sure the ioctls work */
if (ioctl(f, BLKGETSIZE64, &size) < 0) {
- log_
debug
("ioctl fails %s: %s", dname, strerror(errno));
+ log_
fct
("ioctl fails %s: %s", dname, strerror(errno));
goto fail;
}
if (size <= 0 || size == (uint64_t) -1) {
goto fail;
}
if (size <= 0 || size == (uint64_t) -1) {
- log_
debug
("ioctl wrong size %s: %ld", dname, size);
+ log_
fct
("ioctl wrong size %s: %ld", dname, size);
goto fail;
}
goto fail;
}
@@
-96,41
+121,38
@@
static void analyze_disk(const char *dname)
close(f);
}
close(f);
}
-
-struct psensor **hdd_psensor_list_add(struct psensor **sensors,
- int values_max_length)
+void
+atasmart_psensor_list_append(struct psensor ***sensors, int values_max_length)
{
char **paths, **tmp, *id;
SkDisk *disk;
{
char **paths, **tmp, *id;
SkDisk *disk;
- struct psensor *sensor
, **tmp_sensors, **result
;
+ struct psensor *sensor;
- log_
debug("hdd_psensor_list_add(hdd_atasmart)"
);
+ log_
fct_enter(
);
paths = dir_list("/dev", filter_sd);
paths = dir_list("/dev", filter_sd);
- result = sensors;
tmp = paths;
while (*tmp) {
tmp = paths;
while (*tmp) {
- log_
debug("hdd_psensor_list_add(hdd_atasmart) o
pen %s", *tmp);
+ log_
fct("O
pen %s", *tmp);
if (!sk_disk_open(*tmp, &disk)) {
if (!sk_disk_open(*tmp, &disk)) {
- id = malloc(strlen("hdd at") + strlen(*tmp) + 1);
- strcpy(id, "hdd at");
- strcat(id, *tmp);
+ id = malloc(strlen(PROVIDER_NAME)
+ + 1
+ + strlen(*tmp)
+ + 1);
+ sprintf(id, "%s %s", PROVIDER_NAME, *tmp);
sensor = create_sensor(id,
*tmp,
disk,
values_max_length);
sensor = create_sensor(id,
*tmp,
disk,
values_max_length);
- tmp_sensors = psensor_list_add(result, sensor);
-
- if (result != sensors)
- free(result);
-
- result = tmp_sensors;
+ psensor_list_append(sensors, sensor);
} else {
} else {
- log_err("sk_disk_open %s failure", *tmp);
+ log_err(_("%s: sk_disk_open() failure: %s."),
+ PROVIDER_NAME,
+ *tmp);
analyze_disk(*tmp);
}
analyze_disk(*tmp);
}
@@
-139,32
+161,34
@@
struct psensor **hdd_psensor_list_add(struct psensor **sensors,
paths_free(paths);
paths_free(paths);
-
return result
;
+
log_fct_exit()
;
}
}
-void
hdd
_psensor_list_update(struct psensor **sensors)
+void
atasmart
_psensor_list_update(struct psensor **sensors)
{
struct psensor **cur, *s;
uint64_t kelvin;
int ret;
double c;
{
struct psensor **cur, *s;
uint64_t kelvin;
int ret;
double c;
+ SkDisk *disk;
cur = sensors;
while (*cur) {
s = *cur;
cur = sensors;
while (*cur) {
s = *cur;
- if (s->type == SENSOR_TYPE_HDD_TEMP_ATASMART) {
- ret = sk_disk_smart_read_data(s->disk);
+ if (!(s->type & SENSOR_TYPE_REMOTE)
+ && s->type & SENSOR_TYPE_ATASMART) {
+ disk = get_disk(s);
+
+ ret = sk_disk_smart_read_data(disk);
if (!ret) {
if (!ret) {
- ret = sk_disk_smart_get_temperature(
s->
disk,
+ ret = sk_disk_smart_get_temperature(disk,
&kelvin);
if (!ret) {
c = (kelvin - 273150) / 1000;
psensor_set_current_value(s, c);
&kelvin);
if (!ret) {
c = (kelvin - 273150) / 1000;
psensor_set_current_value(s, c);
- log_debug("hdd_psensor_list_update(hdd_atasmart): %s %.2f",
- s->id,
- c);
+ log_fct("%s %.2f", s->id, c);
}
}
}
}
}
}