diff mbox

[-V3,15/32] virtio-9p: Use little endian format on virtio

Message ID 1269535420-31206-16-git-send-email-aneesh.kumar@linux.vnet.ibm.com
State New
Headers show

Commit Message

Aneesh Kumar K.V March 25, 2010, 4:43 p.m. UTC
We need to use platform independent data format as
part of protocol data. 9P uses little endian format
on wire

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 hw/virtio-9p.c |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index e095916..e8a9eeb 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -426,23 +426,32 @@  static size_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     for (i = 0; fmt[i]; i++) {
 	switch (fmt[i]) {
 	case 'b': {
-	    int8_t *valp = va_arg(ap, int8_t *);
+	    uint8_t *valp = va_arg(ap, uint8_t *);
 	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
 	    break;
 	}
 	case 'w': {
-	    int16_t *valp = va_arg(ap, int16_t *);
-	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    uint16_t val, *valp;
+	    valp = va_arg(ap, uint16_t *);
+	    val = le16_to_cpupu(valp);
+	    offset += pdu_unpack(&val, pdu, offset, sizeof(val));
+	    *valp = val;
 	    break;
 	}
 	case 'd': {
-	    int32_t *valp = va_arg(ap, int32_t *);
-	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    uint32_t val, *valp;
+	    valp = va_arg(ap, uint32_t *);
+	    val = le32_to_cpupu(valp);
+	    offset += pdu_unpack(&val, pdu, offset, sizeof(val));
+	    *valp = val;
 	    break;
 	}
 	case 'q': {
-	    int64_t *valp = va_arg(ap, int64_t *);
-	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    uint64_t val, *valp;
+	    valp = va_arg(ap, uint64_t *);
+	    val = le64_to_cpup(valp);
+	    offset += pdu_unpack(&val, pdu, offset, sizeof(val));
+	    *valp = val;
 	    break;
 	}
 	case 'v': {
@@ -498,22 +507,25 @@  static size_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     for (i = 0; fmt[i]; i++) {
 	switch (fmt[i]) {
 	case 'b': {
-	    int8_t val = va_arg(ap, int);
+	    uint8_t val = va_arg(ap, int);
 	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
 	    break;
 	}
 	case 'w': {
-	    int16_t val = va_arg(ap, int);
+	    uint16_t val;
+	    cpu_to_le16w(&val, va_arg(ap, int));
 	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
 	    break;
 	}
 	case 'd': {
-	    int32_t val = va_arg(ap, int);
+	    uint32_t val;
+	    cpu_to_le32w(&val, va_arg(ap, uint32_t));
 	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
 	    break;
 	}
 	case 'q': {
-	    int64_t val = va_arg(ap, int64_t);
+	    uint64_t val;
+	    cpu_to_le64w(&val, va_arg(ap, uint64_t));
 	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
 	    break;
 	}