From 7f99e96d3ab1466f3754f3c5d2c6530591a827c6 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Fri, 30 Oct 2026 10:09:09 +0800 Subject: [PATCH] feat: convert logging calls to categorized macros (6/8) Convert uncategorized qDebug/qWarning/qInfo/qCritical calls in this part of the code to the categorized macros (appLog/serviceLog/baseLog), so the log level follows the DConfig log_rules of org.deepin.dde.diskmanager and can be switched at runtime by the debug-mode script without restart. --- service/diskmanagerservice.cpp | 171 +++++----- service/diskoperation/DeviceStorage.cpp | 313 +++++++++--------- service/diskoperation/blockspecial.cpp | 33 +- service/diskoperation/device.cpp | 17 +- service/diskoperation/filesystems/btrfs.cpp | 123 +++---- service/diskoperation/filesystems/exfat.cpp | 69 ++-- service/diskoperation/filesystems/ext2.cpp | 139 ++++---- service/diskoperation/filesystems/fat16.cpp | 129 ++++---- .../diskoperation/filesystems/filesystem.cpp | 5 +- .../diskoperation/filesystems/linuxswap.cpp | 37 ++- 10 files changed, 523 insertions(+), 513 deletions(-) diff --git a/service/diskmanagerservice.cpp b/service/diskmanagerservice.cpp index f8ef2db1..66fe7b1b 100644 --- a/service/diskmanagerservice.cpp +++ b/service/diskmanagerservice.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "diskmanagerservice.h" #include "PolicyKitHelper.h" @@ -17,13 +18,13 @@ DiskManagerService::DiskManagerService(const QString &frontEndDBusName, QObject , m_partedcore(new PartedCore(this)) , m_frontEndDBusName(frontEndDBusName) { - qDebug() << "Initializing DiskManagerService with frontEndDBusName:" << frontEndDBusName; + qCDebug(serviceLog) << "Initializing DiskManagerService with frontEndDBusName:" << frontEndDBusName; initConnection(); } void DiskManagerService::initConnection() { - qDebug() << "Entering DiskManagerService::initConnection"; + qCDebug(serviceLog) << "Entering DiskManagerService::initConnection"; connect(m_partedcore, &PartedCore::updateDeviceInfo, this, &DiskManagerService::updateDeviceInfo); connect(m_partedcore, &PartedCore::updateLUKSInfo, this, &DiskManagerService::updateLUKSInfo); connect(m_partedcore, &PartedCore::deletePartitionMessage, this, &DiskManagerService::deletePartition); @@ -48,13 +49,13 @@ void DiskManagerService::initConnection() void DiskManagerService::Quit() { - qDebug() << "Entering DiskManagerService::Quit"; + qCDebug(serviceLog) << "Entering DiskManagerService::Quit"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for Quit"; + qCDebug(serviceLog) << "Authorization failed for Quit"; return; } - qDebug() << "DiskManagerService::Quit called"; + qCDebug(serviceLog) << "DiskManagerService::Quit called"; m_partedcore->delTempMountFile(); QCoreApplication::exit(0); } @@ -69,13 +70,13 @@ void DiskManagerService::Quit() // } // QString msg = "DiskManagerService::Start called"; // Q_EMIT MessageReport(msg); -//// qDebug() << msg; +//// qCDebug(serviceLog) << msg; //} void DiskManagerService::Start() { - qDebug() << "Entering DiskManagerService::Start"; + qCDebug(serviceLog) << "Entering DiskManagerService::Start"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for Start"; + qCDebug(serviceLog) << "Authorization failed for Start"; return; } @@ -85,28 +86,28 @@ void DiskManagerService::Start() DeviceInfo DiskManagerService::getDeviceinfo() { - qDebug() << "Entering DiskManagerService::getDeviceinfo"; + qCDebug(serviceLog) << "Entering DiskManagerService::getDeviceinfo"; if (!checkAuthorization()) { - qWarning() << "Authorization failed for getDeviceinfo"; + qCWarning(serviceLog) << "Authorization failed for getDeviceinfo"; return DeviceInfo(); } QString msg = "DiskManagerService::getDeviceinfo"; Q_EMIT MessageReport(msg); -// qDebug() << "DiskManagerService::getDeviceinfo success *******"; +// qCDebug(serviceLog) << "DiskManagerService::getDeviceinfo success *******"; return m_partedcore->getDeviceinfo(); } //TODO: 这里感觉没有必要发送信号 等之后有时间测试一下 能否去掉多余的代码 void DiskManagerService::getalldevice() { - qDebug() << "Entering DiskManagerService::getalldevice"; + qCDebug(serviceLog) << "Entering DiskManagerService::getalldevice"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for getalldevice"; + qCDebug(serviceLog) << "Authorization failed for getalldevice"; return; } -// qDebug() << "DiskManagerService::getalldevice"; +// qCDebug(serviceLog) << "DiskManagerService::getalldevice"; // DeviceInfoMap infores = m_partedcore->getAllDeviceinfo(); // Q_EMIT updateDeviceInfo(infores); emit getAllDeviceInfomation(); @@ -114,7 +115,7 @@ void DiskManagerService::getalldevice() void DiskManagerService::onGetAllDeviceInfomation() { - qDebug() << "Entering DiskManagerService::onGetAllDeviceInfomation"; + qCDebug(serviceLog) << "Entering DiskManagerService::onGetAllDeviceInfomation"; DeviceInfoMap infores = m_partedcore->getAllDeviceinfo(); LVMInfo lvmInfo = m_partedcore->getAllLVMinfo(); LUKSMap luksInfo = m_partedcore->getAllLUKSinfo(); @@ -124,9 +125,9 @@ void DiskManagerService::onGetAllDeviceInfomation() void DiskManagerService::setCurSelect(const PartitionInfo &info) { - qDebug() << "Entering DiskManagerService::setCurSelect"; + qCDebug(serviceLog) << "Entering DiskManagerService::setCurSelect"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for setCurSelect"; + qCDebug(serviceLog) << "Authorization failed for setCurSelect"; return; } @@ -135,9 +136,9 @@ void DiskManagerService::setCurSelect(const PartitionInfo &info) bool DiskManagerService::unmount() { - qDebug() << "Entering DiskManagerService::unmount"; + qCDebug(serviceLog) << "Entering DiskManagerService::unmount"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for unmount"; + qCDebug(serviceLog) << "Authorization failed for unmount"; return false; } @@ -146,15 +147,15 @@ bool DiskManagerService::unmount() bool DiskManagerService::mount(const QString &mountpath) { - qDebug() << "Entering DiskManagerService::mount with mountpath:" << mountpath; + qCDebug(serviceLog) << "Entering DiskManagerService::mount with mountpath:" << mountpath; if (!checkAuthorization()) { - qDebug() << "Authorization failed for mount"; + qCDebug(serviceLog) << "Authorization failed for mount"; return false; } QDBusReply uidReply = connection().interface()->serviceUid(message().service()); if (!uidReply.isValid()) { - qWarning() << "Failed to get invoker UID for mount, refusing operation"; + qCWarning(serviceLog) << "Failed to get invoker UID for mount, refusing operation"; return false; } QString invokerUid = QString::number(uidReply.value()); @@ -163,9 +164,9 @@ bool DiskManagerService::mount(const QString &mountpath) bool DiskManagerService::deCrypt(const LUKS_INFO &luks) { - qDebug() << "Entering DiskManagerService::deCrypt"; + qCDebug(serviceLog) << "Entering DiskManagerService::deCrypt"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for deCrypt"; + qCDebug(serviceLog) << "Authorization failed for deCrypt"; return false; } @@ -174,9 +175,9 @@ bool DiskManagerService::deCrypt(const LUKS_INFO &luks) bool DiskManagerService::cryptMount(const LUKS_INFO &luks) { - qDebug() << "Entering DiskManagerService::cryptMount"; + qCDebug(serviceLog) << "Entering DiskManagerService::cryptMount"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for cryptMount"; + qCDebug(serviceLog) << "Authorization failed for cryptMount"; return false; } @@ -185,9 +186,9 @@ bool DiskManagerService::cryptMount(const LUKS_INFO &luks) bool DiskManagerService::cryptUmount(const LUKS_INFO &luks) { - qDebug() << "Entering DiskManagerService::cryptUmount"; + qCDebug(serviceLog) << "Entering DiskManagerService::cryptUmount"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for cryptUmount"; + qCDebug(serviceLog) << "Authorization failed for cryptUmount"; return false; } @@ -196,9 +197,9 @@ bool DiskManagerService::cryptUmount(const LUKS_INFO &luks) QStringList DiskManagerService::getallsupportfs() { - qDebug() << "Entering DiskManagerService::getallsupportfs"; + qCDebug(serviceLog) << "Entering DiskManagerService::getallsupportfs"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for getallsupportfs"; + qCDebug(serviceLog) << "Authorization failed for getallsupportfs"; return QStringList(); } @@ -207,21 +208,21 @@ QStringList DiskManagerService::getallsupportfs() bool DiskManagerService::format(const QString &fstype, const QString &name) { - qDebug() << "Entering DiskManagerService::format with fstype:" << fstype << "and name:" << name; + qCDebug(serviceLog) << "Entering DiskManagerService::format with fstype:" << fstype << "and name:" << name; if (!checkAuthorization()) { - qWarning() << "Authorization failed for format operation"; + qCWarning(serviceLog) << "Authorization failed for format operation"; return false; } - qDebug() << "Formatting with filesystem:" << fstype << "name:" << name; + qCDebug(serviceLog) << "Formatting with filesystem:" << fstype << "name:" << name; return m_partedcore->format(fstype, name); } bool DiskManagerService::clear(const WipeAction &wipe) { - qDebug() << "Entering DiskManagerService::clear"; + qCDebug(serviceLog) << "Entering DiskManagerService::clear"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for clear"; + qCDebug(serviceLog) << "Authorization failed for clear"; return false; } @@ -230,9 +231,9 @@ bool DiskManagerService::clear(const WipeAction &wipe) bool DiskManagerService::resize(const PartitionInfo &info) { - qDebug() << "Entering DiskManagerService::resize"; + qCDebug(serviceLog) << "Entering DiskManagerService::resize"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for resize"; + qCDebug(serviceLog) << "Authorization failed for resize"; return false; } @@ -241,9 +242,9 @@ bool DiskManagerService::resize(const PartitionInfo &info) bool DiskManagerService::create(const PartitionVec &infovec) { - qDebug() << "Entering DiskManagerService::create"; + qCDebug(serviceLog) << "Entering DiskManagerService::create"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for create"; + qCDebug(serviceLog) << "Authorization failed for create"; return false; } @@ -252,9 +253,9 @@ bool DiskManagerService::create(const PartitionVec &infovec) HardDiskInfo DiskManagerService::onGetDeviceHardInfo(const QString &devicepath) { - qDebug() << "Entering DiskManagerService::onGetDeviceHardInfo for device:" << devicepath; + qCDebug(serviceLog) << "Entering DiskManagerService::onGetDeviceHardInfo for device:" << devicepath; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onGetDeviceHardInfo"; + qCDebug(serviceLog) << "Authorization failed for onGetDeviceHardInfo"; return HardDiskInfo(); } @@ -263,9 +264,9 @@ HardDiskInfo DiskManagerService::onGetDeviceHardInfo(const QString &devicepath) QString DiskManagerService::onGetDeviceHardStatus(const QString &devicepath) { - qDebug() << "Entering DiskManagerService::onGetDeviceHardStatus for device:" << devicepath; + qCDebug(serviceLog) << "Entering DiskManagerService::onGetDeviceHardStatus for device:" << devicepath; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onGetDeviceHardStatus"; + qCDebug(serviceLog) << "Authorization failed for onGetDeviceHardStatus"; return QString(); } @@ -274,9 +275,9 @@ QString DiskManagerService::onGetDeviceHardStatus(const QString &devicepath) HardDiskStatusInfoList DiskManagerService::onGetDeviceHardStatusInfo(const QString &devicepath) { - qDebug() << "Entering DiskManagerService::onGetDeviceHardStatusInfo for device:" << devicepath; + qCDebug(serviceLog) << "Entering DiskManagerService::onGetDeviceHardStatusInfo for device:" << devicepath; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onGetDeviceHardStatusInfo"; + qCDebug(serviceLog) << "Authorization failed for onGetDeviceHardStatusInfo"; return HardDiskStatusInfoList(); } @@ -284,9 +285,9 @@ HardDiskStatusInfoList DiskManagerService::onGetDeviceHardStatusInfo(const QStri } bool DiskManagerService::onDeletePartition() { - qDebug() << "Entering DiskManagerService::onDeletePartition"; + qCDebug(serviceLog) << "Entering DiskManagerService::onDeletePartition"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onDeletePartition"; + qCDebug(serviceLog) << "Authorization failed for onDeletePartition"; return false; } @@ -294,9 +295,9 @@ bool DiskManagerService::onDeletePartition() } bool DiskManagerService::onHidePartition() { - qDebug() << "Entering DiskManagerService::onHidePartition"; + qCDebug(serviceLog) << "Entering DiskManagerService::onHidePartition"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onHidePartition"; + qCDebug(serviceLog) << "Authorization failed for onHidePartition"; return false; } @@ -304,9 +305,9 @@ bool DiskManagerService::onHidePartition() } bool DiskManagerService::onShowPartition() { - qDebug() << "Entering DiskManagerService::onShowPartition"; + qCDebug(serviceLog) << "Entering DiskManagerService::onShowPartition"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onShowPartition"; + qCDebug(serviceLog) << "Authorization failed for onShowPartition"; return false; } @@ -314,9 +315,9 @@ bool DiskManagerService::onShowPartition() } bool DiskManagerService::onDetectionPartitionTableError(const QString &devicePath) { - qDebug() << "Entering DiskManagerService::onDetectionPartitionTableError for device:" << devicePath; + qCDebug(serviceLog) << "Entering DiskManagerService::onDetectionPartitionTableError for device:" << devicePath; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onDetectionPartitionTableError"; + qCDebug(serviceLog) << "Authorization failed for onDetectionPartitionTableError"; return false; } @@ -331,9 +332,9 @@ bool DiskManagerService::onCreatePartitionTable(const QString &devicePath, const } bool DiskManagerService::onCheckBadBlocksCount(const QString &devicePath, int blockStart, int blockEnd, int checkConut, int checkSize, int flag) { - qDebug() << "Entering DiskManagerService::onCheckBadBlocksCount for device:" << devicePath; + qCDebug(serviceLog) << "Entering DiskManagerService::onCheckBadBlocksCount for device:" << devicePath; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onCheckBadBlocksCount"; + qCDebug(serviceLog) << "Authorization failed for onCheckBadBlocksCount"; return false; } @@ -341,9 +342,9 @@ bool DiskManagerService::onCheckBadBlocksCount(const QString &devicePath, int bl } bool DiskManagerService::onCheckBadBlocksTime(const QString &devicePath, int blockStart, int blockEnd, const QString &checkTime, int checkSize, int flag) { - qDebug() << "Entering DiskManagerService::onCheckBadBlocksTime for device:" << devicePath; + qCDebug(serviceLog) << "Entering DiskManagerService::onCheckBadBlocksTime for device:" << devicePath; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onCheckBadBlocksTime"; + qCDebug(serviceLog) << "Authorization failed for onCheckBadBlocksTime"; return false; } @@ -351,9 +352,9 @@ bool DiskManagerService::onCheckBadBlocksTime(const QString &devicePath, int blo } bool DiskManagerService::onFixBadBlocks(const QString &devicePath, QStringList badBlocksList, int checkSize, int flag) { - qDebug() << "Entering DiskManagerService::onFixBadBlocks for device:" << devicePath; + qCDebug(serviceLog) << "Entering DiskManagerService::onFixBadBlocks for device:" << devicePath; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onFixBadBlocks"; + qCDebug(serviceLog) << "Authorization failed for onFixBadBlocks"; return false; } @@ -362,9 +363,9 @@ bool DiskManagerService::onFixBadBlocks(const QString &devicePath, QStringList b bool DiskManagerService::onCreateVG(QString vgName, QList devList, long long size) { - qDebug() << "Entering DiskManagerService::onCreateVG for VG:" << vgName; + qCDebug(serviceLog) << "Entering DiskManagerService::onCreateVG for VG:" << vgName; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onCreateVG"; + qCDebug(serviceLog) << "Authorization failed for onCreateVG"; return false; } @@ -373,9 +374,9 @@ bool DiskManagerService::onCreateVG(QString vgName, QList devList, long bool DiskManagerService::onCreateLV(QString vgName, QList lvList) { - qDebug() << "Entering DiskManagerService::onCreateLV for VG:" << vgName; + qCDebug(serviceLog) << "Entering DiskManagerService::onCreateLV for VG:" << vgName; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onCreateLV"; + qCDebug(serviceLog) << "Authorization failed for onCreateLV"; return false; } @@ -384,9 +385,9 @@ bool DiskManagerService::onCreateLV(QString vgName, QList lvList) bool DiskManagerService::onDeleteVG(QStringList vglist) { - qDebug() << "Entering DiskManagerService::onDeleteVG"; + qCDebug(serviceLog) << "Entering DiskManagerService::onDeleteVG"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onDeleteVG"; + qCDebug(serviceLog) << "Authorization failed for onDeleteVG"; return false; } @@ -395,9 +396,9 @@ bool DiskManagerService::onDeleteVG(QStringList vglist) bool DiskManagerService::onDeleteLV(QStringList lvlist) { - qDebug() << "Entering DiskManagerService::onDeleteLV"; + qCDebug(serviceLog) << "Entering DiskManagerService::onDeleteLV"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onDeleteLV"; + qCDebug(serviceLog) << "Authorization failed for onDeleteLV"; return false; } @@ -406,9 +407,9 @@ bool DiskManagerService::onDeleteLV(QStringList lvlist) bool DiskManagerService::onResizeVG(QString vgName, QList devList, long long size) { - qDebug() << "Entering DiskManagerService::onResizeVG for VG:" << vgName; + qCDebug(serviceLog) << "Entering DiskManagerService::onResizeVG for VG:" << vgName; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onResizeVG"; + qCDebug(serviceLog) << "Authorization failed for onResizeVG"; return false; } @@ -417,9 +418,9 @@ bool DiskManagerService::onResizeVG(QString vgName, QList devList, long bool DiskManagerService::onResizeLV(LVAction lvAction) { - qDebug() << "Entering DiskManagerService::onResizeLV for LV:" << lvAction.m_lvName; + qCDebug(serviceLog) << "Entering DiskManagerService::onResizeLV for LV:" << lvAction.m_lvName; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onResizeLV"; + qCDebug(serviceLog) << "Authorization failed for onResizeLV"; return false; } @@ -428,9 +429,9 @@ bool DiskManagerService::onResizeLV(LVAction lvAction) bool DiskManagerService::onMountLV(LVAction lvAction) { - qDebug() << "Entering DiskManagerService::onMountLV for LV:" << lvAction.m_lvName; + qCDebug(serviceLog) << "Entering DiskManagerService::onMountLV for LV:" << lvAction.m_lvName; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onMountLV"; + qCDebug(serviceLog) << "Authorization failed for onMountLV"; return false; } @@ -439,9 +440,9 @@ bool DiskManagerService::onMountLV(LVAction lvAction) bool DiskManagerService::onUmountLV(LVAction lvAction) { - qDebug() << "Entering DiskManagerService::onUmountLV for LV:" << lvAction.m_lvName; + qCDebug(serviceLog) << "Entering DiskManagerService::onUmountLV for LV:" << lvAction.m_lvName; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onUmountLV"; + qCDebug(serviceLog) << "Authorization failed for onUmountLV"; return false; } @@ -450,9 +451,9 @@ bool DiskManagerService::onUmountLV(LVAction lvAction) bool DiskManagerService::onClearLV(LVAction lvAction) { - qDebug() << "Entering DiskManagerService::onClearLV for LV:" << lvAction.m_lvName; + qCDebug(serviceLog) << "Entering DiskManagerService::onClearLV for LV:" << lvAction.m_lvName; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onClearLV"; + qCDebug(serviceLog) << "Authorization failed for onClearLV"; return false; } @@ -461,9 +462,9 @@ bool DiskManagerService::onClearLV(LVAction lvAction) bool DiskManagerService::onDeletePVList(QList devList) { - qDebug() << "Entering DiskManagerService::onDeletePVList"; + qCDebug(serviceLog) << "Entering DiskManagerService::onDeletePVList"; if (!checkAuthorization()) { - qDebug() << "Authorization failed for onDeletePVList"; + qCDebug(serviceLog) << "Authorization failed for onDeletePVList"; return false; } @@ -501,29 +502,29 @@ int DiskManagerService::test() bool DiskManagerService::checkAuthorization(void) { #ifdef NO_DBUS_CALLER_AUTH_CHECK - qDebug() << "Authorization check was skipped"; + qCDebug(serviceLog) << "Authorization check was skipped"; return true; #else QString actionId("com.deepin.pkexec.deepin-diskmanager"); QString serviceName = message().service(); if (serviceName == m_frontEndDBusName) { - qDebug() << "Authorization granted for frontend:" << serviceName; + qCDebug(serviceLog) << "Authorization granted for frontend:" << serviceName; return true; } QDBusReply uidReply = connection().interface()->serviceUid(serviceName); if (uidReply.isValid() && uidReply.value() == 0) { - qDebug() << "Authorization granted for root user"; + qCDebug(serviceLog) << "Authorization granted for root user"; return true; } if (PolicyKitHelper::instance()->checkAuthorization(actionId, serviceName)) { - qDebug() << "Authorization granted via Polkit for service:" << serviceName; + qCDebug(serviceLog) << "Authorization granted via Polkit for service:" << serviceName; return true; } - qWarning() << "Authorization denied for service:" << serviceName; + qCWarning(serviceLog) << "Authorization denied for service:" << serviceName; sendErrorReply(QDBusError::AccessDenied); return false; #endif diff --git a/service/diskoperation/DeviceStorage.cpp b/service/diskoperation/DeviceStorage.cpp index 2f04c897..1fde882f 100755 --- a/service/diskoperation/DeviceStorage.cpp +++ b/service/diskoperation/DeviceStorage.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "DeviceStorage.h" #include #include @@ -15,19 +16,19 @@ DeviceStorage::DeviceStorage() : m_model(""), m_vendor(""), m_mediaType(""), m_size(""), m_rotationRate(""), m_interface("") , m_serialNumber(""), m_version(""), m_capabilities(""), m_description(""), m_KeyToLshw(""), m_KeyFromStorage("") { - qDebug() << "DeviceStorage object created"; + qCDebug(serviceLog) << "DeviceStorage object created"; } bool DeviceStorage::setHwinfoInfo(const QMap &mapInfo) { - qDebug() << "Setting hwinfo info for storage device"; + qCDebug(serviceLog) << "Setting hwinfo info for storage device"; // 龙芯机器中 hwinfo --disk会列出所有的分区信息 // 存储设备不应包含分区,根据SysFS BusID 来确定是否是分区信息 if (mapInfo.find("SysFS BusID") == mapInfo.end()) { - qWarning() << "No SysFS BusID found in hwinfo info"; + qCWarning(serviceLog) << "No SysFS BusID found in hwinfo info"; return false; } - qDebug() << "SysFS BusID found, proceeding"; + qCDebug(serviceLog) << "SysFS BusID found, proceeding"; setAttribute(mapInfo, "Model", m_model); setAttribute(mapInfo, "Vendor", m_vendor); @@ -36,12 +37,12 @@ bool DeviceStorage::setHwinfoInfo(const QMap &mapInfo) QRegularExpression re(".*\\((.*)\\).*"); QRegularExpressionMatch match = re.match(m_interface); if (match.hasMatch()) { - qDebug() << "Interface match found"; + qCDebug(serviceLog) << "Interface match found"; m_interface = match.captured(1); #else QRegExp re(".*\\((.*)\\).*"); if (re.exactMatch(m_interface)) { - qDebug() << "Interface match found"; + qCDebug(serviceLog) << "Interface match found"; m_interface = re.cap(1); #endif m_interface.replace("Controller", ""); @@ -58,7 +59,7 @@ bool DeviceStorage::setHwinfoInfo(const QMap &mapInfo) m_size.replace(QRegExp("\\(.*\\)"), "").replace(" ", ""); #endif if (m_size.startsWith("0") || m_size == "") { - qDebug() << "Size is 0 or empty, returning false"; + qCDebug(serviceLog) << "Size is 0 or empty, returning false"; return false; } @@ -67,20 +68,20 @@ bool DeviceStorage::setHwinfoInfo(const QMap &mapInfo) setAttribute(mapInfo, "SysFS BusID", m_KeyToLshw); setAttribute(mapInfo, "Device File", m_DeviceFile); - qDebug() << "Hwinfo info set successfully for device:" << m_DeviceFile; + qCDebug(serviceLog) << "Hwinfo info set successfully for device:" << m_DeviceFile; return true; } bool DeviceStorage::setKLUHwinfoInfo(const QMap &mapInfo) { - qDebug() << "Entering DeviceStorage::setKLUHwinfoInfo"; + qCDebug(serviceLog) << "Entering DeviceStorage::setKLUHwinfoInfo"; // 龙芯机器中 hwinfo --disk会列出所有的分区信息 // 存储设备不应包含分区,根据SysFS BusID 来确定是否是分区信息 if (mapInfo.find("SysFS BusID") == mapInfo.end()) { - qDebug() << "No SysFS BusID found in KLU hwinfo, returning false"; + qCDebug(serviceLog) << "No SysFS BusID found in KLU hwinfo, returning false"; return false; } - qDebug() << "SysFS BusID found in KLU hwinfo, proceeding"; + qCDebug(serviceLog) << "SysFS BusID found in KLU hwinfo, proceeding"; setAttribute(mapInfo, "Model", m_model); setAttribute(mapInfo, "Vendor", m_vendor); @@ -89,12 +90,12 @@ bool DeviceStorage::setKLUHwinfoInfo(const QMap &mapInfo) QRegularExpression re(".*\\((.*)\\).*"); QRegularExpressionMatch match = re.match(m_interface); if (match.hasMatch()) { - qDebug() << "KLU Interface match found"; + qCDebug(serviceLog) << "KLU Interface match found"; m_interface = match.captured(1); #else QRegExp re(".*\\((.*)\\).*"); if (re.exactMatch(m_interface)) { - qDebug() << "KLU Interface match found"; + qCDebug(serviceLog) << "KLU Interface match found"; m_interface = re.cap(1); #endif m_interface.replace("Controller", ""); @@ -111,7 +112,7 @@ bool DeviceStorage::setKLUHwinfoInfo(const QMap &mapInfo) m_size.replace(QRegExp("\\(.*\\)"), "").replace(" ", ""); #endif if (m_size.startsWith("0") || m_size == "") { - qDebug() << "KLU size is 0 or empty, returning false"; + qCDebug(serviceLog) << "KLU size is 0 or empty, returning false"; return false; } @@ -123,32 +124,32 @@ bool DeviceStorage::setKLUHwinfoInfo(const QMap &mapInfo) // KLU里面的介质类型的处理方式比较特殊 if (mapInfo["Driver"].contains("usb-storage")) { - qDebug() << "Driver contains usb-storage, setting media type to USB"; + qCDebug(serviceLog) << "Driver contains usb-storage, setting media type to USB"; m_mediaType = "USB"; } // loadOtherDeviceInfo(mapInfo); - qDebug() << "Exiting DeviceStorage::setKLUHwinfoInfo"; + qCDebug(serviceLog) << "Exiting DeviceStorage::setKLUHwinfoInfo"; return true; } bool DeviceStorage::addInfoFromlshw(const QMap &mapInfo) { - qDebug() << "Adding lshw info for storage device"; + qCDebug(serviceLog) << "Adding lshw info for storage device"; // 先获取需要进行匹配的关键字 QStringList keys = mapInfo["bus info"].split("@"); if (keys.size() != 2) { - qWarning() << "Invalid bus info format:" << mapInfo["bus info"]; + qCWarning(serviceLog) << "Invalid bus info format:" << mapInfo["bus info"]; return false; } if (keys[0].trimmed() == "nvme") { - qDebug() << "nvme device found, not check KeyToLshw"; + qCDebug(serviceLog) << "nvme device found, not check KeyToLshw"; } else { QString key = keys[1].trimmed(); key.replace(".", ":"); if (key != m_KeyToLshw) { - qDebug() << "lshw key does not match, returning false" << keys[0].trimmed() << key << m_KeyToLshw; + qCDebug(serviceLog) << "lshw key does not match, returning false" << keys[0].trimmed() << key << m_KeyToLshw; return false; } } @@ -156,47 +157,47 @@ bool DeviceStorage::addInfoFromlshw(const QMap &mapInfo) // 获取唯一key QStringList words = mapInfo["bus info"].split(":"); if (words.size() == 2) { - qDebug() << "Setting KeyFromStorage"; + qCDebug(serviceLog) << "Setting KeyFromStorage"; m_KeyFromStorage = words[0]; m_KeyFromStorage.replace("@", ""); } else { - qDebug() << "Cannot set KeyFromStorage, invalid format for bus info"; + qCDebug(serviceLog) << "Cannot set KeyFromStorage, invalid format for bus info"; } // 获取基本信息 getInfoFromLshw(mapInfo); - qDebug() << "Lshw info added successfully"; + qCDebug(serviceLog) << "Lshw info added successfully"; return true; } bool DeviceStorage::addInfoFromSmartctl(const QMap &mapInfo) { - qDebug() << "Entering DeviceStorage::addInfoFromSmartctl"; + qCDebug(serviceLog) << "Entering DeviceStorage::addInfoFromSmartctl"; // 获取基本信息 getInfoFromsmartctl(mapInfo); - qDebug() << "Exiting DeviceStorage::addInfoFromSmartctl"; + qCDebug(serviceLog) << "Exiting DeviceStorage::addInfoFromSmartctl"; return true; } bool DeviceStorage::setMediaType(const QString &name, const QString &value) { - qDebug() << "Entering DeviceStorage::setMediaType for name:" << name << "value:" << value; + qCDebug(serviceLog) << "Entering DeviceStorage::setMediaType for name:" << name << "value:" << value; if (!m_DeviceFile.contains(name)) { - qDebug() << "Device file does not contain name, returning false"; + qCDebug(serviceLog) << "Device file does not contain name, returning false"; return false; } if (QString("0") == value) { - qDebug() << "Setting media type to SSD"; + qCDebug(serviceLog) << "Setting media type to SSD"; m_mediaType = "SSD"; } else if (QString("1") == value) { - qDebug() << "Setting media type to HDD"; + qCDebug(serviceLog) << "Setting media type to HDD"; m_mediaType = "HDD"; } else { - qDebug() << "Setting media type to UnKnow"; + qCDebug(serviceLog) << "Setting media type to UnKnow"; m_mediaType = "UnKnow"; } @@ -205,25 +206,25 @@ bool DeviceStorage::setMediaType(const QString &name, const QString &value) bool DeviceStorage::setKLUMediaType(const QString &name, const QString &value) { - qDebug() << "Entering DeviceStorage::setKLUMediaType for name:" << name << "value:" << value; + qCDebug(serviceLog) << "Entering DeviceStorage::setKLUMediaType for name:" << name << "value:" << value; if (!m_DeviceFile.contains(name)) { - qDebug() << "Device file does not contain name, returning false"; + qCDebug(serviceLog) << "Device file does not contain name, returning false"; return false; } if (m_mediaType == "USB") { - qDebug() << "Media type is already USB, returning true"; + qCDebug(serviceLog) << "Media type is already USB, returning true"; return true; } if (QString("0") == value) { - qDebug() << "Setting media type to SSD for KLU"; + qCDebug(serviceLog) << "Setting media type to SSD for KLU"; m_mediaType = "SSD"; } else if (QString("1") == value) { - qDebug() << "Setting media type to HDD for KLU"; + qCDebug(serviceLog) << "Setting media type to HDD for KLU"; m_mediaType = "HDD"; } else { - qDebug() << "Setting media type to UnKnow for KLU"; + qCDebug(serviceLog) << "Setting media type to UnKnow for KLU"; m_mediaType = "UnKnow"; } @@ -232,7 +233,7 @@ bool DeviceStorage::setKLUMediaType(const QString &name, const QString &value) void DeviceStorage::getInfoFromLshw(const QMap &mapInfo) { - qDebug() << "Entering DeviceStorage::getInfoFromLshw"; + qCDebug(serviceLog) << "Entering DeviceStorage::getInfoFromLshw"; setAttribute(mapInfo, "capabilities", m_capabilities); setAttribute(mapInfo, "version", m_version); setAttribute(mapInfo, "serial", m_serialNumber, false); @@ -244,13 +245,13 @@ void DeviceStorage::getInfoFromLshw(const QMap &mapInfo) QRegularExpression re(".*\\((.*)\\)$"); QRegularExpressionMatch match = re.match(m_size); if (match.hasMatch()) { - qDebug() << "Size match found in lshw info"; + qCDebug(serviceLog) << "Size match found in lshw info"; m_size = match.captured(1); } #else QRegExp re(".*\\((.*)\\)$"); if (re.exactMatch(m_size)) { - qDebug() << "Size match found in lshw info"; + qCDebug(serviceLog) << "Size match found in lshw info"; m_size = re.cap(1); } #endif @@ -258,7 +259,7 @@ void DeviceStorage::getInfoFromLshw(const QMap &mapInfo) void DeviceStorage::getInfoFromsmartctl(const QMap &mapInfo) { - qDebug() << "Getting smartctl info for storage device"; + qCDebug(serviceLog) << "Getting smartctl info for storage device"; // 固件版本 m_firmwareVersion = mapInfo["Firmware Version"]; @@ -266,7 +267,7 @@ void DeviceStorage::getInfoFromsmartctl(const QMap &mapInfo) QString sataVersion = mapInfo["SATA Version"]; QStringList strList = sataVersion.split(","); if (strList.size() == 2) { - qDebug() << "SATA version found, setting speed"; + qCDebug(serviceLog) << "SATA version found, setting speed"; m_speed = strList[1].trimmed(); } @@ -275,14 +276,14 @@ void DeviceStorage::getInfoFromsmartctl(const QMap &mapInfo) // 通电时间 m_powerOnHours = mapInfo["Power_On_Hours"]; if (m_powerOnHours == "") { - qDebug() << "Power_On_Hours is empty, trying Power On Hours"; + qCDebug(serviceLog) << "Power_On_Hours is empty, trying Power On Hours"; m_powerOnHours = mapInfo["Power On Hours"]; } // 通电次数 m_powerCycleCount = mapInfo["Power_Cycle_Count"]; if (m_powerCycleCount == "") { - qDebug() << "Power_Cycle_Count is empty, trying Power Cycles"; + qCDebug(serviceLog) << "Power_Cycle_Count is empty, trying Power Cycles"; m_powerCycleCount = mapInfo["Power Cycles"]; } @@ -327,26 +328,26 @@ void DeviceStorage::getInfoFromsmartctl(const QMap &mapInfo) void DeviceStorage::setAttribute(const QMap &mapInfo, const QString &key, QString &variable, bool overwrite) { - // qDebug() << "Setting attribute for key:" << key; + // qCDebug(serviceLog) << "Setting attribute for key:" << key; if (mapInfo.find(key) == mapInfo.end()) { - qDebug() << "Key not found in map:" << key; + qCDebug(serviceLog) << "Key not found in map:" << key; return; } if (mapInfo[key] == "") { - qDebug() << "Empty value for key:" << key; + qCDebug(serviceLog) << "Empty value for key:" << key; return; } if (overwrite) { - qDebug() << "Overwrite is true, setting variable to map value"; + qCDebug(serviceLog) << "Overwrite is true, setting variable to map value"; variable = mapInfo[key].trimmed(); } else { if (variable.isEmpty()) { - qDebug() << "Variable is empty, setting variable to map value"; + qCDebug(serviceLog) << "Variable is empty, setting variable to map value"; variable = mapInfo[key].trimmed(); } if (variable.contains("Unknown", Qt::CaseInsensitive)) { - qDebug() << "Variable contains Unknown, setting variable to map value"; + qCDebug(serviceLog) << "Variable contains Unknown, setting variable to map value"; variable = mapInfo[key].trimmed(); } } @@ -354,12 +355,12 @@ void DeviceStorage::setAttribute(const QMap &mapInfo, const QS bool DeviceStorage::getDiskInfoFromHwinfo(const QString &devicePath) { - qDebug() << "Getting disk info from hwinfo for device:" << devicePath; + qCDebug(serviceLog) << "Getting disk info from hwinfo for device:" << devicePath; QString cmd = QString("hwinfo --disk --only %1").arg(devicePath); QString outPut; QString error; if (Utils::executCmd(cmd, outPut, error) != 0) { - qDebug() << "Failed to execute hwinfo command, error:" << error; + qCDebug(serviceLog) << "Failed to execute hwinfo command, error:" << error; return false; } @@ -374,20 +375,20 @@ bool DeviceStorage::getDiskInfoFromHwinfo(const QString &devicePath) if (!cid.isEmpty()) { m_serialNumber = cid; } - qDebug() << "Successfully got disk info from hwinfo"; + qCDebug(serviceLog) << "Successfully got disk info from hwinfo"; return true; } void DeviceStorage::getMapInfoFromHwinfo(const QString &info, QMap &mapInfo, const QString &ch) { - qDebug() << "DeviceStorage::getMapInfoFromHwinfo BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getMapInfoFromHwinfo BEGIN"; QStringList infoList = info.split("\n"); for (QStringList::iterator it = infoList.begin(); it != infoList.end(); ++it) { QStringList words = (*it).split(ch); if (words.size() != 2) { - qDebug() << "words.size() != 2, continue"; + qCDebug(serviceLog) << "words.size() != 2, continue"; continue; } @@ -395,59 +396,59 @@ void DeviceStorage::getMapInfoFromHwinfo(const QString &info, QMap &mapInfo) { - qDebug() << "DeviceStorage::getMapInfoFromInput BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getMapInfoFromInput BEGIN"; QStringList items = info.split("\n\n"); foreach (const QString &item, items) { if (item.isEmpty()) { - qDebug() << "item is empty, continue"; + qCDebug(serviceLog) << "item is empty, continue"; continue; } getMapInfoFromHwinfo(item, mapInfo); } - qDebug() << "DeviceStorage::getMapInfoFromInput END"; + qCDebug(serviceLog) << "DeviceStorage::getMapInfoFromInput END"; } bool DeviceStorage::getDiskInfoFromLshw(const QString &devicePath) { - qDebug() << "DeviceStorage::getDiskInfoFromLshw BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoFromLshw BEGIN"; QString outPut, error; if (Utils::executCmd("lshw -C disk", outPut, error) != 0) { - qDebug() << "Failed to execute lshw command, error:" << error; + qCDebug(serviceLog) << "Failed to execute lshw command, error:" << error; return false; } @@ -457,14 +458,14 @@ bool DeviceStorage::getDiskInfoFromLshw(const QString &devicePath) QStringList list2 = item.split("*-namespace"); foreach (const QString &item2, list2) { if (item2.contains(devicePath)) { - qDebug() << "devicePath found in lshw output"; + qCDebug(serviceLog) << "devicePath found in lshw output"; diskInfo = item2; break; } } } if (diskInfo.isEmpty()) { - qDebug() << "devicePath not found in lshw output, return false"; + qCDebug(serviceLog) << "devicePath not found in lshw output, return false"; return false; } @@ -472,65 +473,65 @@ bool DeviceStorage::getDiskInfoFromLshw(const QString &devicePath) getMapInfoFromLshw(diskInfo, mapInfo); addInfoFromlshw(mapInfo); - qDebug() << "DeviceStorage::getDiskInfoFromLshw END"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoFromLshw END"; return true; } void DeviceStorage::getMapInfoFromLshw(const QString &info, QMap &mapInfo, const QString &ch) { - qDebug() << "DeviceStorage::getMapInfoFromLshw BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getMapInfoFromLshw BEGIN"; QStringList infoList = info.split("\n"); for (QStringList::iterator it = infoList.begin(); it != infoList.end(); ++it) { QStringList words = (*it).split(ch); if (words.size() != 2) { - qDebug() << "words.size() != 2, continue"; + qCDebug(serviceLog) << "words.size() != 2, continue"; continue; } // && words[0].contains("configuration") == false && words[0].contains("resources") == false // 将configuration的内容进行拆分 if (words[0].contains("configuration") == true) { - qDebug() << "words[0] contains configuration"; + qCDebug(serviceLog) << "words[0] contains configuration"; QStringList keyValues = words[1].split(" "); for (QStringList::iterator it = keyValues.begin(); it != keyValues.end(); ++it) { QStringList attr = (*it).split("="); if (attr.size() != 2) { - qDebug() << "attr.size() != 2, continue"; + qCDebug(serviceLog) << "attr.size() != 2, continue"; continue; } mapInfo.insert(attr[0].trimmed(), attr[1].trimmed()); } } else if (words[0].contains("resources") == true) { - qDebug() << "words[0] contains resources"; + qCDebug(serviceLog) << "words[0] contains resources"; QStringList keyValues = words[1].split(" "); for (QStringList::iterator it = keyValues.begin(); it != keyValues.end(); ++it) { QStringList attr = (*it).split(":"); if (attr.size() != 2) { - qDebug() << "attr.size() != 2, continue"; + qCDebug(serviceLog) << "attr.size() != 2, continue"; continue; } if (mapInfo.find(attr[0].trimmed()) != mapInfo.end()) { - qDebug() << "mapInfo contains attr[0].trimmed()"; + qCDebug(serviceLog) << "mapInfo contains attr[0].trimmed()"; mapInfo[attr[0].trimmed()] += QString(" "); } mapInfo[attr[0].trimmed()] += attr[1].trimmed(); } } else { - qDebug() << "words[0] does not contain configuration or resources"; + qCDebug(serviceLog) << "words[0] does not contain configuration or resources"; mapInfo.insert(words[0].trimmed(), words[1].trimmed()); } } - qDebug() << "DeviceStorage::getMapInfoFromLshw END"; + qCDebug(serviceLog) << "DeviceStorage::getMapInfoFromLshw END"; } bool DeviceStorage::getDiskInfoFromLsblk(const QString &devicePath) { - qDebug() << "DeviceStorage::getDiskInfoFromLsblk BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoFromLsblk BEGIN"; QString cmd = QString("lsblk -d -o name,rota %1").arg(devicePath); QString outPut, error; if (Utils::executCmd(cmd, outPut, error) != 0) { - qDebug() << "Failed to execute lsblk command, error:" << error; + qCDebug(serviceLog) << "Failed to execute lsblk command, error:" << error; return false; } @@ -539,20 +540,20 @@ bool DeviceStorage::getDiskInfoFromLsblk(const QString &devicePath) loadLsblkInfo(outPut, mapInfo); if (mapInfo.size() == 1) { - qDebug() << "mapInfo.size() is 1"; + qCDebug(serviceLog) << "mapInfo.size() is 1"; setMediaType(mapInfo.firstKey(),mapInfo.value(mapInfo.firstKey())); } else { - qDebug() << "mapInfo.size() is not 1, return false"; + qCDebug(serviceLog) << "mapInfo.size() is not 1, return false"; return false; } - qDebug() << "DeviceStorage::getDiskInfoFromLsblk END"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoFromLsblk END"; return true; } void DeviceStorage::loadLsblkInfo(const QString &info, QMap &mapInfo) { - qDebug() << "DeviceStorage::loadLsblkInfo BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::loadLsblkInfo BEGIN"; QStringList lines = info.split("\n"); foreach (QString line, lines) { @@ -562,29 +563,29 @@ void DeviceStorage::loadLsblkInfo(const QString &info, QMap &m QStringList words = line.replace(QRegExp("[\\s]+"), " ").split(" "); #endif if (words.size() != 2 || words[0] == "NAME") { - qDebug() << "words.size() != 2 or words[0] is NAME, continue"; + qCDebug(serviceLog) << "words.size() != 2 or words[0] is NAME, continue"; continue; } mapInfo.insert(words[0].trimmed(), words[1].trimmed()); } - qDebug() << "DeviceStorage::loadLsblkInfo END"; + qCDebug(serviceLog) << "DeviceStorage::loadLsblkInfo END"; } bool DeviceStorage::getDiskInfoFromSmartCtl(const QString &devicePath) { - qDebug() << "DeviceStorage::getDiskInfoFromSmartCtl BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoFromSmartCtl BEGIN"; QString cmd = QString("smartctl --all %1").arg(devicePath); QString outPut, error; int exitcode = Utils::executCmd(cmd, outPut, error); if (outPut.contains("Please specify device type with the -d option")) { - qDebug() << "need to specify device type"; + qCDebug(serviceLog) << "need to specify device type"; cmd = QString("smartctl --all -d sat %1").arg(devicePath); exitcode = Utils::executCmd(cmd, outPut, error); } if (exitcode != 0) { - qDebug() << "Failed to execute smartctl command, error:" << error; + qCDebug(serviceLog) << "Failed to execute smartctl command, error:" << error; return false; } @@ -594,25 +595,25 @@ bool DeviceStorage::getDiskInfoFromSmartCtl(const QString &devicePath) addInfoFromSmartctl(mapInfo); - qDebug() << "DeviceStorage::getDiskInfoFromSmartCtl END"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoFromSmartCtl END"; return true; } void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model) { - qDebug() << "DeviceStorage::getDiskInfoModel BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoModel BEGIN"; QString cmd = QString("smartctl --all %1").arg(devicePath); QString outPut, error; int exitcode = Utils::executCmd(cmd, outPut, error); if (outPut.contains("Please specify device type with the -d option")) { - qDebug() << "need to specify device type"; + qCDebug(serviceLog) << "need to specify device type"; cmd = QString("smartctl --all -d sat %1").arg(devicePath); exitcode = Utils::executCmd(cmd, outPut, error); } if (exitcode != 0) { - qDebug() << "Failed to execute smartctl command, error:" << error; + qCDebug(serviceLog) << "Failed to execute smartctl command, error:" << error; return; } @@ -620,7 +621,7 @@ void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model) for (int i = 0; i < infoList.size(); i++) { QString info = infoList[i]; if(info.startsWith("Device Model:") || info.startsWith("Product:") || info.startsWith("Model Number:")){ - qDebug() << "found model in smartctl output"; + qCDebug(serviceLog) << "found model in smartctl output"; model = info.split(":").last().trimmed(); return; } @@ -629,18 +630,18 @@ void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model) cmd = "lshw -C disk"; exitcode = Utils::executCmd(cmd, outPut, error); if (exitcode != 0) { - qDebug() << "Failed to execute lshw command, error:" << error; + qCDebug(serviceLog) << "Failed to execute lshw command, error:" << error; return; } infoList = outPut.split("*-disk\n"); for (int i =0; i < infoList.size(); i++) { if(infoList[i].contains(devicePath)) { - qDebug() << "found devicePath in lshw output"; + qCDebug(serviceLog) << "found devicePath in lshw output"; QStringList tempList = infoList[i].split("\n"); for (int j = 0; j < tempList.size(); j++) { if(tempList[j].contains("product:")){ - qDebug() << "found model in lshw output"; + qCDebug(serviceLog) << "found model in lshw output"; model = tempList[j].split(":").last().trimmed(); return; } @@ -652,7 +653,7 @@ void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model) cmd = "udevadm info " + devicePath; exitcode = Utils::executCmd(cmd, outPut, error); if (exitcode != 0) { - qDebug() << "Failed to execute udevadm command, error:" << error; + qCDebug(serviceLog) << "Failed to execute udevadm command, error:" << error; return; } QString key = "ID_MODEL="; @@ -667,20 +668,20 @@ void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model) return; } - qWarning() << "tried a lot but got nothing about model for" << devicePath; + qCWarning(serviceLog) << "tried a lot but got nothing about model for" << devicePath; // 若未获取到型号名,返回未知 - qDebug() << "model not found, set to UnKnow"; + qCDebug(serviceLog) << "model not found, set to UnKnow"; model = "UnKnow"; return; } QString DeviceStorage::getDiskInfoMediaType(const QString &devicePath) { - qDebug() << "DeviceStorage::getDiskInfoMediaType BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoMediaType BEGIN"; QStringList deviceList = devicePath.split("/"); if (deviceList.size() < 2) { - qDebug() << "deviceList.size() < 2, return UnKnow"; + qCDebug(serviceLog) << "deviceList.size() < 2, return UnKnow"; return "UnKnow"; } QString device = deviceList[deviceList.size()-1]; @@ -688,32 +689,32 @@ QString DeviceStorage::getDiskInfoMediaType(const QString &devicePath) QString value = Utils::readContent(rotational_file).trimmed(); if ("1" == value) { - qDebug() << "value is 1"; + qCDebug(serviceLog) << "value is 1"; QString cmd = QString("smartctl -i %1").arg(devicePath); QString outPut, error; int exitcode = Utils::executCmd(cmd, outPut, error); if (outPut.contains("Solid State Device")) { - qDebug() << "is Solid State Device"; + qCDebug(serviceLog) << "is Solid State Device"; value = "0"; } else if (outPut.contains("Please specify device type with the -d option")) { - qDebug() << "need to specify device type"; + qCDebug(serviceLog) << "need to specify device type"; //FIXME: Hard type scsi for USB disk cmd = QString("smartctl -i -d scsi %1").arg(devicePath); exitcode = Utils::executCmd(cmd, outPut, error); if (!outPut.contains("Rotation Rate:")) { - qDebug() << "not contains Rotation Rate"; + qCDebug(serviceLog) << "not contains Rotation Rate"; value = "0"; } } } if (QString("0") == value) { - qDebug() << "return SSD"; + qCDebug(serviceLog) << "return SSD"; return "SSD"; } else if (QString("1") == value) { - qDebug() << "return HDD"; + qCDebug(serviceLog) << "return HDD"; return "HDD"; } else { - qDebug() << "return UnKnow"; + qCDebug(serviceLog) << "return UnKnow"; return "UnKnow"; } } @@ -724,7 +725,7 @@ static bool isPGUX() QString output, err; if (isPGUX != -1) { - qDebug() << "isPGUX is not -1, return isPGUX"; + qCDebug(serviceLog) << "isPGUX is not -1, return isPGUX"; return 1 == isPGUX; } @@ -738,17 +739,17 @@ static bool isPGUX() void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &interface, QString &model) { - qDebug() << "DeviceStorage::getDiskInfoInterface BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoInterface BEGIN"; QString bootDevicePath("/proc/bootdevice/product_name"); QFile file(bootDevicePath); if (file.open(QIODevice::ReadOnly)) { - qDebug() << "open /proc/bootdevice/product_name success"; + qCDebug(serviceLog) << "open /proc/bootdevice/product_name success"; if (model == file.readLine().simplified()) { - qDebug() << "model is boot device"; + qCDebug(serviceLog) << "model is boot device"; QString spec_version = Utils::readContent("/sys/block/sdd/device/spec_version").trimmed(); if (!spec_version.isEmpty()) { - qDebug() << "spec_version is not empty"; + qCDebug(serviceLog) << "spec_version is not empty"; if (spec_version.contains("300") || spec_version.contains("310") || spec_version.contains("400")) { interface = "UFS"; } @@ -758,35 +759,35 @@ void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &int } if (interface.isEmpty()) { - qDebug() << "interface is empty"; + qCDebug(serviceLog) << "interface is empty"; QString cmd = QString("hwinfo --disk --only %1").arg(devicePath); QString outPut, error; int exitcode = Utils::executCmd(cmd, outPut, error); if (exitcode != 0) { interface = "UnKnow"; - qDebug() << "Failed to execute hwinfo command, error:" << error; + qCDebug(serviceLog) << "Failed to execute hwinfo command, error:" << error; return; } QStringList outPutList = outPut.split("("); interface = outPutList[outPutList.size() - 1].split(" ")[0]; } - qDebug() << "DeviceStorage::getDiskInfoInterface END"; + qCDebug(serviceLog) << "DeviceStorage::getDiskInfoInterface END"; return; } void DeviceStorage::updateForHWDevice(const QString &/*devicePath*/) { - qDebug() << "DeviceStorage::updateForHWDevice BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::updateForHWDevice BEGIN"; if (Utils::readContent("/proc/bootdevice/product_name").trimmed().isEmpty()) { - qDebug() << "Fail to read the product_name file or the file is empty, return"; + qCDebug(serviceLog) << "Fail to read the product_name file or the file is empty, return"; return; } // m_firmwareVersion if (m_firmwareVersion.isEmpty()) { - qDebug() << "m_firmwareVersion is empty"; + qCDebug(serviceLog) << "m_firmwareVersion is empty"; if (isPGUX()) { - qDebug() << "is PGUX"; + qCDebug(serviceLog) << "is PGUX"; m_firmwareVersion = Utils::readContent("/proc/bootdevice/rev").trimmed(); } } @@ -832,12 +833,12 @@ void DeviceStorage::updateForHWDevice(const QString &/*devicePath*/) } } - qDebug() << "DeviceStorage::updateForHWDevice END"; + qCDebug(serviceLog) << "DeviceStorage::updateForHWDevice END"; } void DeviceStorage::getMapInfoFromSmartctl(QMap &mapInfo, const QString &info, const QString &ch) { - qDebug() << "DeviceStorage::getMapInfoFromSmartctl BEGIN"; + qCDebug(serviceLog) << "DeviceStorage::getMapInfoFromSmartctl BEGIN"; QString indexName; int startIndex = 0; @@ -864,22 +865,22 @@ void DeviceStorage::getMapInfoFromSmartctl(QMap &mapInfo, cons if (index > 0 && reg.exactMatch(line) == false && false == line.contains("Error") && false == line.contains("hh:mm:SS")) { #endif if (line.indexOf("(") < index && line.indexOf(")") > index) { - qDebug() << "bracket contains ch, continue"; + qCDebug(serviceLog) << "bracket contains ch, continue"; continue; } if (line.indexOf("[") < index && line.indexOf("]") > index) { - qDebug() << "square bracket contains ch, continue"; + qCDebug(serviceLog) << "square bracket contains ch, continue"; continue; } indexName = line.mid(0, index).trimmed().remove(" is"); if (mapInfo.contains(indexName)) { - qDebug() << "mapInfo contains indexName"; + qCDebug(serviceLog) << "mapInfo contains indexName"; mapInfo[indexName] += ", "; mapInfo[indexName] += line.mid(index + 1).trimmed(); } else { - qDebug() << "mapInfo not contains indexName"; + qCDebug(serviceLog) << "mapInfo not contains indexName"; mapInfo[indexName] = line.mid(index + 1).trimmed(); } continue; @@ -887,11 +888,11 @@ void DeviceStorage::getMapInfoFromSmartctl(QMap &mapInfo, cons if (indexName.isEmpty() == false && (line.startsWith("\t\t") || line.startsWith(" ")) && line.contains(":") == false) { if (mapInfo.contains(indexName)) { - qDebug() << "mapInfo contains indexName"; + qCDebug(serviceLog) << "mapInfo contains indexName"; mapInfo[indexName] += ", "; mapInfo[indexName] += line.trimmed(); } else { - qDebug() << "mapInfo not contains indexName"; + qCDebug(serviceLog) << "mapInfo not contains indexName"; mapInfo[indexName] = line.trimmed(); } @@ -903,14 +904,14 @@ void DeviceStorage::getMapInfoFromSmartctl(QMap &mapInfo, cons QRegularExpression rx("^[ ]*[0-9]+[ ]+([\\w-_]+)[ ]+0x[0-9a-fA-F-]+[ ]+[0-9]+[ ]+[0-9]+[ ]+[0-9]+[ ]+[\\w-]+[ ]+[\\w-]+[ ]+[\\w-]+[ ]+([0-9\\/w-]+[ ]*[ 0-9\\/w-()]*)$"); QRegularExpressionMatch matchR = rx.match(line); if (matchR.hasMatch()) { - qDebug() << "matchR.hasMatch() is true"; + qCDebug(serviceLog) << "matchR.hasMatch() is true"; mapInfo[matchR.captured(1)] = matchR.captured(2); continue; } #else QRegExp rx("^[ ]*[0-9]+[ ]+([\\w-_]+)[ ]+0x[0-9a-fA-F-]+[ ]+[0-9]+[ ]+[0-9]+[ ]+[0-9]+[ ]+[\\w-]+[ ]+[\\w-]+[ ]+[\\w-]+[ ]+([0-9\\/w-]+[ ]*[ 0-9\\/w-()]*)$"); if (rx.indexIn(line) > -1) { - qDebug() << "rx.indexIn(line) > -1"; + qCDebug(serviceLog) << "rx.indexIn(line) > -1"; mapInfo[rx.cap(1)] = rx.cap(2); continue; } @@ -919,126 +920,126 @@ void DeviceStorage::getMapInfoFromSmartctl(QMap &mapInfo, cons QStringList strList; if (line.endsWith(")")) { - qDebug() << "line endsWith )"; + qCDebug(serviceLog) << "line endsWith )"; int leftBracket = line.indexOf("("); if (leftBracket > 0) { - qDebug() << "leftBracket > 0"; + qCDebug(serviceLog) << "leftBracket > 0"; QString str = line.left(leftBracket).trimmed(); strList = str.trimmed().split(" "); if (strList.size() > 2) { - qDebug() << "strList.size() > 2"; + qCDebug(serviceLog) << "strList.size() > 2"; strList.last() += line.mid(leftBracket); } } } else if (strList.size() == 0) { - qDebug() << "strList.size() is 0"; + qCDebug(serviceLog) << "strList.size() is 0"; strList = line.trimmed().split(" "); } if (strList.size() < 5) { - qDebug() << "strList.size() < 5, continue"; + qCDebug(serviceLog) << "strList.size() < 5, continue"; continue; } if (line.contains("Power_On_Hours")) { - qDebug() << "line contains Power_On_Hours"; + qCDebug(serviceLog) << "line contains Power_On_Hours"; mapInfo["Power_On_Hours"] = strList.last(); continue; } if (line.contains("Power_Cycle_Count")) { - qDebug() << "line contains Power_Cycle_Count"; + qCDebug(serviceLog) << "line contains Power_Cycle_Count"; mapInfo["Power_Cycle_Count"] = strList.last(); continue; } if (line.contains("Raw_Read_Error_Rate")) { - qDebug() << "line contains Raw_Read_Error_Rate"; + qCDebug(serviceLog) << "line contains Raw_Read_Error_Rate"; mapInfo["Raw_Read_Error_Rate"] = strList.last(); continue; } if (line.contains("Spin_Up_Time")) { - qDebug() << "line contains Spin_Up_Time"; + qCDebug(serviceLog) << "line contains Spin_Up_Time"; mapInfo["Spin_Up_Time"] = strList.last(); continue; } if (line.contains("Start_Stop_Count")) { - qDebug() << "line contains Start_Stop_Count"; + qCDebug(serviceLog) << "line contains Start_Stop_Count"; mapInfo["Start_Stop_Count"] = strList.last(); continue; } if (line.contains("Reallocated_Sector_Ct")) { - qDebug() << "line contains Reallocated_Sector_Ct"; + qCDebug(serviceLog) << "line contains Reallocated_Sector_Ct"; mapInfo["Reallocated_Sector_Ct"] = strList.last(); continue; } if (line.contains("Seek_Error_Rate")) { - qDebug() << "line contains Seek_Error_Rate"; + qCDebug(serviceLog) << "line contains Seek_Error_Rate"; mapInfo["Seek_Error_Rate"] = strList.last(); continue; } if (line.contains("Spin_Retry_Count")) { - qDebug() << "line contains Spin_Retry_Count"; + qCDebug(serviceLog) << "line contains Spin_Retry_Count"; mapInfo["Spin_Retry_Count"] = strList.last(); continue; } if (line.contains("Calibration_Retry_Count")) { - qDebug() << "line contains Calibration_Retry_Count"; + qCDebug(serviceLog) << "line contains Calibration_Retry_Count"; mapInfo["Calibration_Retry_Count"] = strList.last(); continue; } if (line.contains("G-Sense_Error_Rate")) { - qDebug() << "line contains G-Sense_Error_Rate"; + qCDebug(serviceLog) << "line contains G-Sense_Error_Rate"; mapInfo["G-Sense_Error_Rate"] = strList.last(); continue; } if (line.contains("Power-Off_Retract_Count")) { - qDebug() << "line contains Power-Off_Retract_Count"; + qCDebug(serviceLog) << "line contains Power-Off_Retract_Count"; mapInfo["Power-Off_Retract_Count"] = strList.last(); continue; } if (line.contains("Load_Cycle_Count")) { - qDebug() << "line contains Load_Cycle_Count"; + qCDebug(serviceLog) << "line contains Load_Cycle_Count"; mapInfo["Load_Cycle_Count"] = strList.last(); continue; } if (line.contains("Temperature_Celsius")) { - qDebug() << "line contains Temperature_Celsius"; + qCDebug(serviceLog) << "line contains Temperature_Celsius"; mapInfo["Temperature_Celsius"] = strList.last(); continue; } if (line.contains("Reallocated_Event_Count")) { - qDebug() << "line contains Reallocated_Event_Count"; + qCDebug(serviceLog) << "line contains Reallocated_Event_Count"; mapInfo["Reallocated_Event_Count"] = strList.last(); continue; } if (line.contains("Current_Pending_Sector")) { - qDebug() << "line contains Current_Pending_Sector"; + qCDebug(serviceLog) << "line contains Current_Pending_Sector"; mapInfo["Current_Pending_Sector"] = strList.last(); continue; } if (line.contains("Offline_Uncorrectable")) { - qDebug() << "line contains Offline_Uncorrectable"; + qCDebug(serviceLog) << "line contains Offline_Uncorrectable"; mapInfo["Offline_Uncorrectable"] = strList.last(); continue; } if (line.contains("UDMA_CRC_Error_Count")) { - qDebug() << "line contains UDMA_CRC_Error_Count"; + qCDebug(serviceLog) << "line contains UDMA_CRC_Error_Count"; mapInfo["UDMA_CRC_Error_Count"] = strList.last(); continue; } if (line.contains("Multi_Zone_Error_Rate")) { - qDebug() << "line contains Multi_Zone_Error_Rate"; + qCDebug(serviceLog) << "line contains Multi_Zone_Error_Rate"; mapInfo["Multi_Zone_Error_Rate"] = strList.last(); continue; } } - qDebug() << "DeviceStorage::getMapInfoFromSmartctl END"; + qCDebug(serviceLog) << "DeviceStorage::getMapInfoFromSmartctl END"; } } diff --git a/service/diskoperation/blockspecial.cpp b/service/diskoperation/blockspecial.cpp index 4fbbabab..7e65f7d8 100644 --- a/service/diskoperation/blockspecial.cpp +++ b/service/diskoperation/blockspecial.cpp @@ -15,6 +15,7 @@ * along with this program; if not, see . */ +#include "ddlog.h" #include "blockspecial.h" #include @@ -46,7 +47,7 @@ BlockSpecial::BlockSpecial() , m_major(0UL) , m_minor(0UL) { - qDebug() << "BlockSpecial object created with empty name"; + qCDebug(serviceLog) << "BlockSpecial object created with empty name"; } BlockSpecial::BlockSpecial(const QString &name) @@ -54,50 +55,50 @@ BlockSpecial::BlockSpecial(const QString &name) , m_major(0UL) , m_minor(0UL) { - qDebug() << "BlockSpecial object created for device:" << name; + qCDebug(serviceLog) << "BlockSpecial object created for device:" << name; MMNumberMapping::const_iterator mmNumIter = mmNumberCache.find(name); if (mmNumIter != mmNumberCache.end()) { - qDebug() << "Found device in cache:" << name; + qCDebug(serviceLog) << "Found device in cache:" << name; // Use already cached major, minor pair m_major = mmNumIter.value().m_major; m_minor = mmNumIter.value().m_minor; return; } - qDebug() << "Device not in cache, calling stat:" << name; + qCDebug(serviceLog) << "Device not in cache, calling stat:" << name; MmNumber pair = {0UL, 0UL}; // Call stat(name, ...) to get the major, minor pair struct stat sb; if (stat(name.toStdString().c_str(), &sb) == 0 && S_ISBLK(sb.st_mode)) { - qDebug() << "stat successful and is a block device:" << name; + qCDebug(serviceLog) << "stat successful and is a block device:" << name; m_major = major(sb.st_rdev); m_minor = minor(sb.st_rdev); pair.m_major = m_major; pair.m_minor = m_minor; } else { - qDebug() << "stat failed or is not a block device:" << name; + qCDebug(serviceLog) << "stat failed or is not a block device:" << name; } // Add new cache entry for name to major, minor pair - qDebug() << "Adding new cache entry for" << name << "with major" << pair.m_major << "minor" << pair.m_minor; + qCDebug(serviceLog) << "Adding new cache entry for" << name << "with major" << pair.m_major << "minor" << pair.m_minor; mmNumberCache[name] = pair; } BlockSpecial::~BlockSpecial() { // Do not log in destructors of global variables, which can cause crashes - // qDebug() << "BlockSpecial object destroyed for device:" << m_name; + // qCDebug(serviceLog) << "BlockSpecial object destroyed for device:" << m_name; } void BlockSpecial::clearCache() { - qDebug() << "Clearing block device number cache"; + qCDebug(serviceLog) << "Clearing block device number cache"; mmNumberCache.clear(); } void BlockSpecial::registerBlockSpecial(const QString &name, unsigned long major, unsigned long minor) { - qDebug() << "Registering block device:" << name << "with major:" << major << "minor:" << minor; + qCDebug(serviceLog) << "Registering block device:" << name << "with major:" << major << "minor:" << minor; MmNumber pair; pair.m_major = major; pair.m_minor = minor; @@ -107,14 +108,14 @@ void BlockSpecial::registerBlockSpecial(const QString &name, unsigned long major bool operator==(const BlockSpecial &lhs, const BlockSpecial &rhs) { - // qDebug() << "Entering operator== for BlockSpecial"; + // qCDebug(serviceLog) << "Entering operator== for BlockSpecial"; if (lhs.m_major > 0UL || lhs.m_minor > 0UL) { - // qDebug() << "Comparing by major/minor number for" << lhs.m_name << "and" << rhs.m_name; + // qCDebug(serviceLog) << "Comparing by major/minor number for" << lhs.m_name << "and" << rhs.m_name; // Match block special files by major, minor device numbers. return lhs.m_major == rhs.m_major && lhs.m_minor == rhs.m_minor; } else { - // qDebug() << "Comparing by name for" << lhs.m_name << "and" << rhs.m_name; + // qCDebug(serviceLog) << "Comparing by name for" << lhs.m_name << "and" << rhs.m_name; // For non-block special files fall back to name string compare. return lhs.m_name == rhs.m_name; } @@ -122,14 +123,14 @@ bool operator==(const BlockSpecial &lhs, const BlockSpecial &rhs) bool operator<(const BlockSpecial &lhs, const BlockSpecial &rhs) { - // qDebug() << "Entering operator< for BlockSpecial"; + // qCDebug(serviceLog) << "Entering operator< for BlockSpecial"; if (lhs.m_major == 0 && rhs.m_major == 0 && lhs.m_minor == 0 && rhs.m_minor == 0) { - // qDebug() << "Comparing non-block special files by name for" << lhs.m_name << "and" << rhs.m_name; + // qCDebug(serviceLog) << "Comparing non-block special files by name for" << lhs.m_name << "and" << rhs.m_name; // Two non-block special files are ordered by name. return lhs.m_name < rhs.m_name; } else { - // qDebug() << "Comparing block special files by major/minor number for" << lhs.m_name << "and" << rhs.m_name; + // qCDebug(serviceLog) << "Comparing block special files by major/minor number for" << lhs.m_name << "and" << rhs.m_name; // Block special files are ordered by major, minor device numbers. return lhs.m_major < rhs.m_major || (lhs.m_major == rhs.m_major && lhs.m_minor < rhs.m_minor); } diff --git a/service/diskoperation/device.cpp b/service/diskoperation/device.cpp index 71f2910f..3262dce8 100644 --- a/service/diskoperation/device.cpp +++ b/service/diskoperation/device.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "device.h" #include @@ -10,7 +11,7 @@ namespace DiskManager { Device::Device() { - qDebug() << "Initializing Device object with DBus type registrations"; + qCDebug(serviceLog) << "Initializing Device object with DBus type registrations"; qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); @@ -48,23 +49,23 @@ Device::Device() m_highestBusy = 0; m_readonly = false; m_maxPartitionNameLength = 0; - qDebug() << "Device object initialized"; + qCDebug(serviceLog) << "Device object initialized"; } void Device::enablePartitionNaming(int length) { if (length > 0) { m_maxPartitionNameLength = length; - qDebug() << "Enabled partition naming with max length:" << length; + qCDebug(serviceLog) << "Enabled partition naming with max length:" << length; } else { m_maxPartitionNameLength = 0; - qDebug() << "Disabled partition naming"; + qCDebug(serviceLog) << "Disabled partition naming"; } } bool Device::partitionNamingSupported() const { - qDebug() << "Checking if partition naming is supported. Max length:" << m_maxPartitionNameLength; + qCDebug(serviceLog) << "Checking if partition naming is supported. Max length:" << m_maxPartitionNameLength; return m_maxPartitionNameLength > 0; } @@ -75,7 +76,7 @@ bool Device::partitionNamingSupported() const DeviceInfo Device::getDeviceInfo() { - qDebug() << "Entering Device::getDeviceInfo"; + qCDebug(serviceLog) << "Entering Device::getDeviceInfo"; DeviceInfo info; info.m_length = m_length; info.m_heads = m_heads; @@ -93,7 +94,7 @@ DeviceInfo Device::getDeviceInfo() info.m_interface = m_interface; info.m_mediaType = m_mediaType; - qDebug() << "Retrieving device info - Path:" << info.m_path + qCDebug(serviceLog) << "Retrieving device info - Path:" << info.m_path << "Length:" << info.m_length << "SectorSize:" << info.m_sectorSize << "MaxPrims:" << info.m_maxPrims; diff --git a/service/diskoperation/filesystems/btrfs.cpp b/service/diskoperation/filesystems/btrfs.cpp index d54562d2..49ac8a30 100644 --- a/service/diskoperation/filesystems/btrfs.cpp +++ b/service/diskoperation/filesystems/btrfs.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "btrfs.h" #include "fsinfo.h" #include @@ -19,21 +20,21 @@ std::map btrfs_device_cache; FS Btrfs::getFilesystemSupport() { - qDebug() << "Checking Btrfs filesystem support"; + qCDebug(serviceLog) << "Checking Btrfs filesystem support"; FS fs(FS_BTRFS); fs.busy = FS::GPARTED ; if (!Utils::findProgramInPath("mdir").isEmpty()) { - qDebug() << "mdir found, enabling create support"; + qCDebug(serviceLog) << "mdir found, enabling create support"; fs.create = FS::EXTERNAL; fs.create_with_label = FS::EXTERNAL; } if (!Utils::findProgramInPath("btrfs").isEmpty()) { - qDebug() << "btrfs found, enabling read, check, and write_label support"; + qCDebug(serviceLog) << "btrfs found, enabling read, check, and write_label support"; fs.read = FS::EXTERNAL; fs .read_label = FS::EXTERNAL ; fs .read_uuid = FS::EXTERNAL ; @@ -47,22 +48,22 @@ FS Btrfs::getFilesystemSupport() && fs.check && Utils::kernelSupportFS( "btrfs" )) { - qDebug() << "mount, umount, and kernel support found, enabling resize support"; + qCDebug(serviceLog) << "mount, umount, and kernel support found, enabling resize support"; fs.grow = FS::EXTERNAL ; if (fs.read) { //needed to determine a minimum file system size. - qDebug() << "read support found, enabling shrink support"; + qCDebug(serviceLog) << "read support found, enabling shrink support"; fs.shrink = FS::EXTERNAL ; } } } if (!Utils::findProgramInPath("btrfstune").isEmpty()) { - qDebug() << "btrfstune found, enabling write_uuid support"; + qCDebug(serviceLog) << "btrfstune found, enabling write_uuid support"; fs.write_uuid = FS::EXTERNAL; } if ( fs .check ) { - qDebug() << "check support found, enabling copy and move support"; + qCDebug(serviceLog) << "check support found, enabling copy and move support"; fs.copy = FS::GPARTED; fs.move = FS::GPARTED; } @@ -76,7 +77,7 @@ FS Btrfs::getFilesystemSupport() void Btrfs::setUsedSectors(Partition &partition) { - qDebug() << "Setting used sectors for partition:" << partition.getPath(); + qCDebug(serviceLog) << "Setting used sectors for partition:" << partition.getPath(); QString output, error; Utils::executCmd(QString("btrfs filesystem show %1").arg(partition.getPath()), output, error); @@ -89,36 +90,36 @@ void Btrfs::setUsedSectors(Partition &partition) //Btrfs file system wide used bytes (extents and items) QString str ; if (!(str = Utils::regexpLabel(output, "FS bytes used ([0-9\\.]+( ?[KMGTPE]?i?B)?)" ) ).isEmpty()) { - qDebug() << "Found total fs used string:" << str; + qCDebug(serviceLog) << "Found total fs used string:" << str; total_fs_used = qRound64( btrfsSize2Double(str)) ; } QString::size_type offset = 0 ; QString::size_type index ; while ((index = output.indexOf("devid ", offset)) != -1) { - // qDebug() << "Found devid at index:" << index; + // qCDebug(serviceLog) << "Found devid at index:" << index; QString devid_path = Utils::regexpLabel(output.mid(index), "devid .* path (/dev/[[:graph:]]+)" ) ; if (!devid_path.isEmpty()) { - // qDebug() << "Found devid path:" << devid_path; + // qCDebug(serviceLog) << "Found devid path:" << devid_path; //Btrfs per devid used bytes (chunks) Byte_Value used = -1 ; if (!(str = Utils::regexpLabel( output.mid( index ), "devid .* used ([0-9\\.]+( ?[KMGTPE]?i?B)?) path" ) ).isEmpty()) { - // qDebug() << "Found used string for devid:" << str; + // qCDebug(serviceLog) << "Found used string for devid:" << str; used = btrfsSize2num(str, ptn_size, false) ; sum_devid_used += used ; if ( devid_path.contains(partition.getPath())) { - // qDebug() << "devid_path contains partition path, setting devid_used"; + // qCDebug(serviceLog) << "devid_path contains partition path, setting devid_used"; devid_used = used ; } } if ( devid_path.contains(partition.getPath())) { - // qDebug() << "devid_path contains partition path, getting device size"; + // qCDebug(serviceLog) << "devid_path contains partition path, getting device size"; //Btrfs per device size bytes (chunks) if (!(str = Utils::regexpLabel( output.mid(index), "devid .* size ([0-9\\.]+( ?[KMGTPE]?i?B)?) used " ) ).isEmpty()); @@ -130,7 +131,7 @@ void Btrfs::setUsedSectors(Partition &partition) if ( total_fs_used > -1 && devid_size > -1 && devid_used > -1 && sum_devid_used > 0 ) { - qDebug() << "Calculating and setting sector usage"; + qCDebug(serviceLog) << "Calculating and setting sector usage"; auto t = qRound64( devid_size / double(partition.m_sectorSize)) ; //ptn fs size double ptn_fs_used = total_fs_used * ( devid_used / double(sum_devid_used) ) ; //ptn fs used auto n = t - qRound64( ptn_fs_used / double(partition.m_sectorSize) ) ; @@ -140,20 +141,20 @@ void Btrfs::setUsedSectors(Partition &partition) void Btrfs::readLabel(Partition &partition) { - qDebug() << "Reading label for partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading label for partition:" << partition.getPath(); QString output, error; Utils::executCmd(QString("btrfs filesystem show %1").arg(partition.getPath()), output, error); if (output.contains("Label: none uuid:")) { - qDebug() << "Label is none"; + qCDebug(serviceLog) << "Label is none"; partition.setFilesystemLabel(""); } else { - qDebug() << "Label is not none, extracting label"; + qCDebug(serviceLog) << "Label is not none, extracting label"; // Try matching a label enclosed in single quotes, then without quotes, to // handle reporting of mounted file systems by old btrfs-progs 3.12. QString label = Utils::regexpLabel(output, "'(.*)'") ; if (!label.isEmpty()) { - qDebug() << "Label found with single quotes, removing them"; + qCDebug(serviceLog) << "Label found with single quotes, removing them"; label = label.replace("'", ""); } partition.setFilesystemLabel(label); @@ -164,11 +165,11 @@ void Btrfs::readLabel(Partition &partition) bool Btrfs::writeLabel(const Partition &partition) { - qDebug() << "Writing label for partition:" << partition.getPath() + qCDebug(serviceLog) << "Writing label for partition:" << partition.getPath() << "new label:" << partition.getFileSystemLabel(); QString output, error; if (partition.m_busy) { - qDebug() << "Partition is busy, unmounting it"; + qCDebug(serviceLog) << "Partition is busy, unmounting it"; Utils::executCmd(QString("umount -v %1").arg(partition.getPath()), output, error); } @@ -183,7 +184,7 @@ bool Btrfs::writeLabel(const Partition &partition) void Btrfs::readUuid(Partition &partition) { - qDebug() << "Reading UUID for partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading UUID for partition:" << partition.getPath(); QString output, error; auto exitCode = Utils::executCmd(QString("btrfs filesystem show %1").arg(partition.getPath()), output, error); //In many cases the exit status doesn't reflect valid output or an error condition @@ -191,14 +192,14 @@ void Btrfs::readUuid(Partition &partition) QString uuid = Utils::regexpLabel(output, "[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}"); if (!uuid.isEmpty()) { - qDebug() << "Found UUID:" << uuid; + qCDebug(serviceLog) << "Found UUID:" << uuid; partition.m_uuid = uuid; } } bool Btrfs::writeUuid(const Partition &partition) { - qInfo() << "Writing new UUID for partition:" << partition.getPath(); + qCInfo(serviceLog) << "Writing new UUID for partition:" << partition.getPath(); QString output, error; auto exitCode = Utils::executCmd(QString("btrfstune -f -u ").arg(partition.getPath()), output, error); return exitCode == 0; @@ -206,15 +207,15 @@ bool Btrfs::writeUuid(const Partition &partition) bool Btrfs::create(const Partition &new_partition) { - qDebug() << "Creating Btrfs filesystem on:" << new_partition.getPath() + qCDebug(serviceLog) << "Creating Btrfs filesystem on:" << new_partition.getPath() << "with label:" << new_partition.getFileSystemLabel(); QString output, error; QString cmd; if (new_partition.getFileSystemLabel().isEmpty() || new_partition.getFileSystemLabel() == " ") { - qDebug() << "Label is empty, creating without label"; + qCDebug(serviceLog) << "Label is empty, creating without label"; cmd = QString("mkfs.btrfs -f %1").arg(new_partition.getPath()); } else { - qDebug() << "Label is not empty, creating with label"; + qCDebug(serviceLog) << "Label is not empty, creating with label"; cmd = QString("mkfs.btrfs -f -L %1 %2").arg(new_partition.getFileSystemLabel()).arg(new_partition.getPath()); } auto exitCode = Utils::executCmd(cmd, output, error); @@ -223,14 +224,14 @@ bool Btrfs::create(const Partition &new_partition) bool Btrfs::resize(const Partition &partitionNew, bool fillPartition) { - qDebug() << "Resizing Btrfs filesystem on:" << partitionNew.getPath() + qCDebug(serviceLog) << "Resizing Btrfs filesystem on:" << partitionNew.getPath() << "fill partition:" << fillPartition; bool success = true ; QString path = partitionNew.getPath(); const BTRFS_Device& btrfsDev = getCacheEntry(path); if (btrfsDev.devid == -1 ) { - qDebug() << "Invalid devid, returning false"; + qCDebug(serviceLog) << "Invalid devid, returning false"; return false; } QString devIdStr = QString("%1").arg(btrfsDev.devid); @@ -238,39 +239,39 @@ bool Btrfs::resize(const Partition &partitionNew, bool fillPartition) QString mountPoint; QString output, error; if (!partitionNew.m_busy) { - qDebug() << "Partition is not busy, mounting to temporary directory"; + qCDebug(serviceLog) << "Partition is not busy, mounting to temporary directory"; mountPoint = Utils::mkTempDir(""); if (mountPoint.isEmpty()) { - qDebug() << "Failed to create temporary directory"; + qCDebug(serviceLog) << "Failed to create temporary directory"; return false ; } success &= Utils::executCmd(QString("mount -v -t btrfs %1 %2").arg(path).arg(mountPoint), output, error) == 0; } else { - qDebug() << "Partition is busy, finding existing mount point"; + qCDebug(serviceLog) << "Partition is busy, finding existing mount point"; auto mountPoints = partitionNew.getMountPoints(); foreach (auto m , mountPoints) { - // qDebug() << "Checking mount point:" << m; + // qCDebug(serviceLog) << "Checking mount point:" << m; QDir dir(m); if (dir.exists()) { - // qDebug() << "Mount point exists, using it:" << m; + // qCDebug(serviceLog) << "Mount point exists, using it:" << m; mountPoint = m; } } if (mountPoint.isEmpty()) { - qDebug() << "No existing mount point found"; + qCDebug(serviceLog) << "No existing mount point found"; return false; } } if (success) { - qDebug() << "Mount successful, resizing filesystem"; + qCDebug(serviceLog) << "Mount successful, resizing filesystem"; QString size ; if (!fillPartition) { - qDebug() << "Not filling partition, calculating size"; + qCDebug(serviceLog) << "Not filling partition, calculating size"; size = QString("%1").arg(qFloor(Utils::sectorToUnit(partitionNew.getSectorLength(), partitionNew.m_sectorSize, UNIT_KIB))); size += "K"; } else { - qDebug() << "Filling partition, size is max"; + qCDebug(serviceLog) << "Filling partition, size is max"; size = "max"; } QString output, error; @@ -280,7 +281,7 @@ bool Btrfs::resize(const Partition &partitionNew, bool fillPartition) .arg(mountPoint), output, error) == 0; if (!partitionNew.m_busy) { - qDebug() << "Unmounting temporary directory"; + qCDebug(serviceLog) << "Unmounting temporary directory"; success &= Utils::executCmd(QString("umount -v %1").arg(mountPoint), output, error) == 0; } } @@ -293,13 +294,13 @@ bool Btrfs::resize(const Partition &partitionNew, bool fillPartition) bool Btrfs::resize(const QString &path, const QString &size, bool fillPartition) { - qDebug() << "Btrfs::resize is not implemented"; + qCDebug(serviceLog) << "Btrfs::resize is not implemented"; return false; } bool Btrfs::checkRepair(const Partition &partition) { - qDebug() << "Checking/repairing Btrfs filesystem on:" << partition.getPath(); + qCDebug(serviceLog) << "Checking/repairing Btrfs filesystem on:" << partition.getPath(); QString path = partition.getPath(); return checkRepair(path); } @@ -314,10 +315,10 @@ bool Btrfs::checkRepair(const QString &devpath) const BTRFS_Device &Btrfs::getCacheEntry(const QString &path) { - qDebug() << "Btrfs::getCacheEntry BEGIN"; + qCDebug(serviceLog) << "Btrfs::getCacheEntry BEGIN"; std::map::const_iterator bd_iter = btrfs_device_cache.find(BlockSpecial(path)); if ( bd_iter != btrfs_device_cache .end() ) { - qDebug() << "found in cache"; + qCDebug(serviceLog) << "found in cache"; return bd_iter ->second ; } @@ -343,7 +344,7 @@ const BTRFS_Device &Btrfs::getCacheEntry(const QString &path) auto items = line.split(" ", QString::SkipEmptyParts); #endif if (line.trimmed().startsWith("devid") && items.size() == 8) { - qDebug() << "found devid line"; + qCDebug(serviceLog) << "found devid line"; devIdList.push_back(items[1].toInt()); pathList.push_back(items[7]); } @@ -351,13 +352,13 @@ const BTRFS_Device &Btrfs::getCacheEntry(const QString &path) //Add cache entries for all found devices std::vector bs_list; for (unsigned int i = 0 ; i < pathList.size() ; i ++ ) { - // qDebug() << "add path to bs_list"; + // qCDebug(serviceLog) << "add path to bs_list"; bs_list.push_back( BlockSpecial(pathList[i] ) ); } for (unsigned int i = 0 ; i < devIdList .size() ; i ++ ) { - // qDebug() << "add devid to cache"; + // qCDebug(serviceLog) << "add devid to cache"; BTRFS_Device btrfs_dev ; btrfs_dev.devid = devIdList[i] ; btrfs_dev.members = bs_list; @@ -366,23 +367,23 @@ const BTRFS_Device &Btrfs::getCacheEntry(const QString &path) bd_iter = btrfs_device_cache.find( BlockSpecial( path ) ); if ( bd_iter != btrfs_device_cache .end() ) { - qDebug() << "found in cache again"; + qCDebug(serviceLog) << "found in cache again"; return bd_iter ->second ; } //If for any reason we fail to parse the information return an "unknown" record - qDebug() << "fail to parse the information return an unknown record"; + qCDebug(serviceLog) << "fail to parse the information return an unknown record"; static BTRFS_Device btrfs_dev = { -1, } ; return btrfs_dev ; } double Btrfs::btrfsSize2Double(QString &str) { - qDebug() << "Btrfs::btrfsSize2Double BEGIN"; + qCDebug(serviceLog) << "Btrfs::btrfsSize2Double BEGIN"; //"FS bytes used 51.52GiB" QString numStr = Utils::regexpLabel(str, "[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]"); if (!numStr.isEmpty()) { - qDebug() << "numStr is not empty"; + qCDebug(serviceLog) << "numStr is not empty"; double num = numStr.toDouble(); int index = str.indexOf(numStr); int pos = index + numStr.length(); @@ -397,16 +398,16 @@ double Btrfs::btrfsSize2Double(QString &str) case 'E': mult = EXBIBYTE ; break ; default: mult = 1 ; break ; } - qDebug() << "Btrfs::btrfsSize2Double END"; + qCDebug(serviceLog) << "Btrfs::btrfsSize2Double END"; return mult * num; } - qDebug() << "Btrfs::btrfsSize2Double END"; + qCDebug(serviceLog) << "Btrfs::btrfsSize2Double END"; return 0; } Byte_Value Btrfs::btrfsSize2num(QString &str, Byte_Value ptn_bytes, bool scale_up) { - qDebug() << "Btrfs::btrfsSize2num BEGIN"; + qCDebug(serviceLog) << "Btrfs::btrfsSize2num BEGIN"; Byte_Value size_bytes = qRound64( btrfsSize2Double(str )) ; double delta = btrfsSizeMaxDelta( str) ; Byte_Value upper_size = size_bytes + ceil(delta) ; @@ -414,16 +415,16 @@ Byte_Value Btrfs::btrfsSize2num(QString &str, Byte_Value ptn_bytes, bool scale_u if ( size_bytes > ptn_bytes && lower_size <= ptn_bytes ) { - qDebug() << "size_bytes > ptn_bytes && lower_size <= ptn_bytes"; + qCDebug(serviceLog) << "size_bytes > ptn_bytes && lower_size <= ptn_bytes"; size_bytes = ptn_bytes ; } else if ( scale_up && size_bytes < ptn_bytes && upper_size > ptn_bytes ) { - qDebug() << "scale_up && size_bytes < ptn_bytes && upper_size > ptn_bytes"; + qCDebug(serviceLog) << "scale_up && size_bytes < ptn_bytes && upper_size > ptn_bytes"; size_bytes = ptn_bytes ; } - qDebug() << "Btrfs::btrfsSize2num END"; + qCDebug(serviceLog) << "Btrfs::btrfsSize2num END"; return size_bytes ; } @@ -431,7 +432,7 @@ Byte_Value Btrfs::btrfsSize2num(QString &str, Byte_Value ptn_bytes, bool scale_u // tools to str. E.g. btrfs_size_max_delta("2.00GB") -> 5368709.12 double Btrfs::btrfsSizeMaxDelta(QString &str) { - qDebug() << "Btrfs::btrfsSizeMaxDelta BEGIN"; + qCDebug(serviceLog) << "Btrfs::btrfsSizeMaxDelta BEGIN"; QString limit_str ; //Create limit_str. E.g. str = "2.00GB" -> limit_str = "0.005GB" for (int i = 0; i < str.length(); ++i) { @@ -446,17 +447,17 @@ double Btrfs::btrfsSizeMaxDelta(QString &str) } } double max_delta = btrfsSize2Double(limit_str) ; - qDebug() << "Btrfs::btrfsSizeMaxDelta END"; + qCDebug(serviceLog) << "Btrfs::btrfsSizeMaxDelta END"; return max_delta ; } FS_Limits Btrfs::getFilesystemLimits(const Partition &partition) { - qDebug() << "Btrfs::getFilesystemLimits BEGIN"; + qCDebug(serviceLog) << "Btrfs::getFilesystemLimits BEGIN"; //m_fsLimits.min_size = 256 * MEBIBYTE; m_fsLimits.min_size = -1; m_fsLimits.max_size = -1; - qDebug() << "Btrfs::getFilesystemLimits END"; + qCDebug(serviceLog) << "Btrfs::getFilesystemLimits END"; return m_fsLimits; } diff --git a/service/diskoperation/filesystems/exfat.cpp b/service/diskoperation/filesystems/exfat.cpp index f015b16f..5fbf1b7b 100644 --- a/service/diskoperation/filesystems/exfat.cpp +++ b/service/diskoperation/filesystems/exfat.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "exfat.h" #include #include @@ -10,7 +11,7 @@ namespace DiskManager { FS ExFat::getFilesystemSupport() { - qDebug() << "Checking exFAT filesystem support"; + qCDebug(serviceLog) << "Checking exFAT filesystem support"; FS fs(FS_EXFAT); fs.busy = FS::GPARTED; @@ -19,18 +20,18 @@ FS ExFat::getFilesystemSupport() fs.online_read = FS::GPARTED; if (!Utils::findProgramInPath("dump.exfat").isEmpty()) { - qDebug() << "dump.exfat found, enabling read support"; + qCDebug(serviceLog) << "dump.exfat found, enabling read support"; fs.read = FS::EXTERNAL; } QString output, error; if (!Utils::findProgramInPath("mkfs.exfat").isEmpty()) { - qDebug() << "mkfs.exfat found, enabling create support"; + qCDebug(serviceLog) << "mkfs.exfat found, enabling create support"; fs.create = FS::EXTERNAL; } if (!Utils::findProgramInPath("tune.exfat").isEmpty()) { - qDebug() << "tune.exfat found, enabling label and uuid support"; + qCDebug(serviceLog) << "tune.exfat found, enabling label and uuid support"; fs.read_label = FS::EXTERNAL; fs.write_label = FS::EXTERNAL; @@ -38,17 +39,17 @@ FS ExFat::getFilesystemSupport() // 1.1.0. Check the help text for the feature before enabling. Utils::executCmd("tune.exfat", output, error); if (error.indexOf("Set volume serial") < error.length()) { - qDebug() << "tune.exfat supports setting volume serial, enabling uuid read/write"; + qCDebug(serviceLog) << "tune.exfat supports setting volume serial, enabling uuid read/write"; fs.read_uuid = FS::EXTERNAL; fs.write_uuid = FS::EXTERNAL; } } if (!Utils::findProgramInPath("fsck.exfat").isEmpty()) { - qDebug() << "fsck.exfat found, checking version for check support"; + qCDebug(serviceLog) << "fsck.exfat found, checking version for check support"; Utils::executCmd("fsck.exfat -V", output, error); if (output.contains("exfatprogs version")) { - qDebug() << "fsck.exfat from exfatprogs found, enabling check support"; + qCDebug(serviceLog) << "fsck.exfat from exfatprogs found, enabling check support"; fs.check = FS::EXTERNAL; } } @@ -60,13 +61,13 @@ FS ExFat::getFilesystemSupport() void ExFat::setUsedSectors(DiskManager::Partition &partition) { - qDebug() << "Setting used sectors for exFAT partition:" << partition.getPath(); + qCDebug(serviceLog) << "Setting used sectors for exFAT partition:" << partition.getPath(); QString output, error; auto errCode = Utils::executCmd("dump.exfat ", output, error); // dump.exfat returns non-zero status for both success and failure. Instead use // non-empty stderr to identify failure. if (!error.isEmpty() || errCode != 0) { - qDebug() << "dump.exfat failed with error:" << error << "and exit code:" << errCode; + qCDebug(serviceLog) << "dump.exfat failed with error:" << error << "and exit code:" << errCode; return; } @@ -87,7 +88,7 @@ void ExFat::setUsedSectors(DiskManager::Partition &partition) long long volume_length = -1; int index = output.indexOf("Volume Length(sectors):"); if (index < output.length()) { - qDebug() << "Found Volume Length"; + qCDebug(serviceLog) << "Found Volume Length"; sscanf(output.mid(index).toStdString().c_str(), "Volume Length(sectors): %lld", &volume_length); } @@ -95,7 +96,7 @@ void ExFat::setUsedSectors(DiskManager::Partition &partition) long long bytes_per_sector_shift = -1; index = output.indexOf("Sector Size Bits:"); if (index < output.length()) { - qDebug() << "Found Sector Size Bits"; + qCDebug(serviceLog) << "Found Sector Size Bits"; sscanf(output.mid(index).toStdString().c_str(), "Sector Size Bits: %lld", &bytes_per_sector_shift); } @@ -103,7 +104,7 @@ void ExFat::setUsedSectors(DiskManager::Partition &partition) long long sectors_per_cluster_shift = -1; index = output.indexOf("Sector per Cluster bits:"); if (index < output.length()) { - qDebug() << "Found Sector per Cluster bits"; + qCDebug(serviceLog) << "Found Sector per Cluster bits"; sscanf(output.mid(index).toStdString().c_str(), "Sector per Cluster bits: %lld", §ors_per_cluster_shift); } @@ -112,13 +113,13 @@ void ExFat::setUsedSectors(DiskManager::Partition &partition) long long free_clusters = -1; index = output.indexOf("Free Clusters:"); if (index < output.length()) { - qDebug() << "Found Free Clusters"; + qCDebug(serviceLog) << "Found Free Clusters"; sscanf(output.mid(index).toStdString().c_str(), "Free Clusters: %lld", &free_clusters); } if (volume_length > -1 && bytes_per_sector_shift > -1 && sectors_per_cluster_shift > -1 && free_clusters > -1) { - qDebug() << "All required values found, calculating and setting sector usage"; + qCDebug(serviceLog) << "All required values found, calculating and setting sector usage"; Byte_Value sector_size = 1 << bytes_per_sector_shift; Byte_Value cluster_size = sector_size * (1 << sectors_per_cluster_shift); Sector fs_free = free_clusters * cluster_size / partition.m_sectorSize; @@ -130,11 +131,11 @@ void ExFat::setUsedSectors(DiskManager::Partition &partition) void ExFat::readLabel(DiskManager::Partition &partition) { - qDebug() << "Reading label for exFAT partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading label for exFAT partition:" << partition.getPath(); QString output, error; auto errCode = Utils::executCmd(QString("tune.exfat -l %1").arg(partition.getPath()), output, error); if (errCode != 0) { - qDebug() << "tune.exfat -l failed with exit code:" << errCode; + qCDebug(serviceLog) << "tune.exfat -l failed with exit code:" << errCode; return; } @@ -143,26 +144,26 @@ void ExFat::readLabel(DiskManager::Partition &partition) bool ExFat::writeLabel(const DiskManager::Partition &partition) { - qDebug() << "Writing label for exFAT partition:" << partition.getPath() + qCDebug(serviceLog) << "Writing label for exFAT partition:" << partition.getPath() << "new label:" << partition.getFileSystemLabel(); QString cmd, output, error; if (!partition.getFileSystemLabel().isEmpty() && partition.getFileSystemLabel() != " ") { - qDebug() << "Label is not empty, writing it"; + qCDebug(serviceLog) << "Label is not empty, writing it"; cmd = QString("tune.exfat -L %1 %2").arg(partition.getFileSystemLabel()).arg(partition.getPath()); auto errCode = Utils::executCmd(cmd, output, error); return errCode == 0; } - qDebug() << "Label is empty, doing nothing"; + qCDebug(serviceLog) << "Label is empty, doing nothing"; return true; } void ExFat::readUuid(DiskManager::Partition &partition) { - qDebug() << "Reading UUID for exFAT partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading UUID for exFAT partition:" << partition.getPath(); QString output, error; auto errCode = Utils::executCmd(QString("tune.exfat -i %1").arg(partition.getPath()), output, error); if (errCode != 0) { - qDebug() << "tune.exfat -i failed with exit code:" << errCode; + qCDebug(serviceLog) << "tune.exfat -i failed with exit code:" << errCode; return; } partition.m_uuid = serial2BlkidUuid( @@ -171,7 +172,7 @@ void ExFat::readUuid(DiskManager::Partition &partition) bool ExFat::writeUuid(const DiskManager::Partition &partition) { - qDebug() << "Writing new UUID for exFAT partition:" << partition.getPath(); + qCDebug(serviceLog) << "Writing new UUID for exFAT partition:" << partition.getPath(); QString output, error; auto errCode = Utils::executCmd(QString("tune.exfat -I %1 %2") .arg(randomSerial()) @@ -181,14 +182,14 @@ bool ExFat::writeUuid(const DiskManager::Partition &partition) bool ExFat::create(const DiskManager::Partition &new_partition) { - qDebug() << "Creating exFAT filesystem on:" << new_partition.getPath() + qCDebug(serviceLog) << "Creating exFAT filesystem on:" << new_partition.getPath() << "with label:" << new_partition.getFileSystemLabel(); QString cmd, output, error; if (new_partition.getFileSystemLabel().isEmpty() || new_partition.getFileSystemLabel() == " ") { - qDebug() << "Label is empty, creating without label"; + qCDebug(serviceLog) << "Label is empty, creating without label"; cmd = QString("mkfs.exfat %1").arg(new_partition.getPath()); } else { - qDebug() << "Label is not empty, creating with label"; + qCDebug(serviceLog) << "Label is not empty, creating with label"; cmd = QString("mkfs.exfat -n %1 %2").arg(new_partition.getFileSystemLabel()).arg(new_partition.getPath()); } auto errCode = Utils::executCmd(cmd, output, error); @@ -197,26 +198,26 @@ bool ExFat::create(const DiskManager::Partition &new_partition) bool ExFat::resize(const DiskManager::Partition &partitionNew, bool fillPartition) { - qDebug() << "Entering ExFat::resize for partition:" << partitionNew.getPath(); + qCDebug(serviceLog) << "Entering ExFat::resize for partition:" << partitionNew.getPath(); return FileSystem::resize(partitionNew, fillPartition); } bool DiskManager::ExFat::resize(const QString &path, const QString &size, bool fillPartition) { - qDebug() << "Entering ExFat::resize for path:" << path; + qCDebug(serviceLog) << "Entering ExFat::resize for path:" << path; return FileSystem::resize(path, size, fillPartition); } bool DiskManager::ExFat::checkRepair(const DiskManager::Partition &partition) { - qDebug() << "Entering ExFat::checkRepair for partition:" << partition.getPath(); + qCDebug(serviceLog) << "Entering ExFat::checkRepair for partition:" << partition.getPath(); QString path = partition.getPath(); return checkRepair(path); } bool DiskManager::ExFat::checkRepair(const QString &devpath) { - qDebug() << "Checking/repairing exFAT filesystem on:" << devpath; + qCDebug(serviceLog) << "Checking/repairing exFAT filesystem on:" << devpath; QString output, error; auto errCode = Utils::executCmd(QString("fsck.exfat %1").arg(devpath), output, error); return errCode == 0; @@ -224,7 +225,7 @@ bool DiskManager::ExFat::checkRepair(const QString &devpath) FS_Limits DiskManager::ExFat::getFilesystemLimits(const DiskManager::Partition &partition) { - qDebug() << "Entering ExFat::getFilesystemLimits"; + qCDebug(serviceLog) << "Entering ExFat::getFilesystemLimits"; m_fsLimits.min_size = -1; m_fsLimits.max_size = -1; return m_fsLimits; @@ -232,10 +233,10 @@ FS_Limits DiskManager::ExFat::getFilesystemLimits(const DiskManager::Partition & QString DiskManager::ExFat::serial2BlkidUuid(QString serial) { - qDebug() << "Entering ExFat::serial2BlkidUuid for serial:" << serial; + qCDebug(serviceLog) << "Entering ExFat::serial2BlkidUuid for serial:" << serial; QString verifiedSerial = Utils::regexpLabel(serial, "^(0x[[:xdigit:]][[:xdigit:]]*)$"); if (verifiedSerial.isEmpty()) { - qDebug() << "Serial is not valid"; + qCDebug(serviceLog) << "Serial is not valid"; return verifiedSerial; } @@ -246,7 +247,7 @@ QString DiskManager::ExFat::serial2BlkidUuid(QString serial) QString DiskManager::ExFat::randomSerial() { - qDebug() << "Generating random serial number for exFAT"; + qCDebug(serviceLog) << "Generating random serial number for exFAT"; return "0x" + QUuid::createUuid().toString().mid(0, 8); } diff --git a/service/diskoperation/filesystems/ext2.cpp b/service/diskoperation/filesystems/ext2.cpp index c6606119..71b34687 100644 --- a/service/diskoperation/filesystems/ext2.cpp +++ b/service/diskoperation/filesystems/ext2.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "ext2.h" #include "utils.h" @@ -13,12 +14,12 @@ EXT2::EXT2(FSType type) : m_forceAuto64bit(false) , m_specificType(type) { - qDebug() << "EXT2/3/4 filesystem handler created for type:" << Utils::fileSystemTypeToString(type); + qCDebug(serviceLog) << "EXT2/3/4 filesystem handler created for type:" << Utils::fileSystemTypeToString(type); } FS EXT2::getFilesystemSupport() { - qDebug() << "Checking ext2/3/4 filesystem support for type:" << Utils::fileSystemTypeToString(m_specificType); + qCDebug(serviceLog) << "Checking ext2/3/4 filesystem support for type:" << Utils::fileSystemTypeToString(m_specificType); FS fs(m_specificType); fs.busy = FS::GPARTED; @@ -26,14 +27,14 @@ FS EXT2::getFilesystemSupport() m_mkfsCmd = "mkfs." + Utils::fileSystemTypeToString(m_specificType); bool have_64bit_feature = false; if (!Utils::findProgramInPath(m_mkfsCmd).isEmpty()) { - qDebug() << "Found" << m_mkfsCmd << ", enabling create support"; + qCDebug(serviceLog) << "Found" << m_mkfsCmd << ", enabling create support"; fs.create = FS::EXTERNAL; fs.create_with_label = FS::EXTERNAL; // Determine mkfs.ext4 version specific capabilities. m_forceAuto64bit = false; if (m_specificType == FS_EXT4) { - qDebug() << "Filesystem is ext4, checking version capabilities"; + qCDebug(serviceLog) << "Filesystem is ext4, checking version capabilities"; Utils::executCmd(QString("%1%2").arg(m_mkfsCmd).arg(" -V"), output, error); int mke2fs_major_ver = 0; int mke2fs_minor_ver = 0; @@ -41,7 +42,7 @@ FS EXT2::getFilesystemSupport() if (sscanf(output.toLatin1().data(), "mke2fs %d.%d.%d", &mke2fs_major_ver, &mke2fs_minor_ver, &mke2fs_patch_ver) >= 2) { - qDebug() << "mke2fs version:" << mke2fs_major_ver << "." << mke2fs_minor_ver << "." << mke2fs_patch_ver; + qCDebug(serviceLog) << "mke2fs version:" << mke2fs_major_ver << "." << mke2fs_minor_ver << "." << mke2fs_patch_ver; // Ext4 64bit feature was added in e2fsprogs 1.42, but // only enable large volumes from 1.42.9 when a large // number of 64bit bugs were fixed. @@ -52,7 +53,7 @@ FS EXT2::getFilesystemSupport() have_64bit_feature = (mke2fs_major_ver > 1) || (mke2fs_major_ver == 1 && mke2fs_minor_ver > 42) || (mke2fs_major_ver == 1 && mke2fs_minor_ver == 42 && mke2fs_patch_ver >= 9); - qDebug() << "64bit feature support:" << have_64bit_feature; + qCDebug(serviceLog) << "64bit feature support:" << have_64bit_feature; // (#766910) E2fsprogs 1.43 creates 64bit ext4 file // systems by default. RHEL/CentOS 7 configured e2fsprogs @@ -64,56 +65,56 @@ FS EXT2::getFilesystemSupport() // with 64bit ext4 file systems. m_forceAuto64bit = (mke2fs_major_ver > 1) || (mke2fs_major_ver == 1 && mke2fs_minor_ver >= 42); - qDebug() << "Forcing auto 64bit:" << m_forceAuto64bit; + qCDebug(serviceLog) << "Forcing auto 64bit:" << m_forceAuto64bit; } } } if (!Utils::findProgramInPath("dumpe2fs").isEmpty()) { - qDebug() << "dumpe2fs found, enabling read support"; + qCDebug(serviceLog) << "dumpe2fs found, enabling read support"; fs.read = FS::EXTERNAL; fs.online_read = FS::EXTERNAL; } if (!Utils::findProgramInPath("tune2fs").isEmpty()) { - qDebug() << "tune2fs found, enabling uuid read/write support"; + qCDebug(serviceLog) << "tune2fs found, enabling uuid read/write support"; fs.read_uuid = FS::EXTERNAL; fs.write_uuid = FS::EXTERNAL; } if (!Utils::findProgramInPath("e2label").isEmpty()) { - qDebug() << "e2label found, enabling label read/write support"; + qCDebug(serviceLog) << "e2label found, enabling label read/write support"; fs.read_label = FS::EXTERNAL; fs.write_label = FS::EXTERNAL; } if (!Utils::findProgramInPath("e2fsck").isEmpty()) { - qDebug() << "e2fsck found, enabling check support"; + qCDebug(serviceLog) << "e2fsck found, enabling check support"; fs.check = FS::EXTERNAL; } if (!Utils::findProgramInPath("resize2fs").isEmpty()) { - qDebug() << "resize2fs found, enabling grow support"; + qCDebug(serviceLog) << "resize2fs found, enabling grow support"; fs.grow = FS::EXTERNAL; if (fs.read) { // Needed to determine a min file system size.. - qDebug() << "read support found, enabling shrink support"; + qCDebug(serviceLog) << "read support found, enabling shrink support"; fs.shrink = FS::EXTERNAL; } } if (fs.check) { - qDebug() << "check support found, enabling copy/move"; + qCDebug(serviceLog) << "check support found, enabling copy/move"; fs.copy = fs.move = FS::GPARTED; // If supported, use e2image to copy/move the file system as it only // copies used blocks, skipping unused blocks. This is more efficient // than copying all blocks used by GParted's internal method. if (!Utils::findProgramInPath("e2image").isEmpty()) { - qDebug() << "e2image found, checking for -o src_offset support"; + qCDebug(serviceLog) << "e2image found, checking for -o src_offset support"; Utils::executCmd("e2image", output, error); if (Utils::regexpLabel(output, "(-o src_offset)") == "-o src_offset") { - qDebug() << "e2image supports -o src_offset, using it for copy/move"; + qCDebug(serviceLog) << "e2image supports -o src_offset, using it for copy/move"; fs.copy = fs.move = FS::EXTERNAL; } } @@ -127,7 +128,7 @@ FS EXT2::getFilesystemSupport() // #766910 comment #12 onwards for further discussion. // https://bugzilla.gnome.org/show_bug.cgi?id=766910#c12 if (m_specificType == FS_EXT2 || m_specificType == FS_EXT3 || (m_specificType == FS_EXT4 && !have_64bit_feature)) { - qDebug() << "Setting max filesystem size for non-64bit ext4 or ext2/3"; + qCDebug(serviceLog) << "Setting max filesystem size for non-64bit ext4 or ext2/3"; m_fsLimits.max_size = Utils::floorSize(16 * TEBIBYTE - 4 * KIBIBYTE, MEBIBYTE); } @@ -136,11 +137,11 @@ FS EXT2::getFilesystemSupport() void EXT2::setUsedSectors(Partition &partition) { - qDebug() << "Setting used sectors for ext2/3/4 partition:" << partition.getPath(); + qCDebug(serviceLog) << "Setting used sectors for ext2/3/4 partition:" << partition.getPath(); QString output, error, strcmd; strcmd = QString("dumpe2fs -h %1").arg(partition.getPath()); - qDebug() << "Executing dumpe2fs command to get filesystem information"; + qCDebug(serviceLog) << "Executing dumpe2fs command to get filesystem information"; if (!Utils::executCmd(strcmd, output, error)) { long long blockCount = -1; long long blockSize = -1; @@ -151,7 +152,7 @@ void EXT2::setUsedSectors(Partition &partition) QString strmatch = "Block count:"; int index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found block count information"; + qCDebug(serviceLog) << "Found block count information"; blockCount = Utils::regexpLabel(output, QString("(?<=Block count:).*(?=\n)")).trimmed().toLong(); } @@ -159,7 +160,7 @@ void EXT2::setUsedSectors(Partition &partition) strmatch = "Block size:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found block size information"; + qCDebug(serviceLog) << "Found block size information"; blockSize = Utils::regexpLabel(output, QString("(?<=Block size:).*(?=\n)")).trimmed().toLong(); } @@ -167,7 +168,7 @@ void EXT2::setUsedSectors(Partition &partition) strmatch = "Free blocks:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found free blocks information"; + qCDebug(serviceLog) << "Found free blocks information"; freeBlocks = Utils::regexpLabel(output, QString("(?<=Free blocks:).*(?=\n)")).trimmed().toLong(); } @@ -175,13 +176,13 @@ void EXT2::setUsedSectors(Partition &partition) strmatch = "Reserved block count:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found reserved blocks information"; + qCDebug(serviceLog) << "Found reserved blocks information"; reservedBlocks = Utils::regexpLabel(output, QString("(?<=Reserved block count:).*(?=\n)")).trimmed().toLong(); } // 验证数据有效性并计算扇区使用情况 if (blockCount > 0 && blockSize > 0 && freeBlocks >= 0 && reservedBlocks >= 0) { - qDebug() << "Filesystem information validation successful, calculating sector usage"; + qCDebug(serviceLog) << "Filesystem information validation successful, calculating sector usage"; // 计算用户实际可用的空闲块数:可用 = (freeBlocks - reservedBlocks) long long userAvailableBlocks = (freeBlocks > reservedBlocks) ? (freeBlocks - reservedBlocks) : 0; @@ -190,7 +191,7 @@ void EXT2::setUsedSectors(Partition &partition) Sector totalSectors = qRound64(blockCount * (blockSize / double(partition.m_sectorSize))); Sector availableSectors = qRound64(userAvailableBlocks * (blockSize / double(partition.m_sectorSize))); - qDebug() << "EXT* usage calculation: blockCount=" << blockCount + qCDebug(serviceLog) << "EXT* usage calculation: blockCount=" << blockCount << "blockSize=" << blockSize << "freeBlocks=" << freeBlocks << "reservedBlocks=" << reservedBlocks @@ -200,68 +201,68 @@ void EXT2::setUsedSectors(Partition &partition) // 如果分区已挂载,使用 stat 获取更准确的可用块数 if (partition.m_busy && !partition.getMountPoints().empty()) { - qDebug() << "Partition is mounted, using stat for more accurate available space calculation"; + qCDebug(serviceLog) << "Partition is mounted, using stat for more accurate available space calculation"; Byte_Value statTotalSize, statAvailableSize; if (Utils::getMountedFileSystemUsage(partition.getMountPoint(), statTotalSize, statAvailableSize) == 0) { // 使用 stat 获取的可用空间(已经排除了保留空间) Sector statAvailableSectors = qRound64(statAvailableSize / double(partition.m_sectorSize)); - qDebug() << "Using stat data for mounted partition: statAvailableSectors=" << statAvailableSectors; + qCDebug(serviceLog) << "Using stat data for mounted partition: statAvailableSectors=" << statAvailableSectors; partition.setSectorUsage(totalSectors, statAvailableSectors); - qDebug() << "Sector usage set successfully using stat data"; + qCDebug(serviceLog) << "Sector usage set successfully using stat data"; } else { - qDebug() << "Failed to get mounted filesystem usage, using calculated available sectors"; + qCDebug(serviceLog) << "Failed to get mounted filesystem usage, using calculated available sectors"; partition.setSectorUsage(totalSectors, availableSectors); - qDebug() << "Sector usage set successfully using calculated data"; + qCDebug(serviceLog) << "Sector usage set successfully using calculated data"; } } else { - qDebug() << "Partition is not mounted, using calculated available sectors"; + qCDebug(serviceLog) << "Partition is not mounted, using calculated available sectors"; partition.setSectorUsage(totalSectors, availableSectors); - qDebug() << "Sector usage set successfully"; + qCDebug(serviceLog) << "Sector usage set successfully"; } partition.m_fsBlockSize = blockSize; - qDebug() << "Filesystem block size set to:" << blockSize; + qCDebug(serviceLog) << "Filesystem block size set to:" << blockSize; } else { - qDebug() << "Filesystem information validation failed, invalid parameters detected"; + qCDebug(serviceLog) << "Filesystem information validation failed, invalid parameters detected"; } } else { - qDebug() << "dumpe2fs command execution failed, error:" << error; - qDebug() << "Failed to set used sectors for partition:" << partition.getPath(); + qCDebug(serviceLog) << "dumpe2fs command execution failed, error:" << error; + qCDebug(serviceLog) << "Failed to set used sectors for partition:" << partition.getPath(); } } void EXT2::readLabel(Partition &partition) { - qDebug() << "Reading label for ext2/3/4 partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading label for ext2/3/4 partition:" << partition.getPath(); QString output, error; if (!Utils::executCmd(QString("e2label %1").arg(partition.getPath()), output, error)) { partition.setFilesystemLabel(output.trimmed()); } -// qDebug() << __FUNCTION__ << output << error; +// qCDebug(serviceLog) << __FUNCTION__ << output << error; } bool EXT2::writeLabel(const Partition &partition) { - qDebug() << "Writing label for ext2/3/4 partition:" << partition.getPath() + qCDebug(serviceLog) << "Writing label for ext2/3/4 partition:" << partition.getPath() << "new label:" << partition.getFileSystemLabel(); QString output, error; int exitcode = Utils::executCmd(QString("e2label %1 %2").arg(partition.getPath()).arg(partition.getFileSystemLabel()), output, error); -// qDebug() << __FUNCTION__ << output << error; +// qCDebug(serviceLog) << __FUNCTION__ << output << error; return exitcode == 0; } void EXT2::readUuid(Partition &partition) { - qDebug() << "Reading UUID for ext2/3/4 partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading UUID for ext2/3/4 partition:" << partition.getPath(); QString output, error; if (!Utils::executCmd(QString("tune2fs -l %1").arg(partition.getPath()), output, error)) { partition.m_uuid = Utils::regexpLabel(output, "(?<=Filesystem UUID:).*(?=\n)").trimmed(); } -// qDebug() << __FUNCTION__ << output << error; +// qCDebug(serviceLog) << __FUNCTION__ << output << error; } bool EXT2::writeUuid(const Partition &partition) { - qDebug() << "Writing new UUID for ext2/3/4 partition:" << partition.getPath(); + qCDebug(serviceLog) << "Writing new UUID for ext2/3/4 partition:" << partition.getPath(); QString output, error; int exitcode = Utils::executCmd(QString("tune2fs -U random ").arg(partition.getPath()), output, error); return exitcode == 0 || error.compare("Unknown error") == 0; @@ -269,7 +270,7 @@ bool EXT2::writeUuid(const Partition &partition) bool EXT2::create(const Partition &new_partition) { - qDebug() << "Creating ext2/3/4 filesystem on:" << new_partition.getPath() + qCDebug(serviceLog) << "Creating ext2/3/4 filesystem on:" << new_partition.getPath() << "with label:" << new_partition.getFileSystemLabel(); QString features, output, error, cmd; if (m_forceAuto64bit) { @@ -277,25 +278,25 @@ bool EXT2::create(const Partition &new_partition) // by setting or clearing the 64bit feature on the command line depending // of the partition size. if (new_partition.getByteLength() >= 16 * TEBIBYTE) { - qDebug() << "Partition is >= 16TiB, forcing 64bit feature"; + qCDebug(serviceLog) << "Partition is >= 16TiB, forcing 64bit feature"; features = " -O 64bit"; } else { - qDebug() << "Partition is < 16TiB, forcing no 64bit feature"; + qCDebug(serviceLog) << "Partition is < 16TiB, forcing no 64bit feature"; features = " -O ^64bit"; } } QString strlabel = new_partition.getFileSystemLabel(); if (strlabel == " ") { - qDebug() << "Label is a single space, creating without label"; + qCDebug(serviceLog) << "Label is a single space, creating without label"; cmd = QString("%1%2%3%4%5").arg(m_mkfsCmd).arg(" -F").arg(features).arg(" ").arg(new_partition.getPath()); } else { - qDebug() << "Label is not a single space, creating with label if not empty"; + qCDebug(serviceLog) << "Label is not a single space, creating with label if not empty"; strlabel = strlabel.isEmpty() ? strlabel : QString(" -L %1").arg(strlabel); cmd = QString("%1%2%3%4%5%6").arg(m_mkfsCmd).arg(" -F").arg(features).arg(strlabel).arg(" ").arg(new_partition.getPath()); } - qDebug() << " EXT2::create***** " << cmd; + qCDebug(serviceLog) << " EXT2::create***** " << cmd; int exitcode = Utils::executCmd(cmd, output, error); -// qDebug() << "EXT2::create-------" << output << error; +// qCDebug(serviceLog) << "EXT2::create-------" << output << error; return exitcode == 0 || error.compare("Unknown error") == 0; } @@ -314,100 +315,100 @@ G=1024*1024*1024 */ bool EXT2::resize(const Partition &partitionNew, bool fillPartition) { - qDebug() << "EXT2::resize(Partition) BEGIN"; + qCDebug(serviceLog) << "EXT2::resize(Partition) BEGIN"; double d = Utils::sectorToUnit(partitionNew.getSectorLength(), partitionNew.m_sectorSize, UNIT_KIB); return resize(partitionNew.getPath(), QString::number(((long long)d)), fillPartition); } bool EXT2::resize(const QString &path, const QString &size, bool fillPartition) { - qDebug() << "EXT2::resize(path, size) BEGIN"; + qCDebug(serviceLog) << "EXT2::resize(path, size) BEGIN"; QString str_temp = QString("resize2fs -p %1").arg(path); if (!fillPartition) { - qDebug() << "fillPartition is false"; + qCDebug(serviceLog) << "fillPartition is false"; str_temp = QString("%1 %2K").arg(str_temp).arg(size); } QString output, error; int exitcode = Utils::executCmd(str_temp, output, error); - qDebug() << "EXT2::resize(path, size) END"; + qCDebug(serviceLog) << "EXT2::resize(path, size) END"; return 0 == exitcode || 0 == error.compare("Unknown error"); } bool EXT2::checkRepair(const Partition &partition) { - qDebug() << "Checking/repairing ext2/3/4 filesystem on partition:" << partition.getPath(); + qCDebug(serviceLog) << "Checking/repairing ext2/3/4 filesystem on partition:" << partition.getPath(); return checkRepair(partition.getPath()); } bool EXT2::checkRepair(const QString &devpath) { - qDebug() << "Checking/repairing ext2/3/4 filesystem on:" << devpath; + qCDebug(serviceLog) << "Checking/repairing ext2/3/4 filesystem on:" << devpath; QString output, error; int exitcode = Utils::executCmd(QString("e2fsck -f -y -v -C 0 %1").arg(devpath), output, error); -// qDebug() << QString("EXT2::check_repair---%1----%2").arg(output).arg(error); +// qCDebug(serviceLog) << QString("EXT2::check_repair---%1----%2").arg(output).arg(error); return 0 == exitcode || 0 == error.compare("Unknown error"); } FS_Limits EXT2::getFilesystemLimits(const Partition &partition) { - qDebug() << "EXT2::getFilesystemLimits(Partition) BEGIN"; + qCDebug(serviceLog) << "EXT2::getFilesystemLimits(Partition) BEGIN"; return getFilesystemLimits(partition.getPath()); } FS_Limits EXT2::getFilesystemLimits(const QString &path) { - qDebug() << "EXT2::getFilesystemLimits(path) BEGIN"; + qCDebug(serviceLog) << "EXT2::getFilesystemLimits(path) BEGIN"; m_fsLimits = FS_Limits{-1, -1}; QString output, error; int exitcode = Utils::executCmd(QString("e2fsck -f %1").arg(path), output, error); if (exitcode != 0 && error.compare("Unknown error") != 0) { - qDebug() << "e2fsck failed, return"; + qCDebug(serviceLog) << "e2fsck failed, return"; return m_fsLimits; } auto getNumber = [ = ](QString cmd, QString split1, QString split2)->long long{ - qDebug() << "getNumber BEGIN"; + qCDebug(serviceLog) << "getNumber BEGIN"; QString output, error; int exitcode = Utils::executCmd(cmd, output, error); if (exitcode != 0 && error.compare("Unknown error") != 0) { - qDebug() << "executCmd failed, return -1"; + qCDebug(serviceLog) << "executCmd failed, return -1"; return -1; } foreach (QString str, output.split("\n")) { if (str.contains(split1)) { - // qDebug() << "found split1"; + // qCDebug(serviceLog) << "found split1"; auto list = str.split(split2); if (list.count() == 2) { - qDebug() << "found split2, return value"; + qCDebug(serviceLog) << "found split2, return value"; return list[1].trimmed().toLongLong(); } } } - qDebug() << "getNumber END, return -1"; + qCDebug(serviceLog) << "getNumber END, return -1"; return -1; }; long long blockSize = getNumber(QString("tune2fs -l %1").arg(path), "Block size:", ":"); if (-1 == blockSize) { - qDebug() << "blockSize is -1, return"; + qCDebug(serviceLog) << "blockSize is -1, return"; return m_fsLimits; } long long blockCount = getNumber(QString("resize2fs -P %1").arg(path), "Estimated minimum size of the filesystem:", ":"); if (-1 == blockCount) { - qDebug() << "blockCount is -1, return"; + qCDebug(serviceLog) << "blockCount is -1, return"; return m_fsLimits; } m_fsLimits.max_size = 0; m_fsLimits.min_size = blockSize * blockCount; - qDebug() << "EXT2::getFilesystemLimits(path) END"; + qCDebug(serviceLog) << "EXT2::getFilesystemLimits(path) END"; return m_fsLimits; } diff --git a/service/diskoperation/filesystems/fat16.cpp b/service/diskoperation/filesystems/fat16.cpp index 68dc20fb..0bbb5063 100644 --- a/service/diskoperation/filesystems/fat16.cpp +++ b/service/diskoperation/filesystems/fat16.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "fat16.h" #include "utils.h" @@ -16,7 +17,7 @@ namespace DiskManager { FS FAT16::getFilesystemSupport() { - qDebug() << "Checking FAT16/FAT32 filesystem support"; + qCDebug(serviceLog) << "Checking FAT16/FAT32 filesystem support"; FS fs(specificType); // hack to disable silly mtools warnings @@ -25,35 +26,35 @@ FS FAT16::getFilesystemSupport() fs.busy = FS::GPARTED ; if (!Utils::findProgramInPath("mdir").isEmpty()) { - qDebug() << "mdir found, enabling uuid and read support"; + qCDebug(serviceLog) << "mdir found, enabling uuid and read support"; fs.read_uuid = FS::EXTERNAL; if (!Utils::findProgramInPath("minfo").isEmpty()) { - qDebug() << "minfo found, enabling read support"; + qCDebug(serviceLog) << "minfo found, enabling read support"; fs.read = FS::EXTERNAL; } } //find out if we can create fat file systems if (!Utils::findProgramInPath( "mkfs.fat" ).isEmpty()) { - qDebug() << "mkfs.fat found, enabling create support"; + qCDebug(serviceLog) << "mkfs.fat found, enabling create support"; fs.create = FS::EXTERNAL; fs.create_with_label = FS::EXTERNAL; } if (!Utils::findProgramInPath( "fsck.fat" ).isEmpty()) { - qDebug() << "fsck.fat found, enabling check support"; + qCDebug(serviceLog) << "fsck.fat found, enabling check support"; fs.check = FS::EXTERNAL; } if (!Utils::findProgramInPath( "mlabel" ).isEmpty()) { - qDebug() << "mlabel found, enabling label and uuid write support"; + qCDebug(serviceLog) << "mlabel found, enabling label and uuid write support"; fs.read_label = FS::EXTERNAL; fs.write_label = FS::EXTERNAL; fs.write_uuid = FS::EXTERNAL; } #ifdef HAVE_LIBPARTED_FS_RESIZE - qDebug() << "libparted fs resize support found, enabling grow and shrink"; + qCDebug(serviceLog) << "libparted fs resize support found, enabling grow and shrink"; //resizing of start and endpoint are provided by libparted fs.grow = FS::LIBPARTED; fs.shrink = FS::LIBPARTED; @@ -63,11 +64,11 @@ FS FAT16::getFilesystemSupport() fs.online_read = FS::GPARTED; if (fs.fstype == FS_FAT16) { - qDebug() << "Setting filesystem limits for FAT16"; + qCDebug(serviceLog) << "Setting filesystem limits for FAT16"; m_fsLimits.min_size = 16 * MEBIBYTE; m_fsLimits.max_size = (4096 - 1) * MEBIBYTE; // Maximum seems to be just less than 4096 MiB. } else { - qDebug() << "Setting filesystem limits for FAT32"; + qCDebug(serviceLog) << "Setting filesystem limits for FAT32"; //FS_FAT32 m_fsLimits.min_size = 33 * MEBIBYTE; // Smaller file systems will cause Windows' scandisk to fail. @@ -84,7 +85,7 @@ FS FAT16::getFilesystemSupport() void FAT16::setUsedSectors( Partition & partition ) { - qDebug() << "Setting used sectors for FAT partition:" << partition.getPath(); + qCDebug(serviceLog) << "Setting used sectors for FAT partition:" << partition.getPath(); QString output, error, strmatch, strcmd; Sector logicalSectorSize,clusterSize,smallSize,bigSize; @@ -105,7 +106,7 @@ void FAT16::setUsedSectors( Partition & partition ) #endif if (spacedNumberStr.size() > 0) { - qDebug() << "Found free bytes string:" << spacedNumberStr; + qCDebug(serviceLog) << "Found free bytes string:" << spacedNumberStr; m_numOfFreeOrUsedBlocks = atoll(spacedNumberStr.toStdString().c_str()); } } @@ -121,7 +122,7 @@ void FAT16::setUsedSectors( Partition & partition ) strmatch = "sector size:"; int index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found sector size"; + qCDebug(serviceLog) << "Found sector size"; list = Utils::regexpLabel(output, QString("(?<=sector size:).*(?=\n)")).trimmed().split(" "); logicalSectorSize = list.at(0).toLong(); } @@ -130,7 +131,7 @@ void FAT16::setUsedSectors( Partition & partition ) strmatch = "cluster size:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found cluster size"; + qCDebug(serviceLog) << "Found cluster size"; list = Utils::regexpLabel(output, QString("(?<=cluster size:).*(?=\n)")).trimmed().split(" "); clusterSize = list.at(0).toLong(); } @@ -139,7 +140,7 @@ void FAT16::setUsedSectors( Partition & partition ) strmatch = "small size:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found small size"; + qCDebug(serviceLog) << "Found small size"; list = Utils::regexpLabel(output, QString("(?<=small size:).*(?=\n)")).trimmed().split(" "); smallSize = list.at(0).toLong(); } @@ -148,17 +149,17 @@ void FAT16::setUsedSectors( Partition & partition ) strmatch = "big size:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { - qDebug() << "Found big size"; + qCDebug(serviceLog) << "Found big size"; list = Utils::regexpLabel(output, QString("(?<=big size:).*(?=\n)")).trimmed().split(" "); bigSize = list.at(0).toLong(); } if (bigSize <= 0 && smallSize <= 0) { - qDebug() << "Big size and small size are 0, parsing mformat command line"; + qCDebug(serviceLog) << "Big size and small size are 0, parsing mformat command line"; list = output.split("\n"); for (int i = 0; i < list.size(); i++) { if (list.at(i).contains("mformat command line: mformat -T ")) { - qDebug() << "Found mformat command line"; + qCDebug(serviceLog) << "Found mformat command line"; QStringList slist = list.at(i).split("-T"); list.clear(); list = slist.at(1).split("-h"); @@ -172,22 +173,22 @@ void FAT16::setUsedSectors( Partition & partition ) // FS size in logical sectors long long logical_sectors = -1; if (smallSize > 0) { - qDebug() << "Using small size for logical sectors"; + qCDebug(serviceLog) << "Using small size for logical sectors"; logical_sectors = smallSize; } else if (bigSize > 0) { - qDebug() << "Using big size for logical sectors"; + qCDebug(serviceLog) << "Using big size for logical sectors"; logical_sectors = bigSize; } else { - qDebug() << "Using total number of blocks for logical sectors"; + qCDebug(serviceLog) << "Using total number of blocks for logical sectors"; logical_sectors = m_totalNumOfBlock; } if (m_numOfFreeOrUsedBlocks > -1 && logicalSectorSize > -1 && clusterSize > -1 && logical_sectors > -1) { - qDebug() << "All values found, calculating and setting sector usage"; + qCDebug(serviceLog) << "All values found, calculating and setting sector usage"; Sector fsfree = m_numOfFreeOrUsedBlocks / partition.m_sectorSize; Sector fsSize = logical_sectors * logicalSectorSize / partition.m_sectorSize; -// qDebug() << __FUNCTION__ << fs_free << fs_size; +// qCDebug(serviceLog) << __FUNCTION__ << fs_free << fs_size; partition.setSectorUsage(fsSize, fsfree); partition.m_fsBlockSize = logicalSectorSize * clusterSize; } @@ -197,20 +198,20 @@ void FAT16::setUsedSectors( Partition & partition ) void FAT16::readLabel( Partition & partition ) { - qDebug() << "Reading label for FAT partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading label for FAT partition:" << partition.getPath(); QString output, error, filesystemLabel; QString partitionPath = partition.getPath().remove("/dev/"); if (!Utils::executCmd(QString("ls -l /dev/disk/by-label"), output, error)) { if(output.indexOf(partitionPath)) { - qDebug() << "Found partition path in ls output"; + qCDebug(serviceLog) << "Found partition path in ls output"; QStringList list = output.split("\n"); for (int i = 0; i < list.size(); i++) { if(list.at(i).indexOf(partitionPath) != -1) { - // qDebug() << "Found line with partition path:" << list.at(i); + // qCDebug(serviceLog) << "Found line with partition path:" << list.at(i); QStringList slist = list.at(i).split(" "); for (int j = 0; j < slist.size(); j++) { if(slist.at(j) == "->" && j != 0) { - qDebug() << "Found label:" << slist.at(j-1); + qCDebug(serviceLog) << "Found label:" << slist.at(j-1); filesystemLabel = slist.at(j-1); break; } @@ -220,7 +221,7 @@ void FAT16::readLabel( Partition & partition ) } } if (!filesystemLabel.isEmpty()) { - qDebug() << "Setting filesystem label:" << filesystemLabel; + qCDebug(serviceLog) << "Setting filesystem label:" << filesystemLabel; partition.setFilesystemLabel(filesystemLabel); } @@ -228,45 +229,45 @@ void FAT16::readLabel( Partition & partition ) bool FAT16::writeLabel(const Partition & partition) { - qDebug() << "Writing label for FAT partition:" << partition.getPath() + qCDebug(serviceLog) << "Writing label for FAT partition:" << partition.getPath() << "new label:" << partition.getFileSystemLabel(); QString output, error, cmd; if (partition.getFileSystemLabel().isEmpty() || partition.getFileSystemLabel() == " ") { - qDebug() << "Label is empty, clearing it"; + qCDebug(serviceLog) << "Label is empty, clearing it"; cmd = QString("mlabel -c :: -i %1").arg(partition.getPath()); } else { - qDebug() << "Label is not empty, setting it"; + qCDebug(serviceLog) << "Label is not empty, setting it"; cmd = QString("mlabel :: %1 -i %2").arg(partition.getFileSystemLabel()).arg(partition.getPath()); } -// qDebug() << __FUNCTION__ << cmd; +// qCDebug(serviceLog) << __FUNCTION__ << cmd; int exitcode = Utils::executCmd(cmd, output, error); -// qDebug() << __FUNCTION__ << exitcode; -// qDebug() << __FUNCTION__ << output << error; +// qCDebug(serviceLog) << __FUNCTION__ << exitcode; +// qCDebug(serviceLog) << __FUNCTION__ << output << error; return exitcode == 0; } void FAT16::readUuid( Partition & partition ) { - qDebug() << "Reading UUID for FAT partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading UUID for FAT partition:" << partition.getPath(); QString output, error; QString cmd = QString("mdir -f :: -i %1").arg(partition.getPath()); if (!Utils::executCmd( cmd, output, error)) { - qDebug() << "mdir successful, parsing volume serial number"; + qCDebug(serviceLog) << "mdir successful, parsing volume serial number"; partition.m_uuid = Utils::regexpLabel(output, "Volume Serial Number is[[:blank:]]([^[:space:]]+)"); if (partition .m_uuid == "0000-0000") { - qDebug() << "Volume serial number is 0000-0000, clearing it"; + qCDebug(serviceLog) << "Volume serial number is 0000-0000, clearing it"; partition .m_uuid .clear() ; } } -// qDebug() << __FUNCTION__ << output << error; +// qCDebug(serviceLog) << __FUNCTION__ << output << error; } bool FAT16::writeUuid(const Partition & partition) { - qDebug() << "Writing new UUID for FAT partition:" << partition.getPath(); + qCDebug(serviceLog) << "Writing new UUID for FAT partition:" << partition.getPath(); QString output, error; int exitcode = Utils::executCmd(QString("mlabel -s -n :: -i ").arg(partition.getPath()), output, error); return exitcode == 0 || error.compare("Unknown error") == 0; @@ -274,51 +275,51 @@ bool FAT16::writeUuid(const Partition & partition) bool FAT16::create(const Partition & new_partition) { - qDebug() << "Creating FAT filesystem on:" << new_partition.getPath() + qCDebug(serviceLog) << "Creating FAT filesystem on:" << new_partition.getPath() << "with label:" << new_partition.getFileSystemLabel(); QString output, error, cmd; QString fat_size = (specificType == FS_FAT16 ? "16" : "32"); int exitcode = -1; if (new_partition.getFileSystemLabel().isEmpty() || new_partition.getFileSystemLabel() == " ") { - qDebug() << "Label is empty, creating without label"; + qCDebug(serviceLog) << "Label is empty, creating without label"; cmd = QString("mkfs.fat -F %1 -v -I %2").arg(fat_size).arg(new_partition.getPath()); } else { - qDebug() << "Label is not empty, creating with label"; + qCDebug(serviceLog) << "Label is not empty, creating with label"; cmd = QString("mkfs.fat -F %1 -v -I -n %2 %3").arg(fat_size).arg(new_partition.getFileSystemLabel()).arg(new_partition.getPath()); } - qDebug() << "FAT16::create***** " << cmd; + qCDebug(serviceLog) << "FAT16::create***** " << cmd; exitcode = Utils::executCmd(cmd ,output, error); return exitcode == 0 && error.compare("Unknown error") == 0; } bool FAT16::checkRepair(const Partition &partition) { - qDebug() << "Checking/repairing FAT filesystem on partition:" << partition.getPath(); + qCDebug(serviceLog) << "Checking/repairing FAT filesystem on partition:" << partition.getPath(); return checkRepair(partition.getPath()); } bool FAT16::checkRepair(const QString &devpath) { - qDebug() << "Checking/repairing FAT filesystem on:" << devpath; + qCDebug(serviceLog) << "Checking/repairing FAT filesystem on:" << devpath; QString output, error; int exitcode = Utils::executCmd(QString("fsck.fat -a -w -v %1").arg(devpath), output, error); -// qDebug() << QString("EXT2::check_repair---%1----%2").arg(output).arg(error); +// qCDebug(serviceLog) << QString("EXT2::check_repair---%1----%2").arg(output).arg(error); return exitcode == 0 || error.compare("Unknown error") == 0; } FS_Limits FAT16::getFilesystemLimits(const Partition &partition) { - qDebug() << "FAT16::getFilesystemLimits(Partition) BEGIN"; + qCDebug(serviceLog) << "FAT16::getFilesystemLimits(Partition) BEGIN"; return getFilesystemLimits(partition.getPath()); } FS_Limits FAT16::getFilesystemLimits(const QString &path) { - qDebug() << "FAT16::getFilesystemLimits(path) BEGIN"; + qCDebug(serviceLog) << "FAT16::getFilesystemLimits(path) BEGIN"; m_fsLimits = FS_Limits {-1, 0}; if (Utils::findProgramInPath("fatresize").isEmpty()) { - qDebug() << "fatresize not found, return"; + qCDebug(serviceLog) << "fatresize not found, return"; return m_fsLimits; } @@ -327,7 +328,7 @@ FS_Limits FAT16::getFilesystemLimits(const QString &path) QString output, error; int exitcode = Utils::executCmd(QString("fatresize %1 -i").arg(path), output, error); if (exitcode != 0) { - qDebug() << "fatresize failed, return"; + qCDebug(serviceLog) << "fatresize failed, return"; return m_fsLimits; } long long minSize = 0, maxSize = 0; @@ -337,24 +338,24 @@ FS_Limits FAT16::getFilesystemLimits(const QString &path) foreach (QString str, output.split("\n")) { if (str.contains("FAT")) { - qDebug() << "found FAT string"; + qCDebug(serviceLog) << "found FAT string"; if (str.contains("fat32")) { - qDebug() << "is fat32"; + qCDebug(serviceLog) << "is fat32"; fs = FS_FAT32; } else if (str.contains("fat16")) { - qDebug() << "is fat16"; + qCDebug(serviceLog) << "is fat16"; fs = FS_FAT16; } } if (str.contains("Min size:")) { - qDebug() << "found Min size"; + qCDebug(serviceLog) << "found Min size"; QStringList list = str.split(":"); minSize = list.size() == 2 ? list[1].trimmed().toLongLong() : static_cast(-1); } if (str.contains("Max size:")) { - qDebug() << "found Max size"; + qCDebug(serviceLog) << "found Max size"; QStringList list = str.split(":"); maxSize = list.size() == 2 ? list[1].trimmed().toLongLong() : static_cast(-1); } @@ -362,37 +363,37 @@ FS_Limits FAT16::getFilesystemLimits(const QString &path) if (fs == FS_UNKNOWN) { - qDebug() << "fs is unknown, return"; + qCDebug(serviceLog) << "fs is unknown, return"; return m_fsLimits; } if (fs == FS_FAT16) { - qDebug() << "fs is fat16"; + qCDebug(serviceLog) << "fs is fat16"; if (maxSize > 64 * MEBIBYTE) { - qDebug() << "maxSize > 64MB"; + qCDebug(serviceLog) << "maxSize > 64MB"; maxSize = 64 * MEBIBYTE; } } if (fs == FS_FAT32) { - qDebug() << "fs is fat32"; + qCDebug(serviceLog) << "fs is fat32"; if (minSize < 512 * MEBIBYTE) { - qDebug() << "minSize < 512MB"; + qCDebug(serviceLog) << "minSize < 512MB"; minSize = 512 * MEBIBYTE; } } m_fsLimits.max_size = maxSize; m_fsLimits.min_size = minSize; - qDebug() << "FAT16::getFilesystemLimits(path) END"; + qCDebug(serviceLog) << "FAT16::getFilesystemLimits(path) END"; return m_fsLimits; } //fat格式需要操作分区表 lvm不支持fat格式的调整大小 fatresize命令也不是一个好的调整分区大小方式 相对来说libparted库更合适 bool FAT16::resize(const Partition &partitionNew, bool fillPartition) { - // qDebug() << "FAT16::resize(Partition) BEGIN"; + // qCDebug(serviceLog) << "FAT16::resize(Partition) BEGIN"; double d = Utils::sectorToUnit(partitionNew.getSectorLength(), partitionNew.m_sectorSize, UNIT_KIB); return resize(partitionNew.getPath(), QString::number(((long long)d)), fillPartition); } @@ -403,12 +404,12 @@ fatresize */ bool FAT16::resize(const QString &path, const QString &size, bool fillPartition) { - // qDebug() << "FAT16::resize(path, size) BEGIN"; + // qCDebug(serviceLog) << "FAT16::resize(path, size) BEGIN"; Q_UNUSED(fillPartition) //通过fatresize获取文件系统类型以及最小文件系统 QString output, error; int exitcode = Utils::executCmd(QString("fatresize %1 -s %2ki").arg(path).arg(size), output, error); - qDebug() << "FAT16::resize(path, size) END"; + qCDebug(serviceLog) << "FAT16::resize(path, size) END"; return 0 == exitcode || error.compare("Unknown error") == 0; } diff --git a/service/diskoperation/filesystems/filesystem.cpp b/service/diskoperation/filesystems/filesystem.cpp index ece8acc2..70cc9cdc 100644 --- a/service/diskoperation/filesystems/filesystem.cpp +++ b/service/diskoperation/filesystems/filesystem.cpp @@ -1,7 +1,8 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only +#include "ddlog.h" #include "filesystem.h" #include @@ -9,6 +10,6 @@ namespace DiskManager { FileSystem::FileSystem() { - // qDebug() << "Constructing a FileSystem object."; + // qCDebug(serviceLog) << "Constructing a FileSystem object."; } } // namespace DiskManager diff --git a/service/diskoperation/filesystems/linuxswap.cpp b/service/diskoperation/filesystems/linuxswap.cpp index 7484d149..6036732d 100644 --- a/service/diskoperation/filesystems/linuxswap.cpp +++ b/service/diskoperation/filesystems/linuxswap.cpp @@ -16,6 +16,7 @@ * along with this program; if not, see . */ +#include "ddlog.h" #include "linuxswap.h" #include "utils.h" #include "diskoperation/blockspecial.h" @@ -27,7 +28,7 @@ namespace DiskManager { FS LinuxSwap::getFilesystemSupport() { - qDebug() << "Checking Linux swap filesystem support"; + qCDebug(serviceLog) << "Checking Linux swap filesystem support"; FS fs(FS_LINUX_SWAP); fs.busy = FS::GPARTED; @@ -35,7 +36,7 @@ FS LinuxSwap::getFilesystemSupport() fs.online_read = FS::EXTERNAL; if (!Utils::findProgramInPath("mkswap").isEmpty()) { - qDebug() << "mkswap found, enabling create, grow, shrink, copy, move support."; + qCDebug(serviceLog) << "mkswap found, enabling create, grow, shrink, copy, move support."; fs.create = FS::EXTERNAL; fs.create_with_label = FS::EXTERNAL; fs.grow = FS::EXTERNAL; @@ -45,7 +46,7 @@ FS LinuxSwap::getFilesystemSupport() } if (!Utils::findProgramInPath("swaplabel").isEmpty()) { - qDebug() << "swaplabel found, enabling label and uuid support."; + qCDebug(serviceLog) << "swaplabel found, enabling label and uuid support."; fs.read_label = FS::EXTERNAL; fs.write_label = FS::EXTERNAL; fs.read_uuid = FS::EXTERNAL; @@ -57,19 +58,19 @@ FS LinuxSwap::getFilesystemSupport() void LinuxSwap::setUsedSectors(Partition &partition) { - qDebug() << "Setting used sectors for swap partition:" << partition.getPath(); + qCDebug(serviceLog) << "Setting used sectors for swap partition:" << partition.getPath(); if (partition.m_busy) { - qDebug() << "Partition is busy, checking /proc/swaps."; + qCDebug(serviceLog) << "Partition is busy, checking /proc/swaps."; m_numOfFreeOrUsedBlocks = -1; QFile file("/proc/swaps"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << "/proc/swaps opened successfully."; + qCDebug(serviceLog) << "/proc/swaps opened successfully."; QString line = file.readLine(); BlockSpecial bsPath = BlockSpecial(partition.getPath()); while (!file.atEnd() || !line.isEmpty()) { QString filename = Utils::regexpLabel(line, ".*?(?= )"); if (bsPath == BlockSpecial(filename)) { - qDebug() << "Found swap entry for partition" << partition.getPath(); + qCDebug(serviceLog) << "Found swap entry for partition" << partition.getPath(); sscanf(line.toLatin1(), "%*s %*s %*d %lld", &m_numOfFreeOrUsedBlocks); break; } @@ -77,10 +78,10 @@ void LinuxSwap::setUsedSectors(Partition &partition) } file.close(); } else { - qDebug() << "Failed to open /proc/swaps."; + qCDebug(serviceLog) << "Failed to open /proc/swaps."; } if (m_numOfFreeOrUsedBlocks > -1) { - qDebug() << "Calculating and setting sector usage."; + qCDebug(serviceLog) << "Calculating and setting sector usage."; // Ignore swap space reported size to ignore 1 page format // overhead. Instead use partition size as sectors_fs_size so // reported used figure for active swap space starts from 0 @@ -90,7 +91,7 @@ void LinuxSwap::setUsedSectors(Partition &partition) partition.setSectorUsage(m_totalNumOfBlock, m_totalNumOfBlock - m_numOfFreeOrUsedBlocks); } } else { - qDebug() << "Partition is not busy, setting as 100% free."; + qCDebug(serviceLog) << "Partition is not busy, setting as 100% free."; //By definition inactive swap space is 100% free Sector size = partition.getSectorLength(); partition.setSectorUsage(size, size); @@ -99,18 +100,18 @@ void LinuxSwap::setUsedSectors(Partition &partition) void LinuxSwap::readLabel(Partition &partition) { - qDebug() << "Reading label for swap partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading label for swap partition:" << partition.getPath(); QString output, error, label; Utils::executCmd(QString("swaplabel %1").arg(partition.getPath()), output, error); label = Utils::regexpLabel(output, "(?<=LABEL:).*(?=\n)"); partition.setFilesystemLabel(label); -// qDebug() << output << error << "----" << label; +// qCDebug(serviceLog) << output << error << "----" << label; } bool LinuxSwap::writeLabel(const Partition &partition) { - qDebug() << "Writing label for swap partition:" << partition.getPath() + qCDebug(serviceLog) << "Writing label for swap partition:" << partition.getPath() << "new label:" << partition.getFileSystemLabel(); QString output, error; int exitcode = Utils::executCmd(QString("swaplabel -L %1 %2").arg(partition.getFileSystemLabel()).arg(partition.getPath()), @@ -120,7 +121,7 @@ bool LinuxSwap::writeLabel(const Partition &partition) void LinuxSwap::readUuid(Partition &partition) { - qDebug() << "Reading UUID for swap partition:" << partition.getPath(); + qCDebug(serviceLog) << "Reading UUID for swap partition:" << partition.getPath(); QString output, error; Utils::executCmd(QString("swaplabel %1").arg(partition.getPath()), output, error); partition.m_uuid = Utils::regexpLabel(output, "(?<=UUID:).*(?=\n)"); @@ -128,7 +129,7 @@ void LinuxSwap::readUuid(Partition &partition) bool LinuxSwap::writeUuid(const Partition &partition) { - qDebug() << "Writing new UUID for swap partition:" << partition.getPath(); + qCDebug(serviceLog) << "Writing new UUID for swap partition:" << partition.getPath(); QString output, error; int exitcode = Utils::executCmd(QString("swaplabel -L %1 %2").arg(Utils::createUuid()).arg(partition.getPath()), output, error); @@ -137,7 +138,7 @@ bool LinuxSwap::writeUuid(const Partition &partition) bool LinuxSwap::create(const Partition &new_partition) { - qDebug() << "Creating swap partition on:" << new_partition.getPath() + qCDebug(serviceLog) << "Creating swap partition on:" << new_partition.getPath() << "with label:" << new_partition.getFileSystemLabel(); QString output, error; int exitcode = Utils::executCmd(QString("mkswap -L %1 %2").arg(new_partition.getFileSystemLabel()).arg(new_partition.getPath()), @@ -147,12 +148,12 @@ bool LinuxSwap::create(const Partition &new_partition) bool LinuxSwap::resize(const Partition &partitionNew, bool fillPartition) { - qDebug() << "Resizing swap partition:" << partitionNew.getPath() + qCDebug(serviceLog) << "Resizing swap partition:" << partitionNew.getPath() << "fill partition:" << fillPartition; QString output, error; QString command = QString("mkswap -L %1 ").arg(partitionNew.getFileSystemLabel()); if (!partitionNew.m_uuid.isEmpty()) { - qDebug() << "Adding UUID to resize command:" << partitionNew.m_uuid; + qCDebug(serviceLog) << "Adding UUID to resize command:" << partitionNew.m_uuid; command.append(QString(" -U %1 ").arg(partitionNew.m_uuid)); } command.append(partitionNew.getPath());