+#define SWAP32(x) ((((x) & 0x000000FF) << 24) | \
+ (((x) & 0x0000FF00) << 8 ) | \
+ (((x) & 0x00FF0000) >> 8 ) | \
+ (((x) & 0xFF000000) >> 24))
+
+#define SWAP16(x) ((((x) & 0x00FF) << 8) | \
+ (((x) & 0xFF00) >> 8))
+
+// This one is easier, since the types are more standard. No funky shifts here.
+static void object_header_little_to_big_endian(yaffs_ObjectHeader* oh)
+{
+ oh->type = SWAP32(oh->type); // GCC makes enums 32 bits.
+ oh->parentObjectId = SWAP32(oh->parentObjectId); // int
+ oh->sum__NoLongerUsed = SWAP16(oh->sum__NoLongerUsed); // __u16 - Not used, but done for completeness.
+ // name = skip. Char array. Not swapped.
+ oh->yst_mode = SWAP32(oh->yst_mode);
+#ifdef CONFIG_YAFFS_WINCE // WinCE doesn't implement this, but we need to just in case.
+ // In fact, WinCE would be *THE* place where this would be an issue!
+ oh->notForWinCE[0] = SWAP32(oh->notForWinCE[0]);
+ oh->notForWinCE[1] = SWAP32(oh->notForWinCE[1]);
+ oh->notForWinCE[2] = SWAP32(oh->notForWinCE[2]);
+ oh->notForWinCE[3] = SWAP32(oh->notForWinCE[3]);
+ oh->notForWinCE[4] = SWAP32(oh->notForWinCE[4]);
+#else
+ // Regular POSIX.
+ oh->yst_uid = SWAP32(oh->yst_uid);
+ oh->yst_gid = SWAP32(oh->yst_gid);
+ oh->yst_atime = SWAP32(oh->yst_atime);
+ oh->yst_mtime = SWAP32(oh->yst_mtime);
+ oh->yst_ctime = SWAP32(oh->yst_ctime);
+#endif
+
+ oh->fileSize = SWAP32(oh->fileSize); // Aiee. An int... signed, at that!
+ oh->equivalentObjectId = SWAP32(oh->equivalentObjectId);
+ // alias - char array.
+ oh->yst_rdev = SWAP32(oh->yst_rdev);
+
+#ifdef CONFIG_YAFFS_WINCE
+ oh->win_ctime[0] = SWAP32(oh->win_ctime[0]);
+ oh->win_ctime[1] = SWAP32(oh->win_ctime[1]);
+ oh->win_atime[0] = SWAP32(oh->win_atime[0]);
+ oh->win_atime[1] = SWAP32(oh->win_atime[1]);
+ oh->win_mtime[0] = SWAP32(oh->win_mtime[0]);
+ oh->win_mtime[1] = SWAP32(oh->win_mtime[1]);
+ oh->roomToGrow[0] = SWAP32(oh->roomToGrow[0]);
+ oh->roomToGrow[1] = SWAP32(oh->roomToGrow[1]);
+ oh->roomToGrow[2] = SWAP32(oh->roomToGrow[2]);
+ oh->roomToGrow[3] = SWAP32(oh->roomToGrow[3]);
+ oh->roomToGrow[4] = SWAP32(oh->roomToGrow[4]);
+ oh->roomToGrow[5] = SWAP32(oh->roomToGrow[5]);
+#else
+ oh->roomToGrow[0] = SWAP32(oh->roomToGrow[0]);
+ oh->roomToGrow[1] = SWAP32(oh->roomToGrow[1]);
+ oh->roomToGrow[2] = SWAP32(oh->roomToGrow[2]);
+ oh->roomToGrow[3] = SWAP32(oh->roomToGrow[3]);
+ oh->roomToGrow[4] = SWAP32(oh->roomToGrow[4]);
+ oh->roomToGrow[5] = SWAP32(oh->roomToGrow[5]);
+ oh->roomToGrow[6] = SWAP32(oh->roomToGrow[6]);
+ oh->roomToGrow[7] = SWAP32(oh->roomToGrow[7]);
+ oh->roomToGrow[8] = SWAP32(oh->roomToGrow[8]);
+ oh->roomToGrow[9] = SWAP32(oh->roomToGrow[9]);
+ oh->roomToGrow[10] = SWAP32(oh->roomToGrow[10]);
+ oh->roomToGrow[11] = SWAP32(oh->roomToGrow[11]);
+#endif
+}
+
+static int write_object_header(int objId, yaffs_ObjectType t, struct stat *s, int parent, const char *name, int equivalentObj, const char * alias)