backport r1070840: work around libparted segfaults and problems

svn path=/branches/partitionmanager/1.0/partitionmanager/; revision=1070842
This commit is contained in:
Volker Lanz 2010-01-06 22:00:34 +00:00
parent e7fcc10b4c
commit 8f67e3e22c
1 changed files with 30 additions and 1 deletions

View File

@ -38,6 +38,7 @@
#include <QList>
#include <QFile>
#include <QMap>
#include <QRegExp>
#include <kdebug.h>
#include <klocale.h>
@ -266,7 +267,35 @@ void LibParted::scanDevices(OperationStack& ostack)
ostack.clearOperations();
ostack.clearDevices();
ped_device_probe_all();
// LibParted's ped_device_probe_all()
// 1) segfaults when it finds "illegal" entries in /dev/mapper
// 2) takes several minutes to time out if the BIOS says there's a floppy drive present
// when in fact there is none.
// For that reason we scan devices on our own if possible, using what the kernel knows and
// tells us about in /proc/partitions.
QFile partitions("/proc/partitions");
if (partitions.open(QIODevice::ReadOnly))
{
QRegExp rxLine("\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s([^0-9]+)\\s+");
QByteArray line;
while (!(line = partitions.readLine()).isEmpty())
{
if (rxLine.indexIn(line) != -1)
{
const QString device = "/dev/" + rxLine.cap(4);
// kDebug() << "device:" << device;
ped_device_get(device.toLocal8Bit());
}
}
partitions.close();
}
else
{
log(log::information) << i18nc("@info/plain", "Probing for devices using LibParted. This may crash or take a very long time. Read the manual's FAQ section for details.");
ped_device_probe_all();
}
PedDevice* pedDevice = ped_device_get_next(NULL);