Skip to contentSkip to conversation

bswap.h: add cpu_to_be64wu()

PATCH Applied Aurelien Jarno 2 participants 3 messages Jan 1, 2011 – Jan 10, 2011 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bswap.h: add cpu_to_be64wu()

---
 bswap.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
bswap.h +15 -0
index 20caae6..82a7951 100644
@@ -144,6 +144,7 @@ CPU_CONVERT(le, 64, uint64_t)
 
 #define cpu_to_be16wu(p, v) cpu_to_be16w(p, v)
 #define cpu_to_be32wu(p, v) cpu_to_be32w(p, v)
+#define cpu_to_be64wu(p, v) cpu_to_be64w(p, v)
 
 #else
 
@@ -201,6 +202,20 @@ static inline void cpu_to_be32wu(uint32_t *p, uint32_t v)
     p1[3] = v & 0xff;
 }
 
+static inline void cpu_to_be64wu(uint64_t *p, uint64_t v)
+{
+    uint8_t *p1 = (uint8_t *)p;
+
+    p1[0] = v >> 56;
+    p1[1] = v >> 48;
+    p1[2] = v >> 40;
+    p1[3] = v >> 32;
+    p1[4] = v >> 24;
+    p1[5] = v >> 16;
+    p1[6] = v >> 8;
+    p1[7] = v & 0xff;
+}
+
 #endif
 
 #ifdef HOST_WORDS_BIGENDIAN
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 2/2 qcow2: fix unaligned access

cpu_to_be64w() is called with an obviously non-aligned pointer. Use cpu_to_be64wu() instead. It fixes unaligned accesses errors on IA64 hosts.

---
 block/qcow2-cluster.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
block/qcow2-cluster.c +1 -1
index 6928c63..c3ef550 100644
@@ -81,7 +81,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size)
     /* set new table */
     BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_ACTIVATE_TABLE);
     cpu_to_be32w((uint32_t*)data, new_l1_size);
-    cpu_to_be64w((uint64_t*)(data + 4), new_l1_table_offset);
+    cpu_to_be64wu((uint64_t*)(data + 4), new_l1_table_offset);
     ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_size), data,sizeof(data));
     if (ret < 0) {
         goto fail;
Signature · 1 line
1.7.2.3
Applied
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] qcow2: fix unaligned access

Am 01.01.2011 21:50, schrieb Aurelien Jarno:

Quoted 6 lines

cpu_to_be64w() is called with an obviously non-aligned pointer. Use cpu_to_be64wu() instead. It fixes unaligned accesses errors on IA64 hosts.

Thanks, applied to the block branch.

Kevin