From cde6d1eaa06b41167228066828636ef2c60cf376 Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Mon, 22 Nov 2021 13:26:34 +0100 Subject: [PATCH] udisks2: FAT32 format auto-mount fix - after writing new partition table, make sure auto-mount has not mounted any old FAT filesystems that were previously on disks at the same offset. - error out on format errors. (timeout was raised to prevent false positives on formatting time'ing out) --- linux/udisks2api.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/linux/udisks2api.cpp b/linux/udisks2api.cpp index fc4b289..dc9d6e4 100644 --- a/linux/udisks2api.cpp +++ b/linux/udisks2api.cpp @@ -130,18 +130,21 @@ bool UDisks2Api::formatDrive(const QString &device, bool mountAfterwards) } qDebug() << "New partition:" << newpartition.value().path(); QThread::sleep(1); + if (!drive.isEmpty() && drive != "/") + { + /* Unmount one more time, as auto-mount may have tried to mount an old FAT filesystem again if it + * lives at the same sector in the new partition table as before */ + _unmountDrive(drive); + } qDebug() << "Formatting drive as FAT32"; QDBusInterface newblockdevice("org.freedesktop.UDisks2", newpartition.value().path(), "org.freedesktop.UDisks2.Block", QDBusConnection::systemBus()); - newblockdevice.setTimeout(120 * 1000); + newblockdevice.setTimeout(300 * 1000); QDBusReply fatformatreply = newblockdevice.call("Format", "vfat", formatOptions); if (!fatformatreply.isValid()) { - qDebug() << "Error from udisks2 while performing FAT32 format:" << fatformatreply.error().message() - << "(going to try to mount anyway, as errors are sometimes false positive)"; - /* udisks2 sometimes report - "Error synchronizing after formatting with type `vfat': Timed out waiting for object" - when there is nothing actually wrong with the format */ + qDebug() << "Error from udisks2 while performing FAT32 format:" << fatformatreply.error().message(); + return false; } if (mountAfterwards)