AgentLiquid
AgentLiquid

Reputation: 3682

Detecting CDROM media removal/insertion in Linux

Is there a clean way to detect or receive events when a user inserts or removes a CD on a Linux platform?

Upvotes: 3

Views: 4721

Answers (3)

user666739
user666739

Reputation: 9

The best way I was able to find was Halevt. Halevt is apparently a higher level abstraction than using HAL directly. It uses an XML based configuration file that may or may not be to your liking. The configuration file properties documentation is somewhat lacking. A list of all the supported properties are listed here:

http://www.marcuscom.com/hal-spec/hal-spec.html

Also, the link to Halevt: http://www.nongnu.org/halevt/

Upvotes: 0

hlovdal
hlovdal

Reputation: 28180

Traditionally there has been HAL (Hardware Abstraction Layer) for this, but the web page says

HAL is in maintenance mode - no new features are added. All future development focuses on udisks, UPower and other parts of the stack. See Software/DeviceKit for more information.

and the DeviceKit page lists

udisks, a D-Bus interface for dealing with storage devices

So udisks should probably be what you are asking for.

Upvotes: 2

Keith
Keith

Reputation: 43024

Udev monitors hardware and forwards events to dbus. You just need some dbus listener. A quick check using the dbus-monitor tool shows this in my system:

dbus-monitor --system

signal sender=:1.15 -> dest=(null destination) serial=144 path=/org/freedesktop/UDisks; interface=org.freedesktop.UDisks; member=DeviceChanged
   object path "/org/freedesktop/UDisks/devices/sr0"

This is the DeviceChanged event from Udisks, and the device path is included.

So, in whatever programming language you want that supports dbus bindings you can listen for those (system bus) events.

Upvotes: 3

Related Questions