diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 54adeea..65246ab 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,52 +1,72 @@ include(ECMAddTests) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Concurrent Test) ########### fakehardwaretest ############### ecm_add_test(fakehardwaretest.cpp LINK_LIBRARIES KF5Solid_static Qt5::DBus Qt5::Xml Qt5::Test) # QT5 TODO Port solid to QFINDTESTDATA target_compile_definitions(fakehardwaretest PRIVATE SOLID_STATIC_DEFINE=1 TEST_DATA="${CMAKE_CURRENT_SOURCE_DIR}/../src/solid/devices/backends/fakehw/fakecomputer.xml") ########### halbasictest ############### if(NOT WIN32 AND NOT APPLE AND NOT CMAKE_SYSTEM_NAME MATCHES Linux) ecm_add_test(halbasictest.cpp LINK_LIBRARIES KF5Solid_static Qt5::DBus Qt5::Xml Qt5::Test) endif() ########### solidhwtest ############### ecm_add_test(solidhwtest.cpp LINK_LIBRARIES Qt5::DBus Qt5::Xml Qt5::Test ${LIBS} KF5Solid_static) target_compile_definitions(solidhwtest PRIVATE SOLID_STATIC_DEFINE=1 FAKE_COMPUTER_XML="${CMAKE_CURRENT_SOURCE_DIR}/../src/solid/devices/backends/fakehw/fakecomputer.xml") target_include_directories(solidhwtest PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src/solid/devices/backends/fakehw) ########### solidmttest ############### ecm_add_test(solidmttest.cpp LINK_LIBRARIES Qt5::DBus Qt5::Xml Qt5::Test ${LIBS} KF5Solid_static Qt5::Concurrent) target_compile_definitions(solidmttest PRIVATE SOLID_STATIC_DEFINE=1) ########### solidmttest ############### if (WITH_NEW_SOLID_JOB) ecm_add_test(solidjobtest.cpp LINK_LIBRARIES Qt5::Test ${LIBS} KF5Solid_static) endif() ########### solidpowertest ############### if (WITH_NEW_SOLID_JOB AND WITH_NEW_POWER_ASYNC_API) ecm_add_test(solidpowertest.cpp LINK_LIBRARIES Qt5::Test ${LIBS} KF5Solid_static) endif() ########### solidpowertest ############### if(WITH_NEW_POWER_ASYNC_API AND WITH_NEW_POWER_ASYNC_FREEDESKTOP) set(solidFreedesktopTest_SRCS solidfreedesktoptest.cpp fakeUpower.cpp fakelogind.cpp) ecm_add_test(${solidFreedesktopTest_SRCS} TEST_NAME "solidfreedesktopbackend" LINK_LIBRARIES Qt5::Test Qt5::DBus ${LIBS} KF5Solid_static) endif() ########### logindinhibitionargument ########### if(WITH_NEW_POWER_ASYNC_API AND WITH_NEW_POWER_ASYNC_FREEDESKTOP) set(solidLogindInhibitionArgument_SRCS logindinhibitionargumenttest.cpp ../src/solid/power/backends/freedesktop/logindinhibitionargument.cpp ) ecm_add_test(${solidLogindInhibitionArgument_SRCS} TEST_NAME "logindinhibitionargument" LINK_LIBRARIES Qt5::Test KF5Solid_static) endif() + +set(solidUdisks2Test_SRCS solidudisks2test.cpp fakeUdisks2.cpp) +ecm_add_test(${solidUdisks2Test_SRCS} TEST_NAME "solidudisks2" LINK_LIBRARIES Qt5::Test Qt5::DBus ${LIBS} KF5Solid_static) +include(CheckSymbolExists) +check_symbol_exists(major "sys/sysmacros.h" HAVE_SYSMACROS_MAJOR) +check_symbol_exists(minor "sys/sysmacros.h" HAVE_SYSMACROS_MINOR) +check_symbol_exists(major "sys/types.h" HAVE_SYSTYPES_MAJOR) +check_symbol_exists(minor "sys/types.h" HAVE_SYSTYPES_MINOR) +check_symbol_exists(major "sys/mkdev.h" HAVE_SYSMKDEV_MAJOR) +check_symbol_exists(minor "sys/mkdev.h" HAVE_SYSMKDEV_MINOR) + +target_compile_definitions(solidudisks2 PRIVATE + HAVE_SYSMACROS_MAJOR_MINOR=$,$> +) +target_compile_definitions(solidudisks2 PRIVATE + HAVE_SYSTYPES_MAJOR_MINOR=$,$> +) +target_compile_definitions(solidudisks2 PRIVATE + HAVE_SYSMKDEV_MAJOR_MINOR=$,$> +) diff --git a/src/solid/devices/backends/udisks2/CMakeLists.txt b/src/solid/devices/backends/udisks2/CMakeLists.txt index 3439006..710ea9d 100644 --- a/src/solid/devices/backends/udisks2/CMakeLists.txt +++ b/src/solid/devices/backends/udisks2/CMakeLists.txt @@ -1,14 +1,38 @@ set(solid_LIB_SRCS ${solid_LIB_SRCS} devices/backends/udisks2/udisksmanager.cpp devices/backends/udisks2/udisksdevice.cpp devices/backends/udisks2/udisksdevicebackend.cpp devices/backends/udisks2/udisksblock.cpp devices/backends/udisks2/udisksstoragevolume.cpp devices/backends/udisks2/udisksdeviceinterface.cpp devices/backends/udisks2/udisksopticaldisc.cpp devices/backends/udisks2/udisksopticaldrive.cpp devices/backends/udisks2/udisksstoragedrive.cpp devices/backends/udisks2/udisksstorageaccess.cpp devices/backends/udisks2/udisksgenericinterface.cpp devices/backends/udisks2/dbus/manager.cpp -) \ No newline at end of file +) + +# We need the major(3) and minor(3) macros to decompose dev_t device ids +# properly in udisksblock. BSD systems normally have these in sys/types.h. +# Glibc on Linux has a version in that header, but it spits out a deprecation +# warning - on Linux, one should use sys/sysmacros.h. Search for these in +# the relevant headers. +include(CheckSymbolExists) +check_symbol_exists(major "sys/sysmacros.h" HAVE_SYSMACROS_MAJOR) +check_symbol_exists(minor "sys/sysmacros.h" HAVE_SYSMACROS_MINOR) +check_symbol_exists(major "sys/types.h" HAVE_SYSTYPES_MAJOR) +check_symbol_exists(minor "sys/types.h" HAVE_SYSTYPES_MINOR) +check_symbol_exists(major "sys/mkdev.h" HAVE_SYSMKDEV_MAJOR) +check_symbol_exists(minor "sys/mkdev.h" HAVE_SYSMKDEV_MINOR) + +# Set each of these three properties to 0 or 1 +add_definitions( + -DHAVE_SYSMACROS_MAJOR_MINOR=$,$> +) +add_definitions( + -DHAVE_SYSTYPES_MAJOR_MINOR=$,$> +) +add_definitions( + -DHAVE_SYSMKDEV_MAJOR_MINOR=$,$> +) diff --git a/src/solid/devices/backends/udisks2/udisksblock.cpp b/src/solid/devices/backends/udisks2/udisksblock.cpp index 0622ec7..84613e6 100644 --- a/src/solid/devices/backends/udisks2/udisksblock.cpp +++ b/src/solid/devices/backends/udisks2/udisksblock.cpp @@ -1,96 +1,100 @@ /* Copyright 2012 Lukáš Tinkl This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ -#if defined(Q_OS_LINUX) -#include +// Find appropriate major/minor macros - a CMake check tells us +// where to find these. +#if HAVE_SYSMACROS_MAJOR_MINOR +#include +#elif HAVE_SYSTYPES_MAJOR_MINOR +#include +#elif HAVE_SYSMKDEV_MAJOR_MINOR +#include #else -// taken from linux/kdev_t.h -#define MINORBITS 20 -#define MINORMASK ((1U << MINORBITS) - 1) -#define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS)) -#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK)) +// Fall back to the traditional definition of major/minor - 8 bits for each. +#define major(dev) ((dev) >> 8) +#define minor(dev) ((dev) & 0xff) #endif #include #include #include #include #include "udisksblock.h" using namespace Solid::Backends::UDisks2; Block::Block(Device *dev) : DeviceInterface(dev) { m_devNum = m_device->prop("DeviceNumber").toULongLong(); m_devFile = QFile::decodeName(m_device->prop("Device").toByteArray()); // we have a drive (non-block device for udisks), so let's find the corresponding (real) block device if (m_devNum == 0 || m_devFile.isEmpty()) { const QString path = "/org/freedesktop/UDisks2/block_devices"; QDBusMessage call = QDBusMessage::createMethodCall(UD2_DBUS_SERVICE, path, DBUS_INTERFACE_INTROSPECT, "Introspect"); QDBusPendingReply reply = QDBusConnection::systemBus().asyncCall(call); reply.waitForFinished(); if (reply.isValid()) { QDomDocument dom; dom.setContent(reply.value()); QDomNodeList nodeList = dom.documentElement().elementsByTagName("node"); for (int i = 0; i < nodeList.count(); i++) { QDomElement nodeElem = nodeList.item(i).toElement(); if (!nodeElem.isNull() && nodeElem.hasAttribute("name")) { const QString udi = path + "/" + nodeElem.attribute("name"); Device device(udi); if (device.drivePath() == dev->udi()) { m_devNum = device.prop("DeviceNumber").toULongLong(); m_devFile = QFile::decodeName(device.prop("Device").toByteArray()); break; } } } } else { qWarning() << "Failed enumerating UDisks2 objects:" << reply.error().name() << "\n" << reply.error().message(); } } //qDebug() << "devnum:" << m_devNum << "dev file:" << m_devFile; } Block::~Block() { } QString Block::device() const { return m_devFile; } int Block::deviceMinor() const { - return MINOR(m_devNum); + return minor(m_devNum); } int Block::deviceMajor() const { - return MAJOR(m_devNum); + return major(m_devNum); }