detect CD insertion

Hi everyone,

Anybody know how to detect when a CD has been inserted? Or, even better, how to detect when a CD is in the process of being inserted (in a slot-load drive)? I assume the process is different whether it's a USB or IDE drive. I haven't decided which one I want to use yet. Maybe the ability to detect media insertion might sway me

You could look at the source code of an automounter, and see how it detects CD insertion, then write your own program to do what you need, or just monitor /dev/cdrom (maybe called something else if you're using udev) for when the automounter mounts it. I don't think IDE nor USB send tray-open/close or disc insertion signals.

i use ivman, and it works great. its currently hardmasked in gentoo's portage system, but the older versions work great. i haven't upgraded yet to the newer version that uses pmount since gentoo also has that hard masked. of course you can compile from source.

i highly recommend it. also, your assumption of it being different for usb/ide is gradually becoming incorrect. with udev, dbus, and hal, all hardware is being autodetected, auto fstabed, auto dev creation, etc. ivman even works with usb sticks, and pretty much any removable media that can be attached and detected by dbus/hal.

you can also use gnome-volume-manager for the same purpose supposedly. i have not used it, since i'm not using X at all. ivman is console/daemon based.

finally, ide/usb/firewire drives are all at the root the same i believe: ide drives with a usb/firewire bridge. and ide does have the tray open/close, tray lock, disc insertion detect, cd type detect etc. available to userspace via hal.

i use ivman, and it works great. its currently hardmasked in gentoo's portage system, but the older versions work great. i haven't upgraded yet to the newer version that uses pmount since gentoo also has that hard masked. of course you can compile from source.

Thanks! That looks really nice, I like that it can do different things based on the media type (CD audio vs CD data).

Originally Posted by ruzzmon

finally, ide/usb/firewire drives are all at the root the same i believe: ide drives with a usb/firewire bridge. and ide does have the tray open/close, tray lock, disc insertion detect, cd type detect etc. available to userspace via hal.

I installed HAL and ran it, then looked at all of the DBUS messages. I can see events happening when I plug in USB keychains. But when I insert a CD, (into my IDE drive) nothing happens. The CD drive is working, and I can mount the CD manually. Any ideas why HAL can't detect it?

Thanks! That looks really nice, I like that it can do different things based on the media type (CD audio vs CD data).

I installed HAL and ran it, then looked at all of the DBUS messages. I can see events happening when I plug in USB keychains. But when I insert a CD, (into my IDE drive) nothing happens. The CD drive is working, and I can mount the CD manually. Any ideas why HAL can't detect it?

hmm...i think thats a bit unusual. did you run lshal? if you have, make sure your cd drive is showing up. if it is, then insert a dvd (maybe a cd works too) and run lshal again, it should show a few keys change and the title of the dvd. at least thats how it works on mine.

but i guess you say that dbus isn't sending messages...maybe i'm wrong and not all drives are the same??? hal depends on dbus, so i could be way off.

I just tried a few things - first, running hald in --verbose=yes mode. I get a ton of printouts scrolling past whenever I plug in or unplug anything. But it's completely silent when I put in a CD, open up the Gnome CD player app, and play it.

Then I ran lshal. It detected 39 (!) devices. But it looks like it does have some information about my CD drive, but just lists it as "IDE device (master)" - doesn't mention anything about it being a CD drive.

Here's what I think is the relevant section from the lshal output. Do you get something significantly different?

This is what my cd drive looks like in hal, w/o a cd in it. I'll try to get you an output of what lshal looks like w/a DVD in it. keep in mind that i have a firewire bridge going to a pcmcia firewire card, so thats where the scsi and ieee1394 stuff comes from

one final thing i suggest trying is 'dbus-monitor --system'. i bet you did that already tho... anyhow, this program will show you every little msg being sent about whats going on in your computer hardware wise. so if you insert a cd, it should indicate something happened.

i hope i'm helping at least a little, it seems as though you know what you're doing, so i'm sure you'll get it working soon.

This is what my cd drive looks like in hal, w/o a cd in it. I'll try to get you an output of what lshal looks like w/a DVD in it. keep in mind that i have a firewire bridge going to a pcmcia firewire card, so thats where the scsi and ieee1394 stuff comes from

Hmm... on my desktop at work (FC3) that's the same stuff I see. It doesn't seem to detect the low-level tray open/close (immediate button press), but it DOES detect the new media a second or two after I insert the CD. So if I could just get my Gentoo machine to do the same, that would be great. I wonder why lshal doesn't even see my cd drive?

Oh well, this isn't even my car PC (I haven't bought that yet). It's just my development machine... and it's linux support is pretty shoddy. So.. maybe a world recompile might help (ughhh), or maybe I could try emerging an older version. If that doesn't work I'll just wait until I get my EPIA to mess with it.