mirror of
https://github.com/cmclark00/retro-imager.git
synced 2025-05-18 16:05:21 +01:00
udisks2: add support for 'safely removing storage'
mountutils lacks implemention of ejecting storage on Linux. Add that to our own code (not to mountutils as it is hard to do DBus calls from there).
This commit is contained in:
parent
b93fe29617
commit
dc6ef75333
4 changed files with 32 additions and 1 deletions
|
@ -244,6 +244,28 @@ void UDisks2Api::unmountDrive(const QString &device)
|
|||
_unmountDrive(devpath);
|
||||
}
|
||||
|
||||
void UDisks2Api::ejectDrive(const QString &device)
|
||||
{
|
||||
QString devpath = _resolveDevice(device);
|
||||
if (devpath.isEmpty())
|
||||
return;
|
||||
|
||||
_unmountDrive(devpath);
|
||||
::sync();
|
||||
|
||||
QDBusInterface blockdevice("org.freedesktop.UDisks2", devpath,
|
||||
"org.freedesktop.UDisks2.Block", QDBusConnection::systemBus());
|
||||
QString drivepath = blockdevice.property("Drive").value<QDBusObjectPath>().path();
|
||||
if (!drivepath.isEmpty() && drivepath != "/")
|
||||
{
|
||||
QDBusInterface drive("org.freedesktop.UDisks2", drivepath,
|
||||
"org.freedesktop.UDisks2.Drive", QDBusConnection::systemBus());
|
||||
QVariantMap ejectOptions;
|
||||
qDebug() << "Ejecting drive: " << drive.property("Id").toString();
|
||||
drive.call("Eject", ejectOptions);
|
||||
}
|
||||
}
|
||||
|
||||
QByteArrayList UDisks2Api::mountPoints(const QString &partitionDevice)
|
||||
{
|
||||
QString devpath = _resolveDevice(partitionDevice);
|
||||
|
|
|
@ -17,6 +17,7 @@ class UDisks2Api : public QObject
|
|||
public:
|
||||
explicit UDisks2Api(QObject *parent = nullptr);
|
||||
int authOpen(const QString &device, const QString &mode = "rw");
|
||||
void ejectDrive(const QString &device);
|
||||
bool formatDrive(const QString &device, bool mountAfterwards = true);
|
||||
QString mountDevice(const QString &device);
|
||||
void unmountDrive(const QString &device);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue