From owner-freebsd-usb@FreeBSD.ORG Thu Dec 27 20:27:16 2007 Return-Path: Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A0D9916A420 for ; Thu, 27 Dec 2007 20:27:16 +0000 (UTC) (envelope-from ticso@cicely12.cicely.de) Received: from raven.bwct.de (raven.bwct.de [85.159.14.73]) by mx1.freebsd.org (Postfix) with ESMTP id 4FDAA13C442 for ; Thu, 27 Dec 2007 20:27:16 +0000 (UTC) (envelope-from ticso@cicely12.cicely.de) Received: from cicely5.cicely.de ([10.1.1.7]) by raven.bwct.de (8.13.4/8.13.4) with ESMTP id lBRKFQcn068883; Thu, 27 Dec 2007 21:15:26 +0100 (CET) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (cicely12.cicely.de [10.1.1.14]) by cicely5.cicely.de (8.13.4/8.13.4) with ESMTP id lBRKFHdx058608 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 27 Dec 2007 21:15:18 +0100 (CET) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (localhost [127.0.0.1]) by cicely12.cicely.de (8.13.4/8.13.3) with ESMTP id lBRKFHZp036025; Thu, 27 Dec 2007 21:15:17 +0100 (CET) (envelope-from ticso@cicely12.cicely.de) Received: (from ticso@localhost) by cicely12.cicely.de (8.13.4/8.13.3/Submit) id lBRKFGR7036024; Thu, 27 Dec 2007 21:15:16 +0100 (CET) (envelope-from ticso) Date: Thu, 27 Dec 2007 21:15:16 +0100 From: Bernd Walter To: Henrik Gulbrandsen Message-ID: <20071227201515.GC31522@cicely12.cicely.de> References: <1198689316.1119.382.camel@Particle> <20071226.114812.1649771240.imp@bsdimp.com> <1198713403.1119.414.camel@Particle> <20071226.174523.1326317191.imp@bsdimp.com> <1198781185.1119.478.camel@Particle> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1198781185.1119.478.camel@Particle> X-Operating-System: FreeBSD cicely12.cicely.de 5.4-STABLE alpha User-Agent: Mutt/1.5.9i X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED=-1.8, BAYES_00=-2.599 autolearn=ham version=3.2.3 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on cicely12.cicely.de Cc: freebsd-usb@freebsd.org Subject: Re: READ_CAPACITY_OFFBY1 [was: Re: usb/umass, devfs: this sucks] X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: ticso@cicely.de List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Dec 2007 20:27:16 -0000 On Thu, Dec 27, 2007 at 07:46:25PM +0100, Henrik Gulbrandsen wrote: > I'm dropping the stable list and continuing discussion on the USB list. > > On Wed, 2007-12-26 at 11:48 -0700, M. Warner Losh wrote: > > The patch in [usb/78984] is wrong. There are devices that are an odd > > number of sectors. This is one of the places where the obvious patch > > isn't necessarily right. > > On Wed, 2007-12-26 at 17:45 -0700, M. Warner Losh wrote: > > There's already a quirk for this problem that has been applied to the > > few devices that it affects. > > That would be the new READ_CAPACITY_OFFBY1, which you checked in about > five months after my patch submission :-) > > > Maybe we need to add one more to the list? There was also talk of > > forcing a read to the last sector if the sector count was odd, but it > > never got past talk. > > Well, there are at least three ways of handling this, but none of them > seems particularly good to me. It all boils down to a trade-off: > > a) Using the quirk flag. This is the obvious solution, now when it has > been added to the umass.c file. The problem with quirks in general > is highlighted by your check-in comment: "...there are a host of > other devices with this issue, including iPods and some popular > cameras". Each of these will be separately debugged and added to > the list, and since the link between cause and effect can be less > than obvious in this case, that can take hours of work per device. > > b) Reading from the last sector. This is an interesting solution, but > worries me, because that sector will technically be out-of-range in > the devices that we're interested in. If they can't get the sector > count right, how will they handle a read from an invalid sector? > I'm not a bit surprised if there are devices out there that would > block indefinitely, convert the read to a write in the first sector > and corrupt the file system, or generally burn the barn... > > c) Using heuristics. This is what I did when I assumed that there should > typically be an even number of sectors. While that is obviously a bit > too optimistic, perhaps there are other sufficiently good algorithms > for detecting the incorrect cases with a negligible number of false > positives. It may be due to a lack of imagination, but I find it hard > to think of any reason why somebody would put exactly 256001 512-byte > sectors on a umass device, unless that's an off-by-one error in itself. This is my cellphone with a 2GB micro-SD: da9 at umass-sim3 bus 3 target 0 lun 0 da9: < > Removable Direct Access SCSI-0 device da9: 1.000MB/s transfers da9: 1950MB (3994377 512 byte sectors: 255H 63S/T 248C) It offers not the complete media - it offers the slice as the whole media, so theoretically I can adjust the drive size by any number of blocks. And of course you shouldn't forget that umass can also be any kind of HDD attached to an USB converter. I assume part of the problem is that if the media is announced wrong noone has to care about it as long as all sectors can be read, which means that the driver shouldn't truncate to the media size and we don't partition the media ourself, which is most likely true for cameras and such, where most people let the camera partition the media. -- B.Walter http://www.bwct.de http://www.fizon.de bernd@bwct.de info@bwct.de support@fizon.de