sfdisk: store a pointer to the device in SfdiskPartitionTable class.
This commit is contained in:
parent
41473119b1
commit
55b8cd3e6b
|
@ -17,8 +17,8 @@
|
|||
|
||||
#include "backend/corebackenddevice.h"
|
||||
|
||||
CoreBackendDevice::CoreBackendDevice(const QString& device_node) :
|
||||
m_DeviceNode(device_node),
|
||||
CoreBackendDevice::CoreBackendDevice(const QString& deviceNode) :
|
||||
m_DeviceNode(deviceNode),
|
||||
m_Exclusive(false)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class Report;
|
|||
class LIBKPMCORE_EXPORT CoreBackendDevice
|
||||
{
|
||||
public:
|
||||
CoreBackendDevice(const QString& device_node);
|
||||
CoreBackendDevice(const QString& deviceNode);
|
||||
virtual ~CoreBackendDevice() {}
|
||||
|
||||
public:
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#include "util/globallog.h"
|
||||
#include "util/report.h"
|
||||
|
||||
DummyDevice::DummyDevice(const QString& device_node) :
|
||||
CoreBackendDevice(device_node)
|
||||
DummyDevice::DummyDevice(const QString& deviceNode) :
|
||||
CoreBackendDevice(deviceNode)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class DummyDevice : public CoreBackendDevice
|
|||
Q_DISABLE_COPY(DummyDevice)
|
||||
|
||||
public:
|
||||
DummyDevice(const QString& device_node);
|
||||
DummyDevice(const QString& deviceNode);
|
||||
~DummyDevice();
|
||||
|
||||
public:
|
||||
|
|
|
@ -365,7 +365,7 @@ PartitionTable::Flags SfdiskBackend::availableFlags(PartitionTable::TableType ty
|
|||
|
||||
CoreBackendDevice* SfdiskBackend::openDevice(const Device& d)
|
||||
{
|
||||
SfdiskDevice* device = new SfdiskDevice(d.deviceNode());
|
||||
SfdiskDevice* device = new SfdiskDevice(d);
|
||||
|
||||
if (device == nullptr || !device->open()) {
|
||||
delete device;
|
||||
|
@ -377,7 +377,7 @@ CoreBackendDevice* SfdiskBackend::openDevice(const Device& d)
|
|||
|
||||
CoreBackendDevice* SfdiskBackend::openDeviceExclusive(const Device& d)
|
||||
{
|
||||
SfdiskDevice* device = new SfdiskDevice(d.deviceNode());
|
||||
SfdiskDevice* device = new SfdiskDevice(d);
|
||||
|
||||
if (device == nullptr || !device->openExclusive()) {
|
||||
delete device;
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
#include "util/externalcommand.h"
|
||||
#include "util/report.h"
|
||||
|
||||
SfdiskDevice::SfdiskDevice(const QString& deviceNode) :
|
||||
CoreBackendDevice(deviceNode),
|
||||
m_deviceNode(deviceNode)
|
||||
SfdiskDevice::SfdiskDevice(const Device& d) :
|
||||
CoreBackendDevice(d.deviceNode()),
|
||||
m_device(&d)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ bool SfdiskDevice::close()
|
|||
|
||||
CoreBackendPartitionTable* SfdiskDevice::openPartitionTable()
|
||||
{
|
||||
CoreBackendPartitionTable* ptable = new SfdiskPartitionTable(m_deviceNode);
|
||||
CoreBackendPartitionTable* ptable = new SfdiskPartitionTable(m_device);
|
||||
|
||||
if (ptable == nullptr || !ptable->open()) {
|
||||
delete ptable;
|
||||
|
@ -73,7 +73,7 @@ bool SfdiskDevice::createPartitionTable(Report& report, const PartitionTable& pt
|
|||
else
|
||||
tableType = ptable.typeName().toLocal8Bit();
|
||||
|
||||
ExternalCommand createCommand(report, QStringLiteral("sfdisk"), { m_deviceNode } );
|
||||
ExternalCommand createCommand(report, QStringLiteral("sfdisk"), { m_device->deviceNode() } );
|
||||
if ( createCommand.start(-1) && createCommand.write(QByteArrayLiteral("label: ") + tableType +
|
||||
QByteArrayLiteral("\nwrite\n")) && createCommand.waitFor() ) {
|
||||
return createCommand.output().contains(QStringLiteral("Script header accepted."));
|
||||
|
@ -92,7 +92,7 @@ bool SfdiskDevice::readData(QByteArray& buffer, qint64 offset, qint64 size)
|
|||
QStringLiteral("bs=") + QString::number(size),
|
||||
QStringLiteral("count=1"),
|
||||
QStringLiteral("iflag=skip_bytes"),
|
||||
QStringLiteral("if=") + m_deviceNode }, QProcess::SeparateChannels);
|
||||
QStringLiteral("if=") + m_device->deviceNode() }, QProcess::SeparateChannels);
|
||||
if (ddCommand.run(-1) && ddCommand.exitCode() == 0) {
|
||||
buffer = ddCommand.rawOutput();
|
||||
return true;
|
||||
|
@ -107,7 +107,7 @@ bool SfdiskDevice::writeData(QByteArray& buffer, qint64 offset)
|
|||
return false;
|
||||
|
||||
ExternalCommand ddCommand(QStringLiteral("dd"), {
|
||||
QStringLiteral("of=") + m_deviceNode,
|
||||
QStringLiteral("of=") + m_device->deviceNode(),
|
||||
QStringLiteral("seek=") + QString::number(offset),
|
||||
QStringLiteral("bs=1M"),
|
||||
QStringLiteral("oflag=seek_bytes"),
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define SFDISKDEVICE__H
|
||||
|
||||
#include "backend/corebackenddevice.h"
|
||||
#include "core/device.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
|
@ -33,7 +34,7 @@ class SfdiskDevice : public CoreBackendDevice
|
|||
Q_DISABLE_COPY(SfdiskDevice);
|
||||
|
||||
public:
|
||||
SfdiskDevice(const QString& deviceNode);
|
||||
SfdiskDevice(const Device& d);
|
||||
~SfdiskDevice();
|
||||
|
||||
public:
|
||||
|
@ -49,7 +50,7 @@ public:
|
|||
bool writeData(QByteArray& buffer, qint64 offset) override;
|
||||
|
||||
private:
|
||||
QString m_deviceNode;
|
||||
const Device *m_device;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -37,9 +37,9 @@
|
|||
|
||||
#include <KLocalizedString>
|
||||
|
||||
SfdiskPartitionTable::SfdiskPartitionTable(const QString& deviceNode) :
|
||||
SfdiskPartitionTable::SfdiskPartitionTable(const Device* d) :
|
||||
CoreBackendPartitionTable(),
|
||||
m_deviceNode(deviceNode)
|
||||
m_device(d)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ QString SfdiskPartitionTable::createPartition(Report& report, const Partition& p
|
|||
return partition.devicePath() + rem.captured(1);
|
||||
}
|
||||
|
||||
report.line() << xi18nc("@info:progress", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition.deviceNode(), m_deviceNode);
|
||||
report.line() << xi18nc("@info:progress", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition.deviceNode(), m_device->deviceNode());
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
@ -167,20 +167,20 @@ bool SfdiskPartitionTable::setPartitionSystemType(Report& report, const Partitio
|
|||
bool SfdiskPartitionTable::setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state)
|
||||
{
|
||||
if (flag == PartitionTable::FlagBoot && state == true) {
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--activate"), m_deviceNode, QString::number(partition.number()) } );
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--activate"), m_device->deviceNode(), QString::number(partition.number()) } );
|
||||
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else if (flag == PartitionTable::FlagBoot && state == false) {
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--activate"), m_deviceNode, QStringLiteral("-") } );
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--activate"), m_device->deviceNode(), QStringLiteral("-") } );
|
||||
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
|
||||
return true;
|
||||
// FIXME: Do not return false since we have no way of checking if partition table is MBR
|
||||
}
|
||||
|
||||
if (flag == PartitionTable::FlagEsp && state == true) {
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-type"), m_deviceNode, QString::number(partition.number()),
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-type"), m_device->deviceNode(), QString::number(partition.number()),
|
||||
QStringLiteral("C12A7328-F81F-11D2-BA4B-00A0C93EC93B") } );
|
||||
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
|
||||
return true;
|
||||
|
@ -191,7 +191,7 @@ bool SfdiskPartitionTable::setFlag(Report& report, const Partition& partition, P
|
|||
setPartitionSystemType(report, partition);
|
||||
|
||||
if (flag == PartitionTable::FlagBiosGrub && state == true) {
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-type"), m_deviceNode, QString::number(partition.number()),
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-type"), m_device->deviceNode(), QString::number(partition.number()),
|
||||
QStringLiteral("21686148-6449-6E6F-744E-656564454649") } );
|
||||
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
|
||||
return true;
|
||||
|
|
|
@ -32,7 +32,7 @@ class Partition;
|
|||
class SfdiskPartitionTable : public CoreBackendPartitionTable
|
||||
{
|
||||
public:
|
||||
SfdiskPartitionTable(const QString& deviceNode);
|
||||
SfdiskPartitionTable(const Device *d);
|
||||
~SfdiskPartitionTable();
|
||||
|
||||
public:
|
||||
|
@ -50,7 +50,7 @@ public:
|
|||
bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state) override;
|
||||
|
||||
private:
|
||||
QString m_deviceNode;
|
||||
const Device *m_device;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue