Changeset 2076

Show
Ignore:
Timestamp:
11/19/03 04:11:13 (10 years ago)
Author:
mds
Message:

add getsysname() function which converts standard /proc names to

standard sysfs names and magnitudes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/lib/proc.c

    r2066 r2076  
    6565                                       &sensors_proc_bus_max,\ 
    6666                                       sizeof(struct sensors_bus)) 
     67 
     68int getsysname(const sensors_chip_feature *feature, char *sysname, int *sysmag); 
    6769 
    6870/* This reads /proc/sys/dev/sensors/chips into memory */ 
     
    292294                strcpy(n, name.busname); 
    293295                strcat(n, "/"); 
    294                 if(the_feature->sysname != NULL) 
    295                         strcat(n, the_feature->sysname); 
    296                 else 
    297                         strcat(n, the_feature->name); 
     296                /* use rindex to append sysname to n */ 
     297                getsysname(the_feature, rindex(n, '\0'), &mag); 
    298298                if ((f = fopen(n, "r")) != NULL) { 
    299299                        fscanf(f, "%lf", value); 
    300300                        fclose(f); 
    301                         if(the_feature->sysscaling) 
    302                                 mag = the_feature->sysscaling; 
    303                         else 
    304                                 mag = the_feature->scaling; 
    305301                        for (; mag > 0; mag --) 
    306302                                *value /= 10.0; 
     
    341337                strcpy(n, name.busname); 
    342338                strcat(n, "/"); 
    343                 if(the_feature->sysname != NULL) 
    344                         strcat(n, the_feature->sysname); 
    345                 else 
    346                         strcat(n, the_feature->name); 
     339                /* use rindex to append sysname to n */ 
     340                getsysname(the_feature, rindex(n, '\0'), &mag); 
    347341                if ((f = fopen(n, "w")) != NULL) { 
    348                         if(the_feature->sysscaling) 
    349                                 mag = the_feature->sysscaling; 
    350                         else 
    351                                 mag = the_feature->scaling; 
    352342                        for (; mag > 0; mag --) 
    353343                                value *= 10.0; 
     
    372362        return 0; 
    373363} 
     364 
     365#define CURRMAG 3 
     366#define FANMAG 0 
     367#define INMAG 3 
     368#define TEMPMAG 3 
     369 
     370/* 
     371        Returns the sysfs name and magnitude for a given feature. 
     372        First looks for a sysfs name and magnitude in the feature structure. 
     373        These should be added in chips.c for all non-standard feature names. 
     374        If that fails, converts common /proc feature names 
     375        to their sysfs equivalent, and uses common sysfs magnitude. 
     376        If that fails, returns old /proc feature name and magnitude. 
     377 
     378        References: doc/developers/proc in the lm_sensors package; 
     379                    Documentation/i2c/sysfs_interface in the kernel 
     380*/ 
     381int getsysname(const sensors_chip_feature *feature, char *sysname, int *sysmag) 
     382{ 
     383        const char * name = feature->name; 
     384        char last; 
     385        char check; /* used to verify end of string */ 
     386        int num; 
     387         
     388struct match { 
     389        const char * name, * sysname; 
     390        const int sysmag; 
     391}; 
     392 
     393struct match *m; 
     394 
     395struct match matches[] = { 
     396        { "beeps", "beep_mask", 0 }, 
     397        { "pwm", "pwm1", 0 }, 
     398        { "rempte_temp", "temp_input1", TEMPMAG }, 
     399        { "remote_temp_hyst", "temp_hyst1", TEMPMAG }, 
     400        { "remote_temp_low", "temp_min1", TEMPMAG }, 
     401        { "remote_temp_over", "temp_max1", TEMPMAG }, 
     402        { "temp", "temp_input0", TEMPMAG }, 
     403        { "temp_hyst", "temp_hyst0", TEMPMAG }, 
     404        { "temp_low", "temp_min0", TEMPMAG }, 
     405        { "temp_over", "temp_max0", TEMPMAG }, 
     406        { NULL, NULL } 
     407}; 
     408 
     409 
     410/* use override in feature structure if present */ 
     411        if(feature->sysname != NULL) { 
     412                strcpy(sysname, feature->sysname); 
     413                if(feature->sysscaling) 
     414                        *sysmag = feature->sysscaling; 
     415                else 
     416                        *sysmag = feature->scaling; 
     417                return 0; 
     418        } 
     419 
     420/* check for constant mappings */ 
     421        for(m = matches; m->name != NULL; m++) { 
     422                if(!strcmp(m->name, name)) { 
     423                        strcpy(sysname, m->sysname); 
     424                        *sysmag = m->sysmag; 
     425                        return 0; 
     426                } 
     427        } 
     428 
     429/* convert common /proc names to common sysfs names */ 
     430        if(sscanf(name, "fan%d_di%c%c", &num, &last, &check) == 2 && last == 'v') { 
     431                sprintf(sysname, "fan_div%d", num); 
     432                *sysmag = FANMAG; 
     433                return 0; 
     434        } 
     435        if(sscanf(name, "fan%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') { 
     436                sprintf(sysname, "fan_min%d", num); 
     437                *sysmag = FANMAG; 
     438                return 0; 
     439        } 
     440        if(sscanf(name, "fan%d%c", &num, &check) == 1) { 
     441                sprintf(sysname, "fan_input%d", num); 
     442                *sysmag = FANMAG; 
     443                return 0; 
     444        } 
     445 
     446        if(sscanf(name, "in%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') { 
     447                sprintf(sysname, "in_min%d", num); 
     448                *sysmag = INMAG; 
     449                return 0; 
     450        } 
     451        if(sscanf(name, "in%d_ma%c%c", &num, &last, &check) == 2 && last == 'x') { 
     452                sprintf(sysname, "in_max%d", num); 
     453                *sysmag = INMAG; 
     454                return 0; 
     455        } 
     456        if(sscanf(name, "in%d%c", &num, &check) == 1) { 
     457                sprintf(sysname, "in_input%d", num); 
     458                *sysmag = INMAG; 
     459                return 0; 
     460        } 
     461 
     462        if(sscanf(name, "pwm%d%c", &num, &check) == 1) { 
     463                strcpy(sysname, name); 
     464                *sysmag = 0; 
     465                return 0; 
     466        } 
     467 
     468        if(sscanf(name, "sensor%d%c", &num, &check) == 1) { 
     469                strcpy(sysname, name); 
     470                *sysmag = 0; 
     471                return 0; 
     472        } 
     473 
     474        if(sscanf(name, "temp%d_hys%c%c", &num, &last, &check) == 2 && last == 't') { 
     475                sprintf(sysname, "temp_min%d", num); 
     476                *sysmag = TEMPMAG; 
     477                return 0; 
     478        } 
     479        if(sscanf(name, "temp%d_ove%c%c", &num, &last, &check) == 2 && last == 'r') { 
     480                sprintf(sysname, "temp_max%d", num); 
     481                *sysmag = TEMPMAG; 
     482                return 0; 
     483        } 
     484        if(sscanf(name, "temp%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') { 
     485                sprintf(sysname, "temp_min%d", num); 
     486                *sysmag = TEMPMAG; 
     487                return 0; 
     488        } 
     489        if(sscanf(name, "temp%d_ma%c%c", &num, &last, &check) == 2 && last == 'x') { 
     490                sprintf(sysname, "temp_max%d", num); 
     491                *sysmag = TEMPMAG; 
     492                return 0; 
     493        } 
     494        if(sscanf(name, "temp%d%c", &num, &check) == 1) { 
     495                sprintf(sysname, "temp_input%d", num); 
     496                *sysmag = TEMPMAG; 
     497                return 0; 
     498        } 
     499 
     500/* bmcsensors only, not yet in kernel */ 
     501/* 
     502        if(sscanf(name, "curr%d_mi%c%c", &num, &last, &check) == 2 && last == 'n') { 
     503                sprintf(sysname, "curr_min%d", num); 
     504                *sysmag = CURRMAG; 
     505                return 0; 
     506        } 
     507        if(sscanf(name, "curr%d_ma%c%c", &num, &last, &check) == 2 && last == 'x') { 
     508                sprintf(sysname, "curr_max%d", num); 
     509                *sysmag = CURRMAG; 
     510                return 0; 
     511        } 
     512        if(sscanf(name, "curr%d%c", &num, &check) == 1) { 
     513                sprintf(sysname, "curr_input%d", num); 
     514                *sysmag = CURRMAG; 
     515                return 0; 
     516        } 
     517*/ 
     518 
     519/* give up, use old name (probably won't work though...) */ 
     520/* known to be the same: 
     521        "alarms", "beep_enable", "vid", "vrm" 
     522*/ 
     523        strcpy(sysname, name); 
     524        *sysmag = feature->scaling; 
     525        return 0; 
     526}