From b42342d0ace8d6292b2a9c524b91c9e5a2339adf Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Sat, 27 Nov 2021 19:22:55 +0100 Subject: [PATCH] Linux/udisks2/image customization: fix issue with mounting NVMe drives When using image customization with an NVMe drive under RPI OS on a CM4, the system will prompt non-root users for password when mounting the FAT file system. (Passwordless mounting does is available for removable storage, but the NVMe drive qualifies as internal storage instead). - The mount command we send to udisks2 over dbus2 may timeout before the user completed the password prompt. Raise timeout to counter this. - Print mount error details to console - On mount error report error mounting in GUI instead of "/config.txt does not exist" (which happened when mountDevice() returned empty string) --- downloadthread.cpp | 4 +++- linux/udisks2api.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/downloadthread.cpp b/downloadthread.cpp index 4917677..647339f 100644 --- a/downloadthread.cpp +++ b/downloadthread.cpp @@ -916,7 +916,9 @@ bool DownloadThread::_customizeImage() /* Not running as root, try to outsource mounting to udisks2 */ #ifndef QT_NO_DBUS UDisks2Api udisks2; - mountpoints.push_back(udisks2.mountDevice(fatpartition).toStdString()); + QString mp = udisks2.mountDevice(fatpartition); + if (!mp.isEmpty()) + mountpoints.push_back(mp.toStdString()); #endif } else diff --git a/linux/udisks2api.cpp b/linux/udisks2api.cpp index dc9d6e4..7b0360e 100644 --- a/linux/udisks2api.cpp +++ b/linux/udisks2api.cpp @@ -156,6 +156,8 @@ bool UDisks2Api::formatDrive(const QString &device, bool mountAfterwards) for (int attempt = 0; attempt < 10; attempt++) { qDebug() << "Mounting partition"; + // User may need to enter password in authentication dialog if non-removable storage, so set long timeout + filesystem.setTimeout(3600 * 1000); QDBusReply mp = filesystem.call("Mount", mountOptions); if (mp.isValid()) @@ -172,6 +174,10 @@ bool UDisks2Api::formatDrive(const QString &device, bool mountAfterwards) qDebug() << "Was already auto-mounted at:" << mps; return true; } + else + { + qDebug() << "Error mounting:" << mp.error().message(); + } } QThread::sleep(1); @@ -197,6 +203,8 @@ QString UDisks2Api::mountDevice(const QString &device) for (int attempt = 0; attempt < 10; attempt++) { qDebug() << "Mounting partition"; + // User may need to enter password in authentication dialog if non-removable storage, so set long timeout + filesystem.setTimeout(3600 * 1000); QDBusReply mp = filesystem.call("Mount", mountOptions); if (mp.isValid()) @@ -204,6 +212,20 @@ QString UDisks2Api::mountDevice(const QString &device) qDebug() << "Mounted file system at:" << mp; return mp; } + else + { + /* Check if already auto-mounted */ + auto mps = mountPoints(filesystem); + if (!mps.isEmpty()) + { + qDebug() << "Was already auto-mounted at:" << mps; + return mps.first(); + } + else + { + qDebug() << "Error mounting:" << mp.error().message(); + } + } QThread::sleep(1); }