2007-01-04

hotplug events for media changes?

Posted in Computers, PlanetDebian at 12:28 UTC (+0000) by sven

Hi.

I’m currently working on a system image which is (among other things) supposed to automatically mount CDs as they are inserted. The big problem with this is that I finally had to recognize the fact that with all those hotplug events issued, a media change in an existing device is recognized by the kernel (at least it seems so when looking at drivers/ide/ide-cd), but this is not passed to userland, i.e. the hotplug handler (/sbin/hotplug or whatever you wrote to /proc/sys/kernel/hotplug) doesn’t get an event for this. The only way to recognize a media change that I found is to poll the CD-drive(s) for their media status and handle any changes there appropriately.

Given that the kernel already seems to have a mechanism to recognize media changes, it would really be cool if it could issue hotplug events for them.

6 Comments »

  1. James said,

    January 4, 2007 at 15:50 UTC (+0000)

    I remember religiously uninstalling/deleting/nuking/going-in-with-a-scalpel-and-scraping-the-hard-disk-to-make-sure whatever utility used to do that “poll the CD evey second to check what’s in it, and log to syslog if it errors out because there’s nothing there.” Was it autofs, automount? Seems like I haven’t had to do that in a few years, but my Etch KDE still knows that a CD was inserted. So it is still polling the drive, and just leaving syslog alone? A step in the right direction!

  2. sven said,

    January 4, 2007 at 15:54 UTC (+0000)

    Yes, KDE knows about the media change through hald, which in turn seems to use hald-addon-cdrom (or a similar name), which polls the CD drive. I’m not sure though how the polling is done.

  3. Kevin Mark said,

    January 4, 2007 at 19:03 UTC (+0000)

    This brings to mind the adage: if a tree falls in the forest and no one hears it, does it make a sound?
    The kernel knows, but it wont make a ‘sound’, so hotplug can’t know.
    Is this a know bug? is it fixable?

  4. Glennie said,

    January 4, 2007 at 22:53 UTC (+0000)

    Use inotify to detect if a CD is inserted.
    Try inotifywait /sys/bloc/hdX/size. This works on SID and should be better than polling the drive…

  5. sven said,

    January 5, 2007 at 01:07 UTC (+0000)

    Kevin: That’s basically what I see as the problem: The kernel knows, but it won’t tell.
    Glennie: inotifywait sounds like a good plan. I will try that. And since hdX/size should change any time the kernel detects a media change, this might work…. I’ll see.

  6. textshell said,

    January 5, 2007 at 23:49 UTC (+0000)

    I think there is some ioctl based way to get that, i did play around with some time ago… It’s not polling, the call blocks until an event is delivered (or maybe a signal to the process or such stuff). I found it in some programm out there, never seen any kind of proper documentation…
    see http://people.redhat.com/davidz/cd_poll.c for sample code (it says poll in the comment, but it’s event based )

Leave a Comment