[Yaffs] [PATCH] Handle forced endianness while processing ta…

Top Page
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Michał Kępień
To: yaffs
Subject: [Yaffs] [PATCH] Handle forced endianness while processing tags ECC
Convert between little-endian and big-endian byte orders as necessary
while reading and writing ECC for YAFFS2 tags. This makes tags ECC work
properly when the byte order set for a device (using the 'stored_endian'
parameter) necessitates byte order conversions.

Signed-off-by: Michał Kępień <>
This is the simplest/shortest version of this fix as the yaffs_ecc.h
header defines the 'line_parity' and 'line_parity_prime' fields of
'struct yaffs_ecc_other' as unsigned int, which means their size varies
across architectures. This version of this patch assumes that:

  - sizeof(int) == 4 holds for most real-world architectures on which
    this code will run today and in the foreseeable future,

  - since tags ECC is marshalled as a structure of architecture-specific
    size that is stuck to the end of the tags structure, reading/writing
    tags ECC across architectures with different integer type sizes will
    not work anyway (without an additional device parameter and extra
    code handling it), even if this patch handled all of them properly.

I also prepared a more complex version of this patch which properly
handles all possible integer type sizes, but it just seems to me that it
adds too much complexity (additional swap_*() macros in yaffs_endian.h,
new functions using these macros in yaffs_endian.c, a helper function
dispatching execution to the right swapping function depending on
variable size) for little extra value. Please let me know if you would
like me to submit that version instead, though.

yaffs_packedtags2.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/yaffs_packedtags2.c b/yaffs_packedtags2.c
index 905593c..098d5f4 100644
--- a/yaffs_packedtags2.c
+++ b/yaffs_packedtags2.c
@@ -120,10 +120,13 @@ void yaffs_pack_tags2(struct yaffs_dev *dev,
     yaffs_pack_tags2_tags_only(dev, &pt->t, t);

-    if (tags_ecc)
+    if (tags_ecc) {
         yaffs_ecc_calc_other((unsigned char *)&pt->t,
                     sizeof(struct yaffs_packed_tags2_tags_only),
+        yaffs_do_endian_u32(dev, &pt->ecc.line_parity);
+        yaffs_do_endian_u32(dev, &pt->ecc.line_parity_prime);
+    }

 void yaffs_unpack_tags2_tags_only(struct yaffs_dev *dev,
@@ -184,6 +187,8 @@ void yaffs_unpack_tags2(struct yaffs_dev *dev,
         yaffs_ecc_calc_other((unsigned char *)&pt->t,
                 sizeof(struct yaffs_packed_tags2_tags_only),
+        yaffs_do_endian_u32(dev, &ecc.line_parity);
+        yaffs_do_endian_u32(dev, &ecc.line_parity_prime);
         result =
             yaffs_ecc_correct_other((unsigned char *)&pt->t,
                 sizeof(struct yaffs_packed_tags2_tags_only),