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
|
||||
* @return true on success, fals otherwise.
|
||||
*/
|
||||
bool Utils::ejectDevice(QString device)
|
||||
bool Utils::ejectDevice(const QString &device)
|
||||
{
|
||||
#if defined(Q_OS_WIN32)
|
||||
/* See http://support.microsoft.com/kb/165721 on the procedure to eject a
|
||||
|
|
@ -940,52 +940,25 @@ bool Utils::ejectDevice(QString device)
|
|||
|
||||
#endif
|
||||
#if defined(Q_OS_MACOS)
|
||||
// FIXME: FSUnmountVolumeSync is deprecated starting with 10.8.
|
||||
// Use DADiskUnmount / DiskArbitration framework eventually.
|
||||
// BSD label does not include folder.
|
||||
QString bsd = Utils::resolveDevicename(device).remove("/dev/");
|
||||
OSStatus result;
|
||||
ItemCount index = 1;
|
||||
bool found = false;
|
||||
QStorageInfo info(device);
|
||||
if (!info.isValid())
|
||||
return false;
|
||||
|
||||
do {
|
||||
FSVolumeRefNum volrefnum;
|
||||
QString mountPoint = info.rootPath();
|
||||
|
||||
result = FSGetVolumeInfo(kFSInvalidVolumeRefNum, index, &volrefnum,
|
||||
kFSVolInfoFSInfo, NULL, NULL, NULL);
|
||||
if(result == noErr) {
|
||||
GetVolParmsInfoBuffer volparms;
|
||||
/* 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;
|
||||
QProcess proc;
|
||||
proc.start("/usr/sbin/diskutil", {"eject", mountPoint});
|
||||
if (!proc.waitForFinished())
|
||||
return false;
|
||||
|
||||
return proc.exitStatus() == QProcess::NormalExit &&
|
||||
proc.exitCode() == 0;
|
||||
#endif
|
||||
#if defined(Q_OS_LINUX)
|
||||
(void)device;
|
||||
// TODO: eject [<device>|<mountPoint>] or
|
||||
// udisksctl unmount -b <device> && udisksctl power-off -b <device>
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public:
|
|||
static QString resolveMountPoint(QString device);
|
||||
static QMap<QString, QList<int> > findRunningProcess(QStringList names);
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue