mirror of
https://github.com/Rockbox/rockbox.git
synced 2026-07-10 13:29:52 -04:00
rbutilqt: Replace Utils::ejectDevice() on macOS with a diskutil process invocation
Co-authored-by: ChatGPT (GPT-5.3 Mini) <chatgpt@openai.com> Change-Id: Icedf758af6f1f0843c58e7ea5bb3efb2e7177b4a
This commit is contained in:
parent
1039eb305a
commit
379c056299
2 changed files with 14 additions and 41 deletions
|
|
@ -889,7 +889,7 @@ QList<int> Utils::suspendProcess(QList<int> pidlist, bool suspend)
|
||||||
* @param device mountpoint of the device
|
* @param device mountpoint of the device
|
||||||
* @return true on success, fals otherwise.
|
* @return true on success, fals otherwise.
|
||||||
*/
|
*/
|
||||||
bool Utils::ejectDevice(QString device)
|
bool Utils::ejectDevice(const QString &device)
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
/* See http://support.microsoft.com/kb/165721 on the procedure to eject a
|
/* See http://support.microsoft.com/kb/165721 on the procedure to eject a
|
||||||
|
|
@ -940,52 +940,25 @@ bool Utils::ejectDevice(QString device)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
// FIXME: FSUnmountVolumeSync is deprecated starting with 10.8.
|
|
||||||
// Use DADiskUnmount / DiskArbitration framework eventually.
|
// Use DADiskUnmount / DiskArbitration framework eventually.
|
||||||
// BSD label does not include folder.
|
QStorageInfo info(device);
|
||||||
QString bsd = Utils::resolveDevicename(device).remove("/dev/");
|
if (!info.isValid())
|
||||||
OSStatus result;
|
return false;
|
||||||
ItemCount index = 1;
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
do {
|
QString mountPoint = info.rootPath();
|
||||||
FSVolumeRefNum volrefnum;
|
|
||||||
|
|
||||||
result = FSGetVolumeInfo(kFSInvalidVolumeRefNum, index, &volrefnum,
|
QProcess proc;
|
||||||
kFSVolInfoFSInfo, NULL, NULL, NULL);
|
proc.start("/usr/sbin/diskutil", {"eject", mountPoint});
|
||||||
if(result == noErr) {
|
if (!proc.waitForFinished())
|
||||||
GetVolParmsInfoBuffer volparms;
|
return false;
|
||||||
/* See above -- PBHGetVolParmsSync() is not available for 64bit,
|
|
||||||
* and FSGetVolumeParms() on 10.5+ only. */
|
|
||||||
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
|
|
||||||
if(FSGetVolumeParms(volrefnum, &volparms, sizeof(volparms)) == noErr)
|
|
||||||
#else
|
|
||||||
HParamBlockRec hpb;
|
|
||||||
hpb.ioParam.ioNamePtr = NULL;
|
|
||||||
hpb.ioParam.ioVRefNum = volrefnum;
|
|
||||||
hpb.ioParam.ioBuffer = (Ptr)&volparms;
|
|
||||||
hpb.ioParam.ioReqCount = sizeof(volparms);
|
|
||||||
if(PBHGetVolParmsSync(&hpb) == noErr)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
if(volparms.vMServerAdr == 0) {
|
|
||||||
if(bsd == (char*)volparms.vMDeviceID) {
|
|
||||||
pid_t dissenter;
|
|
||||||
result = FSUnmountVolumeSync(volrefnum, 0, &dissenter);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
} while(result == noErr);
|
|
||||||
if(result == noErr && found)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
|
return proc.exitStatus() == QProcess::NormalExit &&
|
||||||
|
proc.exitCode() == 0;
|
||||||
#endif
|
#endif
|
||||||
#if defined(Q_OS_LINUX)
|
#if defined(Q_OS_LINUX)
|
||||||
(void)device;
|
(void)device;
|
||||||
|
// TODO: eject [<device>|<mountPoint>] or
|
||||||
|
// udisksctl unmount -b <device> && udisksctl power-off -b <device>
|
||||||
#endif
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public:
|
||||||
static QString resolveMountPoint(QString device);
|
static QString resolveMountPoint(QString device);
|
||||||
static QMap<QString, QList<int> > findRunningProcess(QStringList names);
|
static QMap<QString, QList<int> > findRunningProcess(QStringList names);
|
||||||
static QList<int> suspendProcess(QList<int> pidlist, bool suspend);
|
static QList<int> suspendProcess(QList<int> pidlist, bool suspend);
|
||||||
static bool ejectDevice(QString device);
|
static bool ejectDevice(const QString &device);
|
||||||
static qint64 recursiveFolderSize(QString path);
|
static qint64 recursiveFolderSize(QString path);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue