[partition] Implement other way of getting partitions
- Just read /proc/partitions and process it; split into columns, add relevant bits. - This implementation supports devices named "name", which the other didn't (but that would be really weird). The tests now pass.
This commit is contained in:
parent
d16c75b15c
commit
f2438a5bf4
@ -34,6 +34,28 @@ getPartitionsForDevice_other(const QString& deviceName)
|
||||
{
|
||||
QStringList partitions;
|
||||
|
||||
QFile dev_partitions( "/proc/partitions" );
|
||||
if ( dev_partitions.open( QFile::ReadOnly ) )
|
||||
{
|
||||
cDebug() << "Reading from" << dev_partitions.fileName();
|
||||
QTextStream in( &dev_partitions );
|
||||
(void) in.readLine(); // That's the header line, skip it
|
||||
while ( !in.atEnd() )
|
||||
{
|
||||
// The fourth column (index from 0, so index 3) is the name of the device;
|
||||
// keep it if it is followed by something.
|
||||
QStringList columns = in.readLine().split( ' ', QString::SkipEmptyParts );
|
||||
if ( ( columns.count() >= 4 ) && ( columns[3].startsWith( deviceName ) ) && ( columns[3] != deviceName ) )
|
||||
{
|
||||
partitions.append( columns[3] );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cDebug() << "Could not open" << dev_partitions.fileName();
|
||||
}
|
||||
|
||||
return partitions;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user