libsensors: Add an interface to retrieve the kernel device name of a chip
PATCH 2/3 libsensors: Add an interface to retrieve the kernel device name of a chip
This lets applications match a kernel class device to a each chip.
--- lib/access.c | 16 +++++++++++++++- lib/libsensors.3 | 12 ++++++++++-- lib/libsensors.map | 1 + lib/sensors.h | 5 +++++ 4 files changed, 31 insertions(+), 3 deletions(-)
lib/sensors.h +5 -0
@@ -90,6 +90,11 @@ void sensors_free_chip_name(sensors_chipint sensors_snprintf_chip_name (char *str,size_t size,const sensors_chip_name *chip); +/* This returns the kernel class device associated with the given +chip name. Only works with kernel 2.6.14 and later. */ +const char * +sensors_get_kernel_name (const sensors_chip_name *chip); +/* This function returns the adapter name of a bus, as used within the sensors_chip_name structure. If it could not be found, it returns NULL */
lib/access.c +15 -1
@@ -1,7 +1,7 @@/* access.c - Part of libsensors, a Linux library for reading sensor data. Copyright (c) 1998, 1999 Frodo Looijaard <[email protected]> -Copyright (C) 2007-2010 Jean Delvare <[email protected]> +Copyright (C) 2007-2014 Jean Delvare <[email protected]> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
@@ -559,3 +559,17 @@ int sensors_do_chip_sets(const sensors_c }return res; } + +/* Would rather live in data.c, but can't be moved there as long as +we need to call sensors_lookup_chip */ +const char * +sensors_get_kernel_name (const sensors_chip_name *chip) +{ +const sensors_chip_features *chip_features; + + chip_features =sensors_lookup_chip (chip); +if (!chip_features) +return NULL ;/* No such chip */ + +return chip_features->kernel_name; +}
lib/libsensors.map +1 -0
@@ -10,6 +10,7 @@ global: sensors_get_features; sensors_get_label; sensors_get_subfeature; + sensors_get_kernel_name; sensors_get_value; sensors_init; sensors_parse_chip_name;
lib/libsensors.3 +10 -2
@@ -1,5 +1,5 @@ .\" Copyright (C) 1998, 1999 Adrian Baugh <[email protected]> -.\" Copyright (C) 2007, 2009, 2013 Jean Delvare <[email protected]> +.\" Copyright (C) 2007-2014 Jean Delvare <[email protected]> .\" based on sensors.h, part of libsensors by Frodo Looijaard .\" libsensors is distributed under the LGPL .\"
@@ -25,7 +25,7 @@ .\" .\" References consulted: .\" libsensors source code -.TH libsensors 3 "September 2013" "lm-sensors 3" "Linux Programmer's Manual" +.TH libsensors 3 "May 2014" "lm-sensors 3" "Linux Programmer's Manual" .SH NAME libsensors \- publicly accessible functions provided by the sensors library
@@ -45,6 +45,7 @@ libsensors \- publicly accessible functi .BI "void sensors_free_chip_name(sensors_chip_name *" chip ");" .BI "int sensors_snprintf_chip_name(char *" str ", size_t " size "," .BI " const sensors_chip_name *" chip ");" +.BI "const char *sensors_get_kernel_name(const sensors_chip_name *" chip ");" .BI "const char *sensors_get_adapter_name(const sensors_bus_id *" bus ");" /* Chips and features enumeration */
@@ -120,6 +121,13 @@ prints a chip name from its internal rep not contain wildcard values! Return the number of characters printed on success (same as snprintf), <0 on error. +.B sensors_get_kernel_name() +returns the name of the kernel class device associated with a given chip; +NULL is returned if no such chip exists. + +Note that this only works with kernel 2.6.14 or newer. Older kernels will +return NULL all the time. + .B sensors_get_adapter_name() returns the adapter name of a bus type, number pair, as used within the sensors_chip_name structure. If it could not be found, it returns NULL.
Signature · 7 lines
Jean Delvare SUSE L3 Support _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors