Blame view
fs/befs/endian.h
3.15 KB
b24413180
|
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4c
|
2 3 4 5 6 7 8 9 10 11 |
/* * linux/fs/befs/endian.h * * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com> * * Partially based on similar funtions in the sysv driver. */ #ifndef LINUX_BEFS_ENDIAN #define LINUX_BEFS_ENDIAN |
9a6ab769b
|
12 |
#include <asm/byteorder.h> |
1da177e4c
|
13 14 |
static inline u64 |
1151895f8
|
15 |
fs64_to_cpu(const struct super_block *sb, fs64 n) |
1da177e4c
|
16 17 |
{ if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
1151895f8
|
18 |
return le64_to_cpu((__force __le64)n); |
1da177e4c
|
19 |
else |
1151895f8
|
20 |
return be64_to_cpu((__force __be64)n); |
1da177e4c
|
21 |
} |
1151895f8
|
22 |
static inline fs64 |
1da177e4c
|
23 24 25 |
cpu_to_fs64(const struct super_block *sb, u64 n) { if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
1151895f8
|
26 |
return (__force fs64)cpu_to_le64(n); |
1da177e4c
|
27 |
else |
1151895f8
|
28 |
return (__force fs64)cpu_to_be64(n); |
1da177e4c
|
29 30 31 |
} static inline u32 |
1151895f8
|
32 |
fs32_to_cpu(const struct super_block *sb, fs32 n) |
1da177e4c
|
33 34 |
{ if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
1151895f8
|
35 |
return le32_to_cpu((__force __le32)n); |
1da177e4c
|
36 |
else |
1151895f8
|
37 |
return be32_to_cpu((__force __be32)n); |
1da177e4c
|
38 |
} |
1151895f8
|
39 |
static inline fs32 |
1da177e4c
|
40 41 42 |
cpu_to_fs32(const struct super_block *sb, u32 n) { if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
1151895f8
|
43 |
return (__force fs32)cpu_to_le32(n); |
1da177e4c
|
44 |
else |
1151895f8
|
45 |
return (__force fs32)cpu_to_be32(n); |
1da177e4c
|
46 47 48 |
} static inline u16 |
1151895f8
|
49 |
fs16_to_cpu(const struct super_block *sb, fs16 n) |
1da177e4c
|
50 51 |
{ if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
1151895f8
|
52 |
return le16_to_cpu((__force __le16)n); |
1da177e4c
|
53 |
else |
1151895f8
|
54 |
return be16_to_cpu((__force __be16)n); |
1da177e4c
|
55 |
} |
1151895f8
|
56 |
static inline fs16 |
1da177e4c
|
57 58 59 |
cpu_to_fs16(const struct super_block *sb, u16 n) { if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
1151895f8
|
60 |
return (__force fs16)cpu_to_le16(n); |
1da177e4c
|
61 |
else |
1151895f8
|
62 |
return (__force fs16)cpu_to_be16(n); |
1da177e4c
|
63 64 65 66 67 |
} /* Composite types below here */ static inline befs_block_run |
a9721f315
|
68 |
fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n) |
1da177e4c
|
69 70 71 72 |
{ befs_block_run run; if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) { |
a9721f315
|
73 74 75 |
run.allocation_group = le32_to_cpu((__force __le32)n.allocation_group); run.start = le16_to_cpu((__force __le16)n.start); run.len = le16_to_cpu((__force __le16)n.len); |
1da177e4c
|
76 |
} else { |
a9721f315
|
77 78 79 |
run.allocation_group = be32_to_cpu((__force __be32)n.allocation_group); run.start = be16_to_cpu((__force __be16)n.start); run.len = be16_to_cpu((__force __be16)n.len); |
1da177e4c
|
80 81 82 |
} return run; } |
a9721f315
|
83 |
static inline befs_disk_block_run |
1da177e4c
|
84 85 |
cpu_to_fsrun(const struct super_block *sb, befs_block_run n) { |
a9721f315
|
86 |
befs_disk_block_run run; |
1da177e4c
|
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) { run.allocation_group = cpu_to_le32(n.allocation_group); run.start = cpu_to_le16(n.start); run.len = cpu_to_le16(n.len); } else { run.allocation_group = cpu_to_be32(n.allocation_group); run.start = cpu_to_be16(n.start); run.len = cpu_to_be16(n.len); } return run; } static inline befs_data_stream |
e0e3d32bb
|
101 |
fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n) |
1da177e4c
|
102 103 104 105 106 |
{ befs_data_stream data; int i; for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i) |
e0e3d32bb
|
107 |
data.direct[i] = fsrun_to_cpu(sb, n->direct[i]); |
1da177e4c
|
108 |
|
e0e3d32bb
|
109 110 111 112 |
data.max_direct_range = fs64_to_cpu(sb, n->max_direct_range); data.indirect = fsrun_to_cpu(sb, n->indirect); data.max_indirect_range = fs64_to_cpu(sb, n->max_indirect_range); data.double_indirect = fsrun_to_cpu(sb, n->double_indirect); |
1da177e4c
|
113 |
data.max_double_indirect_range = fs64_to_cpu(sb, |
e0e3d32bb
|
114 |
n-> |
1da177e4c
|
115 |
max_double_indirect_range); |
e0e3d32bb
|
116 |
data.size = fs64_to_cpu(sb, n->size); |
1da177e4c
|
117 118 119 120 121 |
return data; } #endif //LINUX_BEFS_ENDIAN |