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
171 changes: 86 additions & 85 deletions service/diskmanagerservice.cpp

Large diffs are not rendered by default.

313 changes: 157 additions & 156 deletions service/diskoperation/DeviceStorage.cpp

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions service/diskoperation/blockspecial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include "ddlog.h"
#include "blockspecial.h"

#include <QMap>
Expand Down Expand Up @@ -46,58 +47,58 @@ BlockSpecial::BlockSpecial()
, m_major(0UL)
, m_minor(0UL)
{
qDebug() << "BlockSpecial object created with empty name";
qCDebug(serviceLog) << "BlockSpecial object created with empty name";
}

BlockSpecial::BlockSpecial(const QString &name)
: m_name(name)
, m_major(0UL)
, m_minor(0UL)
{
qDebug() << "BlockSpecial object created for device:" << name;
qCDebug(serviceLog) << "BlockSpecial object created for device:" << name;
MMNumberMapping::const_iterator mmNumIter = mmNumberCache.find(name);
if (mmNumIter != mmNumberCache.end()) {
qDebug() << "Found device in cache:" << name;
qCDebug(serviceLog) << "Found device in cache:" << name;
// Use already cached major, minor pair

m_major = mmNumIter.value().m_major;
m_minor = mmNumIter.value().m_minor;
return;
}
qDebug() << "Device not in cache, calling stat:" << name;
qCDebug(serviceLog) << "Device not in cache, calling stat:" << name;

MmNumber pair = {0UL, 0UL};
// Call stat(name, ...) to get the major, minor pair
struct stat sb;
if (stat(name.toStdString().c_str(), &sb) == 0 && S_ISBLK(sb.st_mode)) {
qDebug() << "stat successful and is a block device:" << name;
qCDebug(serviceLog) << "stat successful and is a block device:" << name;
m_major = major(sb.st_rdev);
m_minor = minor(sb.st_rdev);
pair.m_major = m_major;
pair.m_minor = m_minor;
} else {
qDebug() << "stat failed or is not a block device:" << name;
qCDebug(serviceLog) << "stat failed or is not a block device:" << name;
}
// Add new cache entry for name to major, minor pair
qDebug() << "Adding new cache entry for" << name << "with major" << pair.m_major << "minor" << pair.m_minor;
qCDebug(serviceLog) << "Adding new cache entry for" << name << "with major" << pair.m_major << "minor" << pair.m_minor;
mmNumberCache[name] = pair;
}

BlockSpecial::~BlockSpecial()
{
// Do not log in destructors of global variables, which can cause crashes
// qDebug() << "BlockSpecial object destroyed for device:" << m_name;
// qCDebug(serviceLog) << "BlockSpecial object destroyed for device:" << m_name;
}

void BlockSpecial::clearCache()
{
qDebug() << "Clearing block device number cache";
qCDebug(serviceLog) << "Clearing block device number cache";
mmNumberCache.clear();
}

void BlockSpecial::registerBlockSpecial(const QString &name, unsigned long major, unsigned long minor)
{
qDebug() << "Registering block device:" << name << "with major:" << major << "minor:" << minor;
qCDebug(serviceLog) << "Registering block device:" << name << "with major:" << major << "minor:" << minor;
MmNumber pair;
pair.m_major = major;
pair.m_minor = minor;
Expand All @@ -107,29 +108,29 @@ void BlockSpecial::registerBlockSpecial(const QString &name, unsigned long major

bool operator==(const BlockSpecial &lhs, const BlockSpecial &rhs)
{
// qDebug() << "Entering operator== for BlockSpecial";
// qCDebug(serviceLog) << "Entering operator== for BlockSpecial";
if (lhs.m_major > 0UL || lhs.m_minor > 0UL) {
// qDebug() << "Comparing by major/minor number for" << lhs.m_name << "and" << rhs.m_name;
// qCDebug(serviceLog) << "Comparing by major/minor number for" << lhs.m_name << "and" << rhs.m_name;
// Match block special files by major, minor device numbers.
return lhs.m_major == rhs.m_major && lhs.m_minor == rhs.m_minor;
}
else {
// qDebug() << "Comparing by name for" << lhs.m_name << "and" << rhs.m_name;
// qCDebug(serviceLog) << "Comparing by name for" << lhs.m_name << "and" << rhs.m_name;
// For non-block special files fall back to name string compare.
return lhs.m_name == rhs.m_name;
}
}

bool operator<(const BlockSpecial &lhs, const BlockSpecial &rhs)
{
// qDebug() << "Entering operator< for BlockSpecial";
// qCDebug(serviceLog) << "Entering operator< for BlockSpecial";
if (lhs.m_major == 0 && rhs.m_major == 0 && lhs.m_minor == 0 && rhs.m_minor == 0) {
// qDebug() << "Comparing non-block special files by name for" << lhs.m_name << "and" << rhs.m_name;
// qCDebug(serviceLog) << "Comparing non-block special files by name for" << lhs.m_name << "and" << rhs.m_name;
// Two non-block special files are ordered by name.
return lhs.m_name < rhs.m_name;
}
else {
// qDebug() << "Comparing block special files by major/minor number for" << lhs.m_name << "and" << rhs.m_name;
// qCDebug(serviceLog) << "Comparing block special files by major/minor number for" << lhs.m_name << "and" << rhs.m_name;
// Block special files are ordered by major, minor device numbers.
return lhs.m_major < rhs.m_major || (lhs.m_major == rhs.m_major && lhs.m_minor < rhs.m_minor);
}
Expand Down
17 changes: 9 additions & 8 deletions service/diskoperation/device.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-only

#include "ddlog.h"
#include "device.h"

#include <QDebug>
Expand All @@ -10,7 +11,7 @@ namespace DiskManager {

Device::Device()
{
qDebug() << "Initializing Device object with DBus type registrations";
qCDebug(serviceLog) << "Initializing Device object with DBus type registrations";
qDBusRegisterMetaType<DeviceInfo>();
qDBusRegisterMetaType<DeviceInfoMap>();
qDBusRegisterMetaType<PartitionInfo>();
Expand Down Expand Up @@ -48,23 +49,23 @@ Device::Device()
m_highestBusy = 0;
m_readonly = false;
m_maxPartitionNameLength = 0;
qDebug() << "Device object initialized";
qCDebug(serviceLog) << "Device object initialized";
}

void Device::enablePartitionNaming(int length)
{
if (length > 0) {
m_maxPartitionNameLength = length;
qDebug() << "Enabled partition naming with max length:" << length;
qCDebug(serviceLog) << "Enabled partition naming with max length:" << length;
} else {
m_maxPartitionNameLength = 0;
qDebug() << "Disabled partition naming";
qCDebug(serviceLog) << "Disabled partition naming";
}
}

bool Device::partitionNamingSupported() const
{
qDebug() << "Checking if partition naming is supported. Max length:" << m_maxPartitionNameLength;
qCDebug(serviceLog) << "Checking if partition naming is supported. Max length:" << m_maxPartitionNameLength;
return m_maxPartitionNameLength > 0;
}

Expand All @@ -75,7 +76,7 @@ bool Device::partitionNamingSupported() const

DeviceInfo Device::getDeviceInfo()
{
qDebug() << "Entering Device::getDeviceInfo";
qCDebug(serviceLog) << "Entering Device::getDeviceInfo";
DeviceInfo info;
info.m_length = m_length;
info.m_heads = m_heads;
Expand All @@ -93,7 +94,7 @@ DeviceInfo Device::getDeviceInfo()
info.m_interface = m_interface;
info.m_mediaType = m_mediaType;

qDebug() << "Retrieving device info - Path:" << info.m_path
qCDebug(serviceLog) << "Retrieving device info - Path:" << info.m_path
<< "Length:" << info.m_length
<< "SectorSize:" << info.m_sectorSize
<< "MaxPrims:" << info.m_maxPrims;
Expand Down
Loading
Loading