| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Harrison | 9a6ab76 | 2008-05-16 11:20:25 -0700 | [diff] [blame] | 12 | #include <asm/byteorder.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  | 
 | 14 | static inline u64 | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 15 | fs64_to_cpu(const struct super_block *sb, fs64 n) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | { | 
 | 17 | 	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 18 | 		return le64_to_cpu((__force __le64)n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | 	else | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 20 | 		return be64_to_cpu((__force __be64)n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | } | 
 | 22 |  | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 23 | static inline fs64 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | cpu_to_fs64(const struct super_block *sb, u64 n) | 
 | 25 | { | 
 | 26 | 	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 27 | 		return (__force fs64)cpu_to_le64(n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | 	else | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 29 | 		return (__force fs64)cpu_to_be64(n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | } | 
 | 31 |  | 
 | 32 | static inline u32 | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 33 | fs32_to_cpu(const struct super_block *sb, fs32 n) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { | 
 | 35 | 	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 36 | 		return le32_to_cpu((__force __le32)n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | 	else | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 38 | 		return be32_to_cpu((__force __be32)n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } | 
 | 40 |  | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 41 | static inline fs32 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | cpu_to_fs32(const struct super_block *sb, u32 n) | 
 | 43 | { | 
 | 44 | 	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 45 | 		return (__force fs32)cpu_to_le32(n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | 	else | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 47 | 		return (__force fs32)cpu_to_be32(n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } | 
 | 49 |  | 
 | 50 | static inline u16 | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 51 | fs16_to_cpu(const struct super_block *sb, fs16 n) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { | 
 | 53 | 	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 54 | 		return le16_to_cpu((__force __le16)n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | 	else | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 56 | 		return be16_to_cpu((__force __be16)n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } | 
 | 58 |  | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 59 | static inline fs16 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | cpu_to_fs16(const struct super_block *sb, u16 n) | 
 | 61 | { | 
 | 62 | 	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 63 | 		return (__force fs16)cpu_to_le16(n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | 	else | 
| Al Viro | 1151895 | 2005-12-24 01:32:03 -0500 | [diff] [blame] | 65 | 		return (__force fs16)cpu_to_be16(n); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } | 
 | 67 |  | 
 | 68 | /* Composite types below here */ | 
 | 69 |  | 
 | 70 | static inline befs_block_run | 
| Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 71 | 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] | 72 | { | 
 | 73 | 	befs_block_run run; | 
 | 74 |  | 
 | 75 | 	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) { | 
| Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 76 | 		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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | 	} else { | 
| Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 80 | 		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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | 	} | 
 | 84 | 	return run; | 
 | 85 | } | 
 | 86 |  | 
| Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 87 | static inline befs_disk_block_run | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | cpu_to_fsrun(const struct super_block *sb, befs_block_run n) | 
 | 89 | { | 
| Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 90 | 	befs_disk_block_run run; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 |  | 
 | 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 |  | 
 | 104 | static inline befs_data_stream | 
| Al Viro | a9721f3 | 2005-12-24 14:28:55 -0500 | [diff] [blame] | 105 | fsds_to_cpu(const struct super_block *sb, befs_disk_data_stream n) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { | 
 | 107 | 	befs_data_stream data; | 
 | 108 | 	int i; | 
 | 109 |  | 
 | 110 | 	for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i) | 
 | 111 | 		data.direct[i] = fsrun_to_cpu(sb, n.direct[i]); | 
 | 112 |  | 
 | 113 | 	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); | 
 | 117 | 	data.max_double_indirect_range = fs64_to_cpu(sb, | 
 | 118 | 						     n. | 
 | 119 | 						     max_double_indirect_range); | 
 | 120 | 	data.size = fs64_to_cpu(sb, n.size); | 
 | 121 |  | 
 | 122 | 	return data; | 
 | 123 | } | 
 | 124 |  | 
 | 125 | #endif				//LINUX_BEFS_ENDIAN |