From patchwork Fri Sep 4 02:38:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 32960 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by bilbo.ozlabs.org (Postfix) with ESMTP id 500F7B70B0 for ; Fri, 4 Sep 2009 12:45:53 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932658AbZIDCiZ (ORCPT ); Thu, 3 Sep 2009 22:38:25 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932643AbZIDCiY (ORCPT ); Thu, 3 Sep 2009 22:38:24 -0400 Received: from hera.kernel.org ([140.211.167.34]:41443 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932664AbZIDCiV (ORCPT ); Thu, 3 Sep 2009 22:38:21 -0400 Received: from htj.dyndns.org (IDENT:U2FsdGVkX1+VKNjxd9JX60bEMRj5S4OUEYVkXOZDRE8@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n842c3Lw023782 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Fri, 4 Sep 2009 02:38:05 GMT Received: from [127.0.0.2] (htj.dyndns.org [127.0.0.2]) by htj.dyndns.org (Postfix) with ESMTPSA id 2AFB64572A808; Fri, 4 Sep 2009 11:38:03 +0900 (KST) Message-ID: <4AA07D8A.6090004@kernel.org> Date: Fri, 04 Sep 2009 11:38:02 +0900 From: Tejun Heo User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 To: James Bottomley , linux-scsi , IDE/ATA development list , Milan Kocian , Jan Kara Subject: [PATCH] sr: consider the last written sector when determining media size X-Enigmail-Version: 0.95.7 X-Virus-Scanned: ClamAV 0.93.3/9773/Thu Sep 3 07:38:27 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Fri, 04 Sep 2009 02:38:19 +0000 (UTC) Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org On certain cases, UDF disc doesn't report capacity correctly via READ_CAPACITY but TOC or trackinfo contains valid information which can be obtained using cdrom_get_last_written(). ide-cd considers both values and uses the larger one. Do the same in sr. This fixes bko#9668. http://bugzilla.kernel.org/show_bug.cgi?id=9668 Signed-off-by: Tejun Heo Reported-by: Milan Kocian Cc: Jan Kara Tested-by: Milan Kocian --- drivers/scsi/sr.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index cce0fe4..76bdcfc 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -684,14 +684,20 @@ static void get_sectorsize(struct scsi_cd *cd) cd->capacity = 0x1fffff; sector_size = 2048; /* A guess, just in case */ } else { -#if 0 - if (cdrom_get_last_written(&cd->cdi, - &cd->capacity)) -#endif - cd->capacity = 1 + ((buffer[0] << 24) | - (buffer[1] << 16) | - (buffer[2] << 8) | - buffer[3]); + long last_written; + + cd->capacity = 1 + ((buffer[0] << 24) | (buffer[1] << 16) | + (buffer[2] << 8) | buffer[3]); + /* + * READ_CAPACITY doesn't return the correct size on + * certain UDF media. If last_written is larger, use + * it instead. + * + * http://bugzilla.kernel.org/show_bug.cgi?id=9668 + */ + if (!cdrom_get_last_written(&cd->cdi, &last_written)) + cd->capacity = max_t(long, cd->capacity, last_written); + sector_size = (buffer[4] << 24) | (buffer[5] << 16) | (buffer[6] << 8) | buffer[7]; switch (sector_size) {