Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Sep 2002 14:25:14 +0200
From:      neologism <neologism@seznam.cz>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/42659: atapi cd-rom mounting patch
Message-ID:  <20020911142514.A516@variola>

next in thread | raw e-mail | index | archive | help

>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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020911142514.A516>