Subject: Re: umass woe: sd0(umass0:0:0): readonly device & drive offline
To: Michael van Elst <mlelstv@serpens.de>
From: Hubert Feyrer <feyrer@cs.stevens.edu>
List: tech-kern
Date: 11/20/2005 02:34:08
On Sat, 19 Nov 2005, Michael van Elst wrote:
> If you want to ignore the error, just return 0.

Ok, the patch below does this, and it gets my camera working.
Messages I get are:

1) nothing spectacular when booting without the camera (expected)
2) when plugging in the camera:

 	umass0 at uhub0 port 1 configuration 1 interface 0
 	umass0: DSC DIGITAL CAMERA USB, rev 1.00/1.00, addr 2
 	umass0: using ATAPI over Bulk-Only
 	atapibus0 at umass0: 2 targets
 	sd0 at atapibus0 drive 0: <DIGITAL, CAMERA, 1.00> disk removable
 	sd0(umass0:0:0): readonly device
 	sd0: drive offline

3) When accessing the camera (disklabel, mount, view files, ...):

 	sd0: fabricating a geometry

Other than the fact that the drive is neither readonly nor offline,
this works for me.

One thing I wonder is if the reply should be silently ignored (as it's 
done right now), or if some error/warning/whatever should be printed.

I also have ZERO clue what other SCSI devices this patch may break - I 
cannot test this on anything. Someone please review!

Where to go from there?


  - Hubert


Index: sd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/scsipi/sd.c,v
retrieving revision 1.216.2.3
diff -u -r1.216.2.3 sd.c
--- sd.c	11 Sep 2004 12:55:11 -0000	1.216.2.3
+++ sd.c	20 Nov 2005 01:26:26 -0000
@@ -1367,6 +1367,16 @@
  	int s, error, retval = EJUSTRETURN;

  	/*
+	 * Ignore errors from accessing illegal fields (e.g. trying to
+	 * lock the door of a digicam, which doesn't have a door that
+	 * can be locked)
+	 */
+	if ((sense->flags & SSD_KEY) == SKEY_ILLEGAL_REQUEST &&
+	    sense->add_sense_code == 0x24 &&
+	    sense->add_sense_code_qual == 0x00) /* Illegal field in CDB */
+		return 0;
+ 
+	/*
  	 * If the periph is already recovering, just do the normal
  	 * error processing.
  	 */