/* SPDX-FileCopyrightText: 2008-2010 Volker Lanz SPDX-FileCopyrightText: 2014-2019 Andrius Štikonas SPDX-FileCopyrightText: 2015 Teo Mrnjavac SPDX-FileCopyrightText: 2016 Chantara Tith SPDX-License-Identifier: GPL-3.0-or-later */ /** @file */ #include "plugins/dummy/dummybackend.h" #include "plugins/dummy/dummydevice.h" #include "core/diskdevice.h" #include "core/partition.h" #include "core/partitiontable.h" #include "util/globallog.h" #include #include #include #include K_PLUGIN_CLASS_WITH_JSON(DummyBackend, "pmdummybackendplugin.json") DummyBackend::DummyBackend(QObject*, const QList&) : CoreBackend() { } void DummyBackend::initFSSupport() { } QList DummyBackend::scanDevices(bool excludeReadOnly) { Q_UNUSED(excludeReadOnly) return scanDevices(ScanFlags()); } QList DummyBackend::scanDevices(const ScanFlags scanFlags) { Q_UNUSED(scanFlags) QList result; result.append(scanDevice(QStringLiteral("/dev/sda"))); emitScanProgress(QStringLiteral("/dev/sda"), 100); return result; } Device* DummyBackend::scanDevice(const QString& deviceNode) { DiskDevice* d = new DiskDevice(QStringLiteral("Dummy Device"), QStringLiteral("/tmp") + deviceNode, 255, 30, 63, 512); 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")); CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 4); return d; } FileSystem::Type DummyBackend::detectFileSystem(const QString& deviceNode) { Q_UNUSED(deviceNode) return FileSystem::Type::Unknown; } QString DummyBackend::readLabel(const QString& deviceNode) const { Q_UNUSED(deviceNode) return QString(); } QString DummyBackend::readUUID(const QString& deviceNode) const { Q_UNUSED(deviceNode) return QString(); } std::unique_ptr DummyBackend::openDevice(const Device& d) { std::unique_ptr device = std::make_unique(d.deviceNode()); if (!device->open()) device = nullptr; return device; } std::unique_ptr DummyBackend::openDeviceExclusive(const Device& d) { std::unique_ptr device = std::make_unique(d.deviceNode()); if (!device->openExclusive()) device = nullptr; return device; } bool DummyBackend::closeDevice(std::unique_ptr coreDevice) { return coreDevice->close(); } #include "dummybackend.moc"