Skip to content

Commit

Permalink
block: vhdx - remove BAT file offset bit shifting
Browse files Browse the repository at this point in the history
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 <jcody@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
codyprime authored and stefanhaRH committed Nov 7, 2013
1 parent d92aa88 commit 0b7da09
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
6 changes: 2 additions & 4 deletions block/vhdx.c
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion block/vhdx.h
Expand Up @@ -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;

Expand Down

0 comments on commit 0b7da09

Please sign in to comment.