From patchwork Tue Oct 13 21:46:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artyom Tarasenko X-Patchwork-Id: 35902 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 3F9F5B7334 for ; Wed, 14 Oct 2009 08:47:54 +1100 (EST) Received: from localhost ([127.0.0.1]:37940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxpDj-0007hy-DM for incoming@patchwork.ozlabs.org; Tue, 13 Oct 2009 17:47:51 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MxpCo-0007dX-A7 for qemu-devel@nongnu.org; Tue, 13 Oct 2009 17:46:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MxpCj-0007XU-Ha for qemu-devel@nongnu.org; Tue, 13 Oct 2009 17:46:53 -0400 Received: from [199.232.76.173] (port=41854 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MxpCj-0007X3-8K for qemu-devel@nongnu.org; Tue, 13 Oct 2009 17:46:49 -0400 Received: from mail-yw0-f176.google.com ([209.85.211.176]:44196) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MxpCi-0004a1-Of for qemu-devel@nongnu.org; Tue, 13 Oct 2009 17:46:48 -0400 Received: by ywh6 with SMTP id 6so9419603ywh.4 for ; Tue, 13 Oct 2009 14:46:45 -0700 (PDT) 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:content-type; bh=G8iG5XqL4jvjNrCUxBeVQCdqt9yZG3Yrrya+oi/HkxQ=; b=v1mzKfwGnnlrY55n+i/eq1H6A+/j59HB4yRDesU05maodFwT8ahSVqbFv4vZuhIrJL cEnltqkqnAYu5tnhCnlh/IUU2RQsN36t4omUhA3xM4GxP/lhaKJptoGoLv9m/Z17HD+e 1vIlUnCR2jhJZiN2gUASxJJp69W0ixQ/m/JcU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=SZ7iC1CDJC0DdoNxBxu+ml0ljaCoOFfbanyK3ZZtxAC8zC+28NOpTpRAp/7ZAIcNWZ L/xX5kHaRKIWB9MN2c8AB8X9T8rHW/dfasMGPaI+O8MFBIw6D5HvOxz6VXG3VHZ7IpmK e88p3g4RmVaNtNLRPTGiPR+Qb3oYKHFtQ+4ag= MIME-Version: 1.0 Received: by 10.90.61.3 with SMTP id j3mr4665745aga.40.1255470404204; Tue, 13 Oct 2009 14:46:44 -0700 (PDT) From: Artyom Tarasenko Date: Tue, 13 Oct 2009 23:46:24 +0200 Message-ID: To: qemu-devel , Blue Swirl , "Krumme, Chris" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: Subject: [Qemu-devel] [PATCH] scsi disk block descriptor 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 The SCSI-2 documentation suggests, that although the block descriptor is optional for an arbitrary SCSI-2 device (chapter 8.2.10, http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2/SCSI2-08.html ) it is mandatory for a disk: chapters 9.1.2, 9.3.3 ( http://ldkelley.com/SCSI2/SCSI2/SCSI2/SCSI2-09.html ) don't say "optional" any more, just "The block descriptor in the MODE SENSE data describes the block lengths that are used on the medium." v2: limit the number of sectors reported in the block descriptor to 24 bits. Signed-off-by: Artyom Tarasenko --- p = outbuf; @@ -635,6 +637,24 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, outbuf[2] = 0x80; /* Readonly. */ } p += 4; + bdrv_get_geometry(s->dinfo->bdrv, &nb_sectors); + if ((~dbd) & nb_sectors) { + nb_sectors /= s->cluster_size; + nb_sectors--; + if (nb_sectors > 0xffffff) + nb_sectors = 0xffffff; + outbuf[3] = 8; /* Block descriptor length */ + p[0] = 0; /* media density code */ + p[1] = (nb_sectors >> 16) & 0xff; + p[2] = (nb_sectors >> 8) & 0xff; + p[3] = nb_sectors & 0xff; + p[4] = 0; /* reserved */ + p[5] = 0; /* bytes 5-7 are the sector size in bytes */ + p[6] = s->cluster_size * 2; + p[7] = 0; + p += 8; + } + if (page == 4) { int cylinders, heads, secs; diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 3940726..2a9268a 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -624,7 +624,9 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, { uint8_t *p; int page; - + int dbd; + + dbd = buf[1] & 0x8; page = buf[2] & 0x3f; DPRINTF("Mode Sense (page %d, len %d)\n", page, len);