mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-25 20:28:21 +00:00
(mmh)
This patch replaces the I2C chip enumeration (through sysfs) in lib/proc.c with new functions in lib/sysfs (using libsysfs). The patch also updates the init code accordingly. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@3095 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
c277761d15
commit
85a0c8ccb2
4 files changed
+129
-145
No files matched your search
+6
-141
@@ -46,151 +46,16 @@ static int sensors_get_chip_id(sensors_chip_name name);
|
||||
static int getsysname(const sensors_chip_feature *feature, char *sysname,
|
||||
int *sysmag, char *altsysname);
|
||||
|
||||
/* return value: <0 on error, 0 if chip is ignored, 1 if chip is added
|
||||
Warning: name is overwritten */
|
||||
static int sensors_read_one_sysfs_chip(char *name, char *dirname, char *id)
|
||||
{
|
||||
FILE *f;
|
||||
char x[51];
|
||||
int len;
|
||||
sensors_proc_chips_entry entry;
|
||||
|
||||
if ((f = fopen(name, "r")) == NULL)
|
||||
return -SENSORS_ERR_PROC;
|
||||
|
||||
if (fscanf(f, "%50[a-zA-z0-9_ ]%n", x, &len) != 1) {
|
||||
fclose(f);
|
||||
return -SENSORS_ERR_CHIP_NAME;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
/* We don't care about subclients */
|
||||
if (len >= 10 && !strcmp(x + len - 10, " subclient"))
|
||||
return 0;
|
||||
|
||||
/* also, ignore eeproms for all 2.6.x kernels */
|
||||
if (!strcmp(x, "eeprom"))
|
||||
return 0;
|
||||
|
||||
/* Fill in the entry fields */
|
||||
entry.name.prefix = strdup(x);
|
||||
if (entry.name.prefix == NULL)
|
||||
return -SENSORS_ERR_PARSE; /* No better error :( */
|
||||
entry.name.busname = strdup(dirname);
|
||||
if (entry.name.prefix == NULL)
|
||||
return -SENSORS_ERR_PARSE; /* No better error :( */
|
||||
sscanf(id, "%d-%x", &entry.name.bus, &entry.name.addr);
|
||||
|
||||
/* Find out if ISA or not */
|
||||
sprintf(name, "%s/class/i2c-adapter/i2c-%d/device/name",
|
||||
sensors_sysfs_mount, entry.name.bus);
|
||||
if ((f = fopen(name, "r")) != NULL) {
|
||||
if (fgets(x, 5, f) != NULL
|
||||
&& !strncmp(x, "ISA ", 4))
|
||||
entry.name.bus = SENSORS_CHIP_NAME_BUS_ISA;
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
sensors_add_proc_chips(&entry);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* This reads /proc/sys/dev/sensors/chips into memory */
|
||||
int sensors_read_proc_chips(void)
|
||||
{
|
||||
struct dirent *de;
|
||||
DIR *dir;
|
||||
char sysfs[NAME_MAX], n[NAME_MAX];
|
||||
char dirname[NAME_MAX];
|
||||
int res;
|
||||
int res;
|
||||
|
||||
int name[3] = { CTL_DEV, DEV_SENSORS, SENSORS_CHIPS };
|
||||
int buflen = BUF_LEN;
|
||||
char *bufptr = buf;
|
||||
sensors_proc_chips_entry entry;
|
||||
int lineno;
|
||||
|
||||
if (!sensors_found_sysfs)
|
||||
goto proc;
|
||||
|
||||
/* Try /sys/class/hwmon first (Linux 2.6.14 and up) */
|
||||
strncpy(sysfs, sensors_sysfs_mount, sizeof(sysfs) - 1);
|
||||
sysfs[sizeof(sysfs) - 1] = '\0';
|
||||
strncat(sysfs, "/class/hwmon", sizeof(sysfs) - strlen(sysfs) - 1);
|
||||
|
||||
dir = opendir(sysfs);
|
||||
if (! dir)
|
||||
goto oldsys;
|
||||
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
char lnk[NAME_MAX];
|
||||
char *id;
|
||||
|
||||
if (de->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
sprintf(n, "%s/%s", sysfs, de->d_name);
|
||||
strcpy(dirname, n);
|
||||
strcat(n, "/device");
|
||||
if ((res = readlink(n, lnk, NAME_MAX)) < 0)
|
||||
continue;
|
||||
lnk[res] = '\0';
|
||||
|
||||
if (lnk[0] == '/') /* absolute link (unlikely) */
|
||||
strcpy(n, lnk);
|
||||
else if (strncmp(lnk, "../", 3)) /* simple relative link */
|
||||
sprintf(n, "%s/%s/%s", sysfs, de->d_name, lnk);
|
||||
else { /* relative link with ../s, can be simplified */
|
||||
char *p_lnk = lnk + 3;
|
||||
int l = strlen(sysfs) - 1;
|
||||
while (!strncmp(p_lnk, "../", 3)) {
|
||||
p_lnk += 3;
|
||||
while (l && sysfs[--l] != '/') ;
|
||||
}
|
||||
strncpy(n, sysfs, ++l);
|
||||
strcpy(n + l, p_lnk);
|
||||
}
|
||||
strcpy(dirname, n);
|
||||
id = rindex(n, '/');
|
||||
id++;
|
||||
strcat(n, "/name");
|
||||
|
||||
sensors_read_one_sysfs_chip(n, dirname, id);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
|
||||
oldsys:
|
||||
/* Fall back to /sys/bus/i2c (Linux 2.5 to 2.6.13) */
|
||||
strncpy(sysfs, sensors_sysfs_mount, sizeof(sysfs) - 1);
|
||||
sysfs[sizeof(sysfs) - 1] = '\0';
|
||||
strncat(sysfs, "/bus/i2c/devices", sizeof(sysfs) - strlen(sysfs) - 1);
|
||||
|
||||
dir = opendir(sysfs);
|
||||
if (! dir)
|
||||
goto proc;
|
||||
|
||||
while ((de = readdir(dir)) != NULL) {
|
||||
if (!strcmp(de->d_name, "."))
|
||||
continue;
|
||||
if (!strcmp(de->d_name, ".."))
|
||||
continue;
|
||||
/*
|
||||
if (de->d_type != DT_DIR && de->d_type != DT_LNK)
|
||||
continue;
|
||||
*/
|
||||
|
||||
sprintf(n, "%s/%s", sysfs, de->d_name);
|
||||
strcpy(dirname, n);
|
||||
strcat(n, "/name");
|
||||
|
||||
sensors_read_one_sysfs_chip(n, dirname, de->d_name);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
|
||||
proc:
|
||||
int name[3] = { CTL_DEV, DEV_SENSORS, SENSORS_CHIPS };
|
||||
int buflen = BUF_LEN;
|
||||
char *bufptr = buf;
|
||||
sensors_proc_chips_entry entry;
|
||||
int lineno;
|
||||
|
||||
if (sysctl(name, 3, bufptr, &buflen, NULL, 0))
|
||||
return -SENSORS_ERR_PROC;
|
||||
|
||||
Reference in new issue
Block a user