[OpenBIOS] [PATCH 2/5] Fix HFS on little-endian systems
Laurent Vivier
Laurent at vivier.eu
Sun May 17 13:49:09 CEST 2009
Le samedi 16 mai 2009 à 20:16 -0400, Pavel Roskin a écrit :
> hfs_get_ushort() and hfs_get_uint() deal with big-endian data, so simply
> casting to a native type won't work on little-endian machines. Rewrite
> those macros as inline functions so that their arguments are checked.
>
> Don't dereference type-punned pointers. gcc 4.4 warns about it.
> ---
>
> fs/hfs_mdb.h | 11 +++++++++--
> 1 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/fs/hfs_mdb.h b/fs/hfs_mdb.h
> index 3df549a..169b999 100644
> --- a/fs/hfs_mdb.h
> +++ b/fs/hfs_mdb.h
> @@ -19,8 +19,15 @@ 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 (addr[0] << 8) | addr[1];
> +}
> +
> +static inline unsigned short hfs_get_uint(hfs_uint_t addr)
> +{
> + return (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3];
> +}
>
Could you use __be32_to_cpu() and __be16_to_cpu() instead ?
Laurent
More information about the OpenBIOS
mailing list