From patchwork Thu Apr 19 14:29:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 153800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BE84FB6FE9 for ; Fri, 20 Apr 2012 00:45:38 +1000 (EST) Received: from localhost ([::1]:38850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKsOW-0001bF-OW for incoming@patchwork.ozlabs.org; Thu, 19 Apr 2012 10:31:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:44762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKsNX-0000Bp-Qz for qemu-devel@nongnu.org; Thu, 19 Apr 2012 10:30:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SKsNN-00056T-GX for qemu-devel@nongnu.org; Thu, 19 Apr 2012 10:30:35 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:63839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SKsNN-0004Mc-82 for qemu-devel@nongnu.org; Thu, 19 Apr 2012 10:30:25 -0400 Received: by mail-pb0-f45.google.com with SMTP id uo5so12014088pbc.4 for ; Thu, 19 Apr 2012 07:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=yiV/ccllG6TF4EVSkZQdkmqXcdR6jHGcMEX/87sK9z4=; b=USFzQKL5RE1Tdq6PhOA1hrITlx6oMEZhC0WDPaje3uNaDmasla3kjaN0QpTPiyjJ/U luhpCsbjHXtaClNWSf9C47liA61HRUyhJ7WZgDv8wBj13pqw2O783mUX3sAf9PgcApym kPHTFJhTJO1utOhoZ52Y47infPfcZuXIyOPhubofoR8fwmX9tY/eNGpmXYfFdJs0g/0m Zu0CT1FY04j3NZ2MpFoLAGzYT4wIc3fF8RgGKigNJlO7WisNXfkB9vzEgiFZdRVHAgIo sNlWCIcJOI4zA2Sa1/hpDFSB2HDARemG+hQhNNvEkHQrdIV/RnKfyZOf4/WheAgmHoIM LmwQ== Received: by 10.68.218.33 with SMTP id pd1mr5209125pbc.42.1334845824403; Thu, 19 Apr 2012 07:30:24 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id r6sm2401487pbl.24.2012.04.19.07.30.21 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Apr 2012 07:30:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 19 Apr 2012 16:29:32 +0200 Message-Id: <1334845776-11664-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.9.3 In-Reply-To: <1334845776-11664-1-git-send-email-pbonzini@redhat.com> References: <1334845776-11664-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH 12/16] scsi: small refactoring of MMC mode-sense X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make DBD a boolean value, and force device-specific parameter to zero. Signed-off-by: Paolo Bonzini --- hw/scsi-disk.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 30ed3af..2d9ac2d 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1080,11 +1080,12 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf) { SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev); uint64_t nb_sectors; - int page, dbd, buflen, ret, page_control; + bool dbd; + int page, buflen, ret, page_control; uint8_t *p; uint8_t dev_specific_param; - dbd = r->req.cmd.buf[1] & 0x8; + dbd = (r->req.cmd.buf[1] & 0x8) != 0; page = r->req.cmd.buf[2] & 0x3f; page_control = (r->req.cmd.buf[2] & 0xc0) >> 6; DPRINTF("Mode Sense(%d) (page %d, xfer %zd, page_control %d)\n", @@ -1092,10 +1093,15 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf) memset(outbuf, 0, r->req.cmd.xfer); p = outbuf; - if (bdrv_is_read_only(s->qdev.conf.bs)) { - dev_specific_param = 0x80; /* Readonly. */ + dev_specific_param = 0x00; + if (s->qdev.type == TYPE_DISK) { + if (bdrv_is_read_only(s->qdev.conf.bs)) { + dev_specific_param |= 0x80; /* Readonly. */ + } } else { - dev_specific_param = 0x00; + /* MMC prescribes that CD/DVD drives have no block descriptors, + * and defines no device-specific parameter. */ + dbd = true; } if (r->req.cmd.buf[0] == MODE_SENSE) { @@ -1110,9 +1116,8 @@ static int scsi_disk_emulate_mode_sense(SCSIDiskReq *r, uint8_t *outbuf) p += 8; } - /* MMC prescribes that CD/DVD drives have no block descriptors. */ bdrv_get_geometry(s->qdev.conf.bs, &nb_sectors); - if (!dbd && s->qdev.type == TYPE_DISK && nb_sectors) { + if (!dbd && nb_sectors) { if (r->req.cmd.buf[0] == MODE_SENSE) { outbuf[3] = 8; /* Block descriptor length */ } else { /* MODE_SENSE_10 */