diff --git a/src/core/raid/softwareraid.cpp b/src/core/raid/softwareraid.cpp index c084382..eaba9d2 100644 --- a/src/core/raid/softwareraid.cpp +++ b/src/core/raid/softwareraid.cpp @@ -369,9 +369,9 @@ QStringList SoftwareRAID::getDevicePathList(const QString &path) return result; } -bool SoftwareRAID::isRaidPath(const QString &path) +bool SoftwareRAID::isRaidPath(const QString &devicePath) { - return !getDetail(path).isEmpty(); + return !getDetail(devicePath).isEmpty(); } bool SoftwareRAID::createSoftwareRAID(Report &report, @@ -437,32 +437,20 @@ bool SoftwareRAID::reassembleSoftwareRAID(Report& report, const QString &deviceN return stopSoftwareRAID(report, deviceNode) && assembleSoftwareRAID(deviceNode); } -bool SoftwareRAID::isRaidMember(const QString &path) +QString SoftwareRAID::getRaidArrayName(const QString &partitionPath) { - QFile mdstat(QStringLiteral("/proc/mdstat")); + ExternalCommand cmd(QStringLiteral("mdadm"), + { QStringLiteral("--misc"), QStringLiteral("--query"), partitionPath }); - if (!mdstat.open(QIODevice::ReadOnly)) - return false; + if (cmd.run(-1) && cmd.exitCode() == 0) { + QRegularExpression ex(QStringLiteral("device active raid\\d+\\s([\\/\\w]+).")); + QRegularExpressionMatch match = ex.match(cmd.output()); - QTextStream stream(&mdstat); - - QString content = stream.readAll(); - - mdstat.close(); - - QRegularExpression re(QStringLiteral("(\\w+)\\[\\d+\\]")); - QRegularExpressionMatchIterator i = re.globalMatch(content); - - while (i.hasNext()) { - QRegularExpressionMatch reMatch = i.next(); - - QString match = QStringLiteral("/dev/") + reMatch.captured(1); - - if (match == path) - return true; + if (match.hasMatch()) + return match.captured(1); } - return false; + return QString(); } void SoftwareRAID::initPartitions() diff --git a/src/core/raid/softwareraid.h b/src/core/raid/softwareraid.h index c293d13..da120f7 100644 --- a/src/core/raid/softwareraid.h +++ b/src/core/raid/softwareraid.h @@ -70,7 +70,7 @@ public: static QString getUUID(const QString& path); static QStringList getDevicePathList(const QString& path); - static bool isRaidPath(const QString& path); + static bool isRaidPath(const QString& devicePath); static bool createSoftwareRAID(Report& report, const QString& name, @@ -87,7 +87,7 @@ public: static bool reassembleSoftwareRAID(Report& report, const QString& deviceNode); - static bool isRaidMember(const QString& path); + static QString getRaidArrayName(const QString& partitionPath); protected: void initPartitions() override; diff --git a/src/fs/filesystem.cpp b/src/fs/filesystem.cpp index 8de5ee4..62164c4 100644 --- a/src/fs/filesystem.cpp +++ b/src/fs/filesystem.cpp @@ -18,6 +18,7 @@ *************************************************************************/ #include "core/fstab.h" +#include "core/raid/softwareraid.h" #include "fs/filesystem.h" #include "fs/lvm2_pv.h" @@ -125,6 +126,8 @@ QString FileSystem::detectMountPoint(FileSystem* fs, const QString& partitionPat { if (fs->type() == FileSystem::Type::Lvm2_PV) return FS::lvm2_pv::getVGName(partitionPath); + else if (fs->type() == FileSystem::Type::LinuxRaidMember) + return SoftwareRAID::getRaidArrayName(partitionPath); if (partitionPath.isEmpty()) // Happens when during initial scan LUKS is closed return QString(); diff --git a/src/ops/deleteoperation.cpp b/src/ops/deleteoperation.cpp index d1ec00c..2c19f65 100644 --- a/src/ops/deleteoperation.cpp +++ b/src/ops/deleteoperation.cpp @@ -125,7 +125,7 @@ bool DeleteOperation::canDelete(const Partition* p) return false; } else if (p->fileSystem().type() == FileSystem::Type::LinuxRaidMember) { - if (SoftwareRAID::isRaidMember(p->partitionPath())) + if (!SoftwareRAID::getRaidArrayName(p->partitionPath()).isEmpty()) return false; } else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { @@ -138,7 +138,7 @@ bool DeleteOperation::canDelete(const Partition* p) return false; } else if (fs->type() == FileSystem::Type::LinuxRaidMember) { - if (SoftwareRAID::isRaidMember(p->partitionPath())) + if (!SoftwareRAID::getRaidArrayName(p->partitionPath()).isEmpty()) return false; } }