Subject: Re: umass woe: sd0(umass0:0:0): readonly device & drive offline
To: Hubert Feyrer <feyrer@cs.stevens.edu>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: tech-kern
Date: 11/20/2005 17:04:06
--AhhlLboLdkugWU4S
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Nov 20, 2005 at 02:34:08AM +0100, Hubert Feyrer wrote:
> 
> 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.

You don't have SCSIVERBOSE in your kernel, do you ?
Can you try with SCSIVERBOSE ? this should print which command fails with
the "write protected" sense key here.

> 
> 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!

I think a message should be printed, and the periph marked as non-removable.
Also the error should be ignored only when trying to lock/unlock the door.
please try the attached patch instead.

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--

--AhhlLboLdkugWU4S
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

Index: sd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/scsipi/sd.c,v
retrieving revision 1.241
diff -u -r1.241 sd.c
--- sd.c	15 Oct 2005 17:29:25 -0000	1.241
+++ sd.c	20 Nov 2005 16:03:45 -0000
@@ -1128,8 +1128,12 @@
 		return (0);
 
 	case DIOCLOCK:
-		return (scsipi_prevent(periph,
-		    (*(int *)addr) ? SPAMR_PREVENT_DT : SPAMR_ALLOW, 0));
+		if (periph->periph_flags & PERIPH_REMOVABLE)
+			return (scsipi_prevent(periph,
+			    (*(int *)addr) ?
+			    SPAMR_PREVENT_DT : SPAMR_ALLOW, 0));
+		else
+			return (ENOTTY);
 
 	case DIOCEJECT:
 		if ((periph->periph_flags & PERIPH_REMOVABLE) == 0)
@@ -1353,6 +1357,23 @@
 		return (retval);
 
 	/*
+	 * 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) for the SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL command.
+	 */
+	if (xs->cmd.opcode == SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL &&
+	    (sense->flags & SSD_KEY) == SKEY_ILLEGAL_REQUEST &&
+	    sense->add_sense_code == 0x24 &&
+	    sense->add_sense_code_qual == 0x00) { /* Illegal field in CDB */
+		scsipi_printaddr(periph);
+		printf("no door lock\n");
+		periph->periph_flags &= ~PERIPH_REMOVABLE;
+		return 0;
+	}
+
+
+
+	/*
 	 * If the device is not open yet, let the generic code handle it.
 	 */
 	if ((periph->periph_flags & PERIPH_MEDIA_LOADED) == 0)

--AhhlLboLdkugWU4S--