[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 29/36] block: vhdx - remove BAT file offset bit shift
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL 29/36] block: vhdx - remove BAT file offset bit shifting |
Date: |
Thu, 7 Nov 2013 14:12:37 +0100 |
From: Jeff Cody <address@hidden>
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 <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
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 050f071..158edab 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;
--
1.8.3.1
- [Qemu-devel] [PULL 08/36] block: qemu-iotests, removes duplicate double quotes in 039, (continued)
- [Qemu-devel] [PULL 08/36] block: qemu-iotests, removes duplicate double quotes in 039, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 03/36] block/raw-posix: fix FreeBSD compilation, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 12/36] libqtest: rename qmp() to qmp_discard_response(), Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 13/36] libqtest: add qmp(fmt, ...) -> QDict* function, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 01/36] qapi: Fix comment for create-type to match code., Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 05/36] block: qemu-iotests, fix _make_test_img() to work with spaced pathnames, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 26/36] block: vhdx - add region overlap detection for image files, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 22/36] block: vhdx - break endian translation functions out, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 33/36] block: vhdx - add .bdrv_create() support, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 25/36] block: vhdx - log parsing, replay, and flush support, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 29/36] block: vhdx - remove BAT file offset bit shifting,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL 27/36] block: vhdx - add log write support, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 24/36] block: vhdx code movement - move vhdx_close() above vhdx_open(), Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 19/36] block: vhdx - add header update capability., Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 21/36] block: vhdx - log support struct and defines, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 23/36] block: vhdx - update log guid in header, and first write tracker, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 02/36] qemu-iotests: Filter out actual image size in 067, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 30/36] block: vhdx - move more endian translations to vhdx-endian.c, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 31/36] block: vhdx - break out code operations to functions, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 32/36] block: vhdx - fix comment typos in header, fix incorrect struct fields, Stefan Hajnoczi, 2013/11/07
- [Qemu-devel] [PULL 36/36] block: vhdx qemu-iotest - log replay of data sector, Stefan Hajnoczi, 2013/11/07