[OpenBIOS] [PATCH 4/4 v2] Fix HFS on little-endian systems

Pavel Roskin proski at gnu.org
Tue Aug 11 22:33:13 CEST 2009

Fix HFS on little-endian systems

Rewrite hfs_get_ushort() and hfs_get_uint() as inline functions so that
their arguments are checked.  Use __be16_to_cpu and __be32_to_cpu to
byte-swap the result as needed.
 fs/hfs_mdb.h |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/fs/hfs_mdb.h b/fs/hfs_mdb.h
index 3df549a..19182a0 100644
--- a/fs/hfs_mdb.h
+++ b/fs/hfs_mdb.h
@@ -15,12 +15,21 @@
 #ifndef _H_HFS_MDB
 #define _H_HFS_MDB
+#include "libc/byteorder.h"
 typedef unsigned char hfs_char_t;
 typedef unsigned char hfs_ushort_t[2];
 typedef unsigned char hfs_uint_t[4];
-#define hfs_get_ushort(addr)    (*((unsigned short*)(addr)))
-#define hfs_get_uint(addr)      (*((unsigned int*)(addr)))
+static inline unsigned short hfs_get_ushort(hfs_ushort_t addr)
+	return __be16_to_cpu(*((unsigned short *)(addr)));
+static inline unsigned int hfs_get_uint(hfs_uint_t addr)
+	return __be32_to_cpu(*((unsigned int *)(addr)));
  * The HFS Master Directory Block (MDB).

More information about the OpenBIOS mailing list