From owner-freebsd-bugs Wed Sep 11 9:10:15 2002 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 4848137B400 for ; Wed, 11 Sep 2002 09:10:03 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8B6D043E4A for ; Wed, 11 Sep 2002 09:10:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g8BGA2JU063313 for ; Wed, 11 Sep 2002 09:10:02 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g8BGA2c1063312; Wed, 11 Sep 2002 09:10:02 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DDC5037B400 for ; Wed, 11 Sep 2002 09:02:25 -0700 (PDT) Received: from email.seznam.cz (smtp.seznam.cz [212.80.76.43]) by mx1.FreeBSD.org (Postfix) with SMTP id 6FC4543E4A for ; Wed, 11 Sep 2002 09:02:24 -0700 (PDT) (envelope-from neologism@seznam.cz) Received: (qmail 92818 invoked from network); 11 Sep 2002 16:02:11 -0000 Received: from ppp846.brno.worldonline.cz (HELO variola) (212.90.230.69) by smtp.seznam.cz with SMTP; 11 Sep 2002 16:02:11 -0000 Received: from roman by variola with local (Exim 3.13 #1 (Debian)) id 17p6YV-00008Z-00 for ; Wed, 11 Sep 2002 14:25:15 +0200 Message-Id: <20020911142514.A516@variola> Date: Wed, 11 Sep 2002 14:25:14 +0200 From: neologism Reply-To: neologism@seznam.cz To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: kern/42659: atapi cd-rom mounting patch Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 42659 >Category: kern >Synopsis: atapi cd-rom mounting patch >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Wed Sep 11 09:10:01 PDT 2002 >Closed-Date: >Last-Modified: >Originator: neologism >Release: FreeBSD 4.6-RELEASE i386 >Organization: none >Environment: System: FreeBSD variola 4.6-RELEASE FreeBSD 4.6-RELEASE #10: Sat Sep 7 12:15:31 GMT 2002 root@variola:/mnt/linux/bsd/compile/MYKERNEL i386 >Description: Attempt to mount cd-rom in atapi cd-rom drive when cd is still loading leads to an error message. open function of atapi cdrom-drives (acdopen) should wait till medium is fully loaded. As linux and fbsd scsi does. This patch implements this behaviour. >How-To-Repeat: this is a default behaviour for atapi cdrom drives >Fix: diff -urN /sys/dev/ata/atapi-cd.c ./atapi-cd.c --- /sys/dev/ata/atapi-cd.c Wed Mar 27 19:48:37 2002 +++ ./atapi-cd.c Sat Sep 7 12:14:54 2002 @@ -86,6 +86,7 @@ static int acd_init_track(struct acd_softc *, struct cdr_track *); static int acd_flush(struct acd_softc *); static int acd_read_track_info(struct acd_softc *, int32_t, struct acd_track_info *); +static int acd_get_status(struct acd_softc *); static int acd_get_progress(struct acd_softc *, int *); static int acd_send_cue(struct acd_softc *, struct cdr_cuesheet *); static int acd_report_key(struct acd_softc *, struct dvd_authinfo *); @@ -483,6 +484,9 @@ acdopen(dev_t dev, int flags, int fmt, struct proc *p) { struct acd_softc *cdp = dev->si_drv1; + int error; + int stat; + int timeout = 20*2; if (!cdp) return ENXIO; @@ -491,6 +495,22 @@ if (count_dev(dev) > 1) return EBUSY; } + + if (!cdp->changer_info) { + stat = acd_get_status(cdp); + if (stat == CD_OPEN && cdp->cap.eject) { + error = acd_eject(cdp, 1); + if (error) + return EIO; + } + + while (timeout-- > 0) { + stat = acd_get_status(cdp); + if (stat == CD_LOADING) + tsleep (&stat, PRIBIO, "acdld", hz/2); + } + } + if (count_dev(dev) == 1) { if (cdp->changer_info && cdp->slot != cdp->changer_info->current_slot) { acd_select_slot(cdp); @@ -1550,6 +1570,30 @@ info->fixed_packet_size = ntohl(info->fixed_packet_size); info->track_length = ntohl(info->track_length); return 0; +} + +static int +acd_get_status(struct acd_softc *cdp) +{ + struct atapi_reqsense *sense = cdp->device->result; + int stat; + + stat=atapi_test_ready(cdp->device); + + if (stat == 0 || sense->sense_key == 6) + return CD_OK; + if (sense->sense_key == 2 && sense->asc == 4 && sense->ascq == 1) + return CD_LOADING; + + /* Mt Fuji*/ + if (sense->sense_key == 2) { + if (sense->asc == 0x3a && sense->ascq == 1) + return CD_NODISC; + else + return CD_OPEN; + } + + return CD_NOTREADY; } static int diff -urN /sys/dev/ata/atapi-cd.h ./atapi-cd.h --- /sys/dev/ata/atapi-cd.h Mon Mar 18 08:37:34 2002 +++ ./atapi-cd.h Thu Sep 5 14:21:42 2002 @@ -327,3 +327,9 @@ struct devstat *stats; /* devstat entry */ dev_t dev; /* device place holders */ }; +/* Defines for acd_get_status */ +#define CD_OK 0 /* CD is loaded */ +#define CD_LOADING 1 /* CD is being loaded */ +#define CD_NODISC 2 /* no disc present */ +#define CD_OPEN 3 /* tray is open */ +#define CD_NOTREADY 4 /* drive is not ready */ >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message