From a412564b00e00bc031dcc6ce1edbab82f9d17975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 22 Apr 2016 13:30:19 +0100 Subject: [PATCH] Simplify NTFS writeUUID code. Rely on external ntfslabel command. --- src/fs/ntfs.cpp | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/fs/ntfs.cpp b/src/fs/ntfs.cpp index 80f512a..9ee775d 100644 --- a/src/fs/ntfs.cpp +++ b/src/fs/ntfs.cpp @@ -176,27 +176,9 @@ bool ntfs::resize(Report& report, const QString& deviceNode, qint64 length) cons bool ntfs::updateUUID(Report& report, const QString& deviceNode) const { Q_UNUSED(report); - QUuid uuid = QUuid::createUuid(); - char* s = reinterpret_cast(&uuid.data4[0]); + ExternalCommand cmd(QStringLiteral("ntfslabel"), { QStringLiteral("--new-serial"), deviceNode }); - 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 (!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; - } - - 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; + return cmd.run(-1) && cmd.exitCode() == 0; } bool ntfs::updateBootSector(Report& report, const QString& deviceNode) const