summaryrefslogtreecommitdiffstats
path: root/sysfs.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sysfs.cpp')
-rw-r--r--sysfs.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/sysfs.cpp b/sysfs.cpp
index 4ea32b2..0eb7863 100644
--- a/sysfs.cpp
+++ b/sysfs.cpp
@@ -19,6 +19,7 @@
#include <experimental/filesystem>
#include <fstream>
#include <memory>
+#include <phosphor-logging/log.hpp>
#include <thread>
#include "sysfs.hpp"
@@ -238,6 +239,43 @@ std::string findHwmonFromOFPath(const std::string& ofNode)
return emptyString;
}
+std::string findHwmonFromDevPath(const std::string& devPath)
+{
+ fs::path p{"/sys"};
+ p /= devPath;
+ p /= "hwmon";
+
+ try
+ {
+ //This path is also used as a filesystem path to an environment
+ //file, and that has issues with ':'s in the path so they've
+ //been converted to '--'s. Convert them back now.
+ size_t pos = 0;
+ std::string path = p;
+ while ((pos = path.find("--")) != std::string::npos)
+ {
+ path.replace(pos, 2, ":");
+ }
+
+ for (const auto& hwmonInst : fs::directory_iterator(path))
+ {
+ if ((hwmonInst.path().filename().string().find("hwmon") !=
+ std::string::npos))
+ {
+ return hwmonInst.path();
+ }
+ }
+ }
+ catch (const std::exception& e)
+ {
+ using namespace phosphor::logging;
+ log<level::ERR>(
+ "Unable to find hwmon directory from the dev path",
+ entry("PATH=%s", devPath.c_str()));
+ }
+ return emptyString;
+}
+
namespace hwmonio
{
OpenPOWER on IntegriCloud