Warning, file /utilities/isoimagewriter/isoimagewriter/platform_lin.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
0003     SPDX-License-Identifier: GPL-3.0-or-later
0004 */
0005 
0006 ////////////////////////////////////////////////////////////////////////////////
0007 // This file contains Linux implementation of platform-dependent functions
0008 
0009 #include <KLocalizedString>
0010 
0011 #include <QMessageBox>
0012 #include <QDir>
0013 #include <QRegularExpression>
0014 #include <Solid/Block>
0015 #include <Solid/Device>
0016 #include <Solid/StorageDrive>
0017 
0018 #include "mainapplication.h"
0019 #include "usbdevice.h"
0020 
0021 
0022 bool platformEnumFlashDevices(AddFlashDeviceCallbackProc callback, void* cbParam)
0023 {
0024     const auto devices = Solid::Device::listFromType(Solid::DeviceInterface::StorageDrive);
0025     for (const auto &device : devices) {
0026         if (!device.is<Solid::StorageDrive>()) {
0027             qDebug() << "Ignoring" << device.displayName() << device.udi();
0028             continue;
0029         }
0030 
0031         auto storageDrive = device.as<Solid::StorageDrive>();
0032         auto block = device.as<Solid::Block>();
0033         if (storageDrive->isInUse()) {
0034             qDebug() << "Skipping" << device.displayName() << device.udi();
0035             continue;
0036         }
0037 
0038         UsbDevice* deviceData = new UsbDevice;
0039         deviceData->m_PhysicalDevice = block->device();
0040         deviceData->m_Volumes = QStringList{ deviceData->m_PhysicalDevice };
0041 
0042         const QString logicalBlockSizeFile = QStringLiteral("/sys/dev/block/%1:%2/queue/logical_block_size").arg(block->deviceMajor())
0043                                                                                                             .arg(block->deviceMinor());
0044         deviceData->m_SectorSize = readFileContents(logicalBlockSizeFile).toUInt();
0045         if (deviceData->m_SectorSize == 0)
0046             deviceData->m_SectorSize = 512;
0047         deviceData->m_Size = storageDrive->size();
0048         deviceData->m_VisibleName = device.displayName();
0049 
0050         callback(cbParam, deviceData);
0051     }
0052     return true;
0053 }
0054 
0055 bool ensureElevated()
0056 {
0057     // on Linux we use KAuth which uses polkit to run necessary bits as root
0058     return true;
0059 }