Import 2.3.18pre1
[davej-history.git] / fs / udf / udfend.h
blob906a619bc2d9a1be1f25edf3dca7904cb61bba9b
1 #ifndef __UDF_ENDIAN_H
2 #define __UDF_ENDIAN_H
4 #ifndef __KERNEL__
6 #if __BYTE_ORDER == 0
8 #error "__BYTE_ORDER must be defined"
10 #elif __BYTE_ORDER == __BIG_ENDIAN
12 #define le16_to_cpu(x) \
13 ((Uint16)((((Uint16)(x) & 0x00FFU) << 8) | \
14 (((Uint16)(x) & 0xFF00U) >> 8)))
16 #define le32_to_cpu(x) \
17 ((Uint32)((((Uint32)(x) & 0x000000FFU) << 24) | \
18 (((Uint32)(x) & 0x0000FF00U) << 8) | \
19 (((Uint32)(x) & 0x00FF0000U) >> 8) | \
20 (((Uint32)(x) & 0xFF000000U) >> 24)))
22 #define le64_to_cpu(x) \
23 ((Uint64)((((Uint64)(x) & 0x00000000000000FFULL) << 56) | \
24 (((Uint64)(x) & 0x000000000000FF00ULL) << 40) | \
25 (((Uint64)(x) & 0x0000000000FF0000ULL) << 24) | \
26 (((Uint64)(x) & 0x00000000FF000000ULL) << 8) | \
27 (((Uint64)(x) & 0x000000FF00000000ULL) >> 8) | \
28 (((Uint64)(x) & 0x0000FF0000000000ULL) >> 24) | \
29 (((Uint64)(x) & 0x00FF000000000000ULL) >> 40) | \
30 (((Uint64)(x) & 0xFF00000000000000ULL) >> 56)))
32 #define cpu_to_le16(x) (le16_to_cpu(x))
33 #define cpu_to_le32(x) (le32_to_cpu(x))
34 #define cpu_to_le64(x) (le64_to_cpu(x))
36 #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
38 #define le16_to_cpu(x) (x)
39 #define le32_to_cpu(x) (x)
40 #define le64_to_cpu(x) (x)
41 #define cpu_to_le16(x) (x)
42 #define cpu_to_le32(x) (x)
43 #define cpu_to_le64(x) (x)
45 #endif
47 #endif
49 #ifdef __KERNEL__
50 #include <linux/string.h>
51 #endif
53 static inline lb_addr lelb_to_cpu(lb_addr in)
55 lb_addr out;
56 out.logicalBlockNum = le32_to_cpu(in.logicalBlockNum);
57 out.partitionReferenceNum = le16_to_cpu(in.partitionReferenceNum);
58 return out;
61 static inline lb_addr cpu_to_lelb(lb_addr in)
63 lb_addr out;
64 out.logicalBlockNum = cpu_to_le32(in.logicalBlockNum);
65 out.partitionReferenceNum = cpu_to_le16(in.partitionReferenceNum);
66 return out;
69 static inline timestamp lets_to_cpu(timestamp in)
71 timestamp out;
72 memcpy(&out, &in, sizeof(timestamp));
73 out.typeAndTimezone = le16_to_cpu(in.typeAndTimezone);
74 out.year = le16_to_cpu(in.year);
75 return out;
78 static inline long_ad lela_to_cpu(long_ad in)
80 long_ad out;
81 out.extLength = le32_to_cpu(in.extLength);
82 out.extLocation = lelb_to_cpu(in.extLocation);
83 return out;
86 static inline long_ad cpu_to_lela(long_ad in)
88 long_ad out;
89 out.extLength = cpu_to_le32(in.extLength);
90 out.extLocation = cpu_to_lelb(in.extLocation);
91 return out;
94 static inline extent_ad leea_to_cpu(extent_ad in)
96 extent_ad out;
97 out.extLength = le32_to_cpu(in.extLength);
98 out.extLocation = le32_to_cpu(in.extLocation);
99 return out;
102 static inline timestamp cpu_to_lets(timestamp in)
104 timestamp out;
105 memcpy(&out, &in, sizeof(timestamp));
106 out.typeAndTimezone = cpu_to_le16(in.typeAndTimezone);
107 out.year = cpu_to_le16(in.year);
108 return out;
111 #endif /* __UDF_ENDIAN_H */