Changeset 4462
- Timestamp:
- 06/25/07 15:32:27 (6 years ago)
- Location:
- lm-sensors/branches/lm-sensors-3.0.0
- Files:
-
- 7 modified
-
CHANGES (modified) (1 diff)
-
kernel/include/sensors.h (modified) (1 diff)
-
lib/init.c (modified) (2 diffs)
-
lib/proc.c (modified) (3 diffs)
-
lib/proc.h (modified) (1 diff)
-
lib/sysfs.c (modified) (2 diffs)
-
lib/sysfs.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/branches/lm-sensors-3.0.0/CHANGES
r4459 r4462 15 15 Delete support of non-sensor drivers (ddcmon, eeprom) 16 16 Always build with sysfs support 17 Delete procfs support (Linux 2.4) 17 18 Man page sensors.conf.5: Update the chip statement section 18 19 Programs doc/*: Delete, obsolete -
lm-sensors/branches/lm-sensors-3.0.0/kernel/include/sensors.h
r4397 r4462 28 28 * been upgraded to the new model (dynamic discovery of chip features.) 29 29 */ 30 31 32 /* From linux/i2c-proc.h */33 34 /* Sysctl IDs */35 #ifdef DEV_HWMON36 #define DEV_SENSORS DEV_HWMON37 #else /* ndef DEV_HWMOM */38 #define DEV_SENSORS 2 /* The id of the lm_sensors directory within the39 dev table */40 #endif /* def DEV_HWMON */41 42 /* The maximum length of the prefix */43 #define SENSORS_PREFIX_MAX 2044 45 #define SENSORS_CHIPS 146 struct i2c_chips_data {47 int sysctl_id;48 char name[SENSORS_PREFIX_MAX + 13];49 };50 30 51 31 -
lm-sensors/branches/lm-sensors-3.0.0/lib/init.c
r4208 r4462 22 22 #include "sensors.h" 23 23 #include "data.h" 24 #include "proc.h"25 24 #include "error.h" 26 25 #include "access.h" … … 43 42 int res; 44 43 sensors_cleanup(); 45 if (sensors_init_sysfs()) { 46 if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips())) 47 return res; 48 } else { 49 if ((res = sensors_read_proc_bus()) || (res = sensors_read_proc_chips())) 50 return res; 51 } 44 if (!sensors_init_sysfs()) 45 return -SENSORS_ERR_PROC; 46 if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips())) 47 return res; 52 48 if ((res = sensors_scanner_init(input))) 53 49 return -SENSORS_ERR_PARSE; -
lm-sensors/branches/lm-sensors-3.0.0/lib/proc.c
r4357 r4462 18 18 */ 19 19 20 #include <sys/types.h>21 #include <sys/sysctl.h>22 #include <stddef.h>23 #include <unistd.h>24 20 #include <stdio.h> 25 21 #include <string.h> … … 27 23 #include <dirent.h> 28 24 29 #include "kernel/include/sensors.h"30 25 #include "data.h" 31 26 #include "error.h" 32 27 #include "access.h" 33 28 #include "general.h" 34 #include "sysfs.h"35 36 /* OK, this proves one thing: if there are too many chips detected, we get in37 trouble. The limit is around 4096/sizeof(struct sensors_chip_data), which38 works out to about 100 entries right now. That seems sensible enough,39 but if we ever get at the point where more chips can be detected, we must40 enlarge buf, and check that sysctl can handle larger buffers. */41 42 #define BUF_LEN 409643 44 static char buf[BUF_LEN];45 29 46 30 static int getsysname(const sensors_chip_feature *feature, char *sysname, 47 31 int *sysmag, char *altsysname); 48 32 49 /* This reads /proc/sys/dev/sensors/chips into memory */ 50 int sensors_read_proc_chips(void) 51 { 52 int res; 53 54 int name[3] = { CTL_DEV, DEV_SENSORS, SENSORS_CHIPS }; 55 size_t buflen = BUF_LEN; 56 char *bufptr = buf; 57 sensors_proc_chips_entry entry; 58 int lineno; 59 60 if (sysctl(name, 3, bufptr, &buflen, NULL, 0)) 61 return -SENSORS_ERR_PROC; 62 63 lineno = 1; 64 while (buflen >= sizeof(struct i2c_chips_data)) { 65 if ((res = 66 sensors_parse_chip_name(((struct i2c_chips_data *) bufptr)->name, 67 &entry.name))) { 68 sensors_parse_error("Parsing /proc/sys/dev/sensors/chips",lineno); 69 return res; 70 } 71 entry.sysctl = ((struct i2c_chips_data *) bufptr)->sysctl_id; 72 sensors_add_proc_chips(&entry); 73 bufptr += sizeof(struct i2c_chips_data); 74 buflen -= sizeof(struct i2c_chips_data); 75 lineno++; 76 } 77 return 0; 78 } 79 80 int sensors_read_proc_bus(void) 81 { 82 FILE *f; 83 char line[255]; 84 char *border; 85 sensors_bus entry; 86 int lineno; 87 88 f = fopen("/proc/bus/i2c","r"); 89 if (!f) 90 return -SENSORS_ERR_PROC; 91 lineno=1; 92 while (fgets(line,255,f)) { 93 if (strlen(line) > 0) 94 line[strlen(line)-1] = '\0'; 95 if (! (border = rindex(line,'\t'))) 96 goto ERROR; 97 /* Skip algorithm name */ 98 *border='\0'; 99 if (! (border = rindex(line,'\t'))) 100 goto ERROR; 101 if (! (entry.adapter = strdup(border + 1))) 102 goto FAT_ERROR; 103 *border='\0'; 104 if (! (border = rindex(line,'\t'))) 105 goto ERROR; 106 *border='\0'; 107 if (strncmp(line,"i2c-",4)) 108 goto ERROR; 109 if (sensors_parse_i2cbus_name(line,&entry.number)) 110 goto ERROR; 111 sensors_strip_of_spaces(entry.adapter); 112 sensors_add_proc_bus(&entry); 113 lineno++; 114 } 115 fclose(f); 116 return 0; 117 FAT_ERROR: 118 sensors_fatal_error("sensors_read_proc_bus","Allocating entry"); 119 ERROR: 120 sensors_parse_error("Parsing /proc/bus/i2c",lineno); 121 fclose(f); 122 return -SENSORS_ERR_PROC; 123 } 124 125 126 /* This returns the first detected chip which matches the name */ 127 static int sensors_get_chip_id(sensors_chip_name name) 128 { 129 int i; 130 for (i = 0; i < sensors_proc_chips_count; i++) 131 if (sensors_match_chip(name, sensors_proc_chips[i].name)) 132 return sensors_proc_chips[i].sysctl; 133 return -SENSORS_ERR_NO_ENTRY; 134 } 135 136 /* This reads a feature /proc or /sys file. 33 /* This reads a feature from a sysfs file. 137 34 Sysfs uses a one-value-per file system... 138 35 */ 139 36 int sensors_read_proc(sensors_chip_name name, int feature, double *value) 140 37 { 141 int sysctl_name[4] = { CTL_DEV, DEV_SENSORS };142 38 const sensors_chip_feature *the_feature; 143 size_t buflen = BUF_LEN;144 39 int mag; 145 146 if (!sensors_found_sysfs) 147 if ((sysctl_name[2] = sensors_get_chip_id(name)) < 0) 148 return sysctl_name[2]; 40 char n[NAME_MAX], altn[NAME_MAX]; 41 FILE *f; 42 149 43 if (! (the_feature = sensors_lookup_feature_nr(name.prefix,feature))) 150 44 return -SENSORS_ERR_NO_ENTRY; 151 if (sensors_found_sysfs) { 152 char n[NAME_MAX], altn[NAME_MAX]; 153 FILE *f; 154 strcpy(n, name.busname); 155 strcat(n, "/"); 156 strcpy(altn, n); 157 /* use rindex to append sysname to n */ 158 getsysname(the_feature, rindex(n, '\0'), &mag, rindex(altn, '\0')); 159 if ((f = fopen(n, "r")) != NULL 160 || (f = fopen(altn, "r")) != NULL) { 161 int res = fscanf(f, "%lf", value); 162 fclose(f); 163 if (res != 1) 164 return -SENSORS_ERR_PROC; 165 for (; mag > 0; mag --) 166 *value /= 10.0; 167 } else 45 46 strcpy(n, name.busname); 47 strcat(n, "/"); 48 strcpy(altn, n); 49 /* use rindex to append sysname to n */ 50 getsysname(the_feature, rindex(n, '\0'), &mag, rindex(altn, '\0')); 51 if ((f = fopen(n, "r")) != NULL 52 || (f = fopen(altn, "r")) != NULL) { 53 int res = fscanf(f, "%lf", value); 54 fclose(f); 55 if (res != 1) 168 56 return -SENSORS_ERR_PROC; 169 } else { 170 sysctl_name[3] = the_feature->sysctl; 171 if (sysctl(sysctl_name, 4, buf, &buflen, NULL, 0)) 172 return -SENSORS_ERR_PROC; 173 *value = *((long *) (buf + the_feature->offset)); 174 for (mag = the_feature->scaling; mag > 0; mag --) 57 for (; mag > 0; mag --) 175 58 *value /= 10.0; 176 for (; mag < 0; mag ++)177 *value *= 10.0;178 } 59 } else 60 return -SENSORS_ERR_PROC; 61 179 62 return 0; 180 63 } … … 182 65 int sensors_write_proc(sensors_chip_name name, int feature, double value) 183 66 { 184 int sysctl_name[4] = { CTL_DEV, DEV_SENSORS };185 67 const sensors_chip_feature *the_feature; 186 size_t buflen = BUF_LEN;187 68 int mag; 69 char n[NAME_MAX], altn[NAME_MAX]; 70 FILE *f; 188 71 189 if (!sensors_found_sysfs)190 if ((sysctl_name[2] = sensors_get_chip_id(name)) < 0)191 return sysctl_name[2];192 72 if (! (the_feature = sensors_lookup_feature_nr(name.prefix,feature))) 193 73 return -SENSORS_ERR_NO_ENTRY; 194 if (sensors_found_sysfs) { 195 char n[NAME_MAX], altn[NAME_MAX]; 196 FILE *f; 197 strcpy(n, name.busname); 198 strcat(n, "/"); 199 strcpy(altn, n); 200 /* use rindex to append sysname to n */ 201 getsysname(the_feature, rindex(n, '\0'), &mag, rindex(altn, '\0')); 202 if ((f = fopen(n, "w")) != NULL 203 || (f = fopen(altn, "w")) != NULL) { 204 for (; mag > 0; mag --) 205 value *= 10.0; 206 fprintf(f, "%d", (int) value); 207 fclose(f); 208 } else 209 return -SENSORS_ERR_PROC; 210 } else { 211 sysctl_name[3] = the_feature->sysctl; 212 if (sysctl(sysctl_name, 4, buf, &buflen, NULL, 0)) 213 return -SENSORS_ERR_PROC; 214 /* The following line is known to solve random problems, still it 215 can't be considered a definitive solution... 216 if (sysctl_name[0] != CTL_DEV) { sysctl_name[0] = CTL_DEV ; } */ 217 for (mag = the_feature->scaling; mag > 0; mag --) 74 75 strcpy(n, name.busname); 76 strcat(n, "/"); 77 strcpy(altn, n); 78 /* use rindex to append sysname to n */ 79 getsysname(the_feature, rindex(n, '\0'), &mag, rindex(altn, '\0')); 80 if ((f = fopen(n, "w")) != NULL 81 || (f = fopen(altn, "w")) != NULL) { 82 for (; mag > 0; mag --) 218 83 value *= 10.0; 219 for (; mag < 0; mag ++) 220 value /= 10.0; 221 * ((long *) (buf + the_feature->offset)) = (long) value; 222 buflen = the_feature->offset + sizeof(long); 223 #ifdef DEBUG 224 /* The following get* calls don't do anything, they are here 225 for debugging purposes only. Strace will show the 226 returned values. */ 227 getuid(); geteuid(); 228 getgid(); getegid(); 229 #endif 230 if (sysctl(sysctl_name, 4, NULL, 0, buf, buflen)) 231 return -SENSORS_ERR_PROC; 232 } 84 fprintf(f, "%d", (int) value); 85 fclose(f); 86 } else 87 return -SENSORS_ERR_PROC; 88 233 89 return 0; 234 90 } -
lm-sensors/branches/lm-sensors-3.0.0/lib/proc.h
r3093 r4462 21 21 #define SENSORS_LIB_PROC_H 22 22 23 /* Read /proc/sys/dev/sensors/chips */24 extern int sensors_read_proc_chips(void);25 26 /* Read /proc/bus/i2c */27 extern int sensors_read_proc_bus(void);28 29 23 /* Read a value out of a /proc file */ 30 24 extern int sensors_read_proc(sensors_chip_name name, int feature, -
lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c
r4420 r4462 31 31 #include "general.h" 32 32 #include "sysfs.h" 33 34 int sensors_found_sysfs = 0;35 33 36 34 char sensors_sysfs_mount[NAME_MAX]; … … 201 199 { 202 200 if (sysfs_get_mnt_path(sensors_sysfs_mount, NAME_MAX) == 0) 203 sensors_found_sysfs =1;204 205 return sensors_found_sysfs;201 return 1; 202 203 return 0; 206 204 } 207 205 -
lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.h
r4458 r4462 21 21 #define SENSORS_LIB_SYSFS_H 22 22 23 extern int sensors_found_sysfs;24 25 23 extern char sensors_sysfs_mount[]; 26 24
