6 #include <asm/byteorder.h>
7 #include "blktrace_api.h"
9 #define CHECK_MAGIC(t) (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
10 #define SUPPORTED_VERSION (0x04)
12 #if defined(__LITTLE_ENDIAN_BITFIELD)
13 #define be16_to_cpu(x) __bswap_16(x)
14 #define be32_to_cpu(x) __bswap_32(x)
15 #define be64_to_cpu(x) __bswap_64(x)
16 #define cpu_to_be16(x) __bswap_16(x)
17 #define cpu_to_be32(x) __bswap_32(x)
18 #define cpu_to_be64(x) __bswap_64(x)
19 #elif defined(__BIG_ENDIAN_BITFIELD)
20 #define be16_to_cpu(x) (x)
21 #define be32_to_cpu(x) (x)
22 #define be64_to_cpu(x) (x)
23 #define cpu_to_be16(x) (x)
24 #define cpu_to_be32(x) (x)
25 #define cpu_to_be64(x) (x)
30 static inline int verify_trace(struct blk_io_trace *t)
32 if (!CHECK_MAGIC(t)) {
33 fprintf(stderr, "bad trace magic %x\n", t->magic);
36 if ((t->magic & 0xff) != SUPPORTED_VERSION) {
37 fprintf(stderr, "unsupported trace version %x\n",
45 static inline void trace_to_be(struct blk_io_trace *t)
47 t->magic = cpu_to_be32(t->magic);
48 t->sequence = cpu_to_be32(t->sequence);
49 t->time = cpu_to_be64(t->time);
50 t->sector = cpu_to_be64(t->sector);
51 t->bytes = cpu_to_be32(t->bytes);
52 t->action = cpu_to_be32(t->action);
53 t->pid = cpu_to_be32(t->pid);
54 t->cpu = cpu_to_be32(t->cpu);
55 t->error = cpu_to_be16(t->error);
56 t->pdu_len = cpu_to_be16(t->pdu_len);
57 t->device = cpu_to_be32(t->device);
58 /* t->comm is a string (endian neutral) */
61 static inline void trace_to_cpu(struct blk_io_trace *t)
63 t->magic = be32_to_cpu(t->magic);
64 t->sequence = be32_to_cpu(t->sequence);
65 t->time = be64_to_cpu(t->time);
66 t->sector = be64_to_cpu(t->sector);
67 t->bytes = be32_to_cpu(t->bytes);
68 t->action = be32_to_cpu(t->action);
69 t->pid = be32_to_cpu(t->pid);
70 t->cpu = be32_to_cpu(t->cpu);
71 t->error = be16_to_cpu(t->error);
72 t->pdu_len = be16_to_cpu(t->pdu_len);
73 t->device = be32_to_cpu(t->device);
74 /* t->comm is a string (endian neutral) */