mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-21 11:39:31 +00:00
Move sensors_proc_read and sensors_proc_write to sysfs.c, and rename them
to something more in line with what they do. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4553 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
7cb36ef6d2
commit
7a2ab38ecf
6 files changed
+75
-133
No files matched your search
+1
-2
@@ -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
|
||||
|
||||
+3
-3
@@ -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;
|
||||
}
|
||||
|
||||
-97
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
proc.c - Part of libsensors, a Linux library for reading sensor data.
|
||||
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
||||
|
||||
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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
proc.h - Part of libsensors, a Linux library for reading sensor data.
|
||||
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
|
||||
|
||||
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
|
||||
+65
@@ -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;
|
||||
}
|
||||
@@ -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 */
|
||||
Reference in new issue
Block a user