public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Jones <pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	fedora-kernel-list
	<fedora-kernel-list-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH] make sr_mod report more accurate drive status after closing the tray.
Date: Thu, 10 Jul 2008 17:24:24 -0400	[thread overview]
Message-ID: <48767E08.50202@redhat.com> (raw)


Right now, when using sr_mod and issuing the CDROM_DRIVE_STATUS ioctl,
there's no way to differentiate between when you've just closed the
drive tray, but the media is not yet loaded, and when there's no media.
This seems to be accidental.

Here's a patch that seems to fix this behaviour:

Signed-off-by: Peter Jones <pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index ae87d08..43a084b 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -306,10 +306,9 @@ int sr_drive_status(struct cdrom_device_info *cdi, 
int slot)
  		/* we have no changer support */
  		return -EINVAL;
  	}
-	if (0 == sr_test_unit_ready(cd->device, &sshdr))
-		return CDS_DISC_OK;
-
-	if (!cdrom_get_media_event(cdi, &med)) {
+	if (0 == sr_test_unit_ready(cd->device, &sshdr)
+			&& sshdr.sense_key == 0
+			&& !cdrom_get_media_event(cdi, &med)) {
  		if (med.media_present)
  			return CDS_DISC_OK;
  		else if (med.door_open)
@@ -319,10 +318,27 @@ int sr_drive_status(struct cdrom_device_info *cdi, 
int slot)
  	}

  	/*
-	 * 0x04 is format in progress .. but there must be a disc present!
+	 * ASC: 0x04: "logical unit is not ready"
+	 * ASCQ: 0x01: cause not reportable
+	 *       0x02: in process of becoming ready
+	 *       0x03: initializing command required
+	 *       0x04: format in progress .. but there must be a disc present!
+	 *       0x07: operation in progress
+	 *       0x08: long write in progress
  	 */
-	if (sshdr.sense_key == NOT_READY && sshdr.asc == 0x04)
-		return CDS_DISC_OK;
+	if (sshdr.sense_key == NOT_READY && sshdr.asc == 0x04) {
+		switch (sshdr.ascq) {
+			case 0x01:
+			case 0x02:
+				return CDS_DRIVE_NOT_READY;
+			case 0x03:
+				return CDS_TRAY_OPEN;
+			case 0x04:
+			case 0x07:
+			case 0x08:
+				return CDS_DRIVE_NOT_READY;
+		}
+	}

  	/*
  	 * If not using Mt Fuji extended media tray reports,

             reply	other threads:[~2008-07-10 21:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-10 21:24 Peter Jones [this message]
2008-07-10 21:51 ` [PATCH] make sr_mod report more accurate drive status after closing the tray James Bottomley
     [not found]   ` <1215726719.3353.92.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-07-11 14:51     ` Peter Jones
     [not found]       ` <4877738B.4090100-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2008-07-11 20:17         ` Peter Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48767E08.50202@redhat.com \
    --to=pjones-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=fedora-kernel-list-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=linux-scsi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox