Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/befs/endian.h |
| 4 | * |
| 5 | * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com> |
| 6 | * |
| 7 | * Partially based on similar funtions in the sysv driver. |
| 8 | */ |
| 9 | |
| 10 | #ifndef LINUX_BEFS_ENDIAN |
| 11 | #define LINUX_BEFS_ENDIAN |
| 12 | |
Harvey Harrison | 9a6ab76 | 2008-05-16 11:20:25 -0700 | [diff] [blame] | 13 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | static inline u64 |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 16 | fs64_to_cpu(const struct super_block *sb, fs64 n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | { |
| 18 | if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 19 | return le64_to_cpu((__force __le64)n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | else |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 21 | return be64_to_cpu((__force __be64)n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 24 | static inline fs64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | cpu_to_fs64(const struct super_block *sb, u64 n) |
| 26 | { |
| 27 | if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 28 | return (__force fs64)cpu_to_le64(n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | else |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 30 | return (__force fs64)cpu_to_be64(n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static inline u32 |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 34 | fs32_to_cpu(const struct super_block *sb, fs32 n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | { |
| 36 | if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 37 | return le32_to_cpu((__force __le32)n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | else |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 39 | return be32_to_cpu((__force __be32)n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 42 | static inline fs32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | cpu_to_fs32(const struct super_block *sb, u32 n) |
| 44 | { |
| 45 | if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 46 | return (__force fs32)cpu_to_le32(n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | else |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 48 | return (__force fs32)cpu_to_be32(n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static inline u16 |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 52 | fs16_to_cpu(const struct super_block *sb, fs16 n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
| 54 | if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 55 | return le16_to_cpu((__force __le16)n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | else |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 57 | return be16_to_cpu((__force __be16)n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 60 | static inline fs16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | cpu_to_fs16(const struct super_block *sb, u16 n) |
| 62 | { |
| 63 | if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 64 | return (__force fs16)cpu_to_le16(n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | else |
Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 66 | return (__force fs16)cpu_to_be16(n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | /* Composite types below here */ |
| 70 | |
| 71 | static inline befs_block_run |
Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 72 | fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 74 | befs_block_run run; |
| 75 | |
| 76 | if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) { |
Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 77 | run.allocation_group = le32_to_cpu((__force __le32)n.allocation_group); |
| 78 | run.start = le16_to_cpu((__force __le16)n.start); |
| 79 | run.len = le16_to_cpu((__force __le16)n.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } else { |
Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 81 | run.allocation_group = be32_to_cpu((__force __be32)n.allocation_group); |
| 82 | run.start = be16_to_cpu((__force __be16)n.start); |
| 83 | run.len = be16_to_cpu((__force __be16)n.len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | return run; |
| 86 | } |
| 87 | |
Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 88 | static inline befs_disk_block_run |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | cpu_to_fsrun(const struct super_block *sb, befs_block_run n) |
| 90 | { |
Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 91 | befs_disk_block_run run; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 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); |
| 97 | } else { |
| 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); |
| 101 | } |
| 102 | return run; |
| 103 | } |
| 104 | |
| 105 | static inline befs_data_stream |
Jesper Juhl | e0e3d32 | 2011-01-12 17:00:26 -0800 | [diff] [blame] | 106 | fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
| 108 | befs_data_stream data; |
| 109 | int i; |
| 110 | |
| 111 | for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i) |
Jesper Juhl | e0e3d32 | 2011-01-12 17:00:26 -0800 | [diff] [blame] | 112 | data.direct[i] = fsrun_to_cpu(sb, n->direct[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Jesper Juhl | e0e3d32 | 2011-01-12 17:00:26 -0800 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | data.max_double_indirect_range = fs64_to_cpu(sb, |
Jesper Juhl | e0e3d32 | 2011-01-12 17:00:26 -0800 | [diff] [blame] | 119 | n-> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | max_double_indirect_range); |
Jesper Juhl | e0e3d32 | 2011-01-12 17:00:26 -0800 | [diff] [blame] | 121 | data.size = fs64_to_cpu(sb, n->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | return data; |
| 124 | } |
| 125 | |
| 126 | #endif //LINUX_BEFS_ENDIAN |