Print more info about LUKS partitions in the infopane.

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1325759
This commit is contained in:
Andrius Štikonas 2012-11-21 00:54:04 +00:00
parent f4e7603a41
commit 39dc9c5c46
3 changed files with 92 additions and 7 deletions

View File

@ -20,6 +20,7 @@
#include "fs/luks.h"
#include "util/capacity.h"
#include "util/externalcommand.h"
#include <QString>
@ -51,4 +52,64 @@ namespace FS
{
return Capacity::unitFactor(Capacity::Byte, Capacity::EiB);
}
QString luks::getCipherName(const QString& deviceNode)
{
ExternalCommand cmd("cryptsetup", QStringList() << "luksDump" << deviceNode);
if (cmd.run())
{
QRegExp rxCipherName("(?:Cipher name:\\s+)([A-Za-z0-9-]+)");
if (rxCipherName.indexIn(cmd.output()) > -1)
return rxCipherName.cap(1);
}
return "---";
}
QString luks::getCipherMode(const QString& deviceNode)
{
ExternalCommand cmd("cryptsetup", QStringList() << "luksDump" << deviceNode);
if (cmd.run())
{
QRegExp rxCipherMode("(?:Cipher mode:\\s+)([A-Za-z0-9-]+)");
if (rxCipherMode.indexIn(cmd.output()) > -1)
return rxCipherMode.cap(1);
}
return "---";
}
QString luks::getHashName(const QString& deviceNode)
{
ExternalCommand cmd("cryptsetup", QStringList() << "luksDump" << deviceNode);
if (cmd.run())
{
QRegExp rxHash("(?:Hash spec:\\s+)([A-Za-z0-9-]+)");
if (rxHash.indexIn(cmd.output()) > -1)
return rxHash.cap(1);
}
return "---";
}
QString luks::getKeySize(const QString& deviceNode)
{
ExternalCommand cmd("cryptsetup", QStringList() << "luksDump" << deviceNode);
if (cmd.run())
{
QRegExp rxKeySize("(?:MK bits:\\s+)(\\d+)");
if (rxKeySize.indexIn(cmd.output()) > -1)
return rxKeySize.cap(1);
}
return "---";
}
QString luks::getPayloadOffset(const QString& deviceNode)
{
ExternalCommand cmd("cryptsetup", QStringList() << "luksDump" << deviceNode);
if (cmd.run())
{
QRegExp rxPayloadOffset("(?:Payload offset:\\s+)(\\d+)");
if (rxPayloadOffset.indexIn(cmd.output()) > -1)
return rxPayloadOffset.cap(1);
}
return "---";
}
}

View File

@ -60,6 +60,12 @@ namespace FS
virtual qint64 maxCapacity() const;
virtual bool supportToolFound() const { return true; }
static QString getCipherName (const QString& deviceNode);
static QString getCipherMode (const QString& deviceNode);
static QString getHashName (const QString& deviceNode);
static QString getKeySize (const QString& deviceNode);
static QString getPayloadOffset (const QString& deviceNode);
public:
static CommandSupportType m_GetUsed;
static CommandSupportType m_GetLabel;

View File

@ -23,6 +23,7 @@
#include "core/partition.h"
#include "fs/filesystem.h"
#include "fs/luks.h"
#include "util/capacity.h"
@ -113,13 +114,30 @@ void InfoPane::showPartition(Qt::DockWidgetArea area, const Partition& p)
int x = 0;
int y = createHeader(p.deviceNode(), cols(area));
createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), cols(area), x, y);
createLabels(i18nc("@label partition", "Capacity:"), Capacity::formatByteSize(p.capacity()), cols(area), x, y);
createLabels(i18nc("@label partition", "Available:"), Capacity::formatByteSize(p.available()), cols(area), x, y);
createLabels(i18nc("@label partition", "Used:"), Capacity::formatByteSize(p.used()), cols(area), x, y);
createLabels(i18nc("@label partition", "First sector:"), KGlobal::locale()->formatNumber(p.firstSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Last sector:"), KGlobal::locale()->formatNumber(p.lastSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Number of sectors:"), KGlobal::locale()->formatNumber(p.length(), 0), cols(area), x, y);
if (p.fileSystem().name() == "luks")
{
QString deviceNode = p.devicePath() + QString::number(p.number());
createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), cols(area), x, y);
createLabels(i18nc("@label partition", "Capacity:"), Capacity::formatByteSize(p.capacity()), cols(area), x, y);
createLabels(i18nc("@label partition", "Cipher name:"), FS::luks::getCipherName(deviceNode), cols(area), x, y);
createLabels(i18nc("@label partition", "Cipher mode:"), FS::luks::getCipherMode(deviceNode), cols(area), x, y);
createLabels(i18nc("@label partition", "Hash:"), FS::luks::getHashName(deviceNode), cols(area), x, y);
createLabels(i18nc("@label partition", "Key size:"), FS::luks::getKeySize(deviceNode), cols(area), x, y);
createLabels(i18nc("@label partition", "Payload offset:"), FS::luks::getPayloadOffset(deviceNode), cols(area), x, y);
createLabels(i18nc("@label partition", "First sector:"), KGlobal::locale()->formatNumber(p.firstSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Last sector:"), KGlobal::locale()->formatNumber(p.lastSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Number of sectors:"), KGlobal::locale()->formatNumber(p.length(), 0), cols(area), x, y);
}
else
{
createLabels(i18nc("@label partition", "File system:"), p.fileSystem().name(), cols(area), x, y);
createLabels(i18nc("@label partition", "Capacity:"), Capacity::formatByteSize(p.capacity()), cols(area), x, y);
createLabels(i18nc("@label partition", "Available:"), Capacity::formatByteSize(p.available()), cols(area), x, y);
createLabels(i18nc("@label partition", "Used:"), Capacity::formatByteSize(p.used()), cols(area), x, y);
createLabels(i18nc("@label partition", "First sector:"), KGlobal::locale()->formatNumber(p.firstSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Last sector:"), KGlobal::locale()->formatNumber(p.lastSector(), 0), cols(area), x, y);
createLabels(i18nc("@label partition", "Number of sectors:"), KGlobal::locale()->formatNumber(p.length(), 0), cols(area), x, y);
}
}
/** Shows information about a Device in the InfoPane