Support "eject" on OS X.

Change-Id: I103587f2fad2b8b31a1bc53afbd107bf55f62c93
This commit is contained in:
Dominik Riebeling 2012-09-16 21:07:46 +02:00
parent f902bbe07e
commit 1c975eefd3
2 changed files with 40 additions and 1 deletions

View file

@ -748,6 +748,45 @@ bool Utils::ejectDevice(QString device)
CloseHandle(hdl); CloseHandle(hdl);
return success; return success;
#endif
#if defined(Q_OS_MACX)
// 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;
do {
FSVolumeRefNum volrefnum;
result = FSGetVolumeInfo(kFSInvalidVolumeRefNum, index, &volrefnum,
kFSVolInfoFSInfo, NULL, NULL, NULL);
if(result == noErr) {
GetVolParmsInfoBuffer volparms;
HParamBlockRec hpb;
hpb.ioParam.ioNamePtr = NULL;
hpb.ioParam.ioVRefNum = volrefnum;
hpb.ioParam.ioBuffer = (Ptr)&volparms;
hpb.ioParam.ioReqCount = sizeof(volparms);
if(PBHGetVolParmsSync(&hpb) == noErr) {
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;
#endif #endif
return false; return false;
} }

View file

@ -111,7 +111,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
} }
#endif #endif
#if !defined(Q_OS_WIN32) #if !defined(Q_OS_WIN32) && !defined(Q_OS_MACX)
/* eject funtionality is only implemented on W32 right now. */ /* eject funtionality is only implemented on W32 right now. */
ui.buttonEject->setEnabled(false); ui.buttonEject->setEnabled(false);
#endif #endif