Define the installed volume as a CD / DVD on osx

When you mount something in osx, it appears under / Volumes / mountname

Is there a way using the command line or C / C ++ to identify the volume as a CD / DVD?

My best idea is something like this.

df | grep mountname 

to get the path / dev / diskNsM

and then

 drutil | grep /dev/diskN 

to ensure that the device installed in the path is a burner.

This works, but I am concerned about the case when the CD / DVD is not a burner. Will it be displayed on drutil output? Does the Mac even have a non-burning CD?

Also, I would prefer to use C, C ++, or the C target for 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 read-only, but I don’t see if this or any related call can distinguish between a CD / DVD and a volume that has just been installed on a tone.

It will only need to work for OSX 10.5 and later.

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 all I need!

I will learn about using IOKit to do this programmatically later, but this is apparently the fastest way to do this.

+6
source share
2 answers

You will receive the most detailed information from

 diskutil info /Volume/foo 

In particular, see the records of the optical drive and optical media that you get only for CD / DVD, so it is quite reliable.

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

I did not go deep into other parameters, but since you can get the drive name from statfs , it is theoretically possible to use IOKit to check the device and you will see IOCDMedia or IODVDMedia if it is a CD / DVD drive (i.e. if you are looking for the IO*Media class IO*Media , the BSD Name property has a disk name, e.g. disk6 )

+2
source

Apple Developer Central has an example CDROMSample project code that shows IOKit routines to access CD-ROM properties. It will also give you the opportunity to get started with DVDs.

+2
source

Source: https://habr.com/ru/post/907569/


All Articles