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.
+4
A:
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));
+
nall
2009-11-08 23:10:12
the VolumeToBSDNode example is out of date and will not compile with modern SDK's (10.5 or 10.6). it relies on PBHGetVolParmsSync() which is an ancient legacy function. does anybody know of a modern way to achieve the same results? (mapping from/to bsd device name to logical volume name)
kent
2009-11-09 17:31:57
good point. updated with a diff.
nall
2009-11-09 19:31:25
thanks alot for updating this, nall! great work! +1
kent
2009-11-10 13:23:02
A:
Where is the updated code? Could you please post it or give reference?
joearul
2010-08-17 21:24:01