Announcement

Collapse
No announcement yet.

detect CD insertion

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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.

    Comment


    • #3
      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've set it up to:
      1. detect audio cd, auto play via mplayer by mounting a cdfs partition and simultaneously copy and compress into ogg.
      2. detect dvd, auto play via mplayer
      3. detect data cd, auto mount under media

      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.

      Comment


      • #4
        second on ivman

        Comment


        • #5
          Hey, new people. Welcome

          I know that debian does an automount to /dev/cdrom but i always seem to break this and have never looked into how it works. Maybe someone here knows?
          -pkg

          Check out my tC: http://publicjestering.com/tc
          Check out my site: http://publicjestering.com

          Comment


          • #6
            Originally posted by ruzzmon
            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?

            Comment


            • #7
              Originally posted by gentoocar
              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.

              also, i'm not really new, i just haven't really posted

              Comment


              • #8
                Hi ruzzmon,

                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?

                Code:
                udi = '/org/freedesktop/Hal/devices/ide_1_0'
                  info.udi = '/org/freedesktop/Hal/devices/ide_1_0'  (string)
                  info.product = 'IDE device (master)'  (string)
                  ide.channel = 0  (0x0)  (int)
                  ide.host = 1  (0x1)  (int)
                  info.parent = '/org/freedesktop/Hal/devices/ide_host_1'  (string)
                  ide.linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:1f.1/ide1/1.0'  (string)
                  linux.sysfs_path_device = '/sys/devices/pci0000:00/0000:00:1f.1/ide1/1.0'  (string)
                  linux.sysfs_path = '/sys/devices/pci0000:00/0000:00:1f.1/ide1/1.0'  (string)
                  info.bus = 'ide'  (string)

                Comment


                • #9
                  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

                  Code:
                  udi = '/org/freedesktop/Hal/devices/block_11_0'
                    storage.policy.desired_mount_point = 'cdrom'  (string)
                    storage.policy.mount_filesystem = 'auto'  (string)
                    storage.policy.should_mount = true  (bool)
                    info.udi = '/org/freedesktop/Hal/devices/block_11_0'  (string)
                    storage.requires_eject = true  (bool)
                    storage.hotpluggable = true  (bool)
                    storage.cdrom.write_speed = 0  (0x0)  (int)
                    storage.cdrom.read_speed = 4224  (0x1080)  (int)
                    storage.cdrom.support_media_changed = true  (bool)
                    storage.cdrom.dvdplusrw = false  (bool)
                    storage.cdrom.dvdplusr = false  (bool)
                    storage.cdrom.dvdram = false  (bool)
                    storage.cdrom.dvdrw = false  (bool)
                    storage.cdrom.dvdr = false  (bool)
                    storage.cdrom.dvd = true  (bool)
                    storage.cdrom.cdrw = false  (bool)
                    storage.cdrom.cdr = false  (bool)
                    storage.removable = true  (bool)
                    info.product = 'DVD-ROM SR-8184'  (string)
                    info.vendor = 'MAT****A'  (string)
                    storage.drive_type = 'cdrom'  (string)
                    block.storage_device = '/org/freedesktop/Hal/devices/block_11_0'  (string)
                    storage.physical_device = '/org/freedesktop/Hal/devices/ieee1394_0'  (string)
                    storage.vendor = 'MAT****A'  (string)
                    storage.model = 'DVD-ROM SR-8184'  (string)
                    storage.automount_enabled_hint = true  (bool)
                    storage.no_partitions_hint = true  (bool)
                    storage.media_check_enabled = true  (bool)
                    storage.bus = 'ieee1394'  (string)
                    block.minor = 0  (0x0)  (int)
                    block.major = 11  (0xb)  (int)
                    info.capabilities = 'block storage.cdrom storage'  (string)
                    info.category = 'storage'  (string)
                    info.parent = '/org/freedesktop/Hal/devices/scsi_0_0_0_0'  (string)
                    block.device = '/dev/sr0'  (string)
                    block.is_volume = false  (bool)
                    block.have_scanned = false  (bool)
                    block.no_partitions = true  (bool)
                    linux.sysfs_path_device = '/sys/block/sr0'  (string)
                    linux.sysfs_path = '/sys/block/sr0'  (string)
                    info.bus = 'block'  (string)
                  based on what you're saying, it seems as tho hal is not seeing your cd drive at all. i have what you showed in your post as well, but that is just the ide interface.

                  the key you want to look for is: storage.policy.desired_mount_point = 'cdrom' . it doesn't make sense why hal can't find it. what version are you using? i'm guessing you emerged the latest.

                  here's what i'm using, in case there's some difference (but like i said, this has been working for awhile for me):
                  Code:
                  [ebuild   R   ] sys-apps/hal-0.4.8  -debug -doc -livecd +pcmcia 0 kB
                  [ebuild   R   ] sys-apps/dbus-0.23.4-r1  -X -debug -gtk -mono +python -qt +xml2 0 kB
                  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.

                  Comment


                  • #10
                    Originally posted by ruzzmon
                    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.

                    Comment


                    • #11
                      I don't know, but I'd like to mention sysfs vs udev. I found alot of things would not work with sysfs, which is part of the reason why I switched to udev. Other times, I might have some software configured for sysfs but it wouldn't work because I just switched to udev.

                      Worth checking out I suppose. If I'm off-the-wall then just ignore me.

                      Comment


                      • #12
                        ever tried AUTOFS?

                        http://gentoo-wiki.com/HOWTO_Auto_mo...ystems_(AUTOFS)

                        I just enter the /mnt/cdrom directory and linux mounts the cdrom for me then I just hit the eject button on the cdrom and it unmounts it and ejects the cd

                        Comment


                        • #13
                          Originally posted by TheLlama
                          I don't know, but I'd like to mention sysfs vs udev. I found alot of things would not work with sysfs, which is part of the reason why I switched to udev. Other times, I might have some software configured for sysfs but it wouldn't work because I just switched to udev.

                          Worth checking out I suppose. If I'm off-the-wall then just ignore me.
                          I can pretty much echo that. udev is married to the SuSE distro but I'm a Gentoo-lover right now so my sentiments may change in the future Anyhoo I'm beginning to ramble...
                          Silverwolf 2 is dead.
                          Silverwolf 3...?

                          Comment

                          Working...
                          X