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)
This commit is contained in:
Floris Bos 2021-11-22 13:26:34 +01:00
parent 71c1ea21dd
commit cde6d1eaa0

View file

@ -130,18 +130,21 @@ bool UDisks2Api::formatDrive(const QString &device, bool mountAfterwards)
} }
qDebug() << "New partition:" << newpartition.value().path(); qDebug() << "New partition:" << newpartition.value().path();
QThread::sleep(1); 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"; qDebug() << "Formatting drive as FAT32";
QDBusInterface newblockdevice("org.freedesktop.UDisks2", newpartition.value().path(), QDBusInterface newblockdevice("org.freedesktop.UDisks2", newpartition.value().path(),
"org.freedesktop.UDisks2.Block", QDBusConnection::systemBus()); "org.freedesktop.UDisks2.Block", QDBusConnection::systemBus());
newblockdevice.setTimeout(120 * 1000); newblockdevice.setTimeout(300 * 1000);
QDBusReply<void> fatformatreply = newblockdevice.call("Format", "vfat", formatOptions); QDBusReply<void> fatformatreply = newblockdevice.call("Format", "vfat", formatOptions);
if (!fatformatreply.isValid()) if (!fatformatreply.isValid())
{ {
qDebug() << "Error from udisks2 while performing FAT32 format:" << fatformatreply.error().message() qDebug() << "Error from udisks2 while performing FAT32 format:" << fatformatreply.error().message();
<< "(going to try to mount anyway, as errors are sometimes false positive)"; return false;
/* udisks2 sometimes report
"Error synchronizing after formatting with type `vfat': Timed out waiting for object"
when there is nothing actually wrong with the format */
} }
if (mountAfterwards) if (mountAfterwards)