Blob Blame History Raw
### Eclipse Workspace Patch 1.0
#P lsvpd-new

Add ids file lookup to runtime.

Currently the pci.ids and usb.ids files are located by the Makefile
and the location defined by the build.  This presents a problem when
the build system has the files in a different location from the host.
This patch addresses this problem by moving the logic to locate the
ids files into the vpdupdate code.

Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>

---

Index: src/include/devicelookup.hpp
===================================================================
RCS file: /cvsroot/lsvpd/lsvpd-new/src/include/devicelookup.hpp,v
retrieving revision 1.1
diff -u -r1.1 devicelookup.hpp
--- src/include/devicelookup.hpp	18 Feb 2008 19:45:54 -0000	1.1
+++ src/include/devicelookup.hpp	16 Oct 2009 09:35:42 -0000
@@ -58,7 +58,11 @@
 
 			void fillManus( ifstream& idFile );
 
+			static void findIdsPrefix( );
+			
 		public:
+			static string idsPrefix;
+		
 			DeviceLookup( ifstream& idFile );
 			~DeviceLookup( );
 			const Manufacturer* getManufacturer( int id ) const;
@@ -99,8 +103,8 @@
 			 */
 			const string& getName( int manID, int devID, int subID )const;
 
-			static const string PCI_ID_FILE;
-			static const string USB_ID_FILE;
+			static string getPciIds( );
+			static string getUsbIds( );
 	};
 }
 #endif
Index: src/internal/sys_interface/sysfstreecollector.cpp
===================================================================
RCS file: /cvsroot/lsvpd/lsvpd-new/src/internal/sys_interface/sysfstreecollector.cpp,v
retrieving revision 1.11
diff -u -r1.11 sysfstreecollector.cpp
--- src/internal/sys_interface/sysfstreecollector.cpp	16 Mar 2009 13:24:48 -0000	1.11
+++ src/internal/sys_interface/sysfstreecollector.cpp	16 Oct 2009 09:35:43 -0000
@@ -77,7 +77,7 @@
 		mPciTable = NULL;
 		mUsbTable = NULL;
 
-		id.open( DeviceLookup::PCI_ID_FILE.c_str( ), ios::in );
+		id.open( DeviceLookup::getPciIds( ).c_str( ), ios::in );
 		if( id )
 		{
 			mPciTable = new DeviceLookup( id );
@@ -91,7 +91,7 @@
 				LOG_ERR );
 		}
 
-		id.open( DeviceLookup::USB_ID_FILE.c_str( ), ios::in );
+		id.open( DeviceLookup::getUsbIds( ).c_str( ), ios::in );
 		if( id )
 		{
 			mUsbTable = new DeviceLookup( id );
Index: src/internal/devicelookup.cpp
===================================================================
RCS file: /cvsroot/lsvpd/lsvpd-new/src/internal/devicelookup.cpp,v
retrieving revision 1.2
diff -u -r1.2 devicelookup.cpp
--- src/internal/devicelookup.cpp	18 Feb 2008 19:45:54 -0000	1.2
+++ src/internal/devicelookup.cpp	16 Oct 2009 09:35:43 -0000
@@ -27,6 +27,8 @@
 #include <libvpd-2/vpdexception.hpp>
 #include <libvpd-2/lsvpd.hpp>
 
+#include <sys/stat.h>
+
 /**
  * The Manufacturer object will store the id and name of a single manufacturer
  * entry from the pci.ids file.  It will also store a hash_map of devices
@@ -34,8 +36,6 @@
  */
 namespace lsvpd
 {
-	const string DeviceLookup::PCI_ID_FILE( PCI_IDS );
-	const string DeviceLookup::USB_ID_FILE( USB_IDS );
 
 	DeviceLookup::DeviceLookup( ifstream& pciID )
 	{
@@ -119,4 +119,45 @@
 		const Device* d = m->getDevice( devID );
 		return (d->getSubDevice( subID ))->getName( );
 	}
+	
+	void DeviceLookup::findIdsPrefix( )
+	{
+		// There are 6 potential locations for the ids files:
+		// /usr/share, /usr/local/share, /usr/share/misc,
+		// /usr/local/share/misc, /usr/share/hwdata,
+		// and /usr/local/share/hwdata
+		
+		struct stat buf;
+		
+		if ( !stat( "/usr/share/pci.ids", &buf ) )
+			DeviceLookup::idsPrefix = "/usr/share";
+		else if ( !stat( "/usr/local/share/pci.ids", &buf ) )
+			DeviceLookup::idsPrefix = "/usr/local/share";
+		else if ( !stat( "/usr/share/misc/pci.ids", &buf ) )
+			DeviceLookup::idsPrefix = "/usr/share/misc";
+		else if ( !stat( "/usr/local/share/misc/pci.ids", &buf ) )
+			DeviceLookup::idsPrefix = "/usr/local/share/misc";
+		else if ( !stat( "/usr/share/hwdata/pci.ids", &buf ) )
+			DeviceLookup::idsPrefix = "/usr/share/hwdata";
+		else if ( !stat( "/usr/local/share/hwdata/pci.ids", &buf ) )
+			DeviceLookup::idsPrefix = "/usr/local/share/hwdata";
+	}
+	
+	string DeviceLookup::getPciIds( )
+	{
+		if ( DeviceLookup::idsPrefix == "" )
+			DeviceLookup::findIdsPrefix( );
+			
+		return DeviceLookup::idsPrefix + "/pci.ids";
+	}
+	
+	string DeviceLookup::getUsbIds( )
+	{
+		if ( DeviceLookup::idsPrefix == "" )
+			findIdsPrefix( );
+			
+		return DeviceLookup::idsPrefix + "/usb.ids";
+	}
+	
+	string DeviceLookup::idsPrefix = "";
 }