endian.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/fs/befs/endian.h
  4. *
  5. * Copyright (C) 2001 Will Dyson <will_dyson@pobox.com>
  6. *
  7. * Partially based on similar funtions in the sysv driver.
  8. */
  9. #ifndef LINUX_BEFS_ENDIAN
  10. #define LINUX_BEFS_ENDIAN
  11. #include <asm/byteorder.h>
  12. static inline u64
  13. fs64_to_cpu(const struct super_block *sb, fs64 n)
  14. {
  15. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  16. return le64_to_cpu((__force __le64)n);
  17. else
  18. return be64_to_cpu((__force __be64)n);
  19. }
  20. static inline fs64
  21. cpu_to_fs64(const struct super_block *sb, u64 n)
  22. {
  23. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  24. return (__force fs64)cpu_to_le64(n);
  25. else
  26. return (__force fs64)cpu_to_be64(n);
  27. }
  28. static inline u32
  29. fs32_to_cpu(const struct super_block *sb, fs32 n)
  30. {
  31. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  32. return le32_to_cpu((__force __le32)n);
  33. else
  34. return be32_to_cpu((__force __be32)n);
  35. }
  36. static inline fs32
  37. cpu_to_fs32(const struct super_block *sb, u32 n)
  38. {
  39. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  40. return (__force fs32)cpu_to_le32(n);
  41. else
  42. return (__force fs32)cpu_to_be32(n);
  43. }
  44. static inline u16
  45. fs16_to_cpu(const struct super_block *sb, fs16 n)
  46. {
  47. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  48. return le16_to_cpu((__force __le16)n);
  49. else
  50. return be16_to_cpu((__force __be16)n);
  51. }
  52. static inline fs16
  53. cpu_to_fs16(const struct super_block *sb, u16 n)
  54. {
  55. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
  56. return (__force fs16)cpu_to_le16(n);
  57. else
  58. return (__force fs16)cpu_to_be16(n);
  59. }
  60. /* Composite types below here */
  61. static inline befs_block_run
  62. fsrun_to_cpu(const struct super_block *sb, befs_disk_block_run n)
  63. {
  64. befs_block_run run;
  65. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
  66. run.allocation_group = le32_to_cpu((__force __le32)n.allocation_group);
  67. run.start = le16_to_cpu((__force __le16)n.start);
  68. run.len = le16_to_cpu((__force __le16)n.len);
  69. } else {
  70. run.allocation_group = be32_to_cpu((__force __be32)n.allocation_group);
  71. run.start = be16_to_cpu((__force __be16)n.start);
  72. run.len = be16_to_cpu((__force __be16)n.len);
  73. }
  74. return run;
  75. }
  76. static inline befs_disk_block_run
  77. cpu_to_fsrun(const struct super_block *sb, befs_block_run n)
  78. {
  79. befs_disk_block_run run;
  80. if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE) {
  81. run.allocation_group = cpu_to_le32(n.allocation_group);
  82. run.start = cpu_to_le16(n.start);
  83. run.len = cpu_to_le16(n.len);
  84. } else {
  85. run.allocation_group = cpu_to_be32(n.allocation_group);
  86. run.start = cpu_to_be16(n.start);
  87. run.len = cpu_to_be16(n.len);
  88. }
  89. return run;
  90. }
  91. static inline befs_data_stream
  92. fsds_to_cpu(const struct super_block *sb, const befs_disk_data_stream *n)
  93. {
  94. befs_data_stream data;
  95. int i;
  96. for (i = 0; i < BEFS_NUM_DIRECT_BLOCKS; ++i)
  97. data.direct[i] = fsrun_to_cpu(sb, n->direct[i]);
  98. data.max_direct_range = fs64_to_cpu(sb, n->max_direct_range);
  99. data.indirect = fsrun_to_cpu(sb, n->indirect);
  100. data.max_indirect_range = fs64_to_cpu(sb, n->max_indirect_range);
  101. data.double_indirect = fsrun_to_cpu(sb, n->double_indirect);
  102. data.max_double_indirect_range = fs64_to_cpu(sb,
  103. n->
  104. max_double_indirect_range);
  105. data.size = fs64_to_cpu(sb, n->size);
  106. return data;
  107. }
  108. #endif //LINUX_BEFS_ENDIAN