detecting open/close state of cd drive

Hi.

Is there some one who can tell me how to determine if the CD tray is
open or closed.
My current approach is to simply issue a devctl call, like
DCMD_CAM_CDROMSTART.
I have a feeling there must be a better way.

/Tomas Rosenkvist

Michel Benoit <michel.benoit@saabcom.se> wrote:

Hi.

Is there some one who can tell me how to determine if the CD tray is
open or closed.
My current approach is to simply issue a devctl call, like
DCMD_CAM_CDROMSTART.
I have a feeling there must be a better way.

Take a look at the DCMD_CAM_DEVINFO devctl.

Thank you, that was a cleaner way of doing it, but it is still not good
enough.
The flag field in cam_devinfo_t is always 0x35 or 0x37, DEV_NO_MEDIA goes
on or off.
I can still not see the difference between tray open and tray closed, with
no disc inserted. What I want to know is if the tray is open, not if a
disc is inserted.

Ok ,next issue. Once the tray is inserted I have no problems detecting an
audio cd (sopen("/fs/cd0/.info./audio",…)) but for some reason if the
tray was closed by hand, rather than closed by the eject command, I can
not detect a cd_rom record. I try to do that by calling:
open("/fs/cd0/.info./volume").
I can not even browse the cd from a shell after the tray was closed by
hand and I detect it with the devctl call above, or any other call I have
tried. (I use a timer to make the checking every second while the tray is
open)
What am I missing???

/Tomas Rosenkvist


Kevin Chiles wrote:

Michel Benoit <> michel.benoit@saabcom.se> > wrote:
Hi.

Is there some one who can tell me how to determine if the CD tray is
open or closed.
My current approach is to simply issue a devctl call, like
DCMD_CAM_CDROMSTART.
I have a feeling there must be a better way.

Take a look at the DCMD_CAM_DEVINFO devctl.

Tomas Rosenkvist <tomasr@sms.se> wrote:

Thank you, that was a cleaner way of doing it, but it is still not good
enough.
The flag field in cam_devinfo_t is always 0x35 or 0x37, DEV_NO_MEDIA goes
on or off.
I can still not see the difference between tray open and tray closed, with
no disc inserted. What I want to know is if the tray is open, not if a
disc is inserted.

There currently isn’t a was to get this information. We are in the process
of adding a CAM pass through interface to the drivers that will allow you
to get this info.

Ok ,next issue. Once the tray is inserted I have no problems detecting an
audio cd (sopen("/fs/cd0/.info./audio",…)) but for some reason if the
tray was closed by hand, rather than closed by the eject command, I can
not detect a cd_rom record. I try to do that by calling:
open("/fs/cd0/.info./volume").
I can not even browse the cd from a shell after the tray was closed by
hand and I detect it with the devctl call above, or any other call I have
tried. (I use a timer to make the checking every second while the tray is
open)
What am I missing???

What is the make/model of the CD-ROM?

Tomas Rosenkvist wrote:

Glad to see someone using the “.info.” entries :wink: Some minor points
about them, which you may or may not care about …

Ok ,next issue. Once the tray is inserted I have no problems detecting an
audio cd (sopen("/fs/cd0/.info./audio",…))

This may also be a multisession / enhanced audio CD too (in other words,
it has some non-data tracks but may also have data tracks too). But,
you
can definitely play audio from it (“echo play >/fs/cd0/.info./audio”).

I can not detect a cd_rom record. I try to do that by calling:
open("/fs/cd0/.info./volume").

A data CD does not always supply all the information fields in the
primary volume header. By default, entries that are blank/missing
are not shown in the “.info.” filesystem. So you may miss some CDs.
You can force their presence whenever a data CD (as opposed to
audio-only) is inserted by passing the option “cd info=+.info.” to
the filesystem (the leading ‘+’ means always show possible 0-length
entries, a leading ‘-’ means hide such unspecified header fields,
the rest is the name of the pseudo-directory).