2020-09-30 23:58:54 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2019 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "plugins/dummy/dummybackend.h"
|
|
|
|
#include "plugins/dummy/dummydevice.h"
|
|
|
|
|
2016-05-31 19:28:31 +01:00
|
|
|
#include "core/diskdevice.h"
|
2015-06-04 01:29:22 +01:00
|
|
|
#include "core/partition.h"
|
|
|
|
#include "core/partitiontable.h"
|
|
|
|
|
|
|
|
#include "util/globallog.h"
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KPluginFactory>
|
|
|
|
|
2021-12-24 18:58:27 +00:00
|
|
|
K_PLUGIN_CLASS_WITH_JSON(DummyBackend, "pmdummybackendplugin.json")
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
DummyBackend::DummyBackend(QObject*, const QList<QVariant>&) :
|
2015-07-13 15:16:36 +01:00
|
|
|
CoreBackend()
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DummyBackend::initFSSupport()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-09 15:40:06 +00:00
|
|
|
QList<Device*> DummyBackend::scanDevices(bool excludeReadOnly)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2019-02-09 15:40:06 +00:00
|
|
|
Q_UNUSED(excludeReadOnly)
|
|
|
|
return scanDevices(ScanFlags());
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Device*> DummyBackend::scanDevices(const ScanFlags scanFlags)
|
|
|
|
{
|
|
|
|
Q_UNUSED(scanFlags)
|
2015-07-13 15:16:36 +01:00
|
|
|
QList<Device*> result;
|
|
|
|
result.append(scanDevice(QStringLiteral("/dev/sda")));
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
emitScanProgress(QStringLiteral("/dev/sda"), 100);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2022-01-16 14:22:50 +00:00
|
|
|
return result;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
2017-12-06 21:33:31 +00:00
|
|
|
Device* DummyBackend::scanDevice(const QString& deviceNode)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2017-12-06 21:33:31 +00:00
|
|
|
DiskDevice* d = new DiskDevice(QStringLiteral("Dummy Device"), QStringLiteral("/tmp") + deviceNode, 255, 30, 63, 512);
|
2015-07-13 15:16:36 +01:00
|
|
|
CoreBackend::setPartitionTableForDevice(*d, new PartitionTable(PartitionTable::msdos_sectorbased, 2048, d->totalSectors() - 2048));
|
|
|
|
CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 128);
|
|
|
|
d->partitionTable()->updateUnallocated(*d);
|
|
|
|
d->setIconName(QStringLiteral("drive-harddisk"));
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 4);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return d;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
2016-05-06 22:42:01 +01:00
|
|
|
FileSystem::Type DummyBackend::detectFileSystem(const QString& deviceNode)
|
|
|
|
{
|
|
|
|
Q_UNUSED(deviceNode)
|
|
|
|
|
2018-04-07 19:54:30 +01:00
|
|
|
return FileSystem::Type::Unknown;
|
2016-05-06 22:42:01 +01:00
|
|
|
}
|
|
|
|
|
2018-01-31 15:04:55 +00:00
|
|
|
QString DummyBackend::readLabel(const QString& deviceNode) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(deviceNode)
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DummyBackend::readUUID(const QString& deviceNode) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(deviceNode)
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2018-03-31 14:44:40 +01:00
|
|
|
std::unique_ptr<CoreBackendDevice> DummyBackend::openDevice(const Device& d)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2018-03-31 14:44:40 +01:00
|
|
|
std::unique_ptr<DummyDevice> device = std::make_unique<DummyDevice>(d.deviceNode());
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2018-03-31 14:44:40 +01:00
|
|
|
if (!device->open())
|
2015-07-22 14:48:03 +01:00
|
|
|
device = nullptr;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return device;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 14:44:40 +01:00
|
|
|
std::unique_ptr<CoreBackendDevice> DummyBackend::openDeviceExclusive(const Device& d)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2018-03-31 14:44:40 +01:00
|
|
|
std::unique_ptr<DummyDevice> device = std::make_unique<DummyDevice>(d.deviceNode());
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2018-03-31 14:44:40 +01:00
|
|
|
if (!device->openExclusive())
|
2015-07-22 14:48:03 +01:00
|
|
|
device = nullptr;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return device;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
2018-03-31 14:44:40 +01:00
|
|
|
bool DummyBackend::closeDevice(std::unique_ptr<CoreBackendDevice> coreDevice)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2017-12-06 21:33:31 +00:00
|
|
|
return coreDevice->close();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "dummybackend.moc"
|