| Author |
Reliable CD Ejection
|
|
| Bender 2007-12-07, 7:24 pm |
| Simple problem. I want to eject a CD from a drive. After plenty of
tooling around the only reliable way I could do this is to utilize the
raw device number (or block device number).
I'm using the Solaris SUNWcdrw package to burn disks so I decided to use
it to extract the raw device number using 'cdrw -l'. Ex: Parse out
"/dev/rdsk/c0d0t0s0" and do a /usr/bin/eject on that device.
The problem is 'cdrw -l' doesn't always give me the raw device number.
Sometimes it gives me the logical name 'cdrom0'. Fortunately I'm working
on a closed system so I could parse out the /etc/mnttab file to get the
block device for the /cdrom mount point but this would never work in a
real world situation.
Finally my question. How can I always reliably eject a CD from its drive?
Thanks.
| |
| fjblurt@yahoo.com 2007-12-08, 1:45 am |
| On Dec 7, 3:48 pm, Bender <jnbben...@gmail.com> wrote:
> Simple problem. I want to eject a CD from a drive. After plenty of
> tooling around the only reliable way I could do this is to utilize the
> raw device number (or block device number).
>
> I'm using the Solaris SUNWcdrw package to burn disks so I decided to use
> it to extract the raw device number using 'cdrw -l'. Ex: Parse out
> "/dev/rdsk/c0d0t0s0" and do a /usr/bin/eject on that device.
> The problem is 'cdrw -l' doesn't always give me the raw device number.
> Sometimes it gives me the logical name 'cdrom0'. Fortunately I'm working
> on a closed system so I could parse out the /etc/mnttab file to get the
> block device for the /cdrom mount point but this would never work in a
> real world situation.
>
> Finally my question. How can I always reliably eject a CD from its drive?
If there is more than one CD drive on the system, how will you know
which one to eject?
| |
| Bender 2007-12-08, 1:45 am |
| fjblurt@yahoo.com wrote:
> On Dec 7, 3:48 pm, Bender <jnbben...@gmail.com> wrote:
>
> If there is more than one CD drive on the system, how will you know
> which one to eject?
That situation I can guarantee against or at least give the user an
option. After poking around it looks like some ioctl calls with
CDROMEJECT should do the trick but still...
How do I discover the CD device names?
| |
| Bill Marcum 2007-12-08, 7:43 pm |
| On 2007-12-07, Bender <jnbbender@gmail.com> wrote:
>
>
> Simple problem. I want to eject a CD from a drive. After plenty of
> tooling around the only reliable way I could do this is to utilize the
> raw device number (or block device number).
>
> I'm using the Solaris SUNWcdrw package to burn disks so I decided to use
> it to extract the raw device number using 'cdrw -l'. Ex: Parse out
> "/dev/rdsk/c0d0t0s0" and do a /usr/bin/eject on that device.
> The problem is 'cdrw -l' doesn't always give me the raw device number.
> Sometimes it gives me the logical name 'cdrom0'. Fortunately I'm working
> on a closed system so I could parse out the /etc/mnttab file to get the
> block device for the /cdrom mount point but this would never work in a
> real world situation.
>
Wait a minute. If 'cdrw -l' returns a mount point, shouldn't you
umount the cdrom before ejecting it?
ls -ld . $(cdrw -l) | awk '/^b/{print $9}'
should list only block device names.
| |
| Bender 2007-12-08, 7:43 pm |
| Bill Marcum wrote:
> On 2007-12-07, Bender <jnbbender@gmail.com> wrote:
> Wait a minute. If 'cdrw -l' returns a mount point, shouldn't you
> umount the cdrom before ejecting it?
>
> ls -ld . $(cdrw -l) | awk '/^b/{print $9}'
> should list only block device names.
'cdrw -l' returns the raw device name or the logical device
name(cdrom0). The nice thing about this is you can eject an unmounted
CD, one that is blank. I would like to get the device name because then
I would be able to handle the non-mounted case.
In the case where I wanted to eject a CD only if it were mounted I would
parse out the /etc/mnttab using getmntent and grab the device name that way.
|
|
|
|