diff --git a/include/BlockSpecial.h b/include/BlockSpecial.h index 71f3357e..b05f4dac 100644 --- a/include/BlockSpecial.h +++ b/include/BlockSpecial.h @@ -43,6 +43,8 @@ public: unsigned long m_minor; // {"", 0, 0}. static void clear_cache(); + static void register_block_special( const Glib::ustring & name, + unsigned long major, unsigned long minor ); }; // Operator overloading > The Decision between Member and Non-member diff --git a/src/BlockSpecial.cc b/src/BlockSpecial.cc index ed6ff71b..2481e02f 100644 --- a/src/BlockSpecial.cc +++ b/src/BlockSpecial.cc @@ -79,6 +79,16 @@ void BlockSpecial::clear_cache() mm_number_cache.clear(); } +void BlockSpecial::register_block_special( const Glib::ustring & name, + unsigned long major, unsigned long minor ) +{ + MM_Number pair; + pair.m_major = major; + pair.m_minor = minor; + // Add new, or update existing, cache entry for name to major, minor pair + mm_number_cache[name] = pair; +} + bool operator==( const BlockSpecial & lhs, const BlockSpecial & rhs ) { if ( lhs.m_major > 0UL && lhs.m_minor > 0UL ) diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index ade2ab4e..38d4d9c2 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -169,7 +169,8 @@ void GParted_Core::set_devices_thread( std::vector * pdevices ) BlockSpecial::clear_cache(); // MUST BE FIRST. Cache of name to major, minor // numbers incrementally loaded when BlockSpecial // objects are created in the following caches. - Proc_Partitions_Info pp_info( true ) ; //Refresh cache of proc partition information + Proc_Partitions_Info pp_info( true ) ; // SHOULD BE SECOND. Caches /proc/partitions and + // pre-populates BlockSpecial cache. FS_Info fs_info( true ) ; //Refresh cache of file system information DMRaid dmraid( true ) ; //Refresh cache of dmraid device information LVM2_PV_Info::clear_cache(); // Cache automatically loaded if and when needed diff --git a/src/Proc_Partitions_Info.cc b/src/Proc_Partitions_Info.cc index 153c0061..fd16fb61 100644 --- a/src/Proc_Partitions_Info.cc +++ b/src/Proc_Partitions_Info.cc @@ -15,11 +15,13 @@ */ #include "../include/Proc_Partitions_Info.h" +#include "../include/BlockSpecial.h" #include "../include/Utils.h" #include #include #include +#include namespace GParted { @@ -73,10 +75,23 @@ void Proc_Partitions_Info::load_proc_partitions_info_cache() std::string line ; Glib::ustring device; - // Read whole disk device names, excluding partitions, from - // /proc/partitions and save in this cache. while ( getline( proc_partitions, line ) ) { + // Pre-populate BlockSpecial cache with major, minor numbers of + // all names found from /proc/partitions. + Glib::ustring name = Utils::regexp_label( line, + "^[[:blank:]]*[[:digit:]]+[[:blank:]]+[[:digit:]]+[[:blank:]]+[[:digit:]]+[[:blank:]]+([[:graph:]]+)$" ); + if ( name == "" ) + continue; + unsigned long maj; + unsigned long min; + if ( sscanf( line.c_str(), "%lu %lu", &maj, &min ) != 2 ) + continue; + BlockSpecial::register_block_special( "/dev/" + name, maj, min ); + + // Recognise only whole disk device names, excluding partitions, + // from /proc/partitions and save in this cache. + //Whole disk devices are the ones we want. //Device names without a trailing digit refer to the whole disk. device = Utils::regexp_label(line, "^[\t ]+[0-9]+[\t ]+[0-9]+[\t ]+[0-9]+[\t ]+([^0-9]+)$") ;