Show
Ignore:
Timestamp:
12/08/98 23:52:05 (15 years ago)
Author:
frodo
Message:

Introduced /proc/sys/dev/sensors/chips file

See doc/sysctl for an explanation why it is needed.

Also fixed two very small cleanup bugs in lm75/lm78, which would probably be
impossible to trigger anyway, but still.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/kernel/sensors.c

    r46 r51  
    4242static void sensors_write_reals(int nrels,void *buffer,int *bufsize, 
    4343                                long *results, int magnitude); 
     44static int sensors_proc_chips(ctl_table *ctl, int write, struct file * filp, 
     45                              void *buffer, size_t *lenp); 
     46static int sensors_sysctl_chips (ctl_table *table, int *name, int nlen,  
     47                                 void *oldval, size_t *oldlenp, void *newval, 
     48                                 size_t newlen, void **context); 
    4449 
    4550static int sensors_init(void); 
     
    6368  { 0 } 
    6469}; 
     70 
     71static ctl_table sensors_proc_dev_sensors[] = { 
     72  { SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &sensors_proc_chips,  
     73    &sensors_sysctl_chips }, 
     74  { 0 } 
     75}; 
     76 
     77static ctl_table sensors_proc_dev[] = { 
     78  { DEV_SENSORS, "sensors", NULL, 0, 0555, sensors_proc_dev_sensors }, 
     79  { 0 }, 
     80}; 
     81 
     82 
     83static ctl_table sensors_proc[] = { 
     84  { CTL_DEV, "dev", NULL, 0, 0555, sensors_proc_dev }, 
     85  { 0 } 
     86}; 
     87 
     88 
     89static struct ctl_table_header *sensors_proc_header; 
     90static int sensors_initialized; 
    6591 
    6692/* This returns a nice name for a new directory; for example lm78-isa-0310 
     
    207233} 
    208234#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */ 
     235 
     236int sensors_proc_chips(ctl_table *ctl, int write, struct file * filp, 
     237                       void *buffer, size_t *lenp) 
     238{ 
     239  char BUF[SENSORS_PREFIX_MAX + 30]; 
     240  int buflen,curbufsize,i; 
     241  struct ctl_table *client_tbl; 
     242 
     243  if (write) 
     244    return 0; 
     245 
     246  /* If buffer is size 0, or we try to read when not at the start, we 
     247     return nothing. Note that I think writing when not at the start 
     248     does not work either, but anyway, this is straight from the kernel 
     249     sources. */ 
     250  if (!*lenp || (filp->f_pos && !write)) { 
     251    *lenp = 0; 
     252    return 0; 
     253  } 
     254  curbufsize = 0; 
     255  for (i = 0; i < SENSORS_ENTRY_MAX; i ++) 
     256    if (sensors_entries[i]) { 
     257      client_tbl = sensors_entries[i]->ctl_table->child->child; 
     258      buflen = sprintf(BUF,"%d\t%s\n",client_tbl->ctl_name, 
     259                       client_tbl->procname); 
     260      if (buflen + curbufsize > *lenp) 
     261        buflen=*lenp-curbufsize; 
     262      copy_to_user(buffer,BUF,buflen); 
     263      curbufsize += buflen; 
     264      (char *) buffer += buflen; 
     265    } 
     266  *lenp = curbufsize; 
     267  filp->f_pos += curbufsize; 
     268  return 0; 
     269} 
     270 
     271int sensors_sysctl_chips (ctl_table *table, int *name, int nlen, void *oldval, 
     272                          size_t *oldlenp, void *newval, size_t newlen, 
     273                          void **context) 
     274{ 
     275  struct sensors_chips_data data; 
     276  int i,oldlen,nrels,maxels; 
     277  struct ctl_table *client_tbl; 
     278 
     279  if (oldval && oldlenp && ! get_user_data(oldlen,oldlenp) && oldlen) { 
     280    maxels = oldlen / sizeof(struct sensors_chips_data); 
     281    nrels = 0; 
     282    for (i = 0; (i < SENSORS_ENTRY_MAX) && (nrels < maxels); i++) 
     283      if (sensors_entries[i]) { 
     284        client_tbl = sensors_entries[i]->ctl_table->child->child; 
     285        data.sysctl_id = client_tbl->ctl_name; 
     286        strcpy(data.name,client_tbl->procname); 
     287        copy_to_user(oldval,&data,sizeof(struct sensors_chips_data)); 
     288        (char *) oldval += sizeof(struct sensors_chips_data); 
     289        nrels++; 
     290      } 
     291    oldlen = nrels * sizeof(struct sensors_chips_data); 
     292    put_user(oldlen,oldlenp); 
     293  } 
     294  return 0; 
     295} 
     296 
    209297 
    210298/* This funcion reads or writes a 'real' value (encoded by the combination 
     
    263351 
    264352    /* And write them to buffer, converting to reals */ 
    265     sensors_write_reals(nrels,buffer,lenp,results,mag); 
    266353    sensors_write_reals(nrels,buffer,lenp,results,mag); 
    267354    filp->f_pos += *lenp; 
     
    478565{ 
    479566  printk("sensors.o version %s (%s)\n",LM_VERSION,LM_DATE); 
     567  sensors_initialized = 0; 
     568  if (! (sensors_proc_header = register_sysctl_table(sensors_proc,0))) 
     569    return -ENOMEM; 
     570  sensors_initialized ++; 
    480571  return 0; 
    481572} 
     
    483574int sensors_cleanup(void) 
    484575{ 
     576  if (sensors_initialized >= 1) { 
     577    unregister_sysctl_table(sensors_proc_header); 
     578    sensors_initialized --; 
     579  } 
    485580  return 0; 
    486581}