From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N2Pko-0001Sj-Tr for qemu-devel@nongnu.org; Mon, 26 Oct 2009 09:36:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N2Pkj-0001SH-Lw for qemu-devel@nongnu.org; Mon, 26 Oct 2009 09:36:57 -0400 Received: from [199.232.76.173] (port=43168 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N2Pkj-0001SE-Gp for qemu-devel@nongnu.org; Mon, 26 Oct 2009 09:36:53 -0400 Received: from mail-yw0-f176.google.com ([209.85.211.176]:47219) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N2Pkj-0005AY-3x for qemu-devel@nongnu.org; Mon, 26 Oct 2009 09:36:53 -0400 Received: by ywh6 with SMTP id 6so9311383ywh.4 for ; Mon, 26 Oct 2009 06:36:52 -0700 (PDT) MIME-Version: 1.0 From: Artyom Tarasenko Date: Mon, 26 Oct 2009 15:36:32 +0200 Message-ID: Content-Type: multipart/mixed; boundary=005045016fad806fea0476d6a77a Subject: [Qemu-devel] [PATCH] scsi-disk: Inquiry with allocation length of CDB < 36 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel , Blue Swirl --005045016fad806fea0476d6a77a Content-Type: text/plain; charset=ISO-8859-1 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 --- diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2a9268a..1a7487e 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); - } } 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; --005045016fad806fea0476d6a77a Content-Type: text/plain; charset=US-ASCII; name="0001-scsi-disk-short-inquiry.patch" Content-Disposition: attachment; filename="0001-scsi-disk-short-inquiry.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g199t5h50 U2lnbmVkLW9mZi1ieTogQXJ0eW9tIFRhcmFzZW5rbyA8YXRhcjRxZW11QGdtYWlsLmNvbT4KLS0t CmRpZmYgLS1naXQgYS9ody9zY3NpLWRpc2suYyBiL2h3L3Njc2ktZGlzay5jCmluZGV4IDJhOTI2 OGEuLjFhNzQ4N2UgMTAwNjQ0Ci0tLSBhL2h3L3Njc2ktZGlzay5jCisrKyBiL2h3L3Njc2ktZGlz ay5jCkBAIC01LDYgKzUsMTIgQEAKICAqIEJhc2VkIG9uIGNvZGUgYnkgRmFicmljZSBCZWxsYXJk CiAgKgogICogV3JpdHRlbiBieSBQYXVsIEJyb29rCisgKiBNb2RpZmljYXRpb25zOgorICogIDIw MDktT2N0LTI2IEFydHlvbSBUYXJhc2Vua28gOiBpbXBsZW1lbnRlZCBzdGFtZGFyZCBpbnF1aXJ5 IGZvciB0aGUgY2FzZQorICogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3aGVuIHRo ZSBhbGxvY2F0aW9uIGxlbmd0aCBvZiBDREIgaXMgc21hbGxlcgorICogICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICB0aGFuIDM2LgorICogIDIwMDktT2N0LTEzIEFydHlvbSBUYXJhc2Vu a28gOiBpbXBsZW1lbnRlZCB0aGUgYmxvY2sgZGVzY3JpcHRvciBpbiB0aGUgCisgKiAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgIE1PREUgU0VOU0UgcmVzcG9uc2UuCiAgKgogICogVGhp cyBjb2RlIGlzIGxpY2VuY2VkIHVuZGVyIHRoZSBMR1BMLgogICoKQEAgLTU3NiwxMSArNTgyLDYg QEAgc3RhdGljIGludDMyX3Qgc2NzaV9zZW5kX2NvbW1hbmQoU0NTSURldmljZSAqZCwgdWludDMy X3QgdGFnLAogICAgICAgICAgICAgICAgICAgICAgImlzIGxlc3MgdGhhbiA1XG4iLCBsZW4pOwog ICAgICAgICAgICAgICAgIGdvdG8gZmFpbDsKICAgICAgICAgICAgIH0KLQotICAgICAgICAgICAg aWYgKGxlbiA8IDM2KSB7Ci0gICAgICAgICAgICAgICAgQkFERigiRXJyb3I6IElucXVpcnkgKFNU QU5EQVJEKSBidWZmZXIgc2l6ZSAlZCAiCi0gICAgICAgICAgICAgICAgICAgICAiaXMgbGVzcyB0 aGFuIDM2IChUT0RPOiBvbmx5IDUgcmVxdWlyZWQpXG4iLCBsZW4pOwotICAgICAgICAgICAgfQog ICAgICAgICB9CiAKICAgICAgICAgaWYobGVuID4gU0NTSV9NQVhfSU5RVUlSWV9MRU4pCkBAIC02 MDQsNyArNjA1LDEzIEBAIHN0YXRpYyBpbnQzMl90IHNjc2lfc2VuZF9jb21tYW5kKFNDU0lEZXZp Y2UgKmQsIHVpbnQzMl90IHRhZywKICAgICAgICAgICAgU29tZSBsYXRlciBjb21tYW5kcyBhcmUg YWxzbyBpbXBsZW1lbnRlZC4gKi8KIAlvdXRidWZbMl0gPSAzOwogCW91dGJ1ZlszXSA9IDI7IC8q IEZvcm1hdCAyICovCi0Jb3V0YnVmWzRdID0gbGVuIC0gNTsgLyogQWRkaXRpb25hbCBMZW5ndGgg PSAoTGVuIC0gMSkgLSA0ICovCisJaWYgKGxlbiA+IDM2KSB7CisJICAgIG91dGJ1Zls0XSA9IGxl biAtIDU7IC8qIEFkZGl0aW9uYWwgTGVuZ3RoID0gKExlbiAtIDEpIC0gNCAqLworCX0gZWxzZSB7 CisgICAgICAgICAgICAgIC8qIElmIHRoZSBhbGxvY2F0aW9uIGxlbmd0aCBvZiBDREIgaXMgdG9v IHNtYWxsLCB0aGUgYWRkaXRpb25hbCBsZW5ndGgKKyAgICAgICAgICAgICAgICAgaXMgbm90IGFk anVzdGVkICovICAKKwkgICAgb3V0YnVmWzRdID0gMzYgLSA1OworCX0KICAgICAgICAgLyogU3lu YyBkYXRhIHRyYW5zZmVyIGFuZCBUQ1EuICAqLwogICAgICAgICBvdXRidWZbN10gPSAweDEwIHwg KHItPmJ1cy0+dGNxID8gMHgwMiA6IDApOwogCXItPmlvdi5pb3ZfbGVuID0gbGVuOwo= --005045016fad806fea0476d6a77a--