From 23b0bf6b32b0e96c47a42f84558972aee2e54fcb Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Thu, 30 Mar 2023 16:26:26 +0200 Subject: [PATCH] Linux udisks2: force kernel to rescan MBR before ejection Otherwise it may still be doing it during ejection, resulting in read IO errors in dmesg, which are harmless by themselves but may confuse users. Also tell udisks2 not to analyze disk by setting 'HintAuto' property on BlockDevice object to 'false' --- src/linux/udisks2api.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/linux/udisks2api.cpp b/src/linux/udisks2api.cpp index 52c2ced..3752f4a 100644 --- a/src/linux/udisks2api.cpp +++ b/src/linux/udisks2api.cpp @@ -250,12 +250,24 @@ void UDisks2Api::ejectDrive(const QString &device) if (devpath.isEmpty()) return; - _unmountDrive(devpath); - ::sync(); - QDBusInterface blockdevice("org.freedesktop.UDisks2", devpath, "org.freedesktop.UDisks2.Block", QDBusConnection::systemBus()); + + bool hintAuto = blockdevice.property("HintAuto").toBool(); + if (hintAuto) + { + qDebug() << "Deactivating auto-mount for" << device; + blockdevice.setProperty("HintAuto", false); + } + + /* Force kernel to rescan partitions now. Otherwise it may still be doing it + while we are ejecting, resulting in read IO errors in dmesg */ + QVariantMap rescanOptions; + blockdevice.call("Rescan", rescanOptions); + + _unmountDrive(devpath); QString drivepath = blockdevice.property("Drive").value().path(); + if (!drivepath.isEmpty() && drivepath != "/") { QDBusInterface drive("org.freedesktop.UDisks2", drivepath,