Question

Given a path, in Mac OS X, is there a way to tell that it is a mounted CD or DVD, as opposed to a regular directory, a regular file, or mounted DMG or other mountable file type? Specifically I would like to know if it is a CD or DVD when a user supplies a path directly, or via the NSOpenPanel, or drags the CD onto the app. I need to take special action in these cases.

Was it helpful?

Solution

Check out Apple's VolumeToBSDNode example code. I believe it should have the code bits you need.

Description

Shows how to iterate across all mounted volumes and retrieve the BSD node name (/dev/disk*) for each volume. That information is used to determine if the volume is on a CD, DVD, or some other storage media.

As Kent points out, the PBHGetVolParmsSync call in this example is deprecated. Here's a diff to use the newer function:

-            HParamBlockRec pb;

-            // Use the volume reference number to retrieve the volume parameters. See the documentation
-            // on PBHGetVolParmsSync for other possible ways to specify a volume.
-            pb.ioParam.ioNamePtr = NULL;
-            pb.ioParam.ioVRefNum = actualVolume;
-            pb.ioParam.ioBuffer = (Ptr) &volumeParms;
-            pb.ioParam.ioReqCount = sizeof(volumeParms);
-            
-            // A version 4 GetVolParmsInfoBuffer contains the BSD node name in the vMDeviceID field.
-            // It is actually a char * value. This is mentioned in the header CoreServices/CarbonCore/Files.h.
-            result = PBHGetVolParmsSync(&pb);
+            // Use FSGetVolumeParms instead of the deprecated PBHGetVolParmsSync
+            result = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
+
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top