From e3477347e1b916f863e73e2c15fa49c9fd3a2e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 11 Mar 2016 00:31:30 +0000 Subject: [PATCH] Fix updating NTFS UUID. For some reason dd did not work properly, use QFile instead. --- src/fs/ntfs.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/fs/ntfs.cpp b/src/fs/ntfs.cpp index 7d8a1a1..8e0f96d 100644 --- a/src/fs/ntfs.cpp +++ b/src/fs/ntfs.cpp @@ -61,7 +61,7 @@ void ntfs::init() m_Create = findExternal(QStringLiteral("mkfs.ntfs")) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = findExternal(QStringLiteral("ntfsclone")) ? cmdSupportFileSystem : cmdSupportNone; m_Backup = cmdSupportCore; - m_UpdateUUID = findExternal(QStringLiteral("dd")) ? cmdSupportFileSystem : cmdSupportNone; + m_UpdateUUID = cmdSupportCore; m_Move = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; m_GetUUID = cmdSupportCore; } @@ -177,16 +177,26 @@ bool ntfs::resize(Report& report, const QString& deviceNode, qint64 length) cons bool ntfs::updateUUID(Report& report, const QString& deviceNode) const { QUuid uuid = QUuid::createUuid(); + char* s = reinterpret_cast(&uuid.data4[0]); - ExternalCommand cmd(report, QStringLiteral("dd"), QStringList() << QStringLiteral("of=") + deviceNode << QStringLiteral("bs=1") << QStringLiteral("count=8") << QStringLiteral("seek=72")); - - if (!cmd.start()) + QFile device(deviceNode); + if (!device.open(QFile::ReadWrite | QFile::Unbuffered)) { + Log() << xi18nc("@info/plain", "Could not open partition %1 for writing when trying to update the NTFS serial number.", deviceNode); return false; + } - if (cmd.write(reinterpret_cast(&uuid.data4[0]), 8) != 8) + if (!device.seek(0x48)) { + Log() << xi18nc("@info/plain", "Could not seek to position 0x48 on partition %1 when trying to update the NTFS serial number.", deviceNode); return false; + } - return cmd.waitFor(-1); + if (device.write(s, 8) != 8) { + Log() << xi18nc("@info/plain", "Could not write new NTFS serial number to partition %1.", deviceNode); + return false; + } + + Log() << xi18nc("@info/plain", "Updated NTFS serial number for partition %1 successfully.", deviceNode); + return true; } bool ntfs::updateBootSector(Report& report, const QString& deviceNode) const