kern/53941: [PATCH] ATAPI CD drives don't open the tray if they're empty

Benjamin Lutz benlutz at datacomm.ch
Mon Jun 30 15:30:16 PDT 2003


>Number:         53941
>Category:       kern
>Synopsis:       [PATCH] ATAPI CD drives don't open the tray if they're empty
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 30 15:30:14 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Benjamin Lutz
>Release:        FreeBSD 5.1-RELEASE i386
>Organization:
>Environment:
System: FreeBSD merlin 5.1-RELEASE FreeBSD 5.1-RELEASE #6: Mon Jun 30 23:29:15 CEST 2003 root at merlin:/usr/src/sys/i386/compile/MERLIN i386

>Description:
cdcontrol -f /dev/acd0 eject does not work if the cd drive is empty. This is not a bug in cdcontrol, but in the kernel's atapi-cd code. If the drive is empty, it seems that acd_start_stop(cdp, 0) always returns EBUSY.

>How-To-Repeat:
Type "cdcontrol -f /dev/acd0 eject". The cd tray opens if a cd is in the drive, but doesn't if there isn't one.

>Fix:
----- DIFF START -----
--- atapi-cd.c.orig     Mon Jun 30 23:42:47 2003
+++ atapi-cd.c  Mon Jun 30 23:28:54 2003
@@ -1860,9 +1860,9 @@
 {
     int error;

-    if ((error = acd_start_stop(cdp, 0)) == EBUSY) {
-       if (!close)
-           return 0;
+    error = acd_start_stop(cdp, 0);
+
+    if (close && (error == EBUSY)) {
        if ((error = acd_start_stop(cdp, 3)))
            return error;
        acd_read_toc(cdp);
@@ -1870,10 +1870,6 @@
        cdp->flags |= F_LOCKED;
        return 0;
     }
-    if (error)
-       return error;
-    if (close)
-       return 0;
     acd_prevent_allow(cdp, 0);
     cdp->flags &= ~F_LOCKED;
     cdp->device->flags |= ATA_D_MEDIA_CHANGED;
---- DIFF END ----

I changed the code to ignore the error returned by acd_start_stop(cdp, 0) if we're trying to open the tray. Shouldn't matter much, since if the drive shouldn't be opened, it'll be locked.

I tested this by using a cd burner and trying to open the tray while burning a CD. As expected it did not interrupt the burning process. Now, there's one thing that still bothers me a tiny bit... Maybe someone with more background knowledge can check this. My code now executes the following if we're trying to open the drive:

acd_start_stop(cdp, 0);
acd_prevent_allow(cdp, 0);
cdp->flags &= ~F_LOCKED;
cdp->device->flags |= ATA_D_MEDIA_CHANGED;
return acd_start_stop(cdp, 2);

In other words, cdp->flags and cdp->device->flags always get changed. As I said, this doesn't seem to matter on my machine, but maybe I'm overlooking something.

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list