| | 44 | static int sensors_proc_chips(ctl_table *ctl, int write, struct file * filp, |
| | 45 | void *buffer, size_t *lenp); |
| | 46 | static 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); |
| | 70 | |
| | 71 | static 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 | |
| | 77 | static ctl_table sensors_proc_dev[] = { |
| | 78 | { DEV_SENSORS, "sensors", NULL, 0, 0555, sensors_proc_dev_sensors }, |
| | 79 | { 0 }, |
| | 80 | }; |
| | 81 | |
| | 82 | |
| | 83 | static ctl_table sensors_proc[] = { |
| | 84 | { CTL_DEV, "dev", NULL, 0, 0555, sensors_proc_dev }, |
| | 85 | { 0 } |
| | 86 | }; |
| | 87 | |
| | 88 | |
| | 89 | static struct ctl_table_header *sensors_proc_header; |
| | 90 | static int sensors_initialized; |
| | 235 | |
| | 236 | int 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 | |
| | 271 | int 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 | |