Blame view

fs/befs/endian.h 3.15 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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   Harvey Harrison   byteorder: don't ...
12
  #include <asm/byteorder.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
  
  static inline u64
1151895f8   Al Viro   [PATCH] befs: int...
15
  fs64_to_cpu(const struct super_block *sb, fs64 n)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
  {
  	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
1151895f8   Al Viro   [PATCH] befs: int...
18
  		return le64_to_cpu((__force __le64)n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  	else
1151895f8   Al Viro   [PATCH] befs: int...
20
  		return be64_to_cpu((__force __be64)n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  }
1151895f8   Al Viro   [PATCH] befs: int...
22
  static inline fs64
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
  cpu_to_fs64(const struct super_block *sb, u64 n)
  {
  	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
1151895f8   Al Viro   [PATCH] befs: int...
26
  		return (__force fs64)cpu_to_le64(n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
  	else
1151895f8   Al Viro   [PATCH] befs: int...
28
  		return (__force fs64)cpu_to_be64(n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
  }
  
  static inline u32
1151895f8   Al Viro   [PATCH] befs: int...
32
  fs32_to_cpu(const struct super_block *sb, fs32 n)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
34
  {
  	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
1151895f8   Al Viro   [PATCH] befs: int...
35
  		return le32_to_cpu((__force __le32)n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
  	else
1151895f8   Al Viro   [PATCH] befs: int...
37
  		return be32_to_cpu((__force __be32)n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
  }
1151895f8   Al Viro   [PATCH] befs: int...
39
  static inline fs32
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
41
42
  cpu_to_fs32(const struct super_block *sb, u32 n)
  {
  	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
1151895f8   Al Viro   [PATCH] befs: int...
43
  		return (__force fs32)cpu_to_le32(n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
  	else
1151895f8   Al Viro   [PATCH] befs: int...
45
  		return (__force fs32)cpu_to_be32(n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
  }
  
  static inline u16
1151895f8   Al Viro   [PATCH] befs: int...
49
  fs16_to_cpu(const struct super_block *sb, fs16 n)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
  {
  	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
1151895f8   Al Viro   [PATCH] befs: int...
52
  		return le16_to_cpu((__force __le16)n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  	else
1151895f8   Al Viro   [PATCH] befs: int...
54
  		return be16_to_cpu((__force __be16)n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
  }
1151895f8   Al Viro   [PATCH] befs: int...
56
  static inline fs16
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
58
59
  cpu_to_fs16(const struct super_block *sb, u16 n)
  {
  	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
1151895f8   Al Viro   [PATCH] befs: int...
60
  		return (__force fs16)cpu_to_le16(n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  	else
1151895f8   Al Viro   [PATCH] befs: int...
62
  		return (__force fs16)cpu_to_be16(n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
65
66
67
  }
  
  /* Composite types below here */
  
  static inline befs_block_run
a9721f315   Al Viro   [PATCH] befs: end...
68
  fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
72
  {
  	befs_block_run run;
  
  	if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
a9721f315   Al Viro   [PATCH] befs: end...
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   Linus Torvalds   Linux-2.6.12-rc2
76
  	} else {
a9721f315   Al Viro   [PATCH] befs: end...
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   Linus Torvalds   Linux-2.6.12-rc2
80
81
82
  	}
  	return run;
  }
a9721f315   Al Viro   [PATCH] befs: end...
83
  static inline befs_disk_block_run
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
85
  cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
  {
a9721f315   Al Viro   [PATCH] befs: end...
86
  	befs_disk_block_run run;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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   Jesper Juhl   befs: don't pass ...
101
  fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
102
103
104
105
106
  {
  	befs_data_stream data;
  	int i;
  
  	for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i)
e0e3d32bb   Jesper Juhl   befs: don't pass ...
107
  		data.direct[i] = fsrun_to_cpu(sb, n->direct[i]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
108

e0e3d32bb   Jesper Juhl   befs: don't pass ...
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   Linus Torvalds   Linux-2.6.12-rc2
113
  	data.max_double_indirect_range = fs64_to_cpu(sb,
e0e3d32bb   Jesper Juhl   befs: don't pass ...
114
  						     n->
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
  						     max_double_indirect_range);
e0e3d32bb   Jesper Juhl   befs: don't pass ...
116
  	data.size = fs64_to_cpu(sb, n->size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
119
120
121
  
  	return data;
  }
  
  #endif				//LINUX_BEFS_ENDIAN