diff --git a/src/backend/corebackenddevice.h b/src/backend/corebackenddevice.h index 600adc6..b3c3126 100644 --- a/src/backend/corebackenddevice.h +++ b/src/backend/corebackenddevice.h @@ -91,23 +91,6 @@ public: */ virtual bool createPartitionTable(Report& report, const PartitionTable& ptable) = 0; - /** - * Read data from an opened device into a buffer. - * @param buffer the buffer to write the read data to - * @param offset offset byte where to start reading on the device - * @param size the number of bytes to read - * @return true on success - */ - virtual bool readData(QByteArray& buffer, qint64 offset, qint64 size) = 0; - - /** - * Write data from a buffer to an exclusively opened device. - * @param buffer the buffer with the data - * @param offset offset byte where to start writing to the device - * @return true on success - */ - virtual bool writeData(QByteArray& buffer, qint64 offset) = 0; - protected: void setExclusive(bool b) { m_Exclusive = b; diff --git a/src/core/copysource.h b/src/core/copysource.h index 3f25e7f..f8f36b2 100644 --- a/src/core/copysource.h +++ b/src/core/copysource.h @@ -43,7 +43,6 @@ protected: public: virtual bool open() = 0; virtual QString path() const = 0; - virtual bool readData(QByteArray& buffer, qint64 readOffset, qint64 size) = 0; virtual qint64 length() const = 0; virtual bool overlaps(const CopyTarget& target) const = 0; diff --git a/src/core/copysourcedevice.cpp b/src/core/copysourcedevice.cpp index 3b91744..9754a0d 100644 --- a/src/core/copysourcedevice.cpp +++ b/src/core/copysourcedevice.cpp @@ -63,22 +63,6 @@ qint64 CopySourceDevice::length() const return lastByte() - firstByte() + 1; } -/** Reads a given number of bytes from the Device into the given buffer. - - Note that @p readOffset must be greater or equal than zero. - - @param buffer the buffer to store the read bytes in - @param readOffset the offset to begin reading - @param size the number of bytes to read - - @return true if successful -*/ -bool CopySourceDevice::readData(QByteArray& buffer, qint64 readOffset, qint64 size) -{ - Q_ASSERT(readOffset >= 0); - return m_BackendDevice->readData(buffer, readOffset, size); -} - /** Checks if this CopySourceDevice overlaps with the given CopyTarget @param target the CopyTarget to check overlapping with @return true if overlaps diff --git a/src/core/copysourcedevice.h b/src/core/copysourcedevice.h index 04f1734..bfdbd45 100644 --- a/src/core/copysourcedevice.h +++ b/src/core/copysourcedevice.h @@ -45,7 +45,6 @@ public: public: bool open() override; - bool readData(QByteArray& buffer, qint64 readOffset, qint64 size) override; qint64 length() const override; bool overlaps(const CopyTarget& target) const override; diff --git a/src/core/copysourcefile.cpp b/src/core/copysourcefile.cpp index 936aec0..40c3a15 100644 --- a/src/core/copysourcefile.cpp +++ b/src/core/copysourcefile.cpp @@ -45,18 +45,3 @@ qint64 CopySourceFile::length() const { return QFileInfo(file()).size(); } - -/** Reads the given number of bytes from the file into the given buffer. - @param buffer buffer to store the bytes read in - @param readOffset offset where to begin reading - @param size the number of bytes to read - @return true on success -*/ -bool CopySourceFile::readData(QByteArray& buffer, qint64 readOffset, qint64 size) -{ - if (!file().seek(readOffset)) - return false; - - buffer = file().read(size); - return !buffer.isEmpty(); -} diff --git a/src/core/copysourcefile.h b/src/core/copysourcefile.h index 0ff8ff7..3a5cebd 100644 --- a/src/core/copysourcefile.h +++ b/src/core/copysourcefile.h @@ -40,7 +40,6 @@ public: public: bool open() override; - bool readData(QByteArray& buffer, qint64 readOffset, qint64 size) override; qint64 length() const override; bool overlaps(const CopyTarget&) const override { diff --git a/src/core/copysourceshred.cpp b/src/core/copysourceshred.cpp index b8d708e..91ab354 100644 --- a/src/core/copysourceshred.cpp +++ b/src/core/copysourceshred.cpp @@ -43,17 +43,3 @@ qint64 CopySourceShred::length() const { return size(); } - -/** Reads the given number of bytes from the source into the given buffer. - @param buffer buffer to store the data read in - @param readOffset offset where to begin reading (unused) - @param size the number of bytes to read - @return true on success -*/ -bool CopySourceShred::readData(QByteArray& buffer, qint64 readOffset, qint64 size) -{ - Q_UNUSED(readOffset); - - buffer = sourceFile().read(size); - return !buffer.isEmpty(); -} diff --git a/src/core/copysourceshred.h b/src/core/copysourceshred.h index e293531..a181100 100644 --- a/src/core/copysourceshred.h +++ b/src/core/copysourceshred.h @@ -39,7 +39,6 @@ public: public: bool open() override; - bool readData(QByteArray& buffer, qint64 readOffset, qint64 size) override; qint64 length() const override; bool overlaps(const CopyTarget&) const override { diff --git a/src/core/copytarget.h b/src/core/copytarget.h index 97385a1..92324f6 100644 --- a/src/core/copytarget.h +++ b/src/core/copytarget.h @@ -41,7 +41,6 @@ protected: public: virtual bool open() = 0; - virtual bool writeData(QByteArray& buffer, qint64 writeOffset) = 0; virtual qint64 firstByte() const = 0; virtual qint64 lastByte() const = 0; virtual QString path() const = 0; diff --git a/src/core/copytargetdevice.cpp b/src/core/copytargetdevice.cpp index 92e67f2..2ad9a02 100644 --- a/src/core/copytargetdevice.cpp +++ b/src/core/copytargetdevice.cpp @@ -52,25 +52,6 @@ bool CopyTargetDevice::open() return m_BackendDevice != nullptr; } -/** Writes the given number of bytes to the Device. - - Note that @p writeOffset must be greater or equal than zero. - - @param buffer the data to write - @param writeOffset where to start writing on the Device - @return true on success -*/ -bool CopyTargetDevice::writeData(QByteArray& buffer, qint64 writeOffset) -{ - Q_ASSERT(writeOffset >= 0); - bool rval = m_BackendDevice->writeData(buffer, writeOffset); - - if (rval) - setBytesWritten(bytesWritten() + buffer.size()); - - return rval; -} - QString CopyTargetDevice::path() const { return m_Device.deviceNode(); diff --git a/src/core/copytargetdevice.h b/src/core/copytargetdevice.h index 556b75e..f7021d2 100644 --- a/src/core/copytargetdevice.h +++ b/src/core/copytargetdevice.h @@ -46,7 +46,6 @@ public: public: bool open() override; - bool writeData(QByteArray& buffer, qint64 writeOffset) override; qint64 firstByte() const override { return m_FirstByte; /**< @return the first byte to write to */ } diff --git a/src/core/copytargetfile.cpp b/src/core/copytargetfile.cpp index 508f9b2..bd87637 100644 --- a/src/core/copytargetfile.cpp +++ b/src/core/copytargetfile.cpp @@ -33,21 +33,3 @@ bool CopyTargetFile::open() { return file().open(QIODevice::WriteOnly | QIODevice::Truncate); } - -/** Writes the given number of bytes from the given buffer to the file. - @param buffer the data to write - @param writeOffset where in the file to start writing - @return true on success -*/ -bool CopyTargetFile::writeData(QByteArray& buffer, qint64 writeOffset) -{ - if (!file().seek(writeOffset)) - return false; - - bool rval = file().write(buffer) == buffer.size(); - - if (rval) - setBytesWritten(bytesWritten() + buffer.size()); - - return rval; -} diff --git a/src/core/copytargetfile.h b/src/core/copytargetfile.h index 17ecff2..258a403 100644 --- a/src/core/copytargetfile.h +++ b/src/core/copytargetfile.h @@ -40,7 +40,6 @@ public: public: bool open() override; - bool writeData(QByteArray& buffer, qint64 writeOffset) override; qint64 firstByte() const override { return 0; /**< @return always 0 for a file */ diff --git a/src/plugins/dummy/dummydevice.cpp b/src/plugins/dummy/dummydevice.cpp index 92c2de7..d2b43e9 100644 --- a/src/plugins/dummy/dummydevice.cpp +++ b/src/plugins/dummy/dummydevice.cpp @@ -66,26 +66,3 @@ bool DummyDevice::createPartitionTable(Report& report, const PartitionTable& pta return true; } - -bool DummyDevice::readData(QByteArray& buffer, qint64 offset, qint64 size) -{ - Q_UNUSED(buffer); - Q_UNUSED(offset); - Q_UNUSED(size); - - if (!isExclusive()) - return false; - - return true; -} - -bool DummyDevice::writeData(QByteArray& buffer, qint64 offset) -{ - Q_UNUSED(buffer); - Q_UNUSED(offset); - - if (!isExclusive()) - return false; - - return true; -} diff --git a/src/plugins/dummy/dummydevice.h b/src/plugins/dummy/dummydevice.h index 9493365..6895e65 100644 --- a/src/plugins/dummy/dummydevice.h +++ b/src/plugins/dummy/dummydevice.h @@ -44,9 +44,6 @@ public: CoreBackendPartitionTable* openPartitionTable() override; bool createPartitionTable(Report& report, const PartitionTable& ptable) override; - - bool readData(QByteArray& buffer, qint64 offset, qint64 size) override; - bool writeData(QByteArray& buffer, qint64 offset) override; }; #endif diff --git a/src/plugins/libparted/libparteddevice.cpp b/src/plugins/libparted/libparteddevice.cpp index 6354b58..d97e41c 100644 --- a/src/plugins/libparted/libparteddevice.cpp +++ b/src/plugins/libparted/libparteddevice.cpp @@ -110,23 +110,3 @@ bool LibPartedDevice::createPartitionTable(Report& report, const PartitionTable& return LibPartedPartitionTable::commit(disk); } - -bool LibPartedDevice::readData(QByteArray& buffer, qint64 offset, qint64 size) -{ - if (!isExclusive()) - return false; - - void *data = malloc(size); - bool rval = ped_device_read(pedDevice(), data, offset / pedDevice()->sector_size, size / pedDevice()->sector_size); - buffer = QByteArray(static_cast(data), size); - free(data); - return rval; -} - -bool LibPartedDevice::writeData(QByteArray& buffer, qint64 offset) -{ - if (!isExclusive()) - return false; - - return ped_device_write(pedDevice(), static_cast(buffer.constData()), offset / pedDevice()->sector_size, buffer.size() / pedDevice()->sector_size); -} diff --git a/src/plugins/libparted/libparteddevice.h b/src/plugins/libparted/libparteddevice.h index c8d98c0..dc8f16a 100644 --- a/src/plugins/libparted/libparteddevice.h +++ b/src/plugins/libparted/libparteddevice.h @@ -47,9 +47,6 @@ public: bool createPartitionTable(Report& report, const PartitionTable& ptable) override; - bool readData(QByteArray& buffer, qint64 offset, qint64 size) override; - bool writeData(QByteArray& buffer, qint64 offset) override; - protected: PedDevice* pedDevice() { return m_PedDevice; diff --git a/src/plugins/sfdisk/sfdiskdevice.cpp b/src/plugins/sfdisk/sfdiskdevice.cpp index c8ce382..7dfc248 100644 --- a/src/plugins/sfdisk/sfdiskdevice.cpp +++ b/src/plugins/sfdisk/sfdiskdevice.cpp @@ -79,40 +79,3 @@ bool SfdiskDevice::createPartitionTable(Report& report, const PartitionTable& pt return false; } - -bool SfdiskDevice::readData(QByteArray& buffer, qint64 offset, qint64 size) -{ - if (!isExclusive()) - return false; - - ExternalCommand ddCommand(QStringLiteral("dd"), { - QStringLiteral("skip=") + QString::number(offset), - QStringLiteral("bs=") + QString::number(size), - QStringLiteral("count=1"), - QStringLiteral("iflag=skip_bytes"), - QStringLiteral("if=") + m_device->deviceNode() }, QProcess::SeparateChannels); - if (ddCommand.run(-1) && ddCommand.exitCode() == 0) { - buffer = ddCommand.rawOutput(); - return true; - } - - return false; -} - -bool SfdiskDevice::writeData(QByteArray& buffer, qint64 offset) -{ - if (!isExclusive()) - return false; - - ExternalCommand ddCommand(QStringLiteral("dd"), { - QStringLiteral("of=") + m_device->deviceNode(), - QStringLiteral("seek=") + QString::number(offset), - QStringLiteral("bs=1M"), - QStringLiteral("oflag=seek_bytes"), - QStringLiteral("conv=fsync") }, QProcess::SeparateChannels); - if ( ddCommand.write(buffer) && ddCommand.start(-1) && ddCommand.waitFor() && ddCommand.exitCode() == 0 ) { - return true; - } - - return false; -} diff --git a/src/plugins/sfdisk/sfdiskdevice.h b/src/plugins/sfdisk/sfdiskdevice.h index aeab327..096dd74 100644 --- a/src/plugins/sfdisk/sfdiskdevice.h +++ b/src/plugins/sfdisk/sfdiskdevice.h @@ -46,9 +46,6 @@ public: bool createPartitionTable(Report& report, const PartitionTable& ptable) override; - bool readData(QByteArray& buffer, qint64 offset, qint64 size) override; - bool writeData(QByteArray& buffer, qint64 offset) override; - private: const Device *m_device; }; diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp index 3d77b81..3694e5b 100644 --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -25,7 +25,13 @@ #include - +/** Reads the given number of bytes from the sourceDevice into the given buffer. + @param sourceDevice device or file to read from + @param buffer buffer to store the bytes read in + @param offset offset where to begin reading + @param size the number of bytes to read + @return true on success +*/ bool ExternalCommandHelper::readData(QString& sourceDevice, QByteArray& buffer, qint64 offset, qint64 size) { QFile device(sourceDevice); @@ -50,6 +56,12 @@ bool ExternalCommandHelper::readData(QString& sourceDevice, QByteArray& buffer, return true; } +/** Writes the data from buffer to a given device or file. + @param targetDevice device or file to write to + @param buffer the data that we write + @param offset offset where to begin writing + @return true on success +*/ bool ExternalCommandHelper::writeData(QString &targetDevice, QByteArray& buffer, qint64 offset) { QFile device(targetDevice);