gparted r933 - in trunk: . src



Author: gedakc
Date: Wed Oct 15 15:51:24 2008
New Revision: 933
URL: http://svn.gnome.org/viewvc/gparted?rev=933&view=rev

Log:
Enhanced to recognize /dev/mapper/* devices.
The move away from libparted device recognition broke recognition of /dev/mapper/* devices.  Problem now fixed.
Thanks to Colin Watson for the patch.

Modified:
   trunk/AUTHORS
   trunk/ChangeLog
   trunk/src/GParted_Core.cc

Modified: trunk/AUTHORS
==============================================================================
--- trunk/AUTHORS	(original)
+++ trunk/AUTHORS	Wed Oct 15 15:51:24 2008
@@ -22,6 +22,9 @@
 	* Created OperationLabelPartition.h, OperationLabelPartition.cc
 	* Maintained from official 0.3.5 release onward 
 
+Colin Watson		<cjwatson debian org>
+	* Wrote patch to recognize /dev/mapper/* devices
+
 Michael Monreal		<michael monreal gmx net>
 	* Wrote small patch to implement themed app icon in hicolor
 

Modified: trunk/src/GParted_Core.cc
==============================================================================
--- trunk/src/GParted_Core.cc	(original)
+++ trunk/src/GParted_Core.cc	Wed Oct 15 15:51:24 2008
@@ -38,8 +38,14 @@
 #include "../include/reiser4.h"
 #include "../include/ufs.h"
 
+#include <set>
 #include <cerrno>
+#include <cstring>
 #include <sys/statvfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
 
 std::vector<Glib::ustring> libparted_messages ; //see ped_exception_handler()
 
@@ -136,7 +142,11 @@
 	{
 		device_paths .clear() ;
 
-		//Fixme:  Remove code to read /proc/partitions when libparted bug 194 is fixed.
+		//Fixme:  Remove code to read:
+		//           /proc/partitions,
+		//           /proc/devices, and
+		//           /dev/mapper
+		//        when libparted bug 194 is fixed.
 		//        This was a problem with no floppy drive yet BIOS indicated one existed.
 		//        http://parted.alioth.debian.org/cgi-bin/trac.cgi/ticket/194
 		//
@@ -164,6 +174,51 @@
     			}
     		}
     		proc_partitions .close() ;
+
+			std::set<unsigned int> dm_majors;
+			std::ifstream proc_devices( "/proc/devices" ) ;
+			if ( proc_devices )
+			{
+				//parse device numbers from /proc/devices
+				std::string line ;
+				bool seen_bd = false ;
+				while ( getline( proc_devices, line ) )
+				{
+					if ( ! seen_bd )
+					{
+						if ( ! line .compare( 0, 14, "Block devices:" ) == 0 )
+							seen_bd = true ;
+						continue ;
+					}
+					unsigned int major ;
+					char c_str[256+1] ;
+					if ( sscanf( line .c_str(), "%u %256s", &major, c_str ) == 2 )
+						dm_majors .insert( major );
+				}
+				proc_devices .close() ;
+			}
+
+			DIR *mapper_dir = opendir( "/dev/mapper" );
+			if ( mapper_dir )
+			{
+				struct dirent *mapper_entry ;
+				while ( (mapper_entry = readdir( mapper_dir )) )
+				{
+					if ( strcmp( mapper_entry ->d_name, "." ) == 0 ||
+							strcmp( mapper_entry ->d_name, ".." ) == 0 ||
+							strcmp( mapper_entry ->d_name, "control" ) == 0 )
+						continue ;
+					std::string mapper_name = "/dev/mapper/" ;
+					mapper_name += mapper_entry ->d_name ;
+					struct stat st ;
+					if ( stat( mapper_name .c_str(), &st ) != 0 )
+						continue;
+					if ( dm_majors .find( major( st.st_rdev ) ) != dm_majors .end() )
+						//TODO avoid probing partition nodes for dmraid devices
+						ped_device_get( mapper_name .c_str() ) ;
+				}
+				closedir( mapper_dir ) ;
+			}
     	}
     	else
     	{



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