7#include "udisksblock.h"
10#include <linux/kdev_t.h>
14#define MINORMASK ((1U << MINORBITS) - 1)
15#define MAJOR(dev) ((unsigned int)((dev) >> MINORBITS))
16#define MINOR(dev) ((unsigned int)((dev)&MINORMASK))
19#include <QDBusConnection>
20#include <QDBusPendingReply>
21#include <QDomDocument>
24#include "udisks_debug.h"
26using namespace Solid::Backends::UDisks2;
28Block::Block(Device *dev)
29 : DeviceInterface(dev)
30 , m_devNum(m_device->prop(QStringLiteral(
"DeviceNumber")).toULongLong())
31 , m_devFile(
QFile::decodeName(m_device->prop(QStringLiteral(
"Device")).toByteArray()))
34 if (m_devNum == 0 || m_devFile.isEmpty()) {
35 QDBusMessage call = QDBusMessage::createMethodCall(QStringLiteral(UD2_DBUS_SERVICE),
36 QStringLiteral(UD2_DBUS_PATH_BLOCKDEVICES),
37 QStringLiteral(DBUS_INTERFACE_INTROSPECT),
38 QStringLiteral(
"Introspect"));
39 QDBusPendingReply<QString> reply = QDBusConnection::systemBus().asyncCall(call);
40 reply.waitForFinished();
42 if (reply.isValid()) {
44 dom.setContent(reply.value());
45 QDomNodeList nodeList = dom.documentElement().elementsByTagName(QStringLiteral(
"node"));
46 for (int i = 0; i < nodeList.count(); i++) {
47 QDomElement nodeElem = nodeList.item(i).toElement();
48 if (!nodeElem.isNull() && nodeElem.hasAttribute(QStringLiteral(
"name"))) {
49 const QString udi = QStringLiteral(UD2_DBUS_PATH_BLOCKDEVICES) + QLatin1Char(
'/') + nodeElem.attribute(QStringLiteral(
"name"));
52 if (device.drivePath() == dev->udi()) {
53 m_devNum = device.prop(QStringLiteral(
"DeviceNumber")).toULongLong();
54 m_devFile = QFile::decodeName(device.prop(QStringLiteral(
"Device")).toByteArray());
60 qCWarning(UDISKS2) <<
"Failed enumerating UDisks2 objects:" << reply.error().name() << QStringLiteral(
"\n") << reply.error().message();
76int Block::deviceMinor()
const
78 return MINOR(m_devNum);
81int Block::deviceMajor()
const
83 return MAJOR(m_devNum);
86#include "moc_udisksblock.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:49 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.