Make nightly build test works.
[bertos.git] / bertos / fs / battfs.c
index a10ef85f68d21192b7d0b140cad1bb29134708be..4f4d48920e659051212f0dbc32fcba8da5e095f1 100644 (file)
  *
  * \brief BattFS: a filesystem for embedded platforms (implementation).
  *
- * \version $Id:$
+ * \version $Id$
  *
  * \author Francesco Sacchi <batt@develer.com>
  *
  */
 
 #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;
@@ -518,6 +522,9 @@ bool battfs_fsck(struct BattFsSuper *disk)
 
        bool start = true;
 
+       /* Uneeded, the first time will be overwritten but useful to silence
+        * the warning for uninitialized value */
+       FSCHECK(readHdr(disk, 0, &prev_hdr));
        for (pgcnt_t page = 0; page < disk->page_count; page++)
        {
                FSCHECK(readHdr(disk, disk->page_array[page], &hdr));
@@ -875,7 +882,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;