Blob Blame History Raw
From 4a19168dbd3949a4d5b7fd69fd6d646652f63ea3 Mon Sep 17 00:00:00 2001
From: Lyonel Vincent <lyonel@ezix.org>
Date: Tue, 16 Aug 2016 23:34:44 +0200
Subject: [PATCH 11/43] report modalias information for PCI and network devices

cf. http://www.linuxfromscratch.org/lfs/view/development/chapter07/udev.html
---
 src/core/network.cc | 1 +
 src/core/pci.cc     | 5 +++++
 src/core/sysfs.cc   | 4 ++++
 src/core/sysfs.h    | 1 +
 4 files changed, 11 insertions(+)

diff --git a/src/core/network.cc b/src/core/network.cc
index 15a961d..77233fc 100644
--- a/src/core/network.cc
+++ b/src/core/network.cc
@@ -337,6 +337,7 @@ bool scan_network(hwNode & n)
 
       string businfo = sysfs::entry::byClass("net", interface.getLogicalName()).businfo();
       interface.setBusInfo(businfo);
+      interface.setConfig("modalias", sysfs::entry::byClass("net", interface.getLogicalName()).modalias());
 
 //scan_mii(fd, interface);
       scan_ip(interface);
diff --git a/src/core/pci.cc b/src/core/pci.cc
index fab6fd2..f667f89 100644
--- a/src/core/pci.cc
+++ b/src/core/pci.cc
@@ -3,6 +3,7 @@
 #include "pci.h"
 #include "osutils.h"
 #include "options.h"
+#include "sysfs.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -1147,6 +1148,10 @@ bool scan_pci(hwNode & n)
           device->claim();
         }
 
+	string modalias = sysfs::entry::byBus("pci", devices[i]->d_name).modalias();
+	if(modalias!="")
+		device->setConfig("modalias", modalias);
+
         if(exists(resourcename))
         {
             FILE*resource = fopen(resourcename.c_str(), "r");
diff --git a/src/core/sysfs.cc b/src/core/sysfs.cc
index acc9d00..2b09554 100644
--- a/src/core/sysfs.cc
+++ b/src/core/sysfs.cc
@@ -298,6 +298,10 @@ entry entry::parent() const
   return e;
 }
 
+string entry::modalias() const
+{
+  return get_string(This->devpath+"/modalias");
+}
 
 vector < entry > sysfs::entries_by_bus(const string & busname)
 {
diff --git a/src/core/sysfs.h b/src/core/sysfs.h
index a9dc573..d37e2d4 100644
--- a/src/core/sysfs.h
+++ b/src/core/sysfs.h
@@ -24,6 +24,7 @@ namespace sysfs
       string name() const;
       string businfo() const;
       string driver() const;
+      string modalias() const;
       entry parent() const;
       string name_in_class(const string &) const;
 
-- 
2.10.2