File indexing completed on 2024-05-12 05:48:27
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2014-2019 Andrius Štikonas <andrius@stikonas.eu> 0004 SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org> 0005 SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-3.0-or-later 0008 */ 0009 0010 /** @file 0011 */ 0012 0013 #include "plugins/dummy/dummybackend.h" 0014 #include "plugins/dummy/dummydevice.h" 0015 0016 #include "core/diskdevice.h" 0017 #include "core/partition.h" 0018 #include "core/partitiontable.h" 0019 0020 #include "util/globallog.h" 0021 0022 #include <QString> 0023 #include <QStringList> 0024 0025 #include <KLocalizedString> 0026 #include <KPluginFactory> 0027 0028 K_PLUGIN_CLASS_WITH_JSON(DummyBackend, "pmdummybackendplugin.json") 0029 0030 0031 DummyBackend::DummyBackend(QObject*, const QList<QVariant>&) : 0032 CoreBackend() 0033 { 0034 } 0035 0036 void DummyBackend::initFSSupport() 0037 { 0038 } 0039 0040 QList<Device*> DummyBackend::scanDevices(bool excludeReadOnly) 0041 { 0042 Q_UNUSED(excludeReadOnly) 0043 return scanDevices(ScanFlags()); 0044 } 0045 0046 QList<Device*> DummyBackend::scanDevices(const ScanFlags scanFlags) 0047 { 0048 Q_UNUSED(scanFlags) 0049 QList<Device*> result; 0050 result.append(scanDevice(QStringLiteral("/dev/sda"))); 0051 0052 emitScanProgress(QStringLiteral("/dev/sda"), 100); 0053 0054 return result; 0055 } 0056 0057 Device* DummyBackend::scanDevice(const QString& deviceNode) 0058 { 0059 DiskDevice* d = new DiskDevice(QStringLiteral("Dummy Device"), QStringLiteral("/tmp") + deviceNode, 255, 30, 63, 512); 0060 CoreBackend::setPartitionTableForDevice(*d, new PartitionTable(PartitionTable::msdos_sectorbased, 2048, d->totalSectors() - 2048)); 0061 CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 128); 0062 d->partitionTable()->updateUnallocated(*d); 0063 d->setIconName(QStringLiteral("drive-harddisk")); 0064 0065 CoreBackend::setPartitionTableMaxPrimaries(*d->partitionTable(), 4); 0066 0067 return d; 0068 } 0069 0070 FileSystem::Type DummyBackend::detectFileSystem(const QString& deviceNode) 0071 { 0072 Q_UNUSED(deviceNode) 0073 0074 return FileSystem::Type::Unknown; 0075 } 0076 0077 QString DummyBackend::readLabel(const QString& deviceNode) const 0078 { 0079 Q_UNUSED(deviceNode) 0080 0081 return QString(); 0082 } 0083 0084 QString DummyBackend::readUUID(const QString& deviceNode) const 0085 { 0086 Q_UNUSED(deviceNode) 0087 0088 return QString(); 0089 } 0090 0091 std::unique_ptr<CoreBackendDevice> DummyBackend::openDevice(const Device& d) 0092 { 0093 std::unique_ptr<DummyDevice> device = std::make_unique<DummyDevice>(d.deviceNode()); 0094 0095 if (!device->open()) 0096 device = nullptr; 0097 0098 return device; 0099 } 0100 0101 std::unique_ptr<CoreBackendDevice> DummyBackend::openDeviceExclusive(const Device& d) 0102 { 0103 std::unique_ptr<DummyDevice> device = std::make_unique<DummyDevice>(d.deviceNode()); 0104 0105 if (!device->openExclusive()) 0106 device = nullptr; 0107 0108 return device; 0109 } 0110 0111 bool DummyBackend::closeDevice(std::unique_ptr<CoreBackendDevice> coreDevice) 0112 { 0113 return coreDevice->close(); 0114 } 0115 0116 #include "dummybackend.moc"