From 6b772f33323db15610cfa39519465aa9b0e518f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Thu, 28 Apr 2016 22:38:38 +0100 Subject: [PATCH] Optimize luks::mapperName function. Now it uses lsblk to find out mapper node. It also makes opened luks volumes to be properly detected when no cryptsetup is found, e.g. crypt is opened in initramfs. --- src/fs/luks.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/fs/luks.cpp b/src/fs/luks.cpp index cfef42d..9754a94 100644 --- a/src/fs/luks.cpp +++ b/src/fs/luks.cpp @@ -511,18 +511,16 @@ bool luks::updateUUID(Report& report, const QString& deviceNode) const QString luks::mapperName(const QString& deviceNode) { - ExternalCommand cmd(QStringLiteral("find"), - { QStringLiteral("/dev/mapper/"), - QStringLiteral("-exec"), - QStringLiteral("cryptsetup"), - QStringLiteral("status"), - QStringLiteral("{}"), - QStringLiteral(";") }); - if (cmd.run()) { - QRegExp rxDeviceName(QStringLiteral("(/dev/mapper/[A-Za-z0-9-/]+) is " - "active[A-Za-z0-9- \\.\n]+[A-Za-z0-9-: \n]+") + deviceNode); - if (rxDeviceName.indexIn(cmd.output()) > -1) - return rxDeviceName.cap(1); + ExternalCommand cmd(QStringLiteral("lsblk"), + { QStringLiteral("--raw"), + QStringLiteral("--noheadings"), + QStringLiteral("--output"), + QStringLiteral("name"), + deviceNode }); + if (cmd.run(-1) && cmd.exitCode() == 0) { + QStringList output=cmd.output().split(QStringLiteral("\n")); + output.removeFirst(); + return QStringLiteral("/dev/mapper/") + output.first(); } return QString(); }