Tuesday 15 February 2011

c++ - How to check if CD drive is open or closed in linux? -


I am creating an application for which it is necessary to know that the CD drive is open or closed.

Remove opens the CD drive, and checks how long it will take to open it (a small amount of time says that it is open, and long, Well ...), but I can not use this technique because the application actually opens the drive (and I do not want to reopen the drive, if it is closed, then I want to turn off the drive if it Is open).

How do I do this on Linux? I saw it is possible to do this under Windows (although it might be wrong), but I have not seen a way to do it on Linux.

If it is not possible to use this Linux API call, is it possible to implement this low-level function that can do this?

For example code to work, you should do it like this:

  #include & lt; Sys / ioctl.h & gt; #include & lt; Linux / cdrom.h & gt; Int results = ioctl (fd, cdROM_DRIVE_STATUS, CDSL_NONE); Switch (results) {Cases CDS_NO_INFO: ... break; Cases CDS_NO_DISC: ... break; Case CDSTTROPOAPO ... ... break; Case CDsIDiv_ONRADY: ... break; Cases CDS_DISC_OK: ... break; Default: / * Error * /}   

i.e. The result is returned as the ioctl () function result, not in the slot argument.

No comments:

Post a Comment