Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Identify a mounted volume as a CD/DVD on osx

When you mount anything on osx it shows up under /Volumes/mountname

Is there any way, using the commandline or C/C++ to identify the volume as a CD/DVD rom?

My current best idea goes something like this.

df | grep mountname 

to get the /dev/diskNsM path

and then

drutil | grep /dev/diskN 

to see if the path mounted device is the burner.

This works, but i'm concerned about the case where the CD/DVD is not a burner. Will it still show up in the output of drutil? Do macs even come with a non-burner CD/DVD drive?

Also i would prefer using C,C++ or objective C to do this.

I already use

const char *tmp = '/Volumes/mysterydrive';
statfs(tmp, &m);
if(m.f_flags & MNT_RDONLY)
{
    read_only = true;
}

to determine if the volume is readonly, but i cannot see if this or any related call can distinguish between a CD/DVD and a readonly mounted volume.

It would only need to work for OSX 10.5 and newer.

Any ideas?

EDIT:

Using

  diskutil info /Volumes/mysterydrive

I got the following output if its a CD/DVD

  Optical Drive Type:       CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-R DL, DVD-RW, DVD+R, DVD+R DL, DVD+RW
  Optical Media Type:       DVD-R
  Optical Media Erasable:   No

And that's all i need!

I'll look into using IOKit to do it programmatically later, but this seems to be the quickest way to get it done.

like image 367
Kimmeh Avatar asked Feb 03 '12 13:02

Kimmeh


People also ask

How do I find CD-ROM on Mac?

On your Mac, choose Apple menu > System Preferences, then click CDs & DVDs . If you don't have an optical drive built into or connected to your Mac, CDs & DVDs preferences aren't available. Use the pop-up menus to choose an action for the type of inserted discs.

How do I identify a CD-ROM?

Microsoft Windows usersOpen System Information. In the System Information window, click the + symbol next to Components. If you see "CD-ROM," click it once to display the CD-ROM in the left window. Otherwise, click "+" next to "Multimedia" and then click "CD-ROM" to see the CD-ROM information in the left window.

Which Mac has a CD-ROM?

Released in June 2012, this 13-inch MacBook Pro model was the last Mac with a built-in CD/DVD drive sold by Apple.

How do you mount a DVD on a Mac?

1. Insert CDs and DVDs into the Mac's SuperDrive or Combo Drive. Press the "Media Eject" key or press and hold the "F12" key to open the drawer on Macs with tray-loading optical drives. Slot-loading drives require a moment of firm pressure to insert media for reading.


1 Answers

You get the most detailed information from

diskutil info /Volume/foo

In particular see Optical Drive and Optical Media entries which you only get for CD/DVDs so it is quite reliable.

Unfortunately the frameworks that diskutil uses to get all that information are private, so it will be hard to replicate it in C code.

I didn't dig deeper into other options, but since you can get the disk name from statfs it may be in theory possible to use IOKit to check out the device and you'll see IOCDMedia or IODVDMedia class if it is a CD/DVD drive (i.e. if you look for IO*Media class the BSD Name property has the disk name like disk6)

like image 71
Simon Urbanek Avatar answered Oct 13 '22 11:10

Simon Urbanek