atapi cd-rom mounting patch

neologism neologism at seznam.cz
Sat Sep 7 12:50:51 CEST 2002


zdravim

nova verze patche, zmeny:
 o overovani eject capability
 o workaround pro changery

stale shanim nekoho kdo ma stary cd-rom drive (atapi) aby to vyzkousel

diki

Roman Divacky

-- 

Whole life is distress and woe. No deliverance. Maybe death...
-------------- next part --------------
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 */


More information about the Users-l mailing list