blob: 27223878ba9fc9b9ba354a887837653ecdd170f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/befs/endian.h
3 *
4 * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
5 *
6 * Partially based on similar funtions in the sysv driver.
7 */
8
9#ifndef LINUX_BEFS_ENDIAN
10#define LINUX_BEFS_ENDIAN
11
Harvey Harrison9a6ab762008-05-16 11:20:25 -070012#include <asm/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14static inline u64
Al Viro11518952005-12-24 01:32:03 -050015fs64_to_cpu(const struct super_block *sb, fs64 n)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016{
17 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
Al Viro11518952005-12-24 01:32:03 -050018 return le64_to_cpu((__force __le64)n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 else
Al Viro11518952005-12-24 01:32:03 -050020 return be64_to_cpu((__force __be64)n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021}
22
Al Viro11518952005-12-24 01:32:03 -050023static inline fs64
Linus Torvalds1da177e2005-04-16 15:20:36 -070024cpu_to_fs64(const struct super_block *sb, u64 n)
25{
26 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
Al Viro11518952005-12-24 01:32:03 -050027 return (__force fs64)cpu_to_le64(n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 else
Al Viro11518952005-12-24 01:32:03 -050029 return (__force fs64)cpu_to_be64(n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030}
31
32static inline u32
Al Viro11518952005-12-24 01:32:03 -050033fs32_to_cpu(const struct super_block *sb, fs32 n)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
35 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
Al Viro11518952005-12-24 01:32:03 -050036 return le32_to_cpu((__force __le32)n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 else
Al Viro11518952005-12-24 01:32:03 -050038 return be32_to_cpu((__force __be32)n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
Al Viro11518952005-12-24 01:32:03 -050041static inline fs32
Linus Torvalds1da177e2005-04-16 15:20:36 -070042cpu_to_fs32(const struct super_block *sb, u32 n)
43{
44 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
Al Viro11518952005-12-24 01:32:03 -050045 return (__force fs32)cpu_to_le32(n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 else
Al Viro11518952005-12-24 01:32:03 -050047 return (__force fs32)cpu_to_be32(n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
50static inline u16
Al Viro11518952005-12-24 01:32:03 -050051fs16_to_cpu(const struct super_block *sb, fs16 n)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
53 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
Al Viro11518952005-12-24 01:32:03 -050054 return le16_to_cpu((__force __le16)n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 else
Al Viro11518952005-12-24 01:32:03 -050056 return be16_to_cpu((__force __be16)n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Al Viro11518952005-12-24 01:32:03 -050059static inline fs16
Linus Torvalds1da177e2005-04-16 15:20:36 -070060cpu_to_fs16(const struct super_block *sb, u16 n)
61{
62 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
Al Viro11518952005-12-24 01:32:03 -050063 return (__force fs16)cpu_to_le16(n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 else
Al Viro11518952005-12-24 01:32:03 -050065 return (__force fs16)cpu_to_be16(n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
68/* Composite types below here */
69
70static inline befs_block_run
Al Viroa9721f32005-12-24 14:28:55 -050071fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
73 befs_block_run run;
74
75 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
Al Viroa9721f32005-12-24 14:28:55 -050076 run.allocation_group = le32_to_cpu((__force __le32)n.allocation_group);
77 run.start = le16_to_cpu((__force __le16)n.start);
78 run.len = le16_to_cpu((__force __le16)n.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 } else {
Al Viroa9721f32005-12-24 14:28:55 -050080 run.allocation_group = be32_to_cpu((__force __be32)n.allocation_group);
81 run.start = be16_to_cpu((__force __be16)n.start);
82 run.len = be16_to_cpu((__force __be16)n.len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
84 return run;
85}
86
Al Viroa9721f32005-12-24 14:28:55 -050087static inline befs_disk_block_run
Linus Torvalds1da177e2005-04-16 15:20:36 -070088cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
89{
Al Viroa9721f32005-12-24 14:28:55 -050090 befs_disk_block_run run;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
93 run.allocation_group = cpu_to_le32(n.allocation_group);
94 run.start = cpu_to_le16(n.start);
95 run.len = cpu_to_le16(n.len);
96 } else {
97 run.allocation_group = cpu_to_be32(n.allocation_group);
98 run.start = cpu_to_be16(n.start);
99 run.len = cpu_to_be16(n.len);
100 }
101 return run;
102}
103
104static inline befs_data_stream
Jesper Juhle0e3d322011-01-12 17:00:26 -0800105fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 befs_data_stream data;
108 int i;
109
110 for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i)
Jesper Juhle0e3d322011-01-12 17:00:26 -0800111 data.direct[i] = fsrun_to_cpu(sb, n->direct[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Jesper Juhle0e3d322011-01-12 17:00:26 -0800113 data.max_direct_range = fs64_to_cpu(sb, n->max_direct_range);
114 data.indirect = fsrun_to_cpu(sb, n->indirect);
115 data.max_indirect_range = fs64_to_cpu(sb, n->max_indirect_range);
116 data.double_indirect = fsrun_to_cpu(sb, n->double_indirect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 data.max_double_indirect_range = fs64_to_cpu(sb,
Jesper Juhle0e3d322011-01-12 17:00:26 -0800118 n->
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 max_double_indirect_range);
Jesper Juhle0e3d322011-01-12 17:00:26 -0800120 data.size = fs64_to_cpu(sb, n->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 return data;
123}
124
125#endif //LINUX_BEFS_ENDIAN