Support "eject" on OS X.
authorDominik Riebeling <Dominik.Riebeling@gmail.com>
Sun, 16 Sep 2012 19:07:46 +0000 (16 21:07 +0200)
committerDominik Riebeling <Dominik.Riebeling@gmail.com>
Sun, 16 Sep 2012 19:08:18 +0000 (16 21:08 +0200)
Change-Id: I103587f2fad2b8b31a1bc53afbd107bf55f62c93

rbutil/rbutilqt/base/utils.cpp
rbutil/rbutilqt/rbutilqt.cpp

index cffa4b1..eec03fe 100644 (file)
@@ -749,6 +749,45 @@ bool Utils::ejectDevice(QString device)
     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
     return false;
 }
 
index aa0c365..0cdd836 100644 (file)
@@ -111,7 +111,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
     }
 #endif
 
-#if !defined(Q_OS_WIN32)
+#if !defined(Q_OS_WIN32) && !defined(Q_OS_MACX)
     /* eject funtionality is only implemented on W32 right now. */
     ui.buttonEject->setEnabled(false);
 #endif