mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-15 19:13:10 +00:00
(mmh)
This patch replaces the I2C bus enumeration (through sysfs) in lib/proc.c with a new function in lib/sysfs (using libsysfs). The patch also updates the init code accordingly. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@3094 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
87fba1c487
commit
c277761d15
4 files changed
+74
-65
No files matched your search
+7
-3
@@ -41,11 +41,15 @@ int sensors_init(FILE *input)
|
||||
{
|
||||
int res;
|
||||
sensors_cleanup();
|
||||
sensors_init_sysfs();
|
||||
if ((res = sensors_read_proc_chips()))
|
||||
return res;
|
||||
if ((res = sensors_read_proc_bus()))
|
||||
return res;
|
||||
if (sensors_init_sysfs()) {
|
||||
if ((res = sensors_read_sysfs_bus()))
|
||||
return res;
|
||||
} else {
|
||||
if ((res = sensors_read_proc_bus()))
|
||||
return res;
|
||||
}
|
||||
sensors_yyin = input;
|
||||
if ((res = sensors_yyparse()))
|
||||
return -SENSORS_ERR_PARSE;
|
||||
|
||||
+5
-62
@@ -214,68 +214,11 @@ proc:
|
||||
|
||||
int sensors_read_proc_bus(void)
|
||||
{
|
||||
struct dirent *de;
|
||||
DIR *dir;
|
||||
FILE *f;
|
||||
char line[255];
|
||||
char *border;
|
||||
sensors_bus entry;
|
||||
int lineno;
|
||||
char sysfs[NAME_MAX], n[NAME_MAX];
|
||||
char dirname[NAME_MAX];
|
||||
|
||||
if (sensors_found_sysfs) {
|
||||
strncpy(sysfs, sensors_sysfs_mount, sizeof(sysfs) - 1);
|
||||
sysfs[sizeof(sysfs) - 1] = 0;
|
||||
strncat(sysfs, "/class/i2c-adapter",
|
||||
sizeof(sysfs) - strlen(sysfs) - 1);
|
||||
|
||||
/* Then read from it */
|
||||
dir = opendir(sysfs);
|
||||
if (! dir)
|
||||
goto proc;
|
||||
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
if (!strcmp(de->d_name, "."))
|
||||
continue;
|
||||
if (!strcmp(de->d_name, ".."))
|
||||
continue;
|
||||
|
||||
strcpy(n, sysfs);
|
||||
strcat(n, "/");
|
||||
strcat(n, de->d_name);
|
||||
strcpy(dirname, n);
|
||||
strcat(n, "/device/name");
|
||||
|
||||
if ((f = fopen(n, "r")) != NULL) {
|
||||
char x[120];
|
||||
fgets(x, 120, f);
|
||||
fclose(f);
|
||||
if((border = index(x, '\n')) != NULL)
|
||||
*border = 0;
|
||||
entry.adapter=strdup(x);
|
||||
if(!strncmp(x, "ISA ", 4)) {
|
||||
entry.number = SENSORS_CHIP_NAME_BUS_ISA;
|
||||
entry.algorithm = strdup("ISA bus algorithm");
|
||||
} else if(!sscanf(de->d_name, "i2c-%d", &entry.number)) {
|
||||
entry.number = SENSORS_CHIP_NAME_BUS_DUMMY;
|
||||
entry.algorithm = strdup("Dummy bus algorithm");
|
||||
} else
|
||||
entry.algorithm = strdup("Unavailable from sysfs");
|
||||
if (entry.algorithm == NULL)
|
||||
goto FAT_ERROR_SYS;
|
||||
sensors_add_proc_bus(&entry);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
FAT_ERROR_SYS:
|
||||
sensors_fatal_error("sensors_read_proc_bus", "Allocating entry");
|
||||
closedir(dir);
|
||||
return -SENSORS_ERR_PROC;
|
||||
}
|
||||
|
||||
proc:
|
||||
FILE *f;
|
||||
char line[255];
|
||||
char *border;
|
||||
sensors_bus entry;
|
||||
int lineno;
|
||||
|
||||
f = fopen("/proc/bus/i2c","r");
|
||||
if (!f)
|
||||
|
||||
+60
@@ -20,6 +20,10 @@
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <sysfs/libsysfs.h>
|
||||
#include "data.h"
|
||||
#include "error.h"
|
||||
#include "access.h"
|
||||
#include "general.h"
|
||||
#include "sysfs.h"
|
||||
|
||||
int sensors_found_sysfs = 0;
|
||||
@@ -34,3 +38,59 @@ int sensors_init_sysfs(void)
|
||||
|
||||
return sensors_found_sysfs;
|
||||
}
|
||||
|
||||
/* returns 0 if successful, !0 otherwise */
|
||||
int sensors_read_sysfs_bus(void)
|
||||
{
|
||||
struct sysfs_class *cls;
|
||||
struct dlist *clsdevs;
|
||||
struct sysfs_class_device *clsdev;
|
||||
sensors_bus entry;
|
||||
int ret = 0;
|
||||
|
||||
if (!(cls = sysfs_open_class("i2c-adapter"))) {
|
||||
ret = -SENSORS_ERR_PROC;
|
||||
goto exit0;
|
||||
}
|
||||
|
||||
if (!(clsdevs = sysfs_get_class_devices(cls))) {
|
||||
ret = -SENSORS_ERR_PROC;
|
||||
goto exit1;
|
||||
}
|
||||
|
||||
dlist_for_each_data(clsdevs, clsdev, struct sysfs_class_device) {
|
||||
struct sysfs_device *dev;
|
||||
struct sysfs_attribute *attr;
|
||||
|
||||
if (!(dev = sysfs_get_classdev_device(clsdev)))
|
||||
continue;
|
||||
if (!(attr = sysfs_get_device_attr(dev, "name")))
|
||||
continue;
|
||||
|
||||
entry.adapter = strdup(attr->value);
|
||||
if (!entry.adapter)
|
||||
sensors_fatal_error(__FUNCTION__, "out of memory");
|
||||
|
||||
if (!strncmp(entry.adapter, "ISA ", 4)) {
|
||||
entry.number = SENSORS_CHIP_NAME_BUS_ISA;
|
||||
entry.algorithm = strdup("ISA bus algorithm");
|
||||
} else if (sscanf(clsdev->name, "i2c-%d", &entry.number) != 1) {
|
||||
entry.number = SENSORS_CHIP_NAME_BUS_DUMMY;
|
||||
entry.algorithm = strdup("Dummy bus algorithm");
|
||||
} else
|
||||
entry.algorithm = strdup("Unavailable from sysfs");
|
||||
|
||||
if (!entry.algorithm)
|
||||
sensors_fatal_error(__FUNCTION__, "out of memory");
|
||||
|
||||
sensors_add_proc_bus(&entry);
|
||||
}
|
||||
|
||||
exit1:
|
||||
/* this frees *cls _and_ *clsdevs */
|
||||
sysfs_close_class(cls);
|
||||
|
||||
exit0:
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -26,4 +26,6 @@ extern char sensors_sysfs_mount[];
|
||||
|
||||
extern int sensors_init_sysfs(void);
|
||||
|
||||
extern int sensors_read_sysfs_bus(void);
|
||||
|
||||
#endif /* !SENSORS_LIB_SYSFS_H */
|
||||
Reference in new issue
Block a user