Skip to contentSkip to conversation

cramfs big-endian user-space patch

PATCH New Daniel Quinlan 1 participant 1 message Feb 26, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cramfs big-endian user-space patch

The cramfs CVS tree is under http://sourceforge.net/projects/cramfs/

This patch is against the "linux" module, use the HEAD of the tree.

- Dan

Index: Documentation/filesystems/cramfs.txt
===================================================================
RCS file: /cvsroot/cramfs/linux/Documentation/filesystems/cramfs.txt,v retrieving revision 1.3

filesystems/cramfs.txt +5 -6
diff -u -r1.3 cramfs.txt
@@ -37,12 +37,11 @@
 the update lasts only as long as the inode is cached in memory, after
 which the timestamp reverts to 1970, i.e. moves backwards in time.
 
-Currently, cramfs must be written and read with architectures of the
-same endianness, and can be read only by kernels with PAGE_CACHE_SIZE
-== 4096.  At least the latter of these is a bug, but it hasn't been
-decided what the best fix is.  For the moment if you have larger pages
-you can just change the #define in mkcramfs.c, so long as you don't
-mind the filesystem becoming unreadable to future kernels.
+Currently, cramfs can be read only by kernels with PAGE_CACHE_SIZE ==
+4096.  This is a bug, but it hasn't been decided what the best fix is.
+For the moment if you have larger pages you can just change the
+#define in mkcramfs.c, so long as you don't mind the filesystem
+becoming unreadable to future kernels.
 
 
 For /usr/share/magic

Index: fs/cramfs/README
===================================================================
RCS file: /cvsroot/cramfs/linux/fs/cramfs/README,v retrieving revision 1.4

cramfs/README +25 -14
diff -u -r1.4 README
@@ -6,8 +6,8 @@
 swapped around (though it does care that directory entries (inodes) in
 a given directory are contiguous, as this is used by readdir).
 
-All data is currently in host-endian format; neither mkcramfs nor the
-kernel ever do swabbing.  (See section `Block Size' below.)
+All data is in little-endian format; user-space tools and the kernel do
+swabbing on big-endian systems.  (See section `Byte Order' below.)
 
 <filesystem>:
 	<superblock>
@@ -71,6 +71,27 @@
 with -z if you want it to create files that can have holes in them.
 
 
+Byte Order
+----------
+
+When defining the cramfs filesystem, the two options for byte order were
+`always use little-endian' (like ext2fs) or `writer chooses endianness;
+kernel adapts at runtime'.  Little-endian wins because of code
+simplicity and little CPU overhead even on big-endian machines.
+
+While cramfs has always been defined to be little-endian, this
+implementation originally required that cramfs filesystems be written
+and read with architectures of the same endianness; big-endian machines
+would write and read cramfs filesystems with big-endian byte order (the
+"incorrect" byte order for cramfs filesystems).
+
+Now, only little-endian cramfs filesystems are supported for both
+little-endian and big-endian machines.  If you need to support
+big-endian cramfs filesystems for a legacy application on a big-endian
+machine, you could remove the byte-swapping, but it would probably be
+better to write a one-time byte order conversion program.
+
+
 Tools
 -----
 
@@ -108,17 +129,8 @@
 PAGE_CACHE_SIZE is subject to change between kernel versions
 (currently possible with arm and ia64).
 
-The remaining options try to make cramfs more sharable.
-
-One part of that is addressing endianness.  The two options here are
-`always use little-endian' (like ext2fs) or `writer chooses
-endianness; kernel adapts at runtime'.  Little-endian wins because of
-code simplicity and little CPU overhead even on big-endian machines.
-
-The cost of swabbing is changing the code to use the le32_to_cpu
-etc. macros as used by ext2fs.  We don't need to swab the compressed
-data, only the superblock, inodes and block pointers.
-
+The remaining options try to make cramfs more sharable by choosing a
+block size.  The options are:
 
 The other part of making cramfs more sharable is choosing a block
 size.  The options are:
@@ -152,7 +164,6 @@
 cost is greater complexity.  Probably not worth it, but I hope someone
 will disagree.  (If it is implemented, then I'll re-use that code in
 e2compr.)
-
 
 Another cost of 2 and 3 over 1 is making mkcramfs use a different
 block size, but that just means adding and parsing a -b option.

Index: fs/cramfs/inode.c
===================================================================
RCS file: /cvsroot/cramfs/linux/fs/cramfs/inode.c,v retrieving revision 1.4

cramfs/inode.c +28 -25

131 lines not on this page · raw message

Index: include/linux/cramfs_fs.h
===================================================================
RCS file: /cvsroot/cramfs/linux/include/linux/cramfs_fs.h,v retrieving revision 1.2

linux/cramfs_fs.h +61 -8

83 lines not on this page · raw message

Index: scripts/cramfs/cramfsck.c
===================================================================
RCS file: /cvsroot/cramfs/linux/scripts/cramfs/cramfsck.c,v retrieving revision 1.4

cramfs/cramfsck.c +37 -25

125 lines not on this page · raw message

Index: scripts/cramfs/mkcramfs.c
===================================================================
RCS file: /cvsroot/cramfs/linux/scripts/cramfs/mkcramfs.c,v retrieving revision 1.4

cramfs/mkcramfs.c +18 -17
diff -u -r1.4 mkcramfs.c
@@ -380,19 +380,20 @@
 
 	offset += opt_pad;	/* 0 if no padding */
 
-	super->magic = CRAMFS_MAGIC;
+	super->magic = CRAMFS_32(CRAMFS_MAGIC);
 	super->flags = CRAMFS_FLAG_FSID_VERSION_2 | CRAMFS_FLAG_SORTED_DIRS;
 	if (opt_holes)
 		super->flags |= CRAMFS_FLAG_HOLES;
 	if (image_length > 0)
 		super->flags |= CRAMFS_FLAG_SHIFTED_ROOT_OFFSET;
-	super->size = size;
+	super->flags = CRAMFS_32(super->flags);
+	super->size = CRAMFS_32(size);
 	memcpy(super->signature, CRAMFS_SIGNATURE, sizeof(super->signature));
 
-	super->fsid.crc = crc32(0L, Z_NULL, 0);
-	super->fsid.edition = opt_edition;
-	super->fsid.blocks = total_blocks;
-	super->fsid.files = total_nodes;
+	super->fsid.crc = CRAMFS_32(crc32(0L, Z_NULL, 0));
+	super->fsid.edition = CRAMFS_32(opt_edition);
+	super->fsid.blocks = CRAMFS_32(total_blocks);
+	super->fsid.files = CRAMFS_32(total_nodes);
 
 	memset(super->name, 0x00, sizeof(super->name));
 	if (opt_name)
@@ -400,11 +401,11 @@
 	else
 		strncpy(super->name, "Compressed", sizeof(super->name));
 
-	super->root.mode = root->mode;
-	super->root.uid = root->uid;
+	super->root.mode = CRAMFS_16(root->mode);
+	super->root.uid = CRAMFS_16(root->uid);
 	super->root.gid = root->gid;
-	super->root.size = root->size;
-	super->root.offset = offset >> 2;
+	super->root.size = CRAMFS_24(root->size);
+	CRAMFS_SET_OFFSET(&(super->root), offset >> 2);
 
 	return offset;
 }
@@ -419,7 +420,7 @@
 	if (offset >= (1 << (2 + CRAMFS_OFFSET_WIDTH))) {
 		die(MKFS_ERROR, 0, "filesystem too big");
 	}
-	inode->offset = (offset >> 2);
+	CRAMFS_SET_OFFSET(inode, offset >> 2);
 }
 
 /*
@@ -481,10 +482,10 @@
 
 			entry->dir_offset = offset;
 
-			inode->mode = entry->mode;
-			inode->uid = entry->uid;
+			inode->mode = CRAMFS_16(entry->mode);
+			inode->uid = CRAMFS_16(entry->uid);
 			inode->gid = entry->gid;
-			inode->size = entry->size;
+			inode->size = CRAMFS_24(entry->size);
 			inode->offset = 0;
 			/* Non-empty directories, regfiles and symlinks will
 			   write over inode->offset later. */
@@ -497,7 +498,7 @@
 				*(base + offset + len) = '\0';
 				len++;
 			}
-			inode->namelen = len >> 2;
+			CRAMFS_SET_NAMELEN(inode, len >> 2);
 			offset += len;
 
 			if (opt_verbose)
@@ -608,7 +609,7 @@
 			die(MKFS_ERROR, 0, "AIEEE: block \"compressed\" to > 2*blocklength (%ld)", len);
 		}
 
-		*(u32 *) (base + offset) = curr;
+		*(u32 *) (base + offset) = CRAMFS_32(curr);
 		offset += 4;
 	} while (size);
 
@@ -823,7 +824,7 @@
 	/* Put the checksum in. */
 	crc = crc32(0L, Z_NULL, 0);
 	crc = crc32(crc, (rom_image+opt_pad), (offset-opt_pad));
-	((struct cramfs_super *) (rom_image+opt_pad))->fsid.crc = crc;
+	((struct cramfs_super *) (rom_image+opt_pad))->fsid.crc = CRAMFS_32(crc);
 	printf("CRC: %x\n", crc);
 
 	/* Check to make sure we allocated enough space. */