[yast-commit] r56449 - in /trunk/storage/libstorage/src: ProcPart.cc ProcPart.h Storage.cc
Author: aschnell Date: Fri Mar 27 16:48:22 2009 New Revision: 56449 URL: http://svn.opensuse.org/viewcvs/yast?rev=56449&view=rev Log: - remember onlt size not complete line in ProcPart - cleanup Modified: trunk/storage/libstorage/src/ProcPart.cc trunk/storage/libstorage/src/ProcPart.h trunk/storage/libstorage/src/Storage.cc Modified: trunk/storage/libstorage/src/ProcPart.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/ProcPart.cc?rev=56449&r1=56448&r2=56449&view=diff ============================================================================== --- trunk/storage/libstorage/src/ProcPart.cc (original) +++ trunk/storage/libstorage/src/ProcPart.cc Fri Mar 27 16:48:22 2009 @@ -3,11 +3,11 @@ Textdomain "storage" */ -#include <sstream> #include "y2storage/AppUtil.h" #include "y2storage/Regex.h" #include "y2storage/StorageTmpl.h" +#include "y2storage/AsciiFile.h" #include "y2storage/ProcPart.h" @@ -16,69 +16,59 @@ using namespace std; -ProcPart::ProcPart() : AsciiFile( "/proc/partitions" ) + ProcPart::ProcPart() { - y2mil( "numLines " << numLines() ); - for( unsigned i=0; i<numLines(); i++ ) - { - y2mil( "line " << (i+1) << " is \"" << (*this)[i] << "\"" ); - string tmp = extractNthWord( 3, (*this)[i] ); - if( !tmp.empty() && tmp!="name" ) - { - co[tmp] = i; - } - } + reload(); } -bool -ProcPart::getInfo( const string& Dev, unsigned long long& SizeK, - unsigned long& Major, unsigned long& Minor ) const + + void + ProcPart::reload() { - bool ret = false; - map<string,int>::const_iterator i = co.find( devName(Dev) ); - if( i != co.end() ) + data.clear(); + + AsciiFile file("/proc/partitions"); + const vector<string>& lines = file.lines(); + + for (vector<string>::const_iterator it = lines.begin(); it != lines.end(); ++it) { - extractNthWord( 0, (*this)[i->second] ) >> Major; - extractNthWord( 1, (*this)[i->second] ) >> Minor; - extractNthWord( 2, (*this)[i->second] ) >> SizeK; - ret = true; + string device = extractNthWord(3, *it); + if (!device.empty() && device != "name") + { + unsigned long long sizeK; + extractNthWord(2, *it) >> sizeK; + data[device] = sizeK; + } } - return( ret ); } -bool -ProcPart::getSize( const string& Dev, unsigned long long& SizeK ) const + + bool + ProcPart::getSize(const string& device, unsigned long long& sizeK) const { - bool ret = false; - map<string,int>::const_iterator i = co.find( devName(Dev) ); - if( i != co.end() ) + bool ret = false; + map<string, unsigned long long>::const_iterator i = data.find(undevDevice(device)); + if (i != data.end()) { - extractNthWord( 2, (*this)[i->second] ) >> SizeK; - ret = true; + sizeK = i->second; + ret = true; } - y2mil( "dev:" << Dev << " ret:" << ret << " Size:" << (ret?SizeK:0) ); - return( ret ); + y2mil("dev:" << device << " ret:" << ret << " sizeK:" << (ret ? sizeK : 0)); + return ret; } -string -ProcPart::devName( const string& Dev ) - { - return( undevDevice( Dev )); - } -list<string> -ProcPart::getMatchingEntries( const string& regexp ) const + list<string> + ProcPart::getMatchingEntries(const string& regexp) const { - Regex reg( "^" + regexp + "$" ); - list<string> ret; - for( map<string,int>::const_iterator i=co.begin(); i!=co.end(); i++ ) + Regex reg("^" + regexp + "$"); + list<string> ret; + for (map<string, unsigned long long>::const_iterator i = data.begin(); i != data.end(); ++i) { - if( reg.match( i->first )) - { - ret.push_back( i->first ); - } + if (reg.match(i->first)) + ret.push_back(i->first); } - return( ret ); + return ret; } } Modified: trunk/storage/libstorage/src/ProcPart.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/ProcPart.h?rev=56449&r1=56448&r2=56449&view=diff ============================================================================== --- trunk/storage/libstorage/src/ProcPart.h (original) +++ trunk/storage/libstorage/src/ProcPart.h Fri Mar 27 16:48:22 2009 @@ -1,28 +1,38 @@ #ifndef PROC_PART_H #define PROC_PART_H + #include <string> #include <list> #include <map> -#include "y2storage/AsciiFile.h" namespace storage { + using std::string; + using std::list; + using std::map; + -class ProcPart : public AsciiFile + class ProcPart { public: + ProcPart(); - bool getInfo( const string& Dev, unsigned long long& SizeK, - unsigned long& Major, unsigned long& Minor ) const; - bool getSize( const string& Dev, unsigned long long& SizeK ) const; - std::list<string> getMatchingEntries( const string& regexp ) const; + + void reload(); + + bool getSize(const string& device, unsigned long long& sizeK) const; + + list<string> getMatchingEntries(const string& regexp) const; + protected: - static string devName( const string& Dev ); - std::map<string,int> co; + + map<string, unsigned long long> data; + }; } + #endif Modified: trunk/storage/libstorage/src/Storage.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Storage.cc?rev=56449&r1=56448&r2=56449&view=diff ============================================================================== --- trunk/storage/libstorage/src/Storage.cc (original) +++ trunk/storage/libstorage/src/Storage.cc Fri Mar 27 16:48:22 2009 @@ -199,22 +199,21 @@ } void Storage::detectObjects() - { - ProcPart* ppart = new ProcPart; - detectDisks( *ppart ); +{ + ProcPart ppart; + detectDisks(ppart); if( instsys() ) { DmraidCo::activate( true ); MdCo::activate( true, tmpDir() ); LvmVg::activate( true ); - delete ppart; - ppart = new ProcPart; + ppart.reload(); } detectMds(); - detectDmraid( *ppart ); - detectDmmultipath( *ppart ); + detectDmraid(ppart); + detectDmmultipath(ppart); detectLvmVgs(); - detectDm( *ppart ); + detectDm(ppart); LvmVgPair p = lvgPair(); y2mil( "p length:" << p.length() ); @@ -235,7 +234,7 @@ else { fstab = new EtcFstab( "/etc", isRootMounted() ); - detectLoops( *ppart ); + detectLoops(ppart); ProcMounts pm( this ); if( !instsys() ) detectNfs( pm ); @@ -251,7 +250,6 @@ rm.execute(MDADMBIN " --stop " + quote("/dev/" + extractNthWord(0, c.getLine(i)))); } } - delete ppart; } void Storage::deleteClist( CCont& co ) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
aschnell@svn.opensuse.org