[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Endianness.



Bored. Does someone (particularly someone who might want me to look at some 
BE images for them) want to finish this?

I'll take out the structs and revert to uint32_t once it's done, but this 
way we get forced to fix all occurrences to make it compile, and we can't 
miss any. Try to keep the 'XXX: FIXME' comments in the bits we can revert 
to being slightly less ugly once we do that.

i.e. What was 
	node.nodetype |= JFFS2_NODE_ACCURATE;
and is now
	node.nodetype = cpu_to_je16(je16_to_cpu(node.nodetype)|JFFS....
can revert to
	node.nodetype |= cpu_to_je16(JFFS2_NODE_ACCURATE);

But only once the job is done and all my testing is in BE mode so I still 
catch errors.

Index: include/linux/jffs2.h
===================================================================
RCS file: /home/cvs/mtd/include/linux/jffs2.h,v
retrieving revision 1.24
diff -u -p -r1.24 jffs2.h
--- include/linux/jffs2.h	20 May 2002 14:56:37 -0000	1.24
+++ include/linux/jffs2.h	20 Aug 2002 13:05:56 -0000
@@ -68,30 +68,65 @@
 					   compression type */
 
 
+/* These can go once we've made sure we've caught all uses without
+   byteswapping */
+
+typedef struct {
+	uint32_t v32;
+} __attribute__((packed))  jint32_t;
+
+typedef struct {
+	uint16_t v16;
+} __attribute__((packed)) jint16_t;
+
+#define JFFS2_NATIVE_ENDIAN
+
+#if defined(JFFS2_NATIVE_ENDIAN)
+#define cpu_to_je16(x) ((jint16_t){x})
+#define cpu_to_je32(x) ((jint32_t){x})
+
+#define je16_to_cpu(x) ((x).v16)
+#define je32_to_cpu(x) ((x).v32)
+#elif defined(JFFS2_BIG_ENDIAN)
+#define cpu_to_je16(x) ((jint16_t){cpu_to_be16(x)})
+#define cpu_to_je32(x) ((jint32_t){cpu_to_be32(x)})
+
+#define je16_to_cpu(x) (be16_to_cpu(x.v16))
+#define je32_to_cpu(x) (be32_to_cpu(x.v32))
+#elif defined(JFFS2_LITTLE_ENDIAN)
+#define cpu_to_je16(x) ((jint16_t){cpu_to_le16(x)})
+#define cpu_to_je32(x) ((jint32_t){cpu_to_le32(x)})
+
+#define je16_to_cpu(x) (le16_to_cpu(x.v16))
+#define je32_to_cpu(x) (le32_to_cpu(x.v32))
+#else 
+#error wibble
+#endif
+
 struct jffs2_unknown_node
 {
 	/* All start like this */
-	uint16_t magic;
-	uint16_t nodetype;
-	uint32_t totlen; /* So we can skip over nodes we don't grok */
-	uint32_t hdr_crc;
+	jint16_t magic;
+	jint16_t nodetype;
+	jint32_t totlen; /* So we can skip over nodes we don't grok */
+	jint32_t hdr_crc;
 } __attribute__((packed));
 
 struct jffs2_raw_dirent
 {
-	uint16_t magic;
-	uint16_t nodetype;	/* == JFFS_NODETYPE_DIRENT */
-	uint32_t totlen;
-	uint32_t hdr_crc;
-	uint32_t pino;
-	uint32_t version;
-	uint32_t ino; /* == zero for unlink */
-	uint32_t mctime;
+	jint16_t magic;
+	jint16_t nodetype;	/* == JFFS_NODETYPE_DIRENT */
+	jint32_t totlen;
+	jint32_t hdr_crc;
+	jint32_t pino;
+	jint32_t version;
+	jint32_t ino; /* == zero for unlink */
+	jint32_t mctime;
 	uint8_t nsize;
 	uint8_t type;
 	uint8_t unused[2];
-	uint32_t node_crc;
-	uint32_t name_crc;
+	jint32_t node_crc;
+	jint32_t name_crc;
 	uint8_t name[0];
 } __attribute__((packed));
 
@@ -103,27 +138,27 @@ struct jffs2_raw_dirent
 */
 struct jffs2_raw_inode
 {
-	uint16_t magic;      /* A constant magic number.  */
-	uint16_t nodetype;   /* == JFFS_NODETYPE_INODE */
-	uint32_t totlen;     /* Total length of this node (inc data, etc.) */
-	uint32_t hdr_crc;
-	uint32_t ino;        /* Inode number.  */
-	uint32_t version;    /* Version number.  */
-	uint32_t mode;       /* The file's type or mode.  */
-	uint16_t uid;        /* The file's owner.  */
-	uint16_t gid;        /* The file's group.  */
-	uint32_t isize;      /* Total resultant size of this inode (used for truncations)  */
-	uint32_t atime;      /* Last access time.  */
-	uint32_t mtime;      /* Last modification time.  */
-	uint32_t ctime;      /* Change time.  */
-	uint32_t offset;     /* Where to begin to write.  */
-	uint32_t csize;      /* (Compressed) data size */
-	uint32_t dsize;	     /* Size of the node's data. (after decompression) */
+	jint16_t magic;      /* A constant magic number.  */
+	jint16_t nodetype;   /* == JFFS_NODETYPE_INODE */
+	jint32_t totlen;     /* Total length of this node (inc data, etc.) */
+	jint32_t hdr_crc;
+	jint32_t ino;        /* Inode number.  */
+	jint32_t version;    /* Version number.  */
+	jint32_t mode;       /* The file's type or mode.  */
+	jint16_t uid;        /* The file's owner.  */
+	jint16_t gid;        /* The file's group.  */
+	jint32_t isize;      /* Total resultant size of this inode (used for truncations)  */
+	jint32_t atime;      /* Last access time.  */
+	jint32_t mtime;      /* Last modification time.  */
+	jint32_t ctime;      /* Change time.  */
+	jint32_t offset;     /* Where to begin to write.  */
+	jint32_t csize;      /* (Compressed) data size */
+	jint32_t dsize;	     /* Size of the node's data. (after decompression) */
 	uint8_t compr;       /* Compression algorithm used */
 	uint8_t usercompr;   /* Compression algorithm requested by the user */
-	uint16_t flags;	     /* See JFFS2_INO_FLAG_* */
-	uint32_t data_crc;   /* CRC for the (compressed) data.  */
-	uint32_t node_crc;   /* CRC for the raw inode (excluding data)  */
+	jint16_t flags;	     /* See JFFS2_INO_FLAG_* */
+	jint32_t data_crc;   /* CRC for the (compressed) data.  */
+	jint32_t node_crc;   /* CRC for the raw inode (excluding data)  */
 //	uint8_t data[dsize];
 } __attribute__((packed));
 
Index: fs/jffs2/nodemgmt.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodemgmt.c,v
retrieving revision 1.71
diff -u -p -r1.71 nodemgmt.c
--- fs/jffs2/nodemgmt.c	17 Aug 2002 22:32:11 -0000	1.71
+++ fs/jffs2/nodemgmt.c	20 Aug 2002 13:05:57 -0000
@@ -475,15 +475,16 @@ void jffs2_mark_node_obsolete(struct jff
 		printk(KERN_WARNING "Short read from obsoleted node at 0x%08x: %d\n", ref->flash_offset &~3, retlen);
 		return;
 	}
-	if (PAD(n.totlen) != PAD(ref->totlen)) {
-		printk(KERN_WARNING "Node totlen on flash (0x%08x) != totlen in node ref (0x%08x)\n", n.totlen, ref->totlen);
+	if (PAD(je32_to_cpu(n.totlen)) != PAD(ref->totlen)) {
+		printk(KERN_WARNING "Node totlen on flash (0x%08x) != totlen in node ref (0x%08x)\n", je32_to_cpu(n.totlen), ref->totlen);
 		return;
 	}
-	if (!(n.nodetype & JFFS2_NODE_ACCURATE)) {
-		D1(printk(KERN_DEBUG "Node at 0x%08x was already marked obsolete (nodetype 0x%04x\n", ref->flash_offset &~3, n.nodetype));
+	if (!(je16_to_cpu(n.nodetype) & JFFS2_NODE_ACCURATE)) {
+		D1(printk(KERN_DEBUG "Node at 0x%08x was already marked obsolete (nodetype 0x%04x\n", ref->flash_offset &~3, je16_to_cpu(n.nodetype)));
 		return;
 	}
-	n.nodetype &= ~JFFS2_NODE_ACCURATE;
+	/* XXX FIXME: This is ugly now */
+	n.nodetype = cpu_to_je16(je16_to_cpu(n.nodetype) & ~JFFS2_NODE_ACCURATE);
 	ret = jffs2_flash_write(c, ref->flash_offset&~3, sizeof(n), &retlen, (char *)&n);
 	if (ret) {
 		printk(KERN_WARNING "Write error in obliterating obsoleted node at 0x%08x: %d\n", ref->flash_offset &~3, ret);
Index: fs/jffs2/scan.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/scan.c,v
retrieving revision 1.80
diff -u -p -r1.80 scan.c
--- fs/jffs2/scan.c	17 Aug 2002 22:29:28 -0000	1.80
+++ fs/jffs2/scan.c	20 Aug 2002 13:05:58 -0000
@@ -276,71 +276,82 @@ static int jffs2_scan_eraseblock (struct
 			continue;
 		}
 
-		if (node.magic == JFFS2_EMPTY_BITMASK && node.nodetype == JFFS2_EMPTY_BITMASK) {
+		if (je16_to_cpu(node.magic) == JFFS2_EMPTY_BITMASK && 
+		    je16_to_cpu(node.nodetype) == JFFS2_EMPTY_BITMASK) {
 			D1(printk(KERN_DEBUG "Found empty flash at 0x%x\n", ofs));
 			err = jffs2_scan_empty(c, jeb, &ofs, &noise);
 			if (err) return err;
 			continue;
 		}
 
-		if (ofs == jeb->offset && node.magic == KSAMTIB_CIGAM_2SFFJ) {
+		if (ofs == jeb->offset && je16_to_cpu(node.magic) == KSAMTIB_CIGAM_2SFFJ) {
 			printk(KERN_WARNING "Magic bitmask is backwards at offset 0x%08x. Wrong endian filesystem?\n", ofs);
 			DIRTY_SPACE(4);
 			ofs += 4;
 			continue;
 		}
-		if (node.magic == JFFS2_DIRTY_BITMASK) {
+		if (je16_to_cpu(node.magic) == JFFS2_DIRTY_BITMASK) {
 			D1(printk(KERN_DEBUG "Empty bitmask at 0x%08x\n", ofs));
 			DIRTY_SPACE(4);
 			ofs += 4;
 			continue;
 		}
-		if (node.magic == JFFS2_OLD_MAGIC_BITMASK) {
+		if (je16_to_cpu(node.magic) == JFFS2_OLD_MAGIC_BITMASK) {
 			printk(KERN_WARNING "Old JFFS2 bitmask found at 0x%08x\n", ofs);
 			printk(KERN_WARNING "You cannot use older JFFS2 filesystems with newer kernels\n");
 			DIRTY_SPACE(4);
 			ofs += 4;
 			continue;
 		}
-		if (node.magic != JFFS2_MAGIC_BITMASK) {
+		if (je16_to_cpu(node.magic) != JFFS2_MAGIC_BITMASK) {
 			/* OK. We're out of possibilities. Whinge and move on */
-			noisy_printk(&noise, "jffs2_scan_eraseblock(): Magic bitmask 0x%04x not found at 0x%08x: 0x%04x instead\n", JFFS2_MAGIC_BITMASK, ofs, node.magic);
+			noisy_printk(&noise, "jffs2_scan_eraseblock(): Magic bitmask 0x%04x not found at 0x%08x: 0x%04x instead\n", 
+				     JFFS2_MAGIC_BITMASK, ofs, 
+				     je16_to_cpu(node.magic));
 			DIRTY_SPACE(4);
 			ofs += 4;
 			continue;
 		}
 		/* We seem to have a node of sorts. Check the CRC */
-		nodetype = node.nodetype;
-		node.nodetype |= JFFS2_NODE_ACCURATE;
+		nodetype = je16_to_cpu(node.nodetype);
+		node.nodetype = cpu_to_je16(nodetype | JFFS2_NODE_ACCURATE);
+
 		hdr_crc = crc32(0, &node, sizeof(node)-4);
-		node.nodetype = nodetype;
-		if (hdr_crc != node.hdr_crc) {
+
+		node.nodetype = cpu_to_je16(nodetype);
+
+		if (hdr_crc != je32_to_cpu(node.hdr_crc)) {
 			noisy_printk(&noise, "jffs2_scan_eraseblock(): Node at 0x%08x {0x%04x, 0x%04x, 0x%08x) has invalid CRC 0x%08x (calculated 0x%08x)\n",
-				     ofs, node.magic, node.nodetype, node.totlen, node.hdr_crc, hdr_crc);
+				     ofs, je16_to_cpu(node.magic),
+				     je16_to_cpu(node.nodetype), 
+				     je32_to_cpu(node.totlen),
+				     je32_to_cpu(node.hdr_crc),
+				     hdr_crc);
 			DIRTY_SPACE(4);
 			ofs += 4;
 			continue;
 		}
 
-		if (ofs + node.totlen > jeb->offset + c->sector_size) {
+		if (ofs + je32_to_cpu(node.totlen) > 
+		    jeb->offset + c->sector_size) {
 			/* Eep. Node goes over the end of the erase block. */
 			printk(KERN_WARNING "Node at 0x%08x with length 0x%08x would run over the end of the erase block\n",
-			       ofs, node.totlen);
+			       ofs, je32_to_cpu(node.totlen));
 			printk(KERN_WARNING "Perhaps the file system was created with the wrong erase size?\n");
 			DIRTY_SPACE(4);
 			ofs += 4;
 			continue;
 		}
 
-		if (!(node.nodetype & JFFS2_NODE_ACCURATE)) {
+		if (!(je16_to_cpu(node.nodetype) & JFFS2_NODE_ACCURATE)) {
 			/* Wheee. This is an obsoleted node */
 			D2(printk(KERN_DEBUG "Node at 0x%08x is obsolete. Skipping\n", ofs));
-			DIRTY_SPACE(PAD(node.totlen));
-			ofs += PAD(node.totlen);
+			DIRTY_SPACE(PAD(je32_to_cpu(node.totlen)));
+			ofs += PAD(je32_to_cpu(node.totlen));
 			continue;
 		}
 
-		switch(node.nodetype) {
+		switch(je16_to_cpu(node.nodetype)) {
 		case JFFS2_NODETYPE_INODE:
 			err = jffs2_scan_inode_node(c, jeb, &ofs);
 			if (err) return err;
@@ -352,9 +363,9 @@ static int jffs2_scan_eraseblock (struct
 			break;
 
 		case JFFS2_NODETYPE_CLEANMARKER:
-			if (node.totlen != c->cleanmarker_size) {
+			if (je32_to_cpu(node.totlen) != c->cleanmarker_size) {
 				printk(KERN_NOTICE "CLEANMARKER node found at 0x%08x has totlen 0x%x != normal 0x%x\n", 
-				       ofs, node.totlen, c->cleanmarker_size);
+				       ofs, je32_to_cpu(node.totlen), c->cleanmarker_size);
 				DIRTY_SPACE(PAD(sizeof(struct jffs2_unknown_node)));
 			} else if (jeb->first_node) {
 				printk(KERN_NOTICE "CLEANMARKER node found at 0x%08x, not first node in block (0x%08x)\n", ofs, jeb->offset);
@@ -379,35 +390,35 @@ static int jffs2_scan_eraseblock (struct
 			break;
 
 		case JFFS2_NODETYPE_PADDING:
-			DIRTY_SPACE(PAD(node.totlen));
-			ofs += PAD(node.totlen);
+			DIRTY_SPACE(PAD(je32_to_cpu(node.totlen)));
+			ofs += PAD(je32_to_cpu(node.totlen));
 			break;
 
 		default:
-			switch (node.nodetype & JFFS2_COMPAT_MASK) {
+			switch (je16_to_cpu(node.nodetype) & JFFS2_COMPAT_MASK) {
 			case JFFS2_FEATURE_ROCOMPAT:
-				printk(KERN_NOTICE "Read-only compatible feature node (0x%04x) found at offset 0x%08x\n", node.nodetype, ofs);
+				printk(KERN_NOTICE "Read-only compatible feature node (0x%04x) found at offset 0x%08x\n", je16_to_cpu(node.nodetype), ofs);
 			        c->flags |= JFFS2_SB_FLAG_RO;
 				if (!(jffs2_is_readonly(c)))
 					return -EROFS;
-				DIRTY_SPACE(PAD(node.totlen));
-				ofs += PAD(node.totlen);
+				DIRTY_SPACE(PAD(je32_to_cpu(node.totlen)));
+				ofs += PAD(je32_to_cpu(node.totlen));
 				break;
 
 			case JFFS2_FEATURE_INCOMPAT:
-				printk(KERN_NOTICE "Incompatible feature node (0x%04x) found at offset 0x%08x\n", node.nodetype, ofs);
+				printk(KERN_NOTICE "Incompatible feature node (0x%04x) found at offset 0x%08x\n", je16_to_cpu(node.nodetype), ofs);
 				return -EINVAL;
 
 			case JFFS2_FEATURE_RWCOMPAT_DELETE:
-				D1(printk(KERN_NOTICE "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", node.nodetype, ofs));
-				DIRTY_SPACE(PAD(node.totlen));
-				ofs += PAD(node.totlen);
+				D1(printk(KERN_NOTICE "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", je16_to_cpu(node.nodetype), ofs));
+				DIRTY_SPACE(PAD(je32_to_cpu(node.totlen)));
+				ofs += PAD(je32_to_cpu(node.totlen));
 				break;
 
 			case JFFS2_FEATURE_RWCOMPAT_COPY:
-				D1(printk(KERN_NOTICE "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", node.nodetype, ofs));
-				USED_SPACE(PAD(node.totlen));
-				ofs += PAD(node.totlen);
+				D1(printk(KERN_NOTICE "Unknown but compatible feature node (0x%04x) found at offset 0x%08x\n", je16_to_cpu(node.nodetype), ofs));
+				USED_SPACE(PAD(je32_to_cpu(node.totlen)));
+				ofs += PAD(je32_to_cpu(node.totlen));
 				break;
 			}
 		}
@@ -531,14 +542,14 @@ static int jffs2_scan_inode_node(struct 
 
 	/* We sort of assume that the node was accurate when it was 
 	   first written to the medium :) */
-	oldnodetype = ri.nodetype;
-	ri.nodetype |= JFFS2_NODE_ACCURATE;
+	oldnodetype = je16_to_cpu(ri.nodetype);
+	ri.nodetype = cpu_to_je16(oldnodetype | JFFS2_NODE_ACCURATE);
 	crc = crc32(0, &ri, sizeof(ri)-8);
-	ri.nodetype = oldnodetype;
+	ri.nodetype = cpu_to_je16(oldnodetype);
 
-	if(crc != ri.node_crc) {
+	if(crc != je32_to_cpu(ri.node_crc)) {
 		printk(KERN_NOTICE "jffs2_scan_inode_node(): CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
-		       *ofs, ri.node_crc, crc);
+		       *ofs, je32_to_cpu(ri.node_crc), crc);
 		/* FIXME: Why do we believe totlen? */
 		DIRTY_SPACE(4);
 		*ofs += 4;
@@ -546,12 +557,12 @@ static int jffs2_scan_inode_node(struct 
 	}
 	/* There was a bug where we wrote hole nodes out with csize/dsize
 	   swapped. Deal with it */
-	if (ri.compr == JFFS2_COMPR_ZERO && !ri.dsize && ri.csize) {
+	if (ri.compr == JFFS2_COMPR_ZERO && !je32_to_cpu(ri.dsize) && je32_to_cpu(ri.csize)) {
 		ri.dsize = ri.csize;
-		ri.csize = 0;
+		ri.csize = cpu_to_je32(0);
 	}
 
-	if (ri.csize) {
+	if (je32_to_cpu(ri.csize)) {
 		/* Check data CRC too */
 		unsigned char *dbuf;
 		uint32_t crc;
@@ -561,25 +572,25 @@ static int jffs2_scan_inode_node(struct 
 			printk(KERN_NOTICE "jffs2_scan_inode_node(): allocation of temporary data buffer for CRC check failed\n");
 			return -ENOMEM;
 		}
-		ret = jffs2_flash_read(c, *ofs+sizeof(ri), ri.csize, &retlen, dbuf);
+		ret = jffs2_flash_read(c, *ofs+sizeof(ri), je32_to_cpu(ri.csize), &retlen, dbuf);
 		if (ret) {
 			printk(KERN_NOTICE "jffs2_scan_inode_node(): Read error at 0x%08x: %d\n", *ofs+sizeof(ri), ret);
 			kfree(dbuf);
 			return ret;
 		}
-		if (retlen != ri.csize) {
+		if (retlen != je32_to_cpu(ri.csize)) {
 			printk(KERN_NOTICE "Short read: 0x%x bytes at 0x%08x instead of requested %x\n", 
-			       retlen, *ofs+ sizeof(ri), ri.csize);
+			       retlen, *ofs+ sizeof(ri), je32_to_cpu(ri.csize));
 			kfree(dbuf);
 			return -EIO;
 		}
-		crc = crc32(0, dbuf, ri.csize);
+		crc = crc32(0, dbuf, je32_to_cpu(ri.csize));
 		kfree(dbuf);
-		if (crc != ri.data_crc) {
+		if (crc != je32_to_cpu(ri.data_crc)) {
 			printk(KERN_NOTICE "jffs2_scan_inode_node(): Data CRC failed on node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
-			       *ofs, ri.data_crc, crc);
-			DIRTY_SPACE(PAD(ri.totlen));
-			*ofs += PAD(ri.totlen);
+			       *ofs, je32_to_cpu(ri.data_crc), crc);
+			DIRTY_SPACE(PAD(je32_to_cpu(ri.totlen)));
+			*ofs += PAD(je32_to_cpu(ri.totlen));
 			return 0;
 		}
 	}
@@ -638,7 +649,8 @@ static int jffs2_scan_inode_node(struct 
 		if (!jeb->used_size) {
 			D1(printk(KERN_DEBUG "No valid nodes yet found in this eraseblock 0x%08x, so obsoleting the new instance at 0x%08x\n", 
 				  jeb->offset, raw->flash_offset & ~3));
- 			ri.nodetype &= ~JFFS2_NODE_ACCURATE;
+			/* XXX FIXME: This is now ugly */
+			ri.nodetype = cpu_to_je16(je16_to_cpu(ri.nodetype) & ~JFFS2_NODE_ACCURATE);
 			/* Perhaps we could also mark it as such on the medium. Maybe later */
 		}
 		break;
Index: fs/jffs2/write.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/write.c,v
retrieving revision 1.57
diff -u -p -r1.57 write.c
--- fs/jffs2/write.c	16 Aug 2002 13:28:03 -0000	1.57
+++ fs/jffs2/write.c	20 Aug 2002 13:06:01 -0000
@@ -34,16 +34,20 @@ int jffs2_do_new_inode(struct jffs2_sb_i
 	f->inocache = ic;
 	f->inocache->nlink = 1;
 	f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
-	f->inocache->ino = ri->ino =  ++c->highest_ino;
-	D1(printk(KERN_DEBUG "jffs2_do_new_inode(): Assigned ino# %d\n", ri->ino));
+	f->inocache->ino = ++c->highest_ino;
+	ri->ino = cpu_to_je32(f->inocache->ino);
+
+	D1(printk(KERN_DEBUG "jffs2_do_new_inode(): Assigned ino# %d\n", f->inocache->ino));
 	jffs2_add_ino_cache(c, f->inocache);
 
-	ri->magic = JFFS2_MAGIC_BITMASK;
-	ri->nodetype = JFFS2_NODETYPE_INODE;
-	ri->totlen = PAD(sizeof(*ri));
-	ri->hdr_crc = crc32(0, ri, sizeof(struct jffs2_unknown_node)-4);
-	ri->mode = mode;
-	f->highest_version = ri->version = 1;
+	ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
+	ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
+	ri->totlen = cpu_to_je32(PAD(sizeof(*ri)));
+	ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
+	ri->mode = cpu_to_je32(mode);
+
+	f->highest_version = 1;
+	ri->version = cpu_to_je32(f->highest_version);
 
 	return 0;
 }
@@ -88,7 +92,7 @@ struct jffs2_full_dnode *jffs2_write_dno
 	int ret;
 	unsigned long cnt = 2;
 
-	D1(if(ri->hdr_crc != crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)) {
+	D1(if(je32_to_cpu(ri->hdr_crc) != crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)) {
 		printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dnode()\n");
 		BUG();
 	}
@@ -100,8 +104,8 @@ struct jffs2_full_dnode *jffs2_write_dno
 
 	writecheck(c, flash_ofs);
 
-	if (ri->totlen != sizeof(*ri) + datalen) {
-		printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08x) + datalen (0x%08x)\n", ri->totlen, sizeof(*ri), datalen);
+	if (je32_to_cpu(ri->totlen) != sizeof(*ri) + datalen) {
+		printk(KERN_WARNING "jffs2_write_dnode: ri->totlen (0x%08x) != sizeof(*ri) (0x%08x) + datalen (0x%08x)\n", je32_to_cpu(ri->totlen), sizeof(*ri), datalen);
 	}
 	raw = jffs2_alloc_raw_node_ref();
 	if (!raw)
@@ -113,11 +117,11 @@ struct jffs2_full_dnode *jffs2_write_dno
 		return ERR_PTR(-ENOMEM);
 	}
 	raw->flash_offset = flash_ofs;
-	raw->totlen = PAD(ri->totlen);
+	raw->totlen = PAD(je32_to_cpu(ri->totlen));
 	raw->next_phys = NULL;
 
-	fn->ofs = ri->offset;
-	fn->size = ri->dsize;
+	fn->ofs = je32_to_cpu(ri->offset);
+	fn->size = je32_to_cpu(ri->dsize);
 	fn->frags = 0;
 	fn->raw = raw;
 
@@ -160,7 +164,10 @@ struct jffs2_full_dnode *jffs2_write_dno
 	raw->next_in_ino = f->inocache->nodes;
 	f->inocache->nodes = raw;
 
-	D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n", flash_ofs, ri->dsize, ri->csize, ri->node_crc, ri->data_crc, ri->totlen));
+	D1(printk(KERN_DEBUG "jffs2_write_dnode wrote node at 0x%08x with dsize 0x%x, csize 0x%x, node_crc 0x%08x, data_crc 0x%08x, totlen 0x%08x\n",
+		  flash_ofs, je32_to_cpu(ri->dsize), je32_to_cpu(ri->csize),
+		  je32_to_cpu(ri->node_crc), je32_to_cpu(ri->data_crc), 
+		  je32_to_cpu(ri->totlen)));
 	if (writelen)
 		*writelen = retlen;
 
@@ -176,10 +183,12 @@ struct jffs2_full_dirent *jffs2_write_di
 	struct iovec vecs[2];
 	int ret;
 
-	D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n", rd->pino, name, name, rd->ino, rd->name_crc));
+	D1(printk(KERN_DEBUG "jffs2_write_dirent(ino #%u, name at *0x%p \"%s\"->ino #%u, name_crc 0x%08x)\n", 
+		  je32_to_cpu(rd->pino), name, name, je32_to_cpu(rd->ino),
+		  je32_to_cpu(rd->name_crc)));
 	writecheck(c, flash_ofs);
 
-	D1(if(rd->hdr_crc != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) {
+	D1(if(je32_to_cpu(rd->hdr_crc) != crc32(0, rd, sizeof(struct jffs2_unknown_node)-4)) {
 		printk(KERN_CRIT "Eep. CRC not correct in jffs2_write_dirent()\n");
 		BUG();
 	}
@@ -201,13 +210,13 @@ struct jffs2_full_dirent *jffs2_write_di
 		return ERR_PTR(-ENOMEM);
 	}
 	raw->flash_offset = flash_ofs;
-	raw->totlen = PAD(rd->totlen);
+	raw->totlen = PAD(je32_to_cpu(rd->totlen));
 	raw->next_in_ino = f->inocache->nodes;
 	f->inocache->nodes = raw;
 	raw->next_phys = NULL;
 
-	fd->version = rd->version;
-	fd->ino = rd->ino;
+	fd->version = je32_to_cpu(rd->version);
+	fd->ino = je32_to_cpu(rd->ino);
 	fd->nhash = full_name_hash(name, strlen(name));
 	fd->type = rd->type;
 	memcpy(fd->name, name, namelen);
@@ -289,20 +298,20 @@ int jffs2_write_inode_range(struct jffs2
 		   that the comprbuf doesn't need to be kfree()d. 
 		*/
 
-		ri->magic = JFFS2_MAGIC_BITMASK;
-		ri->nodetype = JFFS2_NODETYPE_INODE;
-		ri->totlen = sizeof(*ri) + cdatalen;
-		ri->hdr_crc = crc32(0, ri, sizeof(struct jffs2_unknown_node)-4);
-
-		ri->ino = f->inocache->ino;
-		ri->version = ++f->highest_version;
-		ri->isize = max(ri->isize, offset + datalen);
-		ri->offset = offset;
-		ri->csize = cdatalen;
-		ri->dsize = datalen;
+		ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
+		ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
+		ri->totlen = cpu_to_je32(sizeof(*ri) + cdatalen);
+		ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
+
+		ri->ino = cpu_to_je32(f->inocache->ino);
+		ri->version = cpu_to_je32(++f->highest_version);
+		ri->isize = cpu_to_je32(max(je32_to_cpu(ri->isize), offset + datalen));
+		ri->offset = cpu_to_je32(offset);
+		ri->csize = cpu_to_je32(cdatalen);
+		ri->dsize = cpu_to_je32(datalen);
 		ri->compr = comprtype;
-		ri->node_crc = crc32(0, ri, sizeof(*ri)-8);
-		ri->data_crc = crc32(0, comprbuf, cdatalen);
+		ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
+		ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
 
 		fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, phys_ofs, NULL);
 
@@ -367,12 +376,13 @@ int jffs2_do_create(struct jffs2_sb_info
 		return ret;
 	}
 
-	ri->data_crc = 0;
-	ri->node_crc = crc32(0, ri, sizeof(*ri)-8);
+	ri->data_crc = cpu_to_je32(0);
+	ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
 
 	fn = jffs2_write_dnode(c, f, ri, NULL, 0, phys_ofs, &writtenlen);
 
-	D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n", ri->mode));
+	D1(printk(KERN_DEBUG "jffs2_do_create created file with mode 0x%x\n",
+		  je32_to_cpu(ri->mode)));
 
 	if (IS_ERR(fn)) {
 		D1(printk(KERN_DEBUG "jffs2_write_dnode() failed\n"));
@@ -413,19 +423,19 @@ int jffs2_do_create(struct jffs2_sb_info
 
 	down(&dir_f->sem);
 
-	rd->magic = JFFS2_MAGIC_BITMASK;
-	rd->nodetype = JFFS2_NODETYPE_DIRENT;
-	rd->totlen = sizeof(*rd) + namelen;
-	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
+	rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
+	rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
+	rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
+	rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
 
-	rd->pino = dir_f->inocache->ino;
-	rd->version = ++dir_f->highest_version;
+	rd->pino = cpu_to_je32(dir_f->inocache->ino);
+	rd->version = cpu_to_je32(++dir_f->highest_version);
 	rd->ino = ri->ino;
 	rd->mctime = ri->ctime;
 	rd->nsize = namelen;
 	rd->type = DT_REG;
-	rd->node_crc = crc32(0, rd, sizeof(*rd)-8);
-	rd->name_crc = crc32(0, name, namelen);
+	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
+	rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
 	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, &writtenlen);
 
@@ -471,19 +481,19 @@ int jffs2_do_unlink(struct jffs2_sb_info
 	down(&dir_f->sem);
 
 	/* Build a deletion node */
-	rd->magic = JFFS2_MAGIC_BITMASK;
-	rd->nodetype = JFFS2_NODETYPE_DIRENT;
-	rd->totlen = sizeof(*rd) + namelen;
-	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
-
-	rd->pino = dir_f->inocache->ino;
-	rd->version = ++dir_f->highest_version;
-	rd->ino = 0;
-	rd->mctime = CURRENT_TIME;
+	rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
+	rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
+	rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
+	rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
+
+	rd->pino = cpu_to_je32(dir_f->inocache->ino);
+	rd->version = cpu_to_je32(++dir_f->highest_version);
+	rd->ino = cpu_to_je32(0);
+	rd->mctime = cpu_to_je32(CURRENT_TIME);
 	rd->nsize = namelen;
 	rd->type = DT_UNKNOWN;
-	rd->node_crc = crc32(0, rd, sizeof(*rd)-8);
-	rd->name_crc = crc32(0, name, namelen);
+	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
+	rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
 	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, NULL);
 	
@@ -554,21 +564,21 @@ int jffs2_do_link (struct jffs2_sb_info 
 	down(&dir_f->sem);
 
 	/* Build a deletion node */
-	rd->magic = JFFS2_MAGIC_BITMASK;
-	rd->nodetype = JFFS2_NODETYPE_DIRENT;
-	rd->totlen = sizeof(*rd) + namelen;
-	rd->hdr_crc = crc32(0, rd, sizeof(struct jffs2_unknown_node)-4);
-
-	rd->pino = dir_f->inocache->ino;
-	rd->version = ++dir_f->highest_version;
-	rd->ino = ino;
-	rd->mctime = CURRENT_TIME;
+	rd->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
+	rd->nodetype = cpu_to_je16(JFFS2_NODETYPE_DIRENT);
+	rd->totlen = cpu_to_je32(sizeof(*rd) + namelen);
+	rd->hdr_crc = cpu_to_je32(crc32(0, rd, sizeof(struct jffs2_unknown_node)-4));
+
+	rd->pino = cpu_to_je32(dir_f->inocache->ino);
+	rd->version = cpu_to_je32(++dir_f->highest_version);
+	rd->ino = cpu_to_je32(ino);
+	rd->mctime = cpu_to_je32(CURRENT_TIME);
 	rd->nsize = namelen;
 
 	rd->type = type;
 
-	rd->node_crc = crc32(0, rd, sizeof(*rd)-8);
-	rd->name_crc = crc32(0, name, namelen);
+	rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8));
+	rd->name_crc = cpu_to_je32(crc32(0, name, namelen));
 
 	fd = jffs2_write_dirent(c, dir_f, rd, name, namelen, phys_ofs, NULL);
 	


--
dwmw2



To unsubscribe from this list: send the line "unsubscribe jffs-dev" in
the body of a message to majordomo@xxxxxxx.com