<div dir="ltr">Ignoring any specific technical comments from others.<div><br></div><div>(1) Should this have a ticket? Seems impactful and odd enough to since that shows up in release notes.</div><div><br></div><div>(2) Should it also be applied to 5.x with a separate ticket?</div><div><br></div><div>--joel</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 2, 2024 at 4:40 PM Kinsey Moore <<a href="mailto:kinsey.moore@oarcorp.com">kinsey.moore@oarcorp.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On JFFS2 file systems on NOR flash or dataflash that does not have spare<br>
area for metadata and thus does not invoke delayed writes, it is<br>
possible to put the file system into a state where all blocks have been<br>
written to and all files have been deleted from the filesystem. There is<br>
a bug in the JFFS2 file system scan routine that detects this situation<br>
as a corrupted file system since the scan routine relies on "used" space<br>
to discriminate a valid file system when there are blocks that need to<br>
be erased. The correct fix would require a partial rewrite of the scan<br>
routine, so instead this patch tracks the space marked as obsolete along<br>
with space at the end of each block that is otherwise too small to<br>
contain a JFFS2 node so that it can me compared with the dirty space.<br>
Corrupted data (or otherwise non-JFFS2 blocks) will still cause this<br>
check to fail as corrupted data isn't recognized as obsoleted (deleted)<br>
nodes.<br>
---<br>
 cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h |  3 +++<br>
 cpukit/libfs/src/jffs2/src/scan.c        | 24 ++++++++++++++++++++++++<br>
 2 files changed, 27 insertions(+)<br>
<br>
diff --git a/cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h b/cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h<br>
index 4ee43a6f30..7960f92f85 100644<br>
--- a/cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h<br>
+++ b/cpukit/libfs/src/jffs2/src/jffs2_fs_sb.h<br>
@@ -75,6 +75,9 @@ struct jffs2_sb_info {<br>
        uint32_t bad_size;<br>
        uint32_t sector_size;<br>
        uint32_t unchecked_size;<br>
+#ifdef __rtems__<br>
+       uint32_t obsolete_size;<br>
+#endif<br>
<br>
        uint32_t nr_free_blocks;<br>
        uint32_t nr_erasing_blocks;<br>
diff --git a/cpukit/libfs/src/jffs2/src/scan.c b/cpukit/libfs/src/jffs2/src/scan.c<br>
index 10663feb1f..8ac4a40414 100644<br>
--- a/cpukit/libfs/src/jffs2/src/scan.c<br>
+++ b/cpukit/libfs/src/jffs2/src/scan.c<br>
@@ -264,14 +264,32 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)<br>
        }<br>
 #endif<br>
        if (c->nr_erasing_blocks) {<br>
+#ifdef __rtems__<br>
+               if (c->obsolete_size != c->dirty_size) {<br>
+#endif<br>
                if (!c->used_size && !c->unchecked_size &&<br>
                        ((c->nr_free_blocks+empty_blocks+bad_blocks) != c->nr_blocks || bad_blocks == c->nr_blocks)) {<br>
                        pr_notice("Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes\n");<br>
                        pr_notice("empty_blocks %d, bad_blocks %d, c->nr_blocks %d\n",<br>
                                  empty_blocks, bad_blocks, c->nr_blocks);<br>
+#ifdef __rtems__<br>
+                       pr_notice("nr_erasing_blocks %d, used 0x%x, dirty 0x%x, wasted 0x%x, free 0x%x, erasing 0x%x, bad 0x%x, obsolete 0x%x, unchecked 0x%x\n",<br>
+                                 c->nr_erasing_blocks,<br>
+                                 c->used_size,<br>
+                                 c->dirty_size,<br>
+                                 c->wasted_size,<br>
+                                 c->free_size,<br>
+                                 c->erasing_size,<br>
+                                 c->bad_size,<br>
+                                 c->obsolete_size,<br>
+                                 c->unchecked_size);<br>
+#endif<br>
                        ret = -EIO;<br>
                        goto out;<br>
                }<br>
+#ifdef __rtems__<br>
+               }<br>
+#endif<br>
                spin_lock(&c->erase_completion_lock);<br>
                jffs2_garbage_collect_trigger(c);<br>
                spin_unlock(&c->erase_completion_lock);<br>
@@ -646,6 +664,9 @@ scan_more:<br>
                                  sizeof(struct jffs2_unknown_node),<br>
                                  jeb->offset, c->sector_size, ofs,<br>
                                  sizeof(*node));<br>
+#ifdef __rtems__<br>
+                       c->obsolete_size += (jeb->offset + c->sector_size - ofs);<br>
+#endif<br>
                        if ((err = jffs2_scan_dirty_space(c, jeb, (jeb->offset + c->sector_size)-ofs)))<br>
                                return err;<br>
                        break;<br>
@@ -796,6 +817,9 @@ scan_more:<br>
                        if ((err = jffs2_scan_dirty_space(c, jeb, PAD(je32_to_cpu(node->totlen)))))<br>
                                return err;<br>
                        ofs += PAD(je32_to_cpu(node->totlen));<br>
+#ifdef __rtems__<br>
+                       c->obsolete_size += PAD(je32_to_cpu(node->totlen));<br>
+#endif<br>
                        continue;<br>
                }<br>
<br>
-- <br>
2.39.2<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote></div>