[OpenBIOS] r507 - ofw/fs/fatfs

svn at openbios.org svn at openbios.org
Wed Aug 1 05:11:46 CEST 2007


Author: wmb
Date: 2007-08-01 05:11:46 +0200 (Wed, 01 Aug 2007)
New Revision: 507

Modified:
   ofw/fs/fatfs/bpb.fth
   ofw/fs/fatfs/fat.fth
Log:
FAT filesystem - OLPC trac 2609.  Fixed FAT32 cluster allocation bug.
The "next cluster" field in the fsinfo structure was being treated as
a definitive free cluster number, instead of as a hint for where to
begin searching.  In addition, it was off by one - that field
typically contains the number of the most recently written cluster,
whereas the code was treating it as the next available cluster number.


Modified: ofw/fs/fatfs/bpb.fth
===================================================================
--- ofw/fs/fatfs/bpb.fth	2007-07-30 21:08:57 UTC (rev 506)
+++ ofw/fs/fatfs/bpb.fth	2007-08-01 03:11:46 UTC (rev 507)
@@ -91,21 +91,11 @@
 d# 16 constant fat16
 d# 32 constant fat32
 
-: fs-lelop  ( adr op -- )
-   fsinfo @ 0<>  if
-      over lel@ swap execute swap lel!
-      true fsinfos-dirty c!
-   else
-      2drop
-   then
-;
-: fs-free#+  ( -- )  fs_freecluster#  ['] 1+ fs-lelop  ;
-: fs-free#-  ( -- )  fs_freecluster#  ['] 1- fs-lelop  ;
-: fs-#free+  ( -- )  fs_#freeclusters ['] 1+ fs-lelop  ;
-: fs-#free-  ( -- )  fs_#freeclusters ['] 1- fs-lelop  ;
+: fs-#free+  ( -- )  fs_#freeclusters  dup lel@  1+  swap lel!  true fsinfos-dirty c!  ;
+: fs-#free-  ( -- )  fs_#freeclusters  dup lel@  1-  swap lel!  true fsinfos-dirty c!  ;
+: fs-free#!  ( cluster# -- )  fs_freecluster# lel!  true fsinfos-dirty c!  ;
 
 
-
 \ LICENSE_BEGIN
 \ Copyright (c) 2006 FirmWorks
 \ 

Modified: ofw/fs/fatfs/fat.fth
===================================================================
--- ofw/fs/fatfs/fat.fth	2007-07-30 21:08:57 UTC (rev 506)
+++ ofw/fs/fatfs/fat.fth	2007-08-01 03:11:46 UTC (rev 507)
@@ -179,23 +179,20 @@
    max-cl# l@ 1+ fatc-end @  search-up    if  mark-cluster exit  then
    false
 ;
-: allocate-cluster  ( hint-cluster# -- cluster# true  |  false )
-   fsinfo @ 0<>  if
-      fs_#freeclusters lel@ 0=  if
-         drop false
-      else
-         fs_freecluster# lel@ max-cl# l@ >  if
-            (allocate-cluster)
-            dup  if  fs-#free-  then
-         else
-            drop fs_freecluster# lel@  mark-cluster
-            fs-free#+
-            fs-#free-
-         then
-      then
-   else
-      (allocate-cluster)
-   then
+: allocate-cluster  ( hint-cluster# -- false | cluster# true )
+   fsinfo @  if                                    ( hint )
+      fs_#freeclusters lel@   if                   ( hint )
+         fs_freecluster# lel@ max-cl# l@ <=  if    ( hint )
+            drop fs_freecluster# lel@              ( hint' )
+         then                                      ( hint )
+         (allocate-cluster)                        ( false | cluster# true )
+         dup  if  over fs-free#!  fs-#free-  then  ( false | cluster# true )
+      else                                         ( hint )
+         drop false                                ( false )
+      then                                         ( false | cluster# true )
+   else                                            ( hint )
+      (allocate-cluster)                           ( false | cluster# true )
+   then                                            ( false | cluster# true )
 ;
 
 \ Frees first-cl# and all clusters linked after it.
@@ -205,7 +202,7 @@
    while                               ( cluster# )
       dup  cluster@                    ( cluster# next-cluster# )
       0 rot  cluster!                  ( next-cluster# )
-      fs-#free+
+      fsinfo @  if  fs-#free+  then    ( next-cluster# )
    repeat
    drop
    ?flush-fat-cache




More information about the OpenBIOS mailing list