From owner-freebsd-bugs@FreeBSD.ORG Mon Jun 30 15:30:16 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0126C37B4AA for ; Mon, 30 Jun 2003 15:30:16 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id F158D43FF7 for ; Mon, 30 Jun 2003 15:30:14 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h5UMUEUp012126 for ; Mon, 30 Jun 2003 15:30:14 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h5UMUE7q012125; Mon, 30 Jun 2003 15:30:14 -0700 (PDT) Resent-Date: Mon, 30 Jun 2003 15:30:14 -0700 (PDT) Resent-Message-Id: <200306302230.h5UMUE7q012125@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Benjamin Lutz Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A6F3537B401 for ; Mon, 30 Jun 2003 15:29:22 -0700 (PDT) Received: from maxlor.mine.nu (c-213-160-32-54.customer.ggaweb.ch [213.160.32.54]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2134743FBD for ; Mon, 30 Jun 2003 15:29:22 -0700 (PDT) (envelope-from maxlor@maxlor.mine.nu) Received: by maxlor.mine.nu (Postfix, from userid 1000) id 187CB12D262; Tue, 1 Jul 2003 00:29:21 +0200 (CEST) Message-Id: <20030630222921.187CB12D262@maxlor.mine.nu> Date: Tue, 1 Jul 2003 00:29:21 +0200 (CEST) From: Benjamin Lutz To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: kern/53941: [PATCH] ATAPI CD drives don't open the tray if they're empty X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Benjamin Lutz List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jun 2003 22:30:16 -0000 >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@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: