diff --git a/service/diskoperation/filesystems/ntfs.cpp b/service/diskoperation/filesystems/ntfs.cpp index d49bea6a..84dda625 100644 --- a/service/diskoperation/filesystems/ntfs.cpp +++ b/service/diskoperation/filesystems/ntfs.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 "ntfs.h" #include "filesystem.h" #include "utils.h" @@ -12,37 +13,37 @@ namespace DiskManager { FS NTFS::getFilesystemSupport() { - qDebug() << "[NTFS]::getFilesystemSupport - Enter"; + qCDebug(serviceLog) << "[NTFS]::getFilesystemSupport - Enter"; FS fs(FS_NTFS); fs.busy = FS::GPARTED; if (!Utils::findProgramInPath("ntfsinfo").isEmpty()) { - qDebug() << "ntfsinfo found, enabling read support."; + qCDebug(serviceLog) << "ntfsinfo found, enabling read support."; fs.read = FS::EXTERNAL; } if (!Utils::findProgramInPath("ntfslabel").isEmpty()) { - qDebug() << "ntfslabel found, enabling label and uuid support."; + qCDebug(serviceLog) << "ntfslabel found, enabling label and uuid support."; fs .read_label = FS::EXTERNAL ; fs .write_label = FS::EXTERNAL ; fs.write_uuid = FS::EXTERNAL; } if (!Utils::findProgramInPath("mkntfs").isEmpty()) { - qDebug() << "mkntfs found, enabling create support."; + qCDebug(serviceLog) << "mkntfs found, enabling create support."; fs.create = FS::EXTERNAL; fs.create_with_label = FS::EXTERNAL; } //resizing is a delicate process ... if (!Utils::findProgramInPath("ntfsresize").isEmpty()) { - qDebug() << "ntfsresize found, enabling check, grow, shrink, move support."; + qCDebug(serviceLog) << "ntfsresize found, enabling check, grow, shrink, move support."; fs.check = FS::EXTERNAL; fs.grow = FS::EXTERNAL; if (fs.read) {//needed to determine a min file system size.. - qDebug() << "Read support is available, enabling shrink."; + qCDebug(serviceLog) << "Read support is available, enabling shrink."; fs.shrink = FS::EXTERNAL; } @@ -50,7 +51,7 @@ FS NTFS::getFilesystemSupport() } if (!Utils::findProgramInPath("ntfsclone").isEmpty()) { - qDebug() << "ntfsclone found, enabling copy support."; + qCDebug(serviceLog) << "ntfsclone found, enabling copy support."; fs.copy = FS::EXTERNAL; } @@ -61,46 +62,46 @@ FS NTFS::getFilesystemSupport() // For GParted this means 2 MiB because smallest GUI unit is MiB. m_fsLimits.min_size = 2 * MEBIBYTE; - qDebug() << "[NTFS]::getFilesystemSupport - Exit"; + qCDebug(serviceLog) << "[NTFS]::getFilesystemSupport - Exit"; return fs; } void NTFS::setUsedSectors( Partition & partition ) { - qDebug() << "[NTFS]::setUsedSectors - Enter"; + qCDebug(serviceLog) << "[NTFS]::setUsedSectors - Enter"; QString output, error, strmatch; m_blocksSize = m_numOfFreeOrUsedBlocks = m_totalNumOfBlock = -1; QString cmd = QString("ntfsinfo --mft --force %1").arg(partition.getPath()); if (!Utils::executCmd(cmd, output, error)) { - qDebug() << "ntfsinfo executed successfully."; + qCDebug(serviceLog) << "ntfsinfo executed successfully."; strmatch = "Cluster Size:"; int index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { m_blocksSize = Utils::regexpLabel(output, QString("(?<=Cluster Size:).*(?=\n)")).trimmed().toLong(); - qDebug() << "Found Cluster Size:" << m_blocksSize; + qCDebug(serviceLog) << "Found Cluster Size:" << m_blocksSize; } strmatch = "Volume Size in Clusters:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { m_totalNumOfBlock = Utils::regexpLabel(output, QString("(?<=Volume Size in Clusters:).*(?=\n)")).trimmed().toLong(); - qDebug() << "Found Volume Size in Clusters:" << m_totalNumOfBlock; + qCDebug(serviceLog) << "Found Volume Size in Clusters:" << m_totalNumOfBlock; } strmatch = "Free Clusters:"; index = output.indexOf(strmatch); if (index >= 0 && index < output.length()) { m_numOfFreeOrUsedBlocks = Utils::regexpLabel(output, QString("(?<=Free Clusters:).*(?=[(])")).trimmed().toLong(); - qDebug() << "Found Free Clusters:" << m_numOfFreeOrUsedBlocks; + qCDebug(serviceLog) << "Found Free Clusters:" << m_numOfFreeOrUsedBlocks; } } else { - qDebug() << "ntfsinfo execution failed. Error:" << error; + qCDebug(serviceLog) << "ntfsinfo execution failed. Error:" << error; } if (m_blocksSize > -1 && m_totalNumOfBlock > -1 && m_numOfFreeOrUsedBlocks > -1) { - qDebug() << "Calculating and setting sector usage."; + qCDebug(serviceLog) << "Calculating and setting sector usage."; m_totalNumOfBlock = m_totalNumOfBlock * (m_blocksSize / partition.m_sectorSize); m_numOfFreeOrUsedBlocks = m_numOfFreeOrUsedBlocks * (m_blocksSize / partition.m_sectorSize); @@ -108,61 +109,61 @@ void NTFS::setUsedSectors( Partition & partition ) partition.m_fsBlockSize = m_blocksSize; } - qDebug() << "[NTFS]::setUsedSectors - Exit"; + qCDebug(serviceLog) << "[NTFS]::setUsedSectors - Exit"; } void NTFS::readLabel( Partition & partition ) { - qDebug() << "[NTFS]::readLabel - Enter"; + qCDebug(serviceLog) << "[NTFS]::readLabel - Enter"; QString output, error; if (!Utils::executCmd(QString("ntfslabel --force %1").arg(partition.getPath()), output, error)) { - qDebug() << "Successfully read label:" << output.trimmed(); + qCDebug(serviceLog) << "Successfully read label:" << output.trimmed(); partition.setFilesystemLabel(output.trimmed()); } else { - qDebug() << "Failed to read label. Error:" << error; + qCDebug(serviceLog) << "Failed to read label. Error:" << error; } - qDebug() << "[NTFS]::readLabel - Exit"; + qCDebug(serviceLog) << "[NTFS]::readLabel - Exit"; } bool NTFS::writeLabel( const Partition & partition) { - qDebug() << "[NTFS]::writeLabel - Enter"; + qCDebug(serviceLog) << "[NTFS]::writeLabel - Enter"; QString output, error; int exitcode = Utils::executCmd(QString("ntfslabel --force %1 %2").arg(partition.getPath()).arg(partition.getFileSystemLabel()), output, error); bool success = (exitcode == 0); - qDebug() << "[NTFS]::writeLabel - Exit with status:" << success; + qCDebug(serviceLog) << "[NTFS]::writeLabel - Exit with status:" << success; return success; } void NTFS::readUuid(Partition & partition) { - qDebug() << "[NTFS]::readUuid - Enter/Exit"; + qCDebug(serviceLog) << "[NTFS]::readUuid - Enter/Exit"; } bool NTFS::writeUuid( const Partition & partition) { - qDebug() << "[NTFS]::writeUuid - Enter"; + qCDebug(serviceLog) << "[NTFS]::writeUuid - Enter"; QString output, error; int exitcode = Utils::executCmd(QString("ntfslabel --new-serial %1").arg(partition.getPath()), output, error); bool success = (exitcode == 0 || error.compare("Unknown error") == 0); - qDebug() << "[NTFS]::writeUuid - Exit with status:" << success; + qCDebug(serviceLog) << "[NTFS]::writeUuid - Exit with status:" << success; return success; } bool NTFS::create(const Partition & newPartition) { - qDebug() << "[NTFS]::create - Enter"; + qCDebug(serviceLog) << "[NTFS]::create - Enter"; QString output, error; int exitcode = -1; if (newPartition.getFileSystemLabel().isEmpty() || newPartition.getFileSystemLabel() == " ") { - qDebug() << "Creating NTFS without label on" << newPartition.getPath(); + qCDebug(serviceLog) << "Creating NTFS without label on" << newPartition.getPath(); exitcode = Utils::executCmd(QString("mkntfs -Q -v -F %1").arg(newPartition.getPath()), output, error); } else { - qDebug() << "Creating NTFS with label" << newPartition.getFileSystemLabel() << "on" << newPartition.getPath(); + qCDebug(serviceLog) << "Creating NTFS with label" << newPartition.getFileSystemLabel() << "on" << newPartition.getPath(); exitcode = Utils::executCmd(QString("mkntfs -Q -v -F %1 -L %2").arg(newPartition.getPath()).arg(newPartition.getFileSystemLabel()),output, error); } bool success = (exitcode == 0 && error.compare("Unknown error") == 0); - qDebug() << "[NTFS]::create - Exit with status:" << success; + qCDebug(serviceLog) << "[NTFS]::create - Exit with status:" << success; return success; } @@ -179,22 +180,22 @@ NTFSRESIZE使用K=10^3、M=10^6和G=10^9,符合Si、ATA、IEEE标准和磁盘 bool NTFS::resize(const Partition &partitionNew, bool fillPartition) { - // qDebug() << "[NTFS]::resize(Partition) - Enter, partition:" << partitionNew.getPath() << "fill:" << fillPartition; + // qCDebug(serviceLog) << "[NTFS]::resize(Partition) - Enter, partition:" << partitionNew.getPath() << "fill:" << fillPartition; double d = Utils::sectorToUnit(partitionNew.getSectorLength(), partitionNew.m_sectorSize, UNIT_BYTE); bool result = resize(partitionNew.getPath(), QString::number(((long long)d / 1000)), fillPartition); - // qDebug() << "[NTFS]::resize(Partition) - Exit with status:" << result; + // qCDebug(serviceLog) << "[NTFS]::resize(Partition) - Exit with status:" << result; return result; } bool NTFS::resize(const QString &path, const QString &sizeByte, bool fillPartition) { - // qDebug() << "[NTFS]::resize(path) - Enter, path:" << path << "size(k):" << sizeByte << "fill:" << fillPartition; + // qCDebug(serviceLog) << "[NTFS]::resize(path) - Enter, path:" << path << "size(k):" << sizeByte << "fill:" << fillPartition; // bool success; QString output, error; QString size, cmd; if (!fillPartition) { size = QString(" -s %1k").arg(sizeByte); - // qDebug() << "Shrinking filesystem, size arg:" << size; + // qCDebug(serviceLog) << "Shrinking filesystem, size arg:" << size; } //Utils::executCmd(QString("umount %1").arg(path)); @@ -202,10 +203,10 @@ bool NTFS::resize(const QString &path, const QString &sizeByte, bool fillPartiti cmd = "ntfsresize --force --force" + size ; // Real resize cmd = QString("%1 %2").arg(cmd).arg(path); - // qDebug() << "Executing ntfsresize command:" << cmd; + // qCDebug(serviceLog) << "Executing ntfsresize command:" << cmd; // success = !Utils::executCmd(cmd, output, error); bool success = !Utils::executCmd(cmd, output, error); - // qDebug() << "[NTFS]::resize(path) - Exit with status:" << success << "output:" << output << "error:" << error; + // qCDebug(serviceLog) << "[NTFS]::resize(path) - Exit with status:" << success << "output:" << output << "error:" << error; return success; } @@ -220,59 +221,59 @@ bool NTFS::resize(const QString &path, const QString &sizeByte, bool fillPartiti bool NTFS::checkRepair(const Partition &partition) { - qDebug() << "[NTFS]::checkRepair - Enter"; + qCDebug(serviceLog) << "[NTFS]::checkRepair - Enter"; bool result = checkRepair(partition.getPath()); - qDebug() << "[NTFS]::checkRepair - return " << result; + qCDebug(serviceLog) << "[NTFS]::checkRepair - return " << result; return result; } bool NTFS::checkRepair(const QString &devpath) { - qDebug() << "[NTFS]::checkRepair(path) - Enter"; + qCDebug(serviceLog) << "[NTFS]::checkRepair(path) - Enter"; QString output, error; int exitcode = Utils::executCmd(QString("ntfsresize -i -f -v %1").arg(devpath), output, error); bool success = (exitcode == 0 || error.compare("Unknown error") == 0); - qDebug() << "[NTFS]::checkRepair(path) - Exit with status:" << success; + qCDebug(serviceLog) << "[NTFS]::checkRepair(path) - Exit with status:" << success; return success; } FS_Limits NTFS::getFilesystemLimits(const Partition &partition) { - // qDebug() << "[NTFS]::getFilesystemLimits(Partition) - Enter, for partition:" << partition.getPath(); + // qCDebug(serviceLog) << "[NTFS]::getFilesystemLimits(Partition) - Enter, for partition:" << partition.getPath(); FS_Limits limits = getFilesystemLimits(partition.getPath()); - // qDebug() << "[NTFS]::getFilesystemLimits(Partition) - Exit"; + // qCDebug(serviceLog) << "[NTFS]::getFilesystemLimits(Partition) - Exit"; return limits; } FS_Limits NTFS::getFilesystemLimits(const QString &path) { - qDebug() << "[NTFS]::getFilesystemLimits(path) - Enter, for path:" << path; + qCDebug(serviceLog) << "[NTFS]::getFilesystemLimits(path) - Enter, for path:" << path; m_fsLimits = FS_Limits {-1, -1}; QString cmd, output, error; //Utils::executCmd(QString("umount %1").arg(path), output, error); cmd = QString("ntfsresize -m -f %1").arg(path); - qDebug() << "Executing ntfsresize command:" << cmd; + qCDebug(serviceLog) << "Executing ntfsresize command:" << cmd; if (Utils::executCmd(cmd, output, error) != 0 && error.compare("Unknown error") != 0) { - qDebug() << "ntfsresize execution failed. Error:" << error; + qCDebug(serviceLog) << "ntfsresize execution failed. Error:" << error; return m_fsLimits; } foreach (QString str, output.split("\n")) { - // qDebug()<<"getFilesystemLimits ntfs"< 5 @@ -81,99 +82,99 @@ void XFS::setUsedSectors(Partition &partition) } if (value[0].startsWith("blocksize")) { m_blocksSize = value[1].trimmed().toULongLong(); - qDebug() << "Found blocksize:" << m_blocksSize; + qCDebug(serviceLog) << "Found blocksize:" << m_blocksSize; } else if (value[0].startsWith("dblocks")) { m_totalNumOfBlock = value[1].trimmed().toULongLong(); - qDebug() << "Found dblocks:" << m_totalNumOfBlock; + qCDebug(serviceLog) << "Found dblocks:" << m_totalNumOfBlock; } else if (value[0].startsWith("fdblocks")) { m_numOfFreeOrUsedBlocks = value[1].trimmed().toULongLong(); - qDebug() << "Found fdblocks:" << m_numOfFreeOrUsedBlocks; + qCDebug(serviceLog) << "Found fdblocks:" << m_numOfFreeOrUsedBlocks; } else { continue; } } if (m_totalNumOfBlock > -1 && m_numOfFreeOrUsedBlocks > -1 && m_blocksSize > -1) { - qDebug() << "Calculating and setting sector usage."; + qCDebug(serviceLog) << "Calculating and setting sector usage."; m_totalNumOfBlock = qRound64(m_totalNumOfBlock * (m_blocksSize / double(partition.m_sectorSize))); m_numOfFreeOrUsedBlocks = qRound64(m_numOfFreeOrUsedBlocks * (m_blocksSize / double(partition.m_sectorSize))); partition.setSectorUsage(m_totalNumOfBlock, m_numOfFreeOrUsedBlocks); partition.m_fsBlockSize = m_blocksSize; } } else { - qDebug() << "xfs_db command failed. Output:" << output << "Error:" << error; + qCDebug(serviceLog) << "xfs_db command failed. Output:" << output << "Error:" << error; } - qDebug() << "[XFS]::setUsedSectors - Exit"; + qCDebug(serviceLog) << "[XFS]::setUsedSectors - Exit"; } void XFS::readLabel(Partition &partition) { - qDebug() << "[XFS]::readLabel - Enter"; + qCDebug(serviceLog) << "[XFS]::readLabel - Enter"; QString output, error; if (!Utils::executCmd(QString("xfs_db -r -c label %1").arg(partition.getPath()), output, error)) { auto items = output.split("="); if (items.size() == 2) { QString label = items[1].replace("\"", "").trimmed(); - qDebug() << "Successfully read label:" << label; + qCDebug(serviceLog) << "Successfully read label:" << label; partition.setFilesystemLabel(label); } } else { - qDebug() << "Failed to read label. Error:" << error; + qCDebug(serviceLog) << "Failed to read label. Error:" << error; } - qDebug() << "[XFS]::readLabel - Exit"; + qCDebug(serviceLog) << "[XFS]::readLabel - Exit"; } bool XFS::writeLabel(const Partition &partition) { - qDebug() << "[XFS]::writeLabel - Enter"; + qCDebug(serviceLog) << "[XFS]::writeLabel - Enter"; QString cmd = ""; if (partition.getFileSystemLabel().isEmpty()) { - qDebug() << "Label is empty, clearing label on" << partition.getPath(); + qCDebug(serviceLog) << "Label is empty, clearing label on" << partition.getPath(); cmd = QString("xfs_admin -L -- %1").arg(partition.getPath()); } else { - qDebug() << "Setting label" << partition.getFileSystemLabel() << "on" << partition.getPath(); + qCDebug(serviceLog) << "Setting label" << partition.getFileSystemLabel() << "on" << partition.getPath(); cmd = QString("xfs_admin -L %1 %2").arg(partition.getFileSystemLabel()).arg(partition.getPath()); } QString output, error; int exitcode = Utils::executCmd(cmd, output, error); bool success = (exitcode == 0); - qDebug() << "[XFS]::writeLabel - Exit with status:" << success; + qCDebug(serviceLog) << "[XFS]::writeLabel - Exit with status:" << success; return success; } void XFS::readUuid(Partition &partition) { - qDebug() << "[XFS]::readUuid - Enter"; + qCDebug(serviceLog) << "[XFS]::readUuid - Enter"; QString output, error; if (!Utils::executCmd(QString("xfs_admin -u %1").arg(partition.getPath()), output, error)) { QString uuid = Utils::regexpLabel(output, "^UUID[[:blank:]]*=[[:blank:]]*(" RFC4122_NONE_NIL_UUID_REGEXP ")"); - qDebug() << "Successfully read UUID:" << uuid; + qCDebug(serviceLog) << "Successfully read UUID:" << uuid; partition.m_uuid = uuid; } else { - qDebug() << "Failed to read UUID. Error:" << error; + qCDebug(serviceLog) << "Failed to read UUID. Error:" << error; } - qDebug() << "[XFS]::readUuid - Exit"; + qCDebug(serviceLog) << "[XFS]::readUuid - Exit"; } bool XFS::writeUuid(const Partition &partition) { - qDebug() << "[XFS]::writeUuid - Enter"; + qCDebug(serviceLog) << "[XFS]::writeUuid - Enter"; QString output, error; int exitcode = Utils::executCmd(QString("xfs_admin -U generate %1").arg(partition.getPath()), output, error); bool success = (exitcode == 0 || error.compare("Unknown error") == 0); - qDebug() << "[XFS]::writeUuid - Exit with status:" << success; + qCDebug(serviceLog) << "[XFS]::writeUuid - Exit with status:" << success; return success; } bool XFS::create(const Partition &newPartition) { - qDebug() << "[XFS]::create - Enter"; + qCDebug(serviceLog) << "[XFS]::create - Enter"; QString output, error; int exitcode = -1; if (newPartition.getFileSystemLabel().isEmpty() || newPartition.getFileSystemLabel().trimmed().isEmpty()) { - qDebug() << "Creating XFS without label on" << newPartition.getPath(); + qCDebug(serviceLog) << "Creating XFS without label on" << newPartition.getPath(); exitcode = Utils::executCmd(QString("mkfs.xfs -f %1").arg(newPartition.getPath()), output, error); } else { - qDebug() << "Creating XFS with label" << newPartition.getFileSystemLabel() << "on" << newPartition.getPath(); + qCDebug(serviceLog) << "Creating XFS with label" << newPartition.getFileSystemLabel() << "on" << newPartition.getPath(); exitcode = Utils::executCmd(QString("mkfs.xfs -f -L %1 %2").arg(newPartition.getFileSystemLabel()).arg(newPartition.getPath()), output, error); } bool success = (exitcode == 0 && error.compare("Unknown error") == 0); - qDebug() << "[XFS]::create - Exit with status:" << success; + qCDebug(serviceLog) << "[XFS]::create - Exit with status:" << success; return success; } /* @@ -188,73 +189,73 @@ XFSRESIZE使用K=10^3、M=10^6和G=10^9,符合Si、ATA、IEEE标准和磁盘 */ bool XFS::resize(const Partition &partitionNew, bool fillPartition) { - // qDebug() << "[XFS]::resize - Enter, partition:" << partitionNew.getPath() << "fill:" << fillPartition; + // qCDebug(serviceLog) << "[XFS]::resize - Enter, partition:" << partitionNew.getPath() << "fill:" << fillPartition; Q_UNUSED(fillPartition); bool success = true ; QString mountPoint; QString output, error; if (!partitionNew.m_busy) { - // qDebug() << "Partition not busy, creating a temporary mount point."; + // qCDebug(serviceLog) << "Partition not busy, creating a temporary mount point."; mountPoint = Utils::mkTempDir(""); if (mountPoint.isEmpty()) { - qDebug() << "Failed to create temp dir."; + qCDebug(serviceLog) << "Failed to create temp dir."; return false; } - // qDebug() << "Mounting" << partitionNew.getPath() << "to" << mountPoint; + // qCDebug(serviceLog) << "Mounting" << partitionNew.getPath() << "to" << mountPoint; success &= Utils::executCmd(QString("mount -v -t xfs %1 %2") .arg(partitionNew.getPath()) .arg(mountPoint),output, error) == 0; } else { mountPoint = partitionNew.getMountPoint(); - // qDebug() << "Partition is busy, using existing mount point:" << mountPoint; + // qCDebug(serviceLog) << "Partition is busy, using existing mount point:" << mountPoint; } if (success) { - // qDebug() << "Growing filesystem on" << mountPoint; + // qCDebug(serviceLog) << "Growing filesystem on" << mountPoint; success &= Utils::executCmd(QString("xfs_growfs %1").arg(mountPoint), output, error) == 0; if (partitionNew.m_busy) { - // qDebug() << "Partition was busy, unmounting" << mountPoint; + // qCDebug(serviceLog) << "Partition was busy, unmounting" << mountPoint; success &= Utils::executCmd(QString("umount -v %1").arg(mountPoint), output, error) == 0; } } if (!partitionNew.m_busy) { - // qDebug() << "Partition was not busy, removing temp dir" << mountPoint; + // qCDebug(serviceLog) << "Partition was not busy, removing temp dir" << mountPoint; Utils::rmTempDir(mountPoint) ; } - // qDebug() << "[XFS]::resize - Exit with status:" << success; + // qCDebug(serviceLog) << "[XFS]::resize - Exit with status:" << success; return success ; } bool XFS::checkRepair(const Partition &partition) { - qDebug() << "[XFS]::checkRepair(Partition) - Enter, for partition:" << partition.getPath(); + qCDebug(serviceLog) << "[XFS]::checkRepair(Partition) - Enter, for partition:" << partition.getPath(); bool result = checkRepair(partition.getPath()); - qDebug() << "[XFS]::checkRepair(Partition) - Exit with status:" << result; + qCDebug(serviceLog) << "[XFS]::checkRepair(Partition) - Exit with status:" << result; return result; } bool XFS::checkRepair(const QString &devpath) { - qDebug() << "[XFS]::checkRepair(path) - Enter"; + qCDebug(serviceLog) << "[XFS]::checkRepair(path) - Enter"; QString output, error; int exitcode = Utils::executCmd(QString("xfs_repair -v %1").arg(devpath), output, error); bool success = (exitcode == 0 || error.compare("Unknown error") == 0); - qDebug() << "[XFS]::checkRepair(path) - Exit with status:" << success; + qCDebug(serviceLog) << "[XFS]::checkRepair(path) - Exit with status:" << success; return success; } FS_Limits XFS::getFilesystemLimits(const Partition &partition) { - qDebug() << "[XFS]::getFilesystemLimits - Enter, for partition:" << partition.getPath(); + qCDebug(serviceLog) << "[XFS]::getFilesystemLimits - Enter, for partition:" << partition.getPath(); // Official minsize = 16MB, but the smallest xfs_repair can handle is 32MB. //m_fsLimits.min_size = 32 * MEBIBYTE; m_fsLimits.min_size = -1; m_fsLimits.max_size = -1; - qDebug() << "[XFS]::getFilesystemLimits - Exit"; + qCDebug(serviceLog) << "[XFS]::getFilesystemLimits - Exit"; return m_fsLimits; } } // namespace DiskManager diff --git a/service/diskoperation/fsinfo.cpp b/service/diskoperation/fsinfo.cpp index 94e2ca47..84743cbd 100644 --- a/service/diskoperation/fsinfo.cpp +++ b/service/diskoperation/fsinfo.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 "fsinfo.h" #include "utils.h" #include "procpartitionsinfo.h" @@ -18,7 +19,7 @@ QVector FsInfo::m_fileSystemInfoCache; void FsInfo::loadCache() { - qDebug() << "FsInfo::loadCache called."; + qCDebug(serviceLog) << "FsInfo::loadCache called."; setCommandsFound(); loadFileSystemInfoCache(); m_fsInfoCacheInitialized = true; @@ -26,7 +27,7 @@ void FsInfo::loadCache() QString FsInfo::getFileSystemType(const QString &path) { - qDebug() << "FsInfo::getFileSystemType called for path:" << path; + qCDebug(serviceLog) << "FsInfo::getFileSystemType called for path:" << path; initializeIfRequired(); const fileSystemEntry &fsEntry = getCacheEntryByPath(path); QString fsType = fsEntry.m_type; @@ -34,9 +35,9 @@ QString FsInfo::getFileSystemType(const QString &path) // If vfat, decide whether fat16 or fat32 if (fsType == "vfat") { - qDebug() << "fsType is vfat, determining if fat16 or fat32."; + qCDebug(serviceLog) << "fsType is vfat, determining if fat16 or fat32."; if (m_needBlkidVfatCacheUpdateWorkaround) { - qDebug() << "Using blkid vfat cache update workaround."; + qCDebug(serviceLog) << "Using blkid vfat cache update workaround."; // Blkid cache does not correctly add and remove SEC_TYPE when // overwriting FAT16 and FAT32 file systems with each other, so // prevents correct identification. Run blkid command again, @@ -45,98 +46,98 @@ QString FsInfo::getFileSystemType(const QString &path) QString error; if (!Utils::executCmd("blkid -c /dev/null " + path, output, error)) { fsSecType = Utils::regexpLabel(output, " SEC_TYPE=\"([^\"]*)\""); - qDebug() << "Bypassed cache, got fsSecType:" << fsSecType; + qCDebug(serviceLog) << "Bypassed cache, got fsSecType:" << fsSecType; } } if (fsSecType == "msdos") { - qDebug() << "fsSecType is msdos, setting fsType to fat16."; + qCDebug(serviceLog) << "fsSecType is msdos, setting fsType to fat16."; fsType = "fat16"; } else { - qDebug() << "fsSecType is not msdos, setting fsType to fat32."; + qCDebug(serviceLog) << "fsSecType is not msdos, setting fsType to fat32."; fsType = "fat32"; } } - qDebug() << "Returning fsType:" << fsType; + qCDebug(serviceLog) << "Returning fsType:" << fsType; return fsType; } QString FsInfo::getPathByUuid(const QString &uuid) { - qDebug() << "FsInfo::getPathByUuid called with uuid:" << uuid; + qCDebug(serviceLog) << "FsInfo::getPathByUuid called with uuid:" << uuid; initializeIfRequired(); for (int i = 0; i < m_fileSystemInfoCache.size(); i++) { if (uuid == m_fileSystemInfoCache[i].m_uuid) { - qDebug() << "Found path:" << m_fileSystemInfoCache[i].m_path.m_name << "for uuid:" << uuid; + qCDebug(serviceLog) << "Found path:" << m_fileSystemInfoCache[i].m_path.m_name << "for uuid:" << uuid; return m_fileSystemInfoCache[i].m_path.m_name; } } - qDebug() << "No path found for uuid:" << uuid; + qCDebug(serviceLog) << "No path found for uuid:" << uuid; return ""; } QString FsInfo::getPathByLabel(const QString &label) { - qDebug() << "FsInfo::getPathByLabel called with label:" << label; + qCDebug(serviceLog) << "FsInfo::getPathByLabel called with label:" << label; initializeIfRequired(); updateFileSystemInfoCacheAllLabels(); for (int i = 0; i < m_fileSystemInfoCache.size(); i++) { if (label == m_fileSystemInfoCache[i].m_label) { - qDebug() << "Found path:" << m_fileSystemInfoCache[i].m_path.m_name << "for label:" << label; + qCDebug(serviceLog) << "Found path:" << m_fileSystemInfoCache[i].m_path.m_name << "for label:" << label; return m_fileSystemInfoCache[i].m_path.m_name; } } - qDebug() << "No path found for label:" << label; + qCDebug(serviceLog) << "No path found for label:" << label; return ""; } QString FsInfo::getLabel(const QString &path, bool &found) { - qDebug() << "FsInfo::getLabel called for path:" << path; + qCDebug(serviceLog) << "FsInfo::getLabel called for path:" << path; initializeIfRequired(); BlockSpecial bs = BlockSpecial(path); for (int i = 0; i < m_fileSystemInfoCache.size(); i++) { if (bs == m_fileSystemInfoCache[i].m_path) { - qDebug() << "Found cache entry for path:" << path; + qCDebug(serviceLog) << "Found cache entry for path:" << path; if (m_fileSystemInfoCache[i].m_haveLabel || m_fileSystemInfoCache[i].m_type == "") { // Already have the label or this is a blank cache entry // for a whole disk device containing a partition table, // so no label (as created by // load_fs_info_cache_extra_for_path()). found = m_fileSystemInfoCache[i].m_haveLabel; - qDebug() << "Label already in cache or blank entry. Found:" << found << "Label:" << m_fileSystemInfoCache[i].m_label; + qCDebug(serviceLog) << "Label already in cache or blank entry. Found:" << found << "Label:" << m_fileSystemInfoCache[i].m_label; return m_fileSystemInfoCache[i].m_label; } // Run blkid to get the label for this one partition, update the // cache and return the found label. - qDebug() << "Label not in cache, running blkid to get it."; + qCDebug(serviceLog) << "Label not in cache, running blkid to get it."; found = runBlkidUpdateCacheOneLabel(m_fileSystemInfoCache[i]); - qDebug() << "Found:" << found << "Label:" << m_fileSystemInfoCache[i].m_label; + qCDebug(serviceLog) << "Found:" << found << "Label:" << m_fileSystemInfoCache[i].m_label; return m_fileSystemInfoCache[i].m_label; } } - qDebug() << "No cache entry found for path:" << path; + qCDebug(serviceLog) << "No cache entry found for path:" << path; found = false; return ""; } QString FsInfo::getUuid(const QString &path) { - qDebug() << "FsInfo::getUuid called for path:" << path; + qCDebug(serviceLog) << "FsInfo::getUuid called for path:" << path; initializeIfRequired(); const fileSystemEntry &fsEntry = getCacheEntryByPath(path); - qDebug() << "Returning uuid:" << fsEntry.m_uuid; + qCDebug(serviceLog) << "Returning uuid:" << fsEntry.m_uuid; return fsEntry.m_uuid; } void FsInfo::initializeIfRequired() { if (!m_fsInfoCacheInitialized) { - qDebug() << "Cache not initialized, initializing now."; + qCDebug(serviceLog) << "Cache not initialized, initializing now."; setCommandsFound(); loadFileSystemInfoCache(); m_fsInfoCacheInitialized = true; @@ -145,9 +146,9 @@ void FsInfo::initializeIfRequired() void FsInfo::setCommandsFound() { - qDebug() << "FsInfo::setCommandsFound called."; + qCDebug(serviceLog) << "FsInfo::setCommandsFound called."; m_blkidFound = (!Utils::findProgramInPath("blkid").isEmpty()); - qDebug() << "blkid found:" << m_blkidFound; + qCDebug(serviceLog) << "blkid found:" << m_blkidFound; if (m_blkidFound) { // Blkid from util-linux before 2.23 has a cache update bug which prevents // correct identification between FAT16 and FAT32 when overwriting one @@ -160,14 +161,14 @@ void FsInfo::setCommandsFound() if (sscanf(blkidVersion.toStdString().c_str(), "%d.%d", &blkidMajorVer, &blkidMinorVer) == 2) { m_needBlkidVfatCacheUpdateWorkaround = (blkidMajorVer < 2 || (blkidMajorVer == 2 && blkidMinorVer < 23)); - qDebug() << "blkid version:" << blkidVersion << "Need workaround:" << m_needBlkidVfatCacheUpdateWorkaround; + qCDebug(serviceLog) << "blkid version:" << blkidVersion << "Need workaround:" << m_needBlkidVfatCacheUpdateWorkaround; } } } void FsInfo::loadFileSystemInfoCache() { - qDebug() << "FsInfo::loadFileSystemInfoCache called."; + qCDebug(serviceLog) << "FsInfo::loadFileSystemInfoCache called."; m_fileSystemInfoCache.clear(); // Run "blkid" and load entries into the cache. runBlkidLoadCache(); @@ -180,7 +181,7 @@ void FsInfo::loadFileSystemInfoCache() for (int i = 0; i < allDevices.size(); i++) { const fileSystemEntry &fsEntry = getCacheEntryByPath(allDevices[i]); if (fsEntry.m_path == emptyBs) { - qDebug() << "Cache entry missing for whole disk device:" << allDevices[i] << ", loading it."; + qCDebug(serviceLog) << "Cache entry missing for whole disk device:" << allDevices[i] << ", loading it."; // Run "blkid PATH" and load entry into cache for missing entries. loadFileSystemInfoCacheExtraForPath(allDevices[i]); } @@ -189,7 +190,7 @@ void FsInfo::loadFileSystemInfoCache() bool FsInfo::runBlkidLoadCache(const QString &path) { - qDebug() << "FsInfo::runBlkidLoadCache called for path:" << (path.isEmpty() ? "all" : path); + qCDebug(serviceLog) << "FsInfo::runBlkidLoadCache called for path:" << (path.isEmpty() ? "all" : path); QString cmd = "blkid"; if (path.size()) cmd = cmd + " " + path; //Glib::shell_quote(path); @@ -197,14 +198,14 @@ bool FsInfo::runBlkidLoadCache(const QString &path) QString error; bool loadedEntries = false; if (m_blkidFound && !Utils::executCmd(cmd, output, error)) { - qDebug() << "blkid command successful."; + qCDebug(serviceLog) << "blkid command successful."; QStringList strlist = output.split("\n"); for (int i = 0; i < strlist.size(); i++) { fileSystemEntry fsEntry = {BlockSpecial(), "", "", "", false, ""}; QString entryPath = Utils::regexpLabel(strlist[i], "(?<=/).*?(?=: )"); if (entryPath.length() > 0) { entryPath = "/" + entryPath; - // qDebug() << "Parsing blkid output for path:" << entryPath; + // qCDebug(serviceLog) << "Parsing blkid output for path:" << entryPath; fsEntry.m_path = BlockSpecial(entryPath); fsEntry.m_type = Utils::regexpLabel(strlist[i], "(?<= TYPE=\").*?(?=\")"); fsEntry.m_secType = Utils::regexpLabel(strlist[i], " SEC_TYPE=\"([^\"]*)\""); @@ -213,37 +214,37 @@ bool FsInfo::runBlkidLoadCache(const QString &path) m_fileSystemInfoCache.push_back(fsEntry); loadedEntries = true; -// qDebug() << fsEntry.m_path.m_name << fsEntry.m_type << fsEntry.m_secType << fsEntry.m_uuid << fsEntry.m_label; +// qCDebug(serviceLog) << fsEntry.m_path.m_name << fsEntry.m_type << fsEntry.m_secType << fsEntry.m_uuid << fsEntry.m_label; } } } else { - qDebug() << "blkid command failed or blkid not found."; + qCDebug(serviceLog) << "blkid command failed or blkid not found."; } return loadedEntries; } const fileSystemEntry &FsInfo::getCacheEntryByPath(const QString &path) { - qDebug() << "FsInfo::getCacheEntryByPath called for path:" << path; + qCDebug(serviceLog) << "FsInfo::getCacheEntryByPath called for path:" << path; BlockSpecial bs = BlockSpecial(path); for (int i = 0; i < m_fileSystemInfoCache.size(); i++) { if (bs == m_fileSystemInfoCache[i].m_path) { - qDebug() << "Found cache entry for path:" << path; + qCDebug(serviceLog) << "Found cache entry for path:" << path; return m_fileSystemInfoCache[i]; } } - qDebug() << "No cache entry found for path:" << path << ", returning static notFound."; + qCDebug(serviceLog) << "No cache entry found for path:" << path << ", returning static notFound."; static fileSystemEntry notFound = {BlockSpecial(), "", "", "", false, ""}; return notFound; } void FsInfo::loadFileSystemInfoCacheExtraForPath(const QString &path) { - qDebug() << "FsInfo::loadFileSystemInfoCacheExtraForPath called for path:" << path; + qCDebug(serviceLog) << "FsInfo::loadFileSystemInfoCacheExtraForPath called for path:" << path; bool entryAdded = runBlkidLoadCache(path); if (!entryAdded) { - qDebug() << "No entry added by runBlkidLoadCache, adding a blank entry for path:" << path; + qCDebug(serviceLog) << "No entry added by runBlkidLoadCache, adding a blank entry for path:" << path; // Ran "blkid PATH" but didn't find details suitable for loading as a // cache entry so add a blank entry for PATH name here. fileSystemEntry fsEntry = {BlockSpecial(path), "", "", "", false, ""}; @@ -253,16 +254,16 @@ void FsInfo::loadFileSystemInfoCacheExtraForPath(const QString &path) void FsInfo::updateFileSystemInfoCacheAllLabels() { - qDebug() << "FsInfo::updateFileSystemInfoCacheAllLabels called."; + qCDebug(serviceLog) << "FsInfo::updateFileSystemInfoCacheAllLabels called."; if (!m_blkidFound) { - qDebug() << "blkid not found, returning."; + qCDebug(serviceLog) << "blkid not found, returning."; return; } // For all cache entries which are file systems but don't yet have a label load it // now. for (int i = 0; i < m_fileSystemInfoCache.size(); i++) { if (m_fileSystemInfoCache[i].m_type != "" && !m_fileSystemInfoCache[i].m_haveLabel) { - qDebug() << "Updating label for cache entry:" << m_fileSystemInfoCache[i].m_path.m_name; + qCDebug(serviceLog) << "Updating label for cache entry:" << m_fileSystemInfoCache[i].m_path.m_name; runBlkidUpdateCacheOneLabel(m_fileSystemInfoCache[i]); } } @@ -270,9 +271,9 @@ void FsInfo::updateFileSystemInfoCacheAllLabels() bool FsInfo::runBlkidUpdateCacheOneLabel(fileSystemEntry &fsEntry) { - qDebug() << "FsInfo::runBlkidUpdateCacheOneLabel called for path:" << fsEntry.m_path.m_name; + qCDebug(serviceLog) << "FsInfo::runBlkidUpdateCacheOneLabel called for path:" << fsEntry.m_path.m_name; if (!m_blkidFound) { - qDebug() << "blkid not found, returning false."; + qCDebug(serviceLog) << "blkid not found, returning false."; return false; } @@ -282,13 +283,13 @@ bool FsInfo::runBlkidUpdateCacheOneLabel(fileSystemEntry &fsEntry) QString error; bool success = !Utils::executCmd("blkid -o value -s LABEL " + fsEntry.m_path.m_name, output, error); if (!success) { - qDebug() << "blkid command to get label failed."; + qCDebug(serviceLog) << "blkid command to get label failed."; return false; } size_t len = output.length(); if (len > 0 && output.back() == '\n') { - qDebug() << "Stripping trailing newline from blkid output."; + qCDebug(serviceLog) << "Stripping trailing newline from blkid output."; // Output is either the label with a terminating new line or zero bytes // when the file system has no label. Strip optional trailing new line // from blkid output. @@ -297,7 +298,7 @@ bool FsInfo::runBlkidUpdateCacheOneLabel(fileSystemEntry &fsEntry) // Update cache entry with the read label. fsEntry.m_haveLabel = true; fsEntry.m_label = output; - qDebug() << "Updated label:" << fsEntry.m_label; + qCDebug(serviceLog) << "Updated label:" << fsEntry.m_label; return true; } diff --git a/service/diskoperation/luksoperator/luksoperator.cpp b/service/diskoperation/luksoperator/luksoperator.cpp index f215407d..3f100aa9 100644 --- a/service/diskoperation/luksoperator/luksoperator.cpp +++ b/service/diskoperation/luksoperator/luksoperator.cpp @@ -1,8 +1,9 @@ // Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd. -// 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 "luksoperator.h" #include "../fsinfo.h" #include @@ -23,18 +24,18 @@ static const QString saveKeyPath = "/root/.deepin-diskmanager-service"; //ke LUKSOperator::LUKSOperator() { - qDebug() << "LUKSOperator constructor called"; + qCDebug(serviceLog) << "LUKSOperator constructor called"; } bool LUKSOperator::updateLUKSInfo(DeviceInfoMap &dev, LVMInfo &lvmInfo, LUKSMap &luks) { - qDebug() << "Updating LUKS information"; + qCDebug(serviceLog) << "Updating LUKS information"; m_dev = &dev; m_lvmInfo = &lvmInfo; resetLuksMap(luks); //初始化映射 算法 if (!initMapper(luks) || !getCIPHERSupport(luks.m_cryptSuuport)) { - qDebug() << "Failed to initialize mapper or get CIPHER support."; + qCDebug(serviceLog) << "Failed to initialize mapper or get CIPHER support."; return setLUKSErr(luks, CRYPTError::CRYPT_ERR_INIT_FAILED); } @@ -42,11 +43,11 @@ bool LUKSOperator::updateLUKSInfo(DeviceInfoMap &dev, LVMInfo &lvmInfo, LUKSMap for (DeviceInfoMap::iterator devIt = dev.begin(); devIt != dev.end(); ++devIt) { devIt.value().m_crySupport = luks.m_cryptSuuport; if (!lvmInfo.lvInfoExists(devIt.key()) && isLUKS(devIt.key())) { //判断是否为lv加密的映射盘 - // qDebug() << "Device" << devIt.key() << "is a LUKS device (not LVM)."; + // qCDebug(serviceLog) << "Device" << devIt.key() << "is a LUKS device (not LVM)."; devIt->m_luksFlag = LUKSFlag::IS_CRYPT_LUKS; LUKS_INFO info; if (!getLUKSInfo(luks, devIt.key(), info)) { - qDebug() << "Failed to get LUKS info for device:" << devIt.key(); + qCDebug(serviceLog) << "Failed to get LUKS info for device:" << devIt.key(); return setLUKSErr(luks, CRYPTError::CRYPT_ERR_GET_LUKSINFO_FAILED); } luks.m_luksMap.insert(info.m_devicePath, info); @@ -57,12 +58,12 @@ bool LUKSOperator::updateLUKSInfo(DeviceInfoMap &dev, LVMInfo &lvmInfo, LUKSMap if (partIt->m_fileSystemType != FSType::FS_LUKS) { //分区通过文件系统判断是否为luks continue; } - // qDebug() << "Partition" << partIt->m_path << "is a LUKS partition."; + // qCDebug(serviceLog) << "Partition" << partIt->m_path << "is a LUKS partition."; partIt->m_luksFlag = LUKSFlag::IS_CRYPT_LUKS;//获取分区数据 devIt->m_luksFlag = LUKSFlag::IS_CRYPT_LUKS; LUKS_INFO info; if (!getLUKSInfo(luks, partIt->m_path, info)) { - qDebug() << "Failed to get LUKS info for partition:" << partIt->m_path; + qCDebug(serviceLog) << "Failed to get LUKS info for partition:" << partIt->m_path; return setLUKSErr(luks, CRYPTError::CRYPT_ERR_GET_LUKSINFO_FAILED); } luks.m_luksMap.insert(info.m_devicePath, info); @@ -74,14 +75,14 @@ bool LUKSOperator::updateLUKSInfo(DeviceInfoMap &dev, LVMInfo &lvmInfo, LUKSMap if (!isLUKS(lvIt->m_lvPath)) { continue; } - // qDebug() << "LV" << lvIt->m_lvPath << "is a LUKS LV."; + // qCDebug(serviceLog) << "LV" << lvIt->m_lvPath << "is a LUKS LV."; lvIt->m_luksFlag = LUKSFlag::IS_CRYPT_LUKS; lvIt->m_lvFsType = FSType::FS_LUKS; lvIt->m_fsUsed = lvIt->m_LESize * lvIt->m_lvLECount; vgIt.value().m_luksFlag = LUKSFlag::IS_CRYPT_LUKS; LUKS_INFO info; if (!getLUKSInfo(luks, lvIt->toMapperPath(), info)) { - qDebug() << "Failed to get LUKS info for LV:" << lvIt->toMapperPath(); + qCDebug(serviceLog) << "Failed to get LUKS info for LV:" << lvIt->toMapperPath(); return setLUKSErr(luks, CRYPTError::CRYPT_ERR_GET_LUKSINFO_FAILED); } @@ -96,17 +97,17 @@ bool LUKSOperator::updateLUKSInfo(DeviceInfoMap &dev, LVMInfo &lvmInfo, LUKSMap bool LUKSOperator::encrypt(LUKSMap &luks, LUKS_INFO &luksInfo) { - qDebug() << "Starting encryption for device:" << luksInfo.m_devicePath; + qCDebug(serviceLog) << "Starting encryption for device:" << luksInfo.m_devicePath; //判断参数是否正确 if (!(luksInfo.m_crypt == CRYPT_CIPHER::AES_XTS_PLAIN64 || luksInfo.m_crypt == CRYPT_CIPHER::SM4_XTS_PLAIN64) || luksInfo.m_devicePath.isEmpty() || luksInfo.m_decryptStr.isEmpty()) { - qWarning() << "Invalid arguments for encryption"; + qCWarning(serviceLog) << "Invalid arguments for encryption"; return setLUKSErr(luks, CRYPTError::CRYPT_ERR_ENCRYPT_ARGUMENT); } //加密 if (!format(luksInfo)) { - qCritical() << Q_FUNC_INFO << "format failed"; + qCCritical(serviceLog) << Q_FUNC_INFO << "format failed"; return setLUKSErr(luks, CRYPTError::CRYPT_ERR_ENCRYPT_FAILED); } //添加错误记录 @@ -115,26 +116,26 @@ bool LUKSOperator::encrypt(LUKSMap &luks, LUKS_INFO &luksInfo) addToken(luksInfo, luksInfo.m_tokenList); bool success = getLUKSInfo(luks, luksInfo.m_devicePath, luksInfo); luksInfo.isDecrypt = false; - qDebug() << "Encryption finished for device:" << luksInfo.m_devicePath << "Success:" << success; + qCDebug(serviceLog) << "Encryption finished for device:" << luksInfo.m_devicePath << "Success:" << success; return setLUKSErr(luks, luksInfo, success ? CRYPTError::CRYPT_ERR_NORMAL : CRYPTError::CRYPT_ERR_GET_LUKSINFO_FAILED); } bool LUKSOperator::decrypt(LUKSMap &luks, LUKS_INFO &luksInfo) { - qDebug() << "Starting decryption for device:" << luksInfo.m_devicePath; + qCDebug(serviceLog) << "Starting decryption for device:" << luksInfo.m_devicePath; //判断参数是否正确 if (luksInfo.m_mapper.m_dmName.isEmpty() || luksInfo.m_devicePath.isEmpty() || luksInfo.m_decryptStr.isEmpty()) { - qWarning() << "Invalid arguments for decryption"; + qCWarning(serviceLog) << "Invalid arguments for decryption"; return setLUKSErr(luks, CRYPTError::CRYPT_ERR_ENCRYPT_ARGUMENT); } if (!luksInfo.isDecrypt) { - qDebug() << "Device not decrypted, attempting to open."; + qCDebug(serviceLog) << "Device not decrypted, attempting to open."; luksInfo.m_decryptErrCount = open(luksInfo) ? 0 : luksInfo.m_decryptErrCount + 1; } else { - qDebug() << "Device already decrypted, testing key."; + qCDebug(serviceLog) << "Device already decrypted, testing key."; luksInfo.m_decryptErrCount = testKey(luksInfo) ? 0 : luksInfo.m_decryptErrCount + 1; } @@ -142,65 +143,65 @@ bool LUKSOperator::decrypt(LUKSMap &luks, LUKS_INFO &luksInfo) updateDecryptToken(luksInfo, false); getLUKSInfo(luks, luksInfo.m_devicePath, luksInfo); luksInfo.isDecrypt = (0 == luksInfo.m_decryptErrCount); - qDebug() << "Decryption finished for device:" << luksInfo.m_devicePath << "Success:" << luksInfo.isDecrypt; + qCDebug(serviceLog) << "Decryption finished for device:" << luksInfo.m_devicePath << "Success:" << luksInfo.isDecrypt; return setLUKSErr(luks, luksInfo, luksInfo.isDecrypt ? CRYPTError::CRYPT_ERR_NORMAL : CRYPTError::CRYPT_ERR_DECRYPT_FAILED); } bool LUKSOperator::closeMapper(LUKSMap &luks, LUKS_INFO &luksInfo) { - qDebug() << "LUKSOperator::closeMapper called for device:" << luksInfo.m_devicePath; + qCDebug(serviceLog) << "LUKSOperator::closeMapper called for device:" << luksInfo.m_devicePath; //如果没有打开 返回正确 if (!luksInfo.isDecrypt) { - qDebug() << "Device not decrypted, no need to close mapper."; + qCDebug(serviceLog) << "Device not decrypted, no need to close mapper."; return setLUKSErr(luks, luksInfo, CRYPTError::CRYPT_ERR_NORMAL); } //判断参数是否正确 if (luksInfo.m_mapper.m_dmPath.isEmpty()) { - qWarning() << "Invalid arguments for closeMapper: dmPath is empty."; + qCWarning(serviceLog) << "Invalid arguments for closeMapper: dmPath is empty."; return setLUKSErr(luks, luksInfo, CRYPTError::CRYPT_ERR_ENCRYPT_ARGUMENT); } bool success = close(luksInfo); - qDebug() << "Closed mapper for device:" << luksInfo.m_devicePath << "Success:" << success; + qCDebug(serviceLog) << "Closed mapper for device:" << luksInfo.m_devicePath << "Success:" << success; return setLUKSErr(luks, luksInfo, success ? CRYPTError::CRYPT_ERR_NORMAL : CRYPTError::CRYPT_ERR_DECRYPT_FAILED); } bool LUKSOperator::addKeyAndCrypttab(LUKSMap &luks, LUKS_INFO &luksInfo) { - qDebug() << "LUKSOperator::addKeyAndCrypttab called for device:" << luksInfo.m_devicePath; + qCDebug(serviceLog) << "LUKSOperator::addKeyAndCrypttab called for device:" << luksInfo.m_devicePath; if (!addKeyFile(luksInfo)) { - qDebug() << "addKeyFile failed for device:" << luksInfo.m_devicePath; + qCDebug(serviceLog) << "addKeyFile failed for device:" << luksInfo.m_devicePath; return setLUKSErr(luks, luksInfo, CRYPTError::CRYPT_ERR_ADD_KEY_FAILED); } bool success = wirteCrypttab(luksInfo, true); - qDebug() << "addKeyAndCrypttab finished for device:" << luksInfo.m_devicePath << "Success:" << success; + qCDebug(serviceLog) << "addKeyAndCrypttab finished for device:" << luksInfo.m_devicePath << "Success:" << success; return setLUKSErr(luks, luksInfo, success ? CRYPTError::CRYPT_ERR_NORMAL : CRYPTError::CRYPT_ERR_CRYPTTAB_FAILED); } bool LUKSOperator::deleteKeyAndCrypttab(LUKSMap &luks, LUKS_INFO &luksInfo) { - qDebug() << "LUKSOperator::deleteKeyAndCrypttab called for device:" << luksInfo.m_devicePath; + qCDebug(serviceLog) << "LUKSOperator::deleteKeyAndCrypttab called for device:" << luksInfo.m_devicePath; if (!deleteKeyFile(luksInfo)) { - qDebug() << "deleteKeyFile failed for device:" << luksInfo.m_devicePath; + qCDebug(serviceLog) << "deleteKeyFile failed for device:" << luksInfo.m_devicePath; return setLUKSErr(luks, luksInfo, CRYPTError::CRYPT_ERR_DEL_KEY_FAILED); } bool success = wirteCrypttab(luksInfo, false); - qDebug() << "deleteKeyAndCrypttab finished for device:" << luksInfo.m_devicePath << "Success:" << success; + qCDebug(serviceLog) << "deleteKeyAndCrypttab finished for device:" << luksInfo.m_devicePath << "Success:" << success; return setLUKSErr(luks, luksInfo, success ? CRYPTError::CRYPT_ERR_NORMAL : CRYPTError::CRYPT_ERR_CRYPTTAB_FAILED); } bool LUKSOperator::removeMapperAndKey(LUKSMap &luks, LUKS_INFO &luksInfo) { - qDebug() << "LUKSOperator::removeMapperAndKey called for device:" << luksInfo.m_devicePath; + qCDebug(serviceLog) << "LUKSOperator::removeMapperAndKey called for device:" << luksInfo.m_devicePath; bool success = deleteKeyAndCrypttab(luks, luksInfo) && closeMapper(luks, luksInfo); - qDebug() << "removeMapperAndKey finished for device:" << luksInfo.m_devicePath << "Success:" << success; + qCDebug(serviceLog) << "removeMapperAndKey finished for device:" << luksInfo.m_devicePath << "Success:" << success; return success; } void LUKSOperator::resetLuksMap(LUKSMap &luks) { - qDebug() << "LUKSOperator::resetLuksMap called."; + qCDebug(serviceLog) << "LUKSOperator::resetLuksMap called."; luks.m_mapper.clear(); luks.m_luksMap.clear(); luks.m_cryErr = CRYPTError::CRYPT_ERR_NORMAL; @@ -214,19 +215,19 @@ void LUKSOperator::resetLuksMap(LUKSMap &luks) bool LUKSOperator::initMapper(LUKSMap &luks) { - qDebug() << "LUKSOperator::initMapper called."; + qCDebug(serviceLog) << "LUKSOperator::initMapper called."; luks.m_mapper.clear(); QString cmd, strout, strerr; cmd = QString("dmsetup ls --target crypt"); //获取所有解密的设备 if (Utils::executCmd(cmd, strout, strerr) != 0) { - qDebug() << "Failed to execute 'dmsetup ls'."; + qCDebug(serviceLog) << "Failed to execute 'dmsetup ls'."; return false; } foreach (QString str, strout.split("\n")) { QStringList list = str.split("\t"); if (list.count() == 2) { - qDebug() << "Processing decrypted device:" << list[0]; + qCDebug(serviceLog) << "Processing decrypted device:" << list[0]; LUKS_MapperInfo mapper; mapper.m_dmName = list[0]; mapper.m_dmPath = "/dev/mapper/" + mapper.m_dmName; @@ -234,7 +235,7 @@ bool LUKSOperator::initMapper(LUKSMap &luks) QString cmd2, strout2, strerr2; cmd2 = QString(" cryptsetup status %1").arg(mapper.m_dmPath); if (Utils::executCmd(cmd2, strout2, strerr2) != 0) { - qDebug() << "Failed to execute 'cryptsetup status' for" << mapper.m_dmPath; + qCDebug(serviceLog) << "Failed to execute 'cryptsetup status' for" << mapper.m_dmPath; return false; } @@ -261,10 +262,10 @@ bool LUKSOperator::initMapper(LUKSMap &luks) auto it = m_dev->find(mapper.m_dmPath); if (it != m_dev->end()) { - qDebug() << "Found device info for mapper path:" << mapper.m_dmPath; + qCDebug(serviceLog) << "Found device info for mapper path:" << mapper.m_dmPath; auto partIt = it.value().m_partition.begin(); if (partIt != it.value().m_partition.end()) { - qDebug() << "Found partition info for mapper path."; + qCDebug(serviceLog) << "Found partition info for mapper path."; PartitionInfo part = *partIt; mapper.m_busy = part.m_busy; mapper.m_mountPoints = part.m_mountPoints; @@ -275,10 +276,10 @@ bool LUKSOperator::initMapper(LUKSMap &luks) mapper.m_uuid = part.m_uuid; mapper.m_fsLimits = part.m_fsLimits; if (FS_FAT32 == mapper.m_luksFs || FS_FAT16 == mapper.m_luksFs) { - qDebug() << "FAT filesystem, no resize limits."; + qCDebug(serviceLog) << "FAT filesystem, no resize limits."; mapper.m_fsLimits = FS_Limits(-1, -1); //fat格式不支持逻辑卷的扩展缩小 } else if (FS_UNALLOCATED == mapper.m_luksFs) { //empty fs , no limits - qDebug() << "Unallocated space, no resize limits."; + qCDebug(serviceLog) << "Unallocated space, no resize limits."; mapper.m_fsLimits = FS_Limits(0, 0); } } @@ -298,7 +299,7 @@ bool LUKSOperator::initMapper(LUKSMap &luks) luks.m_mapper.insert(mapper.m_devicePath, mapper); } } - qDebug() << "initMapper finished."; + qCDebug(serviceLog) << "initMapper finished."; return true; } @@ -309,7 +310,7 @@ bool LUKSOperator::getCIPHERSupport(CRYPT_CIPHER_Support &support) cmd = QString("modprobe -c"); if (Utils::executCmd(cmd, strout, strerr) != 0) { - qDebug() << "Failed to execute 'cryptsetup --help'."; + qCDebug(serviceLog) << "Failed to execute 'cryptsetup --help'."; return false; } @@ -380,7 +381,7 @@ bool LUKSOperator::getLUKSInfo(const LUKSMap &luks, const QString &devPath, LUKS QString cmd, strout, strerr; cmd = QString("cryptsetup luksDump %1 --debug-json").arg(devPath); if (Utils::executCmd(cmd, strout, strerr) != 0) { - qDebug() << "Failed to execute 'cryptsetup luksDump' for" << devPath; + qCDebug(serviceLog) << "Failed to execute 'cryptsetup luksDump' for" << devPath; return false; } info.m_tokenList.clear(); @@ -421,7 +422,7 @@ bool LUKSOperator::getLUKSInfo(const LUKSMap &luks, const QString &devPath, LUKS bool LUKSOperator::jsonToLUKSInfo(QString jsonStr, LUKS_INFO &info) { - qDebug() << "LUKSOperator::jsonToLUKSInfo called."; + qCDebug(serviceLog) << "LUKSOperator::jsonToLUKSInfo called."; //获取对象填入value中 同时判断该value是否为object auto getObjectValue = [ = ](QJsonObject obj, QString key, QJsonValue & value)->bool{ if (!obj.contains(key)) @@ -511,17 +512,17 @@ bool LUKSOperator::jsonToLUKSInfo(QString jsonStr, LUKS_INFO &info) bool LUKSOperator::isLUKS(QString devPath) { - qDebug() << "LUKSOperator::isLUKS called for device:" << devPath; + qCDebug(serviceLog) << "LUKSOperator::isLUKS called for device:" << devPath; QString cmd, strout, strerr; cmd = QString("cryptsetup isLuks %1").arg(devPath); bool result = (0 == Utils::executCmd(cmd, strout, strerr)); - qDebug() << "Device" << devPath << "is LUKS:" << result; + qCDebug(serviceLog) << "Device" << devPath << "is LUKS:" << result; return result; } bool LUKSOperator::format(const LUKS_INFO &luks) { - qInfo() << "Formatting device for LUKS:" << luks.m_devicePath << "with cipher:" << Utils::getCipherStr(luks.m_crypt); + qCInfo(serviceLog) << "Formatting device for LUKS:" << luks.m_devicePath << "with cipher:" << Utils::getCipherStr(luks.m_crypt); QString outPut, error; QString cmd = QString("cryptsetup --cipher %1 --key-size 256 --hash sha256 luksFormat --label=%2 %3 -q") .arg(Utils::getCipherStr(luks.m_crypt)) @@ -529,14 +530,14 @@ bool LUKSOperator::format(const LUKS_INFO &luks) .arg(luks.m_devicePath); bool success = (Utils::executWithInputOutputCmd(cmd, &luks.m_decryptStr, outPut, error) == 0); if (!success) { - qCritical() << Q_FUNC_INFO << "output:" << outPut << "\terror:" << error; + qCCritical(serviceLog) << Q_FUNC_INFO << "output:" << outPut << "\terror:" << error; } return success; } bool LUKSOperator::open(const LUKS_INFO &luks) { - qDebug() << "Opening LUKS device:" << luks.m_devicePath << "with mapper:" << luks.m_mapper.m_dmName; + qCDebug(serviceLog) << "Opening LUKS device:" << luks.m_devicePath << "with mapper:" << luks.m_mapper.m_dmName; QString outPut, error; QString cmd = QString("cryptsetup open %1 %2 -q") .arg(luks.m_devicePath) @@ -555,27 +556,27 @@ bool LUKSOperator::testKey(const LUKS_INFO &luks) bool LUKSOperator::close(const LUKS_INFO &luks) { - qDebug() << "Closing LUKS device:" << luks.m_mapper.m_dmPath; + qCDebug(serviceLog) << "Closing LUKS device:" << luks.m_mapper.m_dmPath; QString cmd, strout, strerr; cmd = QString("cryptsetup close %1").arg(luks.m_mapper.m_dmPath); bool result = (0 == Utils::executCmd(cmd, strout, strerr)); - qDebug() << "Closing device" << luks.m_mapper.m_dmPath << "result:" << result; + qCDebug(serviceLog) << "Closing device" << luks.m_mapper.m_dmPath << "result:" << result; return result; } bool LUKSOperator::addToken(const LUKS_INFO &luks, QStringList list, int number) { - qDebug() << "LUKSOperator::addToken BEGIN"; + qCDebug(serviceLog) << "LUKSOperator::addToken BEGIN"; QString cmd, strout, strerr; foreach (QString str, list) { if (number == -1) { - // qDebug() << "number is -1"; + // qCDebug(serviceLog) << "number is -1"; str = str.replace(" ", "$####$"); cmd = QString("cryptsetup token add --key-description='%1' %2 ") .arg(str) .arg(luks.m_devicePath); } else { - // qDebug() << "number is not -1"; + // qCDebug(serviceLog) << "number is not -1"; cmd = QString("cryptsetup token add --key-description='%1' --token-id=%2 %3") .arg(str) .arg(number) @@ -584,17 +585,17 @@ bool LUKSOperator::addToken(const LUKS_INFO &luks, QStringList list, int number) } if (Utils::executCmd(cmd, strout, strerr) != 0) { - qDebug() << "executCmd failed, return false"; + qCDebug(serviceLog) << "executCmd failed, return false"; return false; } } - qDebug() << "LUKSOperator::addToken END"; + qCDebug(serviceLog) << "LUKSOperator::addToken END"; return true; } bool LUKSOperator::removeToken(const LUKS_INFO &luks, int number) { - qDebug() << "LUKSOperator::removeToken called for device:" << luks.m_devicePath << "token id:" << number; + qCDebug(serviceLog) << "LUKSOperator::removeToken called for device:" << luks.m_devicePath << "token id:" << number; QString cmd, strout, strerr; cmd = QString("cryptsetup token remove --token-id %1 %2 ") .arg(number) @@ -604,23 +605,23 @@ bool LUKSOperator::removeToken(const LUKS_INFO &luks, int number) bool LUKSOperator::updateDecryptToken(LUKS_INFO &info, bool isFirst) { - qDebug() << "LUKSOperator::updateDecryptToken BEGIN"; + qCDebug(serviceLog) << "LUKSOperator::updateDecryptToken BEGIN"; if (!isFirst) { - qDebug() << "isFirst is false"; + qCDebug(serviceLog) << "isFirst is false"; if (!removeToken(info, 0)) { - qDebug() << "removeToken failed, return false"; + qCDebug(serviceLog) << "removeToken failed, return false"; return false; } } info.m_decryptErrorLastTime = QDateTime::currentDateTime().toString("yyyy-MM-dd$$hh:mm:ss"); - qDebug() << "LUKSOperator::updateDecryptToken END"; + qCDebug(serviceLog) << "LUKSOperator::updateDecryptToken END"; return addToken(info, QStringList() << QString("decryptCount:%1####decryptErrTimer:%2").arg(info.m_decryptErrCount).arg(info.m_decryptErrorLastTime), 0); } bool LUKSOperator::addKeyFile(const LUKS_INFO &luks) { - qInfo() << "Adding key file for LUKS device:" << luks.m_devicePath; + qCInfo(serviceLog) << "Adding key file for LUKS device:" << luks.m_devicePath; //创建文件 QDir dir; if(!dir.exists(saveKeyPath)){ @@ -647,7 +648,7 @@ bool LUKSOperator::addKeyFile(const LUKS_INFO &luks) bool LUKSOperator::deleteKeyFile(const LUKS_INFO &luks) { - qInfo() << "Deleting key file for LUKS device:" << luks.m_devicePath; + qCInfo(serviceLog) << "Deleting key file for LUKS device:" << luks.m_devicePath; QString filePath = QString("%1/%2.key").arg(saveKeyPath).arg(luks.m_dmUUID); if (!QFile::exists(filePath)) { return true; @@ -660,13 +661,13 @@ bool LUKSOperator::deleteKeyFile(const LUKS_INFO &luks) bool LUKSOperator::wirteCrypttab(LUKS_INFO &luksInfo, bool isMount) { - qDebug() << "LUKSOperator::wirteCrypttab BEGIN"; + qCDebug(serviceLog) << "LUKSOperator::wirteCrypttab BEGIN"; QString filePath = QString("%1/%2.key").arg(saveKeyPath).arg(luksInfo.m_dmUUID); // open crypttab QFile file("/etc/crypttab"); QStringList list; if (!file.open(QIODevice::ReadOnly)) { //打开指定文件 - qDebug() << "open /etc/crypttab failed, return false"; + qCDebug(serviceLog) << "open /etc/crypttab failed, return false"; return false; } QFileDevice::Permissions origPerm = file.permissions(); @@ -677,23 +678,23 @@ bool LUKSOperator::wirteCrypttab(LUKS_INFO &luksInfo, bool isMount) QByteArray line = file.readLine();//获取数据 QString str = line; if (isMount) { - // qDebug() << "isMount is true"; + // qCDebug(serviceLog) << "isMount is true"; QString mountStr = QString("%1 UUID=\"%2\" %3\n").arg(luksInfo.m_mapper.m_dmName).arg(luksInfo.m_dmUUID).arg(filePath); if (str.contains(luksInfo.m_dmUUID) && !findflag) { //首次查找到uuid - // qDebug() << "found uuid and not findflag"; + // qCDebug(serviceLog) << "found uuid and not findflag"; findflag = true; list << mountStr; continue; } else if (file.atEnd() && !findflag) { //查找到结尾且没有查找到uuid - qDebug() << "atEnd and not findflag"; + qCDebug(serviceLog) << "atEnd and not findflag"; list << str << mountStr; break; } list << str; } else { - // qDebug() << "isMount is false"; + // qCDebug(serviceLog) << "isMount is false"; if (!str.contains(luksInfo.m_dmUUID)) { - // qDebug() << "not contains uuid"; + // qCDebug(serviceLog) << "not contains uuid"; list << str; } } @@ -703,7 +704,7 @@ bool LUKSOperator::wirteCrypttab(LUKS_INFO &luksInfo, bool isMount) // 原子写入:先写临时文件,再 rename 到 /etc/crypttab,避免 TOCTOU 竞态 QSaveFile saveFile(QStringLiteral("/etc/crypttab")); if (!saveFile.open(QIODevice::WriteOnly)) { - qDebug() << "open /etc/crypttab for write failed, return false"; + qCDebug(serviceLog) << "open /etc/crypttab for write failed, return false"; return false; } QTextStream out(&saveFile); @@ -712,19 +713,19 @@ bool LUKSOperator::wirteCrypttab(LUKS_INFO &luksInfo, bool isMount) } out.flush(); if (!saveFile.commit()) { - qDebug() << "commit /etc/crypttab failed, return false"; + qCDebug(serviceLog) << "commit /etc/crypttab failed, return false"; return false; } // 恢复原文件权限,避免 QSaveFile 使用临时文件导致权限被 umask 改变 QFile::setPermissions(QStringLiteral("/etc/crypttab"), origPerm); - qDebug() << "Successfully created key file:" << filePath; - qDebug() << "LUKSOperator::wirteCrypttab END"; + qCDebug(serviceLog) << "Successfully created key file:" << filePath; + qCDebug(serviceLog) << "LUKSOperator::wirteCrypttab END"; return true; } bool LUKSOperator::setLUKSErr(LUKSMap &luksInfo, const CRYPTError &err) { - qDebug() << "LUKSOperator::setLUKSErr(luksInfo, err) called"; + qCDebug(serviceLog) << "LUKSOperator::setLUKSErr(luksInfo, err) called"; m_cryErr = err; luksInfo.m_cryErr = err; return luksInfo.m_cryErr == CRYPTError::CRYPT_ERR_NORMAL; @@ -732,7 +733,7 @@ bool LUKSOperator::setLUKSErr(LUKSMap &luksInfo, const CRYPTError &err) bool LUKSOperator::setLUKSErr(LUKSMap &luksInfo, LUKS_INFO &info, const CRYPTError &err) { - qDebug() << "LUKSOperator::setLUKSErr(luksInfo, info, err) called"; + qCDebug(serviceLog) << "LUKSOperator::setLUKSErr(luksInfo, info, err) called"; info.m_cryptErr = err; return setLUKSErr(luksInfo, err); } diff --git a/service/diskoperation/lvmoperator/lvmoperator.cpp b/service/diskoperation/lvmoperator/lvmoperator.cpp index 46298baa..b818e068 100644 --- a/service/diskoperation/lvmoperator/lvmoperator.cpp +++ b/service/diskoperation/lvmoperator/lvmoperator.cpp @@ -1,8 +1,9 @@ // Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd. -// 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 "lvmoperator.h" #include "utils.h" #include "mountinfo.h" @@ -23,13 +24,13 @@ LVMError LVMOperator::m_lvmErr = LVM_ERR_NORMAL; /******************************** 初始化操作 ******************************/ LVMOperator::LVMOperator() { - qDebug() << "LVMOperator constructor called"; + qCDebug(serviceLog) << "LVMOperator constructor called"; initSuport(); } void LVMOperator::resetLVMInfo(LVMInfo &lvmInfo) { - qDebug() << "LVMOperator::resetLVMInfo called."; + qCDebug(serviceLog) << "LVMOperator::resetLVMInfo called."; lvmInfo.m_pvInfo.clear(); lvmInfo.m_vgInfo.clear(); lvmInfo.m_lvmErr = LVMError::LVM_ERR_NORMAL; @@ -37,9 +38,9 @@ void LVMOperator::resetLVMInfo(LVMInfo &lvmInfo) bool LVMOperator::initSuport() { - qDebug() << "Initializing LVM support"; + qCDebug(serviceLog) << "Initializing LVM support"; if (!m_initSupport) { - qDebug() << "Initializing LVM command support flags."; + qCDebug(serviceLog) << "Initializing LVM command support flags."; m_lvmSupport.LVM_CMD_lvchange = getExecSupport("lvchange"); m_lvmSupport.LVM_CMD_lvconvert = getExecSupport("lvconvert"); m_lvmSupport.LVM_CMD_lvcreate = getExecSupport("lvcreate"); @@ -88,13 +89,13 @@ bool LVMOperator::initSuport() /******************************** 更新DATA ******************************/ bool LVMOperator::getDeviceLVMData(DeviceInfoMap &dev, const LVMInfo &lvmInfo) { - qDebug() << "LVMOperator::getDeviceLVMData called."; + qCDebug(serviceLog) << "LVMOperator::getDeviceLVMData called."; auto pv2vg_func = [ = ](const PVInfo & pv) { - qDebug() << "pv2vg_func called for PV:" << pv.m_pvPath; + qCDebug(serviceLog) << "pv2vg_func called for PV:" << pv.m_pvPath; VGData vg; vg.m_vgName = pv.m_vgName; if (vg.m_vgName.isEmpty()) { - qDebug() << "VG name is empty, using PV path as VG name."; + qCDebug(serviceLog) << "VG name is empty, using PV path as VG name."; vg.m_vgName = pv.m_pvPath; } vg.m_vgSize = pv.m_pvSize; @@ -124,7 +125,7 @@ bool LVMOperator::getDeviceLVMData(DeviceInfoMap &dev, const LVMInfo &lvmInfo) diskIter->m_vgFlag = LVM_FLAG_NOT_PV; QMap::ConstIterator pvIter = lvmInfo.m_pvInfo.find(diskIter->m_path); if (pvIter != lvmInfo.m_pvInfo.end() && QString("unrecognized") == diskIter.value().m_disktype) { //不存在分区表 磁盘加入 - // qDebug() << "Disk has no partition table, treating as PV."; + // qCDebug(serviceLog) << "Disk has no partition table, treating as PV."; diskIter->m_vgFlag = pvIter->noJoinVG() ? LVMFlag::LVM_FLAG_NOT_JOIN_VG : LVMFlag::LVM_FLAG_JOIN_VG; diskIter->m_vglist.push_back(pv2vg_func(pvIter.value())); continue; @@ -133,7 +134,7 @@ bool LVMOperator::getDeviceLVMData(DeviceInfoMap &dev, const LVMInfo &lvmInfo) for (QVector::iterator partIter = diskIter.value().m_partition.begin(); partIter != diskIter.value().m_partition.end(); ++partIter) { QMap::ConstIterator pvIter = lvmInfo.m_pvInfo.find(partIter->m_path); if (lvmInfo.m_pvInfo.end() != pvIter) { - // qDebug() << "Found PV info for partition:" << partIter->m_path; + // qCDebug(serviceLog) << "Found PV info for partition:" << partIter->m_path; const PVInfo &pv = pvIter.value(); LVMFlag flag = pvIter->noJoinVG() ? LVMFlag::LVM_FLAG_NOT_JOIN_VG : LVMFlag::LVM_FLAG_JOIN_VG; //判断pv是否加入vg diskIter->m_vgFlag = flag; @@ -144,13 +145,13 @@ bool LVMOperator::getDeviceLVMData(DeviceInfoMap &dev, const LVMInfo &lvmInfo) } } - qDebug() << "LVMOperator::getDeviceLVMData completed, return true"; + qCDebug(serviceLog) << "LVMOperator::getDeviceLVMData completed, return true"; return true; } bool LVMOperator::getDeviceDataAndLVMInfo(DeviceInfoMap &dev, LVMInfo &lvmInfo) { - qDebug() << "LVMOperator::getDeviceDataAndLVMInfo called."; + qCDebug(serviceLog) << "LVMOperator::getDeviceDataAndLVMInfo called."; m_devInfo = dev; updateLVMInfo(lvmInfo); getDeviceLVMData(dev, lvmInfo); @@ -160,7 +161,7 @@ bool LVMOperator::getDeviceDataAndLVMInfo(DeviceInfoMap &dev, LVMInfo &lvmInfo) /******************************** 更新info ******************************/ bool LVMOperator::updateLVMInfo(LVMInfo &lvmInfo) { - qDebug() << "LVMOperator::updateLVMInfo called."; + qCDebug(serviceLog) << "LVMOperator::updateLVMInfo called."; initSuport(); resetLVMInfo(lvmInfo); updateVGInfo(lvmInfo); @@ -170,9 +171,9 @@ bool LVMOperator::updateLVMInfo(LVMInfo &lvmInfo) bool LVMOperator::updatePVInfo(LVMInfo &lvmInfo) { - qDebug() << "LVMOperator::updatePVInfo called."; + qCDebug(serviceLog) << "LVMOperator::updatePVInfo called."; if (Utils::findProgramInPath("lsblk").isEmpty() || LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_pvs) { - qDebug() << "lsblk or pvs command not found."; + qCDebug(serviceLog) << "lsblk or pvs command not found."; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } @@ -182,7 +183,7 @@ bool LVMOperator::updatePVInfo(LVMInfo &lvmInfo) Utils::executCmd("pvs --noheadings -o pv_name", strout, strerror); strout = strout.trimmed(); foreach (QString str, strout.split("\n")) { - // qDebug() << "Processing PV:" << str; + // qCDebug(serviceLog) << "Processing PV:" << str; if (str.isEmpty()) { continue; } @@ -216,22 +217,22 @@ bool LVMOperator::updatePVInfo(LVMInfo &lvmInfo) cmd = QString("lsblk %1 -o type -nd").arg(pv.m_pvPath); Utils::executCmd(cmd, strout, strerror); if (strout.contains("part")) { - // qDebug() << "Device is a partition."; + // qCDebug(serviceLog) << "Device is a partition."; pv.m_lvmDevType = DevType::DEV_PARTITION; } else if (strout.contains("disk")) { - // qDebug() << "Device is a disk."; + // qCDebug(serviceLog) << "Device is a disk."; pv.m_lvmDevType = DevType::DEV_DISK; } else if (strout.contains("loop")) { - // qDebug() << "Device is a loop device."; + // qCDebug(serviceLog) << "Device is a loop device."; pv.m_lvmDevType = DevType::DEV_LOOP; } else if (strout.contains("raid")) { - // qDebug() << "Device is a RAID device."; + // qCDebug(serviceLog) << "Device is a RAID device."; pv.m_lvmDevType = DevType::DEV_META_DEVICES; } else if (strout.contains("crypt")) { - // qDebug() << "Device is a LUKS device."; + // qCDebug(serviceLog) << "Device is a LUKS device."; pv.m_lvmDevType = DevType::DEV_META_DEVICES; } else { - // qDebug() << "Device is an unknown device type."; + // qCDebug(serviceLog) << "Device is an unknown device type."; pv.m_lvmDevType = DevType::DEV_UNKNOW_DEVICES; } @@ -243,7 +244,7 @@ bool LVMOperator::updatePVInfo(LVMInfo &lvmInfo) if (list.size() < 4) { continue; } - // qDebug() << "Processing segment:" << str.trimmed(); + // qCDebug(serviceLog) << "Processing segment:" << str.trimmed(); QVectorlvVec; VG_PV_Ranges vgRanges; vgRanges.m_vgName = pv.m_vgName; @@ -252,7 +253,7 @@ bool LVMOperator::updatePVInfo(LVMInfo &lvmInfo) vgRanges.m_start = getStringListItem(list, 1).toLongLong(); vgRanges.m_end = getStringListItem(list, 2).toLongLong() + vgRanges.m_start - 1; if (!list[0].contains("free")) { - // qDebug() << "Segment is not free."; + // qCDebug(serviceLog) << "Segment is not free."; vgRanges.m_used = true; LV_PV_Ranges lvRanges = vgRanges; lvRanges.m_devPath = getStringListItem(list, 3); @@ -263,7 +264,7 @@ bool LVMOperator::updatePVInfo(LVMInfo &lvmInfo) pv.m_vgRangesList.push_back(vgRanges); } if (pv.joinVG() && lvmInfo.vgExists(pv)) { - // qDebug() << "PV" << pv.m_pvPath << "is part of VG" << pv.m_vgName << ", adding to VG info."; + // qCDebug(serviceLog) << "PV" << pv.m_pvPath << "is part of VG" << pv.m_vgName << ", adding to VG info."; lvmInfo.m_vgInfo[pv.m_vgName].m_pvInfo.insert(pv.m_pvPath, pv); } lvmInfo.m_pvInfo.insert(pv.m_pvPath, pv); @@ -274,14 +275,14 @@ bool LVMOperator::updatePVInfo(LVMInfo &lvmInfo) bool LVMOperator::updateVGInfo(LVMInfo &lvmInfo) { - qDebug() << "LVMOperator::updateVGInfo start"; + qCDebug(serviceLog) << "LVMOperator::updateVGInfo start"; if (m_lvmSupport.LVM_CMD_vgs == LVM_CMD_Support::NONE) { - qDebug() << "LVM_CMD_vgs not supported."; + qCDebug(serviceLog) << "LVM_CMD_vgs not supported."; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } //查看是否有重名vg存在 如果存在 将其中一个vg更换名称 if (!checkVG()) { - qDebug() << "VG already exists."; + qCDebug(serviceLog) << "VG already exists."; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_ALREADY_EXISTS); } @@ -293,7 +294,7 @@ bool LVMOperator::updateVGInfo(LVMInfo &lvmInfo) foreach (QString str, strout.split("\n")) { if (str.isEmpty()) { - // qDebug() << "VG UUID is empty. continue."; + // qCDebug(serviceLog) << "VG UUID is empty. continue."; continue; } @@ -336,9 +337,9 @@ bool LVMOperator::updateVGInfo(LVMInfo &lvmInfo) bool LVMOperator::updateLVInfo(LVMInfo &lvmInfo, VGInfo &vg) { - qDebug() << "LVMOperator::updateLVInfo start"; + qCDebug(serviceLog) << "LVMOperator::updateLVInfo start"; if (LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_lvs) { - qDebug() << "LVM_CMD_lvs not supported."; + qCDebug(serviceLog) << "LVM_CMD_lvs not supported."; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } @@ -350,7 +351,7 @@ bool LVMOperator::updateLVInfo(LVMInfo &lvmInfo, VGInfo &vg) strout = strout.trimmed(); foreach (QString str, strout.split("\n")) { if (str.isEmpty()) { - // qDebug() << "LV path is empty. continue."; + // qCDebug(serviceLog) << "LV path is empty. continue."; continue; } LVInfo lv; @@ -382,7 +383,7 @@ bool LVMOperator::updateLVInfo(LVMInfo &lvmInfo, VGInfo &vg) bool labelFound = false; QString label = DiskManager::FsInfo::getLabel(lvPath, labelFound); if (labelFound) { - // qDebug() << "LV label is found."; + // qCDebug(serviceLog) << "LV label is found."; lv.m_fileSystemLabel = label; } @@ -410,7 +411,7 @@ bool LVMOperator::updateLVInfo(LVMInfo &lvmInfo, VGInfo &vg) long long Size = vg.m_peUnused * vg.m_PESize; if (Size) { - qDebug() << "VG has unused space."; + qCDebug(serviceLog) << "VG has unused space."; LVInfo unallocLv; unallocLv.m_lvPath = "Unallocated"; unallocLv.m_vgName = vg.m_vgName; //vg名称 @@ -424,27 +425,27 @@ bool LVMOperator::updateLVInfo(LVMInfo &lvmInfo, VGInfo &vg) vg.m_lvlist.push_back(unallocLv); } - qDebug() << "LVMOperator::updateLVInfo end"; + qCDebug(serviceLog) << "LVMOperator::updateLVInfo end"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NORMAL); } /******************************** lvm操作 ******************************/ bool LVMOperator::createVG(LVMInfo &lvmInfo, QString vgName, QList devList, long long size) { - qDebug() << "LVMOperator::createVG start"; + qCDebug(serviceLog) << "LVMOperator::createVG start"; if (LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_vgcreate || LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_pvcreate) { - qWarning() << "Failed to create VG: required commands not supported"; + qCWarning(serviceLog) << "Failed to create VG: required commands not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } if (vgName.isEmpty() || vgName.count() >= 128 || devList.count() == 0 || size == 0) { - qWarning() << "Failed to create VG: invalid arguments"; + qCWarning(serviceLog) << "Failed to create VG: invalid arguments"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_ARGUMENT); } //判断vg是否已经存在 存在退出 if (lvmInfo.vgExists(vgName)) { - qWarning() << "Failed to create VG: VG already exists -" << vgName; + qCWarning(serviceLog) << "Failed to create VG: VG already exists -" << vgName; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_ALREADY_EXISTS); } //创建pv @@ -466,12 +467,12 @@ bool LVMOperator::createVG(LVMInfo &lvmInfo, QString vgName, QList devLi //创建vg int errCode = vgCreate(vgName, vgPV); if (errCode != 0) { - qWarning() << "Failed to create VG:" << vgName << "Error code:" << errCode; + qCWarning(serviceLog) << "Failed to create VG:" << vgName << "Error code:" << errCode; if (errCode == 3) { //之后可能出现的问题有 vg存在 输入输出设备错误 vg创建失败 - qWarning() << "VG already exists or input/output device error"; + qCWarning(serviceLog) << "VG already exists or input/output device error"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_ALREADY_EXISTS); } else { - qWarning() << "VG create failed"; + qCWarning(serviceLog) << "VG create failed"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_CREATE_FAILED); } } @@ -483,16 +484,16 @@ bool LVMOperator::createVG(LVMInfo &lvmInfo, QString vgName, QList devLi bool LVMOperator::deleteVG(LVMInfo &lvmInfo, QStringList vglist) { - qDebug() << "LVMOperator::deleteVG start"; + qCDebug(serviceLog) << "LVMOperator::deleteVG start"; if (LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_pvremove || LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_vgremove || LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_lvremove) { - qWarning() << "Failed to delete VG: required commands not supported"; + qCWarning(serviceLog) << "Failed to delete VG: required commands not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } foreach (const QString &vgName, vglist) { if (!lvmInfo.vgExists(vgName)) { //vg 不存在 报错返回 - qWarning() << "Failed to delete VG:" << vgName << "VG does not exist"; + qCWarning(serviceLog) << "Failed to delete VG:" << vgName << "VG does not exist"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_NO_EXISTS); } VGInfo vgInfo = lvmInfo.getVG(vgName); @@ -504,14 +505,14 @@ bool LVMOperator::deleteVG(LVMInfo &lvmInfo, QStringList vglist) } if (!lvRemove(lvmInfo, lvList)) { - qWarning() << "Failed to delete VG:" << vgName << "LV delete failed"; + qCWarning(serviceLog) << "Failed to delete VG:" << vgName << "LV delete failed"; return setLVMErr(lvmInfo, lvmInfo.m_lvmErr); } //删除vg int exitCode = vgRemove(vgInfo); if (exitCode != 0) { - qWarning() << "Failed to delete VG:" << vgName << "VG delete failed"; + qCWarning(serviceLog) << "Failed to delete VG:" << vgName << "VG delete failed"; return exitCode == 5 ? setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_IN_USED) : setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_DELETE_FAILED); } @@ -522,15 +523,15 @@ bool LVMOperator::deleteVG(LVMInfo &lvmInfo, QStringList vglist) } } } - qDebug() << "LVMOperator::deleteVG end"; + qCDebug(serviceLog) << "LVMOperator::deleteVG end"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NORMAL); } bool LVMOperator::resizeVG(LVMInfo &lvmInfo, QString vgName, QList devList, long long size) { - qDebug() << "LVMOperator::resizeVG start"; + qCDebug(serviceLog) << "LVMOperator::resizeVG start"; if (!lvmInfo.vgExists(vgName) || devList.size() <= 0 || size <= 0) { - qWarning() << "Failed to resize VG: invalid arguments"; + qCWarning(serviceLog) << "Failed to resize VG: invalid arguments"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_ARGUMENT); } if (LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_vgextend @@ -538,7 +539,7 @@ bool LVMOperator::resizeVG(LVMInfo &lvmInfo, QString vgName, QList devLi || LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_pvcreate || LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_pvremove || LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_pvmove) { - qWarning() << "Failed to resize VG: required commands not supported"; + qCWarning(serviceLog) << "Failed to resize VG: required commands not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } @@ -549,7 +550,7 @@ bool LVMOperator::resizeVG(LVMInfo &lvmInfo, QString vgName, QList devLi foreach (const PVData &pv, devList) { if (lvmInfo.pvOfVg(vgName, pv)) { //pv存在 且属于当前vg - // qDebug() << "PV already exists in VG:" << vgName; + // qCDebug(serviceLog) << "PV already exists in VG:" << vgName; oldPVlist.push_back(pv); continue; } @@ -564,18 +565,18 @@ bool LVMOperator::resizeVG(LVMInfo &lvmInfo, QString vgName, QList devLi if (!lvmInfo.pvExists(pv)) { //pv不存在 if (!pvCreate(pv.m_devicePath)) { - qWarning() << "Failed to resize VG: PV create failed"; + qCWarning(serviceLog) << "Failed to resize VG: PV create failed"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_PV_CREATE_FAILED); } } else { if (lvmInfo.getPV(pv).joinVG()) { //加入了其他vg - qWarning() << "Failed to resize VG: PV already exists in another VG"; + qCWarning(serviceLog) << "Failed to resize VG: PV already exists in another VG"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_ARGUMENT); } } //扩展vg if (!vgExtend(vgName, pv.m_devicePath)) { - qWarning() << "Failed to resize VG: PV extend failed"; + qCWarning(serviceLog) << "Failed to resize VG: PV extend failed"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_EXTEND_FAILED); } } @@ -594,28 +595,28 @@ bool LVMOperator::resizeVG(LVMInfo &lvmInfo, QString vgName, QList devLi updateLVMInfo(lvmInfo); - qDebug() << "LVMOperator::resizeVG end"; + qCDebug(serviceLog) << "LVMOperator::resizeVG end"; return deletePVList(lvmInfo, delPVList); } bool LVMOperator::createLV(LVMInfo &lvmInfo, QString vgName, QList lvList) { - qDebug() << "LVMOperator::createLV start"; + qCDebug(serviceLog) << "LVMOperator::createLV start"; if (LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_lvcreate) { - qWarning() << "Failed to create LV: lvcreate command not supported"; + qCWarning(serviceLog) << "Failed to create LV: lvcreate command not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } //判断参数是否正确 if (vgName.isEmpty() || lvList.count() == 0) { - qWarning() << "Failed to create LV: invalid arguments"; + qCWarning(serviceLog) << "Failed to create LV: invalid arguments"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_ARGUMENT); } //vg是否存在 auto vgIt = lvmInfo.m_vgInfo.find(vgName); if (lvmInfo.m_vgInfo.end() == vgIt) { - qWarning() << "Failed to create LV: VG does not exist"; + qCWarning(serviceLog) << "Failed to create LV: VG does not exist"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_NO_EXISTS); } @@ -649,45 +650,45 @@ bool LVMOperator::createLV(LVMInfo &lvmInfo, QString vgName, QList lvL } //更新lv数据 - qInfo() << "Creating LV in VG:" << vgName << "with size:" << lvList.first().m_lvByteSize; + qCInfo(serviceLog) << "Creating LV in VG:" << vgName << "with size:" << lvList.first().m_lvByteSize; updateLVInfo(lvmInfo, vg); - qInfo() << "Successfully created LV in VG:" << vgName; + qCInfo(serviceLog) << "Successfully created LV in VG:" << vgName; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NORMAL); } bool LVMOperator::lvRemove(LVMInfo &lvmInfo, QStringList lvlist) { - qDebug() << "LVMOperator::lvRemove start"; + qCDebug(serviceLog) << "LVMOperator::lvRemove start"; if (LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_lvremove) { - qWarning() << "Failed to remove LV: lvremove command not supported"; + qCWarning(serviceLog) << "Failed to remove LV: lvremove command not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } foreach (const QString &lvPath, lvlist) { int exitCode = lvRemove(lvPath); if (exitCode != 0) { - qWarning() << "Failed to remove LV:" << lvPath << "Exit code:" << exitCode; + qCWarning(serviceLog) << "Failed to remove LV:" << lvPath << "Exit code:" << exitCode; return exitCode == 5 ? setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_IN_USED) : setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_DELETE_FAILED); } } - qDebug() << "LVMOperator::lvRemove end"; + qCDebug(serviceLog) << "LVMOperator::lvRemove end"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NORMAL); } bool LVMOperator::resizeLV(LVMInfo &lvmInfo, LVAction &lvAct, LVInfo &info) { - qDebug() << "LVMOperator::resizeLV start"; + qCDebug(serviceLog) << "LVMOperator::resizeLV start"; if ((LVM_ACT_LV_EXTEND == lvAct.m_lvAct && LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_lvextend) || (LVM_ACT_LV_REDUCE == lvAct.m_lvAct && LVM_CMD_Support::NONE == m_lvmSupport.LVM_CMD_lvreduce) || FS_FAT16 == lvAct.m_lvFs || FS_FAT32 == lvAct.m_lvFs) { - qWarning() << "Failed to resize LV: lvextend or lvreduce command not supported"; + qCWarning(serviceLog) << "Failed to resize LV: lvextend or lvreduce command not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } FileSystem *fs = m_supportFs.getFsObject(lvAct.m_lvFs); if (fs == nullptr) { - qWarning() << "Failed to resize LV: file system not supported"; + qCWarning(serviceLog) << "Failed to resize LV: file system not supported"; if (lvAct.m_lvFs == FS_UNALLOCATED) { //文件系统不存在 可以直接扩大或缩小lv - qWarning() << "Failed to resize LV: file system not supported for resizing"; + qCWarning(serviceLog) << "Failed to resize LV: file system not supported for resizing"; return setLVMErr(lvmInfo, resizeLV(info.m_lvPath, lvAct) ? LVMError::LVM_ERR_NORMAL : (lvAct.m_lvAct == LVM_ACT_LV_EXTEND ? LVM_ERR_LV_EXTEND_FAILED : LVM_ERR_LV_REDUCE_FAILED)); } return setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_RESIZE_FS_NO_SUPPORT); //fs no support resize @@ -701,40 +702,40 @@ bool LVMOperator::resizeLV(LVMInfo &lvmInfo, LVAction &lvAct, LVInfo &info) if (lvAct.m_lvAct == LVM_ACT_LV_EXTEND) { //放大lv if (!resizeLV(info.m_lvPath, lvAct)) { - qWarning() << "Failed to resize LV: failed to extend LV"; + qCWarning(serviceLog) << "Failed to resize LV: failed to extend LV"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_EXTEND_FAILED); } //放大文件系统 if (!(fs->checkRepair(p) && fs->resize(p, true))) { - qWarning() << "Failed to resize LV: failed to resize file system"; + qCWarning(serviceLog) << "Failed to resize LV: failed to resize file system"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_EXTEND_FS_FAILED); } } else { //缩小文件系统后 if (!(fs->checkRepair(p) && fs->resize(p, false))) { - qWarning() << "Failed to resize LV: failed to resize file system"; + qCWarning(serviceLog) << "Failed to resize LV: failed to resize file system"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_EXTEND_FS_FAILED); } //缩小lv if (!resizeLV(info.m_lvPath, lvAct)) { - qWarning() << "Failed to resize LV: failed to reduce LV"; + qCWarning(serviceLog) << "Failed to resize LV: failed to reduce LV"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_EXTEND_FAILED); } //再次放大文件系统的原因是 进制单位不同 导致缩小后的文件系统跟设备大小不对等 所以再次扩大文件系统使得文件系统填充设备 if (!(fs->checkRepair(p) && fs->resize(p, true))) { - qWarning() << "Failed to resize LV: failed to resize file system"; + qCWarning(serviceLog) << "Failed to resize LV: failed to resize file system"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_LV_EXTEND_FAILED); } } - qDebug() << "LVMOperator::resizeLV end"; + qCDebug(serviceLog) << "LVMOperator::resizeLV end"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NORMAL); } bool LVMOperator::deletePVList(LVMInfo &lvmInfo, QList devList) { - qDebug() << "LVMOperator::deletePVList start"; + qCDebug(serviceLog) << "LVMOperator::deletePVList start"; if (devList.size() == 0) { - qWarning() << "Failed to delete PV: no PVs specified"; + qCWarning(serviceLog) << "Failed to delete PV: no PVs specified"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NORMAL); } @@ -754,7 +755,7 @@ bool LVMOperator::deletePVList(LVMInfo &lvmInfo, QList devList) } if (m_lvmSupport.LVM_CMD_pvremove == LVM_CMD_Support::NONE) { //命令不支持 - qWarning() << "Failed to delete PV: pvremove command not supported"; + qCWarning(serviceLog) << "Failed to delete PV: pvremove command not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } @@ -762,7 +763,7 @@ bool LVMOperator::deletePVList(LVMInfo &lvmInfo, QList devList) PVInfo info = lvmInfo.getPV(pv); if (info.joinVG()) { //加入vg if (!lvmInfo.vgExists(info)) { //vg是否存在 - qWarning() << "Failed to delete PV: VG does not exist"; + qCWarning(serviceLog) << "Failed to delete PV: VG does not exist"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_NO_EXISTS); } VGInfo vg = lvmInfo.getVG(info.m_vgName); @@ -774,35 +775,35 @@ bool LVMOperator::deletePVList(LVMInfo &lvmInfo, QList devList) //pv正常删除 //todo 此处可以优化算法 找出节省时间和移动最少的move方式 if (info.m_pvUsedPE > 0) { //pv存在被使用 移动pv if (m_lvmSupport.LVM_CMD_pvmove == LVM_CMD_Support::NONE) { //命令不支持 - qWarning() << "Failed to delete PV: pvmove command not supported"; + qCWarning(serviceLog) << "Failed to delete PV: pvmove command not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } if (!pvMove(info.m_pvPath)) { //移动失败 - qWarning() << "Failed to delete PV: failed to move PV"; + qCWarning(serviceLog) << "Failed to delete PV: failed to move PV"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_PV_MOVE_FAILED); } } //移除pv 在vg内 if (m_lvmSupport.LVM_CMD_vgreduce == LVM_CMD_Support::NONE) { //命令不支持 - qWarning() << "Failed to delete PV: vgreduce command not supported"; + qCWarning(serviceLog) << "Failed to delete PV: vgreduce command not supported"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NO_CMD_SUPPORT); } if (!vgReduce(info.m_vgName, info.m_pvPath)) { //移除pv失败 - qWarning() << "Failed to delete PV: failed to reduce VG"; + qCWarning(serviceLog) << "Failed to delete PV: failed to reduce VG"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_VG_REDUCE_FAILED); } } //删除pv if (!pvRemove(info.m_pvPath)) { - qWarning() << "Failed to delete PV: failed to remove PV"; + qCWarning(serviceLog) << "Failed to delete PV: failed to remove PV"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_PV_DELETE_FAILED); } } if (vgList.size()) { - qDebug() << "LVMOperator::deletePVList delete vgList" << vgList; + qCDebug(serviceLog) << "LVMOperator::deletePVList delete vgList" << vgList; #if QT_VERSION_MAJOR > 5 return deleteVG(lvmInfo, vgList.values()); #else @@ -810,21 +811,21 @@ bool LVMOperator::deletePVList(LVMInfo &lvmInfo, QList devList) #endif } - qDebug() << "LVMOperator::deletePVList end"; + qCDebug(serviceLog) << "LVMOperator::deletePVList end"; return setLVMErr(lvmInfo, LVMError::LVM_ERR_NORMAL); } /******************************** private lvm操作 ******************************/ int LVMOperator::vgCreate(const QString &vgName, const QStringList &pvList) { - // qDebug() << "LVMOperator::vgCreate vgName" << vgName << "pvList" << pvList; + // qCDebug(serviceLog) << "LVMOperator::vgCreate vgName" << vgName << "pvList" << pvList; QString strout, strerror; return Utils::executCmd(QString("vgcreate %1 %2 -y").arg(vgName).arg(pvList.join(" ")), strout, strerror); } int LVMOperator::vgRemove(const VGInfo &vgInfo) { - // qDebug() << "LVMOperator::vgRemove vgInfo" << vgInfo; + // qCDebug(serviceLog) << "LVMOperator::vgRemove vgInfo" << vgInfo; //删除vg QString strout, strerror; return Utils::executCmd(QString("vgremove %1 -y").arg(vgInfo.m_vgName), strout, strerror); //删除vg @@ -832,9 +833,9 @@ int LVMOperator::vgRemove(const VGInfo &vgInfo) bool LVMOperator::vgRename(const QString &uuid, const QString &newName) { - qDebug() << "LVMOperator::vgRename uuid" << uuid << "newName" << newName; + qCDebug(serviceLog) << "LVMOperator::vgRename uuid" << uuid << "newName" << newName; if (m_lvmSupport.LVM_CMD_vgrename == LVM_CMD_Support::NONE || uuid.isEmpty() || newName.isEmpty()) { - qWarning() << "Failed to rename VG: invalid arguments"; + qCWarning(serviceLog) << "Failed to rename VG: invalid arguments"; return false; } QString strout, strerror; @@ -843,21 +844,21 @@ bool LVMOperator::vgRename(const QString &uuid, const QString &newName) bool LVMOperator::vgReduce(const QString &vgName, const QString &pvPath) { - qDebug() << "LVMOperator::vgReduce vgName" << vgName << "pvPath" << pvPath; + qCDebug(serviceLog) << "LVMOperator::vgReduce vgName" << vgName << "pvPath" << pvPath; QString strout, strerror; return Utils::executCmd(QString("vgreduce %1 %2 -y").arg(vgName).arg(pvPath), strout, strerror) == 0; } bool LVMOperator::vgExtend(const QString &vgName, const QString &pvPath) { - qDebug() << "LVMOperator::vgExtend vgName" << vgName << "pvPath" << pvPath; + qCDebug(serviceLog) << "LVMOperator::vgExtend vgName" << vgName << "pvPath" << pvPath; QString strout, strerror; return Utils::executCmd(QString("vgextend %1 %2 -y").arg(vgName).arg(pvPath), strout, strerror) == 0; } bool LVMOperator::checkVG() { - qDebug() << "LVMOperator::checkVG"; + qCDebug(serviceLog) << "LVMOperator::checkVG"; struct VG { QString vgName; QString vgUuid; @@ -910,64 +911,64 @@ bool LVMOperator::checkVG() foreach (const VG &vg, renameVg) { vgRename(vg.vgUuid, vg.vgName); } - qDebug() << "LVMOperator::checkVG end"; + qCDebug(serviceLog) << "LVMOperator::checkVG end"; return true; } bool LVMOperator::pvCreate(const QString &devPath) { - qDebug() << "LVMOperator::pvCreate devPath" << devPath; + qCDebug(serviceLog) << "LVMOperator::pvCreate devPath" << devPath; QString strout, strerror; auto errCode = Utils::executCmd(QString("pvcreate %1 -y").arg(devPath), strout, strerror); - qInfo() << "pvcreate " << devPath << " output:" << strout << " error:" << strerror; + qCInfo(serviceLog) << "pvcreate " << devPath << " output:" << strout << " error:" << strerror; return errCode == 0; } bool LVMOperator::pvMove(const QString &pvPath, const QString &dest) { - qDebug() << "LVMOperator::pvMove pvPath" << pvPath << "dest" << dest; + qCDebug(serviceLog) << "LVMOperator::pvMove pvPath" << pvPath << "dest" << dest; QString strout, strerror; return Utils::executCmd(QString("pvmove %1 %2-y").arg(pvPath).arg(dest), strout, strerror) == 0; } bool LVMOperator::pvRemove(const QString &devPath) { - qDebug() << "LVMOperator::pvRemove devPath" << devPath; + qCDebug(serviceLog) << "LVMOperator::pvRemove devPath" << devPath; QString strout, strerror; return Utils::executCmd(QString("pvremove %1 -y").arg(devPath), strout, strerror) == 0; } bool LVMOperator::lvCreate(const QString &vgName, const QString &lvName, const long long &size) { - qDebug() << "LVMOperator::lvCreate vgName" << vgName << "lvName" << lvName << "size" << size; + qCDebug(serviceLog) << "LVMOperator::lvCreate vgName" << vgName << "lvName" << lvName << "size" << size; QString strout, strerror; return Utils::executCmd(QString("lvcreate -L %1b -n %2 %3 -y").arg(size).arg(lvName).arg(vgName), strout, strerror) == 0; } int LVMOperator::lvRemove(const QString &lvPath) { - qDebug() << "LVMOperator::lvRemove lvPath" << lvPath; + qCDebug(serviceLog) << "LVMOperator::lvRemove lvPath" << lvPath; if (DiskManager::MountInfo::getMountedMountpoints(lvPath).count() == 0) { - qDebug() << "LVMOperator::lvRemove lvPath" << lvPath << "not mounted"; + qCDebug(serviceLog) << "LVMOperator::lvRemove lvPath" << lvPath << "not mounted"; QString strout, strerror; return Utils::executCmd(QString("lvremove %1 -y").arg(lvPath), strout, strerror); } - qDebug() << "LVMOperator::lvRemove return 5"; + qCDebug(serviceLog) << "LVMOperator::lvRemove return 5"; return 5; //因为lvremove 删除一个挂载的lv时 返回的错误码是5 如果发现待删除的lv被挂载了,就返回5 与lvremove错误码保持一致 } bool LVMOperator::resizeLV(const QString &devPath, const LVAction &act) { - qDebug() << "LVMOperator::resizeLV devPath" << devPath << "act" << act.m_lvAct << "size" << act.m_lvByteSize; + qCDebug(serviceLog) << "LVMOperator::resizeLV devPath" << devPath << "act" << act.m_lvAct << "size" << act.m_lvByteSize; QString cmd, strout, strerr; if (LVM_ACT_LV_EXTEND == act.m_lvAct) { - qDebug() << "LVMOperator::resizeLV extend"; + qCDebug(serviceLog) << "LVMOperator::resizeLV extend"; cmd = "lvextend" ; } else if (LVM_ACT_LV_REDUCE == act.m_lvAct) { - qDebug() << "LVMOperator::resizeLV reduce"; + qCDebug(serviceLog) << "LVMOperator::resizeLV reduce"; cmd = "lvreduce" ; } else { - qDebug() << "LVMOperator::resizeLV act" << act.m_lvAct << "not support"; + qCDebug(serviceLog) << "LVMOperator::resizeLV act" << act.m_lvAct << "not support"; return false; } cmd += QString(" -f -y -L %1b %2").arg(act.m_lvByteSize).arg(devPath); @@ -978,209 +979,209 @@ bool LVMOperator::resizeLV(const QString &devPath, const LVAction &act) void LVMOperator::printError(const LVMError &error) { - qDebug() << "LVMOperator::printError error" << error; + qCDebug(serviceLog) << "LVMOperator::printError error" << error; switch (error) { case LVMError::LVM_ERR_NORMAL: - qDebug() << "LVM_ERR_NORMAL"; + qCDebug(serviceLog) << "LVM_ERR_NORMAL"; break; case LVMError::LVM_ERR_NO_CMD_SUPPORT: - qDebug() << "LVM_ERR_NO_CMD_SUPPORT"; + qCDebug(serviceLog) << "LVM_ERR_NO_CMD_SUPPORT"; break; case LVMError::LVM_ERR_PV: - qDebug() << "LVM_ERR_PV"; + qCDebug(serviceLog) << "LVM_ERR_PV"; break; case LVMError::LVM_ERR_PV_CREATE_FAILED: - qDebug() << "LVM_ERR_PV_CREATE_FAILED"; + qCDebug(serviceLog) << "LVM_ERR_PV_CREATE_FAILED"; break; case LVMError::LVM_ERR_PV_DELETE_FAILED: - qDebug() << "LVM_ERR_PV_DELETE_FAILED"; + qCDebug(serviceLog) << "LVM_ERR_PV_DELETE_FAILED"; break; case LVMError::LVM_ERR_LV: - qDebug() << "LVM_ERR_LV"; + qCDebug(serviceLog) << "LVM_ERR_LV"; break; case LVMError::LVM_ERR_LV_CREATE_FAILED: - qDebug() << "LVM_ERR_LV_CREATE_FAILED"; + qCDebug(serviceLog) << "LVM_ERR_LV_CREATE_FAILED"; break; case LVMError::LVM_ERR_LV_ARGUMENT: - qDebug() << "LVM_ERR_LV_ARGUMENT"; + qCDebug(serviceLog) << "LVM_ERR_LV_ARGUMENT"; break; case LVMError::LVM_ERR_LV_NO_EXISTS: - qDebug() << "LVM_ERR_LV_NO_EXISTS"; + qCDebug(serviceLog) << "LVM_ERR_LV_NO_EXISTS"; break; case LVMError::LVM_ERR_LV_DELETE_FAILED: - qDebug() << "LVM_ERR_LV_DELETE_FAILED"; + qCDebug(serviceLog) << "LVM_ERR_LV_DELETE_FAILED"; break; case LVMError::LVM_ERR_VG: - qDebug() << "LVM_ERR_VG"; + qCDebug(serviceLog) << "LVM_ERR_VG"; break; case LVMError::LVM_ERR_VG_CREATE_FAILED: - qDebug() << "LVM_ERR_VG_CREATE_FAILED"; + qCDebug(serviceLog) << "LVM_ERR_VG_CREATE_FAILED"; break; case LVMError::LVM_ERR_VG_ARGUMENT: - qDebug() << "LVM_ERR_VG_ARGUMENT"; + qCDebug(serviceLog) << "LVM_ERR_VG_ARGUMENT"; break; case LVMError::LVM_ERR_VG_NO_EXISTS: - qDebug() << "LVM_ERR_VG_NO_EXISTS"; + qCDebug(serviceLog) << "LVM_ERR_VG_NO_EXISTS"; break; case LVMError::LVM_ERR_VG_ALREADY_EXISTS: - qDebug() << "LVM_ERR_VG_ALREADY_EXISTS"; + qCDebug(serviceLog) << "LVM_ERR_VG_ALREADY_EXISTS"; break; case LVMError::LVM_ERR_VG_DELETE_FAILED: - qDebug() << "LVM_ERR_VG_DELETE_FAILED"; + qCDebug(serviceLog) << "LVM_ERR_VG_DELETE_FAILED"; break; default: - qDebug() << "LVMError default"; + qCDebug(serviceLog) << "LVMError default"; } } void LVMOperator::printLVMInfo(const LVMInfo &lvmInfo) { - qDebug() << "**********************************************************************"; - qDebug() << QString("LVMVGINFO:====================================being"); + qCDebug(serviceLog) << "**********************************************************************"; + qCDebug(serviceLog) << QString("LVMVGINFO:====================================being"); foreach (auto it, lvmInfo.m_vgInfo) { printVGInfo(it); } - qDebug() << QString("LVMVGINFO:====================================end"); - qDebug() << "**********************************************************************"; + qCDebug(serviceLog) << QString("LVMVGINFO:====================================end"); + qCDebug(serviceLog) << "**********************************************************************"; - qDebug() << QString("LVMPVINFO:====================================being"); + qCDebug(serviceLog) << QString("LVMPVINFO:====================================being"); foreach (auto it, lvmInfo.m_pvInfo) { printPVInfo(it); } - qDebug() << QString("LVMPVINFO:====================================end"); - qDebug() << "**********************************************************************"; + qCDebug(serviceLog) << QString("LVMPVINFO:====================================end"); + qCDebug(serviceLog) << "**********************************************************************"; } void LVMOperator::printDeviceLVMData(const DeviceInfoMap &dev) { auto printVGData = [ = ](const VGData & vg) { - qDebug() << "vgName" << vg.m_vgName; - qDebug() << "vgSize" << vg.m_vgSize; - qDebug() << "m_vgUuid" << vg.m_vgUuid; - qDebug() << "vgByteSize" << vg.m_vgByteSize; + qCDebug(serviceLog) << "vgName" << vg.m_vgName; + qCDebug(serviceLog) << "vgSize" << vg.m_vgSize; + qCDebug(serviceLog) << "m_vgUuid" << vg.m_vgUuid; + qCDebug(serviceLog) << "vgByteSize" << vg.m_vgByteSize; foreach (auto lvIt, vg.m_lvList) { - qDebug() << ""; - qDebug() << "lvName" << lvIt.m_lvName; - qDebug() << "lvPath" << lvIt.m_lvPath; - qDebug() << "lvSize" << lvIt.m_lvSize; - qDebug() << "lvByteSize" << lvIt.m_lvByteSize; - qDebug() << ""; + qCDebug(serviceLog) << ""; + qCDebug(serviceLog) << "lvName" << lvIt.m_lvName; + qCDebug(serviceLog) << "lvPath" << lvIt.m_lvPath; + qCDebug(serviceLog) << "lvSize" << lvIt.m_lvSize; + qCDebug(serviceLog) << "lvByteSize" << lvIt.m_lvByteSize; + qCDebug(serviceLog) << ""; } }; - qDebug() << "**********************************************************************"; + qCDebug(serviceLog) << "**********************************************************************"; foreach (auto it, dev) { if (it.m_vgFlag == LVMFlag::LVM_FLAG_JOIN_VG) { - qDebug() << QString("dev disk %1 LVMData:====================================being").arg(it.m_path); - qDebug() << "vgData COUNT:" << it.m_vglist.count(); + qCDebug(serviceLog) << QString("dev disk %1 LVMData:====================================being").arg(it.m_path); + qCDebug(serviceLog) << "vgData COUNT:" << it.m_vglist.count(); foreach (auto vgIt, it.m_vglist) { printVGData(vgIt); } - qDebug() << QString("dev disk %1 LVMData:====================================end").arg(it.m_path); + qCDebug(serviceLog) << QString("dev disk %1 LVMData:====================================end").arg(it.m_path); } foreach (auto it2, it.m_partition) { if (it2.m_vgFlag) { - qDebug() << QString("dev part %1 LVMData:====================================being").arg(it2.m_path); + qCDebug(serviceLog) << QString("dev part %1 LVMData:====================================being").arg(it2.m_path); printVGData(it2.m_vgData); - qDebug() << QString("dev part %1 LVMData:====================================end").arg(it2.m_path); + qCDebug(serviceLog) << QString("dev part %1 LVMData:====================================end").arg(it2.m_path); } } } - qDebug() << "**********************************************************************"; + qCDebug(serviceLog) << "**********************************************************************"; } void LVMOperator::printPVInfo(const PVInfo &info) { - qDebug() << "PVInfo:====================================being"; - qDebug() << "vg_name: " << info.m_vgName; - qDebug() << "pvFmt: " << info.m_pvFmt; //pv格式 lvm1 lvm2 - qDebug() << "pvPath: " << info.m_pvPath; //pv路径 /dev/sdb1 ... - qDebug() << "pvUuid: " << info.m_pvUuid; //pv uuid 唯一名称 - qDebug() << "pvMdaSize: " << info.m_pvMdaSize; //pv metadata size - qDebug() << "pvMdaCount: " << info.m_pvMdaCount; //pv metadata 个数 - qDebug() << "pvSize: " << info.m_pvSize; //字符串类型 展示用 - qDebug() << "pvFree: " << info.m_pvFree; //字符串类型 展示用 - qDebug() << "pvUsedPE: " << info.m_pvUsedPE; //已经使用pe个数 - qDebug() << "pvUnusedPE: " << info.m_pvUnusedPE; //未使用pe个数 - qDebug() << "PESize: " << info.m_PESize; //单个pe大小 - qDebug() << "pvStatus: " << info.m_pvStatus; //状态 - qDebug() << "pvError: " << info.m_pvError; //物理卷错误码 + qCDebug(serviceLog) << "PVInfo:====================================being"; + qCDebug(serviceLog) << "vg_name: " << info.m_vgName; + qCDebug(serviceLog) << "pvFmt: " << info.m_pvFmt; //pv格式 lvm1 lvm2 + qCDebug(serviceLog) << "pvPath: " << info.m_pvPath; //pv路径 /dev/sdb1 ... + qCDebug(serviceLog) << "pvUuid: " << info.m_pvUuid; //pv uuid 唯一名称 + qCDebug(serviceLog) << "pvMdaSize: " << info.m_pvMdaSize; //pv metadata size + qCDebug(serviceLog) << "pvMdaCount: " << info.m_pvMdaCount; //pv metadata 个数 + qCDebug(serviceLog) << "pvSize: " << info.m_pvSize; //字符串类型 展示用 + qCDebug(serviceLog) << "pvFree: " << info.m_pvFree; //字符串类型 展示用 + qCDebug(serviceLog) << "pvUsedPE: " << info.m_pvUsedPE; //已经使用pe个数 + qCDebug(serviceLog) << "pvUnusedPE: " << info.m_pvUnusedPE; //未使用pe个数 + qCDebug(serviceLog) << "PESize: " << info.m_PESize; //单个pe大小 + qCDebug(serviceLog) << "pvStatus: " << info.m_pvStatus; //状态 + qCDebug(serviceLog) << "pvError: " << info.m_pvError; //物理卷错误码 for (auto it = info.m_lvRangesList.begin(); it != info.m_lvRangesList.end(); ++it) { //lv pv分布情况 vgName foreach (const LV_PV_Ranges &tmp, it.value()) { - qDebug() << ""; - qDebug() << "lvName :" << tmp.m_lvName; - qDebug() << "lv path:" << tmp.m_devPath ; - qDebug() << "lv start:" << tmp.m_start ; - qDebug() << "lv end:" << tmp.m_end ; - qDebug() << ""; + qCDebug(serviceLog) << ""; + qCDebug(serviceLog) << "lvName :" << tmp.m_lvName; + qCDebug(serviceLog) << "lv path:" << tmp.m_devPath ; + qCDebug(serviceLog) << "lv start:" << tmp.m_start ; + qCDebug(serviceLog) << "lv end:" << tmp.m_end ; + qCDebug(serviceLog) << ""; } } foreach (const VG_PV_Ranges &tmp, info.m_vgRangesList) { //vg pv分布情况 - qDebug() << ""; - qDebug() << "vgName :" << tmp.m_vgName; - qDebug() << "vg used:" << tmp.m_used ; - qDebug() << "vg start:" << tmp.m_start ; - qDebug() << "vg end:" << tmp.m_end ; - qDebug() << ""; + qCDebug(serviceLog) << ""; + qCDebug(serviceLog) << "vgName :" << tmp.m_vgName; + qCDebug(serviceLog) << "vg used:" << tmp.m_used ; + qCDebug(serviceLog) << "vg start:" << tmp.m_start ; + qCDebug(serviceLog) << "vg end:" << tmp.m_end ; + qCDebug(serviceLog) << ""; } - qDebug() << "lvmDevType: " << info.m_lvmDevType; //lvm 设备类型 - qDebug() << "pvByteTotalSize: " << info.m_pvByteTotalSize;//pv总大小 单位byte - qDebug() << "pvByteFreeSize: " << info.m_pvByteFreeSize;//pv未使用大小 单位byte - qDebug() << "PVInfo:====================================end"; + qCDebug(serviceLog) << "lvmDevType: " << info.m_lvmDevType; //lvm 设备类型 + qCDebug(serviceLog) << "pvByteTotalSize: " << info.m_pvByteTotalSize;//pv总大小 单位byte + qCDebug(serviceLog) << "pvByteFreeSize: " << info.m_pvByteFreeSize;//pv未使用大小 单位byte + qCDebug(serviceLog) << "PVInfo:====================================end"; } void LVMOperator::printVGInfo(const VGInfo &info) { - qDebug() << "VGInfo:====================================being"; - qDebug() << "vgName: " << info.m_vgName; //vg名称 vg0, vg1 .... - qDebug() << "vgUuid: " << info.m_vgUuid; //vg唯一名称 uuid - qDebug() << "vgSize: " << info.m_vgSize; //字符串类型 展示用 vg总大小 - qDebug() << "vgUsed: " << info.m_vgUsed; //字符串类型 展示用 vg使用 - qDebug() << "vgUnused: " << info.m_vgUnused; //字符串类型 展示用 vg已用 - qDebug() << "pvCount: " << info.m_pvCount; //物理卷个数 - qDebug() << "peCount: " << info.m_peCount; //pe个数 - qDebug() << "peUsed: " << info.m_peUsed; //pe使用个数 - qDebug() << "peUnused: " << info.m_peUnused; //pe未使用个数 - qDebug() << "PESize: " << info.m_PESize; //单个pe大小 - qDebug() << "curLV: " << info.m_curLV; //当前lv个数 - qDebug() << "vgStatus: " << QString(info.m_vgStatus); //状态 - qDebug() << "vgError: " << info.m_vgError; //逻辑卷组错误码 + qCDebug(serviceLog) << "VGInfo:====================================being"; + qCDebug(serviceLog) << "vgName: " << info.m_vgName; //vg名称 vg0, vg1 .... + qCDebug(serviceLog) << "vgUuid: " << info.m_vgUuid; //vg唯一名称 uuid + qCDebug(serviceLog) << "vgSize: " << info.m_vgSize; //字符串类型 展示用 vg总大小 + qCDebug(serviceLog) << "vgUsed: " << info.m_vgUsed; //字符串类型 展示用 vg使用 + qCDebug(serviceLog) << "vgUnused: " << info.m_vgUnused; //字符串类型 展示用 vg已用 + qCDebug(serviceLog) << "pvCount: " << info.m_pvCount; //物理卷个数 + qCDebug(serviceLog) << "peCount: " << info.m_peCount; //pe个数 + qCDebug(serviceLog) << "peUsed: " << info.m_peUsed; //pe使用个数 + qCDebug(serviceLog) << "peUnused: " << info.m_peUnused; //pe未使用个数 + qCDebug(serviceLog) << "PESize: " << info.m_PESize; //单个pe大小 + qCDebug(serviceLog) << "curLV: " << info.m_curLV; //当前lv个数 + qCDebug(serviceLog) << "vgStatus: " << QString(info.m_vgStatus); //状态 + qCDebug(serviceLog) << "vgError: " << info.m_vgError; //逻辑卷组错误码 foreach (auto it, info.m_lvlist) { printLVInfo(it); } - qDebug() << "pvList: " << info.m_pvInfo.keys(); //逻辑卷pv - qDebug() << "VGInfo:====================================end"; + qCDebug(serviceLog) << "pvList: " << info.m_pvInfo.keys(); //逻辑卷pv + qCDebug(serviceLog) << "VGInfo:====================================end"; } void LVMOperator::printLVInfo(const LVInfo &info) { - qDebug() << "LVInfo:====================================being"; - qDebug() << "vgName: " << info.m_vgName; //vg名称 - qDebug() << "lvPath: " << info.m_lvPath; //lv路径 - qDebug() << "lvUuid: " << info.m_lvUuid; //lv uuid 唯一名称 - qDebug() << "lvName: " << info.m_lvName; //lv名称 lv0 lv1 .... - qDebug() << "lvFsType: " << Utils::fileSystemTypeToString(info.m_lvFsType); //文件系统类型 - qDebug() << "lvSize: " << info.m_lvSize; //字符串类型 展示用 - qDebug() << "lvLECount: " << info.m_lvLECount; //le个数 - qDebug() << "fsUsed: " << info.m_fsUsed; //文件已经使用大小 - qDebug() << "fsUnused: " << info.m_fsUnused; //文件未使用大小 - qDebug() << "LESize: " << info.m_LESize; //单个pe大小 与所在vg的pe大小相同 - qDebug() << "busy: " << info.m_busy; //挂载标志 - qDebug() << "mountpoints: " << info.m_mountPoints; - qDebug() << "lvStatus: " << QString(info.m_lvStatus); - qDebug() << "lvError: " << info.m_lvError; //逻辑卷错误码 - qDebug() << "mountUuid: " << info.m_mountUuid;//逻辑卷挂载uuid - qDebug() << "fsLimits_min_size: " << info.m_fsLimits.min_size; - qDebug() << "fsLimits_max_size: " << info.m_fsLimits.max_size; - qDebug() << "luksFlag: " << info.m_luksFlag; - qDebug() << "fileSystemLabel: " << info.m_fileSystemLabel; - qDebug() << "LVInfo:====================================end"; + qCDebug(serviceLog) << "LVInfo:====================================being"; + qCDebug(serviceLog) << "vgName: " << info.m_vgName; //vg名称 + qCDebug(serviceLog) << "lvPath: " << info.m_lvPath; //lv路径 + qCDebug(serviceLog) << "lvUuid: " << info.m_lvUuid; //lv uuid 唯一名称 + qCDebug(serviceLog) << "lvName: " << info.m_lvName; //lv名称 lv0 lv1 .... + qCDebug(serviceLog) << "lvFsType: " << Utils::fileSystemTypeToString(info.m_lvFsType); //文件系统类型 + qCDebug(serviceLog) << "lvSize: " << info.m_lvSize; //字符串类型 展示用 + qCDebug(serviceLog) << "lvLECount: " << info.m_lvLECount; //le个数 + qCDebug(serviceLog) << "fsUsed: " << info.m_fsUsed; //文件已经使用大小 + qCDebug(serviceLog) << "fsUnused: " << info.m_fsUnused; //文件未使用大小 + qCDebug(serviceLog) << "LESize: " << info.m_LESize; //单个pe大小 与所在vg的pe大小相同 + qCDebug(serviceLog) << "busy: " << info.m_busy; //挂载标志 + qCDebug(serviceLog) << "mountpoints: " << info.m_mountPoints; + qCDebug(serviceLog) << "lvStatus: " << QString(info.m_lvStatus); + qCDebug(serviceLog) << "lvError: " << info.m_lvError; //逻辑卷错误码 + qCDebug(serviceLog) << "mountUuid: " << info.m_mountUuid;//逻辑卷挂载uuid + qCDebug(serviceLog) << "fsLimits_min_size: " << info.m_fsLimits.min_size; + qCDebug(serviceLog) << "fsLimits_max_size: " << info.m_fsLimits.max_size; + qCDebug(serviceLog) << "luksFlag: " << info.m_luksFlag; + qCDebug(serviceLog) << "fileSystemLabel: " << info.m_fileSystemLabel; + qCDebug(serviceLog) << "LVInfo:====================================end"; } diff --git a/service/diskoperation/mountinfo.cpp b/service/diskoperation/mountinfo.cpp index f2d6e0fa..8f019d7e 100644 --- a/service/diskoperation/mountinfo.cpp +++ b/service/diskoperation/mountinfo.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 "mountinfo.h" #include "utils.h" #include "fsinfo.h" @@ -20,7 +21,7 @@ static MountInfo::MountMapping fstabInfo; void MountInfo::loadCache(QString &rootFs) { - qDebug() << "MountInfo::loadCache called."; + qCDebug(serviceLog) << "MountInfo::loadCache called."; mountInfo.clear(); fstabInfo.clear(); @@ -28,7 +29,7 @@ void MountInfo::loadCache(QString &rootFs) readMountpointsFromFileSwaps("/proc/swaps", mountInfo); if (!haveRootfsDev(mountInfo)) { - qDebug() << "Rootfs device not found in /proc/mounts, falling back to mount command."; + qCDebug(serviceLog) << "Rootfs device not found in /proc/mounts, falling back to mount command."; // Old distributions only contain 'rootfs' and '/dev/root' device names // for the / (root) file system in /proc/mounts with '/dev/root' being a // block device rather than a symlink to the true device. This prevents @@ -47,7 +48,7 @@ void MountInfo::loadCache(QString &rootFs) // Sort the mount points and remove duplicates ... (no need to do this for fstab_info) MountMapping::iterator iterMp; for (iterMp = mountInfo.begin(); iterMp != mountInfo.end(); ++iterMp) { - qDebug() << "Sorting and removing duplicate mountpoints for device:" << iterMp.key().m_name; + qCDebug(serviceLog) << "Sorting and removing duplicate mountpoints for device:" << iterMp.key().m_name; std::sort(iterMp.value().mountpoints.begin(), iterMp.value().mountpoints.end()); iterMp.value().mountpoints.erase( @@ -58,85 +59,85 @@ void MountInfo::loadCache(QString &rootFs) bool MountInfo::isDevMounted(const QString &path) { - qDebug() << "MountInfo::isDevMounted called for path:" << path; + qCDebug(serviceLog) << "MountInfo::isDevMounted called for path:" << path; return isDevMounted(BlockSpecial(path)); } bool MountInfo::isDevMounted(const BlockSpecial &blockSpecial) { - qDebug() << "MountInfo::isDevMounted called for BlockSpecial:" << blockSpecial.m_name; + qCDebug(serviceLog) << "MountInfo::isDevMounted called for BlockSpecial:" << blockSpecial.m_name; MountMapping::const_iterator iterMp = mountInfo.find(blockSpecial); bool isMounted = iterMp != mountInfo.end(); - qDebug() << "Device" << blockSpecial.m_name << "is mounted:" << isMounted; + qCDebug(serviceLog) << "Device" << blockSpecial.m_name << "is mounted:" << isMounted; return isMounted; } bool MountInfo::isDevMountedReadonly(const QString &path) { - qDebug() << "MountInfo::isDevMountedReadonly called for path:" << path; + qCDebug(serviceLog) << "MountInfo::isDevMountedReadonly called for path:" << path; return isDevMountedReadonly(BlockSpecial(path)); } bool MountInfo::isDevMountedReadonly(const BlockSpecial &blockSpecial) { - qDebug() << "MountInfo::isDevMountedReadonly called for BlockSpecial:" << blockSpecial.m_name; + qCDebug(serviceLog) << "MountInfo::isDevMountedReadonly called for BlockSpecial:" << blockSpecial.m_name; MountMapping::const_iterator iterMp = mountInfo.find(blockSpecial); if (iterMp == mountInfo.end()) { - qDebug() << "Device not found in mount info."; + qCDebug(serviceLog) << "Device not found in mount info."; return false; } - qDebug() << "Device" << blockSpecial.m_name << "is readonly:" << iterMp.value().readonly; + qCDebug(serviceLog) << "Device" << blockSpecial.m_name << "is readonly:" << iterMp.value().readonly; return iterMp.value().readonly; } const QVector &MountInfo::getMountedMountpoints(const QString &path) { - qDebug() << "MountInfo::getMountedMountpoints called for path:" << path; + qCDebug(serviceLog) << "MountInfo::getMountedMountpoints called for path:" << path; return find(mountInfo, path).mountpoints; } const QVector &MountInfo::getFileSystemTableMountpoints(const QString &path) { - qDebug() << "MountInfo::getFileSystemTableMountpoints called for path:" << path; + qCDebug(serviceLog) << "MountInfo::getFileSystemTableMountpoints called for path:" << path; return find(fstabInfo, path).mountpoints; } void MountInfo::readMountpointsFromFile(const QString &fileName, MountInfo::MountMapping &map, QString &rootFs) { - qDebug() << "MountInfo::readMountpointsFromFile called for file:" << fileName; + qCDebug(serviceLog) << "MountInfo::readMountpointsFromFile called for file:" << fileName; FILE *fp = setmntent(fileName.toStdString().c_str(), "r"); if (fp == nullptr) { - qDebug() << "Failed to open" << fileName; + qCDebug(serviceLog) << "Failed to open" << fileName; return; } struct mntent *p = nullptr; while ((p = getmntent(fp)) != nullptr) { QString node = p->mnt_fsname; QString mountpoint = p->mnt_dir; - qDebug() << "Processing mount entry: dir=" << p->mnt_dir << ", FsName=" << p->mnt_fsname; + qCDebug(serviceLog) << "Processing mount entry: dir=" << p->mnt_dir << ", FsName=" << p->mnt_fsname; if (0 == rootFs.length() && (0 == strcmp(p->mnt_dir, "/root") || 0 == strcmp(p->mnt_dir, "/home") || 0 == strcmp(p->mnt_dir, "/opt") || 0 == strcmp(p->mnt_dir, "/var"))) { rootFs = p->mnt_fsname; - qDebug() <<"Set RootFS:" << rootFs; + qCDebug(serviceLog) <<"Set RootFS:" << rootFs; } QString uuid = Utils::regexpLabel(node, "(?<=UUID\\=).*"); if (!uuid.isEmpty()) { - qDebug() << "Found UUID in node, resolving path:" << uuid; + qCDebug(serviceLog) << "Found UUID in node, resolving path:" << uuid; node = FsInfo::getPathByUuid(uuid); } QString label = Utils::regexpLabel(node, "(?<=LABEL\\=).*"); if (!label.isEmpty()) { - qDebug() << "Found LABEL in node, resolving path:" << label; + qCDebug(serviceLog) << "Found LABEL in node, resolving path:" << label; node = FsInfo::getPathByLabel(label); } if (!node.isEmpty()) { - qDebug() << "Adding mountpoint entry for node:" << node << "mountpoint:" << mountpoint; + qCDebug(serviceLog) << "Adding mountpoint entry for node:" << node << "mountpoint:" << mountpoint; addMountpointEntry(map, node, mountpoint, parseReadonlyFlag(p->mnt_opts)); } } @@ -146,11 +147,11 @@ void MountInfo::readMountpointsFromFile(const QString &fileName, MountInfo::Moun void MountInfo::addMountpointEntry(MountInfo::MountMapping &map, QString &node, QString &mountPoint, bool readonly) { - qDebug() << "MountInfo::addMountpointEntry called for node:" << node << "mountPoint:" << mountPoint << "readonly:" << readonly; + qCDebug(serviceLog) << "MountInfo::addMountpointEntry called for node:" << node << "mountPoint:" << mountPoint << "readonly:" << readonly; // Only add node path if mount point exists QFile file(mountPoint); if (file.exists()) { - qDebug() << "Mountpoint" << mountPoint << "exists, adding to map."; + qCDebug(serviceLog) << "Mountpoint" << mountPoint << "exists, adding to map."; // Map::operator[] default constructs MountEntry for new keys (nodes). MountEntry &mountentry = map[BlockSpecial(node)]; mountentry.readonly = mountentry.readonly || readonly; @@ -160,36 +161,36 @@ void MountInfo::addMountpointEntry(MountInfo::MountMapping &map, QString &node, bool MountInfo::parseReadonlyFlag(const QString &str) { - qDebug() << "MountInfo::parseReadonlyFlag called for options string:" << str; + qCDebug(serviceLog) << "MountInfo::parseReadonlyFlag called for options string:" << str; QStringList mntopts = str.split(","); for (int i = 0; i < mntopts.size(); i++) { if (mntopts[i] == "rw") { - qDebug() << "Found 'rw' option, returning false (not readonly)."; + qCDebug(serviceLog) << "Found 'rw' option, returning false (not readonly)."; return false; } else if (mntopts[i] == "ro") { - qDebug() << "Found 'ro' option, returning true (readonly)."; + qCDebug(serviceLog) << "Found 'ro' option, returning true (readonly)."; return true; } } - qDebug() << "No 'ro' or 'rw' option found, defaulting to false (not readonly)."; + qCDebug(serviceLog) << "No 'ro' or 'rw' option found, defaulting to false (not readonly)."; return false; // Default is read-write mount } void MountInfo::readMountpointsFromFileSwaps(const QString &fileName, MountInfo::MountMapping &map) { - qDebug() << "MountInfo::readMountpointsFromFileSwaps called for file:" << fileName; + qCDebug(serviceLog) << "MountInfo::readMountpointsFromFileSwaps called for file:" << fileName; QFile file(fileName); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); QString line = in.readLine(); QString node; while (!in.atEnd() || !line.isEmpty()) { - // qDebug() << "Processing swap line:" << line; + // qCDebug(serviceLog) << "Processing swap line:" << line; node = Utils::regexpLabel(line, "^(/[^ ]+)"); if (node.size() > 0) { - // qDebug() << "Found swap device:" << node; + // qCDebug(serviceLog) << "Found swap device:" << node; map[BlockSpecial(node)].mountpoints.push_back("" /* no mountpoint for swap */); } line = in.readLine(); @@ -199,36 +200,36 @@ void MountInfo::readMountpointsFromFileSwaps(const QString &fileName, MountInfo: bool MountInfo::haveRootfsDev(MountInfo::MountMapping &) { - qDebug() << "MountInfo::haveRootfsDev called."; + qCDebug(serviceLog) << "MountInfo::haveRootfsDev called."; MountMapping::const_iterator iterMp; for (iterMp = mountInfo.begin(); iterMp != mountInfo.end(); iterMp++) { if (!iterMp.value().mountpoints.isEmpty() && iterMp.value().mountpoints[0] == "/") { - // qDebug() << "Found root mountpoint for device:" << iterMp.key().m_name; + // qCDebug(serviceLog) << "Found root mountpoint for device:" << iterMp.key().m_name; if (iterMp.key().m_name != "rootfs" && iterMp.key().m_name != "/dev/root") { - // qDebug() << "Device is not 'rootfs' or '/dev/root', returning true."; + // qCDebug(serviceLog) << "Device is not 'rootfs' or '/dev/root', returning true."; return true; } } } - qDebug() << "No suitable rootfs device found, returning false."; + qCDebug(serviceLog) << "No suitable rootfs device found, returning false."; return false; } void MountInfo::readMountpointsFromMountCommand(MountInfo::MountMapping &map) { - qDebug() << "MountInfo::readMountpointsFromMountCommand called."; + qCDebug(serviceLog) << "MountInfo::readMountpointsFromMountCommand called."; QString output; QString error; if (!Utils::executCmd("mount", output, error)) { QStringList lines; lines = output.split("\n"); for (int i = 0; i < lines.size(); i++) { - // qDebug() << "Processing mount command output line:" << lines[i]; + // qCDebug(serviceLog) << "Processing mount command output line:" << lines[i]; // Process line like "/dev/sda3 on / type ext4 (rw)" QString node = Utils::regexpLabel(lines[i], ".*?(?= )"); QString mountpoint = Utils::regexpLabel(lines[i], "(?<=on ).*?(?= type)"); QString mntopts = Utils::regexpLabel(lines[i], "(?<=\\().*?(?=\\))"); - // qDebug() << node << mountpoint << mntopts; + // qCDebug(serviceLog) << node << mountpoint << mntopts; if (!node.isEmpty()) { addMountpointEntry(map, node, mountpoint, parseReadonlyFlag(mntopts)); } @@ -238,15 +239,15 @@ void MountInfo::readMountpointsFromMountCommand(MountInfo::MountMapping &map) const MountEntry &MountInfo::find(const MountInfo::MountMapping &map, const QString &path) { - // qDebug() << "MountInfo::find called for path:" << path; + // qCDebug(serviceLog) << "MountInfo::find called for path:" << path; MountMapping::const_iterator iterMp = map.find(BlockSpecial(path)); if (iterMp != map.end()) { - // qDebug() << "Found entry for path:" << path; + // qCDebug(serviceLog) << "Found entry for path:" << path; return iterMp.value(); } - // qDebug() << "No entry found for path:" << path << ", returning static not_mounted."; + // qCDebug(serviceLog) << "No entry found for path:" << path << ", returning static not_mounted."; static MountEntry not_mounted = MountEntry(); return not_mounted; } diff --git a/service/diskoperation/partedcore.cpp b/service/diskoperation/partedcore.cpp index 94f99af8..517ddfd7 100644 --- a/service/diskoperation/partedcore.cpp +++ b/service/diskoperation/partedcore.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 "gpt_header.h" #include "partedcore.h" #include "fsinfo.h" @@ -97,41 +98,41 @@ PartedCore::~PartedCore() /***********************************************public DBUS****************************************************************/ DeviceInfo PartedCore::getDeviceinfo() { - qDebug() << "PartedCore::getDeviceinfo called"; + qCDebug(serviceLog) << "PartedCore::getDeviceinfo called"; DeviceInfo info; return info; } DeviceInfoMap PartedCore::getAllDeviceinfo() { - qDebug() << "PartedCore::getAllDeviceinfo called"; + qCDebug(serviceLog) << "PartedCore::getAllDeviceinfo called"; return m_inforesult; } LVMInfo PartedCore::getAllLVMinfo() { - qDebug() << "PartedCore::getAllLVMinfo called"; + qCDebug(serviceLog) << "PartedCore::getAllLVMinfo called"; return m_lvmInfo; } LUKSMap PartedCore::getAllLUKSinfo() { - qDebug() << "PartedCore::getAllLUKSinfo called"; + qCDebug(serviceLog) << "PartedCore::getAllLUKSinfo called"; return m_LUKSInfo; } QStringList PartedCore::getallsupportfs() { - qDebug() << "PartedCore::getallsupportfs called"; + qCDebug(serviceLog) << "PartedCore::getallsupportfs called"; return supportedFSInstance()->getAllFsName(); } HardDiskInfo PartedCore::getDeviceHardInfo(const QString &devicepath) { - // qDebug() << __FUNCTION__ << "Get Device Hard Info Start"; + // qCDebug(serviceLog) << __FUNCTION__ << "Get Device Hard Info Start"; HardDiskInfo hdinfo; if (devicepath.isEmpty()) { - qDebug() << "disk path is empty"; + qCDebug(serviceLog) << "disk path is empty"; return hdinfo; } @@ -167,38 +168,38 @@ HardDiskInfo PartedCore::getDeviceHardInfo(const QString &devicepath) hdinfo.m_firmwareVersion = device.m_firmwareVersion; hdinfo.m_speed = device.m_speed; if (hdinfo.m_mediaType == "SSD") { - qDebug() << "Media type is SSD, setting rotation rate to -"; + qCDebug(serviceLog) << "Media type is SSD, setting rotation rate to -"; hdinfo.m_rotationRate = "-"; } - qDebug() << "Get device hard info for " << devicepath; - qDebug() << "Model: " << hdinfo.m_model; - qDebug() << "Vendor: " << hdinfo.m_vendor; - qDebug() << "Media type: " << hdinfo.m_mediaType; - qDebug() << "Size: " << hdinfo.m_size; - qDebug() << "Rotation rate: " << hdinfo.m_rotationRate; - qDebug() << "Interface: " << hdinfo.m_interface; - qDebug() << "Serial number: " << hdinfo.m_serialNumber; - qDebug() << "Version: " << hdinfo.m_version; - qDebug() << "Capabilities: " << hdinfo.m_capabilities; - qDebug() << "Description: " << hdinfo.m_description; - qDebug() << "Power on hours: " << hdinfo.m_powerOnHours; - qDebug() << "Power cycle count: " << hdinfo.m_powerCycleCount; - qDebug() << "Firmware version: " << hdinfo.m_firmwareVersion; - qDebug() << "Speed: " << hdinfo.m_speed; + qCDebug(serviceLog) << "Get device hard info for " << devicepath; + qCDebug(serviceLog) << "Model: " << hdinfo.m_model; + qCDebug(serviceLog) << "Vendor: " << hdinfo.m_vendor; + qCDebug(serviceLog) << "Media type: " << hdinfo.m_mediaType; + qCDebug(serviceLog) << "Size: " << hdinfo.m_size; + qCDebug(serviceLog) << "Rotation rate: " << hdinfo.m_rotationRate; + qCDebug(serviceLog) << "Interface: " << hdinfo.m_interface; + qCDebug(serviceLog) << "Serial number: " << hdinfo.m_serialNumber; + qCDebug(serviceLog) << "Version: " << hdinfo.m_version; + qCDebug(serviceLog) << "Capabilities: " << hdinfo.m_capabilities; + qCDebug(serviceLog) << "Description: " << hdinfo.m_description; + qCDebug(serviceLog) << "Power on hours: " << hdinfo.m_powerOnHours; + qCDebug(serviceLog) << "Power cycle count: " << hdinfo.m_powerCycleCount; + qCDebug(serviceLog) << "Firmware version: " << hdinfo.m_firmwareVersion; + qCDebug(serviceLog) << "Speed: " << hdinfo.m_speed; return hdinfo; } QString PartedCore::getDeviceHardStatus(const QString &devicepath) { - // qDebug() << __FUNCTION__ << "Get Device Hard Status Start"; + // qCDebug(serviceLog) << __FUNCTION__ << "Get Device Hard Status Start"; QString status; QString devicePath = devicepath; if (devicepath.contains("nvme")) { - qDebug() << "Device path contains nvme"; + qCDebug(serviceLog) << "Device path contains nvme"; QStringList list = devicepath.split("nvme"); if (list.size() < 2) { - qDebug() << "Invalid nvme device path format"; + qCDebug(serviceLog) << "Invalid nvme device path format"; return status; } QString str = ""; @@ -217,12 +218,12 @@ QString PartedCore::getDeviceHardStatus(const QString &devicepath) QString output, error; int 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 status; } if (output.indexOf("SMART overall-health self-assessment test result:") != -1) { - qDebug() << "Found SMART overall-health self-assessment test result"; + qCDebug(serviceLog) << "Found SMART overall-health self-assessment test result"; QStringList list = output.split("\n"); for (int i = 0; i < list.size(); i++) { if (list.at(i).indexOf("SMART overall-health self-assessment test result:") != -1) { @@ -232,21 +233,21 @@ QString PartedCore::getDeviceHardStatus(const QString &devicepath) #else status.remove(QRegExp("^ +\\s*")); #endif -// qDebug() << __FUNCTION__ << status; +// qCDebug(serviceLog) << __FUNCTION__ << status; break; } } } else { - qDebug() << "SMART overall-health self-assessment test result not found, trying -d sat"; + qCDebug(serviceLog) << "SMART overall-health self-assessment test result not found, trying -d sat"; QString cmd = QString("smartctl -H -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 status; } if (output.indexOf("SMART overall-health self-assessment test result:") != -1) { - qDebug() << "Found SMART overall-health self-assessment test result with -d sat"; + qCDebug(serviceLog) << "Found SMART overall-health self-assessment test result with -d sat"; QStringList list = output.split("\n"); for (int i = 0; i < list.size(); i++) { if (list.at(i).indexOf("SMART overall-health self-assessment test result:") != -1) { @@ -256,32 +257,32 @@ QString PartedCore::getDeviceHardStatus(const QString &devicepath) #else status.remove(QRegExp("^ +\\s*")); #endif -// qDebug() << __FUNCTION__ << status; +// qCDebug(serviceLog) << __FUNCTION__ << status; break; } } } else { - qDebug() << "SMART overall-health self-assessment test result not found even with -d sat"; + qCDebug(serviceLog) << "SMART overall-health self-assessment test result not found even with -d sat"; } } - // qDebug() << __FUNCTION__ << "Get Device Hard Status End"; + // qCDebug(serviceLog) << __FUNCTION__ << "Get Device Hard Status End"; return status; } HardDiskStatusInfoList PartedCore::getDeviceHardStatusInfo(const QString &devicepath) { - // qDebug() << __FUNCTION__ << "Get Device Hard Status Info Start"; + // qCDebug(serviceLog) << __FUNCTION__ << "Get Device Hard Status Info Start"; HardDiskStatusInfoList hdsilist; QString devicePath = devicepath; // QString devicePath = "/dev/nvme12n1"; if (devicePath.contains("nvme")) { - qDebug() << "Device path contains nvme"; + qCDebug(serviceLog) << "Device path contains nvme"; //重新拼接硬盘字符串 QStringList list = devicePath.split("nvme"); if (list.size() < 2) { - qDebug() << "Invalid nvme device path format, returning empty list"; + qCDebug(serviceLog) << "Invalid nvme device path format, returning empty list"; return hdsilist; } QString str = ""; @@ -299,12 +300,12 @@ HardDiskStatusInfoList PartedCore::getDeviceHardStatusInfo(const QString &device QString output, error; int 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 hdsilist; } // Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org\n\n=== START OF SMART DATA SECTION ===\nSMART/Health Information (NVMe Log 0x02, NSID 0xffffffff)\nCritical Warning: 0x00\nTemperature: 25 Celsius\nAvailable Spare: 100%\nAvailable Spare Threshold: 5%\nPercentage Used: 1%\nData Units Read: 3,196,293 [1.63 TB]\nData Units Written: 3,708,861 [1.89 TB]\nHost Read Commands: 47,399,157\nHost Write Commands: 65,181,192\nController Busy Time: 418\nPower Cycles: 97\nPower On Hours: 1,362\nUnsafe Shutdowns: 44\nMedia and Data Integrity Errors: 0\nError Information Log Entries: 171\nWarning Comp. Temperature Time: 0\nCritical Comp. Temperature Time: 0\n\n"; -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-only @@ -315,29 +316,29 @@ HardDiskStatusInfoList PartedCore::getDeviceHardStatusInfo(const QString &device if (list.at(i).contains(":")) { QStringList slist = list.at(i).split(":"); if (slist.size() != 2) { - qDebug() << "Invalid smartctl output format, breaking loop"; + qCDebug(serviceLog) << "Invalid smartctl output format, breaking loop"; break; } hdsinfo.m_attributeName = slist.at(0); hdsinfo.m_rawValue = slist.at(1).trimmed(); } else { - qDebug() << "Line does not contain ':', continuing"; + qCDebug(serviceLog) << "Line does not contain ':', continuing"; continue; } hdsilist.append(hdsinfo); } } else { - qDebug() << "Device path does not contain nvme, using default smartctl"; + qCDebug(serviceLog) << "Device path does not contain nvme, using default smartctl"; QString cmd = QString("smartctl -A %1").arg(devicepath); QString output, error; int 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 hdsilist; } if (output.contains("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE")) { - qDebug() << "Found SMART attributes header"; + qCDebug(serviceLog) << "Found SMART attributes header"; QStringList list = output.split("\n"); int n = list.indexOf("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE"); for (int i = n + 1; i < list.size(); i++) { @@ -349,12 +350,12 @@ HardDiskStatusInfoList PartedCore::getDeviceHardStatusInfo(const QString &device slist.removeAll(""); if (slist.size() == 0) { - qDebug() << "Empty line, breaking loop"; + qCDebug(serviceLog) << "Empty line, breaking loop"; break; } if (list.size() >= 10) { - qDebug() << "Parsing SMART attribute line"; + qCDebug(serviceLog) << "Parsing SMART attribute line"; hdsinfo.m_id = slist.at(0); hdsinfo.m_attributeName = slist.at(1); hdsinfo.m_flag = slist.at(2); @@ -372,16 +373,16 @@ HardDiskStatusInfoList PartedCore::getDeviceHardStatusInfo(const QString &device hdsilist.append(hdsinfo); } } else { - qDebug() << "SMART attributes header not found, trying -d sat"; + qCDebug(serviceLog) << "SMART attributes header not found, trying -d sat"; QString cmd = QString("smartctl -A -d sat %1").arg(devicepath); QString output, error; int 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 hdsilist; } if (output.contains("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE")) { - qDebug() << "Found SMART attributes header with -d sat"; + qCDebug(serviceLog) << "Found SMART attributes header with -d sat"; QStringList list = output.split("\n"); int n = list.indexOf("ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE"); for (int i = n + 1; i < list.size(); i++) { @@ -391,12 +392,12 @@ HardDiskStatusInfoList PartedCore::getDeviceHardStatusInfo(const QString &device slist.removeAll(""); if (slist.size() == 0) { - qDebug() << "Empty line, breaking loop"; + qCDebug(serviceLog) << "Empty line, breaking loop"; break; } if (list.size() >= 10) { - qDebug() << "Parsing SMART attribute line with -d sat"; + qCDebug(serviceLog) << "Parsing SMART attribute line with -d sat"; hdsinfo.m_id = slist.at(0); hdsinfo.m_attributeName = slist.at(1); hdsinfo.m_flag = slist.at(2); @@ -414,17 +415,17 @@ HardDiskStatusInfoList PartedCore::getDeviceHardStatusInfo(const QString &device hdsilist.append(hdsinfo); } } else { - qDebug() << "SMART attributes header not found even with -d sat"; + qCDebug(serviceLog) << "SMART attributes header not found even with -d sat"; } } } - // qDebug() << __FUNCTION__ << "Get Device Hard Status Info end"; + // qCDebug(serviceLog) << __FUNCTION__ << "Get Device Hard Status Info end"; return hdsilist; } bool PartedCore::createPartitionTable(const QString &devicePath, const QString &length, const QString §orSize, const QString &diskLabel) { - qDebug() << "PartedCore::createPartitionTable BEGIN"; + qCDebug(serviceLog) << "PartedCore::createPartitionTable BEGIN"; // Glib::ustring device_path = device.get_path(); // FIXME: Should call file system specific removal actions @@ -450,10 +451,10 @@ bool PartedCore::createPartitionTable(const QString &devicePath, const QString & //close luks map of partition and remove luksKey auto devIt = m_deviceMap.find(devicePath); if (devIt != m_deviceMap.end()) { - qDebug() << "found device in m_deviceMap"; + qCDebug(serviceLog) << "found device in m_deviceMap"; bool isClose = false; if (!closeLUKSMap(devIt.value(), isClose)) { - qDebug() << "closeLUKSMap failed"; + qCDebug(serviceLog) << "closeLUKSMap failed"; return false; } } @@ -472,34 +473,34 @@ bool PartedCore::createPartitionTable(const QString &devicePath, const QString & bool flag = newDiskLabel(devicePath, diskLabel); if (!m_isClear) { - qDebug() << "m_isClear is false"; + qCDebug(serviceLog) << "m_isClear is false"; emit refreshDeviceInfo(DISK_SIGNAL_TYPE_CREATE_TABLE, flag, ""); } - qDebug() << "PartedCore::createPartitionTable END"; + qCDebug(serviceLog) << "PartedCore::createPartitionTable END"; return flag; } bool PartedCore::detectionPartitionTableError(const QString &devicePath) { - qDebug() << "PartedCore::detectionPartitionTableError BEGIN"; - // qDebug() << __FUNCTION__ << "Detection Partition Table Error start"; + qCDebug(serviceLog) << "PartedCore::detectionPartitionTableError BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Detection Partition Table Error start"; struct stat fileStat; stat(devicePath.toStdString().c_str(), &fileStat); if (!S_ISBLK(fileStat.st_mode)) { - qDebug() << __FUNCTION__ << QString("%1 is not blk file").arg(devicePath); + qCDebug(serviceLog) << __FUNCTION__ << QString("%1 is not blk file").arg(devicePath); return false; } bool needRewrite = gptIsExpanded(devicePath); if (needRewrite) { - qDebug() << "needRewrite is true"; + qCDebug(serviceLog) << "needRewrite is true"; QString outPutFix, errorFix; QString cmdFix = QString("fdisk %1").arg(devicePath); QString intPut("w"); Utils::executWithInputOutputCmd(cmdFix, &intPut, outPutFix, errorFix); - qDebug() << __FUNCTION__ << "createPartition Partition Table Rewrite Done"; + qCDebug(serviceLog) << __FUNCTION__ << "createPartition Partition Table Rewrite Done"; return false; } @@ -508,19 +509,19 @@ bool PartedCore::detectionPartitionTableError(const QString &devicePath) argList << "-l" << devicePath << "2>&1"; int ret = Utils::executWithErrorCmd("fdisk", argList, outPut, outPutError, error); if (ret != 0) { - qDebug() << __FUNCTION__ << "Detection Partition Table Error order error"; + qCDebug(serviceLog) << __FUNCTION__ << "Detection Partition Table Error order error"; return false; } QStringList outPulList = outPut.split("\n"); for (int i = 0; i < outPulList.size(); i++) { if (strstr(outPulList[i].toStdString().c_str(), "Partition table entries are not in disk order") != nullptr) { - qDebug() << "Partition table entries are not in disk order"; + qCDebug(serviceLog) << "Partition table entries are not in disk order"; return true; } } - // qDebug() << __FUNCTION__ << "Detection Partition Table Error end"; - qDebug() << "PartedCore::detectionPartitionTableError END"; + // qCDebug(serviceLog) << __FUNCTION__ << "Detection Partition Table Error end"; + qCDebug(serviceLog) << "PartedCore::detectionPartitionTableError END"; return false; // QString cmd = QString("fdisk -l %1 2>&1").arg(devicePath); @@ -530,7 +531,7 @@ bool PartedCore::detectionPartitionTableError(const QString &devicePath) // memset(pb, 0, 1024); // if (fd == nullptr) { -// qDebug() << __FUNCTION__ << "Detection Partition Table Error order error"; +// qCDebug(serviceLog) << __FUNCTION__ << "Detection Partition Table Error order error"; // return false; // } @@ -543,7 +544,7 @@ bool PartedCore::detectionPartitionTableError(const QString &devicePath) // QString cmd_fix = QString("echo w | fdisk %1").arg(devicePath); // FILE *fixfd = popen(cmd_fix.toStdString().data(), "r"); -// qDebug() << __FUNCTION__ << "Detection Partition Table Rewrite Done"; +// qCDebug(serviceLog) << __FUNCTION__ << "Detection Partition Table Rewrite Done"; // if (fixfd) { // fclose(fixfd); // } @@ -553,52 +554,52 @@ bool PartedCore::detectionPartitionTableError(const QString &devicePath) // } // fclose(fd); -// qDebug() << __FUNCTION__ << "Detection Partition Table Error end"; +// qCDebug(serviceLog) << __FUNCTION__ << "Detection Partition Table Error end"; // return false; } bool PartedCore::create(const PartitionVec &infovec) { - qDebug() << "PartedCore::create BEGIN"; - // qDebug() << __FUNCTION__ << "Create start"; + qCDebug(serviceLog) << "PartedCore::create BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Create start"; bool success = true; for (PartitionInfo info : infovec) { Partition newPartition; newPartition.reset(info); if (!create(newPartition)) { - qDebug() << __FUNCTION__ << "Create Partitione error"; + qCDebug(serviceLog) << __FUNCTION__ << "Create Partitione error"; success = false; break; } } if (!m_isClear) { - qDebug() << "m_isClear is false"; + qCDebug(serviceLog) << "m_isClear is false"; m_type = DISK_SIGNAL_TYPE_CREATE_FAILED; emit refreshDeviceInfo(m_type, m_arg1, m_arg2); } - // qDebug() << __FUNCTION__ << "Create end"; - qDebug() << "PartedCore::create END"; + // qCDebug(serviceLog) << __FUNCTION__ << "Create end"; + qCDebug(serviceLog) << "PartedCore::create END"; return success; } bool PartedCore::format(const QString &fstype, const QString &name) { - qDebug() << "PartedCore::format BEGIN"; - // qDebug() << __FUNCTION__ << "Format Partitione start"; + qCDebug(serviceLog) << "PartedCore::format BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Format Partitione start"; Partition part = m_curpartition; part.m_fstype = Utils::stringToFileSystemType(fstype); part.setFilesystemLabel(name); bool success = formatPartition(part); - // qDebug() << __FUNCTION__ << "Format Partitione end"; - qDebug() << "PartedCore::format END"; + // qCDebug(serviceLog) << __FUNCTION__ << "Format Partitione end"; + qCDebug(serviceLog) << "PartedCore::format END"; return success; } bool PartedCore::clear(const WipeAction &wipe) { //arg check - // qDebug() << __FUNCTION__ << QString("Clear Partitione start, path: %1").arg(wipe.m_path) ; + // qCDebug(serviceLog) << __FUNCTION__ << QString("Clear Partitione start, path: %1").arg(wipe.m_path) ; bool success = false; FSType fs = Utils::stringToFileSystemType(wipe.m_fstype); //TODO 此处是否可用 supportedFileSystem(fs);判断? @@ -720,7 +721,7 @@ bool PartedCore::clear(const WipeAction &wipe) } else if (DISK_TYPE == wipe.m_diskType) { Device dev = m_deviceMap.value(wipe.m_path); curDevicePath = wipe.m_path; - qDebug() << __FUNCTION__ << "Clear: createPartitionTable start : " << dev.m_path; + qCDebug(serviceLog) << __FUNCTION__ << "Clear: createPartitionTable start : " << dev.m_path; curDiskType = dev.m_diskType; if (curDiskType == "unrecognized" || curDiskType == "none") { curDiskType = "gpt"; @@ -753,7 +754,7 @@ bool PartedCore::clear(const WipeAction &wipe) } pVec.push_back(pInfo); - qDebug() << __FUNCTION__ << "Clear: createPartition start : " << pInfo.m_path; + qCDebug(serviceLog) << __FUNCTION__ << "Clear: createPartition start : " << pInfo.m_path; success = create(pVec); if (!success) { QString str = QString("%1:%2:%3").arg("DISK_ERROR").arg(DISK_ERROR::DISK_ERR_CREATE_PART_FAILED).arg(wipe.m_path); @@ -772,21 +773,21 @@ bool PartedCore::clear(const WipeAction &wipe) //清除 switch (wipe.m_clearType) { case SECURE_TYPE: - qDebug() << __FUNCTION__ << "Clear: secuClear start"; + qCDebug(serviceLog) << __FUNCTION__ << "Clear: secuClear start"; success = secuClear(m_curpartition.getPath(), m_curpartition.m_sectorStart, m_curpartition.m_sectorEnd, m_curpartition.m_sectorSize, wipe.m_fstype, wipe.m_fileSystemLabel, 1); break; case DOD_TYPE: - qDebug() << __FUNCTION__ << "Clear: secuClear start"; + qCDebug(serviceLog) << __FUNCTION__ << "Clear: secuClear start"; success = secuClear(m_curpartition.getPath(), m_curpartition.m_sectorStart, m_curpartition.m_sectorEnd, m_curpartition.m_sectorSize, wipe.m_fstype, wipe.m_fileSystemLabel, 7); break; case GUTMANN_TYPE: - qDebug() << __FUNCTION__ << "Clear: secuClear start"; + qCDebug(serviceLog) << __FUNCTION__ << "Clear: secuClear start"; success = secuClear(m_curpartition.getPath(), m_curpartition.m_sectorStart, m_curpartition.m_sectorEnd, m_curpartition.m_sectorSize, wipe.m_fstype, wipe.m_fileSystemLabel, 35); break; } if (!success) { - qDebug() << __FUNCTION__ << "secuClear error"; + qCDebug(serviceLog) << __FUNCTION__ << "secuClear error"; QString str = QString("%1:%2:%3").arg("DISK_ERROR").arg(DISK_ERROR::DISK_ERR_UPDATE_KERNEL_FAILED).arg(wipe.m_path); m_isClear = false; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CLEAR, false, str); @@ -797,7 +798,7 @@ bool PartedCore::clear(const WipeAction &wipe) if (wipe.m_luksFlag == LUKSFlag::NOT_CRYPT_LUKS) { success = format(wipe.m_fstype, wipe.m_fileSystemLabel); if (!success) { - qDebug() << __FUNCTION__ << "format error"; + qCDebug(serviceLog) << __FUNCTION__ << "format error"; blockSignals(false); QString str = QString("%1:%2:%3").arg("DISK_ERROR").arg(DISK_ERROR::DISK_ERR_CREATE_PART_FAILED).arg(wipe.m_path); m_isClear = false; @@ -874,7 +875,7 @@ bool PartedCore::clear(const WipeAction &wipe) } QPairpair = tmpMountDevice(mountPath, devPath, fsType, wipe.m_user); m_isClear = false; - // qDebug() << __FUNCTION__ << "clear end"; + // qCDebug(serviceLog) << __FUNCTION__ << "clear end"; if (pair.first) { deleteMountPointExclude(devPath); } @@ -883,8 +884,8 @@ bool PartedCore::clear(const WipeAction &wipe) bool PartedCore::resize(const PartitionInfo &info) { - qDebug() << "PartedCore::resize BEGIN"; - // qDebug() << __FUNCTION__ << "Resize Partitione start: " << info.m_devicePath; + qCDebug(serviceLog) << "PartedCore::resize BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Resize Partitione start: " << info.m_devicePath; // //对应 Bug 95232, 如果检测到虚拟磁盘扩容的话,重新写一下分区表,就可以修正分区表数据. reWritePartition(info.m_devicePath); @@ -903,32 +904,32 @@ bool PartedCore::resize(const PartitionInfo &info) // if (fixfd) { // fclose(fixfd); // } -// qDebug() << __FUNCTION__ << "createPartition Partition Table Rewrite Done"; +// qCDebug(serviceLog) << __FUNCTION__ << "createPartition Partition Table Rewrite Done"; // } // } // fclose(fd); // } - // qDebug() << __FUNCTION__ << "Resize Partitione start"; + // qCDebug(serviceLog) << __FUNCTION__ << "Resize Partitione start"; Partition newPartition = m_curpartition; newPartition.reset(info); if (newPartition.getByteLength() < m_curpartition.m_fsLimits.min_size) { - qDebug() << "newPartition.getByteLength() < m_curpartition.m_fsLimits.min_size, return false"; + qCDebug(serviceLog) << "newPartition.getByteLength() < m_curpartition.m_fsLimits.min_size, return false"; return sendRefSigAndReturn(false); } bool success = resize(newPartition); emit refreshDeviceInfo(); - // qDebug() << __FUNCTION__ << "Resize Partitione end"; - qDebug() << "PartedCore::resize END"; + // qCDebug(serviceLog) << __FUNCTION__ << "Resize Partitione end"; + qCDebug(serviceLog) << "PartedCore::resize END"; return success; } bool PartedCore::deletePartition() { - qDebug() << "PartedCore::deletePartition BEGIN"; - // qDebug() << __FUNCTION__ << "Delete Partition start"; + qCDebug(serviceLog) << "PartedCore::deletePartition BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Delete Partition start"; PedPartition *ped = nullptr; PedDevice *lpDevice = nullptr; PedDisk *lpDisk = nullptr; @@ -939,20 +940,20 @@ bool PartedCore::deletePartition() //close luksMapper bool isClose = false; if (!closeLUKSMap(devicePath, isClose)) { - qDebug() << __FUNCTION__ << "Close luks Mapper failed"; + qCDebug(serviceLog) << __FUNCTION__ << "Close luks Mapper failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_DEL, true, QString("0:%1").arg(DISK_ERROR::DISK_ERR_PART_INFO)); } bool success = true; if (m_LUKSInfo.luksExists(parttitionPath)) { - qDebug() << "luksExists is true"; + qCDebug(serviceLog) << "luksExists is true"; LUKS_INFO info = m_LUKSInfo.getLUKS(parttitionPath); success = LUKSOperator::removeMapperAndKey(m_LUKSInfo, info); } if (!getDeviceAndDisk(devicePath, lpDevice, lpDisk) || !success) { - qDebug() << __FUNCTION__ << "get device and disk failed"; + qCDebug(serviceLog) << __FUNCTION__ << "get device and disk failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_DEL, true, QString("0:%1").arg(DISK_ERROR::DISK_ERR_DISK_INFO)); } @@ -970,39 +971,39 @@ bool PartedCore::deletePartition() ped = ped_disk_get_partition(lpDisk, num); if (ped == nullptr) { - qDebug() << __FUNCTION__ << "Get Partition failed"; + qCDebug(serviceLog) << __FUNCTION__ << "Get Partition failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_DEL, true, QString("0:%1").arg(DISK_ERROR::DISK_ERR_PART_INFO)); } int i = ped_disk_delete_partition(lpDisk, ped); if (i == 0) { - qDebug() << __FUNCTION__ << "Delete Partition failed"; + qCDebug(serviceLog) << __FUNCTION__ << "Delete Partition failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_DEL, true, QString("0:%1").arg(DISK_ERROR::DISK_ERR_DELETE_PART_FAILED)); } if (!commit(lpDisk)) { - qDebug() << __FUNCTION__ << "Delete Partition commit failed"; + qCDebug(serviceLog) << __FUNCTION__ << "Delete Partition commit failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_DEL, true, QString("0:%1").arg(DISK_ERROR::DISK_ERR_UPDATE_KERNEL_FAILED)); } destroyDeviceAndDisk(lpDevice, lpDisk); - // qDebug() << __FUNCTION__ << "Delete Partition end"; - qDebug() << "PartedCore::deletePartition END"; + // qCDebug(serviceLog) << __FUNCTION__ << "Delete Partition end"; + qCDebug(serviceLog) << "PartedCore::deletePartition END"; return sendRefSigAndReturn(true, DISK_SIGNAL_TYPE_DEL, true, "1:0"); } bool PartedCore::showPartition() { - qDebug() << "PartedCore::showPartition BEGIN"; - // qDebug() << __FUNCTION__ << "Show Partition start"; + qCDebug(serviceLog) << "PartedCore::showPartition BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Show Partition start"; getPartitionHiddenFlag(); #if QT_VERSION_MAJOR > 5 if (m_hiddenPartition.indexOf(m_curpartition.m_uuid.toUtf8()) == -1) { #else if (m_hiddenPartition.indexOf(m_curpartition.m_uuid) == -1) { #endif - qDebug() << "partition not hidden, return false"; + qCDebug(serviceLog) << "partition not hidden, return false"; emit refreshDeviceInfo(); emit showPartitionInfo("0"); return false; @@ -1012,7 +1013,7 @@ bool PartedCore::showPartition() QStringList list; if (!file.open(QIODevice::ReadOnly)) { //打开指定文件 - qDebug() << __FUNCTION__ << "Permanent unmount open file error"; + qCDebug(serviceLog) << __FUNCTION__ << "Permanent unmount open file error"; emit refreshDeviceInfo(); emit showPartitionInfo("0"); return false; @@ -1023,14 +1024,14 @@ bool PartedCore::showPartition() QString str = line; if (str.contains(m_curpartition.m_uuid)) { - qDebug() << "contains uuid, continue"; + qCDebug(serviceLog) << "contains uuid, continue"; continue; } list << str; } file.close(); if (file.open(QIODevice::ReadWrite | QIODevice::Truncate)) { - qDebug() << "open file for write"; + qCDebug(serviceLog) << "open file for write"; QTextStream out(&file); for (int i = 0; i < list.count(); i++) { out << list.at(i); @@ -1044,16 +1045,16 @@ bool PartedCore::showPartition() emit refreshDeviceInfo(); emit showPartitionInfo("1"); - // qDebug() << __FUNCTION__ << "Show Partition end"; - qDebug() << "PartedCore::showPartition END"; + // qCDebug(serviceLog) << __FUNCTION__ << "Show Partition end"; + qCDebug(serviceLog) << "PartedCore::showPartition END"; return true; } bool PartedCore::hidePartition() { - qDebug() << "PartedCore::hidePartition BEGIN"; - // qDebug() << __FUNCTION__ << "Hide Partition start"; + qCDebug(serviceLog) << "PartedCore::hidePartition BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Hide Partition start"; //ENV{ID_FS_UUID}==\"1ee3b4c6-1c69-46b9-9656-8c534ffd4f43\", ENV{UDISKS_IGNORE}=\"1\"\n getPartitionHiddenFlag(); #if QT_VERSION_MAJOR > 5 @@ -1061,7 +1062,7 @@ bool PartedCore::hidePartition() #else if (m_hiddenPartition.indexOf(m_curpartition.m_uuid) != -1) { #endif - qDebug() << "partition already hidden, return false"; + qCDebug(serviceLog) << "partition already hidden, return false"; emit refreshDeviceInfo(); emit hidePartitionInfo("0"); return false; @@ -1069,30 +1070,30 @@ bool PartedCore::hidePartition() QFile file("/etc/udev/rules.d/80-udisks2.rules"); if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) { //打开指定文件 - qDebug() << __FUNCTION__ << "Permanent mount open file error"; + qCDebug(serviceLog) << __FUNCTION__ << "Permanent mount open file error"; emit refreshDeviceInfo(); emit hidePartitionInfo("0"); return false; } else { - qDebug() << "open file for write"; + qCDebug(serviceLog) << "open file for write"; QTextStream out(&file); out << QString("ENV{ID_FS_UUID}==\"%1\", ENV{UDISKS_IGNORE}=\"1\"").arg(m_curpartition.m_uuid) << "\n"; } - // qDebug() << __FUNCTION__ << "Hide Partition end"; + // qCDebug(serviceLog) << __FUNCTION__ << "Hide Partition end"; Utils::executCmd("udevadm control --reload"); emit refreshDeviceInfo(); emit hidePartitionInfo("1"); - qDebug() << "PartedCore::hidePartition END"; + qCDebug(serviceLog) << "PartedCore::hidePartition END"; return true; } void PartedCore::setCurSelect(const PartitionInfo &info) { - qDebug() << "PartedCore::setCurSelect BEGIN"; + qCDebug(serviceLog) << "PartedCore::setCurSelect BEGIN"; auto it = m_deviceMap.find(info.m_devicePath); if (it == m_deviceMap.end()) { - qDebug() << "device not found, return"; + qCDebug(serviceLog) << "device not found, return"; return; } @@ -1100,56 +1101,56 @@ void PartedCore::setCurSelect(const PartitionInfo &info) foreach (const Partition *part, dev.m_partitions) { if (infoBelongToPartition(*part, info)) { - qDebug() << "found partition, set m_curpartition"; + qCDebug(serviceLog) << "found partition, set m_curpartition"; m_curpartition = *part; return ; } if (part->m_insideExtended) {//扩展分区 查看是否为逻辑分区 - qDebug() << "is extended partition"; + qCDebug(serviceLog) << "is extended partition"; foreach (const Partition *partlogical, part->m_logicals) { if (infoBelongToPartition(*partlogical, info)) { - qDebug() << "found logical partition, set m_curpartition"; + qCDebug(serviceLog) << "found logical partition, set m_curpartition"; m_curpartition = *partlogical; return; } } } } - qDebug() << "PartedCore::setCurSelect END"; + qCDebug(serviceLog) << "PartedCore::setCurSelect END"; } bool PartedCore::mountAndWriteFstab(const QString &mountpath, const QString &mountUid) { - qDebug() << "PartedCore::mountAndWriteFstab BEGIN"; - // qDebug() << __FUNCTION__ << "Permanent mount start"; + qCDebug(serviceLog) << "PartedCore::mountAndWriteFstab BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Permanent mount start"; QString type = Utils::fileSystemTypeToString(m_curpartition.m_fstype); bool success = mountDevice(mountpath, m_curpartition.getPath(), m_curpartition.m_fstype, mountUid) //位置不可交换 利用&&运算特性 && writeFstab(m_curpartition.m_uuid, mountpath, type, true); - // qDebug() << __FUNCTION__ << "Permanent mount end"; + // qCDebug(serviceLog) << __FUNCTION__ << "Permanent mount end"; deleteMountPointExclude(m_curpartition.getPath()); - qDebug() << "PartedCore::mountAndWriteFstab END"; + qCDebug(serviceLog) << "PartedCore::mountAndWriteFstab END"; return sendRefSigAndReturn(success); } bool PartedCore::unmount() { - qDebug() << "PartedCore::unmount BEGIN"; - // qDebug() << __FUNCTION__ << "Unmount start"; + qCDebug(serviceLog) << "PartedCore::unmount BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "Unmount start"; if (!umontDevice(m_curpartition.getMountPoints(), m_curpartition.getPath())) { //卸载挂载点 内部有信号发送 不要重复发送信号 - qDebug() << "umontDevice failed, return false"; + qCDebug(serviceLog) << "umontDevice failed, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_UMNT, true, "0"); } QString type = Utils::fileSystemTypeToString(m_curpartition.m_fstype);//修改/etc/fstab //writeFstab(m_curpartition.m_uuid, "", type, false);//非挂载 不需要挂载点 - // qDebug() << __FUNCTION__ << "Unmount end"; + // qCDebug(serviceLog) << __FUNCTION__ << "Unmount end"; addMountPointExclude(m_curpartition.getPath()); - qDebug() << "PartedCore::unmount END"; + qCDebug(serviceLog) << "PartedCore::unmount END"; return sendRefSigAndReturn(true, DISK_SIGNAL_TYPE_UMNT, true, "1"); } bool PartedCore::cryptMount(const LUKS_INFO &luks) { - qDebug() << "PartedCore::cryptMount BEGIN"; + qCDebug(serviceLog) << "PartedCore::cryptMount BEGIN"; LUKS_INFO luks2 = luks; if (!m_LUKSInfo.luksExists(luks.m_devicePath) //luks || !luks2.isDecrypt //判断是否解密 @@ -1157,14 +1158,14 @@ bool PartedCore::cryptMount(const LUKS_INFO &luks) || luks2.m_mapper.m_luksFs == FSType::FS_UNALLOCATED || luks2.m_mapper.m_luksFs == FSType::FS_UNKNOWN || luks2.m_mapper.m_luksFs == FSType::FS_UNFORMATTED) { - qDebug() << "invalid luks info, return false"; + qCDebug(serviceLog) << "invalid luks info, return false"; return sendRefSigAndReturn(false); } //mount foreach (const QString &mount, luks2.m_mapper.m_mountPoints) { if (!mountDevice(mount, luks2.m_mapper.m_dmPath, luks2.m_mapper.m_luksFs)) { - qDebug() << "mountDevice failed, return false"; + qCDebug(serviceLog) << "mountDevice failed, return false"; return sendRefSigAndReturn(false) ; } } @@ -1172,72 +1173,72 @@ bool PartedCore::cryptMount(const LUKS_INFO &luks) //write confile if ((luks2.m_luksVersion == 1 && luks2.m_keySlots < LUKS1_MaxKey) //判断密钥槽是否仍有空间 || (luks2.m_luksVersion == 2 && luks2.m_keySlots < LUKS2_MaxKey)) { - qDebug() << "key slots available"; + qCDebug(serviceLog) << "key slots available"; if (!LUKSOperator::addKeyAndCrypttab(m_LUKSInfo, luks2)) { //判断写入crypttab文件是否成功 - qDebug() << "addKeyAndCrypttab failed, return false"; + qCDebug(serviceLog) << "addKeyAndCrypttab failed, return false"; return sendRefSigAndReturn(false) ; } foreach (const QString &mount, luks2.m_mapper.m_mountPoints) { //判断写入fstab文件是否成功 if (!writeFstab(luks2.m_mapper.m_uuid, mount, Utils::fileSystemTypeToString(luks2.m_mapper.m_luksFs))) { - qDebug() << "writeFstab failed, return false"; + qCDebug(serviceLog) << "writeFstab failed, return false"; return sendRefSigAndReturn(false) ; } } } - qDebug() << "PartedCore::cryptMount END"; + qCDebug(serviceLog) << "PartedCore::cryptMount END"; return sendRefSigAndReturn(true); } bool PartedCore::cryptUmount(const LUKS_INFO &luks) { - qDebug() << "PartedCore::cryptUmount BEGIN"; + qCDebug(serviceLog) << "PartedCore::cryptUmount BEGIN"; LUKS_INFO luks2 = luks; if (!m_LUKSInfo.luksExists(luks2.m_devicePath) || !luks2.m_mapper.m_busy) { luks2.m_cryptErr = CRYPTError::CRYPT_ERR_DEVICE_NO_EXISTS; - qDebug() << __FUNCTION__ << "Unmount CRYPT device error:device not exists or not mount"; + qCDebug(serviceLog) << __FUNCTION__ << "Unmount CRYPT device error:device not exists or not mount"; return sendRefSigAndReturn(true, DISK_SIGNAL_TYPE_UMNT, true, "0"); } //卸载 if (!umontDevice(luks2.m_mapper.m_mountPoints, luks2.m_mapper.m_dmName)) { - qDebug() << __FUNCTION__ << "Unmount CRYPT device error:device umount error"; + qCDebug(serviceLog) << __FUNCTION__ << "Unmount CRYPT device error:device umount error"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_UMNT, true, "0"); } //判断写入fstab文件是否成功 foreach (const QString &mount, luks2.m_mapper.m_mountPoints) { if (!writeFstab(luks2.m_mapper.m_uuid, mount, Utils::fileSystemTypeToString(luks2.m_mapper.m_luksFs), false)) { - qDebug() << __FUNCTION__ << "Unmount CRYPT device error: writeFstab error"; + qCDebug(serviceLog) << __FUNCTION__ << "Unmount CRYPT device error: writeFstab error"; } } LUKSOperator::removeMapperAndKey(m_LUKSInfo, luks2); - qDebug() << __FUNCTION__ << "Unmount CRYPT device end"; + qCDebug(serviceLog) << __FUNCTION__ << "Unmount CRYPT device end"; return sendRefSigAndReturn(true, DISK_SIGNAL_TYPE_UMNT, true, "1"); } bool PartedCore::deCrypt(const LUKS_INFO &luks) { - qDebug() << "PartedCore::deCrypt BEGIN"; + qCDebug(serviceLog) << "PartedCore::deCrypt BEGIN"; LUKS_INFO luks2 = luks; do { if (!m_LUKSInfo.luksExists(luks.m_devicePath)) { - qDebug() << "luks not exists"; + qCDebug(serviceLog) << "luks not exists"; luks2.m_cryptErr = CRYPTError::CRYPT_ERR_DEVICE_NO_EXISTS; break; } luks2.isDecrypt = m_LUKSInfo.getLUKS(luks.m_devicePath).isDecrypt; if (!LUKSOperator::decrypt(m_LUKSInfo, luks2)) { - qDebug() << "decrypt failed"; + qCDebug(serviceLog) << "decrypt failed"; luks2.m_cryptErr = CRYPTError::CRYPT_ERR_DECRYPT_FAILED; break; } probeDeviceInfo(); if (!m_LUKSInfo.luksExists(luks.m_devicePath)) { - qDebug() << "luks not exists after probe"; + qCDebug(serviceLog) << "luks not exists after probe"; luks2.m_cryptErr = CRYPTError::CRYPT_ERR_DEVICE_NO_EXISTS; break; } @@ -1247,59 +1248,59 @@ bool PartedCore::deCrypt(const LUKS_INFO &luks) //发送解密是否成功信号 luks2.m_decryptStr = luks.m_decryptStr; emit deCryptMessage(luks2); - qDebug() << "PartedCore::deCrypt END"; + qCDebug(serviceLog) << "PartedCore::deCrypt END"; return luks2.m_cryptErr == CRYPTError::CRYPT_ERR_NORMAL; } bool PartedCore::updateUsb() { - qDebug() << "PartedCore::updateUsb BEGIN"; - // qDebug() << __FUNCTION__ << "USB add update start"; + qCDebug(serviceLog) << "PartedCore::updateUsb BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "USB add update start"; sleep(5); //据说 有一个硬盘插入后需要等待5s才能刷新出设备文件 autoMount(); - // qDebug() << __FUNCTION__ << "USB add update end"; - qDebug() << "PartedCore::updateUsb END"; + // qCDebug(serviceLog) << __FUNCTION__ << "USB add update end"; + qCDebug(serviceLog) << "PartedCore::updateUsb END"; return true; } bool PartedCore::updateUsbRemove() { - qDebug() << "PartedCore::updateUsbRemove BEGIN"; - // qDebug() << __FUNCTION__ << "USB add update remove"; + qCDebug(serviceLog) << "PartedCore::updateUsbRemove BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "USB add update remove"; emit refreshDeviceInfo(DISK_SIGNAL_USBUPDATE); autoUmount(); - // qDebug() << __FUNCTION__ << "USB add update end"; - qDebug() << "PartedCore::updateUsbRemove END"; + // qCDebug(serviceLog) << __FUNCTION__ << "USB add update end"; + qCDebug(serviceLog) << "PartedCore::updateUsbRemove END"; return true; } bool PartedCore::checkBadBlocks(const QString &devicePath, int blockStart, int blockEnd, int checkConut, int checkSize, int flag) { - qDebug() << "PartedCore::checkBadBlocks(count) BEGIN"; + qCDebug(serviceLog) << "PartedCore::checkBadBlocks(count) BEGIN"; if (m_workerCheckThread == nullptr) { - qDebug() << "m_workerCheckThread is null, create new thread"; + qCDebug(serviceLog) << "m_workerCheckThread is null, create new thread"; m_workerCheckThread = new QThread(); m_workerCheckThread->start(); m_checkThread.moveToThread(m_workerCheckThread); -// qDebug() << QThread::currentThreadId() << 1111111111111 << endl; +// qCDebug(serviceLog) << QThread::currentThreadId() << 1111111111111 << endl; } m_checkThread.setStopFlag(flag); if (flag == 1 || flag == 3) { - qDebug() << "flag is 1 or 3"; + qCDebug(serviceLog) << "flag is 1 or 3"; m_checkThread.setCountInfo(devicePath, blockStart, blockEnd, checkConut, checkSize); emit checkBadBlocksRunCountStart(); } - qDebug() << "PartedCore::checkBadBlocks(count) END"; + qCDebug(serviceLog) << "PartedCore::checkBadBlocks(count) END"; return true; } bool PartedCore::checkBadBlocks(const QString &devicePath, int blockStart, int blockEnd, QString checkTime, int checkSize, int flag) { - qDebug() << "PartedCore::checkBadBlocks(time) BEGIN"; + qCDebug(serviceLog) << "PartedCore::checkBadBlocks(time) BEGIN"; if (m_workerCheckThread == nullptr) { - qDebug() << "m_workerCheckThread is null, create new thread"; + qCDebug(serviceLog) << "m_workerCheckThread is null, create new thread"; m_workerCheckThread = new QThread(); m_workerCheckThread->start(); m_checkThread.moveToThread(m_workerCheckThread); @@ -1307,20 +1308,20 @@ bool PartedCore::checkBadBlocks(const QString &devicePath, int blockStart, int b m_checkThread.setStopFlag(flag); if (flag == 1 || flag == 3) { - qDebug() << "flag is 1 or 3"; + qCDebug(serviceLog) << "flag is 1 or 3"; m_checkThread.setTimeInfo(devicePath, blockStart, blockEnd, checkTime, checkSize); emit checkBadBlocksRunTimeStart(); } - qDebug() << "PartedCore::checkBadBlocks(time) END"; + qCDebug(serviceLog) << "PartedCore::checkBadBlocks(time) END"; return true; } bool PartedCore::fixBadBlocks(const QString &devicePath, QStringList badBlocksList, int checkSize, int flag) { - qDebug() << "PartedCore::fixBadBlocks BEGIN"; + qCDebug(serviceLog) << "PartedCore::fixBadBlocks BEGIN"; if (m_workerFixThread == nullptr) { - qDebug() << "m_workerFixThread is null, create new thread"; + qCDebug(serviceLog) << "m_workerFixThread is null, create new thread"; m_workerFixThread = new QThread(); m_workerFixThread->start(); m_fixthread.moveToThread(m_workerFixThread); @@ -1335,40 +1336,40 @@ bool PartedCore::fixBadBlocks(const QString &devicePath, QStringList badBlocksLi m_fixthread.setStopFlag(flag); if (flag == 1 || flag == 3) { - qDebug() << "flag is 1 or 3"; + qCDebug(serviceLog) << "flag is 1 or 3"; m_fixthread.setFixBadBlocksInfo(devicePath, badBlocksList, checkSize); emit fixBadBlocksStart(); } - qDebug() << "PartedCore::fixBadBlocks END"; + qCDebug(serviceLog) << "PartedCore::fixBadBlocks END"; return true; } void PartedCore::refreshFunc() { - qDebug() << "PartedCore::refreshFunc BEGIN"; - // qDebug() << __FUNCTION__ << "refreshFunc start"; + qCDebug(serviceLog) << "PartedCore::refreshFunc BEGIN"; + // qCDebug(serviceLog) << __FUNCTION__ << "refreshFunc start"; emit refreshDeviceInfo(); - // qDebug() << __FUNCTION__ << "refreshFunc end"; - qDebug() << "PartedCore::refreshFunc END"; + // qCDebug(serviceLog) << __FUNCTION__ << "refreshFunc end"; + qCDebug(serviceLog) << "PartedCore::refreshFunc END"; } bool PartedCore::createVG(QString vgName, QList devList, long long size) { - qDebug() << "PartedCore::createVG BEGIN"; + qCDebug(serviceLog) << "PartedCore::createVG BEGIN"; std::settmpDevList; //TODO: for (auto it = devList.begin();it!=devList.end();++it) { if(m_LUKSInfo.mapperExists(it->m_devicePath)){ - qDebug() << "mapper exists"; + qCDebug(serviceLog) << "mapper exists"; it->m_devicePath = m_LUKSInfo.getMapper(it->m_devicePath).m_devicePath; } } foreach (PVData pv, devList) { if (!tmpDevList.insert(pv).second || !checkPVDevice(vgName, pv, true)) { //插入失败说明有重复 - qDebug() << "insert failed or checkPVDevice failed"; + qCDebug(serviceLog) << "insert failed or checkPVDevice failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_VGCREATE, true, QString("0:%1").arg(LVM_ERR_VG_ARGUMENT)); } } @@ -1378,14 +1379,14 @@ bool PartedCore::createVG(QString vgName, QList devList, long long size) // find luks Device and Close bool isClose = false; if (!closeLUKSMap(devList, isClose)) { - qDebug() << "closeLUKSMap failed"; + qCDebug(serviceLog) << "closeLUKSMap failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_VGCREATE, true, QString("0:%1").arg(LVM_ERR_VG_ARGUMENT)); } //磁盘 foreach (PVData pv, list) { if (pv.m_type == DEV_PARTITION) { - qDebug() << "pv type is DEV_PARTITION"; + qCDebug(serviceLog) << "pv type is DEV_PARTITION"; //todo 修改分区类型 Partition p; p.m_devicePath = pv.m_devicePath; @@ -1400,31 +1401,31 @@ bool PartedCore::createVG(QString vgName, QList devList, long long size) if (!LVMOperator::createVG(m_lvmInfo, vgName, list, size)) { - qDebug() << "createVG failed"; + qCDebug(serviceLog) << "createVG failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_VGCREATE, true, QString("0:%1").arg(m_lvmInfo.m_lvmErr)); } - qDebug() << "PartedCore::createVG END"; + qCDebug(serviceLog) << "PartedCore::createVG END"; return sendRefSigAndReturn(true, DISK_SIGNAL_TYPE_VGCREATE, true, QString("1:%1").arg(m_lvmInfo.m_lvmErr)); } bool PartedCore::deleteVG(QStringList vglist) { - qDebug() << "PartedCore::deleteVG BEGIN"; + qCDebug(serviceLog) << "PartedCore::deleteVG BEGIN"; // find luks Device and Close bool isClose = false; closeLUKSMap(vglist, isClose, bool()); bool flag = LVMOperator::deleteVG(m_lvmInfo, vglist); QString str = flag ? "1:0" : QString("0:%1").arg(m_lvmInfo.m_lvmErr); - qDebug() << "PartedCore::deleteVG END"; + qCDebug(serviceLog) << "PartedCore::deleteVG END"; return sendRefSigAndReturn(flag, DISK_SIGNAL_TYPE_VGDELETE, flag, str); } bool PartedCore::createLV(QString vgName, QList lvList) { - qDebug() << "PartedCore::createLV BEGIN"; + qCDebug(serviceLog) << "PartedCore::createLV BEGIN"; foreach (const LVAction &clv, lvList) { if (!supportedFileSystem(clv.m_lvFs)) { //判断文件系统是否支持 - qDebug() << "file system not supported, return false"; + qCDebug(serviceLog) << "file system not supported, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CREATE_FAILED, false, QString("%1:%2:%3") .arg("LVMError").arg(LVMError::LVM_ERR_LV_ARGUMENT).arg("unknow")); } @@ -1432,7 +1433,7 @@ bool PartedCore::createLV(QString vgName, QList lvList) //创建lv 失败返回false if (!LVMOperator::createLV(m_lvmInfo, vgName, lvList)) { - qDebug() << "createLV failed, return false"; + qCDebug(serviceLog) << "createLV failed, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CREATE_FAILED, false, QString("%1:%2:%3") .arg("LVMError").arg(LVMError::LVM_ERR_LV_CREATE_FAILED).arg("unknow")); } @@ -1444,17 +1445,17 @@ bool PartedCore::createLV(QString vgName, QList lvList) VGInfo vg = m_lvmInfo.getVG(vgName); foreach (const LVAction &clv, lvList) { if (!vg.lvInfoExists(clv.m_lvName)) { - qDebug() << "lv info not exists, continue"; + qCDebug(serviceLog) << "lv info not exists, continue"; continue; } LVInfo lv = vg.getLVinfo(clv.m_lvName); lv.m_lvFsType = clv.m_lvFs; if (clv.m_luksFlag == LUKSFlag::NOT_CRYPT_LUKS) { - qDebug() << "not crypt luks"; + qCDebug(serviceLog) << "not crypt luks"; lvVec.push_back(lv); } else { - qDebug() << "is crypt luks"; + qCDebug(serviceLog) << "is crypt luks"; lvVecDecrypt.push_back(lv); lvVecActDecrypt.push_back(clv); } @@ -1462,19 +1463,19 @@ bool PartedCore::createLV(QString vgName, QList lvList) QString userName = lvList.begin()->m_user; if (userName.trimmed().isEmpty()) { - qDebug() << "userName is empty, return false"; + qCDebug(serviceLog) << "userName is empty, return false"; return sendRefSigAndReturn(false); } foreach (const LVInfo &lvInfo, lvVec) { if (lvInfo.m_lvUuid.trimmed().isEmpty()) { - qDebug() << "lvUuid is empty, return false"; + qCDebug(serviceLog) << "lvUuid is empty, return false"; return sendRefSigAndReturn(false); } //创建文件系统 QString lvPath = QString("/dev/%1/%2").arg(lvInfo.m_vgName).arg(lvInfo.m_lvName); if (!createFileSystem(lvInfo.m_lvFsType, lvInfo.m_busy, lvPath)) { - qDebug() << "createFileSystem failed, return false"; + qCDebug(serviceLog) << "createFileSystem failed, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CREATE_FAILED, false, QString("%1:%2:%3") .arg("LVMError").arg(LVMError::LVM_ERR_LV_CREATE_FS_FAILED).arg(lvPath)); } @@ -1482,7 +1483,7 @@ bool PartedCore::createLV(QString vgName, QList lvList) QString mountPath = getTmpMountPath(userName, lvInfo.m_fileSystemLabel, lvInfo.m_lvUuid, lvInfo.m_lvPath); auto pair = tmpMountDevice(mountPath, lvInfo.m_lvPath, lvInfo.m_lvFsType, userName); if (!pair.first) { - qDebug() << "tmpMountDevice failed, return false"; + qCDebug(serviceLog) << "tmpMountDevice failed, return false"; return sendRefSigAndReturn(pair.first, DISK_SIGNAL_TYPE_CREATE_FAILED, pair.first, pair.second); } } @@ -1492,21 +1493,21 @@ bool PartedCore::createLV(QString vgName, QList lvList) LUKS_INFO info = getNewLUKSInfo(lv); //加密失败 if (!LUKSOperator::encrypt(m_LUKSInfo, info)) { - qDebug() << "encrypt failed, return false"; + qCDebug(serviceLog) << "encrypt failed, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CREATE_FAILED, false, QString("%1:%2:%3") .arg("CRYPTError").arg(CRYPTError::CRYPT_ERR_ENCRYPT_FAILED).arg(info.m_devicePath)); } //解密失败 if (!LUKSOperator::decrypt(m_LUKSInfo, info)) { - qDebug() << "decrypt failed, return false"; + qCDebug(serviceLog) << "decrypt failed, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CREATE_FAILED, false, QString("%1:%2:%3").arg("CRYPTError") .arg(CRYPTError::CRYPT_ERR_DECRYPT_FAILED).arg(info.m_devicePath)); } //创建文件系统失败 if (!createFileSystem(info.m_mapper.m_luksFs, info.m_mapper.m_busy, info.m_mapper.m_dmPath, info.m_mapper.m_fileSystemLabel)) { - qDebug() << "createFileSystem failed, return false"; + qCDebug(serviceLog) << "createFileSystem failed, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CREATE_FAILED, false, QString("%1:%2:%3") .arg("LVMError").arg(LVMError::LVM_ERR_LV_CREATE_FS_FAILED).arg(info.m_devicePath)); } @@ -1519,47 +1520,47 @@ bool PartedCore::createLV(QString vgName, QList lvList) QString mountPath = getTmpMountPath(userName, info.m_mapper.m_fileSystemLabel, info.m_mapper.m_uuid, info.m_mapper.m_dmPath); auto pair = tmpMountDevice(mountPath, info.m_mapper.m_dmPath, info.m_mapper.m_luksFs, userName); if (!pair.first) { - qDebug() << "tmpMountDevice failed, return false"; + qCDebug(serviceLog) << "tmpMountDevice failed, return false"; return sendRefSigAndReturn(pair.first, DISK_SIGNAL_TYPE_CREATE_FAILED, pair.first, pair.second); } } - qDebug() << "PartedCore::createLV END"; + qCDebug(serviceLog) << "PartedCore::createLV END"; return sendRefSigAndReturn(true); } bool PartedCore::deleteLV(QStringList lvlist) { - qDebug() << "PartedCore::deleteLV BEGIN"; + qCDebug(serviceLog) << "PartedCore::deleteLV BEGIN"; // find luks Device and Close bool isClose = false; closeLUKSMap(lvlist, isClose); bool flag = LVMOperator::lvRemove(m_lvmInfo, lvlist); QString str = flag ? "1:0" : QString("0:%1").arg(m_lvmInfo.m_lvmErr); - qDebug() << "PartedCore::deleteLV END"; + qCDebug(serviceLog) << "PartedCore::deleteLV END"; return sendRefSigAndReturn(flag, DISK_SIGNAL_TYPE_LVDELETE, flag, str); } bool PartedCore::resizeVG(QString vgName, QList devList, long long size) { - qDebug() << "PartedCore::resizeVG BEGIN"; + qCDebug(serviceLog) << "PartedCore::resizeVG BEGIN"; std::settmpDevList; //TODO: for (auto it = devList.begin();it!=devList.end();++it) { if(m_LUKSInfo.mapperExists(it->m_devicePath)){ - qDebug() << "mapper exists"; + qCDebug(serviceLog) << "mapper exists"; it->m_devicePath = m_LUKSInfo.getMapper(it->m_devicePath).m_devicePath; } } foreach (PVData pv, devList) { if (!tmpDevList.insert(pv).second || !checkPVDevice(vgName, pv, false)) { //插入失败说明有重复 - qDebug() << "insert failed or checkPVDevice failed"; + qCDebug(serviceLog) << "insert failed or checkPVDevice failed"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_VGCREATE, true, QString("0:%1").arg(LVM_ERR_VG_ARGUMENT)); } } if (m_workerLVMThread == nullptr) { - qDebug() << "m_workerLVMThread is null, create new thread"; + qCDebug(serviceLog) << "m_workerLVMThread is null, create new thread"; m_workerLVMThread = new QThread(); m_workerLVMThread->start(); m_lvmThread.moveToThread(m_workerLVMThread); @@ -1571,7 +1572,7 @@ bool PartedCore::resizeVG(QString vgName, QList devList, long long size) // find luks Device and Close foreach (const PVData &pv, list) { if (!m_LUKSInfo.luksExists(pv.m_devicePath)) { - qDebug() << "luks not exists, continue"; + qCDebug(serviceLog) << "luks not exists, continue"; continue; } LUKS_INFO luks = m_LUKSInfo.getLUKS(pv.m_devicePath); @@ -1581,7 +1582,7 @@ bool PartedCore::resizeVG(QString vgName, QList devList, long long size) //磁盘 foreach (PVData pv, list) { if (pv.m_type == DEV_PARTITION) { - qDebug() << "pv type is DEV_PARTITION"; + qCDebug(serviceLog) << "pv type is DEV_PARTITION"; //todo 修改分区类型 Partition p; p.m_devicePath = pv.m_devicePath; @@ -1595,73 +1596,73 @@ bool PartedCore::resizeVG(QString vgName, QList devList, long long size) } if (list.size() <= 0) { - qDebug() << "list size is 0, return false"; + qCDebug(serviceLog) << "list size is 0, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_VGCREATE, true, QString("0:%1").arg(LVMError::LVM_ERR_VG_ARGUMENT)); } //线程启动信号 emit resizeVGStart(m_lvmInfo, vgName, list, size); - qDebug() << "PartedCore::resizeVG END"; + qCDebug(serviceLog) << "PartedCore::resizeVG END"; return true; } bool PartedCore::resizeLV(LVAction &lvAct) { - qDebug() << "PartedCore::resizeLV BEGIN"; + qCDebug(serviceLog) << "PartedCore::resizeLV BEGIN"; //lv是否存在 if (! m_lvmInfo.lvInfoExists(lvAct.m_vgName, lvAct.m_lvName)) { - qDebug() << "lv not exists, return false"; + qCDebug(serviceLog) << "lv not exists, return false"; return sendRefSigAndReturn(false); } //执行动作是否为扩大或缩小 if (!(lvAct.m_lvAct == LVM_ACT_LV_EXTEND || lvAct.m_lvAct == LVM_ACT_LV_REDUCE)) { - qDebug() << "lvAct is not extend or reduce, return false"; + qCDebug(serviceLog) << "lvAct is not extend or reduce, return false"; return sendRefSigAndReturn(false); } //调整大小是否小于文件系统最小值 或者等于当前大小 LVInfo info = m_lvmInfo.getLVInfo(lvAct.m_vgName, lvAct.m_lvName); if (lvAct.m_lvByteSize < info.m_fsLimits.min_size || lvAct.m_lvByteSize == (info.m_lvLECount * info.m_LESize)) { - qDebug() << "lvByteSize is less than min_size or equal to current size, return false"; + qCDebug(serviceLog) << "lvByteSize is less than min_size or equal to current size, return false"; return sendRefSigAndReturn(false); } if (lvAct.m_lvAct == LVM_ACT_LV_REDUCE) { //缩小 - qDebug() << "lvAct is reduce"; + qCDebug(serviceLog) << "lvAct is reduce"; //自动卸载 if (!umontDevice(info.m_mountPoints, info.toMapperPath())) { - qDebug() << "umontDevice failed, return false"; + qCDebug(serviceLog) << "umontDevice failed, return false"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_UMNT, true, "0"); } } //调整lv大小 if (!LVMOperator::resizeLV(m_lvmInfo, lvAct, info)) { - qDebug() << "resizeLV failed, return false"; + qCDebug(serviceLog) << "resizeLV failed, return false"; return sendRefSigAndReturn(false); } if (lvAct.m_lvAct == LVM_ACT_LV_REDUCE && info.m_mountPoints.size() >= 1) { - qDebug() << "lvAct is reduce and mountPoints size >= 1"; + qCDebug(serviceLog) << "lvAct is reduce and mountPoints size >= 1"; //调整lv大小 if (!mountDevice(info.m_mountPoints[0], info.m_lvPath, info.m_lvFsType)) { - qDebug() << "mountDevice failed, return false"; + qCDebug(serviceLog) << "mountDevice failed, return false"; return sendRefSigAndReturn(false); } } - qDebug() << "PartedCore::resizeLV END"; + qCDebug(serviceLog) << "PartedCore::resizeLV END"; return sendRefSigAndReturn(true); } bool PartedCore::mountLV(const LVAction &lvAction) { - qDebug() << "PartedCore::mountLV BEGIN"; + qCDebug(serviceLog) << "PartedCore::mountLV BEGIN"; //判断lv是否存在 不存在退出 - qDebug() << __FUNCTION__ << "mount LV start"; + qCDebug(serviceLog) << __FUNCTION__ << "mount LV start"; if (lvAction.m_lvAct != LVM_ACT_LV_MOUNT || !m_lvmInfo.lvInfoExists(lvAction.m_vgName, lvAction.m_lvName)) { - qDebug() << __FUNCTION__ << "mount LV error:lv not exists or lvact not LVM_ACT_LV_MOUNT"; + qCDebug(serviceLog) << __FUNCTION__ << "mount LV error:lv not exists or lvact not LVM_ACT_LV_MOUNT"; return sendRefSigAndReturn(false); } @@ -1669,43 +1670,43 @@ bool PartedCore::mountLV(const LVAction &lvAction) LVInfo lv = m_lvmInfo.getLVInfo(lvAction.m_vgName, lvAction.m_lvName); QString type = Utils::fileSystemTypeToString(lv.m_lvFsType); if (!mountDevice(lvAction.m_mountPoint, lv.m_lvPath, lv.m_lvFsType)) { - qDebug() << "mountDevice failed, return false"; + qCDebug(serviceLog) << "mountDevice failed, return false"; return sendRefSigAndReturn(false); } - qDebug() << "PartedCore::mountLV END"; + qCDebug(serviceLog) << "PartedCore::mountLV END"; return sendRefSigAndReturn(writeFstab(lv.m_mountUuid, lvAction.m_mountPoint, type, true)); } bool PartedCore::umountLV(const LVAction &lvAction) { - qDebug() << "PartedCore::umountLV BEGIN"; + qCDebug(serviceLog) << "PartedCore::umountLV BEGIN"; //判断lv是否存在 不存在退出 - qDebug() << __FUNCTION__ << "Unmount LV start"; + qCDebug(serviceLog) << __FUNCTION__ << "Unmount LV start"; if (lvAction.m_lvAct != LVM_ACT_LV_UMOUNT || !m_lvmInfo.lvInfoExists(lvAction.m_vgName, lvAction.m_lvName)) { - qDebug() << __FUNCTION__ << "Unmount LV error:lv not exists or lvact not LVM_ACT_LV_UMOUNT"; + qCDebug(serviceLog) << __FUNCTION__ << "Unmount LV error:lv not exists or lvact not LVM_ACT_LV_UMOUNT"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_UMNT, true, "0"); } //卸载 LVInfo lv = m_lvmInfo.getLVInfo(lvAction.m_vgName, lvAction.m_lvName); if (!umontDevice(lv.m_mountPoints, lv.toMapperPath())) { - qDebug() << __FUNCTION__ << "Unmount LV error:lv umount error"; + qCDebug(serviceLog) << __FUNCTION__ << "Unmount LV error:lv umount error"; return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_UMNT, true, "0"); } //修改fstab writeFstab(lv.m_mountUuid, "", Utils::fileSystemTypeToString(lv.m_lvFsType), false); - qDebug() << __FUNCTION__ << "Unmount LV end"; - qDebug() << "PartedCore::umountLV END"; + qCDebug(serviceLog) << __FUNCTION__ << "Unmount LV end"; + qCDebug(serviceLog) << "PartedCore::umountLV END"; return sendRefSigAndReturn(true, DISK_SIGNAL_TYPE_UMNT, true, "1"); } bool PartedCore::clearLV(const LVAction &lvAction) { - qDebug() << __FUNCTION__ << "clearLV LV start"; + qCDebug(serviceLog) << __FUNCTION__ << "clearLV LV start"; // 判断act是否正确 lv是否存在 if (!(lvAction.m_lvAct == LVM_ACT_LV_FAST_CLEAR || lvAction.m_lvAct == LVM_ACT_LV_SECURE_CLEAR) || !m_lvmInfo.lvInfoExists(lvAction.m_vgName, lvAction.m_lvName)) { - qDebug() << __FUNCTION__ << "clearLV LV error:lv not exists or lvact not LVM_ACT_LV_FAST_CLEAR or LVM_ACT_LV_SECURE_CLEAR"; + qCDebug(serviceLog) << __FUNCTION__ << "clearLV LV error:lv not exists or lvact not LVM_ACT_LV_FAST_CLEAR or LVM_ACT_LV_SECURE_CLEAR"; QString str = QString("%1:%2:%3").arg("LVMError").arg(LVMError::LVM_ERR_LV_ARGUMENT).arg(lvAction.m_lvName); return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CLEAR, false, str); } @@ -1718,7 +1719,7 @@ bool PartedCore::clearLV(const LVAction &lvAction) || lvAction.m_lvFs == FS_XFS); LVInfo lv = m_lvmInfo.getLVInfo(lvAction.m_vgName, lvAction.m_lvName); if (lv.m_busy || !success) { //被挂载 or 文件系统不支持 退出 - qDebug() << "lv is busy or file system not supported"; + qCDebug(serviceLog) << "lv is busy or file system not supported"; QString str = QString("%1:%2:%3").arg("LVMError").arg(LVMError::LVM_ERR_LV_ARGUMENT).arg(lvAction.m_lvName); return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CLEAR, false, str); } @@ -1726,7 +1727,7 @@ bool PartedCore::clearLV(const LVAction &lvAction) //关闭加密磁盘 bool isClose = false; if (!closeLUKSMap(lv.m_lvPath, isClose)) { - qDebug() << "closeLUKSMap failed"; + qCDebug(serviceLog) << "closeLUKSMap failed"; QString str = QString("%1:%2:%3").arg("CRYPTError").arg(CRYPTError::CRYPT_ERR_CLOSE_FAILED).arg(lv.m_lvPath); return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CLEAR, false, str); } @@ -1735,25 +1736,25 @@ bool PartedCore::clearLV(const LVAction &lvAction) QString type = Utils::getFileSystemSoftWare(lvAction.m_lvFs); switch (lvAction.m_lvAct) { case LVM_ACT_LV_SECURE_CLEAR: - qDebug() << "LVM_ACT_LV_SECURE_CLEAR"; + qCDebug(serviceLog) << "LVM_ACT_LV_SECURE_CLEAR"; //清除算法 secuClear(lv.m_lvPath, 0, lv.m_lvLECount - 1, lv.m_LESize, type); //不要加break 如果是安全清除 还是需要创建文件系统的 case LVM_ACT_LV_FAST_CLEAR: { - qDebug() << "LVM_ACT_LV_FAST_CLEAR"; + qCDebug(serviceLog) << "LVM_ACT_LV_FAST_CLEAR"; QString tmpPath = QString("/dev/%1/%2").arg(lvAction.m_vgName).arg(lvAction.m_lvName); //判断是否加密 if (lvAction.m_luksFlag == LUKSFlag::IS_CRYPT_LUKS) { - qDebug() << "is crypt luks"; + qCDebug(serviceLog) << "is crypt luks"; LUKS_INFO info = getNewLUKSInfo(lvAction); //加密失败 if (!LUKSOperator::encrypt(m_LUKSInfo, info)) { - qDebug() << "encrypt failed"; + qCDebug(serviceLog) << "encrypt failed"; QString str = QString("%1:%2:%3").arg("CRYPTError").arg(CRYPTError::CRYPT_ERR_DECRYPT_FAILED).arg(lv.m_lvPath); return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CLEAR, false, str); } //解密失败 if (!LUKSOperator::decrypt(m_LUKSInfo, info)) { - qDebug() << "decrypt failed"; + qCDebug(serviceLog) << "decrypt failed"; QString str = QString("%1:%2:%3").arg("CRYPTError").arg(CRYPTError::CRYPT_ERR_DECRYPT_FAILED).arg(lv.m_lvPath); return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CLEAR, false, str); } @@ -1764,24 +1765,24 @@ bool PartedCore::clearLV(const LVAction &lvAction) //时虽然没有报错但实际上分区格式还是crypto_LUKS,这里先将分区从crypto_LUKS // 格式化为ext4,在将ext4格式化为exfat。 只有mkfs.exfat会有这种问题 if (lv.m_luksFlag == IS_CRYPT_LUKS && lvAction.m_lvFs == FS_EXFAT) { - qDebug() << "is crypt luks and exfat"; + qCDebug(serviceLog) << "is crypt luks and exfat"; QString output, error; auto errCode = Utils::executCmd(QString("mkfs.ext4 -F %1").arg(tmpPath), output, error); if (errCode != 0) { - qCritical() << "output:" << output << "\terror:" << error; + qCCritical(serviceLog) << "output:" << output << "\terror:" << error; } } //创建文件系统 if (!createFileSystem(lvAction.m_lvFs, false, tmpPath)) { - qDebug() << "createFileSystem failed"; + qCDebug(serviceLog) << "createFileSystem failed"; QString str = QString("%1:%2:%3").arg("LVMError").arg(LVMError::LVM_ERR_LV_CREATE_FS_FAILED).arg(lv.m_lvPath); return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CLEAR, false, str); } break; } default: - qDebug() << "default case"; + qCDebug(serviceLog) << "default case"; QString str = QString("%1:%2:%3").arg("LVMError").arg(LVMError::LVM_ERR_LV_ARGUMENT).arg(lv.m_lvPath); return sendRefSigAndReturn(false, DISK_SIGNAL_TYPE_CLEAR, false, str); } @@ -1789,27 +1790,27 @@ bool PartedCore::clearLV(const LVAction &lvAction) QString mountPath, devPath; //判断是否加密 if (lvAction.m_luksFlag == LUKSFlag::IS_CRYPT_LUKS) { - qDebug() << "is crypt luks"; + qCDebug(serviceLog) << "is crypt luks"; probeDeviceInfo(); LUKS_INFO info = m_LUKSInfo.getLUKS(lv.m_lvPath); //自动挂载 获取挂载文件夹名字 mountPath = getTmpMountPath(lvAction.m_user, info.m_mapper.m_fileSystemLabel, info.m_mapper.m_uuid, info.m_mapper.m_dmPath); devPath = info.m_mapper.m_dmPath; } else { - qDebug() << "not crypt luks"; + qCDebug(serviceLog) << "not crypt luks"; mountPath = getTmpMountPath(lvAction.m_user, lv.m_fileSystemLabel, lv.m_lvUuid, lv.m_lvPath); devPath = lv.m_lvPath; } QPairpair = tmpMountDevice(mountPath, devPath, lvAction.m_lvFs, lvAction.m_user); - qDebug() << __FUNCTION__ << "clearLV LV end"; + qCDebug(serviceLog) << __FUNCTION__ << "clearLV LV end"; return sendRefSigAndReturn(pair.first, DISK_SIGNAL_TYPE_CLEAR, pair.first, pair.second); } bool PartedCore::deletePVList(QList devList) { - qDebug() << "PartedCore::deletePVList BEGIN"; + qCDebug(serviceLog) << "PartedCore::deletePVList BEGIN"; if (m_workerLVMThread == nullptr) { - qDebug() << "m_workerLVMThread is null, create new thread"; + qCDebug(serviceLog) << "m_workerLVMThread is null, create new thread"; m_workerLVMThread = new QThread(); m_workerLVMThread->start(); m_lvmThread.moveToThread(m_workerLVMThread); @@ -1817,24 +1818,24 @@ bool PartedCore::deletePVList(QList devList) //线程启动信号 emit deletePVListStart(m_lvmInfo, devList); - qDebug() << "PartedCore::deletePVList END"; + qCDebug(serviceLog) << "PartedCore::deletePVList END"; return true; } int PartedCore::test() { - qDebug() << "PartedCore::test called"; + qCDebug(serviceLog) << "PartedCore::test called"; return 1; } /***********************************************public****************************************************************/ void PartedCore::setDeviceFromDisk(Device &device, const QString &devicePath) { - qDebug() << "PartedCore::setDeviceFromDisk BEGIN for device:" << devicePath; + qCDebug(serviceLog) << "PartedCore::setDeviceFromDisk BEGIN for device:" << devicePath; PedDevice *lpDevice = nullptr; PedDisk *lpDisk = nullptr; if (getDevice(devicePath, lpDevice, true)) { - qDebug() << "Successfully got device:" << devicePath; + qCDebug(serviceLog) << "Successfully got device:" << devicePath; device.m_heads = lpDevice->bios_geom.heads; device.m_length = lpDevice->length; device.m_path = devicePath; @@ -1845,34 +1846,34 @@ void PartedCore::setDeviceFromDisk(Device &device, const QString &devicePath) device.m_cylsize = device.m_heads * device.m_sectors; setDeviceSerialNumber(device); if (device.m_cylsize < (MEBIBYTE / device.m_sectorSize)) { - qDebug() << "Device cylinder size is less than MEBIBYTE / sectorSize, adjusting."; + qCDebug(serviceLog) << "Device cylinder size is less than MEBIBYTE / sectorSize, adjusting."; device.m_cylsize = MEBIBYTE / device.m_sectorSize; } FSType fstype = detectFilesystem(lpDevice, nullptr); if (fstype != FSType::FS_UNKNOWN) { - qDebug() << "Detected known filesystem:" << Utils::fileSystemTypeToString(fstype); + qCDebug(serviceLog) << "Detected known filesystem:" << Utils::fileSystemTypeToString(fstype); device.m_diskType = "none"; device.m_maxPrims = 1; setDeviceOnePartition(device, lpDevice, fstype); } else if (getDisk(lpDevice, lpDisk, false)) { - qDebug() << "Successfully got disk for partitioned drive."; + qCDebug(serviceLog) << "Successfully got disk for partitioned drive."; // Partitioned drive (excluding "loop"), as recognised by libparted if (lpDisk && lpDisk->type && lpDisk->type->name && strcmp(lpDisk->type->name, "loop") != 0) { - qDebug() << "Disk is partitioned and not a loop device. Type:" << lpDisk->type->name; + qCDebug(serviceLog) << "Disk is partitioned and not a loop device. Type:" << lpDisk->type->name; device.m_diskType = lpDisk->type->name; device.m_maxPrims = ped_disk_get_max_primary_partition_count(lpDisk); // Determine if partition naming is supported. if (ped_disk_type_check_feature(lpDisk->type, PED_DISK_TYPE_PARTITION_NAME)) { - qDebug() << "Partition naming supported."; + qCDebug(serviceLog) << "Partition naming supported."; device.enablePartitionNaming(Utils::getMaxPartitionNameLength(device.m_diskType)); } setDevicePartitions(device, lpDevice, lpDisk); if (device.m_highestBusy) { - qDebug() << "Device is busy, setting readonly flag."; + qCDebug(serviceLog) << "Device is busy, setting readonly flag."; device.m_readonly = !commitToOs(lpDisk); } } @@ -1880,7 +1881,7 @@ void PartedCore::setDeviceFromDisk(Device &device, const QString &devicePath) // else. (Actually any drive reported by libparted as "loop" but // not recognised by blkid on the whole disk device). else if (lpDisk && lpDisk->type && strcmp(lpDisk->type->name, "loop") == 0) { - qDebug() << "Disk is a loop device."; + qCDebug(serviceLog) << "Disk is a loop device."; // else if (lpDisk && lpDisk->type && lpDisk->type->name && strcmp(lpDisk->type->name, "loop") == 0) { device.m_diskType = lpDisk->type->name; //赋值 device.m_maxPrims = 1; //赋值 @@ -1899,7 +1900,7 @@ void PartedCore::setDeviceFromDisk(Device &device, const QString &devicePath) } // Unrecognised, unpartitioned drive. else { - qDebug() << "Unrecognized or unpartitioned drive."; + qCDebug(serviceLog) << "Unrecognized or unpartitioned drive."; device.m_diskType = "unrecognized"; device.m_maxPrims = 1; @@ -1913,22 +1914,22 @@ void PartedCore::setDeviceFromDisk(Device &device, const QString &devicePath) device.m_partitions.push_back(partition_temp); } } else { - qDebug() << "Failed to get disk for device:" << devicePath; + qCDebug(serviceLog) << "Failed to get disk for device:" << devicePath; } destroyDeviceAndDisk(lpDevice, lpDisk); } else { - qDebug() << "Failed to get device:" << devicePath; + qCDebug(serviceLog) << "Failed to get device:" << devicePath; } - qDebug() << "PartedCore::setDeviceFromDisk END for device:" << devicePath; + qCDebug(serviceLog) << "PartedCore::setDeviceFromDisk END for device:" << devicePath; } bool PartedCore::useableDevice(const PedDevice *lpDevice) { - qDebug() << "PartedCore::useableDevice BEGIN for device:" << lpDevice->path; + qCDebug(serviceLog) << "PartedCore::useableDevice BEGIN for device:" << lpDevice->path; Q_ASSERT(nullptr != lpDevice); char *buf = static_cast(malloc(lpDevice->sector_size)); if (!buf) { - qDebug() << "Failed to allocate buffer, returning false"; + qCDebug(serviceLog) << "Failed to allocate buffer, returning false"; return false; } @@ -1937,23 +1938,23 @@ bool PartedCore::useableDevice(const PedDevice *lpDevice) bool success = false; int fd = open(lpDevice->path, O_RDONLY | O_NONBLOCK); if (fd >= 0) { - qDebug() << "Successfully opened device file descriptor."; + qCDebug(serviceLog) << "Successfully opened device file descriptor."; ssize_t bytesRead = read(fd, buf, lpDevice->sector_size); success = (bytesRead == lpDevice->sector_size); close(fd); } free(buf); - qDebug() << "PartedCore::useableDevice END for device:" << lpDevice->path << "result:" << success; + qCDebug(serviceLog) << "PartedCore::useableDevice END for device:" << lpDevice->path << "result:" << success; return success; } bool PartedCore::delTempMountFile() { - qDebug() << "PartedCore::delTempMountFile BEGIN"; + qCDebug(serviceLog) << "PartedCore::delTempMountFile BEGIN"; QDir dir("/media"); QDir userPath; if (!dir.exists()) { - qDebug() << "/media directory does not exist, returning false"; + qCDebug(serviceLog) << "/media directory does not exist, returning false"; return false; } QStringList mountPath; @@ -1967,7 +1968,7 @@ bool PartedCore::delTempMountFile() for (; it != m_deviceMap.end() ; it++) { for (int i = 0; i < it->m_partitions.size(); i++) { if (mountPath.contains(it->m_partitions[i]->getMountPoint())) { - // qDebug() << "Mount path contains partition mount point, removing:" << it->m_partitions[i]->getMountPoint(); + // qCDebug(serviceLog) << "Mount path contains partition mount point, removing:" << it->m_partitions[i]->getMountPoint(); mountPath.removeOne(it->m_partitions[i]->getMountPoint()); } } @@ -1978,18 +1979,18 @@ bool PartedCore::delTempMountFile() for (int i = 0; i < mountPath.size(); i++) { getxattr(mountPath[i].toStdString().c_str(), "user.deepin-diskmanager", value, 1024); if (QString(value) == "deepin-diskmanager") { - qDebug() << "Found deepin-diskmanager xattr, removing directory:" << mountPath[i]; + qCDebug(serviceLog) << "Found deepin-diskmanager xattr, removing directory:" << mountPath[i]; d.rmdir(mountPath[i]); } } - qDebug() << "PartedCore::delTempMountFile END"; + qCDebug(serviceLog) << "PartedCore::delTempMountFile END"; return true; } /***********************************************private general****************************************************************/ void PartedCore::initConnection() { - qDebug() << "PartedCore::initConnection BEGIN"; + qCDebug(serviceLog) << "PartedCore::initConnection BEGIN"; connect(this, &PartedCore::refreshDeviceInfo, this, &PartedCore::onRefreshDeviceInfo); connect(this, &PartedCore::probeAllInfo, &m_probeThread, &ProbeThread::probeDeviceInfo); connect(&m_probeThread, &ProbeThread::updateDeviceInfo, this, &PartedCore::syncDeviceInfo); @@ -2007,21 +2008,21 @@ void PartedCore::initConnection() connect(this, &PartedCore::resizeVGStart, &m_lvmThread, &LVMThread::resizeVG); connect(&m_lvmThread, &LVMThread::deletePVListFinished, this, &PartedCore::deletePVListMessage); connect(&m_lvmThread, &LVMThread::resizeVGFinished, this, &PartedCore::resizeVGMessage); - qDebug() << "PartedCore::initConnection END"; + qCDebug(serviceLog) << "PartedCore::initConnection END"; } void PartedCore::findSupportedCore() { - qDebug() << "PartedCore::findSupportedCore BEGIN"; + qCDebug(serviceLog) << "PartedCore::findSupportedCore BEGIN"; //udevadm_found = !Utils::findProgramInPath("udevadm").isEmpty(); hdparmFound = !Utils::findProgramInPath("hdparm").isEmpty(); - qDebug() << "hdparmFound:" << hdparmFound; - qDebug() << "PartedCore::findSupportedCore END"; + qCDebug(serviceLog) << "hdparmFound:" << hdparmFound; + qCDebug(serviceLog) << "PartedCore::findSupportedCore END"; } void PartedCore::setDeviceSerialNumber(Device &device) { - qDebug() << "PartedCore::setDeviceSerialNumber BEGIN"; + qCDebug(serviceLog) << "PartedCore::setDeviceSerialNumber BEGIN"; if (!hdparmFound) // Serial number left blank when the hdparm command is not installed. return; @@ -2029,7 +2030,7 @@ void PartedCore::setDeviceSerialNumber(Device &device) QString output, error; Utils::executCmd(QString("hdparm -I %1").arg(device.m_path), output, error); if (error.isEmpty()) { - qDebug() << "error is empty"; + qCDebug(serviceLog) << "error is empty"; // hdparm reported an error message to stderr. Assume it's a device // without a hard drive serial number. // @@ -2043,41 +2044,41 @@ void PartedCore::setDeviceSerialNumber(Device &device) // SG_IO: bad/missing sense data, sb[]: 70 00 05 00 00 00 00 0a ... device.m_serialNumber = "none"; } else { - qDebug() << "error is not empty"; + qCDebug(serviceLog) << "error is not empty"; QString serialNumber = Utils::regexpLabel(output, "(?<=Serial Number:).*(?=\n)").trimmed(); if (!serialNumber.isEmpty()) { - qDebug() << "serialNumber is not empty"; + qCDebug(serviceLog) << "serialNumber is not empty"; device.m_serialNumber = serialNumber; } } // Otherwise serial number left blank when not found in the hdparm output. - qDebug() << "PartedCore::setDeviceSerialNumber END"; + qCDebug(serviceLog) << "PartedCore::setDeviceSerialNumber END"; } int PartedCore::getPartitionHiddenFlag() { - qDebug() << __FUNCTION__ << "Get Partition Hidden Flag start"; + qCDebug(serviceLog) << __FUNCTION__ << "Get Partition Hidden Flag start"; m_hiddenPartition.clear(); QFile file("/etc/udev/rules.d/80-udisks2.rules"); QStringList list; if (!file.open(QIODevice::ReadOnly)) { //打开指定文件 - qDebug() << __FUNCTION__ << "Permanent mount open file error"; + qCDebug(serviceLog) << __FUNCTION__ << "Permanent mount open file error"; file.close(); return -1; } else { m_hiddenPartition = file.readAll(); -// qDebug() << m_hiddenPartition; +// qCDebug(serviceLog) << m_hiddenPartition; } file.close(); - qDebug() << __FUNCTION__ << "Get Partition Hidden Flag end"; + qCDebug(serviceLog) << __FUNCTION__ << "Get Partition Hidden Flag end"; return 0; } bool PartedCore::gptIsExpanded(const QString &devicePath) { - qDebug() << __FUNCTION__ << "gptIsExpanded called"; + qCDebug(serviceLog) << __FUNCTION__ << "gptIsExpanded called"; /* GPT 与 MBR 分区格式的介绍可以参考下面的链接: * https://www.cnblogs.com/cwcheng/p/11270774.html @@ -2088,70 +2089,70 @@ bool PartedCore::gptIsExpanded(const QString &devicePath) int fd = ::open(devicePath.toLatin1().data(), O_RDONLY); if (fd < 0) { - qDebug() << "open device failed, return false"; + qCDebug(serviceLog) << "open device failed, return false"; return false; } int ret = ::read(fd, phdr, 1024); ::close(fd); if (ret < 0) { - qDebug() << "read device failed, return false"; + qCDebug(serviceLog) << "read device failed, return false"; return false; } if (0xee == phdr[offset]) { - qDebug() << "is GPT partition table"; + qCDebug(serviceLog) << "is GPT partition table"; gpt_header_t *gpt = (gpt_header_t *)(phdr + 512); for (auto it = m_deviceMap.begin(); it != m_deviceMap.end(); it++) { if (it.key() == devicePath) { Device dev = it.value(); - qDebug() << __FUNCTION__ << " CHEN Enum device : \t " << dev.m_length << " " << dev.m_sectors << " " << dev.m_heads; + qCDebug(serviceLog) << __FUNCTION__ << " CHEN Enum device : \t " << dev.m_length << " " << dev.m_sectors << " " << dev.m_heads; if (gpt->alternative_lba != (dev.m_length - 1)) { - qDebug() << "alternative_lba is not equal to dev.m_length - 1, return true"; + qCDebug(serviceLog) << "alternative_lba is not equal to dev.m_length - 1, return true"; return true; } } } } - qDebug() << "PartedCore::gptIsExpanded END"; + qCDebug(serviceLog) << "PartedCore::gptIsExpanded END"; return false; } void PartedCore::autoMount() { //因为永久挂载的原因需要先执行mount -a让系统文件挂载生效 - qDebug() << __FUNCTION__ << "solt automount start"; + qCDebug(serviceLog) << __FUNCTION__ << "solt automount start"; QString output, errstr; QString cmd = QString("mount -a"); int exitcode = Utils::executCmd(cmd, output, errstr); if (exitcode != 0) { -// qDebug() << __FUNCTION__ << output; - qDebug() << "mount -a failed"; +// qCDebug(serviceLog) << __FUNCTION__ << output; + qCDebug(serviceLog) << "mount -a failed"; } emit refreshDeviceInfo(DISK_SIGNAL_USBUPDATE); - qDebug() << __FUNCTION__ << "solt automount end"; + qCDebug(serviceLog) << __FUNCTION__ << "solt automount end"; } void PartedCore::autoUmount() { - qDebug() << "PartedCore::autoUmount BEGIN"; + qCDebug(serviceLog) << "PartedCore::autoUmount BEGIN"; QStringList deviceList; for (auto it = m_inforesult.begin(); it != m_inforesult.end(); it++) { deviceList << it.key(); } - qDebug() << "current deviceList: " << deviceList; + qCDebug(serviceLog) << "current deviceList: " << deviceList; QString outPut, error; QString cmd = QString("df"); int ret = Utils::executCmd(cmd, outPut, error); if (ret != 0) { - qDebug() << "Detection Partition Table Error order error"; + qCDebug(serviceLog) << "Detection Partition Table Error order error"; return; } QStringList outPutList = outPut.split("\n"); @@ -2170,56 +2171,56 @@ void PartedCore::autoUmount() } if (needUpdate) { - qDebug() << "needUpdate is true"; + qCDebug(serviceLog) << "needUpdate is true"; QStringList arg; arg << "-v" << mountPoint; QString output, errstr; int exitcode = Utils::executeCmdWithArtList("umount", arg, output, errstr); if (exitcode != 0) { - qDebug() << "Failed to umount point: " << mountPoint; + qCDebug(serviceLog) << "Failed to umount point: " << mountPoint; } } } } - qDebug() << "PartedCore::autoUmount END"; + qCDebug(serviceLog) << "PartedCore::autoUmount END"; } void PartedCore::probeDeviceInfo(const QString &) { - qDebug() << "PartedCore::probeDeviceInfo BEGIN"; + qCDebug(serviceLog) << "PartedCore::probeDeviceInfo BEGIN"; m_inforesult.clear(); m_deviceMap.clear(); QString rootFsName; QVector devicePaths; - //qDebug() << __FUNCTION__ << "**1"; + //qCDebug(serviceLog) << __FUNCTION__ << "**1"; devicePaths.clear(); BlockSpecial::clearCache(); - //qDebug() << __FUNCTION__ << "**2"; + //qCDebug(serviceLog) << __FUNCTION__ << "**2"; ProcPartitionsInfo::loadCache(); - //qDebug() << __FUNCTION__ << "**3"; + //qCDebug(serviceLog) << __FUNCTION__ << "**3"; FsInfo::loadCache(); - //qDebug() << __FUNCTION__ << "**4"; - //qDebug() << __FUNCTION__ << "**5"; + //qCDebug(serviceLog) << __FUNCTION__ << "**4"; + //qCDebug(serviceLog) << __FUNCTION__ << "**5"; MountInfo::loadCache(rootFsName); - //qDebug() << __FUNCTION__ << "**6"; + //qCDebug(serviceLog) << __FUNCTION__ << "**6"; ped_device_probe_all(); - //qDebug() << __FUNCTION__ << "**7"; + //qCDebug(serviceLog) << __FUNCTION__ << "**7"; PedDevice *lpDevice = ped_device_get_next(nullptr); while (lpDevice) { /* TO TRANSLATORS: looks like Confirming /dev/sda */ - qDebug() << QString("Confirming %1").arg(lpDevice->path); + qCDebug(serviceLog) << QString("Confirming %1").arg(lpDevice->path); //only add this device if we can read the first sector (which means it's a real device) if (useableDevice(lpDevice)) { - qDebug() << "Device is useable:" << lpDevice->path; + qCDebug(serviceLog) << "Device is useable:" << lpDevice->path; devicePaths.push_back(lpDevice->path); } -// qDebug() << lpDevice->path; +// qCDebug(serviceLog) << lpDevice->path; lpDevice = ped_device_get_next(lpDevice); } -// qDebug() << __FUNCTION__ << "devicepaths size=" << devicepaths.size(); +// qCDebug(serviceLog) << __FUNCTION__ << "devicepaths size=" << devicepaths.size(); std::sort(devicePaths.begin(), devicePaths.end()); - //qDebug() << __FUNCTION__ << "**8"; + //qCDebug(serviceLog) << __FUNCTION__ << "**8"; for (int t = 0; t < devicePaths.size(); t++) { /*TO TRANSLATORS: looks like Searching /dev/sda partitions */ Device tempDevice; @@ -2231,7 +2232,7 @@ void PartedCore::probeDeviceInfo(const QString &) m_deviceMap.insert(devicePaths.at(t), tempDevice); } - //qDebug() << __FUNCTION__ << "**9"; + //qCDebug(serviceLog) << __FUNCTION__ << "**9"; // getPartitionHiddenFlag(); for (auto it = m_deviceMap.begin(); it != m_deviceMap.end(); it++) { DeviceInfo devinfo = it.value().getDeviceInfo(); @@ -2249,10 +2250,10 @@ void PartedCore::probeDeviceInfo(const QString &) //partinfo = pat.getPartitionInfo(); if (rootFsName == pat.getPath()) { partinfo.m_flag = 4; - qDebug() << __FUNCTION__ << "Set systemfs Flags 1 !! " << pat.m_devicePath << " " << pat.m_name << " " << pat.m_uuid; + qCDebug(serviceLog) << __FUNCTION__ << "Set systemfs Flags 1 !! " << pat.m_devicePath << " " << pat.m_name << " " << pat.m_uuid; } - qDebug() << __FUNCTION__ << " EXTEND is " << PartitionType::TYPE_EXTENDED << " and I am " << pat.m_type; + qCDebug(serviceLog) << __FUNCTION__ << " EXTEND is " << PartitionType::TYPE_EXTENDED << " and I am " << pat.m_type; if (pat.m_type == PartitionType::TYPE_EXTENDED) { devinfo.m_partition.push_back(partinfo); for (int k = 0; k < pat.m_logicals.size(); k++) { @@ -2260,9 +2261,9 @@ void PartedCore::probeDeviceInfo(const QString &) partinfo = plogic.getPartitionInfo(); if (rootFsName == plogic.m_name) { partinfo.m_flag = 4; - qDebug() << __FUNCTION__ << "Set systemfs Flags2 !! " << plogic.m_devicePath << " " << plogic.m_name << " " << plogic.m_uuid; + qCDebug(serviceLog) << __FUNCTION__ << "Set systemfs Flags2 !! " << plogic.m_devicePath << " " << plogic.m_name << " " << plogic.m_uuid; } - qDebug() << __FUNCTION__ << plogic.m_devicePath << " " << plogic.m_name << " " << plogic.m_uuid; + qCDebug(serviceLog) << __FUNCTION__ << plogic.m_devicePath << " " << plogic.m_name << " " << plogic.m_uuid; devinfo.m_partition.push_back(partinfo); } } else { @@ -2273,41 +2274,41 @@ void PartedCore::probeDeviceInfo(const QString &) } LVMOperator::getDeviceDataAndLVMInfo(m_inforesult, m_lvmInfo); LUKSOperator::updateLUKSInfo(m_inforesult, m_lvmInfo, m_LUKSInfo); -// qDebug() << __FUNCTION__ << m_inforesult.count(); - //qDebug() << __FUNCTION__ << "**10"; +// qCDebug(serviceLog) << __FUNCTION__ << m_inforesult.count(); + //qCDebug(serviceLog) << __FUNCTION__ << "**10"; } void PartedCore::onRefreshDeviceInfo(int type, bool arg1, QString arg2) { - qDebug() << " will call probeThread in thread !"; + qCDebug(serviceLog) << " will call probeThread in thread !"; if (m_workerThreadProbe == nullptr) { - qDebug() << "m_workerThreadProbe is null, creating new thread"; + qCDebug(serviceLog) << "m_workerThreadProbe is null, creating new thread"; m_workerThreadProbe = new QThread(); - qDebug() << "onRefresh Create thread: " << QThread::currentThreadId() << " ++++++++" << m_workerThreadProbe << "\n"; - qDebug() << " ----------------------! 0 !--------------------- :" << m_probeThread.thread(); + qCDebug(serviceLog) << "onRefresh Create thread: " << QThread::currentThreadId() << " ++++++++" << m_workerThreadProbe << "\n"; + qCDebug(serviceLog) << " ----------------------! 0 !--------------------- :" << m_probeThread.thread(); m_probeThread.moveToThread(m_workerThreadProbe); m_workerThreadProbe->start(); } if (type == DISK_SIGNAL_USBUPDATE) { - qDebug() << "Type is DISK_SIGNAL_USBUPDATE"; + qCDebug(serviceLog) << "Type is DISK_SIGNAL_USBUPDATE"; m_usbSig = type; m_usbArg1 = arg1; m_usbArg2 = arg2; } else { - qDebug() << "Type is not DISK_SIGNAL_USBUPDATE"; + qCDebug(serviceLog) << "Type is not DISK_SIGNAL_USBUPDATE"; m_type = type; m_arg1 = arg1; m_arg2 = arg2; } emit probeAllInfo(); - qDebug() << " called probeThread in thread !"; + qCDebug(serviceLog) << " called probeThread in thread !"; } void PartedCore::syncDeviceInfo(/*const QMap deviceMap, */const DeviceInfoMap inforesult, const LVMInfo lvmInfo, const LUKSMap &luks) { - qDebug() << "syncDeviceInfo finally!"; + qCDebug(serviceLog) << "syncDeviceInfo finally!"; // foreach (auto dev, m_mountPointExclude) { // QString output, error; @@ -2323,7 +2324,7 @@ void PartedCore::syncDeviceInfo(/*const QMap deviceMap, */const emit updateDeviceInfo(m_inforesult, m_lvmInfo); if (m_usbSig == DISK_SIGNAL_USBUPDATE) { - qDebug() << "USB update signal received."; + qCDebug(serviceLog) << "USB update signal received."; emit usbUpdated(); m_usbSig = 0; m_usbArg1 = false; @@ -2333,65 +2334,65 @@ void PartedCore::syncDeviceInfo(/*const QMap deviceMap, */const //刷新线程结束,返回前端信息 switch (m_type) { case DISK_SIGNAL_TYPE_UMNT: - qDebug() << "Emitting unmountPartition signal."; + qCDebug(serviceLog) << "Emitting unmountPartition signal."; emit unmountPartition(m_arg2); break; case DISK_SIGNAL_TYPE_DEL: - qDebug() << "Emitting deletePartitionMessage signal."; + qCDebug(serviceLog) << "Emitting deletePartitionMessage signal."; emit deletePartitionMessage(m_arg2); break; case DISK_SIGNAL_TYPE_SHOW: - qDebug() << "Emitting showPartitionInfo signal."; + qCDebug(serviceLog) << "Emitting showPartitionInfo signal."; emit showPartitionInfo(m_arg2); break; case DISK_SIGNAL_TYPE_CREATE_TABLE: - qDebug() << "Emitting createTableMessage signal."; + qCDebug(serviceLog) << "Emitting createTableMessage signal."; emit createTableMessage(m_arg1); break; // case DISK_SIGNAL_USBUPDATE: // emit usbUpdated(); // break; case DISK_SIGNAL_TYPE_CLEAR: - qDebug() << "Emitting clearMessage signal."; + qCDebug(serviceLog) << "Emitting clearMessage signal."; emit clearMessage(m_arg2); break; case DISK_SIGNAL_TYPE_VGCREATE: - qDebug() << "Emitting vgCreateMessage signal."; + qCDebug(serviceLog) << "Emitting vgCreateMessage signal."; emit vgCreateMessage(m_arg2); break; case DISK_SIGNAL_TYPE_PVDELETE: - qDebug() << "Emitting pvDeleteMessage signal."; + qCDebug(serviceLog) << "Emitting pvDeleteMessage signal."; emit pvDeleteMessage(m_arg2); break; case DISK_SIGNAL_TYPE_VGDELETE: - qDebug() << "Emitting vgDeleteMessage signal."; + qCDebug(serviceLog) << "Emitting vgDeleteMessage signal."; emit vgDeleteMessage(m_arg2); break; case DISK_SIGNAL_TYPE_LVDELETE: - qDebug() << "Emitting lvDeleteMessage signal."; + qCDebug(serviceLog) << "Emitting lvDeleteMessage signal."; emit lvDeleteMessage(m_arg2); break; case DISK_SIGNAL_TYPE_CREATE_FAILED: - qDebug() << "Emitting createFailedMessage signal."; + qCDebug(serviceLog) << "Emitting createFailedMessage signal."; emit createFailedMessage(m_arg2); break; default: - qDebug() << "Unknown signal type."; + qCDebug(serviceLog) << "Unknown signal type."; break; } if (m_type != 0) { - qDebug() << "Resetting signal type and arguments."; + qCDebug(serviceLog) << "Resetting signal type and arguments."; m_type = 0; m_arg1 = false; m_arg2 = ""; } - qDebug() << "PartedCore::syncDeviceInfo END"; + qCDebug(serviceLog) << "PartedCore::syncDeviceInfo END"; } bool PartedCore::secuClear(const QString &path, const Sector &start, const Sector &end, const Byte_Value &size, const QString &fstype, const QString &name, const int &count) { - qDebug() << "PartedCore::secuClear BEGIN"; + qCDebug(serviceLog) << "PartedCore::secuClear BEGIN"; QString cmd, output, error; int exitCode = 0; long long allSecSize = (end - start + 1) * size; @@ -2402,78 +2403,78 @@ bool PartedCore::secuClear(const QString &path, const Sector &start, const Secto //清除末尾残留 for (int i = 0; i < count; ++i) { - // qDebug() << "Starting clear loop iteration:" << i; + // qCDebug(serviceLog) << "Starting clear loop iteration:" << i; int j = 0; while (j < tempEnd) { - // qDebug() << "Clearing 512M block at seek:" << j; + // qCDebug(serviceLog) << "Clearing 512M block at seek:" << j; //判断是否为块设备 stat(path.toStdString().c_str(), &fileStat); if (!S_ISBLK(fileStat.st_mode)) { - qDebug() << __FUNCTION__ << QString("%1 file not exit").arg(path); + qCDebug(serviceLog) << __FUNCTION__ << QString("%1 file not exit").arg(path); return false; } cmd = QString("dd if=/dev/zero of=%1 bs=512M count=1 seek=%2 conv=nocreat").arg(path).arg(j); exitCode = Utils::executCmd(cmd, output, error); if (exitCode != 0) { - qDebug() << __FUNCTION__ << QString("errorCode: %1, error: %2 ").arg(exitCode).arg(error); + qCDebug(serviceLog) << __FUNCTION__ << QString("errorCode: %1, error: %2 ").arg(exitCode).arg(error); return false; } j++; if (j >= tempEnd) { - qDebug() << "Reached end of tempEnd, breaking inner loop."; + qCDebug(serviceLog) << "Reached end of tempEnd, breaking inner loop."; break; } - qDebug() << __FUNCTION__ << QString("count size:%1M current size:%2M").arg(end - 1 * size / 1024 / 1024).arg(j * MEBIBYTE * 512); - qDebug() << __FUNCTION__ << QString("count num:%1 current num:%2").arg(tempEnd).arg(j); + qCDebug(serviceLog) << __FUNCTION__ << QString("count size:%1M current size:%2M").arg(end - 1 * size / 1024 / 1024).arg(j * MEBIBYTE * 512); + qCDebug(serviceLog) << __FUNCTION__ << QString("count num:%1 current num:%2").arg(tempEnd).arg(j); cmd = QString("dd if=/dev/urandom of=%1 bs=512M count=1 seek=%2 conv=nocreat").arg(path).arg(j); exitCode = Utils::executCmd(cmd, output, error); if (exitCode != 0 && j < tempEnd) { - qDebug() << __FUNCTION__ << QString("errorCode: %1, error: %2 ").arg(exitCode).arg(error); + qCDebug(serviceLog) << __FUNCTION__ << QString("errorCode: %1, error: %2 ").arg(exitCode).arg(error); return false; } j++; if (j >= tempEnd) { - qDebug() << "Reached end of tempEnd, breaking inner loop."; + qCDebug(serviceLog) << "Reached end of tempEnd, breaking inner loop."; break; } - qDebug() << __FUNCTION__ << QString("count size:%1M current size:%2M").arg(end - 1 * size / 1024 / 1024).arg(j * MEBIBYTE * 512); - qDebug() << __FUNCTION__ << QString("count num:%1 current num:%2").arg(tempEnd).arg(j); + qCDebug(serviceLog) << __FUNCTION__ << QString("count size:%1M current size:%2M").arg(end - 1 * size / 1024 / 1024).arg(j * MEBIBYTE * 512); + qCDebug(serviceLog) << __FUNCTION__ << QString("count num:%1 current num:%2").arg(tempEnd).arg(j); } //清除末尾残留 if (tmpSize > 0) { - // qDebug() << "Clearing remaining tail data."; + // qCDebug(serviceLog) << "Clearing remaining tail data."; stat(path.toStdString().c_str(), &fileStat); if (!S_ISBLK(fileStat.st_mode)) { - qDebug() << __FUNCTION__ << QString("%1 file not exit").arg(path); + qCDebug(serviceLog) << __FUNCTION__ << QString("%1 file not exit").arg(path); return false; } cmd = QString("dd if=/dev/zero of=%1 bs=%2 count=1 seek=%3 conv=nocreat oflag=seek_bytes").arg(path).arg(tmpSize).arg(j * (MEBIBYTE * 512)); exitCode = Utils::executCmd(cmd, output, error); if (exitCode != 0) { - qDebug() << __FUNCTION__ << QString("errorCode: %1, error: ").arg(exitCode).arg(error); + qCDebug(serviceLog) << __FUNCTION__ << QString("errorCode: %1, error: ").arg(exitCode).arg(error); return false; } } - qDebug() << __FUNCTION__ << " secuClear end "; - qDebug() << __FUNCTION__ << QString("count loop:%1 current loop:%2 ").arg(count).arg(i); + qCDebug(serviceLog) << __FUNCTION__ << " secuClear end "; + qCDebug(serviceLog) << __FUNCTION__ << QString("count loop:%1 current loop:%2 ").arg(count).arg(i); } - qDebug() << "PartedCore::secuClear END"; + qCDebug(serviceLog) << "PartedCore::secuClear END"; return true; } /***********************************************private gparted****************************************************************/ bool PartedCore::getDevice(const QString &devicePath, PedDevice *&lpDevice, bool flush) { - qDebug() << "PartedCore::getDevice BEGIN for device:" << devicePath << ", flush:" << flush; + qCDebug(serviceLog) << "PartedCore::getDevice BEGIN for device:" << devicePath << ", flush:" << flush; lpDevice = ped_device_get(devicePath.toStdString().c_str()); @@ -2487,30 +2488,30 @@ bool PartedCore::getDevice(const QString &devicePath, PedDevice *&lpDevice, bool int ret = ioctl(fd, HDIO_GETGEO, &geo); if (0 == ret && geo.sectors > lpDevice->bios_geom.sectors) { - qDebug() << "Updating device geometry based on ioctl."; + qCDebug(serviceLog) << "Updating device geometry based on ioctl."; lpDevice->bios_geom.sectors = geo.sectors; lpDevice->bios_geom.cylinders = lpDevice->length / (geo.heads * geo.sectors); } close(fd); if (lpDevice) { - qDebug() << "Device found:" << lpDevice->path; + qCDebug(serviceLog) << "Device found:" << lpDevice->path; if (flush) // Force cache coherency before going on to read the partition // table so that libparted reading the whole disk device and the // file system tools reading the partition devices read the same // data. flushDevice(lpDevice); - qDebug() << "PartedCore::getDevice END, device found."; + qCDebug(serviceLog) << "PartedCore::getDevice END, device found."; return true; } - qDebug() << "PartedCore::getDevice END, device not found."; + qCDebug(serviceLog) << "PartedCore::getDevice END, device not found."; return false; } bool PartedCore::getDisk(PedDevice *&lpDevice, PedDisk *&lpDisk, bool strict) { - qDebug() << "PartedCore::getDisk BEGIN for device:" << lpDevice->path << ", strict:" << strict; + qCDebug(serviceLog) << "PartedCore::getDisk BEGIN for device:" << lpDevice->path << ", strict:" << strict; if (lpDevice) { lpDisk = ped_disk_new(lpDevice); @@ -2525,87 +2526,87 @@ bool PartedCore::getDisk(PedDevice *&lpDevice, PedDisk *&lpDisk, bool strict) // We return true here and deal with them in // GParted_Core::setDeviceFromDisk(). if (lpDisk || (!strict && !lpDevice->read_only)) { - qDebug() << "Disk found or not strict and not read-only, returning true."; + qCDebug(serviceLog) << "Disk found or not strict and not read-only, returning true."; return true; } destroyDeviceAndDisk(lpDevice, lpDisk); } - qDebug() << "PartedCore::getDisk END, returning false."; + qCDebug(serviceLog) << "PartedCore::getDisk END, returning false."; return false; } bool PartedCore::getDeviceAndDisk(const QString &devicePath, PedDevice *&lpDevice, PedDisk *&lpDisk, bool strict, bool flush) { - qDebug() << "PartedCore::getDeviceAndDisk BEGIN for device:" << devicePath << ", strict:" << strict << ", flush:" << flush; + qCDebug(serviceLog) << "PartedCore::getDeviceAndDisk BEGIN for device:" << devicePath << ", strict:" << strict << ", flush:" << flush; if (getDevice(devicePath, lpDevice, flush)) { - qDebug() << "Successfully got device, now getting disk."; + qCDebug(serviceLog) << "Successfully got device, now getting disk."; return getDisk(lpDevice, lpDisk, strict); } - qDebug() << "Failed to get device, returning false."; + qCDebug(serviceLog) << "Failed to get device, returning false."; return false; } void PartedCore::destroyDeviceAndDisk(PedDevice *&lpDevice, PedDisk *&lpDisk) { - qDebug() << "PartedCore::destroyDeviceAndDisk BEGIN"; + qCDebug(serviceLog) << "PartedCore::destroyDeviceAndDisk BEGIN"; if (lpDisk) { - qDebug() << "Destroying PedDisk."; + qCDebug(serviceLog) << "Destroying PedDisk."; ped_disk_destroy(lpDisk); } lpDisk = nullptr; if (lpDevice) { - qDebug() << "Destroying PedDevice."; + qCDebug(serviceLog) << "Destroying PedDevice."; ped_device_destroy(lpDevice); } lpDevice = nullptr; - qDebug() << "PartedCore::destroyDeviceAndDisk END"; + qCDebug(serviceLog) << "PartedCore::destroyDeviceAndDisk END"; } bool PartedCore::isBusy(FSType fstype, const QString &path, const PedPartition *lpPartition) { - qDebug() << "PartedCore::isBusy BEGIN for fstype:" << Utils::fileSystemTypeToString(fstype) << ", path:" << path; + qCDebug(serviceLog) << "PartedCore::isBusy BEGIN for fstype:" << Utils::fileSystemTypeToString(fstype) << ", path:" << path; FileSystem *pFilesystem = nullptr; bool busy = false; if (nullptr != lpPartition) { busy = ped_partition_is_busy(lpPartition); - qDebug() << "PedPartition is busy:" << busy; + qCDebug(serviceLog) << "PedPartition is busy:" << busy; } if (!busy && supportedFileSystem(fstype)) { - qDebug() << "Filesystem is supported and not busy from PedPartition. Checking further."; + qCDebug(serviceLog) << "Filesystem is supported and not busy from PedPartition. Checking further."; switch (getFileSystem(fstype).busy) { case FS::GPARTED: - qDebug() << "Checking GPARTED busy status."; + qCDebug(serviceLog) << "Checking GPARTED busy status."; //Search GParted internal mounted partitions map busy = MountInfo::isDevMounted(path); - qDebug() << "MountInfo reports busy:" << busy; + qCDebug(serviceLog) << "MountInfo reports busy:" << busy; break; case FS::EXTERNAL: - qDebug() << "Checking EXTERNAL busy status."; + qCDebug(serviceLog) << "Checking EXTERNAL busy status."; //Call file system specific method pFilesystem = getFileSystemObject(fstype); if (pFilesystem) { busy = pFilesystem->isBusy(path); - qDebug() << "Filesystem object reports busy:" << busy; + qCDebug(serviceLog) << "Filesystem object reports busy:" << busy; } break; default: - qDebug() << "Unknown busy status type."; + qCDebug(serviceLog) << "Unknown busy status type."; break; } } - qDebug() << "PartedCore::isBusy END, result:" << busy; + qCDebug(serviceLog) << "PartedCore::isBusy END, result:" << busy; return busy; } bool PartedCore::flushDevice(PedDevice *lpDevice) { - qDebug() << "PartedCore::flushDevice BEGIN for device:" << lpDevice->path; + qCDebug(serviceLog) << "PartedCore::flushDevice BEGIN for device:" << lpDevice->path; bool success = false; if (ped_device_open(lpDevice)) { - qDebug() << "Device opened successfully."; + qCDebug(serviceLog) << "Device opened successfully."; success = ped_device_sync(lpDevice); ped_device_close(lpDevice); // (!46) Wait for udev rules to complete after this ped_device_open() and @@ -2616,13 +2617,13 @@ bool PartedCore::flushDevice(PedDevice *lpDevice) QString out, err; Utils::executCmd(QString("udevadm settle --timeout=%1").arg(SETTLE_DEVICE_PROBE_MAX_WAIT_SECONDS), out, err); } - qDebug() << "PartedCore::flushDevice END, result:" << success; + qCDebug(serviceLog) << "PartedCore::flushDevice END, result:" << success; return success; } bool PartedCore::commit(PedDisk *lpDisk) { - qDebug() << "PartedCore::commit BEGIN"; + qCDebug(serviceLog) << "PartedCore::commit BEGIN"; bool opened = ped_device_open(lpDisk->dev); bool succeed = ped_disk_commit_to_dev(lpDisk); @@ -2631,65 +2632,65 @@ bool PartedCore::commit(PedDisk *lpDisk) if (opened) { ped_device_close(lpDisk->dev); - qDebug() << "Device closed after commit."; + qCDebug(serviceLog) << "Device closed after commit."; // Wait for udev rules to complete and partition device nodes to settle // from this ped_device_close(). //settleDevice(SETTLE_DEVICE_PROBE_MAX_WAIT_SECONDS); QString out, err; Utils::executCmd(QString("udevadm settle --timeout=%1").arg(SETTLE_DEVICE_PROBE_MAX_WAIT_SECONDS), out, err); - qDebug() << "udevadm settle command executed after closing device."; + qCDebug(serviceLog) << "udevadm settle command executed after closing device."; } - qDebug() << "PartedCore::commit END, result:" << succeed; + qCDebug(serviceLog) << "PartedCore::commit END, result:" << succeed; return succeed; } bool PartedCore::commitToOs(PedDisk *lpDisk) { - qDebug() << "PartedCore::commitToOs BEGIN"; + qCDebug(serviceLog) << "PartedCore::commitToOs BEGIN"; // bool succes; // succes = ped_disk_commit_to_os(lpDisk); // Wait for udev rules to complete and partition device nodes to settle from above // ped_disk_commit_to_os() initiated kernel update of the partitions. //settleDevice(timeout); bool result = ped_disk_commit_to_os(lpDisk); - qDebug() << "PartedCore::commitToOs END, result:" << result; + qCDebug(serviceLog) << "PartedCore::commitToOs END, result:" << result; return result; } bool PartedCore::infoBelongToPartition(const Partition &partition, const PartitionInfo &info) { - qDebug() << "PartedCore::infoBelongToPartition BEGIN"; + qCDebug(serviceLog) << "PartedCore::infoBelongToPartition BEGIN"; bool result = info.m_sectorEnd == partition.m_sectorEnd && info.m_sectorStart == partition.m_sectorStart; - qDebug() << "PartedCore::infoBelongToPartition END, result:" << result; + qCDebug(serviceLog) << "PartedCore::infoBelongToPartition END, result:" << result; return result; } PedPartition *PartedCore::getLpPartition(const PedDisk *lpDisk, const Partition &partition) { - qDebug() << "PartedCore::getLpPartition BEGIN"; + qCDebug(serviceLog) << "PartedCore::getLpPartition BEGIN"; if (partition.m_type == PartitionType::TYPE_EXTENDED) { - qDebug() << "Partition type is EXTENDED."; + qCDebug(serviceLog) << "Partition type is EXTENDED."; return ped_disk_extended_partition(lpDisk); } - qDebug() << "Partition type is not EXTENDED, getting by sector."; + qCDebug(serviceLog) << "Partition type is not EXTENDED, getting by sector."; return ped_disk_get_partition_by_sector(lpDisk, partition.getSector()); } void PartedCore::setDeviceOnePartition(Device &device, PedDevice *lpDevice, FSType fstype) { - qDebug() << "PartedCore::setDeviceOnePartition BEGIN for device:" << device.m_path << ", fstype:" << Utils::fileSystemTypeToString(fstype); + qCDebug(serviceLog) << "PartedCore::setDeviceOnePartition BEGIN for device:" << device.m_path << ", fstype:" << Utils::fileSystemTypeToString(fstype); device.m_partitions.clear(); QString path(lpDevice->path); bool partitionIsBusy = isBusy(fstype, path); Partition *partitionTemp = nullptr; if (fstype == FSType::FS_LUKS) { - qDebug() << "Filesystem is LUKS, setting partitionTemp to nullptr."; + qCDebug(serviceLog) << "Filesystem is LUKS, setting partitionTemp to nullptr."; partitionTemp = nullptr; //= new PartitionLUKS(); return; } else { - qDebug() << "Filesystem is not LUKS, creating new Partition."; + qCDebug(serviceLog) << "Filesystem is not LUKS, creating new Partition."; partitionTemp = new Partition(); } // if (nullptr == partitionTemp) @@ -2705,7 +2706,7 @@ void PartedCore::setDeviceOnePartition(Device &device, PedDevice *lpDevice, FSTy // set_luks_partition( *dynamic_cast( partition_temp ) ); if (partitionTemp->m_busy) { - qDebug() << "Partition is busy, setting highestBusy flag."; + qCDebug(serviceLog) << "Partition is busy, setting highestBusy flag."; device.m_highestBusy = 1; } @@ -2713,23 +2714,23 @@ void PartedCore::setDeviceOnePartition(Device &device, PedDevice *lpDevice, FSTy setMountPoints(*partitionTemp); setUsedSectors(*partitionTemp, nullptr); device.m_partitions.push_back(partitionTemp); - qDebug() << "PartedCore::setDeviceOnePartition END"; + qCDebug(serviceLog) << "PartedCore::setDeviceOnePartition END"; } void PartedCore::setPartitionLabelAndUuid(Partition &partition) { - qDebug() << "PartedCore::setPartitionLabelAndUuid BEGIN for partition:" << partition.getPath(); + qCDebug(serviceLog) << "PartedCore::setPartitionLabelAndUuid BEGIN for partition:" << partition.getPath(); QString partitionPath = partition.getPath(); readLabel(partition); if (!partition.filesystemLabelKnown()) { - qDebug() << "Filesystem label not known, attempting to get from FsInfo."; + qCDebug(serviceLog) << "Filesystem label not known, attempting to get from FsInfo."; bool labelFound = false; QString label = FsInfo::getLabel(partitionPath, labelFound); if (labelFound) { - qDebug() << "Label found:" << label; + qCDebug(serviceLog) << "Label found:" << label; partition.setFilesystemLabel(label); } else { - qDebug() << "Label not found."; + qCDebug(serviceLog) << "Label not found."; } } @@ -2738,30 +2739,30 @@ void PartedCore::setPartitionLabelAndUuid(Partition &partition) partition.m_uuid = FsInfo::getUuid(partitionPath); partition.m_name = partitionPath; if (partition.m_uuid.isEmpty()) { - qDebug() << "UUID is empty, attempting to read from partition."; + qCDebug(serviceLog) << "UUID is empty, attempting to read from partition."; readUuid(partition); } else { - qDebug() << "UUID found:" << partition.m_uuid; + qCDebug(serviceLog) << "UUID found:" << partition.m_uuid; } - qDebug() << "PartedCore::setPartitionLabelAndUuid END"; + qCDebug(serviceLog) << "PartedCore::setPartitionLabelAndUuid END"; } void PartedCore::setMountPoints(Partition &partition) { - qDebug() << "PartedCore::setMountPoints BEGIN for partition:" << partition.getPath(); + qCDebug(serviceLog) << "PartedCore::setMountPoints BEGIN for partition:" << partition.getPath(); //DMRaid dmraid ; //Use cache of dmraid device information if (partition.m_fstype == FSType::FS_LVM2_PV) { - qDebug() << "Filesystem type is LVM2_PV, skipping mount point setting."; + qCDebug(serviceLog) << "Filesystem type is LVM2_PV, skipping mount point setting."; // QString vgname = LVM2_PV_Info::get_vg_name(partition.getPath()); // if (! vgname.isEmpty()) // partition.addMountPoint(vgname); } else if (partition.m_fstype == FSType::FS_LINUX_SWRAID) { - qDebug() << "Filesystem type is LINUX_SWRAID, skipping mount point setting."; + qCDebug(serviceLog) << "Filesystem type is LINUX_SWRAID, skipping mount point setting."; // QString array_path = SWRaid_Info::get_array(partition.getPath()); // if (! array_path.isEmpty()) // partition.addMountPoint(array_path); } else if (partition.m_fstype == FSType::FS_ATARAID) { - qDebug() << "Filesystem type is ATARAID, skipping mount point setting."; + qCDebug(serviceLog) << "Filesystem type is ATARAID, skipping mount point setting."; // QString array_path = SWRaid_Info::get_array(partition.getPath()); // if (! array_path.isEmpty()) { // partition.addMountPoint(array_path); @@ -2771,53 +2772,53 @@ void PartedCore::setMountPoints(Partition &partition) // partition.addMountPoint(array_path); // } } else if (partition.m_fstype == FSType::FS_LUKS) { - qDebug() << "Filesystem type is LUKS, skipping mount point setting."; + qCDebug(serviceLog) << "Filesystem type is LUKS, skipping mount point setting."; // LUKS_Mapping mapping = LUKS_Info::get_cache_entry(partition.getPath()); // if (! mapping.name.isEmpty()) // partition.addMountPoint(DEV_MAPPER_PATH + mapping.name); } // Swap spaces don't have mount points so don't bother trying to add them. else if (partition.m_fstype != FSType::FS_LINUX_SWAP) { - qDebug() << "Filesystem type is not LINUX_SWAP."; + qCDebug(serviceLog) << "Filesystem type is not LINUX_SWAP."; if (partition.m_busy) { - qDebug() << "Partition is busy, attempting to find mount point helper."; + qCDebug(serviceLog) << "Partition is busy, attempting to find mount point helper."; // Normal device, not DMRaid device if (setMountPointsHelper(partition, partition.getPath())) { - qDebug() << "Mount points set by helper, returning."; + qCDebug(serviceLog) << "Mount points set by helper, returning."; return; } - qDebug() << __FUNCTION__ << "xxxUnable to find mount point"; + qCDebug(serviceLog) << __FUNCTION__ << "xxxUnable to find mount point"; } else { // Not busy file system - qDebug() << "Partition is not busy, getting mount points from file system table."; + qCDebug(serviceLog) << "Partition is not busy, getting mount points from file system table."; partition.addMountPoints(MountInfo::getFileSystemTableMountpoints(partition.getPath())); } } - qDebug() << "PartedCore::setMountPoints END"; + qCDebug(serviceLog) << "PartedCore::setMountPoints END"; } bool PartedCore::setMountPointsHelper(Partition &partition, const QString &path) { - qDebug() << "PartedCore::setMountPointsHelper BEGIN for partition:" << partition.getPath() << ", path:" << path; + qCDebug(serviceLog) << "PartedCore::setMountPointsHelper BEGIN for partition:" << partition.getPath() << ", path:" << path; QString searchPath; if (partition.m_fstype == FSType::FS_BTRFS) { - qDebug() << "Filesystem type is BTRFS, setting searchPath to path."; + qCDebug(serviceLog) << "Filesystem type is BTRFS, setting searchPath to path."; searchPath = path; //btrfs.h::get_mount_device( path ) ; } else { - qDebug() << "Filesystem type is not BTRFS, setting searchPath to path."; + qCDebug(serviceLog) << "Filesystem type is not BTRFS, setting searchPath to path."; searchPath = path; } const QVector &mountpoints = MountInfo::getMountedMountpoints(searchPath); if (mountpoints.size()) { - qDebug() << "Mount points found, adding to partition."; + qCDebug(serviceLog) << "Mount points found, adding to partition."; partition.addMountPoints(mountpoints); partition.m_fsReadonly = MountInfo::isDevMountedReadonly(searchPath); - qDebug() << "PartedCore::setMountPointsHelper END, result: true"; + qCDebug(serviceLog) << "PartedCore::setMountPointsHelper END, result: true"; return true; } - qDebug() << "PartedCore::setMountPointsHelper END, result: false"; + qCDebug(serviceLog) << "PartedCore::setMountPointsHelper END, result: false"; return false; } @@ -2869,7 +2870,7 @@ void PartedCore::setUsedSectors(Partition &partition, PedDisk *lpDisk) if (!Utils::getFileSystemSoftWare(partition.m_fstype).isEmpty()) { QString msg("The following list of software packages is required for %1 file system support: %2."); msg = msg.arg(Utils::fileSystemTypeToString(partition.m_fstype)).arg(Utils::getFileSystemSoftWare(partition.m_fstype)); - qDebug() << __FUNCTION__ << msg; + qCDebug(serviceLog) << __FUNCTION__ << msg; } } else if ((unallocated = partition.getSectorsUnallocated()) > 0) { @@ -2880,7 +2881,7 @@ void PartedCore::setUsedSectors(Partition &partition, PedDisk *lpDisk) if (fs.check != FS::NONE && fs.grow != FS::NONE) { temp.append("To grow the file system to fill the partition, select the partition and choose the menu item:\n"); temp.append("Partition --> Check."); - qDebug() << __FUNCTION__ << temp; + qCDebug(serviceLog) << __FUNCTION__ << temp; } } @@ -2923,7 +2924,7 @@ void PartedCore::setDevicePartitions(Device &device, PedDevice *lpDevice, PedDis fstype = detectFilesystem(lpDevice, lpPartition); partitionPath = getPartitionPath(lpPartition); partitionIsBusy = isBusy(fstype, partitionPath, lpPartition); - qDebug() << partitionIsBusy << lpPartition->num << lpPartition->disk->dev->path; + qCDebug(serviceLog) << partitionIsBusy << lpPartition->num << lpPartition->disk->dev->path; // if (fstype == FS_LUKS) // partition_temp = new PartitionLUKS(); // else @@ -2970,7 +2971,7 @@ void PartedCore::setDevicePartitions(Device &device, PedDevice *lpDevice, PedDis break; default: - qDebug() << ped_partition_is_busy(lpPartition) << lpPartition->num << lpPartition->disk->dev->path; + qCDebug(serviceLog) << ped_partition_is_busy(lpPartition) << lpPartition->num << lpPartition->disk->dev->path; // Ignore libparted reported partitions with other type // bits set. break; @@ -3048,7 +3049,7 @@ FSType PartedCore::detectFilesystem(PedDevice *lpDevice, PedPartition *lpPartiti fileSystemName = lpPartition->fs_type->name; if (!fileSystemName.isEmpty()) { fsType = Utils::stringToFileSystemType(fileSystemName); -// qDebug() << fstype; +// qCDebug(serviceLog) << fstype; if (fsType != FSType::FS_UNKNOWN) return fsType; } @@ -3063,7 +3064,7 @@ FSType PartedCore::detectFilesystem(PedDevice *lpDevice, PedPartition *lpPartiti .append("The file system is unknown to GParted \n-") .append("There is no file system available (unformatted) \n- ") .append(QString("The device entry %1 is missing").arg(path)); - qDebug() << __FUNCTION__ << temp; + qCDebug(serviceLog) << __FUNCTION__ << temp; return FSType::FS_UNKNOWN; } @@ -3216,7 +3217,7 @@ bool PartedCore::namePartition(const Partition &partition) msg = QString("Clear partition name on %1").arg(partition.getPath()); else msg = QString("Set partition name to \"%1\" on %2").arg(partition.m_name).arg(partition.getPath()); - qDebug() << __FUNCTION__ << msg; + qCDebug(serviceLog) << __FUNCTION__ << msg; bool success = false; PedDevice *lpDevice = nullptr; @@ -3234,12 +3235,12 @@ bool PartedCore::namePartition(const Partition &partition) bool PartedCore::eraseFilesystemSignatures(const Partition &partition) { if (partition.m_fstype == FS_LUKS && partition.m_busy) { - qDebug() << __FUNCTION__ << "partition contains open LUKS encryption for an erase file system signatures only step"; + qCDebug(serviceLog) << __FUNCTION__ << "partition contains open LUKS encryption for an erase file system signatures only step"; return false; } bool overallSuccess = false; - qDebug() << __FUNCTION__ << QString("clear old file system signatures in %1").arg(partition.getPath()); + qCDebug(serviceLog) << __FUNCTION__ << QString("clear old file system signatures in %1").arg(partition.getPath()); //Get device, disk & partition and open the device. Allocate buffer and fill with // zeros. Buffer size is the greater of 4 KiB and the sector size. @@ -3359,7 +3360,7 @@ bool PartedCore::setPartitionType(const Partition &partition) // Trying to set the type of a partition on a non-partitioned whole disk // device is a successful non-operation. return true; - qDebug() << __FUNCTION__ << QString("set partition type on %1").arg(partition.getPath()); + qCDebug(serviceLog) << __FUNCTION__ << QString("set partition type on %1").arg(partition.getPath()); //Set partition type appropriately for the type of file system stored in the partition. // Libparted treats every type as a file system, except LVM which it treats as a flag. @@ -3396,7 +3397,7 @@ bool PartedCore::setPartitionType(const Partition &partition) // Also clear any libparted LVM flag so that it doesn't // override the file system type if ((!supportsLvmFlag || ped_partition_set_flag(lpPartition, PED_PARTITION_LVM, 0)) && ped_partition_set_system(lpPartition, lpFsType) && commit(lpDisk)) { - qDebug() << __FUNCTION__ << QString("new partition type: %1").arg(lpPartition->fs_type->name); + qCDebug(serviceLog) << __FUNCTION__ << QString("new partition type: %1").arg(lpPartition->fs_type->name); returnValue = true; } } else if (partition.m_fstype == FS_LVM2_PV) { @@ -3420,7 +3421,7 @@ bool PartedCore::formatPartition(const Partition &partition) { bool success = false; if (partition.m_fstype == FS_LUKS && partition.m_busy) { - qDebug() << __FUNCTION__ << QString("partition contains open LUKS encryption for a format files system only step"); + qCDebug(serviceLog) << __FUNCTION__ << QString("partition contains open LUKS encryption for a format files system only step"); return false; } @@ -3543,10 +3544,10 @@ bool PartedCore::resizeMovePartitionImplement(const Partition &partitionOld, con bool PartedCore::maxImizeFileSystem(const Partition &partition) { if (partition.m_fstype == FS_LUKS && partition.m_busy) { - qDebug() << "PartedCore::maxImizeFileSystem: partition contains open LUKS encryption for a maximize file system only step"; + qCDebug(serviceLog) << "PartedCore::maxImizeFileSystem: partition contains open LUKS encryption for a maximize file system only step"; return false; } - qDebug() << "PartedCore::maxImizeFileSystem: grow file system to fill the partition"; + qCDebug(serviceLog) << "PartedCore::maxImizeFileSystem: grow file system to fill the partition"; // Checking if growing is available or allowed is only relevant for the check // repair operation to inform the user why the grow step is being skipped. For a @@ -3555,7 +3556,7 @@ bool PartedCore::maxImizeFileSystem(const Partition &partition) // Win_GParted::set_valid_operations() and // Dialog_Partition_Resize_Move::Resize_Move_Normal(). if (getFileSystem(partition.m_fstype).grow == FS::NONE) { - qDebug() << "PartedCore::maxImizeFileSystem:growing is not available for this file system"; + qCDebug(serviceLog) << "PartedCore::maxImizeFileSystem:growing is not available for this file system"; // return true; return formatPartition(partition); } @@ -3675,7 +3676,7 @@ void PartedCore::reWritePartition(const QString &devicePath) struct stat fileStat; stat(devicePath.toStdString().c_str(), &fileStat); if (!S_ISBLK(fileStat.st_mode)) { - qDebug() << __FUNCTION__ << QString("%1 is not blk file").arg(devicePath); + qCDebug(serviceLog) << __FUNCTION__ << QString("%1 is not blk file").arg(devicePath); return; } @@ -3685,7 +3686,7 @@ void PartedCore::reWritePartition(const QString &devicePath) QString cmdFix = QString("fdisk %1").arg(devicePath); QString intPut("w"); Utils::executWithInputOutputCmd(cmdFix, &intPut, outPutFix, errorFix); - qDebug() << __FUNCTION__ << "createPartition Partition Table Rewrite Done"; + qCDebug(serviceLog) << __FUNCTION__ << "createPartition Partition Table Rewrite Done"; return; } } @@ -3766,7 +3767,7 @@ bool PartedCore::create(Partition &newPartition) bool PartedCore::createPartition(Partition &newPartition, Sector minSize) { - qDebug() << __FUNCTION__ << "create empty partition from:" << newPartition.m_devicePath; + qCDebug(serviceLog) << __FUNCTION__ << "create empty partition from:" << newPartition.m_devicePath; newPartition.m_partitionNumber = 0; PedDevice *lpDevice = nullptr; PedDisk *lpDisk = nullptr; @@ -3789,7 +3790,7 @@ bool PartedCore::createPartition(Partition &newPartition, Sector minSize) // if (fixfd) { // pclose(fixfd); // } -// qDebug() << __FUNCTION__ << "createPartition Partition Table Rewrite Done"; +// qCDebug(serviceLog) << __FUNCTION__ << "createPartition Partition Table Rewrite Done"; // } // } @@ -3982,11 +3983,11 @@ FS_Limits PartedCore::getFileSystemLimits(FSType fstype, const Partition &partit bool PartedCore::createFileSystem(const Partition &partition) { if (partition.m_fstype == FS_LUKS && partition.m_busy) { - qDebug() << __FUNCTION__ << QString("partition contains open LUKS encryption for a create file system only step"); + qCDebug(serviceLog) << __FUNCTION__ << QString("partition contains open LUKS encryption for a create file system only step"); return false; } -// qDebug() << __FUNCTION__ << partition.m_sectorsUsed << partition.m_sectorsUnused; - qDebug() << __FUNCTION__ << QString("create new %1 file system").arg(partition.m_fstype); +// qCDebug(serviceLog) << __FUNCTION__ << partition.m_sectorsUsed << partition.m_sectorsUnused; + qCDebug(serviceLog) << __FUNCTION__ << QString("create new %1 file system").arg(partition.m_fstype); bool succes = false; FileSystem *pFilesystem = nullptr; switch (getFileSystem(partition.m_fstype).create) { @@ -4031,14 +4032,14 @@ bool PartedCore::createFileSystem(const FSType &type, const bool &busy, const QS bool PartedCore::checkRepairFileSystem(const Partition &partition) { if (partition.m_fstype == FS_LUKS && partition.m_busy) { - qDebug() << "partition contains open LUKS encryption for a check file system only step"; + qCDebug(serviceLog) << "partition contains open LUKS encryption for a check file system only step"; return false; } if (partition.m_busy) // Trying to check an online file system is a successful non-operation. return true; - qDebug() << QString("PartedCore::checkRepairFileSystem:check file system on %1" + qCDebug(serviceLog) << QString("PartedCore::checkRepairFileSystem:check file system on %1" " for errors and (if possible) fix them") .arg(partition.getPath()); @@ -4046,7 +4047,7 @@ bool PartedCore::checkRepairFileSystem(const Partition &partition) FileSystem *pFilesystem = nullptr; switch (getFileSystem(partition.m_fstype).check) { case FS::NONE: - qDebug() << "PartedCore::checkRepairFileSystem ,checking is not available for this file system"; + qCDebug(serviceLog) << "PartedCore::checkRepairFileSystem ,checking is not available for this file system"; break; case FS::GPARTED: break; @@ -4065,9 +4066,9 @@ bool PartedCore::checkRepairFileSystem(const Partition &partition) /***********************************************private 挂载*****************************************************************/ bool PartedCore::mountDevice(const QString &mountpath, const QString devPath, const FSType &fsType, const QString userName) { - qDebug() << __FUNCTION__ << "Mount start"; + qCDebug(serviceLog) << __FUNCTION__ << "Mount start"; if (mountpath.isEmpty() || devPath.isEmpty() || fsType == FSType::FS_UNKNOWN) { - qDebug() << __FUNCTION__ << "Mount argument error"; + qCDebug(serviceLog) << __FUNCTION__ << "Mount argument error"; return false; } @@ -4114,14 +4115,14 @@ bool PartedCore::mountDevice(const QString &mountpath, const QString devPath, co if (needMount) { int exitcode = Utils::executCmd(cmd, output, errstr); if (exitcode != 0) { - qDebug() << __FUNCTION__ << "Mount error, output:" << output << "\terror:" << errstr; + qCDebug(serviceLog) << __FUNCTION__ << "Mount error, output:" << output << "\terror:" << errstr; return false; } } //修改权限 chmod(mountpath.toStdString().c_str(), 0777); - qDebug() << __FUNCTION__ << "Mount end"; + qCDebug(serviceLog) << __FUNCTION__ << "Mount end"; return true; } diff --git a/service/diskoperation/partition.cpp b/service/diskoperation/partition.cpp index 6aa127f8..4d6e10de 100644 --- a/service/diskoperation/partition.cpp +++ b/service/diskoperation/partition.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 "partition.h" #include "utils.h" #include "supportedfilesystems.h" @@ -12,37 +13,37 @@ namespace DiskManager { Partition::Partition() { - qDebug() << "Creating new partition"; + qCDebug(serviceLog) << "Creating new partition"; reset(); } Partition *Partition::clone() const { - qDebug() << "Cloning partition"; + qCDebug(serviceLog) << "Cloning partition"; return new Partition(*this); } bool Partition::sectorUsageKnown() const { - qDebug() << "Checking if sector usage is known"; + qCDebug(serviceLog) << "Checking if sector usage is known"; return m_sectorsUsed >= 0 && m_sectorsUnused >= 0; } Sector Partition::getSectorsUnallocated() const { - qDebug() << "Getting unallocated sectors"; + qCDebug(serviceLog) << "Getting unallocated sectors"; if (m_sectorsUnallocated < m_significantThreshold) { - qDebug() << "Unallocated sectors less than threshold, returning 0"; + qCDebug(serviceLog) << "Unallocated sectors less than threshold, returning 0"; return 0; } else { - qDebug() << "Returning unallocated sectors:" << m_sectorsUnallocated; + qCDebug(serviceLog) << "Returning unallocated sectors:" << m_sectorsUnallocated; return m_sectorsUnallocated; } } void Partition::reset() { - qDebug() << "Resetting partition data"; + qCDebug(serviceLog) << "Resetting partition data"; m_path.clear(); m_status = STAT_REAL; m_type = TYPE_UNALLOCATED; @@ -72,7 +73,7 @@ void Partition::reset() void Partition::reset(const PartitionInfo &info) { - qDebug() << "Resetting partition with PartitionInfo"; + qCDebug(serviceLog) << "Resetting partition with PartitionInfo"; m_status = static_cast(info.m_status); m_type = static_cast(info.m_type); m_alignment = static_cast(info.m_alignment); @@ -100,7 +101,7 @@ void Partition::reset(const PartitionInfo &info) void Partition::set(const QString &devicePath, const QString &partition, int partitionNumber, PartitionType type, FSType fstype, Sector sectorStart, Sector sectorEnd, Byte_Value sectorSize, bool insideExtended, bool busy) { - qDebug() << "set partition entry"; + qCDebug(serviceLog) << "set partition entry"; m_devicePath = devicePath; m_path = partition; m_partitionNumber = partitionNumber; @@ -112,7 +113,7 @@ void Partition::set(const QString &devicePath, const QString &partition, int par m_insideExtended = insideExtended; m_busy = busy; - qDebug() << "Setting partition:" << partition + qCDebug(serviceLog) << "Setting partition:" << partition << "type:" << type << "fs:" << fstype << "sectors:" << sectorStart << "-" << sectorEnd; @@ -120,17 +121,17 @@ void Partition::set(const QString &devicePath, const QString &partition, int par SupportedFileSystems s; FileSystem *fs = s.getFsObject(m_fstype); if (fs) { - qDebug() << "FileSystem object found, getting limits"; + qCDebug(serviceLog) << "FileSystem object found, getting limits"; m_fsLimits = fs->getFilesystemLimits(*this); } else { - qDebug() << "FileSystem object not found, setting default limits"; + qCDebug(serviceLog) << "FileSystem object not found, setting default limits"; m_fsLimits = FS_Limits{-1, -1}; } } void Partition::setUnpartitioned(const QString &devicePath, const QString &partitionPath, FSType fstype, Sector length, Byte_Value sectorSize, bool busy) { - qDebug() << "setUnpartitioned entry"; + qCDebug(serviceLog) << "setUnpartitioned entry"; reset(); // The path from the parent Device object and this child Partition object // spanning the whole device would appear to be the same. However the former @@ -156,7 +157,7 @@ void Partition::setUnpartitioned(const QString &devicePath, const QString &parti void Partition::setUnallocated(const QString &devicePath, Sector sectorStart, Sector sectorEnd, Byte_Value sectorSize, bool insideExtended) { - qDebug() << "Setting unallocated partition at sectors:" + qCDebug(serviceLog) << "Setting unallocated partition at sectors:" << sectorStart << "-" << sectorEnd; reset(); @@ -176,15 +177,15 @@ void Partition::setUnallocated(const QString &devicePath, Sector sectorStart, Se bool Partition::filesystemLabelKnown() const { - qDebug() << "Checking if filesystem label is known"; + qCDebug(serviceLog) << "Checking if filesystem label is known"; return m_haveFileSystemLabel; } void Partition::setFilesystemLabel(const QString &filesystemLabel) { - qDebug() << "Setting filesystem label:" << filesystemLabel; + qCDebug(serviceLog) << "Setting filesystem label:" << filesystemLabel; if (!filesystemLabel.isEmpty()) { - qDebug() << "Filesystem label is not empty, setting it"; + qCDebug(serviceLog) << "Filesystem label is not empty, setting it"; m_filesystemLabel = filesystemLabel; m_haveFileSystemLabel = true; } @@ -197,48 +198,48 @@ void Partition::setFilesystemLabel(const QString &filesystemLabel) void Partition::addMountPoints(const QVector &mountpoints) { - qDebug() << "Adding mount points"; + qCDebug(serviceLog) << "Adding mount points"; m_mountpoints = mountpoints; } QVector Partition::getMountPoints() const { - qDebug() << "Getting mount points"; + qCDebug(serviceLog) << "Getting mount points"; return m_mountpoints; } QString Partition::getMountPoint() const { - qDebug() << "Getting single mount point"; + qCDebug(serviceLog) << "Getting single mount point"; if (m_mountpoints.size() > 0) { - qDebug() << "Mount points exist, returning the first one"; + qCDebug(serviceLog) << "Mount points exist, returning the first one"; return m_mountpoints.front(); } - qDebug() << "No mount points, returning empty string"; + qCDebug(serviceLog) << "No mount points, returning empty string"; return ""; } void Partition::setSectorUsage(Sector sectorsFsSize, Sector sectorsFsUnused) { - qDebug() << "setSectorUsage entry"; + qCDebug(serviceLog) << "setSectorUsage entry"; Sector length = getSectorLength(); - qDebug() << "Setting sector usage, partition length:" << length; + qCDebug(serviceLog) << "Setting sector usage, partition length:" << length; if (0 <= sectorsFsSize && sectorsFsSize <= length && 0 <= sectorsFsUnused && sectorsFsUnused <= sectorsFsSize) { - qDebug() << "Valid sector usage data provided"; + qCDebug(serviceLog) << "Valid sector usage data provided"; m_sectorsUsed = sectorsFsSize - sectorsFsUnused; m_sectorsUnused = sectorsFsUnused; m_sectorsUnallocated = length - sectorsFsSize; m_significantThreshold = calcSignificantUnallocatedSectors(); } else if (sectorsFsSize == -1) { - qDebug() << "sectorsFsSize is -1, calculating usage differently"; + qCDebug(serviceLog) << "sectorsFsSize is -1, calculating usage differently"; if (0 <= sectorsFsUnused && sectorsFsUnused <= length) { - qDebug() << "Valid sectorsFsUnused"; + qCDebug(serviceLog) << "Valid sectorsFsUnused"; m_sectorsUsed = length - sectorsFsUnused; m_sectorsUnused = sectorsFsUnused; } else { - qDebug() << "Invalid sectorsFsUnused"; + qCDebug(serviceLog) << "Invalid sectorsFsUnused"; m_sectorsUsed = -1; m_sectorsUnused = -1; } @@ -249,42 +250,42 @@ void Partition::setSectorUsage(Sector sectorsFsSize, Sector sectorsFsUnused) Byte_Value Partition::getByteLength() const { - qDebug() << "Getting byte length"; + qCDebug(serviceLog) << "Getting byte length"; if (getSectorLength() >= 0) { - qDebug() << "Sector length is valid, calculating byte length"; + qCDebug(serviceLog) << "Sector length is valid, calculating byte length"; return getSectorLength() * m_sectorSize; } else { - qDebug() << "Sector length is invalid, returning -1"; + qCDebug(serviceLog) << "Sector length is invalid, returning -1"; return -1; } } Sector Partition::getSectorLength() const { - qDebug() << "Getting sector length"; + qCDebug(serviceLog) << "Getting sector length"; if (m_sectorStart >= 0 && m_sectorEnd >= 0 && m_sectorEnd < LLONG_MAX) { - qDebug() << "Start and end sectors are valid"; + qCDebug(serviceLog) << "Start and end sectors are valid"; return m_sectorEnd - m_sectorStart + 1; } else { - qDebug() << "Start or end sectors are invalid, returning -1"; + qCDebug(serviceLog) << "Start or end sectors are invalid, returning -1"; return -1; } } QString Partition::getFileSystemLabel() const { - qDebug() << "Getting filesystem label"; + qCDebug(serviceLog) << "Getting filesystem label"; if (m_haveFileSystemLabel) { - qDebug() << "Filesystem label is known, returning it"; + qCDebug(serviceLog) << "Filesystem label is known, returning it"; return m_filesystemLabel; } - qDebug() << "Filesystem label is not known, returning empty string"; + qCDebug(serviceLog) << "Filesystem label is not known, returning empty string"; return ""; } PartitionInfo Partition::getPartitionInfo() const { - qDebug() << "Getting partition info"; + qCDebug(serviceLog) << "Getting partition info"; PartitionInfo info; info.m_devicePath = m_devicePath; info.m_partitionNumber = m_partitionNumber; @@ -310,7 +311,7 @@ PartitionInfo Partition::getPartitionInfo() const info.m_fileSystemReadOnly = m_fsReadonly; info.m_mountPoints = m_mountpoints; info.m_fsLimits = m_fsLimits; - qDebug() << "Getting partition info:" + qCDebug(serviceLog) << "Getting partition info:" << "path:" << info.m_path << "type:" << info.m_type << "fs:" << info.m_fileSystemType @@ -320,7 +321,7 @@ PartitionInfo Partition::getPartitionInfo() const Sector Partition::calcSignificantUnallocatedSectors() const { - qDebug() << "Calculating significant unallocated sectors"; + qCDebug(serviceLog) << "Calculating significant unallocated sectors"; const double HIGHERUNALLOCATEDFRACTION = 0.05; const double LOWERUNALLOCATEDFRACTION = 0.02; Sector length = getSectorLength(); @@ -328,28 +329,28 @@ Sector Partition::calcSignificantUnallocatedSectors() const Sector significant; if (byteLen <= 0) { - qDebug() << "byteLen <= 0, setting significant to 1"; + qCDebug(serviceLog) << "byteLen <= 0, setting significant to 1"; significant = 1; } else if (byteLen <= 100 * MEBIBYTE) { - qDebug() << "byteLen <= 100MiB, using higher fraction"; + qCDebug(serviceLog) << "byteLen <= 100MiB, using higher fraction"; significant = qRound(length * HIGHERUNALLOCATEDFRACTION); } else if (byteLen <= 1 * GIBIBYTE) { - qDebug() << "byteLen <= 1GiB, calculating fraction"; + qCDebug(serviceLog) << "byteLen <= 1GiB, calculating fraction"; double fraction = (HIGHERUNALLOCATEDFRACTION - LOWERUNALLOCATEDFRACTION) - (byteLen - 100 * MEBIBYTE) * (HIGHERUNALLOCATEDFRACTION - LOWERUNALLOCATEDFRACTION) / (1 * GIBIBYTE - 100 * MEBIBYTE) + LOWERUNALLOCATEDFRACTION; significant = qRound(length * fraction); } else { - qDebug() << "byteLen > 1GiB, using lower fraction"; + qCDebug(serviceLog) << "byteLen > 1GiB, using lower fraction"; significant = qRound(length * LOWERUNALLOCATEDFRACTION); } - qDebug() << "Calculated significant sectors (before check):" << significant; + qCDebug(serviceLog) << "Calculated significant sectors (before check):" << significant; if (significant <= 1) { - qDebug() << "Significant sectors <= 1, setting to 1"; + qCDebug(serviceLog) << "Significant sectors <= 1, setting to 1"; significant = 1; } - qDebug() << "Final significant sectors:" << significant; + qCDebug(serviceLog) << "Final significant sectors:" << significant; return significant; } diff --git a/service/diskoperation/procpartitionsinfo.cpp b/service/diskoperation/procpartitionsinfo.cpp index 13d0aef8..43e63984 100644 --- a/service/diskoperation/procpartitionsinfo.cpp +++ b/service/diskoperation/procpartitionsinfo.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 "procpartitionsinfo.h" #include "blockspecial.h" #include "utils.h" @@ -20,23 +21,23 @@ QVector ProcPartitionsInfo::devicePathsCache; void ProcPartitionsInfo::loadCache() { - qDebug() << "Loading proc partitions info cache explicitly"; + qCDebug(serviceLog) << "Loading proc partitions info cache explicitly"; loadProcPartitionsInfoCache(); procPartitionsInfoCacheInitialized = true; } const QVector &ProcPartitionsInfo::getDevicePaths() { - qDebug() << "Getting device paths from cache"; + qCDebug(serviceLog) << "Getting device paths from cache"; initializeIfRequired(); return devicePathsCache; } void ProcPartitionsInfo::initializeIfRequired() { - qDebug() << "Checking if cache needs initialization"; + qCDebug(serviceLog) << "Checking if cache needs initialization"; if (!procPartitionsInfoCacheInitialized) { - qDebug() << "Loading partitions info cache"; + qCDebug(serviceLog) << "Loading partitions info cache"; loadProcPartitionsInfoCache(); procPartitionsInfoCacheInitialized = true; } @@ -45,22 +46,22 @@ void ProcPartitionsInfo::initializeIfRequired() void ProcPartitionsInfo::loadProcPartitionsInfoCache() { devicePathsCache.clear(); - qDebug() << "Reading /proc/partitions"; + qCDebug(serviceLog) << "Reading /proc/partitions"; QFile file("/proc/partitions"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << "Successfully opened /proc/partitions"; + qCDebug(serviceLog) << "Successfully opened /proc/partitions"; QTextStream in(&file); in.skipWhiteSpace(); QString line = in.readLine(); QString device; while (!in.atEnd() || !line.isEmpty()) { - qDebug() << "Processing partition entry"; + qCDebug(serviceLog) << "Processing partition entry"; QStringList strlist = line.split(" "); unsigned long maj = 0; unsigned long min = 0; if (sscanf(line.toStdString().c_str(), "%lu %lu", &maj, &min) != 2) { - qDebug() << "sscanf failed to parse major/minor, skipping line"; + qCDebug(serviceLog) << "sscanf failed to parse major/minor, skipping line"; line = in.readLine(); continue; } @@ -68,11 +69,11 @@ void ProcPartitionsInfo::loadProcPartitionsInfoCache() foreach (QString str, strlist) { if (!str.isEmpty() && str.indexOf(QRegularExpression("[a-z]+\\d?")) != -1) { name = str; - qDebug() << "Found device name in list:" << name; + qCDebug(serviceLog) << "Found device name in list:" << name; break; } } - qDebug() << "Found partition:" << name; + qCDebug(serviceLog) << "Found partition:" << name; BlockSpecial::registerBlockSpecial("/dev/" + name, maj, min); @@ -101,11 +102,11 @@ void ProcPartitionsInfo::loadProcPartitionsInfoCache() // E.g., device = /dev/nvme0n1, partition = /dev/nvme0n1p1 if (device == "") { device = Utils::regexpLabel(name, "^(nvme[0-9]+n[0-9]+)$"); - qDebug() << "Found total devices:" << devicePathsCache.size(); + qCDebug(serviceLog) << "Found total devices:" << devicePathsCache.size(); } else { - qWarning() << "Failed to open /proc/partitions"; + qCWarning(serviceLog) << "Failed to open /proc/partitions"; } - qDebug() << "Found total devices:" << devicePathsCache.size(); + qCDebug(serviceLog) << "Found total devices:" << devicePathsCache.size(); //Device names that end with a #[^p]# are HP Smart Array Devices (disks) // E.g., device = /dev/cciss/c0d0, partition = /dev/cciss/c0d0p1 @@ -121,16 +122,16 @@ void ProcPartitionsInfo::loadProcPartitionsInfoCache() } if (device != "") { - qDebug() << "Adding device to cache:" << device; + qCDebug(serviceLog) << "Adding device to cache:" << device; devicePathsCache.push_back("/dev/" + device); } else { - qDebug() << "Device not recognized as whole disk, not adding to cache:" << name; + qCDebug(serviceLog) << "Device not recognized as whole disk, not adding to cache:" << name; } line = in.readLine(); } file.close(); } else { - qWarning() << "Failed to open /proc/partitions"; + qCWarning(serviceLog) << "Failed to open /proc/partitions"; } } diff --git a/service/diskoperation/supportedfilesystems.cpp b/service/diskoperation/supportedfilesystems.cpp index 1d5b0bd7..799d1baa 100644 --- a/service/diskoperation/supportedfilesystems.cpp +++ b/service/diskoperation/supportedfilesystems.cpp @@ -15,6 +15,7 @@ * along with this program; if not, see . */ +#include "ddlog.h" #include "supportedfilesystems.h" #include "filesystems/ext2.h" #include "filesystems/linuxswap.h" @@ -31,7 +32,7 @@ namespace DiskManager { SupportedFileSystems::SupportedFileSystems() { - qDebug() << "Initializing supported filesystems"; + qCDebug(serviceLog) << "Initializing supported filesystems"; m_fsObjects[FS_UNKNOWN] = NULL; m_fsObjects[FS_OTHER] = NULL; m_fsObjects[FS_BTRFS] = new Btrfs; @@ -69,13 +70,13 @@ SupportedFileSystems::SupportedFileSystems() SupportedFileSystems::~SupportedFileSystems() { - // qDebug() << "Cleaning up filesystem objects"; + // qCDebug(serviceLog) << "Cleaning up filesystem objects"; FSObjectsMap::iterator iter; for (iter = m_fsObjects.begin(); iter != m_fsObjects.end(); iter++) { auto pvalue = iter.value(); if (pvalue != NULL) { - // qDebug() << "Deleting filesystem handler for:" << Utils::fileSystemTypeToString(iter.key()); + // qCDebug(serviceLog) << "Deleting filesystem handler for:" << Utils::fileSystemTypeToString(iter.key()); delete pvalue; } @@ -86,7 +87,7 @@ SupportedFileSystems::~SupportedFileSystems() void SupportedFileSystems::findSupportedFilesystems() { FSObjectsMap::iterator iter; - qDebug() << "Finding supported filesystems"; + qCDebug(serviceLog) << "Finding supported filesystems"; m_fsSupport.clear(); for (iter = m_fsObjects.begin(); iter != m_fsObjects.end(); iter++) { @@ -96,41 +97,41 @@ void SupportedFileSystems::findSupportedFilesystems() m_effectivefs.append(fsName); FS support = psys->getFilesystemSupport(); m_fsSupport.push_back(support); - qDebug() << "Found supported filesystem:" << fsName << "with create support:" << support.create; + qCDebug(serviceLog) << "Found supported filesystem:" << fsName << "with create support:" << support.create; } else { FS fsBasicsupp(iter.key()); fsBasicsupp.move = FS::GPARTED; fsBasicsupp.copy = FS::GPARTED; m_fsSupport.push_back(fsBasicsupp); - qDebug() << "Basic support for filesystem:" << Utils::fileSystemTypeToString(iter.key()); + qCDebug(serviceLog) << "Basic support for filesystem:" << Utils::fileSystemTypeToString(iter.key()); } } - qDebug() << "Total supported filesystems:" << m_fsSupport.size(); + qCDebug(serviceLog) << "Total supported filesystems:" << m_fsSupport.size(); } FileSystem *SupportedFileSystems::getFsObject(FSType fstype) const { -// qDebug() << Utils::fileSystemTypeToString(fstype); +// qCDebug(serviceLog) << Utils::fileSystemTypeToString(fstype); FSObjectsMap::const_iterator iter = m_fsObjects.find(fstype); if (iter == m_fsObjects.end()) { - qDebug() << "Filesystem not found, return NULL"; + qCDebug(serviceLog) << "Filesystem not found, return NULL"; return nullptr; } else { - qDebug() << "Found filesystem handler for value"; + qCDebug(serviceLog) << "Found filesystem handler for value"; return iter.value(); } } const FS &SupportedFileSystems::getFsSupport(FSType fstype) const { - qDebug() << "Getting FS Support for fstype:" << Utils::fileSystemTypeToString(fstype); + qCDebug(serviceLog) << "Getting FS Support for fstype:" << Utils::fileSystemTypeToString(fstype); for (int i = 0; i < m_fsSupport.size(); i++) { if (m_fsSupport[i].fstype == fstype) { - qDebug() << "Found support info for fstype:" << Utils::fileSystemTypeToString(fstype); + qCDebug(serviceLog) << "Found support info for fstype:" << Utils::fileSystemTypeToString(fstype); return m_fsSupport[i]; } } - qDebug() << "Could not find support info for fstype, returning unsupported object:" << Utils::fileSystemTypeToString(fstype); + qCDebug(serviceLog) << "Could not find support info for fstype, returning unsupported object:" << Utils::fileSystemTypeToString(fstype); static FS fsNotsupp(FS_UNSUPPORTED); return fsNotsupp; } @@ -147,7 +148,7 @@ const FS &SupportedFileSystems::getFsSupport(FSType fstype) const const QStringList &SupportedFileSystems::getAllFsName() { - qDebug() << "Getting all effective filesystem names"; + qCDebug(serviceLog) << "Getting all effective filesystem names"; return m_effectivefs; }