On Fri, Feb 29, 2008 at 8:01 PM, James G. Sack (jim) <[EMAIL PROTECTED]> wrote:
> Carl Lowenstein wrote:
>  > When I put a blank CD-R in the drive, after several seconds an icon
>  > labeled "Blank CD-R Disc" appears on the desktop.  Is there some
>  > command-line way to recognize this?
>  >
>  > I am trying to make my CD-burning shell script more foolproof.  If I
>  > start the script too soon, the call to /usr/bin/cdrecord bombs out
>  > with a message about "non-writeable disc".  I think this really means
>  > that the system hasn't gotten around to noticing the presence of the
>  > blank.  If I wait until the icon is visible, then there is no problem.
>  >
>
>  I have absolutely no reason to believe this is the right thing to do,
>  but a couple of 'messin-around' experiments shows that
>
>   dd if=/dev/cdrom bs=512 count=1 of=/dev/null
>   mount /dev/cdrom /mnt
>  both contain "No medium found" if the drive is empty (no disc present)
>   file -s /dev/sr0
>  reports /dev/sr0: writable, no read permission
>
>  With a blank writable disc,
>   dd reports Input/Output error
>   mount reports a different error
>   /dev/sr0: reports empty
>
>  All of them first close the tray if it is open.

OK, you seem to have found something useful.  You must have one of
those new-fangled kernels that maps the CD drive to /dev/sr0.  My CD
drive is /dev/hdc, symlinked to /dev/cdrom.

# blank CD in drive, either open or shut
[EMAIL PROTECTED] tmp]$ file -sL /dev/cdrom; echo $?
/dev/cdrom: ERROR: cannot read `/dev/cdrom' (Input/output error)
0
# if drive is open, closes it.  Does not return until after disc icon
is on screen.

# nothing in drive, either open or shut
[EMAIL PROTECTED] tmp]$ file -sL /dev/cdrom; echo $?
/dev/cdrom: writable, no read permission
0
# if drive is open, closes it.  Returns immediately, at least to the
human observer.

Note that exit status of file command is 0 regardless, so that isn't much help.
But all is not lost:

[EMAIL PROTECTED] tmp]$ file -sL /dev/cdrom | grep -q "cannot read"; echo $?
1
[EMAIL PROTECTED] tmp]$ file -sL /dev/cdrom | grep -q "cannot read"; echo $?
0

I observe by the behavior of grep(1) that file(1) seems to write to
stdout.  Interesting that file(1) should report "writable, no read
permission" for an empty drive, and "cannot read" for a blank disc.

Thanks for the ideas, I had run dry.  No guarantee that this will work
for newer kernels etc.  Will try newer distro's tomorrow some time.

Late-breaking news.  Newer system, with blank CD in drive.  file(1)
reports "ERROR:  cannot read ... "
If run again, it reports "empty".  So best to grep for "writable, no
read permission", I suppose.

    carl
-- 
    carl lowenstein         marine physical lab     u.c. san diego
                                                 [EMAIL PROTECTED]


-- 
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list

Reply via email to