LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-05-2009, 11:18 AM   #1
ohmygoth
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: 0
Question 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!!
 
Old 12-05-2009, 11:58 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 12-05-2009, 01:18 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
SDL library will tell you if the cd is inserted.
 
1 members found this post helpful.
Old 12-06-2009, 02:50 AM   #4
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
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.
 
1 members found this post helpful.
  


Reply

Tags
cd, detect, rom, usb



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Automount dvd ROM when dvd is inserted baddah Linux - Newbie 9 06-20-2006 01:05 PM
usb multi card reader doesnt detect newly inserted cards qwijibow Linux - Hardware 5 10-11-2005 10:17 PM
multi mem card reader doesnt detect newly inserted cards qwijibow Linux - Hardware 1 08-24-2005 03:51 PM
usb multi card reader doesnt detect newly inserted cards qwijibow Linux - Hardware 1 08-24-2005 03:50 PM
Auto Mount CD ROM while inserted anand_kt Linux - Software 2 01-12-2005 07:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration