From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: Re: [PATCH 1/2] Make cramfs little endian only Date: Tue, 4 Dec 2007 12:11:07 -0800 Message-ID: <20071204121107.e31ddd67.akpm@linux-foundation.org> References: <200712041259.52118.lists-receive@programmierforen.de> <200712041301.27285.lists-receive@programmierforen.de> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org, kzak@redhat.com, hch@infradead.org, phillip@lougher.demon.co.uk To: Andi Drebes Return-path: Received: from smtp2.linux-foundation.org ([207.189.120.14]:35425 "EHLO smtp2.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751876AbXLDUML (ORCPT ); Tue, 4 Dec 2007 15:12:11 -0500 In-Reply-To: <200712041301.27285.lists-receive@programmierforen.de> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Tue, 4 Dec 2007 13:01:26 +0100 Andi Drebes wrote: > The following patch makes cramfs little endian only. When trying to mount a big endian image, > an error message is produced. > > The changes were tested on the following types of machines: > An i386 compatible box (little endian) > UltraSparc IIi (big endian) > > Signed-off-by: Andi Drebes > --- > inode.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------- > 1 file changed, 136 insertions(+), 27 deletions(-) > > diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c > index 350680f..3fbf567 100644 > --- a/fs/cramfs/inode.c > +++ b/fs/cramfs/inode.c > @@ -4,6 +4,10 @@ > * Copyright (C) 1999 Linus Torvalds. > * > * This file is released under the GPL. > + * > + * Changelog: > + * 11/07 - Andi Drebes > + * Made cramfs little endian only. > */ > > /* > @@ -40,6 +44,95 @@ static DEFINE_MUTEX(read_mutex); > #define CRAMINO(x) (((x)->offset && (x)->size)?(x)->offset<<2:1) > #define OFFSET(x) ((x)->i_ino) > > +#ifdef __BIG_ENDIAN > +/* Converts a cramfs_info from little endian to big endian. */ > +static inline void cramfs_convert_info_letobe(struct cramfs_info* info) > +{ > + info->crc = swab32(info->crc); > + info->edition = swab32(info->edition); > + info->blocks = swab32(info->blocks); > + info->files = swab32(info->files); > +} > + > +/* Converts a cramfs_info from little endian to big endian. */ > +static inline void cramfs_convert_inode_letobe(struct cramfs_inode* inode) > +{ > + u8* inode_bytes = (u8*)inode; > + u8 old_nloffs[4]; > + > + inode->mode = swab16(inode->mode); > + inode->uid = swab16(inode->uid); > + inode->size = (inode_bytes[6] << 16) | (inode_bytes[5] << 8) | (inode_bytes[4]); eww. Is there a nicer way of doing that? Might be a bit tricky given the weird way in which struct cramfs_inode was defined. > + > + /* Save the old values of the namelength and the offset */ > + memcpy(old_nloffs, inode_bytes+8, 4); > + > + /* Convert the namelength and the offset */ > + inode_bytes[8] = ((old_nloffs[0] & 0x3f) << 2) | ((old_nloffs[3] & 0xc0) >> 6); > + inode_bytes[9] = ((old_nloffs[3] & 0x3f) << 2) | ((old_nloffs[2] & 0xc0) >> 6); > + inode_bytes[10] = ((old_nloffs[2] & 0x3f) << 2) | ((old_nloffs[1] & 0xc0) >> 6); > + inode_bytes[11] = ((old_nloffs[1] & 0x3f) << 2) | ((old_nloffs[0] & 0xc0) >> 6); > +} > + > +/* Converts a cramfs superblock from little endian to big endian. */ > +static inline void cramfs_convert_super_letobe(struct cramfs_super* super) > +{ > + super->magic = swab32(super->magic); > + super->size = swab32(super->size); > + super->flags = swab32(super->flags); > + super->future = swab32(super->future); > + cramfs_convert_info_letobe(&super->fsid); > + cramfs_convert_inode_letobe(&super->root); > +} These inlines are not sane. Just removing those three takes the sparc64 fs/cramfs/inode.o from 6856 bytes of text down to 5668, which is rather a large difference. The patch has a number of trivial coding-style errors. scripts/checkpatch.pl finds them.