[gparted] Improve dmraid device detection with checking udev if needed



commit ce4de8b51e9ffd91ba192863eff4de652a4946dc
Author: Curtis Gedak <gedakc gmail com>
Date:   Sun Apr 26 16:45:53 2009 -0600

    Improve dmraid device detection with checking udev if needed
    
    Some distros appear to display /dev/dm-# device names with
    libparted.  Since this fails a pattern match with the dmraid
    device name, check with udev to see if a pattern match is
    possible with the name returned from udevinfo or udevadm info.
    
    For example:
         /dev/mapper/isw_cjbdddajhi_Vol0 is the device name
         /dev/dm-0 is a symbolic link pointing to the above device name
---
 include/DMRaid.h |    2 ++
 src/DMRaid.cc    |   26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/include/DMRaid.h b/include/DMRaid.h
index 24aa4c7..21c3188 100644
--- a/include/DMRaid.h
+++ b/include/DMRaid.h
@@ -71,6 +71,8 @@ private:
 	static bool dmraid_found ;
 	static bool dmsetup_found ;
 	static bool kpartx_found ;
+	static bool udevinfo_found ;
+	static bool udevadm_found ;
 	static std::vector<Glib::ustring> dmraid_devices ;
 };
 
diff --git a/src/DMRaid.cc b/src/DMRaid.cc
index 3a62c37..8312d81 100644
--- a/src/DMRaid.cc
+++ b/src/DMRaid.cc
@@ -27,6 +27,8 @@ bool DMRaid::dmraid_cache_initialized = false ;
 bool DMRaid::dmraid_found  = false ;
 bool DMRaid::dmsetup_found = false ;
 bool DMRaid::kpartx_found  = false ;
+bool DMRaid::udevinfo_found = false ;
+bool DMRaid::udevadm_found  = false ;
 std::vector<Glib::ustring> DMRaid::dmraid_devices ;
 
 DMRaid::DMRaid()
@@ -82,6 +84,8 @@ void DMRaid::set_commands_found()
 	dmraid_found = (! Glib::find_program_in_path( "dmraid" ) .empty() ) ;
 	dmsetup_found = (! Glib::find_program_in_path( "dmsetup" ) .empty() ) ;
 	kpartx_found = (! Glib::find_program_in_path( "kpartx" ) .empty() ) ;
+	udevinfo_found = (! Glib::find_program_in_path( "udevinfo" ) .empty() ) ;
+	udevadm_found = (! Glib::find_program_in_path( "udevadm" ) .empty() ) ;
 }
 
 bool DMRaid::is_dmraid_supported()
@@ -102,6 +106,28 @@ bool DMRaid::is_dmraid_device( const Glib::ustring & dev_path )
 				device_found = true ;
 	}
 
+	//Some distros appear to default to /dev/dm-# for device names, so
+	//  also check with udev to see if they are in fact dmraid devices
+	if ( ! device_found && ( dev_path .find( "/dev/dm" ) != Glib::ustring::npos ) )
+	{
+		Glib::ustring output = "" ;
+		Glib::ustring error  = "" ;
+		Glib::ustring alt_udev_path = "" ;
+		if ( udevinfo_found )
+			if ( ! Utils::execute_command( "udevinfo --query=name --name=" + dev_path, output, error, true ) )
+				alt_udev_path = output ;
+		else if ( udevadm_found )
+			if ( ! Utils::execute_command( "udevadm info --query=name --name=" + DEV_MAP_PATH + dev_path, output, error, true ) )
+				alt_udev_path = output ;
+		if ( ! alt_udev_path .empty() )
+		{
+			for ( unsigned int k=0; k < dmraid_devices .size(); k++ )
+				if ( alt_udev_path .find( dmraid_devices[k] ) != Glib::ustring::npos )
+					device_found = true ;
+					
+		}
+	}
+
 	return device_found ;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]