Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
*.user
.build
build
.qmake.stash
*.qm
.cache/*
.claude/*
.vscode

# AI
Expand Down
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all -fPIE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z relro -z now -z noexecstack -pie")

set(QT_VERSION_MAJOR 6)
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
# Qt 版本检测
find_package(Qt6 QUIET)
if(Qt6_FOUND)
message("Found Qt6.")

set(QT_VERSION_MAJOR 6)
set(DTK_VERSION 6)
else()
message("Found Qt5.")

set(QT_VERSION_MAJOR 5)
add_compile_definitions(NO_DBUS_CALLER_AUTH_CHECK)
message("NO_DBUS_CALLER_AUTH_CHECK is on.")
endif()

# 检查内存泄漏代码
Expand Down
10 changes: 5 additions & 5 deletions application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ endforeach()
file(GLOB ALL_SOURCES "*.cpp" "./partedproxy/*.cpp" "./widgets/*.cpp" "./widgets/customcontrol/*.cpp" "./widgets/accessible/*.cpp")
file(GLOB ALL_HEADERS "*.h" "./partedproxy/*.h" "./widgets/*.h" "./widgets/customcontrol/*.h" "./widgets/accessible/*.h")
file (GLOB DTNG_TS_FILES translations/*.ts)
qt_create_translation(DTNG_QM_FILES
${CMAKE_SOURCE_DIR}
${DTNG_TS_FILES}
)

if(Qt6_FOUND)
qt_create_translation(DTNG_QM_FILES ${CMAKE_SOURCE_DIR} ${DTNG_TS_FILES})
else()
qt5_create_translation(DTNG_QM_FILES ${CMAKE_SOURCE_DIR} ${DTNG_TS_FILES})
endif()

include_directories(../basestruct)
#link_directories(${PROJECT_BINARY_DIR})
Expand Down
1 change: 1 addition & 0 deletions application/widgets/customcontrol/waterloadingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#if QT_VERSION_MAJOR > 5
#include <random>
#endif
#include <QDebug>

Check warning on line 12 in application/widgets/customcontrol/waterloadingwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

WaterLoadingWidget::WaterLoadingWidget(QWidget *parent) : QWidget(parent)
{
Expand Down
1 change: 1 addition & 0 deletions basestruct/deviceinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// SPDX-License-Identifier: GPL-3.0-only

#include "deviceinfo.h"
#include <QDBusArgument>

Check warning on line 6 in basestruct/deviceinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusArgument> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 7 in basestruct/deviceinfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

/*********************************** stCustest *********************************************/
QDBusArgument &operator<<(QDBusArgument &argument, const stCustest &stcus)
Expand Down
4 changes: 2 additions & 2 deletions basestruct/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ int Utils::getMountedFileSystemUsage(const QString &mountpoint, Byte_Value &file
int ret;
ret = statvfs(mountpoint.toStdString().c_str(), &sfs);
if (ret == 0) {
fileSystemSize = static_cast<Byte_Value>(sfs.f_blocks) * sfs.f_frsize;
fileSystemFree = static_cast<Byte_Value>(sfs.f_bfree) * sfs.f_bsize;
fileSystemSize = static_cast<Byte_Value>(sfs.f_blocks) * sfs.f_bsize;
fileSystemFree = static_cast<Byte_Value>(sfs.f_bavail) * sfs.f_bsize;
} else {
qWarning() << "Utils::getMountedFileSystemUsage - Failed for:" << mountpoint << "Error:" << errno;
QString errorMessage("statvfs(\"%1\"):%2 "); // = "statvfs(\"" + mountpoint + "\"): " + Glib::strerror(errno) ;
Expand Down
14 changes: 7 additions & 7 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ Build-Depends:
cmake,
pkg-config,
libc6-dev,
qt6-tools-dev,
qt6-base-dev,
qt6-tools-dev | qttools5-dev,
qt6-base-dev | qtbase5-dev,
libx11-dev,
libdtk6widget-dev,
qt6-tools-dev-tools,
qt6-base-private-dev,
libdtk6widget-dev | libdtkwidget-dev,
qt6-tools-dev-tools | qttools5-dev-tools,
qt6-base-private-dev | qtbase5-private-dev,
libparted-dev,
libparted-fs-resize0,
libpolkit-qt6-1-dev,
libpolkit-qt6-1-dev | libpolkit-qt5-1-dev,
libgtest-dev,
libgmock-dev,
deepin-gettext-tools
Standards-Version: 4.1.3

Package: deepin-diskmanager
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, smartmontools, exfat-fuse, pkexec
Depends: ${shlibs:Depends}, ${misc:Depends}, smartmontools, pkexec
Description: Disk Utility is a disk management tool for creating, reorganizing and formatting partitions.
Disk Utility is a disk management tool for disk.

2 changes: 0 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/make -f

export QT_SELECT=5

include /usr/share/dpkg/default.mk

override_dh_auto_configure:
Expand Down
7 changes: 5 additions & 2 deletions log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void WriteVersion()
QTextStream ts(&outFile);
auto appName = QCoreApplication::applicationName();
auto version = QCoreApplication::applicationVersion();
ts << appName << " " << version << Qt::endl;
ts << appName << " " << version << "\n";
outFile.close();
s_logMutex.unlock();
}
Expand Down Expand Up @@ -154,6 +154,9 @@ void customLogMessageHandler(QtMsgType type, const QMessageLogContext &ctx, cons
case QtDebugMsg:
logInfo = QString("Debug:");
break;
case QtInfoMsg:
logInfo = QString("Info:");
break;
case QtWarningMsg:
logInfo = QString("Warning:");
break;
Expand All @@ -177,7 +180,7 @@ void customLogMessageHandler(QtMsgType type, const QMessageLogContext &ctx, cons
return;

QTextStream ts(&outFile);
ts << message.toUtf8() << Qt::endl;
ts << message.toUtf8() << "\n";
outFile.close();
s_logMutex.unlock();
}
5 changes: 5 additions & 0 deletions service/diskmanagerservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ int DiskManagerService::test()

bool DiskManagerService::checkAuthorization(void)
{
#ifdef NO_DBUS_CALLER_AUTH_CHECK
qDebug() << "Authorization check was skipped";
return true;
#else
QString actionId("com.deepin.pkexec.deepin-diskmanager");
QString serviceName = message().service();

Expand All @@ -508,6 +512,7 @@ bool DiskManagerService::checkAuthorization(void)
sendErrorReply(QDBusError::AccessDenied);
return false;
}
#endif
}

} // namespace DiskManager
28 changes: 27 additions & 1 deletion service/diskoperation/DeviceStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,26 @@ void DeviceStorage::getDiskInfoModel(const QString &devicePath, QString &model)
}
}

cmd = "udevadm info " + devicePath;
exitcode = Utils::executCmd(cmd, outPut, error);
if (exitcode != 0) {
qDebug() << "Failed to execute udevadm command, error:" << error;
return;
}
QString key = "ID_MODEL=";
int start = outPut.indexOf(key);
if (start != -1) {
start += key.length(); // 移动到等号后面
int end = outPut.indexOf('\n', start); // 找到行尾
if (end == -1) end = outPut.length(); // 如果是最后一行

model = outPut.mid(start, end - start).trimmed();
if (!model.isEmpty())
return;
}

qWarning() << "tried a lot but got nothing about model for" << devicePath;

// 若未获取到型号名,返回未知
qDebug() << "model not found, set to UnKnow";
model = "UnKnow";
Expand Down Expand Up @@ -729,7 +749,13 @@ void DeviceStorage::getDiskInfoInterface(const QString &devicePath, QString &int
QString spec_version = Utils::readContent("/sys/block/sdd/device/spec_version").trimmed();
if (!spec_version.isEmpty()) {
qDebug() << "spec_version is not empty";
interface = (spec_version == "300") ? "UFS 3.0" : "UFS 3.1";
if (spec_version.contains("300")) {
interface = "UFS 3.0";
} else if (spec_version.contains("310")) {
interface = "UFS 3.1";
} else if (spec_version.contains("400")) {
interface = "UFS 4.0";
}
}
}
file.close();
Expand Down
132 changes: 77 additions & 55 deletions service/diskoperation/filesystems/ext2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,73 +137,95 @@ FS EXT2::getFilesystemSupport()
void EXT2::setUsedSectors(Partition &partition)
{
qDebug() << "Setting used sectors for ext2/3/4 partition:" << partition.getPath();
QString output, error, strmatch, strcmd;
m_blocksSize = m_numOfFreeOrUsedBlocks = m_totalNumOfBlock = -1;
QString output, error, strcmd;
strcmd = QString("dumpe2fs -h %1").arg(partition.getPath());

qDebug() << "Executing dumpe2fs command to get filesystem information";
if (!Utils::executCmd(strcmd, output, error)) {
strmatch = ("Block count:");
long long blockCount = -1;
long long blockSize = -1;
long long freeBlocks = -1;
long long reservedBlocks = 0;

// 获取总块数
QString strmatch = "Block count:";
int index = output.indexOf(strmatch);
if (index >= 0 && index < output.length()) {
qDebug() << "Found block count";
m_totalNumOfBlock = Utils::regexpLabel(output, QString("(?<=Block count:).*(?=\n)")).trimmed().toLong();
qDebug() << "Found block count information";
blockCount = Utils::regexpLabel(output, QString("(?<=Block count:).*(?=\n)")).trimmed().toLong();
}
// qDebug() << output;
// qDebug() << output.mid(index, strmatch.length()).toLatin1() << m_totalNumOfBlock;
strmatch = ("Block size:");

// 获取块大小
strmatch = "Block size:";
index = output.indexOf(strmatch);
if (index >= 0 && index < output.length()) {
qDebug() << "Found block size";
m_blocksSize = Utils::regexpLabel(output, QString("(?<=Block size:).*(?=\n)")).trimmed().toLong();
qDebug() << "Found block size information";
blockSize = Utils::regexpLabel(output, QString("(?<=Block size:).*(?=\n)")).trimmed().toLong();
}
// qDebug() << output << output.mid(index, strmatch.length()).toLatin1() << m_blocksSize;

if (partition.m_busy) {
qDebug() << "Partition is busy, getting usage from mounted filesystem";
Byte_Value fs_all;
Byte_Value fs_free;
if (Utils::getMountedFileSystemUsage(partition.getMountPoint(), fs_all, fs_free) == 0) {
qDebug() << "Successfully got mounted filesystem usage";
partition.setSectorUsage(qRound64(fs_all / double(partition.m_sectorSize)), qRound64(fs_free / double(partition.m_sectorSize)));
partition.m_fsBlockSize = m_blocksSize;
}
} else {
qDebug() << "Partition is not busy, estimating minimum size";
// Resize2fs won't shrink a file system smaller than it's own
// estimated minimum size, so use that to derive the free space.
m_numOfFreeOrUsedBlocks = -1;
if (!Utils::executCmd(QString("resize2fs -P %1").arg(partition.getPath()), output, error)) {
qDebug() << "resize2fs -P successful";
if (sscanf(output.toLatin1(), "Estimated minimum size of the filesystem: %lld", &m_numOfFreeOrUsedBlocks) == 1
|| sscanf(output.toStdString().c_str(), "预计文件系统的最小尺寸:%lld", &m_numOfFreeOrUsedBlocks) == 1) {
qDebug() << "Parsed estimated minimum size";
m_numOfFreeOrUsedBlocks = m_totalNumOfBlock - m_numOfFreeOrUsedBlocks;
}
}
// Resize2fs can fail reporting please run fsck first. Fall back
// to reading dumpe2fs output for free space.
if (m_numOfFreeOrUsedBlocks == -1) {
qDebug() << "resize2fs -P failed or did not provide minimum size, falling back to dumpe2fs";
strmatch = "Free blocks:";
index = output.indexOf(strmatch);
if (index < output.length()) {
qDebug() << "Found free blocks in dumpe2fs output";
sscanf(output.mid(index, strmatch.length()).toLatin1(), "Free blocks: %lld", &m_numOfFreeOrUsedBlocks);

// 获取空闲块数
strmatch = "Free blocks:";
index = output.indexOf(strmatch);
if (index >= 0 && index < output.length()) {
qDebug() << "Found free blocks information";
freeBlocks = Utils::regexpLabel(output, QString("(?<=Free blocks:).*(?=\n)")).trimmed().toLong();
}

// 获取保留块数
strmatch = "Reserved block count:";
index = output.indexOf(strmatch);
if (index >= 0 && index < output.length()) {
qDebug() << "Found reserved blocks information";
reservedBlocks = Utils::regexpLabel(output, QString("(?<=Reserved block count:).*(?=\n)")).trimmed().toLong();
}

// 验证数据有效性并计算扇区使用情况
if (blockCount > 0 && blockSize > 0 && freeBlocks >= 0 && reservedBlocks >= 0) {
qDebug() << "Filesystem information validation successful, calculating sector usage";

// 计算用户实际可用的空闲块数:可用 = (freeBlocks - reservedBlocks)
long long userAvailableBlocks = (freeBlocks > reservedBlocks) ? (freeBlocks - reservedBlocks) : 0;
Comment on lines +186 to +187
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Subtracting reservedBlocks from freeBlocks likely underestimates user-available space for ext*.

On ext2/3/4, dumpe2fs typically reports Free blocks: with reserved space already excluded, and also exposes Reserved block count: separately. Assuming freeBlocks includes reserved blocks and subtracting reservedBlocks again can double‑count the reservation and under‑report available space. Please confirm the semantics against real dumpe2fs -h output and adjust the computation accordingly (e.g., use freeBlocks as‑is and keep reservedBlocks only as metadata, or derive used space from blockCount - freeBlocks while tracking reserved separately).


// 转换为扇区数
Sector totalSectors = qRound64(blockCount * (blockSize / double(partition.m_sectorSize)));
Sector availableSectors = qRound64(userAvailableBlocks * (blockSize / double(partition.m_sectorSize)));

qDebug() << "EXT* usage calculation: blockCount=" << blockCount
<< "blockSize=" << blockSize
<< "freeBlocks=" << freeBlocks
<< "reservedBlocks=" << reservedBlocks
<< "userAvailableBlocks=" << userAvailableBlocks
<< "totalSectors=" << totalSectors
<< "availableSectors=" << availableSectors;

// 如果分区已挂载,使用 stat 获取更准确的可用块数
if (partition.m_busy && !partition.getMountPoints().empty()) {
qDebug() << "Partition is mounted, using stat for more accurate available space calculation";
Byte_Value statTotalSize, statAvailableSize;
if (Utils::getMountedFileSystemUsage(partition.getMountPoint(), statTotalSize, statAvailableSize) == 0) {
// 使用 stat 获取的可用空间(已经排除了保留空间)
Sector statAvailableSectors = qRound64(statAvailableSize / double(partition.m_sectorSize));
qDebug() << "Using stat data for mounted partition: statAvailableSectors=" << statAvailableSectors;
partition.setSectorUsage(totalSectors, statAvailableSectors);
qDebug() << "Sector usage set successfully using stat data";
} else {
qDebug() << "Failed to get mounted filesystem usage, using calculated available sectors";
partition.setSectorUsage(totalSectors, availableSectors);
qDebug() << "Sector usage set successfully using calculated data";
}
} else {
qDebug() << "Partition is not mounted, using calculated available sectors";
partition.setSectorUsage(totalSectors, availableSectors);
qDebug() << "Sector usage set successfully";
}

if (m_totalNumOfBlock > -1 && m_numOfFreeOrUsedBlocks > -1 && m_blocksSize > -1) {
qDebug() << "Calculating and setting sector usage from block counts";
m_totalNumOfBlock = qRound64(m_totalNumOfBlock * (m_blocksSize / double(partition.m_sectorSize)));
m_numOfFreeOrUsedBlocks = qRound64(m_numOfFreeOrUsedBlocks * (m_blocksSize / double(partition.m_sectorSize)));
qDebug() << "111111111111111111111111" << m_totalNumOfBlock << m_numOfFreeOrUsedBlocks << m_blocksSize;
partition.setSectorUsage(m_totalNumOfBlock, m_numOfFreeOrUsedBlocks);
partition.m_fsBlockSize = m_blocksSize;
}
partition.m_fsBlockSize = blockSize;
qDebug() << "Filesystem block size set to:" << blockSize;
} else {
qDebug() << "Filesystem information validation failed, invalid parameters detected";
}


} else {
qDebug() << __FUNCTION__ << "dumpe2fs -h failed :" << output << error;
qDebug() << "dumpe2fs command execution failed, error:" << error;
qDebug() << "Failed to set used sectors for partition:" << partition.getPath();
}
}

Expand Down
4 changes: 2 additions & 2 deletions service/diskoperation/partedcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ bool PartedCore::hidePartition()
} else {
qDebug() << "open file for write";
QTextStream out(&file);
out << QString("ENV{ID_FS_UUID}==\"%1\", ENV{UDISKS_IGNORE}=\"1\"").arg(m_curpartition.m_uuid) << Qt::endl;
out << QString("ENV{ID_FS_UUID}==\"%1\", ENV{UDISKS_IGNORE}=\"1\"").arg(m_curpartition.m_uuid) << "\n";
}

// qDebug() << __FUNCTION__ << "Hide Partition end";
Expand Down Expand Up @@ -2283,7 +2283,7 @@ void PartedCore::onRefreshDeviceInfo(int type, bool arg1, QString arg2)
if (m_workerThreadProbe == nullptr) {
qDebug() << "m_workerThreadProbe is null, creating new thread";
m_workerThreadProbe = new QThread();
qDebug() << "onRefresh Create thread: " << QThread::currentThreadId() << " ++++++++" << m_workerThreadProbe << Qt::endl;
qDebug() << "onRefresh Create thread: " << QThread::currentThreadId() << " ++++++++" << m_workerThreadProbe << "\n";
qDebug() << " ----------------------! 0 !--------------------- :" << m_probeThread.thread();
m_probeThread.moveToThread(m_workerThreadProbe);
m_workerThreadProbe->start();
Expand Down
2 changes: 1 addition & 1 deletion service/diskoperation/supportedfilesystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SupportedFileSystems::SupportedFileSystems()
m_fsObjects[FS_EXT4] = new EXT2(FS_EXT4);
// m_fs_objects[FS_F2FS] = new f2fs();
// m_fs_objects[FS_FAT16] = new fat16(FS_FAT16);
m_fsObjects[FS_FAT32] = new FAT16(FS_FAT32);
// m_fsObjects[FS_FAT32] = new FAT16(FS_FAT32);
// m_fs_objects[FS_HFS] = new hfs();
// m_fs_objects[FS_HFSPLUS] = new hfsplus();
// m_fs_objects[FS_JFS] = new jfs();
Expand Down