Changeset 4830
- Timestamp:
- 09/23/07 13:59:51 (6 years ago)
- Location:
- lm-sensors/branches/lm-sensors-3.0.0/lib
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/branches/lm-sensors-3.0.0/lib/access.c
r4796 r4830 90 90 Do not modify the struct the return value points to! Returns NULL if 91 91 not found.*/ 92 const sensors_ chip_feature*sensors_lookup_feature_nr(const sensors_chip_name *chip,92 const sensors_feature_data *sensors_lookup_feature_nr(const sensors_chip_name *chip, 93 93 int feature) 94 94 { … … 108 108 Do not modify the struct the return value points to! Returns NULL if 109 109 not found.*/ 110 static const sensors_ chip_feature*110 static const sensors_feature_data * 111 111 sensors_lookup_feature_name(const sensors_chip_name *chip, const char *feature) 112 112 { 113 113 int i, j; 114 const sensors_ chip_feature*features;114 const sensors_feature_data *features; 115 115 116 116 for (i = 0; i < sensors_proc_chips_count; i++) … … 118 118 features = sensors_proc_chips[i].feature; 119 119 for (j = 0; j < sensors_proc_chips[i].feature_count; j++) 120 if (!strcmp(features[j]. data.name, feature))120 if (!strcmp(features[j].name, feature)) 121 121 return features + j; 122 122 } … … 146 146 char *label; 147 147 const sensors_chip *chip; 148 const sensors_ chip_feature*featureptr;148 const sensors_feature_data *featureptr; 149 149 char buf[128], path[PATH_MAX]; 150 150 FILE *f; … … 158 158 for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));) 159 159 for (i = 0; i < chip->labels_count; i++) 160 if (!strcmp(featureptr-> data.name, chip->labels[i].name)) {160 if (!strcmp(featureptr->name, chip->labels[i].name)) { 161 161 label = strdup(chip->labels[i].value); 162 162 goto sensors_get_label_exit; … … 165 165 /* No user specified label, check for a _label sysfs file */ 166 166 snprintf(path, PATH_MAX, "%s/%s_label", name->path, 167 featureptr-> data.name);167 featureptr->name); 168 168 169 169 if ((f = fopen(path, "r"))) { … … 179 179 180 180 /* No label, return the feature name instead */ 181 label = strdup(featureptr-> data.name);181 label = strdup(featureptr->name); 182 182 183 183 sensors_get_label_exit: … … 192 192 mappings into account. */ 193 193 static int sensors_get_ignored(const sensors_chip_name *name, 194 const sensors_ chip_feature*feature)194 const sensors_feature_data *feature) 195 195 { 196 196 const sensors_chip *chip; … … 198 198 int i; 199 199 200 if (feature-> data.mapping == SENSORS_NO_MAPPING)200 if (feature->mapping == SENSORS_NO_MAPPING) 201 201 main_feature_name = NULL; 202 202 else 203 203 main_feature_name = sensors_lookup_feature_nr(name, 204 feature-> data.mapping)->data.name;204 feature->mapping)->name; 205 205 206 206 for (chip = NULL; (chip = sensors_for_all_config_chips(name, chip));) 207 207 for (i = 0; i < chip->ignores_count; i++) 208 if (!strcmp(feature-> data.name, chip->ignores[i].name) ||208 if (!strcmp(feature->name, chip->ignores[i].name) || 209 209 (main_feature_name && 210 210 !strcmp(main_feature_name, chip->ignores[i].name))) … … 219 219 double *result) 220 220 { 221 const sensors_ chip_feature*main_feature;222 const sensors_ chip_feature*alt_feature;221 const sensors_feature_data *main_feature; 222 const sensors_feature_data *alt_feature; 223 223 const sensors_chip *chip; 224 224 const sensors_expr *expr = NULL; … … 232 232 return -SENSORS_ERR_NO_ENTRY; 233 233 234 if (main_feature-> data.flags & SENSORS_COMPUTE_MAPPING)234 if (main_feature->flags & SENSORS_COMPUTE_MAPPING) 235 235 alt_feature = sensors_lookup_feature_nr(name, 236 main_feature-> data.mapping);236 main_feature->mapping); 237 237 else 238 238 alt_feature = NULL; 239 239 240 if (!(main_feature-> data.flags & SENSORS_MODE_R))240 if (!(main_feature->flags & SENSORS_MODE_R)) 241 241 return -SENSORS_ERR_ACCESS_R; 242 242 for (chip = NULL; 243 243 !expr && (chip = sensors_for_all_config_chips(name, chip));) 244 244 for (i = 0; !final_expr && (i < chip->computes_count); i++) { 245 if (!strcmp(main_feature-> data.name, chip->computes[i].name)) {245 if (!strcmp(main_feature->name, chip->computes[i].name)) { 246 246 expr = chip->computes[i].from_proc; 247 247 final_expr = 1; 248 } else if (alt_feature && !strcmp(alt_feature-> data.name,248 } else if (alt_feature && !strcmp(alt_feature->name, 249 249 chip->computes[i].name)) { 250 250 expr = chip->computes[i].from_proc; … … 266 266 double value) 267 267 { 268 const sensors_ chip_feature*main_feature;269 const sensors_ chip_feature*alt_feature;268 const sensors_feature_data *main_feature; 269 const sensors_feature_data *alt_feature; 270 270 const sensors_chip *chip; 271 271 const sensors_expr *expr = NULL; … … 279 279 return -SENSORS_ERR_NO_ENTRY; 280 280 281 if (main_feature-> data.flags & SENSORS_COMPUTE_MAPPING)281 if (main_feature->flags & SENSORS_COMPUTE_MAPPING) 282 282 alt_feature = sensors_lookup_feature_nr(name, 283 main_feature-> data.mapping);283 main_feature->mapping); 284 284 else 285 285 alt_feature = NULL; 286 286 287 if (!(main_feature-> data.flags & SENSORS_MODE_W))287 if (!(main_feature->flags & SENSORS_MODE_W)) 288 288 return -SENSORS_ERR_ACCESS_W; 289 289 for (chip = NULL; 290 290 !expr && (chip = sensors_for_all_config_chips(name, chip));) 291 291 for (i = 0; !final_expr && (i < chip->computes_count); i++) 292 if (!strcmp(main_feature-> data.name, chip->computes[i].name)) {292 if (!strcmp(main_feature->name, chip->computes[i].name)) { 293 293 expr = chip->computes->to_proc; 294 294 final_expr = 1; 295 } else if (alt_feature && !strcmp(alt_feature-> data.name,295 } else if (alt_feature && !strcmp(alt_feature->name, 296 296 chip->computes[i].name)) { 297 297 expr = chip->computes[i].to_proc; … … 348 348 int *nr) 349 349 { 350 sensors_ chip_feature*feature_list;350 sensors_feature_data *feature_list; 351 351 int i; 352 352 … … 359 359 if (*nr == sensors_proc_chips[i].feature_count) 360 360 return NULL; 361 return &feature_list[(*nr)++] .data;361 return &feature_list[(*nr)++]; 362 362 } 363 363 return NULL; … … 371 371 double res1, res2; 372 372 int res; 373 const sensors_ chip_feature*feature;373 const sensors_feature_data *feature; 374 374 375 375 if (expr->kind == sensors_kind_val) { … … 385 385 expr->data.var))) 386 386 return SENSORS_ERR_NO_ENTRY; 387 if (!(res = sensors_get_value(name, feature-> data.number, result)))387 if (!(res = sensors_get_value(name, feature->number, result))) 388 388 return res; 389 389 return 0; … … 433 433 int i, j; 434 434 int err = 0, res; 435 const sensors_ chip_feature*feature;435 const sensors_feature_data *feature; 436 436 int *feature_list = NULL; 437 437 int feature_count = 0; … … 449 449 continue; 450 450 } 451 feature_nr = feature-> data.number;451 feature_nr = feature->number; 452 452 453 453 /* Check whether we already set this feature */ -
lm-sensors/branches/lm-sensors-3.0.0/lib/access.h
r4776 r4830 27 27 Do not modify the struct the return value points to! Returns NULL if 28 28 not found. */ 29 const sensors_ chip_feature*sensors_lookup_feature_nr(const sensors_chip_name *chip,29 const sensors_feature_data *sensors_lookup_feature_nr(const sensors_chip_name *chip, 30 30 int feature); 31 31 -
lm-sensors/branches/lm-sensors-3.0.0/lib/data.h
r4762 r4830 121 121 } sensors_bus; 122 122 123 /* Internal data about a single chip feature.124 name is the string name used to refer to this feature (both in config125 files and through user functions);126 number is the internal feature number, used in many functions to refer127 to this feature128 mapping is either SENSORS_NO_MAPPING if this is feature is the129 main element of category; or it is the number of a feature with which130 this feature is logically grouped (a group could be fan, fan_max and131 fan_div)132 flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable),133 SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the134 computation rules of the main feature). */135 typedef struct sensors_chip_feature {136 sensors_feature_data data;137 } sensors_chip_feature;138 139 123 /* Internal data about all features of a type of chip */ 140 124 typedef struct sensors_chip_features { 141 125 struct sensors_chip_name chip; 142 struct sensors_ chip_feature*feature;126 struct sensors_feature_data *feature; 143 127 int feature_count; 144 128 } sensors_chip_features; -
lm-sensors/branches/lm-sensors-3.0.0/lib/init.c
r4778 r4830 58 58 59 59 for (i = 0; i < features->feature_count; i++) 60 free(features->feature[i]. data.name);60 free(features->feature[i].name); 61 61 free(features->feature); 62 62 } -
lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h
r4826 r4830 164 164 } sensors_feature_type; 165 165 166 /* This structure is used when you want to get all features of a specific 167 chip. */ 166 /* Data about a single chip feature: 167 name is the string name used to refer to this feature (in config files) 168 number is the internal feature number, used in many functions to refer 169 to this feature 170 type is the feature or subfeature type 171 mapping is either SENSORS_NO_MAPPING if this is feature is the 172 main element of category; or it is the number of a feature with which 173 this subfeature is logically grouped (a group could be fan, fan_min 174 and fan_div) 175 flags is a bitfield, its value is a combination of SENSORS_MODE_R (readable), 176 SENSORS_MODE_W (writable) and SENSORS_COMPUTE_MAPPING (affected by the 177 computation rules of the main feature) */ 168 178 typedef struct sensors_feature_data { 169 179 char *name; -
lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c
r4829 r4830 162 162 struct sysfs_attribute *attr; 163 163 struct dlist *attrs; 164 sensors_ chip_feature*features;165 sensors_ chip_feature*dyn_features;164 sensors_feature_data *features; 165 sensors_feature_data *dyn_features; 166 166 167 167 attrs = sysfs_get_device_attributes(sysdir); … … 173 173 so that we can store them sorted at type and index and then later 174 174 create a dense sorted table. */ 175 features = calloc(ALL_POSSIBLE_FEATURES, sizeof(sensors_ chip_feature));175 features = calloc(ALL_POSSIBLE_FEATURES, sizeof(sensors_feature_data)); 176 176 if (!features) 177 177 sensors_fatal_error(__FUNCTION__, "Out of memory"); … … 218 218 } 219 219 220 if (features[i]. data.name) {220 if (features[i].name) { 221 221 fprintf(stderr, "libsensors error, trying to add dupli" 222 222 "cate feature: %s to dynamic feature table\n", … … 226 226 227 227 /* fill in the feature members */ 228 features[i]. data.type = type;228 features[i].type = type; 229 229 230 230 /* check for _input extension and remove */ 231 231 nr = strlen(name); 232 232 if (nr > 6 && !strcmp(name + nr - 6, "_input")) 233 features[i]. data.name = strndup(name, nr - 6);233 features[i].name = strndup(name, nr - 6); 234 234 else 235 features[i]. data.name = strdup(name);235 features[i].name = strdup(name); 236 236 237 237 if ((type & 0x00FF) == 0) { 238 238 /* main feature */ 239 features[i]. data.mapping = SENSORS_NO_MAPPING;239 features[i].mapping = SENSORS_NO_MAPPING; 240 240 } else { 241 241 /* sub feature */ 242 242 /* The mapping is set below after numbering */ 243 243 if (!(type & 0x10)) 244 features[i]. data.flags |= SENSORS_COMPUTE_MAPPING;244 features[i].flags |= SENSORS_COMPUTE_MAPPING; 245 245 } 246 246 247 247 if (attr->method & SYSFS_METHOD_SHOW) 248 features[i]. data.flags |= SENSORS_MODE_R;248 features[i].flags |= SENSORS_MODE_R; 249 249 if (attr->method & SYSFS_METHOD_STORE) 250 features[i]. data.flags |= SENSORS_MODE_W;250 features[i].flags |= SENSORS_MODE_W; 251 251 252 252 fnum++; … … 258 258 } 259 259 260 dyn_features = calloc(fnum, sizeof(sensors_ chip_feature));260 dyn_features = calloc(fnum, sizeof(sensors_feature_data)); 261 261 if (dyn_features == NULL) { 262 262 sensors_fatal_error(__FUNCTION__, "Out of memory"); … … 265 265 fnum = 0; 266 266 for (i = 0; i < ALL_POSSIBLE_FEATURES; i++) { 267 if (features[i]. data.name) {267 if (features[i].name) { 268 268 dyn_features[fnum] = features[i]; 269 269 fnum++; … … 276 276 int j; 277 277 278 dyn_features[i]. data.number = i;279 if (dyn_features[i]. data.mapping == SENSORS_NO_MAPPING) {278 dyn_features[i].number = i; 279 if (dyn_features[i].mapping == SENSORS_NO_MAPPING) { 280 280 /* Main feature, set the mapping field of all its 281 281 subfeatures */ 282 282 for (j = i + 1; j < fnum && 283 dyn_features[j]. data.mapping != SENSORS_NO_MAPPING;283 dyn_features[j].mapping != SENSORS_NO_MAPPING; 284 284 j++) 285 dyn_features[j]. data.mapping = i;285 dyn_features[j].mapping = i; 286 286 } 287 287 } … … 514 514 double *value) 515 515 { 516 const sensors_ chip_feature*the_feature;516 const sensors_feature_data *the_feature; 517 517 char n[NAME_MAX]; 518 518 FILE *f; … … 523 523 524 524 /* REVISIT: this is a ugly hack */ 525 if (the_feature-> data.type == SENSORS_FEATURE_IN526 || the_feature-> data.type == SENSORS_FEATURE_FAN527 || the_feature-> data.type == SENSORS_FEATURE_TEMP)525 if (the_feature->type == SENSORS_FEATURE_IN 526 || the_feature->type == SENSORS_FEATURE_FAN 527 || the_feature->type == SENSORS_FEATURE_TEMP) 528 528 suffix = "_input"; 529 529 530 snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature-> data.name,530 snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->name, 531 531 suffix); 532 532 if ((f = fopen(n, "r"))) { … … 535 535 if (res != 1) 536 536 return -SENSORS_ERR_PROC; 537 *value /= get_type_scaling(the_feature-> data.type);537 *value /= get_type_scaling(the_feature->type); 538 538 } else 539 539 return -SENSORS_ERR_PROC; … … 545 545 double value) 546 546 { 547 const sensors_ chip_feature*the_feature;547 const sensors_feature_data *the_feature; 548 548 char n[NAME_MAX]; 549 549 FILE *f; … … 554 554 555 555 /* REVISIT: this is a ugly hack */ 556 if (the_feature-> data.type == SENSORS_FEATURE_IN557 || the_feature-> data.type == SENSORS_FEATURE_FAN558 || the_feature-> data.type == SENSORS_FEATURE_TEMP)556 if (the_feature->type == SENSORS_FEATURE_IN 557 || the_feature->type == SENSORS_FEATURE_FAN 558 || the_feature->type == SENSORS_FEATURE_TEMP) 559 559 suffix = "_input"; 560 560 561 snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature-> data.name,561 snprintf(n, NAME_MAX, "%s/%s%s", name->path, the_feature->name, 562 562 suffix); 563 563 if ((f = fopen(n, "w"))) { 564 value *= get_type_scaling(the_feature-> data.type);564 value *= get_type_scaling(the_feature->type); 565 565 fprintf(f, "%d", (int) value); 566 566 fclose(f);
