[PATCH] Always store trace data in big endian format
[blktrace.git] / blktrace.h
1 #ifndef BLKTRACE_H
2 #define BLKTRACE_H
3
4 #include <byteswap.h>
5 #include <asm/types.h>
6 #include <asm/byteorder.h>
7 #include "blktrace_api.h"
8
9 #define CHECK_MAGIC(t)          (((t)->magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
10 #define SUPPORTED_VERSION       (0x02)
11
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)
26 #else
27 #error "Bad arch"
28 #endif
29
30 static inline int verify_trace(struct blk_io_trace *t)
31 {
32         if (!CHECK_MAGIC(t)) {
33                 fprintf(stderr, "bad trace magic %x\n", t->magic);
34                 return 1;
35         }
36         if ((t->magic & 0xff) != SUPPORTED_VERSION) {
37                 fprintf(stderr, "unsupported trace version %x\n", 
38                         t->magic & 0xff);
39                 return 1;
40         }
41
42         return 0;
43 }
44
45 static inline void trace_to_be(struct blk_io_trace *t)
46 {
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->error        = cpu_to_be16(t->error);
55         t->pdu_len      = cpu_to_be16(t->pdu_len);
56 }
57
58 static inline void trace_to_cpu(struct blk_io_trace *t)
59 {
60         t->magic        = be32_to_cpu(t->magic);
61         t->sequence     = be32_to_cpu(t->sequence);
62         t->time         = be64_to_cpu(t->time);
63         t->sector       = be64_to_cpu(t->sector);
64         t->bytes        = be32_to_cpu(t->bytes);
65         t->action       = be32_to_cpu(t->action);
66         t->pid          = be32_to_cpu(t->pid);
67         t->error        = be16_to_cpu(t->error);
68         t->pdu_len      = be16_to_cpu(t->pdu_len);
69 }
70
71 #endif