NetBSD Problem Report #55986

From ryo@tetera.org  Wed Feb 10 15:21:37 2021
Return-Path: <ryo@tetera.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 59D121A9217
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 10 Feb 2021 15:21:37 +0000 (UTC)
Message-Id: <6023f9fe.1c69fb81.f7210.5591@mx.google.com>
Date: Thu, 11 Feb 2021 00:21:33 +0900
From: ryo@tetera.org
Reply-To: ryo@tetera.org
To: gnats-bugs@NetBSD.org
Subject: Cannot eject USB mass storage attached as sd(4)
X-Send-Pr-Version: 3.95

>Number:         55986
>Category:       kern
>Synopsis:       Cannot eject USB mass storage attached as sd(4)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 10 15:25:00 +0000 2021
>Closed-Date:    Sat Feb 13 00:52:47 +0000 2021
>Last-Modified:  Sat Feb 13 00:52:47 +0000 2021
>Originator:     Ryo ONODERA
>Release:        NetBSD 9.99.80
>Organization:
Ryo ONODERA // ryo@tetera.org
PGP fingerprint = 82A2 DC91 76E0 A10A 8ABB  FD1B F404 27FA C7D1 15F3
>Environment:


System: NetBSD brownie 9.99.80 NetBSD 9.99.80 (DTRACE7) #2: Thu Feb 11 00:02:23 JST 2021 ryoon@brownie:/usr/world/9.99/amd64/obj/sys/arch/amd64/compile/DTRACE7 amd64
Architecture: x86_64
Machine: amd64
>Description:
When Amazon Kindle e-ink device is connected to NetBSD/amd64 9.99.80,
Amazon Kindle shows USB drive mode screen and I cannot read ebooks
without ejecting of sd0e.

However "eject /dev/sd0e" always returns EBUSY,
because r1.320 of src/sys/dev/scsipi/cd.c has a mistake.

See: http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/scsipi/sd.c.diff?r1=1.319&r2=1.320&only_with_tag=MAIN
DK_BUSY must have mask as second argument, however it takes bit number.

>How-To-Repeat:
Connect Amazon Kindle to NetBSD/amd64 9.99.80.
Run "eject /dev/sd0e".

>Fix:

Index: sys/dev/scsipi/sd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/scsipi/sd.c,v
retrieving revision 1.330
diff -u -r1.330 sd.c
--- sys/dev/scsipi/sd.c	25 Sep 2020 13:08:00 -0000	1.330
+++ sys/dev/scsipi/sd.c	10 Feb 2021 15:12:13 -0000
@@ -954,11 +954,12 @@
 		if ((periph->periph_flags & PERIPH_REMOVABLE) == 0)
 			return (ENOTTY);
 		if (*(int *)addr == 0) {
+			int pmask = __BIT(part);
 			/*
 			 * Don't force eject: check that we are the only
 			 * partition open. If so, unlock it.
 			 */
-			if (DK_BUSY(dksc, part) == 0) {
+			if (DK_BUSY(dksc, pmask) == 0) {
 				error = scsipi_prevent(periph, SPAMR_ALLOW,
 				    XS_CTL_IGNORE_NOT_READY);
 				if (error)

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55986 CVS commit: src/sys/dev/scsipi
Date: Wed, 10 Feb 2021 11:30:01 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Wed Feb 10 16:30:01 UTC 2021

 Modified Files:
 	src/sys/dev/scsipi: cd.c sd.c

 Log Message:
 PR/55986: Ryo Onodera: DK_BUSY must have mask as second argument. Make cd.c
 consistent by also using __BIT()


 To generate a diff of this commit:
 cvs rdiff -u -r1.349 -r1.350 src/sys/dev/scsipi/cd.c
 cvs rdiff -u -r1.330 -r1.331 src/sys/dev/scsipi/sd.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: John Nemeth <jnemeth@cue.bc.ca>
To: gnats-bugs@netbsd.org, kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
        netbsd-bugs@netbsd.org
Cc: 
Subject: Re: kern/55986: Cannot eject USB mass storage attached as sd(4)
Date: Wed, 10 Feb 2021 08:36:04 -0800

      Silly question, but why are you using the eject command?  That
 command is intended to physically eject the media, as in CDs.  Just
 make sure that there is nothing mounted from the Kindle and pull
 the plug (no need to use the eject command).

From: Ryo ONODERA <ryo@tetera.org>
To: John Nemeth <jnemeth@cue.bc.ca>, gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/55986: Cannot eject USB mass storage attached as sd(4)
Date: Thu, 11 Feb 2021 08:46:49 +0900

 John Nemeth <jnemeth@cue.bc.ca> writes:

 >      Silly question, but why are you using the eject command?  That
 > command is intended to physically eject the media, as in CDs.  Just
 > make sure that there is nothing mounted from the Kindle and pull
 > the plug (no need to use the eject command).

 My original description may be insufficient.
 My problem is described a certain blog post.
 It will help you.
 See: http://www.ereader1.net/2012/10/tip-kindle-charging-via-computer.html

 Thank you.

 -- 
 Ryo ONODERA // ryo@tetera.org
 PGP fingerprint = 82A2 DC91 76E0 A10A 8ABB  FD1B F404 27FA C7D1 15F3

State-Changed-From-To: open->pending-pullups
State-Changed-By: ryoon@NetBSD.org
State-Changed-When: Thu, 11 Feb 2021 00:09:41 +0000
State-Changed-Why:
Pull-up requests to netbsd-8 and netbsd-9


From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@netbsd.org, ryoon@netbsd.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: re: kern/55986: Cannot eject USB mass storage attached as sd(4)
Date: Thu, 11 Feb 2021 22:18:01 +1100

 > However "eject /dev/sd0e" always returns EBUSY,
 > because r1.320 of src/sys/dev/scsipi/cd.c has a mistake.

 thank you!  this has bothered me for years...

From: matthew green <mrg@eterna.com.au>
To: John Nemeth <jnemeth@cue.bc.ca>
Cc: gnats-bugs@netbsd.org, kern-bug-people@netbsd.org,
    gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: re: kern/55986: Cannot eject USB mass storage attached as sd(4)
Date: Thu, 11 Feb 2021 22:22:35 +1100

 John Nemeth writes:
 >      Silly question, but why are you using the eject command?  That
 > command is intended to physically eject the media, as in CDs.  Just
 > make sure that there is nothing mounted from the Kindle and pull
 > the plug (no need to use the eject command).

 you can't read while it's charging from netbsd usb port.
 well, you can now in -current.  yay!

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55986 CVS commit: [netbsd-9] src/sys/dev/scsipi
Date: Thu, 11 Feb 2021 12:53:28 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Thu Feb 11 12:53:28 UTC 2021

 Modified Files:
 	src/sys/dev/scsipi [netbsd-9]: cd.c sd.c

 Log Message:
 Pull up following revision(s) (requested by ryoon in ticket #1203):

 	sys/dev/scsipi/cd.c: revision 1.350
 	sys/dev/scsipi/sd.c: revision 1.331

 PR 55986: Ryo Onodera: DK_BUSY must have mask as second argument. Make cd.c
 consistent by also using __BIT()


 To generate a diff of this commit:
 cvs rdiff -u -r1.342.4.1 -r1.342.4.2 src/sys/dev/scsipi/cd.c
 cvs rdiff -u -r1.327.4.1 -r1.327.4.2 src/sys/dev/scsipi/sd.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55986 CVS commit: [netbsd-8] src/sys/dev/scsipi
Date: Thu, 11 Feb 2021 12:54:56 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Thu Feb 11 12:54:56 UTC 2021

 Modified Files:
 	src/sys/dev/scsipi [netbsd-8]: cd.c sd.c

 Log Message:
 Pull up following revision(s) (requested by ryoon in ticket #1652):

 	sys/dev/scsipi/cd.c: revision 1.350
 	sys/dev/scsipi/sd.c: revision 1.331

 PR 55986: Ryo Onodera: DK_BUSY must have mask as second argument. Make cd.c
 consistent by also using __BIT()


 To generate a diff of this commit:
 cvs rdiff -u -r1.340.6.2 -r1.340.6.3 src/sys/dev/scsipi/cd.c
 cvs rdiff -u -r1.324.6.1 -r1.324.6.2 src/sys/dev/scsipi/sd.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: ryoon@NetBSD.org
State-Changed-When: Sat, 13 Feb 2021 00:52:47 +0000
State-Changed-Why:
Fix ed. Thank you.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.