Solid

udisksblock.cpp
1/*
2 SPDX-FileCopyrightText: 2012 Lukáš Tinkl <ltinkl@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "udisksblock.h"
8
9#if defined(Q_OS_LINUX)
10#include <linux/kdev_t.h>
11#else
12// taken from linux/kdev_t.h
13#define MINORBITS 20
14#define MINORMASK ((1U << MINORBITS) - 1)
15#define MAJOR(dev) ((unsigned int)((dev) >> MINORBITS))
16#define MINOR(dev) ((unsigned int)((dev)&MINORMASK))
17#endif
18
19#include <QDBusConnection>
20#include <QDBusPendingReply>
21#include <QDomDocument>
22#include <QFile>
23
24#include "udisks_debug.h"
25
26using namespace Solid::Backends::UDisks2;
27
28Block::Block(Device *dev)
29 : DeviceInterface(dev)
30 , m_devNum(m_device->prop("DeviceNumber").toULongLong())
31 , m_devFile(QFile::decodeName(m_device->prop("Device").toByteArray()))
32{
33 // we have a drive (non-block device for udisks), so let's find the corresponding (real) block device
34 if (m_devNum == 0 || m_devFile.isEmpty()) {
35 QDBusMessage call = QDBusMessage::createMethodCall(UD2_DBUS_SERVICE, UD2_DBUS_PATH_BLOCKDEVICES, DBUS_INTERFACE_INTROSPECT, "Introspect");
37 reply.waitForFinished();
38
39 if (reply.isValid()) {
40 QDomDocument dom;
41 dom.setContent(reply.value());
42 QDomNodeList nodeList = dom.documentElement().elementsByTagName("node");
43 for (int i = 0; i < nodeList.count(); i++) {
44 QDomElement nodeElem = nodeList.item(i).toElement();
45 if (!nodeElem.isNull() && nodeElem.hasAttribute("name")) {
46 const QString udi = UD2_DBUS_PATH_BLOCKDEVICES + QLatin1Char('/') + nodeElem.attribute("name");
47
48 Device device(udi);
49 if (device.drivePath() == dev->udi()) {
50 m_devNum = device.prop("DeviceNumber").toULongLong();
51 m_devFile = QFile::decodeName(device.prop("Device").toByteArray());
52 break;
53 }
54 }
55 }
56 } else {
57 qCWarning(UDISKS2) << "Failed enumerating UDisks2 objects:" << reply.error().name() << "\n" << reply.error().message();
58 }
59 }
60
61 // qDebug() << "devnum:" << m_devNum << "dev file:" << m_devFile;
62}
63
64Block::~Block()
65{
66}
67
68QString Block::device() const
69{
70 return m_devFile;
71}
72
73int Block::deviceMinor() const
74{
75 return MINOR(m_devNum);
76}
77
78int Block::deviceMajor() const
79{
80 return MAJOR(m_devNum);
81}
82
83#include "moc_udisksblock.cpp"
QDBusPendingCall asyncCall(const QDBusMessage &message, int timeout) const const
QDBusConnection systemBus()
QString message() const const
QString name() const const
QDBusMessage createMethodCall(const QString &service, const QString &path, const QString &interface, const QString &method)
QDBusError error() const const
bool isValid() const const
typename Select< 0 >::Type value() const const
QDomElement documentElement() const const
ParseResult setContent(QAnyStringView text, ParseOptions options)
QString attribute(const QString &name, const QString &defValue) const const
QDomNodeList elementsByTagName(const QString &tagname) const const
bool hasAttribute(const QString &name) const const
bool isNull() const const
QDomElement toElement() const const
int count() const const
QDomNode item(int index) const const
QString decodeName(const QByteArray &localFileName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.