yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
0a122b
From 71ef58e93b4a9aafa838117bdaeebc72c2b826c3 Mon Sep 17 00:00:00 2001
0a122b
From: Jeffrey Cody <jcody@redhat.com>
0a122b
Date: Wed, 20 Nov 2013 19:44:02 +0100
0a122b
Subject: [PATCH 19/25] block: vhdx - move more endian translations to vhdx-endian.c
0a122b
0a122b
RH-Author: Jeffrey Cody <jcody@redhat.com>
0a122b
Message-id: <e18245e69af41489c6172765a45640076f8b2379.1384975172.git.jcody@redhat.com>
0a122b
Patchwork-id: 55812
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH 19/26] block: vhdx - move more endian translations to vhdx-endian.c
0a122b
Bugzilla: 879234
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
0a122b
In preparation for vhdx_create(), move more endian translation
0a122b
functions out to vhdx-endian.c.
0a122b
0a122b
Signed-off-by: Jeff Cody <jcody@redhat.com>
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
(cherry picked from commit c325ee1de84dde5b2a90c30e1b788defa31c5d53)
0a122b
---
0a122b
 block/vhdx-endian.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++
0a122b
 block/vhdx.c        | 20 +++-----------
0a122b
 block/vhdx.h        |  9 ++++++-
0a122b
 3 files changed, 87 insertions(+), 17 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block/vhdx-endian.c |   75 +++++++++++++++++++++++++++++++++++++++++++++++++++
0a122b
 block/vhdx.c        |   20 +++-----------
0a122b
 block/vhdx.h        |    9 +++++-
0a122b
 3 files changed, 87 insertions(+), 17 deletions(-)
0a122b
0a122b
diff --git a/block/vhdx-endian.c b/block/vhdx-endian.c
0a122b
index 3e93e63..fe879ed 100644
0a122b
--- a/block/vhdx-endian.c
0a122b
+++ b/block/vhdx-endian.c
0a122b
@@ -139,3 +139,78 @@ void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr)
0a122b
 }
0a122b
 
0a122b
 
0a122b
+/* Region table entries */
0a122b
+void vhdx_region_header_le_import(VHDXRegionTableHeader *hdr)
0a122b
+{
0a122b
+    assert(hdr != NULL);
0a122b
+
0a122b
+    le32_to_cpus(&hdr->signature);
0a122b
+    le32_to_cpus(&hdr->checksum);
0a122b
+    le32_to_cpus(&hdr->entry_count);
0a122b
+}
0a122b
+
0a122b
+void vhdx_region_header_le_export(VHDXRegionTableHeader *hdr)
0a122b
+{
0a122b
+    assert(hdr != NULL);
0a122b
+
0a122b
+    cpu_to_le32s(&hdr->signature);
0a122b
+    cpu_to_le32s(&hdr->checksum);
0a122b
+    cpu_to_le32s(&hdr->entry_count);
0a122b
+}
0a122b
+
0a122b
+void vhdx_region_entry_le_import(VHDXRegionTableEntry *e)
0a122b
+{
0a122b
+    assert(e != NULL);
0a122b
+
0a122b
+    leguid_to_cpus(&e->guid);
0a122b
+    le64_to_cpus(&e->file_offset);
0a122b
+    le32_to_cpus(&e->length);
0a122b
+    le32_to_cpus(&e->data_bits);
0a122b
+}
0a122b
+
0a122b
+void vhdx_region_entry_le_export(VHDXRegionTableEntry *e)
0a122b
+{
0a122b
+    assert(e != NULL);
0a122b
+
0a122b
+    cpu_to_leguids(&e->guid);
0a122b
+    cpu_to_le64s(&e->file_offset);
0a122b
+    cpu_to_le32s(&e->length);
0a122b
+    cpu_to_le32s(&e->data_bits);
0a122b
+}
0a122b
+
0a122b
+
0a122b
+/* Metadata headers & table */
0a122b
+void vhdx_metadata_header_le_import(VHDXMetadataTableHeader *hdr)
0a122b
+{
0a122b
+    assert(hdr != NULL);
0a122b
+
0a122b
+    le64_to_cpus(&hdr->signature);
0a122b
+    le16_to_cpus(&hdr->entry_count);
0a122b
+}
0a122b
+
0a122b
+void vhdx_metadata_header_le_export(VHDXMetadataTableHeader *hdr)
0a122b
+{
0a122b
+    assert(hdr != NULL);
0a122b
+
0a122b
+    cpu_to_le64s(&hdr->signature);
0a122b
+    cpu_to_le16s(&hdr->entry_count);
0a122b
+}
0a122b
+
0a122b
+void vhdx_metadata_entry_le_import(VHDXMetadataTableEntry *e)
0a122b
+{
0a122b
+    assert(e != NULL);
0a122b
+
0a122b
+    leguid_to_cpus(&e->item_id);
0a122b
+    le32_to_cpus(&e->offset);
0a122b
+    le32_to_cpus(&e->length);
0a122b
+    le32_to_cpus(&e->data_bits);
0a122b
+}
0a122b
+void vhdx_metadata_entry_le_export(VHDXMetadataTableEntry *e)
0a122b
+{
0a122b
+    assert(e != NULL);
0a122b
+
0a122b
+    cpu_to_leguids(&e->item_id);
0a122b
+    cpu_to_le32s(&e->offset);
0a122b
+    cpu_to_le32s(&e->length);
0a122b
+    cpu_to_le32s(&e->data_bits);
0a122b
+}
0a122b
diff --git a/block/vhdx.c b/block/vhdx.c
0a122b
index 97099aa..9d51176 100644
0a122b
--- a/block/vhdx.c
0a122b
+++ b/block/vhdx.c
0a122b
@@ -472,10 +472,7 @@ static int vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s)
0a122b
         goto fail;
0a122b
     }
0a122b
     memcpy(&s->rt, buffer, sizeof(s->rt));
0a122b
-    le32_to_cpus(&s->rt.signature);
0a122b
-    le32_to_cpus(&s->rt.checksum);
0a122b
-    le32_to_cpus(&s->rt.entry_count);
0a122b
-    le32_to_cpus(&s->rt.reserved);
0a122b
+    vhdx_region_header_le_import(&s->rt);
0a122b
     offset += sizeof(s->rt);
0a122b
 
0a122b
     if (!vhdx_checksum_is_valid(buffer, VHDX_HEADER_BLOCK_SIZE, 4) ||
0a122b
@@ -494,10 +491,7 @@ static int vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s)
0a122b
         memcpy(&rt_entry, buffer + offset, sizeof(rt_entry));
0a122b
         offset += sizeof(rt_entry);
0a122b
 
0a122b
-        leguid_to_cpus(&rt_entry.guid);
0a122b
-        le64_to_cpus(&rt_entry.file_offset);
0a122b
-        le32_to_cpus(&rt_entry.length);
0a122b
-        le32_to_cpus(&rt_entry.data_bits);
0a122b
+        vhdx_region_entry_le_import(&rt_entry);
0a122b
 
0a122b
         /* check for region overlap between these entries, and any
0a122b
          * other memory regions in the file */
0a122b
@@ -587,9 +581,7 @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s)
0a122b
     memcpy(&s->metadata_hdr, buffer, sizeof(s->metadata_hdr));
0a122b
     offset += sizeof(s->metadata_hdr);
0a122b
 
0a122b
-    le64_to_cpus(&s->metadata_hdr.signature);
0a122b
-    le16_to_cpus(&s->metadata_hdr.reserved);
0a122b
-    le16_to_cpus(&s->metadata_hdr.entry_count);
0a122b
+    vhdx_metadata_header_le_import(&s->metadata_hdr);
0a122b
 
0a122b
     if (memcmp(&s->metadata_hdr.signature, "metadata", 8)) {
0a122b
         ret = -EINVAL;
0a122b
@@ -608,11 +600,7 @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s)
0a122b
         memcpy(&md_entry, buffer + offset, sizeof(md_entry));
0a122b
         offset += sizeof(md_entry);
0a122b
 
0a122b
-        leguid_to_cpus(&md_entry.item_id);
0a122b
-        le32_to_cpus(&md_entry.offset);
0a122b
-        le32_to_cpus(&md_entry.length);
0a122b
-        le32_to_cpus(&md_entry.data_bits);
0a122b
-        le32_to_cpus(&md_entry.reserved2);
0a122b
+        vhdx_metadata_entry_le_import(&md_entry);
0a122b
 
0a122b
         if (guid_eq(md_entry.item_id, file_param_guid)) {
0a122b
             if (s->metadata_entries.present & META_FILE_PARAMETER_PRESENT) {
0a122b
diff --git a/block/vhdx.h b/block/vhdx.h
0a122b
index 7deb7fd..0acad37 100644
0a122b
--- a/block/vhdx.h
0a122b
+++ b/block/vhdx.h
0a122b
@@ -421,7 +421,14 @@ void vhdx_log_desc_le_export(VHDXLogDescriptor *d);
0a122b
 void vhdx_log_data_le_export(VHDXLogDataSector *d);
0a122b
 void vhdx_log_entry_hdr_le_import(VHDXLogEntryHeader *hdr);
0a122b
 void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr);
0a122b
-
0a122b
+void vhdx_region_header_le_import(VHDXRegionTableHeader *hdr);
0a122b
+void vhdx_region_header_le_export(VHDXRegionTableHeader *hdr);
0a122b
+void vhdx_region_entry_le_import(VHDXRegionTableEntry *e);
0a122b
+void vhdx_region_entry_le_export(VHDXRegionTableEntry *e);
0a122b
+void vhdx_metadata_header_le_import(VHDXMetadataTableHeader *hdr);
0a122b
+void vhdx_metadata_header_le_export(VHDXMetadataTableHeader *hdr);
0a122b
+void vhdx_metadata_entry_le_import(VHDXMetadataTableEntry *e);
0a122b
+void vhdx_metadata_entry_le_export(VHDXMetadataTableEntry *e);
0a122b
 int vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s);
0a122b
 
0a122b
 #endif
0a122b
-- 
0a122b
1.7.1
0a122b