From 89c11567d6b16d0e85d465a1c135f1fc49522eb5 Mon Sep 17 00:00:00 2001 From: xust Date: Thu, 5 Dec 2024 20:10:48 +0800 Subject: [PATCH] fix: cannot correctly recoganize fstab partitions - remove the isFstabItem function; - add Block::Configuration filed in device properties; - initialize param.initOnly with true if Block::Configuration.contains("fstab"); Log: fix partition encrypt issue. Bug: https://pms.uniontech.com/bug-view-292155.html --- .../base/device/private/devicehelper.cpp | 16 ++++++++++++++++ .../dbusservice/global_server_defines.h | 1 + .../menu/diskencryptmenuscene.cpp | 16 +++++++++++++++- .../utils/encryptutils.cpp | 19 ------------------- .../utils/encryptutils.h | 4 ---- 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/dfm-base/base/device/private/devicehelper.cpp b/src/dfm-base/base/device/private/devicehelper.cpp index 31f34da994..04cf3a4e45 100644 --- a/src/dfm-base/base/device/private/devicehelper.cpp +++ b/src/dfm-base/base/device/private/devicehelper.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -121,6 +123,20 @@ QVariantMap DeviceHelper::loadBlockInfo(const BlockDevAutoPtr &dev) datas[kDriveModel] = getNullStrIfNotValid(Property::kDriveModel); datas[kPreferredDevice] = getNullStrIfNotValid(Property::kBlockPreferredDevice); + auto config = dev->getProperty(Property::kBlockConfiguration).toMap(); + if (!config.isEmpty()) { + QJsonObject jsonRootObj; + QMapIterator iter(config); + while (iter.hasNext()) { + iter.next(); + auto key = iter.key(); + QVariantMap value = iter.value().toMap(); + jsonRootObj.insert(key, QJsonObject::fromVariantMap(value)); + } + QJsonDocument doc(jsonRootObj); + datas[kConfiguration] = QString(doc.toJson(QJsonDocument::Compact)); + } + datas[kUDisks2Size] = dev->sizeTotal(); auto mpt = dev->mountPoint(); if (!mpt.isEmpty() && !dev->optical()) { diff --git a/src/dfm-base/dbusservice/global_server_defines.h b/src/dfm-base/dbusservice/global_server_defines.h index 5678ab846c..77171d1197 100644 --- a/src/dfm-base/dbusservice/global_server_defines.h +++ b/src/dfm-base/dbusservice/global_server_defines.h @@ -80,6 +80,7 @@ inline constexpr char kConnectionBus[] { "ConnectionBus" }; inline constexpr char kUDisks2Size[] { "UDisks2Size" }; inline constexpr char kDriveModel[] { "DriveModel" }; inline constexpr char kPreferredDevice[] { "PreferredDevice" }; +inline constexpr char kConfiguration[] { "Configuration" }; } // namespace DeviceProperty /*! diff --git a/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/menu/diskencryptmenuscene.cpp b/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/menu/diskencryptmenuscene.cpp index a8d3b12b25..ce27830d4e 100644 --- a/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/menu/diskencryptmenuscene.cpp +++ b/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/menu/diskencryptmenuscene.cpp @@ -23,6 +23,9 @@ #include #include #include +#include +#include +#include #include #include @@ -105,9 +108,20 @@ bool DiskEncryptMenuScene::initialize(const QVariantHash ¶ms) return false; } + param.initOnly = false; + auto configJson = selectedItemInfo.value("Configuration", "").toString(); + if (!configJson.isEmpty()) { + QJsonParseError err; + QJsonDocument doc = QJsonDocument::fromJson(configJson.toLocal8Bit(), &err); + if (err.error != QJsonParseError::NoError) { + qWarning() << "device configuration not valid!" << device << configJson; + return false; + } + auto obj = doc.object(); + param.initOnly = obj.contains("fstab"); + } param.devID = selectedItemInfo.value("Id").toString(); param.devDesc = device; - param.initOnly = fstab_utils::isFstabItem(devMpt); param.mountPoint = devMpt; param.uuid = selectedItemInfo.value("IdUUID", "").toString(); param.deviceDisplayName = info->displayOf(dfmbase::FileInfo::kFileDisplayName); diff --git a/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/utils/encryptutils.cpp b/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/utils/encryptutils.cpp index 1a34549e6b..0dbc20f2e7 100644 --- a/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/utils/encryptutils.cpp +++ b/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/utils/encryptutils.cpp @@ -51,25 +51,6 @@ QString config_utils::cipherType() return cipher; } -bool fstab_utils::isFstabItem(const QString &mpt) -{ - if (mpt.isEmpty()) - return false; - - bool fstabed { false }; - struct fstab *fs; - setfsent(); - while ((fs = getfsent()) != nullptr) { - QString path = fs->fs_file; - if (mpt == path) { - fstabed = true; - break; - } - } - endfsent(); - return fstabed; -} - int tpm_utils::checkTPM() { return dpfSlotChannel->push("dfmplugin_encrypt_manager", "slot_TPMIsAvailablePro").toInt(); diff --git a/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/utils/encryptutils.h b/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/utils/encryptutils.h index be676dada5..380a4cf29d 100644 --- a/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/utils/encryptutils.h +++ b/src/plugins/filemanager/dfmplugin-disk-encrypt-entry/utils/encryptutils.h @@ -55,10 +55,6 @@ namespace recovery_key_utils { QString formatRecoveryKey(const QString &raw); } -namespace fstab_utils { -bool isFstabItem(const QString &mpt); -} // namespace fstab_utils - namespace device_utils { int encKeyType(const QString &dev); void cacheToken(const QString &device, const QVariantMap &token);