On Wed, 5 Dec 2007, Andi Drebes wrote:
>
> +#ifdef __BIG_ENDIAN
> +
> +/* Converts a cramfs_inode's offset field
> +   from little endianto cpu endian */
> +static u32 cramfs_offset_to_cpu(struct cramfs_inode *inode)
> +{
> +     u8 *inode_bytes = (u8 *)inode;
> +     return ((inode_bytes[8] & 0xc0) >> 6) | (inode_bytes[9] << 2) |
> +             (inode_bytes[10] << 10) | (inode_bytes[11] << 18);
> +}
...
> +#elif defined(__LITTLE_ENDIAN)
> +
> +/* Converts a cramfs_inode's offset field
> +   from little endian to cpu endian */
> +static u32 cramfs_offset_to_cpu(struct cramfs_inode *inode)
> +{
> +     return inode->offset;
> +}

No, no, what I meant about not having any #ifdef __LITTLE_ENDIAN was to do 
the code do the same thing *regardless* of endianness. In other words, a 
simple:

        struct cramfs_inode {
                __le32 mode_uid;        /* CRAMFS_MODE_WIDTH:CRAMFS_UID_WIDTH */
                __le32 size_gid;        /* CRAMFS_SIZE_WIDTH:CRAMFS_GID_WIDTH */
                __le32 namelen_offset;  /* 
CRAMFS_NAMELEN_WIDTH:CRAMFS_OFFSET_WIDTH */
        };

        #define CRAMFS_UID_MASK ((1ul << CRAMFS_UID_WIDTH)-1)
        #define CRAMFS_GID_MASK ((1ul << CRAMFS_GID_WIDTH)-1)
        #define CRAMFS_NAMELEN_MASK ((1ul << CRAMFS_NAMELEN_WIDTH)-1)

        static inline u32 cramfs_mode(struct cramfs_inode *inode)
        {
                return le32_to_cpu(node->mode_uid) >> CRAMFS_UID_WIDTH;
        }

        static inline u32 cramfs_uid(struct cramfs_inode *inode)
        {
                return le32_to_cpu(node->mode_uid) & CRAMFS_UID_MASK;
        }

        static inline u32 cramfs_size(struct cramfs_inode *inode)
        {
                return le32_to_cpu(node->size_gid) >> CRAMFS_GID_WIDTH;
        }

        static inline u32 cramfs_gid(struct cramfs_inode *inode)
        {
                return le32_to_cpu(node->size_gid) & CRAMFS_GID_MASK;
        }

        static inline u32 cramfs_offset(struct cramfs_inode *inode)
        {
                return le32_to_cpu(node->namelen_offset) >> 
CRAMFS_NAMELEN_WIDTH;
        }

        static inline u32 cramfs_namelen(struct cramfs_inode *inode)
        {
                return le32_to_cpu(node->namelen_offset) & CRAMFS_NAMELEN_MASK;
        }

See? No #ifdef's required, no different code-paths, and the code generated 
will be pretty much optimal too.

(No, the above is not tested in any way, shape, or form, and no, I didn't 
double-check that I actually extracted the right bits, but you get the 
idea).

                        Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to