From patchwork Sat Dec 12 19:24:22 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 40991 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 77778B6F1C for ; Sun, 13 Dec 2009 06:28:08 +1100 (EST) Received: from localhost ([127.0.0.1]:42478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NJXah-0006NZ-6T for incoming@patchwork.ozlabs.org; Sat, 12 Dec 2009 14:25:19 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NJXa3-0006Kk-WB for qemu-devel@nongnu.org; Sat, 12 Dec 2009 14:24:40 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NJXZw-0006Cf-3x for qemu-devel@nongnu.org; Sat, 12 Dec 2009 14:24:35 -0500 Received: from [199.232.76.173] (port=57961 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NJXZt-0006CG-VF for qemu-devel@nongnu.org; Sat, 12 Dec 2009 14:24:29 -0500 Received: from mail-fx0-f219.google.com ([209.85.220.219]:65472) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NJXZt-0003J6-Tx for qemu-devel@nongnu.org; Sat, 12 Dec 2009 14:24:30 -0500 Received: by fxm19 with SMTP id 19so1995449fxm.17 for ; Sat, 12 Dec 2009 11:24:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer; bh=bpkk8sH+YdqgTAiNKAhwFdaNQic+2FSaZnkdXRFa4kQ=; b=BOQzU3fcFD5xQBkHjn+DZ2RQlYOfFvG8Yc9G9Am6M92DNAvQK43cxWMQjeiuOY96V4 zky/URBfM5O0xoC/BAZTIlOdmhgzJlHfg2xmv88kdEbt3Y14tGKkxQHBSr10ODN+plJ1 yFbnap7O8BdM8WOHwEswrN41KhJ/MVNekBwpw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=ZR+LTtrVZsJ80MnbCu4LhlH5zFIRKuRgCtj1yLarWHiEPuOymY6Ifclfavs1j6szgl DV1DhsOo1MYvXKoEMRchIsq1Q1rElMG4AVfmzRale61qZgGoSTnRHLP8xyVnho8B8MS1 dQEMcAofgxs/tnbZfjddxCML2bJdf+GP4p4QM= Received: by 10.223.15.148 with SMTP id k20mr3305538faa.6.1260645866095; Sat, 12 Dec 2009 11:24:26 -0800 (PST) Received: from localhost (e181216067.adsl.alicedsl.de [85.181.216.67]) by mx.google.com with ESMTPS id 22sm4746370fkq.54.2009.12.12.11.24.24 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 12 Dec 2009 11:24:25 -0800 (PST) From: Artyom Tarasenko To: "qemu-devel" Date: Sat, 12 Dec 2009 20:24:22 +0100 Message-Id: <1260645862-13701-1-git-send-email-atar4qemu@google.com> X-Mailer: git-send-email 1.6.2.5 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Blue Swirl , Artyom Tarasenko Subject: [Qemu-devel] [FOR 0.12 PATCH] scsi-disk: Inquiry with allocation length of CDB < 36 (v3) 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 the 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 --- diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2e7a57b..495ba35 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-Dec-12 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. * @@ -406,11 +412,6 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) return -1; } - if (req->cmd.xfer < 36) { - BADF("Error: Inquiry (STANDARD) buffer size %zd " - "is less than 36 (TODO: only 5 required)\n", req->cmd.xfer); - } - buflen = req->cmd.xfer; if (buflen > SCSI_MAX_INQUIRY_LEN) buflen = SCSI_MAX_INQUIRY_LEN; @@ -436,7 +437,15 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) Some later commands are also implemented. */ outbuf[2] = 3; outbuf[3] = 2; /* Format 2 */ - outbuf[4] = buflen - 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 | (req->bus->tcq ? 0x02 : 0); return buflen;