From patchwork Fri Oct 11 18:17:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 282916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A266D2C0199 for ; Sat, 12 Oct 2013 06:16:00 +1100 (EST) Received: from localhost ([::1]:55820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUhOT-0004ys-HG for incoming@patchwork.ozlabs.org; Fri, 11 Oct 2013 14:24:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUhI4-0006YA-7W for qemu-devel@nongnu.org; Fri, 11 Oct 2013 14:18:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VUhHy-0007MG-2N for qemu-devel@nongnu.org; Fri, 11 Oct 2013 14:18:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUhHx-0007MA-Pk for qemu-devel@nongnu.org; Fri, 11 Oct 2013 14:18:14 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9BIIDu2020606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 11 Oct 2013 14:18:13 -0400 Received: from localhost ([10.3.112.6]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r9BIIBNP015557 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Fri, 11 Oct 2013 14:18:12 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Fri, 11 Oct 2013 14:17:32 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v7 12/19] block: vhdx - remove BAT file offset bit shifting 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 Bit shifting can be fun, but in this case it was unnecessary. The upper 44 bits of the 64-bit BAT entry is specifies the File Offset, so we shifted the bits to get access to the value. However, per the spec the value is in MB. So we dutifully shifted back to the left by 20 bits, to convert to a true uint64_t file offset. This replaces those steps with just a bit mask, to get rid of the lower 20 bits instead. Signed-off-by: Jeff Cody --- block/vhdx.c | 6 ++---- block/vhdx.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 4c16532..294f503 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -985,7 +985,7 @@ static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num, sinfo->bytes_avail = sinfo->sectors_avail << s->logical_sector_size_bits; - sinfo->file_offset = s->bat[sinfo->bat_idx] >> VHDX_BAT_FILE_OFF_BITS; + sinfo->file_offset = s->bat[sinfo->bat_idx] & VHDX_BAT_FILE_OFF_MASK; sinfo->block_offset = block_offset << s->logical_sector_size_bits; @@ -999,7 +999,6 @@ static void vhdx_block_translate(BDRVVHDXState *s, int64_t sector_num, * in the block, and add in the payload data block offset * in the file, in bytes, to get the final read address */ - sinfo->file_offset <<= 20; /* now in bytes, rather than 1MB units */ sinfo->file_offset += sinfo->block_offset; } @@ -1098,8 +1097,7 @@ static void vhdx_update_bat_table_entry(BlockDriverState *bs, BDRVVHDXState *s, { /* The BAT entry is a uint64, with 44 bits for the file offset in units of * 1MB, and 3 bits for the block state. */ - s->bat[sinfo->bat_idx] = ((sinfo->file_offset>>20) << - VHDX_BAT_FILE_OFF_BITS); + s->bat[sinfo->bat_idx] = sinfo->file_offset; s->bat[sinfo->bat_idx] |= state & VHDX_BAT_STATE_BIT_MASK; diff --git a/block/vhdx.h b/block/vhdx.h index f331548..d3598e0 100644 --- a/block/vhdx.h +++ b/block/vhdx.h @@ -229,7 +229,6 @@ typedef struct QEMU_PACKED VHDXLogDataSector { /* upper 44 bits are the file offset in 1MB units lower 3 bits are the state other bits are reserved */ #define VHDX_BAT_STATE_BIT_MASK 0x07 -#define VHDX_BAT_FILE_OFF_BITS (64 - 44) #define VHDX_BAT_FILE_OFF_MASK 0xFFFFFFFFFFF00000 /* upper 44 bits */ typedef uint64_t VHDXBatEntry;