swab.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * linux/fs/ufs/swab.h
  3. *
  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>
  7. */
  8. #ifndef _UFS_SWAB_H
  9. #define _UFS_SWAB_H
  10. /*
  11. * Notes:
  12. * HERE WE ASSUME EITHER BIG OR LITTLE ENDIAN UFSes
  13. * in case there are ufs implementations that have strange bytesexes,
  14. * you'll need to modify code here as well as in ufs_super.c and ufs_fs.h
  15. * to support them.
  16. */
  17. enum {
  18. BYTESEX_LE,
  19. BYTESEX_BE
  20. };
  21. static inline u64
  22. fs64_to_cpu(struct super_block *sbp, __fs64 n)
  23. {
  24. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  25. return le64_to_cpu((__force __le64)n);
  26. else
  27. return be64_to_cpu((__force __be64)n);
  28. }
  29. static inline __fs64
  30. cpu_to_fs64(struct super_block *sbp, u64 n)
  31. {
  32. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  33. return (__force __fs64)cpu_to_le64(n);
  34. else
  35. return (__force __fs64)cpu_to_be64(n);
  36. }
  37. static inline u32
  38. fs32_to_cpu(struct super_block *sbp, __fs32 n)
  39. {
  40. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  41. return le32_to_cpu((__force __le32)n);
  42. else
  43. return be32_to_cpu((__force __be32)n);
  44. }
  45. static inline __fs32
  46. cpu_to_fs32(struct super_block *sbp, u32 n)
  47. {
  48. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  49. return (__force __fs32)cpu_to_le32(n);
  50. else
  51. return (__force __fs32)cpu_to_be32(n);
  52. }
  53. static inline void
  54. fs32_add(struct super_block *sbp, __fs32 *n, int d)
  55. {
  56. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  57. le32_add_cpu((__le32 *)n, d);
  58. else
  59. be32_add_cpu((__be32 *)n, d);
  60. }
  61. static inline void
  62. fs32_sub(struct super_block *sbp, __fs32 *n, int d)
  63. {
  64. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  65. le32_add_cpu((__le32 *)n, -d);
  66. else
  67. be32_add_cpu((__be32 *)n, -d);
  68. }
  69. static inline u16
  70. fs16_to_cpu(struct super_block *sbp, __fs16 n)
  71. {
  72. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  73. return le16_to_cpu((__force __le16)n);
  74. else
  75. return be16_to_cpu((__force __be16)n);
  76. }
  77. static inline __fs16
  78. cpu_to_fs16(struct super_block *sbp, u16 n)
  79. {
  80. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  81. return (__force __fs16)cpu_to_le16(n);
  82. else
  83. return (__force __fs16)cpu_to_be16(n);
  84. }
  85. static inline void
  86. fs16_add(struct super_block *sbp, __fs16 *n, int d)
  87. {
  88. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  89. le16_add_cpu((__le16 *)n, d);
  90. else
  91. be16_add_cpu((__be16 *)n, d);
  92. }
  93. static inline void
  94. fs16_sub(struct super_block *sbp, __fs16 *n, int d)
  95. {
  96. if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
  97. le16_add_cpu((__le16 *)n, -d);
  98. else
  99. be16_add_cpu((__be16 *)n, -d);
  100. }
  101. #endif /* _UFS_SWAB_H */