2 * linux/fs/befs/endian.h
4 * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
6 * Partially based on similar funtions in the sysv driver.
9 #ifndef LINUX_BEFS_ENDIAN
10 #define LINUX_BEFS_ENDIAN
12 #include <linux/byteorder/generic.h>
16 fs64_to_cpu(const struct super_block
*sb
, u64 n
)
18 if (BEFS_SB(sb
)->byte_order
== BEFS_BYTESEX_LE
)
19 return le64_to_cpu(n
);
21 return be64_to_cpu(n
);
25 cpu_to_fs64(const struct super_block
*sb
, u64 n
)
27 if (BEFS_SB(sb
)->byte_order
== BEFS_BYTESEX_LE
)
28 return cpu_to_le64(n
);
30 return cpu_to_be64(n
);
34 fs32_to_cpu(const struct super_block
*sb
, u32 n
)
36 if (BEFS_SB(sb
)->byte_order
== BEFS_BYTESEX_LE
)
37 return le32_to_cpu(n
);
39 return be32_to_cpu(n
);
43 cpu_to_fs32(const struct super_block
*sb
, u32 n
)
45 if (BEFS_SB(sb
)->byte_order
== BEFS_BYTESEX_LE
)
46 return cpu_to_le32(n
);
48 return cpu_to_be32(n
);
52 fs16_to_cpu(const struct super_block
*sb
, u16 n
)
54 if (BEFS_SB(sb
)->byte_order
== BEFS_BYTESEX_LE
)
55 return le16_to_cpu(n
);
57 return be16_to_cpu(n
);
61 cpu_to_fs16(const struct super_block
*sb
, u16 n
)
63 if (BEFS_SB(sb
)->byte_order
== BEFS_BYTESEX_LE
)
64 return cpu_to_le16(n
);
66 return cpu_to_be16(n
);
69 /* Composite types below here */
71 static inline befs_block_run
72 fsrun_to_cpu(const struct super_block
*sb
, befs_block_run n
)
76 if (BEFS_SB(sb
)->byte_order
== BEFS_BYTESEX_LE
) {
77 run
.allocation_group
= le32_to_cpu(n
.allocation_group
);
78 run
.start
= le16_to_cpu(n
.start
);
79 run
.len
= le16_to_cpu(n
.len
);
81 run
.allocation_group
= be32_to_cpu(n
.allocation_group
);
82 run
.start
= be16_to_cpu(n
.start
);
83 run
.len
= be16_to_cpu(n
.len
);
88 static inline befs_block_run
89 cpu_to_fsrun(const struct super_block
*sb
, befs_block_run n
)
93 if (BEFS_SB(sb
)->byte_order
== BEFS_BYTESEX_LE
) {
94 run
.allocation_group
= cpu_to_le32(n
.allocation_group
);
95 run
.start
= cpu_to_le16(n
.start
);
96 run
.len
= cpu_to_le16(n
.len
);
98 run
.allocation_group
= cpu_to_be32(n
.allocation_group
);
99 run
.start
= cpu_to_be16(n
.start
);
100 run
.len
= cpu_to_be16(n
.len
);
105 static inline befs_data_stream
106 fsds_to_cpu(const struct super_block
*sb
, befs_data_stream n
)
108 befs_data_stream data
;
111 for (i
= 0; i
< BEFS_NUM_DIRECT_BLOCKS
; ++i
)
112 data
.direct
[i
] = fsrun_to_cpu(sb
, n
.direct
[i
]);
114 data
.max_direct_range
= fs64_to_cpu(sb
, n
.max_direct_range
);
115 data
.indirect
= fsrun_to_cpu(sb
, n
.indirect
);
116 data
.max_indirect_range
= fs64_to_cpu(sb
, n
.max_indirect_range
);
117 data
.double_indirect
= fsrun_to_cpu(sb
, n
.double_indirect
);
118 data
.max_double_indirect_range
= fs64_to_cpu(sb
,
120 max_double_indirect_range
);
121 data
.size
= fs64_to_cpu(sb
, n
.size
);
126 #endif //LINUX_BEFS_ENDIAN