diff --git a/AUTHORS b/AUTHORS index 541a499e..baf1482b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -22,6 +22,9 @@ Curtis Gedak * Created OperationLabelPartition.h, OperationLabelPartition.cc * Maintained from official 0.3.5 release onward +Colin Watson + * Wrote patch to recognize /dev/mapper/* devices + Michael Monreal * Wrote small patch to implement themed app icon in hicolor diff --git a/ChangeLog b/ChangeLog index 82c4a6b5..736a0bc8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-10-15 Curtis Gedak + + * src/GParted_Core.cc: 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. + - Closes GParted bug #556114 + 2008-10-14 Curtis Gedak * src/Dialog_Progress.cc: Enhanced detail log to pass as XHTML diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 135a0fd4..237e49a7 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -38,8 +38,14 @@ #include "../include/reiser4.h" #include "../include/ufs.h" +#include #include +#include #include +#include +#include +#include +#include std::vector libparted_messages ; //see ped_exception_handler() @@ -136,7 +142,11 @@ void GParted_Core::set_devices( std::vector & devices ) { 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 @@ void GParted_Core::set_devices( std::vector & devices ) } } proc_partitions .close() ; + + std::set 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 {