diff --git a/lib/Module.mk b/lib/Module.mk index 14b220c9..abfd3d69 100644 --- a/lib/Module.mk +++ b/lib/Module.mk @@ -46,8 +46,7 @@ LIBTARGETS := $(MODULE_DIR)/$(LIBSTLIBNAME) $(MODULE_DIR)/$(LIBSHLIBNAME) \ $(MODULE_DIR)/$(LIBSHSONAME) $(MODULE_DIR)/$(LIBSHBASENAME) LIBCSOURCES := $(MODULE_DIR)/data.c $(MODULE_DIR)/general.c \ - $(MODULE_DIR)/error.c \ - $(MODULE_DIR)/proc.c $(MODULE_DIR)/access.c \ + $(MODULE_DIR)/error.c $(MODULE_DIR)/access.c \ $(MODULE_DIR)/init.c $(MODULE_DIR)/sysfs.c LIBOTHEROBJECTS := $(MODULE_DIR)/conf-parse.o $(MODULE_DIR)/conf-lex.o diff --git a/lib/access.c b/lib/access.c index f9a8eb9e..32a820b2 100644 --- a/lib/access.c +++ b/lib/access.c @@ -24,7 +24,7 @@ #include "sensors.h" #include "data.h" #include "error.h" -#include "proc.h" +#include "sysfs.h" #include "general.h" static int sensors_eval_expr(sensors_chip_name chipname, @@ -258,7 +258,7 @@ int sensors_get_feature(sensors_chip_name name, int feature, double *result) expr = chip->computes[i].from_proc; } } - if (sensors_read_proc(name, feature, &val)) + if (sensors_read_sysfs_attr(name, feature, &val)) return -SENSORS_ERR_PROC; if (!expr) *result = val; @@ -306,7 +306,7 @@ int sensors_set_feature(sensors_chip_name name, int feature, double value) if (expr) if ((res = sensors_eval_expr(name, expr, value, &to_write))) return res; - if (sensors_write_proc(name, feature, to_write)) + if (sensors_write_sysfs_attr(name, feature, to_write)) return -SENSORS_ERR_PROC; return 0; } diff --git a/lib/proc.c b/lib/proc.c deleted file mode 100644 index 6edcb00f..00000000 --- a/lib/proc.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - proc.c - Part of libsensors, a Linux library for reading sensor data. - Copyright (c) 1998, 1999 Frodo Looijaard - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include -#include -#include -#include - -#include "data.h" -#include "error.h" -#include "access.h" -#include "proc.h" - -/* This reads a feature from a sysfs file. - Sysfs uses a one-value-per file system... -*/ -int sensors_read_proc(sensors_chip_name name, int feature, double *value) -{ - const sensors_chip_feature *the_feature; - int mag; - char n[NAME_MAX]; - FILE *f; - int dummy; - char check; - const char *suffix = ""; - - if (!(the_feature = sensors_lookup_feature_nr(&name, feature))) - return -SENSORS_ERR_NO_ENTRY; - - /* REVISIT: this is a ugly hack */ - if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1 - || sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1 - || sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1) - suffix = "_input"; - - snprintf(n, NAME_MAX, "%s/%s%s", name.busname, the_feature->data.name, - suffix); - if ((f = fopen(n, "r"))) { - int res = fscanf(f, "%lf", value); - fclose(f); - if (res != 1) - return -SENSORS_ERR_PROC; - for (mag = the_feature->scaling; mag > 0; mag --) - *value /= 10.0; - } else - return -SENSORS_ERR_PROC; - - return 0; -} - -int sensors_write_proc(sensors_chip_name name, int feature, double value) -{ - const sensors_chip_feature *the_feature; - int mag; - char n[NAME_MAX]; - FILE *f; - int dummy; - char check; - const char *suffix = ""; - - if (!(the_feature = sensors_lookup_feature_nr(&name, feature))) - return -SENSORS_ERR_NO_ENTRY; - - /* REVISIT: this is a ugly hack */ - if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1 - || sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1 - || sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1) - suffix = "_input"; - - snprintf(n, NAME_MAX, "%s/%s%s", name.busname, the_feature->data.name, - suffix); - if ((f = fopen(n, "w"))) { - for (mag = the_feature->scaling; mag > 0; mag --) - value *= 10.0; - fprintf(f, "%d", (int) value); - fclose(f); - } else - return -SENSORS_ERR_PROC; - - return 0; -} diff --git a/lib/proc.h b/lib/proc.h deleted file mode 100644 index d4283ad5..00000000 --- a/lib/proc.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - proc.h - Part of libsensors, a Linux library for reading sensor data. - Copyright (c) 1998, 1999 Frodo Looijaard - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef SENSORS_LIB_PROC_H -#define SENSORS_LIB_PROC_H - -/* Read a value out of a /proc file */ -extern int sensors_read_proc(sensors_chip_name name, int feature, - double *value); - -/* Write a value to a /proc file */ -extern int sensors_write_proc(sensors_chip_name name, int feature, - double value); - -#endif diff --git a/lib/sysfs.c b/lib/sysfs.c index c63cb75d..afcdc5e9 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -393,3 +393,68 @@ exit0: return ret; } +int sensors_read_sysfs_attr(sensors_chip_name name, int feature, double *value) +{ + const sensors_chip_feature *the_feature; + int mag; + char n[NAME_MAX]; + FILE *f; + int dummy; + char check; + const char *suffix = ""; + + if (!(the_feature = sensors_lookup_feature_nr(&name, feature))) + return -SENSORS_ERR_NO_ENTRY; + + /* REVISIT: this is a ugly hack */ + if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1 + || sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1 + || sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1) + suffix = "_input"; + + snprintf(n, NAME_MAX, "%s/%s%s", name.busname, the_feature->data.name, + suffix); + if ((f = fopen(n, "r"))) { + int res = fscanf(f, "%lf", value); + fclose(f); + if (res != 1) + return -SENSORS_ERR_PROC; + for (mag = the_feature->scaling; mag > 0; mag --) + *value /= 10.0; + } else + return -SENSORS_ERR_PROC; + + return 0; +} + +int sensors_write_sysfs_attr(sensors_chip_name name, int feature, double value) +{ + const sensors_chip_feature *the_feature; + int mag; + char n[NAME_MAX]; + FILE *f; + int dummy; + char check; + const char *suffix = ""; + + if (!(the_feature = sensors_lookup_feature_nr(&name, feature))) + return -SENSORS_ERR_NO_ENTRY; + + /* REVISIT: this is a ugly hack */ + if (sscanf(the_feature->data.name, "in%d%c", &dummy, &check) == 1 + || sscanf(the_feature->data.name, "fan%d%c", &dummy, &check) == 1 + || sscanf(the_feature->data.name, "temp%d%c", &dummy, &check) == 1) + suffix = "_input"; + + snprintf(n, NAME_MAX, "%s/%s%s", name.busname, the_feature->data.name, + suffix); + if ((f = fopen(n, "w"))) { + for (mag = the_feature->scaling; mag > 0; mag --) + value *= 10.0; + fprintf(f, "%d", (int) value); + fclose(f); + } else + return -SENSORS_ERR_PROC; + + return 0; +} diff --git a/lib/sysfs.h b/lib/sysfs.h index 77df571a..d9660dc3 100644 --- a/lib/sysfs.h +++ b/lib/sysfs.h @@ -28,4 +28,10 @@ extern int sensors_read_sysfs_chips(void); extern int sensors_read_sysfs_bus(void); +/* Read a value out of a sysfs attribute file */ +int sensors_read_sysfs_attr(sensors_chip_name name, int feature, double *value); + +/* Write a value to a sysfs attribute file */ +int sensors_write_sysfs_attr(sensors_chip_name name, int feature, double value); + #endif /* !SENSORS_LIB_SYSFS_H */