[openfirmware] r858 - ofw/fs/jffs2

svn at openfirmware.info svn at openfirmware.info
Wed Jul 23 21:57:18 CEST 2008


Author: wmb
Date: 2008-07-23 21:57:18 +0200 (Wed, 23 Jul 2008)
New Revision: 858

Modified:
   ofw/fs/jffs2/jffs2.fth
Log:
OLPC trac 7607 - JFFS2 scanning hang.  If a non-summarized
erase block contained a node whose header spanned a page
boundary, and the second page was all ff's due to not
being written (perhaps because of an unclean shutdown),
the scanning process would loop forever.  This change
fixes that bug, and also adds a new command "debug-jffs2"
that will enable warning messages about bad nodes.
Usage:  ok  debug-jffs2  dir nand:\


Modified: ofw/fs/jffs2/jffs2.fth
===================================================================
--- ofw/fs/jffs2/jffs2.fth	2008-07-23 09:29:00 UTC (rev 857)
+++ ofw/fs/jffs2/jffs2.fth	2008-07-23 19:57:18 UTC (rev 858)
@@ -6,7 +6,13 @@
 defer scan-callout  ' noop to scan-callout
 
 0 value debug-scan?  \ True to display progress reports
+0 value warn?        \ True to warn about bad nodes
+true value first-time?
 
+also forth definitions
+: debug-jffs2  true to warn?  true to first-time?  ;
+previous definitions
+
 0 instance value block-buf    \ Start address of working buffer
 0 instance value eb-end       \ End address of working buffer
 0 value cleanmark?
@@ -89,7 +95,6 @@
 : dma-alloc  ( len -- adr )  " dma-alloc" $call-parent  ;
 : dma-free   ( len -- adr )  " dma-free" $call-parent  ;
 
-true value first-time?
 -1 value partition#
 -1 value #writes
 
@@ -187,16 +192,26 @@
 
 \ Validate the summary; it's all in memory now
 \ The numeric field references are from struct jffs2_raw_summary
-: bad-summary?  ( adr -- flag )
-   dup 6 /l*  crc  ( adr crc )
-   over 7 j@ <>  if  drop true exit  then  \ Exit if bad node CRC
+: bad-summary?  ( page# adr -- flag )
+   dup 6 /l*  crc         ( page# adr crc )
+   over 7 j@ <>  if       ( page# adr )
+      warn?  if           ( page# adr )
+         ." JFFS2 warning: Bad CRC in summary node - eblock# " over page>eblock .x cr
+      then
+      2drop true exit
+   then               \ Exit if bad node CRC
 
    \ Omitting CRC check of just the node header, and the
    \ totlen check, as both are covered by the node CRC.
 
-   dup  8 la+  sumsize -8 la+  crc        ( adr crc )
-   over 6 j@ <>  if  drop true exit  then  \ Exit if bad summary data CRC
-   drop false
+   dup  8 la+  sumsize -8 la+  crc    ( page# adr crc )
+   over 6 j@ <>  if                   ( page# adr )
+      warn?  if                       ( page# adr )
+         ." JFFS2 warning: Bad CRC in summary data - eblock# " over page>eblock .x cr
+      then
+      2drop true exit
+   then  \ Exit if bad summary data CRC   ( page# adr )
+   2drop false
 ;
 
 3 /n* instance buffer: curinum  \ cur-inum, cur-vers, cur-offset
@@ -721,8 +736,8 @@
    block-buf /page + -1 j@                        ( page# magic )
    h# 02851885  <>  if   drop true exit  then     ( page# )
 
-   get-summary   if  true exit  then              ( adr )
-   dup bad-summary?  if  drop true exit then      ( adr )
+   dup get-summary   if  drop true exit  then     ( page# adr )
+   tuck bad-summary?  if drop true exit  then     ( adr )
    scan-summary  false
 ;
 
@@ -763,10 +778,13 @@
                drop false              ( false )
             then
             exit
+         then                          ( adr len )
+         warn?  if                     ( adr len )
+            ." JFFS2 warning: Bad CRC in node header - eblock# " have-eblock# .x
+            ." offset " over block-buf - .x  cr
          then
-      else                             ( adr len )
-         1 /string                     ( adr' len' )
       then                             ( adr len )
+      1 /string                        ( adr' len' )
    repeat                              ( adr len )
    2drop false
 ;




More information about the openfirmware mailing list