1 #include <asm/byteorder.h>
7 #include <talloc/talloc.h>
12 static int filter_sensors(const struct dirent *ent)
14 /* Check for prefix "sensor@" */
15 return strncmp(ent->d_name, "sensor@", strlen("sensor@")) == 0;
18 int get_ipmi_sensor(void *t, enum ipmi_sensor_ids sensor_id)
21 struct dirent **namelist;
23 const char sensor_dir[] = "/proc/device-tree/bmc/sensors/";
25 n = scandir(sensor_dir, &namelist, filter_sensors, alphasort);
30 filename = talloc_asprintf(t, "%s%s/ipmi-sensor-type",
31 sensor_dir, namelist[n]->d_name);
32 rc = read_file(t, filename, &buf, &len);
33 if (rc == 0 && len == 4 &&
34 __be32_to_cpu(*(uint32_t *)buf) == sensor_id)
43 filename = talloc_asprintf(t, "%s%s/reg", sensor_dir,
45 /* Free the rest of the scandir strings, if there are any */
50 rc = read_file(t, filename, &buf, &len);
51 if (rc != 0 || len != 4) {
56 rc = __be32_to_cpu(*(uint32_t *)buf);