Skip to content

Commit

Permalink
cramfs: error message about endianess
Browse files Browse the repository at this point in the history
The README file in the cramfs subdirectory says: "All data is currently in
host-endian format; neither mkcramfs nor the kernel ever do swabbing."

If somebody tries to mount a cramfs with the wrong endianess, cramfs only
complains about a wrong magic but doesn't inform the user that only the
endianess isn't right.

The following patch adds an error message to the cramfs sources.  If a user
tries to mount a cramfs with the wrong endianess using the patched sources,
cramfs will display the message "cramfs: wrong endianess".

Signed-off-by: Andi Drebes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
andidr authored and Linus Torvalds committed Oct 17, 2007
1 parent 7f44c36 commit ac8d35c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion fs/cramfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,21 @@ static int cramfs_fill_super(struct super_block *sb, void *data, int silent)

/* Do sanity checks on the superblock */
if (super.magic != CRAMFS_MAGIC) {
/* check for wrong endianess */
if (super.magic == CRAMFS_MAGIC_WEND) {
if (!silent)
printk(KERN_ERR "cramfs: wrong endianess\n");
goto out;
}

/* check at 512 byte offset */
mutex_lock(&read_mutex);
memcpy(&super, cramfs_read(sb, 512, sizeof(super)), sizeof(super));
mutex_unlock(&read_mutex);
if (super.magic != CRAMFS_MAGIC) {
if (!silent)
if (super.magic == CRAMFS_MAGIC_WEND && !silent)
printk(KERN_ERR "cramfs: wrong endianess\n");
else if (!silent)
printk(KERN_ERR "cramfs: wrong magic\n");
goto out;
}
Expand Down
1 change: 1 addition & 0 deletions include/linux/cramfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <linux/types.h>

#define CRAMFS_MAGIC 0x28cd3d45 /* some random number */
#define CRAMFS_MAGIC_WEND 0x453dcd28 /* magic number with the wrong endianess */
#define CRAMFS_SIGNATURE "Compressed ROMFS"

/*
Expand Down

0 comments on commit ac8d35c

Please sign in to comment.