Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  linux/fs/ufs/swab.h
0004  *
0005  * Copyright (C) 1997, 1998 Francois-Rene Rideau <fare@tunes.org>
0006  * Copyright (C) 1998 Jakub Jelinek <jj@ultra.linux.cz>
0007  * Copyright (C) 2001 Christoph Hellwig <hch@infradead.org>
0008  */
0009 
0010 #ifndef _UFS_SWAB_H
0011 #define _UFS_SWAB_H
0012 
0013 /*
0014  * Notes:
0015  *    HERE WE ASSUME EITHER BIG OR LITTLE ENDIAN UFSes
0016  *    in case there are ufs implementations that have strange bytesexes,
0017  *    you'll need to modify code here as well as in ufs_super.c and ufs_fs.h
0018  *    to support them.
0019  */
0020 
0021 enum {
0022     BYTESEX_LE,
0023     BYTESEX_BE
0024 };
0025 
0026 static inline u64
0027 fs64_to_cpu(struct super_block *sbp, __fs64 n)
0028 {
0029     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0030         return le64_to_cpu((__force __le64)n);
0031     else
0032         return be64_to_cpu((__force __be64)n);
0033 }
0034 
0035 static inline __fs64
0036 cpu_to_fs64(struct super_block *sbp, u64 n)
0037 {
0038     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0039         return (__force __fs64)cpu_to_le64(n);
0040     else
0041         return (__force __fs64)cpu_to_be64(n);
0042 }
0043 
0044 static inline u32
0045 fs32_to_cpu(struct super_block *sbp, __fs32 n)
0046 {
0047     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0048         return le32_to_cpu((__force __le32)n);
0049     else
0050         return be32_to_cpu((__force __be32)n);
0051 }
0052 
0053 static inline __fs32
0054 cpu_to_fs32(struct super_block *sbp, u32 n)
0055 {
0056     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0057         return (__force __fs32)cpu_to_le32(n);
0058     else
0059         return (__force __fs32)cpu_to_be32(n);
0060 }
0061 
0062 static inline void
0063 fs32_add(struct super_block *sbp, __fs32 *n, int d)
0064 {
0065     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0066         le32_add_cpu((__le32 *)n, d);
0067     else
0068         be32_add_cpu((__be32 *)n, d);
0069 }
0070 
0071 static inline void
0072 fs32_sub(struct super_block *sbp, __fs32 *n, int d)
0073 {
0074     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0075         le32_add_cpu((__le32 *)n, -d);
0076     else
0077         be32_add_cpu((__be32 *)n, -d);
0078 }
0079 
0080 static inline u16
0081 fs16_to_cpu(struct super_block *sbp, __fs16 n)
0082 {
0083     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0084         return le16_to_cpu((__force __le16)n);
0085     else
0086         return be16_to_cpu((__force __be16)n);
0087 }
0088 
0089 static inline __fs16
0090 cpu_to_fs16(struct super_block *sbp, u16 n)
0091 {
0092     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0093         return (__force __fs16)cpu_to_le16(n);
0094     else
0095         return (__force __fs16)cpu_to_be16(n);
0096 }
0097 
0098 static inline void
0099 fs16_add(struct super_block *sbp, __fs16 *n, int d)
0100 {
0101     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0102         le16_add_cpu((__le16 *)n, d);
0103     else
0104         be16_add_cpu((__be16 *)n, d);
0105 }
0106 
0107 static inline void
0108 fs16_sub(struct super_block *sbp, __fs16 *n, int d)
0109 {
0110     if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
0111         le16_add_cpu((__le16 *)n, -d);
0112     else
0113         be16_add_cpu((__be16 *)n, -d);
0114 }
0115 
0116 #endif /* _UFS_SWAB_H */