Add battfs config file; add shuffle for free blocks.
[bertos.git] / bertos / fs / battfs.c
index a10ef85f68d21192b7d0b140cad1bb29134708be..1ea39c5072e14c45f167cca124308441f2c46812 100644 (file)
  */
 
 #include "battfs.h"
-
+#include "cfg/cfg_battfs.h"
 #include <cfg/debug.h>
 #include <cfg/macros.h> /* MIN, MAX */
 #include <cfg/test.h>
 #include <cpu/byteorder.h> /* cpu_to_xx */
 
-#define LOG_LEVEL       LOG_LVL_INFO
-#define LOG_FORMAT      LOG_FMT_VERBOSE
+#define LOG_LEVEL       BATTFS_LOG_LEVEL
+#define LOG_FORMAT      BATTFS_LOG_FORMAT
 #include <cfg/log.h>
 
 #include <string.h> /* memset, memmove */
@@ -490,10 +490,14 @@ bool battfs_mount(struct BattFsSuper *disk)
        #if LOG_LEVEL >= LOG_LVL_INFO
                dumpPageArray(disk);
        #endif
-       #warning TODO: shuffle free blocks
-       //#if LOG_LEVEL > LOG_LVL_INFO
-       //      dumpPageArray(disk);
-       //#endif
+       #if CONFIG_BATTFS_SHUFFLE_FREE_PAGES
+               SHUFFLE(&disk->page_array[disk->free_page_start], disk->page_count - disk->free_page_start);
+
+               LOG_INFO("Page array after shuffle:\n");
+               #if LOG_LEVEL >= LOG_LVL_INFO
+                       dumpPageArray(disk);
+               #endif
+       #endif
        /* Init list for opened files. */
        LIST_INIT(&disk->file_opened_list);
        return true;
@@ -875,7 +879,7 @@ static bool findFile(BattFsSuper *disk, inode_t inode, pgcnt_t *last)
                else if (hdr.fcs == fcs && hdr.inode < inode)
                        first = page + 1;
                else
-                       *last = page + 1;
+                       *last = page;
        }
        LOG_INFO("Not found: last %d\n", *last);
        return false;