endian.h 3.1 KB

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