1
2
3
4
5
6
7
8
9#ifndef _UFS_SWAB_H
10#define _UFS_SWAB_H
11
12
13
14
15
16
17
18
19
20enum {
21 BYTESEX_LE,
22 BYTESEX_BE
23};
24
25static __inline u64
26fs64_to_cpu(struct super_block *sbp, u64 n)
27{
28 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
29 return le64_to_cpu(n);
30 else
31 return be64_to_cpu(n);
32}
33
34static __inline u64
35cpu_to_fs64(struct super_block *sbp, u64 n)
36{
37 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
38 return cpu_to_le64(n);
39 else
40 return cpu_to_be64(n);
41}
42
43static __inline u32
44fs64_add(struct super_block *sbp, u32 *n, int d)
45{
46 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
47 return *n = cpu_to_le64(le64_to_cpu(*n)+d);
48 else
49 return *n = cpu_to_be64(be64_to_cpu(*n)+d);
50}
51
52static __inline u32
53fs64_sub(struct super_block *sbp, u32 *n, int d)
54{
55 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
56 return *n = cpu_to_le64(le64_to_cpu(*n)-d);
57 else
58 return *n = cpu_to_be64(be64_to_cpu(*n)-d);
59}
60
61static __inline u32
62fs32_to_cpu(struct super_block *sbp, u32 n)
63{
64 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
65 return le32_to_cpu(n);
66 else
67 return be32_to_cpu(n);
68}
69
70static __inline u32
71cpu_to_fs32(struct super_block *sbp, u32 n)
72{
73 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
74 return cpu_to_le32(n);
75 else
76 return cpu_to_be32(n);
77}
78
79static __inline u32
80fs32_add(struct super_block *sbp, u32 *n, int d)
81{
82 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
83 return *n = cpu_to_le32(le32_to_cpu(*n)+d);
84 else
85 return *n = cpu_to_be32(be32_to_cpu(*n)+d);
86}
87
88static __inline u32
89fs32_sub(struct super_block *sbp, u32 *n, int d)
90{
91 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
92 return *n = cpu_to_le32(le32_to_cpu(*n)-d);
93 else
94 return *n = cpu_to_be32(be32_to_cpu(*n)-d);
95}
96
97static __inline u16
98fs16_to_cpu(struct super_block *sbp, u16 n)
99{
100 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
101 return le16_to_cpu(n);
102 else
103 return be16_to_cpu(n);
104}
105
106static __inline u16
107cpu_to_fs16(struct super_block *sbp, u16 n)
108{
109 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
110 return cpu_to_le16(n);
111 else
112 return cpu_to_be16(n);
113}
114
115static __inline u16
116fs16_add(struct super_block *sbp, u16 *n, int d)
117{
118 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
119 return *n = cpu_to_le16(le16_to_cpu(*n)+d);
120 else
121 return *n = cpu_to_be16(be16_to_cpu(*n)+d);
122}
123
124static __inline u16
125fs16_sub(struct super_block *sbp, u16 *n, int d)
126{
127 if (sbp->u.ufs_sb.s_bytesex == BYTESEX_LE)
128 return *n = cpu_to_le16(le16_to_cpu(*n)-d);
129 else
130 return *n = cpu_to_be16(be16_to_cpu(*n)-d);
131}
132
133#endif
134