LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Help: Detect if CD-ROM is inserted (https://www.linuxquestions.org/questions/programming-9/help-detect-if-cd-rom-is-inserted-773670/)

ohmygoth 12-05-2009 11:18 AM

Help: Detect if CD-ROM is inserted
 
Hi, I'm working on C++ under Linux, I've got to make a program that detects if a CD-ROM or USB is inserted/connected and show the content.

I've read a lot, and I understand that for USB I can use some libraries like usb-linux.c, but for the CD-ROM I can't find a thing, only for Windows programming on DOS, the problem is that I don't know how to search :S

Any idea? Is there any library for CD-ROM detect too?

Thnx a lot!!

paulsm4 12-05-2009 11:58 AM

No "library" per se. Your best bet is to:

a) Look at what filesystems are "mounted"
b) parse if one (or more of these) is your CD

"man popen" and "man mount" can give you more info.

smeezekitty 12-05-2009 01:18 PM

SDL library will tell you if the cd is inserted.

gnashley 12-06-2009 02:50 AM

There are several programs out there which do this. But, there is no straightforward way to do it. I mean you can find out if there is a disk inserted -if it has a recognizable file system on it. And you can detect whether the door is opened or closed, but you have to check it and keep the'state' of it to know what is happening. When the door is opened and then closed, you have no way of telling if someone just took a CD out, or just inserted one. So, you have to check when your program first runs if there is a disk in there. If not, you still don't know if the door is open or closed. Your program has to keep checking and remember what the last state was in order to 'deduce' what is happening.


All times are GMT -5. The time now is 06:55 PM.