Changeset 4368
- Timestamp:
- 04/10/07 13:51:07 (6 years ago)
- Location:
- lm-sensors/branches/lm-sensors-3.0.0
- Files:
-
- 4 modified
-
lib/access.c (modified) (5 diffs)
-
lib/sensors.h (modified) (2 diffs)
-
lib/sysfs.c (modified) (4 diffs)
-
prog/sensors/chips_generic.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/branches/lm-sensors-3.0.0/lib/access.c
r4367 r4368 516 516 517 517 static struct feature_type_match temp_matches[] = { 518 { "max", SENSORS_FEATURE_TEMP_MAX },519 { "min", SENSORS_FEATURE_TEMP_MIN },520 { "type", SENSORS_FEATURE_TEMP_SENS },521 518 { "hyst", SENSORS_FEATURE_TEMP_HYST }, 522 519 { "over", SENSORS_FEATURE_TEMP_OVER }, … … 525 522 { "low", SENSORS_FEATURE_TEMP_LOW }, 526 523 { "crit", SENSORS_FEATURE_TEMP_CRIT }, 524 { "alarm", SENSORS_FEATURE_TEMP_ALARM }, 527 525 { "fault", SENSORS_FEATURE_TEMP_FAULT }, 528 { "alarm", SENSORS_FEATURE_TEMP_ALARM },529 526 { "type", SENSORS_FEATURE_TEMP_SENS }, 530 527 { 0 } … … 532 529 533 530 static struct feature_type_match in_matches[] = { 531 { "min", SENSORS_FEATURE_IN_MIN }, 534 532 { "max", SENSORS_FEATURE_IN_MAX }, 533 { "alarm", SENSORS_FEATURE_IN_ALARM }, 534 { "min_alarm", SENSORS_FEATURE_IN_MIN_ALARM }, 535 535 { "max_alarm", SENSORS_FEATURE_IN_MAX_ALARM }, 536 { "min", SENSORS_FEATURE_IN_MIN },537 { "min_alarm", SENSORS_FEATURE_IN_MIN_ALARM },538 { "alarm", SENSORS_FEATURE_IN_ALARM },539 536 { 0 } 540 537 }; … … 563 560 { 564 561 const char *name; 565 regex_t preg;566 562 regmatch_t pmatch[4]; 567 563 int size_first, size_second, retval, i; 568 564 struct feature_type_match *submatches; 565 static regex_t reg; 566 static regex_t *preg = NULL; 569 567 570 568 /* use sysname if exists */ … … 574 572 name = feature->name; 575 573 576 regcomp(&preg, GET_TYPE_REGEX, 0); 577 578 retval = regexec(&preg, name, 4, pmatch, 0); 579 580 regfree(&preg); 574 if (!preg) { 575 regcomp(®, GET_TYPE_REGEX, 0); 576 preg = ® 577 } 578 579 retval = regexec(preg, name, 4, pmatch, 0); 581 580 582 581 if (retval == -1) -
lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h
r4366 r4368 148 148 (sensors_chip_name name, int *nr1,int *nr2); 149 149 150 /* This enum contains some "magic" used by sensors_read_dynamic_chip() from 151 lib/sysfs.c . All the sensor-types (in, fan, temp, misc) are a multiple of 152 0x100 apart, and sensor features which should not have a compute_mapping to 153 the _input feature start at 0x?10. */ 150 154 typedef enum sensors_feature_type { 151 SENSORS_FEATURE_TEMP = 0x0, 152 SENSORS_FEATURE_TEMP_ALARM, 153 SENSORS_FEATURE_TEMP_FAULT, 154 SENSORS_FEATURE_TEMP_SENS, 155 SENSORS_FEATURE_IN = 0x000, 156 SENSORS_FEATURE_IN_MIN, 157 SENSORS_FEATURE_IN_MAX, 158 SENSORS_FEATURE_IN_ALARM = 0x010, 159 SENSORS_FEATURE_IN_MIN_ALARM, 160 SENSORS_FEATURE_IN_MAX_ALARM, 161 162 SENSORS_FEATURE_FAN = 0x100, 163 SENSORS_FEATURE_FAN_MIN, 164 SENSORS_FEATURE_FAN_ALARM = 0x110, 165 SENSORS_FEATURE_FAN_FAULT, 166 SENSORS_FEATURE_FAN_DIV, 167 168 SENSORS_FEATURE_TEMP = 0x200, 155 169 SENSORS_FEATURE_TEMP_HYST, 156 170 SENSORS_FEATURE_TEMP_OVER, … … 161 175 SENSORS_FEATURE_TEMP_LIM, 162 176 SENSORS_FEATURE_TEMP_CRIT, 163 164 SENSORS_FEATURE_IN = 0x100, 165 SENSORS_FEATURE_IN_ALARM, 166 SENSORS_FEATURE_IN_MIN, 167 SENSORS_FEATURE_IN_MAX, 168 SENSORS_FEATURE_IN_MIN_ALARM, 169 SENSORS_FEATURE_IN_MAX_ALARM, 170 171 SENSORS_FEATURE_FAN = 0x200, 172 SENSORS_FEATURE_FAN_ALARM, 173 SENSORS_FEATURE_FAN_FAULT, 174 SENSORS_FEATURE_FAN_MIN, 175 SENSORS_FEATURE_FAN_DIV, 177 SENSORS_FEATURE_TEMP_ALARM = 0x210, 178 SENSORS_FEATURE_TEMP_FAULT, 179 SENSORS_FEATURE_TEMP_SENS, 176 180 177 181 SENSORS_FEATURE_VID = 0x300, 178 182 SENSORS_FEATURE_VRM, 179 183 180 SENSORS_FEATURE_UNKNOWN = INT_MAX 184 SENSORS_FEATURE_UNKNOWN = INT_MAX, 185 186 /* special the largest number of subfeatures used, iow the 187 highest ## from all the 0x?## above + 1*/ 188 SENSORS_FEATURE_MAX_SUB_FEATURES = 19 181 189 } sensors_feature_type; 182 190 -
lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c
r4367 r4368 22 22 23 23 #include <string.h> 24 #include <stdlib.h> 24 25 #include <limits.h> 25 26 #include <errno.h> 26 27 #include <sysfs/libsysfs.h> 27 #include <regex.h>28 28 #include "data.h" 29 29 #include "error.h" … … 36 36 char sensors_sysfs_mount[NAME_MAX]; 37 37 38 #define DYNAMIC_CHIP_REGEX "\\([[:alpha:]]\\{1,\\}[[:digit:]]\\{0,\\}\\)\\(\\_[[:alpha:]]\\{1,\\}\\)\\{0,1\\}" 39 40 static int sensors_read_dynamic_chip_check_mapping( 41 sensors_chip_feature *minor, 42 sensors_chip_feature *major, 43 regmatch_t *pmatch) 44 { 45 if (pmatch[1].rm_so == -1 || pmatch[2].rm_so == -1 || 46 strncmp(minor->data.name, major->data.name, 47 pmatch[1].rm_eo - pmatch[1].rm_so)) { 48 return 0; 49 } else { 50 minor->data.mapping = 51 minor->data.compute_mapping = 52 major->data.number; 53 54 return 1; 55 } 56 } 38 #define MAX_SENSORS_PER_TYPE 16 57 39 58 40 static 59 41 sensors_chip_features sensors_read_dynamic_chip(struct sysfs_device *sysdir) 60 42 { 61 int fnum = 1, i, last_major = -1;43 int i, type, fnum = 1; 62 44 struct sysfs_attribute *attr; 63 45 struct dlist *attrs; 64 46 sensors_chip_features ret = {0, 0}; 65 sensors_chip_feature features[256], *dyn_features; 66 regex_t preg; 67 regmatch_t pmatch[3]; 47 /* room for all 3 (in, fan, temp) types, with all their subfeatures 48 + misc features. We use a large sparse table at first to store all 49 found features, so that we can store them sorted at type and index 50 and then later create a dense sorted table */ 51 sensors_chip_feature features[MAX_SENSORS_PER_TYPE * 52 SENSORS_FEATURE_MAX_SUB_FEATURES * 3 + 53 SENSORS_FEATURE_MAX_SUB_FEATURES]; 54 sensors_chip_feature *dyn_features; 68 55 char *name; 69 56 … … 72 59 if (attrs == NULL) 73 60 return ret; 74 75 regcomp(&preg, DYNAMIC_CHIP_REGEX, 0);76 61 62 memset(features, 0, sizeof(features)); 63 77 64 dlist_for_each_data(attrs, attr, struct sysfs_attribute) { 78 sensors_chip_feature feature = { { 0, }, 0, }; 65 sensors_chip_feature feature = { { 0, }, 0, }; 79 66 name = attr->name; 80 67 … … 82 69 ret.prefix = strndup(attr->value, strlen(attr->value) - 1); 83 70 continue; 84 } else if (regexec(&preg, name, 3, pmatch, 0) != 0) { 85 continue; 86 } 87 88 feature.data.number = fnum; 89 feature.data.mode = (attr->method & (SYSFS_METHOD_SHOW|SYSFS_METHOD_STORE)) == 90 (SYSFS_METHOD_SHOW|SYSFS_METHOD_STORE) ? 91 SENSORS_MODE_RW : 92 (attr->method & SYSFS_METHOD_SHOW) ? SENSORS_MODE_R : 93 (attr->method & SYSFS_METHOD_STORE) ? SENSORS_MODE_W : 94 SENSORS_MODE_NO_RW; 95 feature.data.mapping = SENSORS_NO_MAPPING; 96 feature.data.compute_mapping = SENSORS_NO_MAPPING; 71 } 72 73 /* check for _input extension and remove */ 74 i = strlen(name); 75 if (i > 6 && !strcmp(name + i - 6, "_input")) 76 feature.data.name = strndup(name, i-6); 77 else 78 feature.data.name = strdup(name); 79 80 type = sensors_feature_get_type(&feature.data); 81 if (type == SENSORS_FEATURE_UNKNOWN) { 82 free((char *)feature.data.name); 83 continue; 84 } 97 85 98 if (pmatch[2].rm_so != -1) { 99 if (!strcmp(name + pmatch[2].rm_so, "_input")) { 100 int last_match; 101 102 /* copy only the part before the _ */ 103 feature.data.name = strndup(name, 104 pmatch[1].rm_eo - pmatch[1].rm_so); 105 106 /* check if the features previously read are sub devices of this major 107 and update their mapping accordingly */ 108 last_match = fnum - 1; 109 for(i = fnum - 2; i >= 0; i--) { 110 if (regexec(&preg, features[i].data.name, 3, pmatch, 0) == -1 || 111 !sensors_read_dynamic_chip_check_mapping(&features[i], 112 &feature, pmatch)) { 113 break; 114 } else { 115 last_match = i; 116 } 117 } 118 119 /* if so the major should be in the list before any minor feature, 120 so swap with the oldest read */ 121 if (last_match < fnum - 1) { 122 sensors_chip_feature tmp = features[last_match]; 123 features[last_match] = feature; 124 features[fnum - 1] = tmp; 125 126 last_major = last_match; 127 128 goto NEXT_NUM; /* NOTE: goto used */ 129 } else { 130 last_major = fnum - 1; 131 } 132 133 } else { 134 feature.data.name = strdup(name); 86 /* Get N as in this is the N-th in / fan / temp sensor */ 87 switch (type & 0xFF00) { 88 case SENSORS_FEATURE_IN: 89 i = strtol(name + 2, NULL, 10); 90 break; 91 case SENSORS_FEATURE_FAN: 92 i = strtol(name + 3, NULL, 10); 93 if (i) i--; 94 break; 95 case SENSORS_FEATURE_TEMP: 96 i = strtol(name + 4, NULL, 10); 97 if (i) i--; 98 break; 99 case SENSORS_FEATURE_VID: /* first misc feature */ 100 i = 0; 101 break; 102 } 103 104 if (i >= MAX_SENSORS_PER_TYPE) { 105 fprintf(stderr, "libsensors error, more sensors of one" 106 " type then MAX_SENSORS_PER_TYPE, ignoring " 107 "feature: %s\n", name); 108 free((char *)feature.data.name); 109 continue; 110 } 111 112 /* "calculate" a place to store the feature in our sparse, 113 sorted table */ 114 i = (type >> 8) * MAX_SENSORS_PER_TYPE * 115 SENSORS_FEATURE_MAX_SUB_FEATURES + 116 i * SENSORS_FEATURE_MAX_SUB_FEATURES + (type & 0xFF); 117 118 if (features[i].data.name) { 119 fprintf(stderr, "libsensors error, trying to add dupli" 120 "cate feature: %s to dynamic feature table\n", 121 name); 122 free((char *)feature.data.name); 123 continue; 124 } 125 126 /* fill in the other feature members */ 127 feature.data.number = i + 1; 135 128 136 if (last_major != -1 && 137 !sensors_read_dynamic_chip_check_mapping(&feature, 138 &features[last_major], pmatch)) { 139 last_major = -1; /* no more features for current major */ 140 } 141 } 129 if ( (type & 0xFF00) == SENSORS_FEATURE_VID || 130 (type & 0x00FF) == 0) { 131 /* misc sensor or main feature */ 132 feature.data.mapping = SENSORS_NO_MAPPING; 133 feature.data.compute_mapping = SENSORS_NO_MAPPING; 134 } else if (type & 0x10) { 135 /* sub feature without compute mapping */ 136 feature.data.mapping = i - 137 i % SENSORS_FEATURE_MAX_SUB_FEATURES + 1; 138 feature.data.compute_mapping = SENSORS_NO_MAPPING; 142 139 } else { 143 feature.data.name = strdup(name); 144 } 145 146 features[fnum - 1] = feature; 147 NEXT_NUM: 140 feature.data.mapping = i - 141 i % SENSORS_FEATURE_MAX_SUB_FEATURES + 1; 142 feature.data.compute_mapping = feature.data.mapping; 143 } 144 145 feature.data.mode = 146 (attr->method & (SYSFS_METHOD_SHOW|SYSFS_METHOD_STORE)) 147 == (SYSFS_METHOD_SHOW|SYSFS_METHOD_STORE) ? 148 SENSORS_MODE_RW : (attr->method & SYSFS_METHOD_SHOW) ? 149 SENSORS_MODE_R : (attr->method & SYSFS_METHOD_STORE) ? 150 SENSORS_MODE_W : SENSORS_MODE_NO_RW; 151 152 features[i] = feature; 148 153 fnum++; 149 154 } 150 151 regfree(&preg); 152 153 dyn_features = malloc(sizeof(sensors_chip_feature) * fnum); 155 156 dyn_features = calloc(fnum, sizeof(sensors_chip_feature)); 154 157 if (dyn_features == NULL) { 155 158 sensors_fatal_error(__FUNCTION__,"Out of memory"); 156 159 } 157 160 158 for(i = 0; i < fnum - 1; i++) { 159 dyn_features[i] = features[i]; 160 } 161 dyn_features[fnum - 1].data.name = 0; 161 fnum = 0; 162 for(i = 0; i < sizeof(features)/sizeof(sensors_chip_feature); i++) { 163 if (features[i].data.name) { 164 dyn_features[fnum] = features[i]; 165 fnum++; 166 } 167 } 162 168 163 169 ret.feature = dyn_features; -
lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips_generic.c
r4366 r4368 111 111 char *label; 112 112 int valid, type; 113 const int size = SENSORS_FEATURE_TEMP_ CRIT- SENSORS_FEATURE_TEMP;114 short has_features[SENSORS_FEATURE_TEMP_ CRIT - SENSORS_FEATURE_TEMP] = {0, 0, 0, 0, 0, 0, 0, 0, 0};115 double feature_vals[SENSORS_FEATURE_TEMP_ CRIT- SENSORS_FEATURE_TEMP] = {0.0, };113 const int size = SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP; 114 short has_features[SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP] = {0, }; 115 double feature_vals[SENSORS_FEATURE_TEMP_SENS - SENSORS_FEATURE_TEMP] = {0.0, }; 116 116 117 117 if (sensors_get_label_and_valid(*name, feature->number, &label, &valid)) { … … 255 255 const int size = SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN; 256 256 int valid; 257 short has_features[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = {0, 0, 0, 0, 0};257 short has_features[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = {0, }; 258 258 double feature_vals[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = {0.0, }; 259 259 double val, alarm_max, alarm_min;
