From patchwork Tue Nov 10 21:18:28 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 38100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A9EDBB7BA0 for ; Wed, 11 Nov 2009 09:36:58 +1100 (EST) Received: from localhost ([127.0.0.1]:33284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7y9c-0007ha-Vd for incoming@patchwork.ozlabs.org; Tue, 10 Nov 2009 16:21:33 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N7y75-0005Bo-8c for qemu-devel@nongnu.org; Tue, 10 Nov 2009 16:18:55 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N7y70-00054o-6K for qemu-devel@nongnu.org; Tue, 10 Nov 2009 16:18:54 -0500 Received: from [199.232.76.173] (port=37166 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N7y6z-00054a-RB for qemu-devel@nongnu.org; Tue, 10 Nov 2009 16:18:49 -0500 Received: from mail-yw0-f176.google.com ([209.85.211.176]:40061) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N7y6z-000182-HJ for qemu-devel@nongnu.org; Tue, 10 Nov 2009 16:18:49 -0500 Received: by ywh6 with SMTP id 6so404411ywh.4 for ; Tue, 10 Nov 2009 13:18:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:cc:content-type; bh=RHGLc/hW8xAIK9Z5gf0MS1FB5XzBrQVvvuPPGED4eBU=; b=Kr+6B5nxk7+9QyHgt8ZBF8vMx2zwJkOHC4NmvijDn+6O2H2w08HrNHazcmvqBQe7Xp OJz+b65lVcuNuWMGEK8UqpuuzlowjjO3rF+2oraJ4PttfaS3hCCVPDa1CzXgfKsa5ngT zEguMOhbjFrakdWw0l3O6K6DRcZciT7e4SEAM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:cc:content-type; b=jWUrLHyaDe1SgyVklSsfPZ91vkBC/IwaixMOwero1I+ZZG1adqx1YB8UpuuoZaz4oa z1YytMEYRnE3ccmnM4A9OPwXxWZQ5EsKHdG2PAhc4uIt7TQTb23TrNqxOTPgL7qy5FAL vcQM0U4sRHAscNDy0HYNBOB42NAFOyxwROTWI= MIME-Version: 1.0 Received: by 10.90.15.33 with SMTP id 33mr970943ago.31.1257887928438; Tue, 10 Nov 2009 13:18:48 -0800 (PST) From: Artyom Tarasenko Date: Tue, 10 Nov 2009 22:18:28 +0100 Message-ID: To: qemu-devel X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Blue Swirl Subject: [Qemu-devel] [PATCH] scsi-disk: Inquiry with allocation length of CDB < 36 (v2) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org According to SCSI-2 specification, http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2-08.html#8.2.5 , "if the allocation length of the command descriptor block (CDB) is too small to transfer all of the parameters, the additional length shall not be adjusted to reflect the truncation." The 36 mandatory bytes of response are written to outbuf, and then only the length requested in CDB is transferred. Signed-off-by: Artyom Tarasenko --- if(len > SCSI_MAX_INQUIRY_LEN) @@ -604,7 +605,13 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, Some later commands are also implemented. */ outbuf[2] = 3; outbuf[3] = 2; /* Format 2 */ - outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ + if (len > 36) { + outbuf[4] = len - 5; /* Additional Length = (Len - 1) - 4 */ + } else { + /* If the allocation length of CDB is too small, + the additional length is not adjusted */ + outbuf[4] = 36 - 5; + } /* Sync data transfer and TCQ. */ outbuf[7] = 0x10 | (r->bus->tcq ? 0x02 : 0); r->iov.iov_len = len; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2a9268a..1af983c 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -5,6 +5,12 @@ * Based on code by Fabrice Bellard * * Written by Paul Brook + * Modifications: + * 2009-Oct-26 Artyom Tarasenko : implemented stamdard inquiry for the case + * when the allocation length of CDB is smaller + * than 36. + * 2009-Oct-13 Artyom Tarasenko : implemented the block descriptor in the + * MODE SENSE response. * * This code is licenced under the LGPL. * @@ -576,11 +582,6 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, "is less than 5\n", len); goto fail; } - - if (len < 36) { - BADF("Error: Inquiry (STANDARD) buffer size %d " - "is less than 36 (TODO: only 5 required)\n", len); - } }