1 /* SPDX-License-Identifier: GPL-2.0 */
5 * Copyright (C) 1997, 1998 Francois-Rene Rideau <fare@tunes.org>
6 * Copyright (C) 1998 Jakub Jelinek <jj@ultra.linux.cz>
7 * Copyright (C) 2001 Christoph Hellwig <hch@infradead.org>
15 * HERE WE ASSUME EITHER BIG OR LITTLE ENDIAN UFSes
16 * in case there are ufs implementations that have strange bytesexes,
17 * you'll need to modify code here as well as in ufs_super.c and ufs_fs.h
27 fs64_to_cpu(struct super_block
*sbp
, __fs64 n
)
29 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
30 return le64_to_cpu((__force __le64
)n
);
32 return be64_to_cpu((__force __be64
)n
);
36 cpu_to_fs64(struct super_block
*sbp
, u64 n
)
38 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
39 return (__force __fs64
)cpu_to_le64(n
);
41 return (__force __fs64
)cpu_to_be64(n
);
45 fs32_to_cpu(struct super_block
*sbp
, __fs32 n
)
47 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
48 return le32_to_cpu((__force __le32
)n
);
50 return be32_to_cpu((__force __be32
)n
);
54 cpu_to_fs32(struct super_block
*sbp
, u32 n
)
56 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
57 return (__force __fs32
)cpu_to_le32(n
);
59 return (__force __fs32
)cpu_to_be32(n
);
63 fs32_add(struct super_block
*sbp
, __fs32
*n
, int d
)
65 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
66 le32_add_cpu((__le32
*)n
, d
);
68 be32_add_cpu((__be32
*)n
, d
);
72 fs32_sub(struct super_block
*sbp
, __fs32
*n
, int d
)
74 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
75 le32_add_cpu((__le32
*)n
, -d
);
77 be32_add_cpu((__be32
*)n
, -d
);
81 fs16_to_cpu(struct super_block
*sbp
, __fs16 n
)
83 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
84 return le16_to_cpu((__force __le16
)n
);
86 return be16_to_cpu((__force __be16
)n
);
90 cpu_to_fs16(struct super_block
*sbp
, u16 n
)
92 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
93 return (__force __fs16
)cpu_to_le16(n
);
95 return (__force __fs16
)cpu_to_be16(n
);
99 fs16_add(struct super_block
*sbp
, __fs16
*n
, int d
)
101 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
102 le16_add_cpu((__le16
*)n
, d
);
104 be16_add_cpu((__be16
*)n
, d
);
108 fs16_sub(struct super_block
*sbp
, __fs16
*n
, int d
)
110 if (UFS_SB(sbp
)->s_bytesex
== BYTESEX_LE
)
111 le16_add_cpu((__le16
*)n
, -d
);
113 be16_add_cpu((__be16
*)n
, -d
);
116 #endif /* _UFS_SWAB_H */