4 * Copyright (C) 1997, 1998 Francois-Rene Rideau <fare@tunes.org>
5 * Copyright (C) 1998 Jakub Jelinek <jj@ultra.linux.cz>
6 * Copyright (C) 2001 Christoph Hellwig <hch@infradead.org>
14 * HERE WE ASSUME EITHER BIG OR LITTLE ENDIAN UFSes
15 * in case there are ufs implementations that have strange bytesexes,
16 * you'll need to modify code here as well as in ufs_super.c and ufs_fs.h
26 fs64_to_cpu(struct super_block *sbp, u64 n)
28 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
29 return le64_to_cpu(n);
31 return be64_to_cpu(n);
35 cpu_to_fs64(struct super_block *sbp, u64 n)
37 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
38 return cpu_to_le64(n);
40 return cpu_to_be64(n);
44 fs64_add(struct super_block *sbp, u32 *n, int d)
46 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
47 return *n = cpu_to_le64(le64_to_cpu(*n)+d);
49 return *n = cpu_to_be64(be64_to_cpu(*n)+d);
53 fs64_sub(struct super_block *sbp, u32 *n, int d)
55 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56 return *n = cpu_to_le64(le64_to_cpu(*n)-d);
58 return *n = cpu_to_be64(be64_to_cpu(*n)-d);
62 fs32_to_cpu(struct super_block *sbp, u32 n)
64 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65 return le32_to_cpu(n);
67 return be32_to_cpu(n);
71 cpu_to_fs32(struct super_block *sbp, u32 n)
73 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
74 return cpu_to_le32(n);
76 return cpu_to_be32(n);
80 fs32_add(struct super_block *sbp, u32 *n, int d)
82 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
83 return *n = cpu_to_le32(le32_to_cpu(*n)+d);
85 return *n = cpu_to_be32(be32_to_cpu(*n)+d);
89 fs32_sub(struct super_block *sbp, u32 *n, int d)
91 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
92 return *n = cpu_to_le32(le32_to_cpu(*n)-d);
94 return *n = cpu_to_be32(be32_to_cpu(*n)-d);
98 fs16_to_cpu(struct super_block *sbp, u16 n)
100 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
101 return le16_to_cpu(n);
103 return be16_to_cpu(n);
107 cpu_to_fs16(struct super_block *sbp, u16 n)
109 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
110 return cpu_to_le16(n);
112 return cpu_to_be16(n);
116 fs16_add(struct super_block *sbp, u16 *n, int d)
118 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
119 return *n = cpu_to_le16(le16_to_cpu(*n)+d);
121 return *n = cpu_to_be16(be16_to_cpu(*n)+d);
125 fs16_sub(struct super_block *sbp, u16 *n, int d)
127 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
128 return *n = cpu_to_le16(le16_to_cpu(*n)-d);
130 return *n = cpu_to_be16(be16_to_cpu(*n)-d);
133 #endif /* _UFS_SWAB_H */