mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-27 20:48:22 +00:00
Update the comments and symbols in the whole library code to refer to
features and subfeatures as appropriate. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4836 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
9fe2b3c714
commit
e13c11d353
9 files changed
+128
-119
No files matched your search
+44
-41
@@ -86,20 +86,21 @@ sensors_for_all_config_chips(const sensors_chip_name *name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Look up a resource in the intern chip list, and return a pointer to it.
|
||||
/* Look up a subfeature in the intern chip list, and return a pointer to it.
|
||||
Do not modify the struct the return value points to! Returns NULL if
|
||||
not found.*/
|
||||
const sensors_subfeature *sensors_lookup_feature_nr(const sensors_chip_name *chip,
|
||||
int feature)
|
||||
const sensors_subfeature *
|
||||
sensors_lookup_subfeature_nr(const sensors_chip_name *chip,
|
||||
int subfeat_nr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sensors_proc_chips_count; i++)
|
||||
if (sensors_match_chip(&sensors_proc_chips[i].chip, chip)) {
|
||||
if (feature < 0 ||
|
||||
feature >= sensors_proc_chips[i].subfeature_count)
|
||||
if (subfeat_nr < 0 ||
|
||||
subfeat_nr >= sensors_proc_chips[i].subfeature_count)
|
||||
return NULL;
|
||||
return sensors_proc_chips[i].subfeature + feature;
|
||||
return sensors_proc_chips[i].subfeature + subfeat_nr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -108,7 +109,8 @@ const sensors_subfeature *sensors_lookup_feature_nr(const sensors_chip_name *chi
|
||||
Do not modify the struct the return value points to! Returns NULL if
|
||||
not found.*/
|
||||
static const sensors_subfeature *
|
||||
sensors_lookup_feature_name(const sensors_chip_name *chip, const char *feature)
|
||||
sensors_lookup_subfeature_name(const sensors_chip_name *chip,
|
||||
const char *name)
|
||||
{
|
||||
int i, j;
|
||||
const sensors_subfeature *subfeatures;
|
||||
@@ -117,7 +119,7 @@ sensors_lookup_feature_name(const sensors_chip_name *chip, const char *feature)
|
||||
if (sensors_match_chip(&sensors_proc_chips[i].chip, chip)) {
|
||||
subfeatures = sensors_proc_chips[i].subfeature;
|
||||
for (j = 0; j < sensors_proc_chips[i].subfeature_count; j++)
|
||||
if (!strcmp(subfeatures[j].name, feature))
|
||||
if (!strcmp(subfeatures[j].name, name))
|
||||
return subfeatures + j;
|
||||
}
|
||||
return NULL;
|
||||
@@ -137,7 +139,7 @@ int sensors_chip_name_has_wildcards(const sensors_chip_name *chip)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Look up the label which belongs to this chip. Note that chip should not
|
||||
/* Look up the label for a given feature. Note that chip should not
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself. */
|
||||
@@ -199,13 +201,13 @@ static int sensors_get_ignored(const sensors_chip_name *name,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Read the value of a feature of a certain chip. Note that chip should not
|
||||
/* Read the value of a subfeature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0
|
||||
on failure. */
|
||||
int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
int sensors_get_value(const sensors_chip_name *name, int subfeat_nr,
|
||||
double *result)
|
||||
{
|
||||
const sensors_subfeature *main_feature;
|
||||
const sensors_subfeature *subfeature;
|
||||
const sensors_subfeature *alt_feature;
|
||||
const sensors_chip *chip;
|
||||
const sensors_expr *expr = NULL;
|
||||
@@ -215,21 +217,21 @@ int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
|
||||
if (sensors_chip_name_has_wildcards(name))
|
||||
return -SENSORS_ERR_WILDCARDS;
|
||||
if (!(main_feature = sensors_lookup_feature_nr(name, feature)))
|
||||
if (!(subfeature = sensors_lookup_subfeature_nr(name, subfeat_nr)))
|
||||
return -SENSORS_ERR_NO_ENTRY;
|
||||
|
||||
if (main_feature->flags & SENSORS_COMPUTE_MAPPING)
|
||||
alt_feature = sensors_lookup_feature_nr(name,
|
||||
main_feature->mapping);
|
||||
if (subfeature->flags & SENSORS_COMPUTE_MAPPING)
|
||||
alt_feature = sensors_lookup_subfeature_nr(name,
|
||||
subfeature->mapping);
|
||||
else
|
||||
alt_feature = NULL;
|
||||
|
||||
if (!(main_feature->flags & SENSORS_MODE_R))
|
||||
if (!(subfeature->flags & SENSORS_MODE_R))
|
||||
return -SENSORS_ERR_ACCESS_R;
|
||||
for (chip = NULL;
|
||||
!expr && (chip = sensors_for_all_config_chips(name, chip));)
|
||||
for (i = 0; !final_expr && (i < chip->computes_count); i++) {
|
||||
if (!strcmp(main_feature->name, chip->computes[i].name)) {
|
||||
if (!strcmp(subfeature->name, chip->computes[i].name)) {
|
||||
expr = chip->computes[i].from_proc;
|
||||
final_expr = 1;
|
||||
} else if (alt_feature && !strcmp(alt_feature->name,
|
||||
@@ -237,7 +239,7 @@ int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
expr = chip->computes[i].from_proc;
|
||||
}
|
||||
}
|
||||
if (sensors_read_sysfs_attr(name, feature, &val))
|
||||
if (sensors_read_sysfs_attr(name, subfeat_nr, &val))
|
||||
return -SENSORS_ERR_PROC;
|
||||
if (!expr)
|
||||
*result = val;
|
||||
@@ -246,13 +248,13 @@ int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Set the value of a feature of a certain chip. Note that chip should not
|
||||
/* Set the value of a subfeature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0
|
||||
on failure. */
|
||||
int sensors_set_value(const sensors_chip_name *name, int feature,
|
||||
int sensors_set_value(const sensors_chip_name *name, int subfeat_nr,
|
||||
double value)
|
||||
{
|
||||
const sensors_subfeature *main_feature;
|
||||
const sensors_subfeature *subfeature;
|
||||
const sensors_subfeature *alt_feature;
|
||||
const sensors_chip *chip;
|
||||
const sensors_expr *expr = NULL;
|
||||
@@ -262,21 +264,21 @@ int sensors_set_value(const sensors_chip_name *name, int feature,
|
||||
|
||||
if (sensors_chip_name_has_wildcards(name))
|
||||
return -SENSORS_ERR_WILDCARDS;
|
||||
if (!(main_feature = sensors_lookup_feature_nr(name, feature)))
|
||||
if (!(subfeature = sensors_lookup_subfeature_nr(name, subfeat_nr)))
|
||||
return -SENSORS_ERR_NO_ENTRY;
|
||||
|
||||
if (main_feature->flags & SENSORS_COMPUTE_MAPPING)
|
||||
alt_feature = sensors_lookup_feature_nr(name,
|
||||
main_feature->mapping);
|
||||
if (subfeature->flags & SENSORS_COMPUTE_MAPPING)
|
||||
alt_feature = sensors_lookup_subfeature_nr(name,
|
||||
subfeature->mapping);
|
||||
else
|
||||
alt_feature = NULL;
|
||||
|
||||
if (!(main_feature->flags & SENSORS_MODE_W))
|
||||
if (!(subfeature->flags & SENSORS_MODE_W))
|
||||
return -SENSORS_ERR_ACCESS_W;
|
||||
for (chip = NULL;
|
||||
!expr && (chip = sensors_for_all_config_chips(name, chip));)
|
||||
for (i = 0; !final_expr && (i < chip->computes_count); i++)
|
||||
if (!strcmp(main_feature->name, chip->computes[i].name)) {
|
||||
if (!strcmp(subfeature->name, chip->computes[i].name)) {
|
||||
expr = chip->computes->to_proc;
|
||||
final_expr = 1;
|
||||
} else if (alt_feature && !strcmp(alt_feature->name,
|
||||
@@ -288,7 +290,7 @@ int sensors_set_value(const sensors_chip_name *name, int feature,
|
||||
if (expr)
|
||||
if ((res = sensors_eval_expr(name, expr, value, &to_write)))
|
||||
return res;
|
||||
if (sensors_write_sysfs_attr(name, feature, to_write))
|
||||
if (sensors_write_sysfs_attr(name, subfeat_nr, to_write))
|
||||
return -SENSORS_ERR_PROC;
|
||||
return 0;
|
||||
}
|
||||
@@ -380,7 +382,7 @@ int sensors_eval_expr(const sensors_chip_name *name,
|
||||
{
|
||||
double res1, res2;
|
||||
int res;
|
||||
const sensors_subfeature *feature;
|
||||
const sensors_subfeature *subfeature;
|
||||
|
||||
if (expr->kind == sensors_kind_val) {
|
||||
*result = expr->data.val;
|
||||
@@ -391,10 +393,11 @@ int sensors_eval_expr(const sensors_chip_name *name,
|
||||
return 0;
|
||||
}
|
||||
if (expr->kind == sensors_kind_var) {
|
||||
if (!(feature = sensors_lookup_feature_name(name,
|
||||
if (!(subfeature = sensors_lookup_subfeature_name(name,
|
||||
expr->data.var)))
|
||||
return SENSORS_ERR_NO_ENTRY;
|
||||
if (!(res = sensors_get_value(name, feature->number, result)))
|
||||
if (!(res = sensors_get_value(name, subfeature->number,
|
||||
result)))
|
||||
return res;
|
||||
return 0;
|
||||
}
|
||||
@@ -442,31 +445,31 @@ static int sensors_do_this_chip_sets(const sensors_chip_name *name)
|
||||
double value;
|
||||
int i, j;
|
||||
int err = 0, res;
|
||||
const sensors_subfeature *feature;
|
||||
const sensors_subfeature *subfeature;
|
||||
int *feature_list = NULL;
|
||||
int feature_count = 0;
|
||||
int feature_max = 0;
|
||||
int feature_nr;
|
||||
int subfeat_nr;
|
||||
|
||||
for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));)
|
||||
for (i = 0; i < chip->sets_count; i++) {
|
||||
feature = sensors_lookup_feature_name(name,
|
||||
subfeature = sensors_lookup_subfeature_name(name,
|
||||
chip->sets[i].name);
|
||||
if (!feature) {
|
||||
if (!subfeature) {
|
||||
sensors_parse_error("Unknown feature name",
|
||||
chip->sets[i].lineno);
|
||||
err = SENSORS_ERR_NO_ENTRY;
|
||||
continue;
|
||||
}
|
||||
feature_nr = feature->number;
|
||||
subfeat_nr = subfeature->number;
|
||||
|
||||
/* Check whether we already set this feature */
|
||||
for (j = 0; j < feature_count; j++)
|
||||
if (feature_list[j] == feature_nr)
|
||||
if (feature_list[j] == subfeat_nr)
|
||||
break;
|
||||
if (j != feature_count)
|
||||
continue;
|
||||
sensors_add_array_el(&feature_nr, &feature_list,
|
||||
sensors_add_array_el(&subfeat_nr, &feature_list,
|
||||
&feature_count, &feature_max,
|
||||
sizeof(int));
|
||||
|
||||
@@ -478,8 +481,8 @@ static int sensors_do_this_chip_sets(const sensors_chip_name *name)
|
||||
err = res;
|
||||
continue;
|
||||
}
|
||||
if ((res = sensors_set_value(name, feature_nr, value))) {
|
||||
sensors_parse_error("Failed to set feature",
|
||||
if ((res = sensors_set_value(name, subfeat_nr, value))) {
|
||||
sensors_parse_error("Failed to set value",
|
||||
chip->sets[i].lineno);
|
||||
err = res;
|
||||
continue;
|
||||
|
||||
+4
-3
@@ -23,11 +23,12 @@
|
||||
#include "sensors.h"
|
||||
#include "data.h"
|
||||
|
||||
/* Look up a resource in the intern chip list, and return a pointer to it.
|
||||
/* Look up a subfeature in the intern chip list, and return a pointer to it.
|
||||
Do not modify the struct the return value points to! Returns NULL if
|
||||
not found. */
|
||||
const sensors_subfeature *sensors_lookup_feature_nr(const sensors_chip_name *chip,
|
||||
int feature);
|
||||
const sensors_subfeature *
|
||||
sensors_lookup_subfeature_nr(const sensors_chip_name *chip,
|
||||
int subfeat_nr);
|
||||
|
||||
/* Check whether the chip name is an 'absolute' name, which can only match
|
||||
one chip, or whether it has wildcards. Returns 0 if it is absolute, 1
|
||||
|
||||
+3
-2
@@ -65,7 +65,8 @@ typedef struct sensors_label {
|
||||
int lineno;
|
||||
} sensors_label;
|
||||
|
||||
/* Config file set declaration: a feature name, combined with an expression */
|
||||
/* Config file set declaration: a subfeature name, combined with an
|
||||
expression */
|
||||
typedef struct sensors_set {
|
||||
char *name;
|
||||
sensors_expr *value;
|
||||
@@ -120,7 +121,7 @@ typedef struct sensors_bus {
|
||||
int lineno;
|
||||
} sensors_bus;
|
||||
|
||||
/* Internal data about all features of a type of chip */
|
||||
/* Internal data about all features and subfeatures of a chip */
|
||||
typedef struct sensors_chip_features {
|
||||
struct sensors_chip_name chip;
|
||||
struct sensors_feature *feature;
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ void (*sensors_fatal_error) (const char *proc, const char *err) =
|
||||
static const char *errorlist[] = {
|
||||
/* Unknown error */ "sensors_strerror: Unknown error!",
|
||||
/* SENSORS_ERR_WILDCARDS */ "Wildcard found in chip name",
|
||||
/* SENSORS_ERR_NO_ENTRY */ "No such feature known",
|
||||
/* SENSORS_ERR_NO_ENTRY */ "No such subfeature known",
|
||||
/* SENSORS_ERR_ACCESS */ "Can't read or write",
|
||||
/* SENSORS_ERR_PROC */ "Can't access sysfs file",
|
||||
/* SENSORS_ERR_DIV_ZERO */ "Divide by zero",
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
#define LIB_SENSORS_ERROR_H
|
||||
|
||||
#define SENSORS_ERR_WILDCARDS 1 /* Wildcard found in chip name */
|
||||
#define SENSORS_ERR_NO_ENTRY 2 /* No such feature known */
|
||||
#define SENSORS_ERR_NO_ENTRY 2 /* No such subfeature known */
|
||||
#define SENSORS_ERR_ACCESS 3 /* Can't read or write */
|
||||
#define SENSORS_ERR_PROC 4 /* Can't access /proc file */
|
||||
#define SENSORS_ERR_DIV_ZERO 5 /* Divide by zero */
|
||||
|
||||
+10
-8
@@ -37,9 +37,9 @@ libsensors \- publicly accessible functions provided by the sensors library
|
||||
\fBsensors_chip_name *res);\fP
|
||||
.B const char *sensors_get_adapter_name(int bus_nr);
|
||||
.B char *sensors_get_label(const sensors_chip_name *name, const sensors_feature *feature);\fP
|
||||
.B int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
.B int sensors_get_value(const sensors_chip_name *name, int subfeat_nr,
|
||||
\fBdouble *value);\fP
|
||||
.B int sensors_set_value(const sensors_chip_name *name, int feature,
|
||||
.B int sensors_set_value(const sensors_chip_name *name, int subfeat_nr,
|
||||
\fBdouble value);\fP
|
||||
.B int sensors_do_chip_sets(const sensors_chip_name *name);
|
||||
.B const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
|
||||
@@ -78,15 +78,17 @@ contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself.
|
||||
|
||||
\fBint sensors_get_value(const sensors_chip_name *name,
|
||||
int feature, double *value);\fP
|
||||
\fBint sensors_get_value(const sensors_chip_name *name, int subfeat_nr, double *value);\fP
|
||||
.br
|
||||
Read the value of a feature of a certain chip. Note that chip should not contain wildcard values! This function will return 0 on success, and <0 on failure.
|
||||
Read the value of a subfeature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0 on
|
||||
failure.
|
||||
|
||||
\fBint sensors_set_value(const sensors_chip_name *name,
|
||||
int feature, double value);\fP
|
||||
\fBint sensors_set_value(const sensors_chip_name *name, int subfeat_nr, double value);\fP
|
||||
.br
|
||||
Set the value of a feature of a certain chip. Note that chip should not contain wildcard values! This function will return 0 on success, and <0 on failure.
|
||||
Set the value of a subfeature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0 on
|
||||
failure.
|
||||
|
||||
.B int sensors_do_chip_sets(const sensors_chip_name *name);
|
||||
.br
|
||||
|
||||
+8
-8
@@ -84,23 +84,23 @@ const char *sensors_get_adapter_name(const sensors_bus_id *bus);
|
||||
|
||||
typedef struct sensors_feature sensors_feature;
|
||||
|
||||
/* Look up the label which belongs to this chip. Note that chip should not
|
||||
/* Look up the label for a given feature. Note that chip should not
|
||||
contain wildcard values! The returned string is newly allocated (free it
|
||||
yourself). On failure, NULL is returned.
|
||||
If no label exists for this feature, its name is returned itself. */
|
||||
char *sensors_get_label(const sensors_chip_name *name,
|
||||
const sensors_feature *feature);
|
||||
|
||||
/* Read the value of a feature of a certain chip. Note that chip should not
|
||||
/* Read the value of a subfeature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0
|
||||
on failure. */
|
||||
int sensors_get_value(const sensors_chip_name *name, int feature,
|
||||
int sensors_get_value(const sensors_chip_name *name, int subfeat_nr,
|
||||
double *value);
|
||||
|
||||
/* Set the value of a feature of a certain chip. Note that chip should not
|
||||
/* Set the value of a subfeature of a certain chip. Note that chip should not
|
||||
contain wildcard values! This function will return 0 on success, and <0
|
||||
on failure. */
|
||||
int sensors_set_value(const sensors_chip_name *name, int feature,
|
||||
int sensors_set_value(const sensors_chip_name *name, int subfeat_nr,
|
||||
double value);
|
||||
|
||||
/* Execute all set statements for this particular chip. The chip may contain
|
||||
@@ -126,8 +126,8 @@ const sensors_chip_name *sensors_get_detected_chips(const sensors_chip_name
|
||||
|
||||
/* This enum contains some "magic" used by sensors_read_dynamic_chip() from
|
||||
lib/sysfs.c. All the sensor types (in, fan, temp, vid) are a multiple of
|
||||
0x100 apart, and sensor features which should not have a compute mapping to
|
||||
the _input feature start at 0x?10. */
|
||||
0x100 apart, and sensor subfeatures which should not have a compute
|
||||
mapping to the _input subfeature start at 0x?10. */
|
||||
typedef enum sensors_feature_type {
|
||||
SENSORS_FEATURE_IN = 0x000,
|
||||
SENSORS_FEATURE_IN_MIN,
|
||||
@@ -176,7 +176,7 @@ struct sensors_feature {
|
||||
/* Data about a single chip subfeature:
|
||||
name is the string name used to refer to this subfeature (in config files)
|
||||
number is the internal subfeature number, used in many functions to refer
|
||||
to this feature
|
||||
to this subfeature
|
||||
type is the subfeature type
|
||||
mapping is either SENSORS_NO_MAPPING if this subfeature is the
|
||||
main element of category; or it is the number of a subfeature with which
|
||||
|
||||
+55
-53
@@ -38,10 +38,11 @@
|
||||
char sensors_sysfs_mount[NAME_MAX];
|
||||
|
||||
#define MAX_SENSORS_PER_TYPE 20
|
||||
#define MAX_SUB_FEATURES 8
|
||||
#define MAX_SUBFEATURES 8
|
||||
/* Room for all 3 types (in, fan, temp) with all their subfeatures + VID
|
||||
+ misc features */
|
||||
#define ALL_POSSIBLE_FEATURES (MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6 \
|
||||
#define ALL_POSSIBLE_SUBFEATURES \
|
||||
(MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 6 \
|
||||
+ MAX_SENSORS_PER_TYPE + 1)
|
||||
|
||||
static
|
||||
@@ -64,7 +65,7 @@ int get_type_scaling(int type)
|
||||
}
|
||||
}
|
||||
|
||||
/* Static mappings for use by sensors_feature_get_type() */
|
||||
/* Static mappings for use by sensors_subfeature_get_type() */
|
||||
struct feature_subtype_match
|
||||
{
|
||||
const char *name;
|
||||
@@ -125,9 +126,10 @@ static struct feature_type_match matches[] = {
|
||||
{ "cpu%d%c", cpu_matches },
|
||||
};
|
||||
|
||||
/* Return the feature type and channel number based on the feature name */
|
||||
/* Return the subfeature type and channel number based on the subfeature
|
||||
name */
|
||||
static
|
||||
sensors_feature_type sensors_feature_get_type(const char *name, int *nr)
|
||||
sensors_feature_type sensors_subfeature_get_type(const char *name, int *nr)
|
||||
{
|
||||
char c;
|
||||
int i, count;
|
||||
@@ -161,7 +163,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
int i, type, fnum = 0;
|
||||
struct sysfs_attribute *attr;
|
||||
struct dlist *attrs;
|
||||
sensors_subfeature *features;
|
||||
sensors_subfeature *all_subfeatures;
|
||||
sensors_subfeature *dyn_subfeatures;
|
||||
sensors_feature *dyn_features;
|
||||
|
||||
@@ -170,18 +172,19 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
if (attrs == NULL)
|
||||
return -ENOENT;
|
||||
|
||||
/* We use a large sparse table at first to store all found features,
|
||||
so that we can store them sorted at type and index and then later
|
||||
create a dense sorted table. */
|
||||
features = calloc(ALL_POSSIBLE_FEATURES, sizeof(sensors_subfeature));
|
||||
if (!features)
|
||||
/* We use a large sparse table at first to store all found
|
||||
subfeatures, so that we can store them sorted at type and index
|
||||
and then later create a dense sorted table. */
|
||||
all_subfeatures = calloc(ALL_POSSIBLE_SUBFEATURES,
|
||||
sizeof(sensors_subfeature));
|
||||
if (!all_subfeatures)
|
||||
sensors_fatal_error(__FUNCTION__, "Out of memory");
|
||||
|
||||
dlist_for_each_data(attrs, attr, struct sysfs_attribute) {
|
||||
char *name = attr->name;
|
||||
int nr;
|
||||
|
||||
type = sensors_feature_get_type(name, &nr);
|
||||
type = sensors_subfeature_get_type(name, &nr);
|
||||
if (type == SENSORS_FEATURE_UNKNOWN)
|
||||
continue;
|
||||
|
||||
@@ -197,63 +200,62 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
if (nr >= MAX_SENSORS_PER_TYPE) {
|
||||
fprintf(stderr, "libsensors error, more sensors of one"
|
||||
" type then MAX_SENSORS_PER_TYPE, ignoring "
|
||||
"feature: %s\n", name);
|
||||
"subfeature: %s\n", name);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* "calculate" a place to store the feature in our sparse,
|
||||
/* "calculate" a place to store the subfeature in our sparse,
|
||||
sorted table */
|
||||
switch (type) {
|
||||
case SENSORS_FEATURE_VID:
|
||||
i = nr + MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6;
|
||||
i = nr + MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 6;
|
||||
break;
|
||||
case SENSORS_FEATURE_BEEP_ENABLE:
|
||||
i = MAX_SENSORS_PER_TYPE * MAX_SUB_FEATURES * 6 +
|
||||
i = MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 6 +
|
||||
MAX_SENSORS_PER_TYPE;
|
||||
break;
|
||||
default:
|
||||
i = (type >> 8) * MAX_SENSORS_PER_TYPE *
|
||||
MAX_SUB_FEATURES * 2 + nr * MAX_SUB_FEATURES * 2 +
|
||||
((type & 0x10) >> 4) * MAX_SUB_FEATURES +
|
||||
MAX_SUBFEATURES * 2 + nr * MAX_SUBFEATURES * 2 +
|
||||
((type & 0x10) >> 4) * MAX_SUBFEATURES +
|
||||
(type & 0x0F);
|
||||
}
|
||||
|
||||
if (features[i].name) {
|
||||
if (all_subfeatures[i].name) {
|
||||
fprintf(stderr, "libsensors error, trying to add dupli"
|
||||
"cate feature: %s to dynamic feature table\n",
|
||||
"cate subfeature: %s to dynamic feature table\n",
|
||||
name);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* fill in the feature members */
|
||||
features[i].type = type;
|
||||
/* fill in the subfeature members */
|
||||
all_subfeatures[i].type = type;
|
||||
|
||||
/* check for _input extension and remove */
|
||||
nr = strlen(name);
|
||||
if (nr > 6 && !strcmp(name + nr - 6, "_input"))
|
||||
features[i].name = strndup(name, nr - 6);
|
||||
all_subfeatures[i].name = strndup(name, nr - 6);
|
||||
else
|
||||
features[i].name = strdup(name);
|
||||
all_subfeatures[i].name = strdup(name);
|
||||
|
||||
if ((type & 0x00FF) == 0) {
|
||||
/* main feature */
|
||||
features[i].mapping = SENSORS_NO_MAPPING;
|
||||
/* main subfeature */
|
||||
all_subfeatures[i].mapping = SENSORS_NO_MAPPING;
|
||||
} else {
|
||||
/* sub feature */
|
||||
/* The mapping is set below after numbering */
|
||||
if (!(type & 0x10))
|
||||
features[i].flags |= SENSORS_COMPUTE_MAPPING;
|
||||
all_subfeatures[i].flags |= SENSORS_COMPUTE_MAPPING;
|
||||
}
|
||||
|
||||
if (attr->method & SYSFS_METHOD_SHOW)
|
||||
features[i].flags |= SENSORS_MODE_R;
|
||||
all_subfeatures[i].flags |= SENSORS_MODE_R;
|
||||
if (attr->method & SYSFS_METHOD_STORE)
|
||||
features[i].flags |= SENSORS_MODE_W;
|
||||
all_subfeatures[i].flags |= SENSORS_MODE_W;
|
||||
|
||||
fnum++;
|
||||
}
|
||||
|
||||
if (!fnum) { /* No feature */
|
||||
if (!fnum) { /* No subfeature */
|
||||
chip->subfeature = NULL;
|
||||
goto exit_free;
|
||||
}
|
||||
@@ -264,14 +266,14 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
}
|
||||
|
||||
fnum = 0;
|
||||
for (i = 0; i < ALL_POSSIBLE_FEATURES; i++) {
|
||||
if (features[i].name) {
|
||||
dyn_subfeatures[fnum] = features[i];
|
||||
for (i = 0; i < ALL_POSSIBLE_SUBFEATURES; i++) {
|
||||
if (all_subfeatures[i].name) {
|
||||
dyn_subfeatures[fnum] = all_subfeatures[i];
|
||||
fnum++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Number the subfeatures linearly, so that feature number N is at
|
||||
/* Number the subfeatures linearly, so that subfeature number N is at
|
||||
position N in the array. This allows for O(1) look-ups. */
|
||||
for (i = 0; i < fnum; i++) {
|
||||
int j;
|
||||
@@ -316,7 +318,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
chip->feature_count = fnum;
|
||||
|
||||
exit_free:
|
||||
free(features);
|
||||
free(all_subfeatures);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -401,7 +403,7 @@ static int sensors_read_one_sysfs_chip(struct sysfs_device *dev)
|
||||
|
||||
if (sensors_read_dynamic_chip(&entry, dev) < 0)
|
||||
goto exit_free;
|
||||
if (!entry.subfeature) { /* No feature, discard chip */
|
||||
if (!entry.subfeature) { /* No subfeature, discard chip */
|
||||
err = 0;
|
||||
goto exit_free;
|
||||
}
|
||||
@@ -536,58 +538,58 @@ exit0:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sensors_read_sysfs_attr(const sensors_chip_name *name, int feature,
|
||||
int sensors_read_sysfs_attr(const sensors_chip_name *name, int subfeat_nr,
|
||||
double *value)
|
||||
{
|
||||
const sensors_subfeature *the_feature;
|
||||
const sensors_subfeature *subfeature;
|
||||
char n[NAME_MAX];
|
||||
FILE *f;
|
||||
const char *suffix = "";
|
||||
|
||||
if (!(the_feature = sensors_lookup_feature_nr(name, feature)))
|
||||
if (!(subfeature = sensors_lookup_subfeature_nr(name, subfeat_nr)))
|
||||
return -SENSORS_ERR_NO_ENTRY;
|
||||
|
||||
/* REVISIT: this is a ugly hack */
|
||||
if (the_feature->type == SENSORS_FEATURE_IN
|
||||
|| the_feature->type == SENSORS_FEATURE_FAN
|
||||
|| the_feature->type == SENSORS_FEATURE_TEMP)
|
||||
if (subfeature->type == SENSORS_FEATURE_IN
|
||||
|| subfeature->type == SENSORS_FEATURE_FAN
|
||||
|| subfeature->type == SENSORS_FEATURE_TEMP)
|
||||
suffix = "_input";
|
||||
|
||||
snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->name,
|
||||
snprintf(n, NAME_MAX, "%s/%s%s", name->path, subfeature->name,
|
||||
suffix);
|
||||
if ((f = fopen(n, "r"))) {
|
||||
int res = fscanf(f, "%lf", value);
|
||||
fclose(f);
|
||||
if (res != 1)
|
||||
return -SENSORS_ERR_PROC;
|
||||
*value /= get_type_scaling(the_feature->type);
|
||||
*value /= get_type_scaling(subfeature->type);
|
||||
} else
|
||||
return -SENSORS_ERR_PROC;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sensors_write_sysfs_attr(const sensors_chip_name *name, int feature,
|
||||
int sensors_write_sysfs_attr(const sensors_chip_name *name, int subfeat_nr,
|
||||
double value)
|
||||
{
|
||||
const sensors_subfeature *the_feature;
|
||||
const sensors_subfeature *subfeature;
|
||||
char n[NAME_MAX];
|
||||
FILE *f;
|
||||
const char *suffix = "";
|
||||
|
||||
if (!(the_feature = sensors_lookup_feature_nr(name, feature)))
|
||||
if (!(subfeature = sensors_lookup_subfeature_nr(name, subfeat_nr)))
|
||||
return -SENSORS_ERR_NO_ENTRY;
|
||||
|
||||
/* REVISIT: this is a ugly hack */
|
||||
if (the_feature->type == SENSORS_FEATURE_IN
|
||||
|| the_feature->type == SENSORS_FEATURE_FAN
|
||||
|| the_feature->type == SENSORS_FEATURE_TEMP)
|
||||
if (subfeature->type == SENSORS_FEATURE_IN
|
||||
|| subfeature->type == SENSORS_FEATURE_FAN
|
||||
|| subfeature->type == SENSORS_FEATURE_TEMP)
|
||||
suffix = "_input";
|
||||
|
||||
snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->name,
|
||||
snprintf(n, NAME_MAX, "%s/%s%s", name->path, subfeature->name,
|
||||
suffix);
|
||||
if ((f = fopen(n, "w"))) {
|
||||
value *= get_type_scaling(the_feature->type);
|
||||
value *= get_type_scaling(subfeature->type);
|
||||
fprintf(f, "%d", (int) value);
|
||||
fclose(f);
|
||||
} else
|
||||
|
||||
+2
-2
@@ -29,11 +29,11 @@ int sensors_read_sysfs_chips(void);
|
||||
int sensors_read_sysfs_bus(void);
|
||||
|
||||
/* Read a value out of a sysfs attribute file */
|
||||
int sensors_read_sysfs_attr(const sensors_chip_name *name, int feature,
|
||||
int sensors_read_sysfs_attr(const sensors_chip_name *name, int subfeat_nr,
|
||||
double *value);
|
||||
|
||||
/* Write a value to a sysfs attribute file */
|
||||
int sensors_write_sysfs_attr(const sensors_chip_name *name, int feature,
|
||||
int sensors_write_sysfs_attr(const sensors_chip_name *name, int subfeat_nr,
|
||||
double value);
|
||||
|
||||
#endif /* !SENSORS_LIB_SYSFS_H */
|
||||
Reference in new issue
Block a user