ac51452
### Eclipse Workspace Patch 1.0
ac51452
#P lsvpd-new
ac51452
ac51452
Add ids file lookup to runtime.
ac51452
ac51452
Currently the pci.ids and usb.ids files are located by the Makefile
ac51452
and the location defined by the build.  This presents a problem when
ac51452
the build system has the files in a different location from the host.
ac51452
This patch addresses this problem by moving the logic to locate the
ac51452
ids files into the vpdupdate code.
ac51452
ac51452
Signed-off-by: Eric B Munson <ebmunson@us.ibm.com>
ac51452
ac51452
---
ac51452
ac51452
Index: src/include/devicelookup.hpp
ac51452
===================================================================
ac51452
RCS file: /cvsroot/lsvpd/lsvpd-new/src/include/devicelookup.hpp,v
ac51452
retrieving revision 1.1
ac51452
diff -u -r1.1 devicelookup.hpp
ac51452
--- src/include/devicelookup.hpp	18 Feb 2008 19:45:54 -0000	1.1
ac51452
+++ src/include/devicelookup.hpp	16 Oct 2009 09:35:42 -0000
ac51452
@@ -58,7 +58,11 @@
ac51452
 
ac51452
 			void fillManus( ifstream& idFile );
ac51452
 
ac51452
+			static void findIdsPrefix( );
ac51452
+			
ac51452
 		public:
ac51452
+			static string idsPrefix;
ac51452
+		
ac51452
 			DeviceLookup( ifstream& idFile );
ac51452
 			~DeviceLookup( );
ac51452
 			const Manufacturer* getManufacturer( int id ) const;
ac51452
@@ -99,8 +103,8 @@
ac51452
 			 */
ac51452
 			const string& getName( int manID, int devID, int subID )const;
ac51452
 
ac51452
-			static const string PCI_ID_FILE;
ac51452
-			static const string USB_ID_FILE;
ac51452
+			static string getPciIds( );
ac51452
+			static string getUsbIds( );
ac51452
 	};
ac51452
 }
ac51452
 #endif
ac51452
Index: src/internal/sys_interface/sysfstreecollector.cpp
ac51452
===================================================================
ac51452
RCS file: /cvsroot/lsvpd/lsvpd-new/src/internal/sys_interface/sysfstreecollector.cpp,v
ac51452
retrieving revision 1.11
ac51452
diff -u -r1.11 sysfstreecollector.cpp
ac51452
--- src/internal/sys_interface/sysfstreecollector.cpp	16 Mar 2009 13:24:48 -0000	1.11
ac51452
+++ src/internal/sys_interface/sysfstreecollector.cpp	16 Oct 2009 09:35:43 -0000
ac51452
@@ -77,7 +77,7 @@
ac51452
 		mPciTable = NULL;
ac51452
 		mUsbTable = NULL;
ac51452
 
ac51452
-		id.open( DeviceLookup::PCI_ID_FILE.c_str( ), ios::in );
ac51452
+		id.open( DeviceLookup::getPciIds( ).c_str( ), ios::in );
ac51452
 		if( id )
ac51452
 		{
ac51452
 			mPciTable = new DeviceLookup( id );
ac51452
@@ -91,7 +91,7 @@
ac51452
 				LOG_ERR );
ac51452
 		}
ac51452
 
ac51452
-		id.open( DeviceLookup::USB_ID_FILE.c_str( ), ios::in );
ac51452
+		id.open( DeviceLookup::getUsbIds( ).c_str( ), ios::in );
ac51452
 		if( id )
ac51452
 		{
ac51452
 			mUsbTable = new DeviceLookup( id );
ac51452
Index: src/internal/devicelookup.cpp
ac51452
===================================================================
ac51452
RCS file: /cvsroot/lsvpd/lsvpd-new/src/internal/devicelookup.cpp,v
ac51452
retrieving revision 1.2
ac51452
diff -u -r1.2 devicelookup.cpp
ac51452
--- src/internal/devicelookup.cpp	18 Feb 2008 19:45:54 -0000	1.2
ac51452
+++ src/internal/devicelookup.cpp	16 Oct 2009 09:35:43 -0000
ac51452
@@ -27,6 +27,8 @@
ac51452
 #include <libvpd-2/vpdexception.hpp>
ac51452
 #include <libvpd-2/lsvpd.hpp>
ac51452
 
ac51452
+#include <sys/stat.h>
ac51452
+
ac51452
 /**
ac51452
  * The Manufacturer object will store the id and name of a single manufacturer
ac51452
  * entry from the pci.ids file.  It will also store a hash_map of devices
ac51452
@@ -34,8 +36,6 @@
ac51452
  */
ac51452
 namespace lsvpd
ac51452
 {
ac51452
-	const string DeviceLookup::PCI_ID_FILE( PCI_IDS );
ac51452
-	const string DeviceLookup::USB_ID_FILE( USB_IDS );
ac51452
 
ac51452
 	DeviceLookup::DeviceLookup( ifstream& pciID )
ac51452
 	{
ac51452
@@ -119,4 +119,45 @@
ac51452
 		const Device* d = m->getDevice( devID );
ac51452
 		return (d->getSubDevice( subID ))->getName( );
ac51452
 	}
ac51452
+	
ac51452
+	void DeviceLookup::findIdsPrefix( )
ac51452
+	{
ac51452
+		// There are 6 potential locations for the ids files:
ac51452
+		// /usr/share, /usr/local/share, /usr/share/misc,
ac51452
+		// /usr/local/share/misc, /usr/share/hwdata,
ac51452
+		// and /usr/local/share/hwdata
ac51452
+		
ac51452
+		struct stat buf;
ac51452
+		
ac51452
+		if ( !stat( "/usr/share/pci.ids", &buf ) )
ac51452
+			DeviceLookup::idsPrefix = "/usr/share";
ac51452
+		else if ( !stat( "/usr/local/share/pci.ids", &buf ) )
ac51452
+			DeviceLookup::idsPrefix = "/usr/local/share";
ac51452
+		else if ( !stat( "/usr/share/misc/pci.ids", &buf ) )
ac51452
+			DeviceLookup::idsPrefix = "/usr/share/misc";
ac51452
+		else if ( !stat( "/usr/local/share/misc/pci.ids", &buf ) )
ac51452
+			DeviceLookup::idsPrefix = "/usr/local/share/misc";
ac51452
+		else if ( !stat( "/usr/share/hwdata/pci.ids", &buf ) )
ac51452
+			DeviceLookup::idsPrefix = "/usr/share/hwdata";
ac51452
+		else if ( !stat( "/usr/local/share/hwdata/pci.ids", &buf ) )
ac51452
+			DeviceLookup::idsPrefix = "/usr/local/share/hwdata";
ac51452
+	}
ac51452
+	
ac51452
+	string DeviceLookup::getPciIds( )
ac51452
+	{
ac51452
+		if ( DeviceLookup::idsPrefix == "" )
ac51452
+			DeviceLookup::findIdsPrefix( );
ac51452
+			
ac51452
+		return DeviceLookup::idsPrefix + "/pci.ids";
ac51452
+	}
ac51452
+	
ac51452
+	string DeviceLookup::getUsbIds( )
ac51452
+	{
ac51452
+		if ( DeviceLookup::idsPrefix == "" )
ac51452
+			findIdsPrefix( );
ac51452
+			
ac51452
+		return DeviceLookup::idsPrefix + "/usb.ids";
ac51452
+	}
ac51452
+	
ac51452
+	string DeviceLookup::idsPrefix = "";
ac51452
 }