2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
2016-03-02 19:00:31 +00:00
|
|
|
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
2015-06-04 01:29:22 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
/** @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>
|
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
K_PLUGIN_FACTORY_WITH_JSON(DummyBackendFactory, "pmdummybackendplugin.json", registerPlugin<DummyBackend>();)
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-22 13:18:34 +01:00
|
|
|
QList<Device*> DummyBackend::scanDevices(bool excludeLoop)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2016-07-22 13:18:34 +01:00
|
|
|
Q_UNUSED(excludeLoop)
|
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
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return result;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Device* DummyBackend::scanDevice(const QString& device_node)
|
|
|
|
{
|
2016-05-31 19:28:31 +01:00
|
|
|
DiskDevice* d = new DiskDevice(QStringLiteral("Dummy Device"), QStringLiteral("/tmp") + device_node, 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)
|
|
|
|
|
|
|
|
return FileSystem::Unknown;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:29:22 +01:00
|
|
|
CoreBackendDevice* DummyBackend::openDevice(const QString& device_node)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
DummyDevice* device = new DummyDevice(device_node);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-22 14:48:03 +01:00
|
|
|
if (device == nullptr || !device->open()) {
|
2015-07-13 15:16:36 +01:00
|
|
|
delete device;
|
2015-07-22 14:48:03 +01:00
|
|
|
device = nullptr;
|
2015-07-13 15:16:36 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
CoreBackendDevice* DummyBackend::openDeviceExclusive(const QString& device_node)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
DummyDevice* device = new DummyDevice(device_node);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-22 14:48:03 +01:00
|
|
|
if (device == nullptr || !device->openExclusive()) {
|
2015-07-13 15:16:36 +01:00
|
|
|
delete device;
|
2015-07-22 14:48:03 +01:00
|
|
|
device = nullptr;
|
2015-07-13 15:16:36 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool DummyBackend::closeDevice(CoreBackendDevice* core_device)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return core_device->close();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "dummybackend.moc"
|