Optical disc device names (examle: /dev/disk4) are a bit weird on Mac OS X. Unlike on other OSs, they belong to the mounted media, not the drive so only exist when a disc is inserted. Additionally they are in no term stable. They can change already when anoter .dmg file is mounted before the next disc is inserted into the drive. On Windows drive letters are stable and linux has device names like /dev/cdrom or /dev/sr0 which are quite stable. Changes in hard discs, usb drives and packages have no effect on optical device names there.
I develop a C library working with audio CDs and would like to use the drive numbering exposed by drutil from C.
drutil list
lists all drives connected to the machine (with or without disc and gives them numbers.
With drutil details -drive 1
I can then get the details for the first drive, including the (BSD) device name when a disc is in the drive.
This would be perfect to set a prefered drive in the configuration or similar.
In C I wasn't able to list or index the drives without discs. So when I get the first inserted disc I don't know which drive this disc belongs to.
I can get device names for inserted discs with the IOCDMediaClass
.
I do get a one drive listed with the IOCDBlockStorageDeviceClass
(with or without a disc inserted), but I can't access the device name even when a disc is in the drive.
I prepared some example code that tries to list members of both classes and the device name if available.
The output without a disc in the drive:
detected media:
detected CD block devices:
drive 1:
class name: IODVDServices
The output with a disc in the drive:
detected media:
drive 1:
device name: disk4
class name: IOCDMedia
detected CD block devices:
drive 1:
class name: IODVDServices
PS: I know I can call drutil from C, but that would be a last resort.