[system/kpmcore] src/fs: Rewrite NTFS updateBootSector code.
Andrius Štikonas <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit e6e78265f9dd138c5ede473bf49f9b3164a93b5d by Andrius Štikonas.
Committed on 01/08/2026 at 11:06.
Pushed by stikonas into branch 'master'.
Rewrite NTFS updateBootSector code.
Old code was not safe for partition that starts beyond 2 TiB.
Also switch to QDataStream::LittleEndian rather than hand-fixing endianess.
BUG: 523706
M +7 -10 src/fs/ntfs.cpp
https://invent.kde.org/system/kpmcore/-/commit/e6e78265f9dd138c5ede473bf49f9b3164a93b5d
diff --git a/src/fs/ntfs.cpp b/src/fs/ntfs.cpp
index e2a29a69..a1ab38ec 100644
--- a/src/fs/ntfs.cpp
+++ b/src/fs/ntfs.cpp
@@ -17,10 +17,10 @@
#include <KLocalizedString>
+#include <QFile>
#include <QRegularExpression>
#include <QString>
#include <QStringList>
-#include <QFile>
#include <algorithm>
#include <ctime>
@@ -181,16 +181,13 @@ bool ntfs::updateBootSector(Report& report, const QString& deviceNode) const
{
report.line() << xi18nc("@info:progress", "Updating boot sector for NTFS file system on partition <filename>%1</filename>.", deviceNode);
- qint64 n = firstSector();
- char* s = reinterpret_cast<char*>(&n);
-
-#if Q_BYTE_ORDER == Q_BIG_ENDIAN
- std::swap(s[0], s[3]);
- std::swap(s[1], s[2]);
-#endif
+ QByteArray data;
+ QDataStream stream(&data, QIODevice::WriteOnly);
+ stream.setByteOrder(QDataStream::LittleEndian);
+ stream << static_cast<quint32>(firstSector());
ExternalCommand cmd;
- if (!cmd.writeData(report, QByteArray(s, sizeof(s)), deviceNode, 28)) {
+ if (!cmd.writeData(report, data, deviceNode, 28)) {
Log() << xi18nc("@info:progress", "Could not write new start sector to partition <filename>%1</filename> when trying to update the NTFS boot sector.", deviceNode);
return false;
}
@@ -198,7 +195,7 @@ bool ntfs::updateBootSector(Report& report, const QString& deviceNode) const
// Also update backup NTFS boot sector located at the end of the partition
// NOTE: this should fail if filesystem does not span the whole partition
qint64 pos = (lastSector() - firstSector()) * sectorSize() + 28;
- if (!cmd.writeData(report, QByteArray(s, sizeof(s)), deviceNode, pos)) {
+ if (!cmd.writeData(report, data, deviceNode, pos)) {
Log() << xi18nc("@info:progress", "Could not write new start sector to partition <filename>%1</filename> when trying to update the NTFS boot sector.", deviceNode);
return false;
}