Author: aschnell Date: Tue Mar 3 13:25:45 2009 New Revision: 55875 URL: http://svn.opensuse.org/viewcvs/yast?rev=55875&view=rev Log: - avoid calling external program Modified: trunk/storage/libstorage/src/AppUtil.cc trunk/storage/libstorage/src/AppUtil.h Modified: trunk/storage/libstorage/src/AppUtil.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AppUtil.cc?rev=55875&r1=55874&r2=55875&view=diff ============================================================================== --- trunk/storage/libstorage/src/AppUtil.cc (original) +++ trunk/storage/libstorage/src/AppUtil.cc Tue Mar 3 13:25:45 2009 @@ -21,6 +21,8 @@ #include "y2storage/StorageTmpl.h" #include "y2storage/AppUtil.h" #include "y2storage/SystemCmd.h" +#include "y2storage/StorageTypes.h" + using namespace std; @@ -486,18 +488,25 @@ } -unsigned getMajorDevices( const string& driver ) - { - unsigned ret=0; - string cmd = "grep \" " + driver + "$\" /proc/devices"; - SystemCmd c( cmd ); - if( c.numLines()>0 ) - { - extractNthWord( 0, c.getLine(0)) >> ret; - } - y2mil( "driver:" << driver << " ret:" << ret ); - return( ret ); - } +unsigned +getMajorDevices(const char* driver) +{ + unsigned ret = 0; + + AsciiFile file("/proc/devices"); + const std::vector<string>& lines = file.lines(); + + Regex rx("^" + Regex::ws + "([0-9]+)" + Regex::ws + string(driver) + "$"); + + std::vector<string>::const_iterator it = find_if(lines.begin(), lines.end(), match_regex(rx)); + if (it == lines.end()) + y2err("did not find " << driver << " in /proc/devices"); + else + rx.cap(1) >> ret; + + y2mil("driver:" << driver << " ret:" << ret); + return ret; +} string sformat(const char* format, ...) Modified: trunk/storage/libstorage/src/AppUtil.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/AppUtil.h?rev=55875&r1=55874&r2=55875&view=diff ============================================================================== --- trunk/storage/libstorage/src/AppUtil.h (original) +++ trunk/storage/libstorage/src/AppUtil.h Tue Mar 3 13:25:45 2009 @@ -44,7 +44,8 @@ string undevDevice( const string& dev ); void undevDevice( string& dev ); bool isNfsDev( const string& dev ); -unsigned getMajorDevices( const string& driver ); + +unsigned getMajorDevices(const char* driver); template<class StreamType> -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org