shithub: lwext4

Download patch

ref: d812bca336c8d67a5b1a9744b36c0ecbb5baa8b3
parent: 029801c149836ea76776a9bbebe7bed532febdba
parent: 34dd7330431c99292c332c724e0e493b08e40bd6
author: gkostka <kostka.grzegorz@gmail.com>
date: Mon Apr 7 19:36:00 EDT 2014

Merge with test_suite branch.

diff: cannot open b/blockdev/filedev_win//null: file does not exist: 'b/blockdev/filedev_win//null' diff: cannot open a/blockdev/io_raw//null: file does not exist: 'a/blockdev/io_raw//null' diff: cannot open b/fs_test//null: file does not exist: 'b/fs_test//null'
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,71 +7,24 @@
 aux_source_directory(lwext4 LWEXT4_SRC)
 add_library(lwext4  ${LWEXT4_SRC})
 
-
-#EXECUTABLE
-
+#Examples
 if(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m3)
-#Library size print
-add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
-
+    #Library size print
+    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  cortex-m4)
-#Library size print
-add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
-
-#Discoery disco demo
-enable_language(ASM)
-set (STM32F429_DEMO_ASM
-    demos/stm32f429_disco/startup.S
-)
-
-include_directories(demos/stm32f429_disco)
-include_directories(demos/stm32f429_disco/cmsis)
-include_directories(demos/stm32f429_disco/stm/lcd_utils)
-include_directories(demos/stm32f429_disco/stm/stm32f4_spl/inc)
-include_directories(demos/stm32f429_disco/stm/stm32f429)
-include_directories(demos/stm32f429_disco/stm/usb_dev/Core/inc)
-include_directories(demos/stm32f429_disco/stm/usb_host/Core/inc)
-include_directories(demos/stm32f429_disco/stm/usb_host/Class/MSC/inc)
-include_directories(demos/stm32f429_disco/stm/usb_otg/inc)
-include_directories(demos/stm32f429_disco/stm/usb_user)
-
-aux_source_directory(demos/stm32f429_disco STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/cmsis STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/lcd_utils STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/stm32f4_spl/src STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/stm32f429 STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/usb_host/Core/src STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/usb_host/Class/MSC/src STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/usb_otg/src STM32F429_DEMO)
-aux_source_directory(demos/stm32f429_disco/stm/usb_user STM32F429_DEMO)
-
-add_executable(stm324f29_demo ${STM32F429_DEMO} ${STM32F429_DEMO_ASM})
-
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-format")
-set_target_properties(stm324f29_demo PROPERTIES COMPILE_DEFINITIONS "STM32F429_439xx")
-
-set_target_properties(stm324f29_demo PROPERTIES LINK_FLAGS "-T${CMAKE_SOURCE_DIR}/demos/stm32f429_disco/stm32f429.ld")
-target_link_libraries(stm324f29_demo lwext4)
-
-add_custom_target(stm32f429_size ALL DEPENDS stm324f29_demo COMMAND ${SIZE} -B stm324f29_demo)
-
+    #Library size print
+    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
+    #Discoery disco demo
+    include(demos/stm32f429_disco/stm32f429_demo.cmake)
 elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL  bf518)
-#Library size print
-add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
-
+    #Library size print
+    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND ${SIZE} -B liblwext4.a)
 else()
-#Generic example target
-include_directories(blockdev/filedev)
-include_directories(blockdev/io_raw)
-
-aux_source_directory(blockdev/filedev GENERIC_SRC)
-aux_source_directory(blockdev/io_raw GENERIC_SRC)
-aux_source_directory(demos/generic GENERIC_SRC)
-
-add_executable(fileimage_demo ${GENERIC_SRC})
-target_link_libraries(fileimage_demo lwext4)
-add_custom_target(size ALL DEPENDS lwext4 COMMAND size -B liblwext4.a)
+    #Library size print
+    add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND size -B liblwext4.a)
+    #Generic example target
+    include(demos/generic/generic.cmake)
+    include(fs_test/fs_test.cmake)
 endif()
 
 #DISTRIBUTION
--- a/Makefile
+++ b/Makefile
@@ -32,11 +32,22 @@
 all: generic bf518 cortex-m3 cortex-m4 generic
 
 
-	
 clean:
 	rm -R -f build_bf518
 	rm -R -f build_cortex-m3
 	rm -R -f build_cortex-m4
 	rm -R -f build_generic
+	rm -R -f ext_images
+	
+unpack_images:
+	rm -R -f ext_images
+	7z x ext_images.7z
 
+	
+include fs_test.mk
+
+
+	
+
+	
 	
\ No newline at end of file
--- a/blockdev/filedev/ext4_filedev.c
+++ b/blockdev/filedev/ext4_filedev.c
@@ -45,7 +45,7 @@
 /**@brief   Image file descriptor.*/
 static FILE *dev_file;
 
-#define DROP_LINUXCACHE_BUFFERS 1
+#define DROP_LINUXCACHE_BUFFERS 0
 
 
 /**********************BLOCKDEV INTERFACE**************************************/
@@ -69,9 +69,6 @@
 );
 
 /******************************************************************************/
-EXT4_BCACHE_STATIC_INSTANCE(__cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
-
-/******************************************************************************/
 static int filedev_open(struct ext4_blockdev *bdev)
 {
     dev_file = fopen(fname, "r+b");
@@ -137,13 +134,6 @@
     return EOK;
 }
 
-
-/******************************************************************************/
-
-struct ext4_bcache* ext4_filecache_get(void)
-{
-    return &__cache;
-}
 /******************************************************************************/
 struct ext4_blockdev* ext4_filedev_get(void)
 {
--- a/blockdev/filedev/ext4_filedev.h
+++ b/blockdev/filedev/ext4_filedev.h
@@ -34,13 +34,10 @@
 #include <stdint.h>
 #include <stdbool.h>
 
-/**@brief   Filecache get.*/
-struct ext4_bcache*   ext4_filecache_get(void);
-
 /**@brief   File blockdev get.*/
 struct ext4_blockdev* ext4_filedev_get(void);
 
-/**@brief   Filename set.*/
+/**@brief   Set filename to open.*/
 void ext4_filedev_filename(const char *n);
 
 #endif /* EXT4_FILEDEV_H_ */
--- /dev/null
+++ b/blockdev/filedev_win/io_raw.c
@@ -1,0 +1,192 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+#include <ext4_errno.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+#ifdef WIN32
+#include <windows.h>
+#include <winioctl.h>
+
+
+/**@brief   Default filename.*/
+static const char *fname = "ext2";
+
+/**@brief   IO block size.*/
+#define EXT4_IORAW_BSIZE      512
+
+/**@brief   Image file descriptor.*/
+static HANDLE dev_file;
+
+
+/**********************BLOCKDEV INTERFACE**************************************/
+static int io_raw_open(struct ext4_blockdev *bdev);
+static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+    uint32_t blk_cnt);
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
+    uint64_t blk_id, uint32_t blk_cnt);
+static int io_raw_close(struct  ext4_blockdev *bdev);
+
+
+
+
+/******************************************************************************/
+EXT4_BLOCKDEV_STATIC_INSTANCE(
+    _filedev,
+    EXT4_IORAW_BSIZE,
+    0,
+    io_raw_open,
+    io_raw_bread,
+    io_raw_bwrite,
+    io_raw_close
+);
+
+/******************************************************************************/
+static int io_raw_open(struct ext4_blockdev *bdev)
+{
+    char path[64];
+    DISK_GEOMETRY   pdg;
+    uint64_t disk_size;
+    BOOL bResult   = FALSE;
+    DWORD junk;
+
+    sprintf(path, "\\\\.\\%s", fname);
+
+    dev_file = CreateFile (path,
+            GENERIC_READ | GENERIC_WRITE,
+            FILE_SHARE_WRITE | FILE_SHARE_READ,
+            NULL,
+            OPEN_EXISTING,
+            FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
+            NULL);
+
+    if (dev_file == INVALID_HANDLE_VALUE){
+        return EIO;
+    }
+
+    bResult = DeviceIoControl(dev_file,
+            IOCTL_DISK_GET_DRIVE_GEOMETRY,
+            NULL, 0,
+            &pdg, sizeof(pdg),
+            &junk,
+            (LPOVERLAPPED) NULL);
+
+    if(bResult == FALSE){
+        CloseHandle(dev_file);
+        return EIO;
+    }
+
+
+    disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
+            (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
+
+    _filedev.ph_bsize = pdg.BytesPerSector;
+    _filedev.ph_bcnt  = disk_size / pdg.BytesPerSector;
+
+
+    return EOK;
+}
+
+/******************************************************************************/
+
+static int io_raw_bread(struct  ext4_blockdev *bdev, void *buf, uint64_t blk_id,
+    uint32_t blk_cnt)
+{
+    long hipart = blk_id >> (32-9);
+    long lopart = blk_id << 9;
+    long err;
+
+    SetLastError (0);
+    lopart = SetFilePointer (dev_file, lopart, &hipart, FILE_BEGIN);
+
+    if (lopart == -1  &&  NO_ERROR != (err = GetLastError ()))
+    {
+        return EIO;
+    }
+
+    DWORD   n;
+
+    if (!ReadFile (dev_file, buf, blk_cnt * 512, &n, NULL))
+    {
+        err = GetLastError ();
+        return EIO;
+    }
+    return EOK;
+}
+
+/******************************************************************************/
+static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
+    uint64_t blk_id, uint32_t blk_cnt)
+{
+    long hipart = blk_id >> (32-9);
+    long lopart = blk_id << 9;
+    long err;
+
+    SetLastError (0);
+    lopart = SetFilePointer (dev_file, lopart, &hipart, FILE_BEGIN);
+
+    if (lopart == -1  &&  NO_ERROR != (err = GetLastError ()))
+    {
+        return EIO;
+    }
+
+    DWORD   n;
+
+    if (!WriteFile (dev_file, buf, blk_cnt * 512, &n, NULL))
+    {
+        err = GetLastError ();
+        return EIO;
+    }
+    return EOK;
+}
+
+/******************************************************************************/
+static int io_raw_close(struct  ext4_blockdev *bdev)
+{
+    CloseHandle(dev_file);
+    return EOK;
+}
+
+/******************************************************************************/
+struct  ext4_blockdev* ext4_io_raw_dev_get(void)
+{
+    return &_filedev;
+}
+/******************************************************************************/
+void ext4_io_raw_filename(const char *n)
+{
+    fname = n;
+}
+
+/******************************************************************************/
+#endif
+
--- /dev/null
+++ b/blockdev/filedev_win/io_raw.h
@@ -1,0 +1,44 @@
+/*
+ * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef IO_RAW_H_
+#define IO_RAW_H_
+
+#include <ext4_config.h>
+#include <ext4_blockdev.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+
+
+/**@brief   IO raw blockdev get.*/
+struct  ext4_blockdev* ext4_io_raw_dev_get(void);
+
+/**@brief   Set filrname to open.*/
+void    ext4_io_raw_filename(const char *n);
+
+#endif /* IO_RAW_H_ */
--- a/blockdev/io_raw/io_raw.c
+++ /dev/null
@@ -1,202 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-#include <ext4_errno.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-
-#ifdef WIN32
-#include <windows.h>
-#include <winioctl.h>
-
-
-/**@brief   Default filename.*/
-static const char *fname = "ext2";
-
-/**@brief   IO block size.*/
-#define EXT4_IORAW_BSIZE      512
-
-/**@brief   Image file descriptor.*/
-static HANDLE dev_file;
-
-
-/**********************BLOCKDEV INTERFACE**************************************/
-static int io_raw_open(struct ext4_blockdev *bdev);
-static int io_raw_bread(struct ext4_blockdev *bdev, void *buf, uint64_t blk_id,
-    uint32_t blk_cnt);
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
-    uint64_t blk_id, uint32_t blk_cnt);
-static int io_raw_close(struct  ext4_blockdev *bdev);
-
-
-
-
-/******************************************************************************/
-EXT4_BLOCKDEV_STATIC_INSTANCE(
-    _filedev,
-    EXT4_IORAW_BSIZE,
-    0,
-    io_raw_open,
-    io_raw_bread,
-    io_raw_bwrite,
-    io_raw_close
-);
-
-/******************************************************************************/
-EXT4_BCACHE_STATIC_INSTANCE(__cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
-
-/******************************************************************************/
-static int io_raw_open(struct ext4_blockdev *bdev)
-{
-    char path[64];
-    DISK_GEOMETRY   pdg;
-    uint64_t disk_size;
-    BOOL bResult   = FALSE;
-    DWORD junk;
-
-    sprintf(path, "\\\\.\\%s", fname);
-
-    dev_file = CreateFile (path,
-            GENERIC_READ | GENERIC_WRITE,
-            FILE_SHARE_WRITE | FILE_SHARE_READ,
-            NULL,
-            OPEN_EXISTING,
-            FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
-            NULL);
-
-    if (dev_file == INVALID_HANDLE_VALUE){
-        return EIO;
-    }
-
-    bResult = DeviceIoControl(dev_file,
-            IOCTL_DISK_GET_DRIVE_GEOMETRY,
-            NULL, 0,
-            &pdg, sizeof(pdg),
-            &junk,
-            (LPOVERLAPPED) NULL);
-
-    if(bResult == FALSE){
-        CloseHandle(dev_file);
-        return EIO;
-    }
-
-
-    disk_size = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
-            (ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
-
-    _filedev.ph_bsize = pdg.BytesPerSector;
-    _filedev.ph_bcnt  = disk_size / pdg.BytesPerSector;
-
-
-    return EOK;
-}
-
-/******************************************************************************/
-
-static int io_raw_bread(struct  ext4_blockdev *bdev, void *buf, uint64_t blk_id,
-    uint32_t blk_cnt)
-{
-    long hipart = blk_id >> (32-9);
-    long lopart = blk_id << 9;
-    long err;
-
-    SetLastError (0);
-    lopart = SetFilePointer (dev_file, lopart, &hipart, FILE_BEGIN);
-
-    if (lopart == -1  &&  NO_ERROR != (err = GetLastError ()))
-    {
-        return EIO;
-    }
-
-    DWORD   n;
-
-    if (!ReadFile (dev_file, buf, blk_cnt * 512, &n, NULL))
-    {
-        err = GetLastError ();
-        return EIO;
-    }
-    return EOK;
-}
-
-/******************************************************************************/
-static int io_raw_bwrite(struct ext4_blockdev *bdev, const void *buf,
-    uint64_t blk_id, uint32_t blk_cnt)
-{
-    long hipart = blk_id >> (32-9);
-    long lopart = blk_id << 9;
-    long err;
-
-    SetLastError (0);
-    lopart = SetFilePointer (dev_file, lopart, &hipart, FILE_BEGIN);
-
-    if (lopart == -1  &&  NO_ERROR != (err = GetLastError ()))
-    {
-        return EIO;
-    }
-
-    DWORD   n;
-
-    if (!WriteFile (dev_file, buf, blk_cnt * 512, &n, NULL))
-    {
-        err = GetLastError ();
-        return EIO;
-    }
-    return EOK;
-}
-
-/******************************************************************************/
-static int io_raw_close(struct  ext4_blockdev *bdev)
-{
-    CloseHandle(dev_file);
-    return EOK;
-}
-
-
-/******************************************************************************/
-
-struct  ext4_bcache* ext4_io_raw_cache_get(void)
-{
-    return &__cache;
-}
-/******************************************************************************/
-struct  ext4_blockdev* ext4_io_raw_dev_get(void)
-{
-    return &_filedev;
-}
-/******************************************************************************/
-void ext4_io_raw_filename(const char *n)
-{
-    fname = n;
-}
-
-/******************************************************************************/
-#endif
-
--- a/blockdev/io_raw/io_raw.h
+++ /dev/null
@@ -1,46 +1,0 @@
-/*
- * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-#ifndef IO_RAW_H_
-#define IO_RAW_H_
-
-#include <ext4_config.h>
-#include <ext4_blockdev.h>
-
-#include <stdint.h>
-#include <stdbool.h>
-
-
-/**@brief   IO raw get.*/
-struct  ext4_bcache*   ext4_io_raw_cache_get(void);
-
-/**@brief   IO raw blockdev get.*/
-struct  ext4_blockdev* ext4_io_raw_dev_get(void);
-
-void    ext4_io_raw_filename(const char *n);
-
-#endif /* IO_RAW_H_ */
--- /dev/null
+++ b/demos/generic/generic.cmake
@@ -1,0 +1,9 @@
+include_directories(blockdev/filedev)
+include_directories(blockdev/filedev_win)
+
+aux_source_directory(blockdev/filedev GENERIC_SRC)
+aux_source_directory(blockdev/filedev_win GENERIC_SRC)
+aux_source_directory(demos/generic GENERIC_SRC)
+
+add_executable(fileimage_demo ${GENERIC_SRC})
+target_link_libraries(fileimage_demo lwext4)
\ No newline at end of file
--- a/demos/generic/main.c
+++ b/demos/generic/main.c
@@ -79,8 +79,11 @@
 /**@brief   Block device handle.*/
 static struct ext4_blockdev *bd;
 
+/**@brief   Static cache instance*/
+EXT4_BCACHE_STATIC_INSTANCE(_lwext4_cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
+
 /**@brief   Block cache handle.*/
-static struct ext4_bcache   *bc;
+static struct ext4_bcache   *bc = &_lwext4_cache;
 
 static const char *usage = "                                    \n\
 Welcome in ext4 generic demo.                                   \n\
@@ -97,6 +100,10 @@
     --wpart  - windows partition mode                           \n\
 \n";
 
+
+
+
+
 static char* entry_to_str(uint8_t type)
 {
     switch(type){
@@ -370,8 +377,7 @@
 {
     ext4_filedev_filename(input_name);
     bd = ext4_filedev_get();
-    bc = ext4_filecache_get();
-    if(!bd || !bc){
+    if(!bd){
         printf("Block device ERROR\n");
         return false;
     }
@@ -383,14 +389,13 @@
 #ifdef WIN32
     ext4_io_raw_filename(input_name);
     bd = ext4_io_raw_dev_get();
-    bc = ext4_io_raw_cache_get();
-    if(!bd || !bc){
+    if(!bd){
         printf("Block device ERROR\n");
         return false;
     }
     return true;
 #else
-    printf("open_winpartition: this mode shouls be used only under windows !\n");
+    printf("open_winpartition: this mode should be used only under windows !\n");
     return false;
 #endif
 }
--- a/demos/stm32f429_disco/main.c
+++ b/demos/stm32f429_disco/main.c
@@ -57,7 +57,7 @@
 static int rw_count = 100;
 
 /**@brief   Directory test count*/
-static int dir_cnt  = 10;
+static int dir_cnt  = 50;
 
 /**@brief   Static or dynamic cache mode*/
 static bool cache_mode = false;
@@ -215,6 +215,7 @@
     }
 
 
+
     printf("Add files to: /mp/dir1\n");
     for (i = 0; i < len; ++i) {
         sprintf(path, "/mp/dir1/f%d", i);
@@ -431,6 +432,7 @@
     if(!mount())
         return EXIT_FAILURE;
 
+    ext4_cache_write_back("/mp/", 1);
     cleanup();
 
     if(sbstat){
@@ -464,6 +466,7 @@
         block_stats();
     }
 
+    ext4_cache_write_back("/mp/", 0);
     if(!umount())
         return EXIT_FAILURE;
 
--- /dev/null
+++ b/demos/stm32f429_disco/stm32f429_demo.cmake
@@ -1,0 +1,38 @@
+#Discoery disco demo
+enable_language(ASM)
+set (STM32F429_DEMO_ASM
+    demos/stm32f429_disco/startup.S
+)
+
+
+include_directories(demos/stm32f429_disco)
+include_directories(demos/stm32f429_disco/cmsis)
+include_directories(demos/stm32f429_disco/stm/lcd_utils)
+include_directories(demos/stm32f429_disco/stm/stm32f4_spl/inc)
+include_directories(demos/stm32f429_disco/stm/stm32f429)
+include_directories(demos/stm32f429_disco/stm/usb_dev/Core/inc)
+include_directories(demos/stm32f429_disco/stm/usb_host/Core/inc)
+include_directories(demos/stm32f429_disco/stm/usb_host/Class/MSC/inc)
+include_directories(demos/stm32f429_disco/stm/usb_otg/inc)
+include_directories(demos/stm32f429_disco/stm/usb_user)
+
+aux_source_directory(demos/stm32f429_disco STM32F429_DEMO)
+aux_source_directory(demos/stm32f429_disco/cmsis STM32F429_DEMO)
+aux_source_directory(demos/stm32f429_disco/stm/lcd_utils STM32F429_DEMO)
+aux_source_directory(demos/stm32f429_disco/stm/stm32f4_spl/src STM32F429_DEMO)
+aux_source_directory(demos/stm32f429_disco/stm/stm32f429 STM32F429_DEMO)
+aux_source_directory(demos/stm32f429_disco/stm/usb_host/Core/src STM32F429_DEMO)
+aux_source_directory(demos/stm32f429_disco/stm/usb_host/Class/MSC/src STM32F429_DEMO)
+aux_source_directory(demos/stm32f429_disco/stm/usb_otg/src STM32F429_DEMO)
+aux_source_directory(demos/stm32f429_disco/stm/usb_user STM32F429_DEMO)
+
+add_executable(stm324f29_demo ${STM32F429_DEMO} ${STM32F429_DEMO_ASM})
+
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-unused-parameter")
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_FLAGS "-Wno-format")
+set_target_properties(stm324f29_demo PROPERTIES COMPILE_DEFINITIONS "STM32F429_439xx")
+
+set_target_properties(stm324f29_demo PROPERTIES LINK_FLAGS "-T${CMAKE_SOURCE_DIR}/demos/stm32f429_disco/stm32f429.ld")
+target_link_libraries(stm324f29_demo lwext4)
+
+add_custom_target(stm32f429_size ALL DEPENDS stm324f29_demo COMMAND ${SIZE} -B stm324f29_demo)
\ No newline at end of file
--- /dev/null
+++ b/fs_test.mk
@@ -1,0 +1,507 @@
+
+ifeq ($(OS),Windows_NT)
+LWEXT4_CLIENT = @build_generic\\lwext4_client
+LWEXT4_SERVER = @build_generic\\lwext4_server
+else
+LWEXT4_CLIENT = @build_generic/lwext4_client
+LWEXT4_SERVER = @build_generic/lwext4_server
+endif
+
+TEST_DIR = /test
+
+t0:
+	@echo "T0: Device register test:" 
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+
+t1:
+	@echo "T1: Single mount-umount test:" 
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "umount /"
+
+t2:
+	@echo "T2: Multiple mount-umount test:" 
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "umount /"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "umount /"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "umount /"
+
+t3:
+	@echo "T3: Test dir create/remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 0"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"
+	
+t4:
+	@echo "T4: 10 files create + write + read + remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_fcreate $(TEST_DIR) /f 10"
+	$(LWEXT4_CLIENT) -c "multi_fwrite $(TEST_DIR) /f 10 1024"
+	$(LWEXT4_CLIENT) -c "multi_fread $(TEST_DIR) /f 10 1024"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 10"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	$(LWEXT4_CLIENT) -c "multi_fremove  $(TEST_DIR) /f 10"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"
+	
+t5:
+	@echo "T5: 100 files create + write + read + remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_fcreate $(TEST_DIR) /f 100"
+	$(LWEXT4_CLIENT) -c "multi_fwrite $(TEST_DIR) /f 100 1024"
+	$(LWEXT4_CLIENT) -c "multi_fread $(TEST_DIR) /f 100 1024"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 100"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	$(LWEXT4_CLIENT) -c "multi_fremove  $(TEST_DIR) /f 100"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"
+
+t6:
+	@echo "T6: 1000 files create + write + read + remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_fcreate $(TEST_DIR) /f 1000"
+	$(LWEXT4_CLIENT) -c "multi_fwrite $(TEST_DIR) /f 1000 1024"
+	$(LWEXT4_CLIENT) -c "multi_fread $(TEST_DIR) /f 1000 1024"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 1000"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	$(LWEXT4_CLIENT) -c "multi_fremove  $(TEST_DIR) /f 1000"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"
+
+t7:
+	@echo "T7: 10 dirs create + remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_dcreate $(TEST_DIR) /d 10"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 10"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	$(LWEXT4_CLIENT) -c "multi_dremove $(TEST_DIR) /d 10"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"
+	
+t8:
+	@echo "T8: 100 dirs create + remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_dcreate $(TEST_DIR) /d 100"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 100"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	$(LWEXT4_CLIENT) -c "multi_dremove $(TEST_DIR) /d 100"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"
+
+t9:
+	@echo "T9: 1000 dirs create + remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_dcreate $(TEST_DIR) /d 1000"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 1000"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	$(LWEXT4_CLIENT) -c "multi_dremove $(TEST_DIR) /d 1000"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t10:
+	@echo "T10: 10 entries (dir) dir recursive remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_dcreate $(TEST_DIR) /d 10"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 10"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t11:
+	@echo "T11: 100 entries (dir) dir recursive remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_dcreate $(TEST_DIR) /d 100"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 100"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+
+t12:
+	@echo "T12: 1000 entries (dir) dir recursive remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_dcreate $(TEST_DIR) /d 1000"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 1000"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t13:
+	@echo "T13: 10 entries (files) dir recursive remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_fcreate $(TEST_DIR) /f 10"
+	$(LWEXT4_CLIENT) -c "multi_fwrite $(TEST_DIR) /f 10 1024"
+	$(LWEXT4_CLIENT) -c "multi_fread $(TEST_DIR) /f 10 1024"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 10"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t14:
+	@echo "T14: 100 entries (files) dir recursive remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_fcreate $(TEST_DIR) /f 100"
+	$(LWEXT4_CLIENT) -c "multi_fwrite $(TEST_DIR) /f 100 1024"
+	$(LWEXT4_CLIENT) -c "multi_fread $(TEST_DIR) /f 100 1024"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 100"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t15:
+	@echo "T15: 1000 entries (files) dir recursive remove:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "multi_fcreate $(TEST_DIR) /f 1000"
+	$(LWEXT4_CLIENT) -c "multi_fwrite $(TEST_DIR) /f 1000 1024"
+	$(LWEXT4_CLIENT) -c "multi_fread $(TEST_DIR) /f 1000 1024"
+	$(LWEXT4_CLIENT) -c "dir_open 0 $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "dir_entry_get 0 1000"
+	$(LWEXT4_CLIENT) -c "dir_close 0"
+	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+
+
+t16:	
+	@echo "T16: 8kB file write/read:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "fopen 0 $(TEST_DIR)/test.txt wb+"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 0"
+	
+	$(LWEXT4_CLIENT) -c "fwrite 0 0 8192 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 8192"
+	$(LWEXT4_CLIENT) -c "fsize 0 8192"
+	
+	$(LWEXT4_CLIENT) -c "fseek 0 0 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 8192"
+	
+	$(LWEXT4_CLIENT) -c "fread 0 0  8192 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 8192"
+	$(LWEXT4_CLIENT) -c "fsize 0 8192"
+	
+	$(LWEXT4_CLIENT) -c "fclose 0"
+	$(LWEXT4_CLIENT) -c "fremove $(TEST_DIR)/test.txt"	
+		
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"		
+	
+t17:	
+	@echo "T17: 64kB file write/read:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "fopen 0 $(TEST_DIR)/test.txt wb+"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 0"
+	
+	$(LWEXT4_CLIENT) -c "fwrite 0 0 65536 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 65536"
+	$(LWEXT4_CLIENT) -c "fsize 0 65536"
+	
+	$(LWEXT4_CLIENT) -c "fseek 0 0 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 65536"
+	
+	$(LWEXT4_CLIENT) -c "fread 0 0  65536 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 65536"
+	$(LWEXT4_CLIENT) -c "fsize 0 65536"
+	
+	$(LWEXT4_CLIENT) -c "fclose 0"
+	$(LWEXT4_CLIENT) -c "fremove $(TEST_DIR)/test.txt"	
+		
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t18:	
+	@echo "T18: 512kB file write/read:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "fopen 0 $(TEST_DIR)/test.txt wb+"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 0"
+	
+	$(LWEXT4_CLIENT) -c "fwrite 0 0 524288 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 524288"
+	$(LWEXT4_CLIENT) -c "fsize 0 524288"
+	
+	$(LWEXT4_CLIENT) -c "fseek 0 0 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 524288"
+	
+	$(LWEXT4_CLIENT) -c "fread 0 0  524288 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 524288"
+	$(LWEXT4_CLIENT) -c "fsize 0 524288"
+	
+	$(LWEXT4_CLIENT) -c "fclose 0"
+	$(LWEXT4_CLIENT) -c "fremove $(TEST_DIR)/test.txt"	
+		
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t19:	
+	@echo "T19: 4MB file write/read:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "fopen 0 $(TEST_DIR)/test.txt wb+"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 0"
+	
+	$(LWEXT4_CLIENT) -c "fwrite 0 0 4194304 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 4194304"
+	$(LWEXT4_CLIENT) -c "fsize 0 4194304"
+	
+	$(LWEXT4_CLIENT) -c "fseek 0 0 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 4194304"
+	
+	$(LWEXT4_CLIENT) -c "fread 0 0  4194304 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 4194304"
+	$(LWEXT4_CLIENT) -c "fsize 0 4194304"
+	
+	$(LWEXT4_CLIENT) -c "fclose 0"
+	$(LWEXT4_CLIENT) -c "fremove $(TEST_DIR)/test.txt"	
+		
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t20:	
+	@echo "T20: 32MB file write/read:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "fopen 0 $(TEST_DIR)/test.txt wb+"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 0"
+	
+	$(LWEXT4_CLIENT) -c "fwrite 0 0 33554432 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 33554432"
+	$(LWEXT4_CLIENT) -c "fsize 0 33554432"
+	
+	$(LWEXT4_CLIENT) -c "fseek 0 0 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 33554432"
+	
+	$(LWEXT4_CLIENT) -c "fread 0 0  33554432 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 33554432"
+	$(LWEXT4_CLIENT) -c "fsize 0 33554432"
+	
+	$(LWEXT4_CLIENT) -c "fclose 0"
+	$(LWEXT4_CLIENT) -c "fremove $(TEST_DIR)/test.txt"	
+
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t21:	
+	@echo "T21: 128MB file write/read:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "fopen 0 $(TEST_DIR)/test.txt wb+"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 0"
+	
+	$(LWEXT4_CLIENT) -c "fwrite 0 0 134217728 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 134217728"
+	$(LWEXT4_CLIENT) -c "fsize 0 134217728"
+	
+	$(LWEXT4_CLIENT) -c "fseek 0 0 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 134217728"
+	
+	$(LWEXT4_CLIENT) -c "fread 0 0  134217728 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 134217728"
+	$(LWEXT4_CLIENT) -c "fsize 0 134217728"
+	
+	$(LWEXT4_CLIENT) -c "fclose 0"
+
+	$(LWEXT4_CLIENT) -c "fremove $(TEST_DIR)/test.txt"	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+t22:	
+	@echo "T22: 1GB file write/read:"
+	$(LWEXT4_CLIENT) -c "device_register 0 0 bdev"
+	$(LWEXT4_CLIENT) -c "mount bdev /"
+	$(LWEXT4_CLIENT) -c "stats_save /"
+	$(LWEXT4_CLIENT) -c "dir_mk $(TEST_DIR)"
+	
+	$(LWEXT4_CLIENT) -c "fopen 0 $(TEST_DIR)/test.txt wb+"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 0"
+	
+	$(LWEXT4_CLIENT) -c "fwrite 0 0 1073741824 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 1073741824"
+	$(LWEXT4_CLIENT) -c "fsize 0 1073741824"
+	
+	$(LWEXT4_CLIENT) -c "fseek 0 0 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 0"
+	$(LWEXT4_CLIENT) -c "fsize 0 1073741824"
+	
+	$(LWEXT4_CLIENT) -c "fread 0 0  1073741824 0"
+	
+	$(LWEXT4_CLIENT) -c "ftell 0 1073741824"
+	$(LWEXT4_CLIENT) -c "fsize 0 1073741824"
+	
+	$(LWEXT4_CLIENT) -c "fclose 0"
+	
+	$(LWEXT4_CLIENT) -c "fremove $(TEST_DIR)/test.txt"	
+	$(LWEXT4_CLIENT) -c "dir_rm $(TEST_DIR)"
+	$(LWEXT4_CLIENT) -c "stats_check /"
+	$(LWEXT4_CLIENT) -c "umount /"	
+	
+
+server_ext2:
+	$(LWEXT4_SERVER) -i ext_images/ext2
+
+server_ext3:
+	$(LWEXT4_SERVER) -i ext_images/ext3
+	
+server_ext4:
+	$(LWEXT4_SERVER) -i ext_images/ext4
+
+all_tests: t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20
\ No newline at end of file
--- /dev/null
+++ b/fs_test/fs_test.cmake
@@ -1,0 +1,17 @@
+include_directories(blockdev/filedev)
+include_directories(blockdev/filedev_win)
+
+aux_source_directory(blockdev/filedev BLOCKDEV_SRC)
+aux_source_directory(blockdev/filedev_win BLOCKDEV_SRC)
+
+
+add_executable(lwext4_server fs_test/lwext4_server.c ${BLOCKDEV_SRC})
+target_link_libraries(lwext4_server lwext4)
+if(WIN32)
+target_link_libraries(lwext4_server ws2_32)
+endif(WIN32)
+add_executable(lwext4_client fs_test/lwext4_client.c ${BLOCKDEV_SRC})
+target_link_libraries(lwext4_client lwext4)
+if(WIN32)
+target_link_libraries(lwext4_client ws2_32)
+endif(WIN32)
\ No newline at end of file
--- /dev/null
+++ b/fs_test/lwext4_client.c
@@ -1,0 +1,192 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <getopt.h>
+
+#ifdef WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+static int inet_pton(int af, const char *src, void *dst);
+
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/types.h>
+#endif
+
+static int winsock_init(void);
+static void winsock_fini(void);
+
+/**@brief   Default server addres.*/
+static char *server_addr = "127.0.0.1";
+
+/**@brief   Default connection port.*/
+static int connection_port = 1234;
+
+/**@brief   Call op*/
+static char *op_code;
+
+static const char *usage = "                                    \n\
+Welcome in lwext4_client.                                       \n\
+Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)  \n\
+Usage:                                                          \n\
+    --call (-c) - call opt                                      \n\
+    --port (-p) - server port                                   \n\
+    --addr (-a) - server ip address                             \n\
+\n";
+
+
+
+static int client_connect(void)
+{
+    int fd = 0;
+    struct sockaddr_in serv_addr;
+
+    if(winsock_init() < 0) {
+        printf("winsock_init error\n");
+        exit(-1);
+    }
+
+    memset(&serv_addr, '0', sizeof(serv_addr));
+    fd = socket(AF_INET, SOCK_STREAM, 0);
+    if(fd < 0) {
+        printf("socket() error: %s\n", strerror(errno));
+        exit(-1);
+    }
+
+    serv_addr.sin_family = AF_INET;
+    serv_addr.sin_port = htons(connection_port);
+
+    if(!inet_pton(AF_INET, server_addr, &serv_addr.sin_addr)){
+        printf("inet_pton() error\n");
+        exit(-1);
+    }
+
+    if(connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))){
+        printf("connect() error: %s\n", strerror(errno));
+        exit(-1);
+    }
+
+    return fd;
+}
+
+
+
+static bool parse_opt(int argc, char **argv)
+{
+    int option_index = 0;
+    int c;
+
+    static struct option long_options[] =
+    {
+            {"call",    required_argument, 0, 'c'},
+            {"port",    required_argument, 0, 'p'},
+            {"addr",    required_argument, 0, 'a'},
+            {0, 0, 0, 0}
+    };
+
+    while(-1 != (c = getopt_long (argc, argv, "c:p:a:", long_options, &option_index))) {
+
+        switch(c){
+        case 'a':
+            server_addr = optarg;
+            break;
+        case 'p':
+            connection_port = atoi(optarg);
+            break;
+        case 'c':
+            op_code = optarg;
+            break;
+        default:
+            printf("%s", usage);
+            return false;
+
+        }
+    }
+    return true;
+}
+
+
+int main(int argc, char *argv[])
+{
+    int sockfd;
+    int n;
+    int rc;
+    char recvBuff[1024];
+
+    if(!parse_opt(argc, argv))
+        return -1;
+
+    sockfd = client_connect();
+
+
+    n = send(sockfd, op_code, strlen(op_code), 0);
+    if(n < 0) {
+        printf("\tWrite error: %s fd = %d\n", strerror(errno), sockfd);
+        return -1;
+    }
+
+    n = recv(sockfd, (void *)&rc, sizeof(rc), 0);
+    if(n < 0) {
+        printf("\tWrite error: %s fd = %d\n", strerror(errno), sockfd);
+        return -1;
+    }
+
+    printf("rc: %d %s\n", rc, strerror(rc));
+    if(rc)
+        printf("\t%s\n",op_code);
+
+    return rc;
+}
+
+static int winsock_init(void)
+{
+#if WIN32
+    int rc;
+    static WSADATA wsaData;
+    rc = WSAStartup(MAKEWORD(2,2), &wsaData);
+    if (rc != 0) {
+        return -1;
+    }
+#endif
+    return 0;
+}
+
+static void winsock_fini(void)
+{
+#if WIN32
+    WSACleanup();
+#endif
+}
+
+
+#if WIN32
+static int inet_pton(int af, const char *src, void *dst)
+{
+    struct sockaddr_storage ss;
+    int size = sizeof(ss);
+    char src_copy[INET6_ADDRSTRLEN+1];
+
+    ZeroMemory(&ss, sizeof(ss));
+    /* stupid non-const API */
+    strncpy (src_copy, src, INET6_ADDRSTRLEN+1);
+    src_copy[INET6_ADDRSTRLEN] = 0;
+
+    if (WSAStringToAddress(src_copy, af, NULL, (struct sockaddr *)&ss, &size) == 0) {
+        switch(af) {
+        case AF_INET:
+            *(struct in_addr *)dst = ((struct sockaddr_in *)&ss)->sin_addr;
+            return 1;
+        case AF_INET6:
+            *(struct in6_addr *)dst = ((struct sockaddr_in6 *)&ss)->sin6_addr;
+            return 1;
+        }
+    }
+    return 0;
+}
+#endif
--- /dev/null
+++ b/fs_test/lwext4_server.c
@@ -1,0 +1,1111 @@
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <getopt.h>
+#include <time.h>
+
+#ifdef WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+#else
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/types.h>
+#endif
+
+
+#include <ext4_filedev.h>
+#include <io_raw.h>
+
+#include <ext4.h>
+
+static int winsock_init(void);
+static void winsock_fini(void);
+static char* entry_to_str(uint8_t type);
+
+#define MAX_FILES   64
+#define MAX_DIRS    64
+
+#define MAX_RW_BUFFER   (1024 * 1024)
+#define RW_BUFFER_PATERN    ('x')
+
+
+/**@brief   Default connection port*/
+static int connection_port = 1234;
+
+/**@brief   Default filesystem filename.*/
+static char *ext4_fname = "ext2";
+
+/**@brief   Verbose mode*/
+static int verbose = 0;
+
+/**@brief   Winpart mode*/
+static int winpart = 0;
+
+/**@brief   Blockdev handle*/
+static struct ext4_blockdev *bd;
+
+static int cache_wb = 0;
+
+static char read_buffer[MAX_RW_BUFFER];
+static char write_buffer[MAX_RW_BUFFER];
+
+
+static const char *usage = "                                    \n\
+Welcome in lwext4_server.                                       \n\
+Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)  \n\
+Usage:                                                          \n\
+    --image     (-i) - ext2/3/4 image file                      \n\
+    --port      (-p) - server port                              \n\
+    --verbose   (-v) - verbose mode                             \n\
+    --winpart   (-w) - windows_partition mode                   \n\
+    --cache_wb  (-c) - cache writeback_mode                     \n\
+\n";
+
+
+
+/**@brief   Open file instance descriptor.*/
+struct lwext4_files {
+    char        name[255];
+    ext4_file   fd;
+};
+
+/**@brief   Open directory instance descriptor.*/
+struct lwext4_dirs {
+    char        name[255];
+    ext4_dir    fd;
+};
+
+/**@brief   Library call opcode.*/
+struct lwext4_op_codes {
+    char *func;
+};
+
+/**@brief   Library call wraper.*/
+struct lwext4_call {
+    int (*lwext4_call)(char *p);
+};
+
+/**@brief  */
+static struct lwext4_files file_tab[MAX_FILES];
+
+/**@brief  */
+static struct lwext4_dirs  dir_tab[MAX_DIRS];
+
+/**@brief  */
+static struct lwext4_op_codes op_codes[] = {
+        "device_register",
+        "mount",
+        "umount",
+        "mount_point_stats",
+        "cache_write_back",
+        "fremove",
+        "fopen",
+        "fclose",
+        "fread",
+        "fwrite",
+        "fseek",
+        "ftell",
+        "fsize",
+        "dir_rm",
+        "dir_mk",
+        "dir_open",
+        "dir_close",
+        "dir_entry_get",
+
+        "multi_fcreate",
+        "multi_fwrite",
+        "multi_fread",
+        "multi_fremove",
+        "multi_dcreate",
+        "multi_dremove",
+        "stats_save",
+        "stats_check",
+};
+
+int _device_register(char *p);
+int _mount(char *p);
+int _umount(char *p);
+int _mount_point_stats(char *p);
+int _cache_write_back(char *p);
+int _fremove(char *p);
+int _fopen(char *p);
+int _fclose(char *p);
+int _fread(char *p);
+int _fwrite(char *p);
+int _fseek(char *p);
+int _ftell(char *p);
+int _fsize(char *p);
+int _dir_rm(char *p);
+int _dir_mk(char *p);
+int _dir_open(char *p);
+int _dir_close(char *p);
+int _dir_close(char *p);
+int _dir_entry_get(char *p);
+
+int _multi_fcreate(char *p);
+int _multi_fwrite(char *p);
+int _multi_fread(char *p);
+int _multi_fremove(char *p);
+int _multi_dcreate(char *p);
+int _multi_dremove(char *p);
+int _stats_save(char *p);
+int _stats_check(char *p);
+
+/**@brief  */
+static struct lwext4_call op_call[] = {
+        _device_register,  /*PARAMS(3):   0 cache_mode dev_name   */
+        _mount,            /*PARAMS(2):   dev_name mount_point    */
+        _umount,           /*PARAMS(1):   mount_point             */
+        _mount_point_stats,/*PARAMS(2):   mount_point, 0          */
+        _cache_write_back, /*PARAMS(2):   mount_point, en         */
+        _fremove,          /*PARAMS(1):   path                    */
+        _fopen,            /*PARAMS(2):   fid path flags          */
+        _fclose,           /*PARAMS(1):   fid                     */
+        _fread,            /*PARAMS(4):   fid 0 len 0             */
+        _fwrite,           /*PARAMS(4):   fid 0 len 0             */
+        _fseek,            /*PARAMS(2):   fid off origin          */
+        _ftell,            /*PARAMS(2):   fid exp                 */
+        _fsize,            /*PARAMS(2):   fid exp                 */
+        _dir_rm,           /*PARAMS(1):   path                    */
+        _dir_mk,           /*PARAMS(1):   path                    */
+        _dir_open,         /*PARAMS(2):   did, path               */
+        _dir_close,        /*PARAMS(1):   did                     */
+        _dir_entry_get,    /*PARAMS(2):   did, exp                */
+
+        _multi_fcreate,    /*PARAMS(3):   path prefix cnt         */
+        _multi_fwrite,     /*PARAMS(4):   path prefix cnt size    */
+        _multi_fread,      /*PARAMS(4):   path prefix cnt size    */
+        _multi_fremove,    /*PARAMS(2):   path prefix cnt         */
+        _multi_dcreate,    /*PARAMS(3):   path prefix cnt         */
+        _multi_dremove,    /*PARAMS(2):   path prefix             */
+        _stats_save,       /*PARAMS(1):   path                    */
+        _stats_check,      /*PARAMS(1):   path                    */
+};
+
+static clock_t get_ms(void)
+{
+    struct timeval t;
+    gettimeofday(&t, NULL);
+    return (t.tv_sec * 1000) + (t.tv_usec / 1000);
+}
+
+/**@brief  */
+static int exec_op_code(char *opcode)
+{
+    int i;
+    int r = -1;
+
+    for (i = 0; i < sizeof(op_codes) / sizeof(op_codes[0]); ++i) {
+
+        if(strncmp(op_codes[i].func, opcode, strlen(op_codes[i].func)))
+            continue;
+
+        if(opcode[strlen(op_codes[i].func)] != ' ')
+            continue;
+
+        printf("%s\n", opcode);
+        opcode += strlen(op_codes[i].func);
+        /*Call*/
+
+        clock_t t = get_ms();
+        r = op_call[i].lwext4_call(opcode);
+
+        printf("rc: %d, time: %ums\n", r, (unsigned int)(get_ms() - t));
+
+        break;
+    }
+
+    return r;
+}
+
+
+static int server_open(void)
+{
+    int fd = 0;
+    struct sockaddr_in serv_addr;
+
+    memset(&serv_addr, 0, sizeof(serv_addr));
+
+    if(winsock_init() < 0) {
+        printf("winsock_init() error\n");
+        exit(-1);
+    }
+
+    fd = socket(AF_INET, SOCK_STREAM, 0);
+    if(fd < 0) {
+        printf("socket() error: %s\n", strerror(errno));
+        exit(-1);
+    }
+
+    int yes = 1;
+    if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&yes, sizeof(int))) {
+        printf("setsockopt() error: %s\n", strerror(errno));
+        exit(-1);
+    }
+
+    serv_addr.sin_family = AF_INET;
+    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+    serv_addr.sin_port = htons(connection_port);
+
+    if(bind(fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr))){
+        printf("bind() error: %s\n", strerror(errno));
+        exit(-1);
+    }
+
+    if(listen(fd, 1)){
+        printf("listen() error: %s\n", strerror(errno));
+        exit(-1);
+    }
+
+    return fd;
+}
+
+static bool parse_opt(int argc, char **argv)
+{
+    int option_index = 0;
+    int c;
+
+    static struct option long_options[] = {
+            {"image",   required_argument, 0, 'i'},
+            {"port",    required_argument, 0, 'p'},
+            {"verbose", required_argument, 0, 'v'},
+            {"winpart", required_argument, 0, 'w'},
+            {"cache_wb",required_argument, 0, 'c'},
+            {0, 0, 0, 0}
+    };
+
+    while(-1 != (c = getopt_long (argc, argv, "i:p:v:w:c:", long_options, &option_index))) {
+
+        switch(c){
+        case 'i':
+            ext4_fname = optarg;
+            break;
+        case 'p':
+            connection_port = atoi(optarg);
+            break;
+        case 'v':
+            verbose = atoi(optarg);
+            break;
+        case 'c':
+            cache_wb = atoi(optarg);
+            break;
+        default:
+            printf("%s", usage);
+            return false;
+
+        }
+    }
+    return true;
+}
+
+int main(int argc, char *argv[])
+{
+    int n;
+    int listenfd;
+    int connfd;
+    char op_code[128];
+
+    if(!parse_opt(argc, argv))
+        return -1;
+
+    listenfd = server_open();
+
+    printf("lwext4_server: listening on port: %d\n", connection_port);
+
+    memset(write_buffer, RW_BUFFER_PATERN, MAX_RW_BUFFER);
+    while(1)
+    {
+        connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
+
+        n = recv(connfd, op_code, sizeof(op_code), 0);
+
+        if(n < 0) {
+            printf("recv() error: %s fd = %d\n", strerror(errno), connfd);
+            break;
+        }
+
+        op_code[n] = 0;
+
+        int r = exec_op_code(op_code);
+
+        n = send(connfd, (void *)&r, sizeof(r), 0);
+        if(n < 0) {
+            printf("send() error: %s fd = %d\n", strerror(errno), connfd);
+            break;
+        }
+
+        close(connfd);
+    }
+
+    winsock_fini();
+    return 0;
+}
+
+
+int _device_register(char *p)
+{
+    int dev;
+    int cache_mode;
+    char dev_name[32];
+
+    if(sscanf(p, "%d %d %s", &dev, &cache_mode, dev_name) != 3){
+        printf("Param list error\n");
+        return -1;
+    }
+
+#ifdef WIN32
+    if(winpart){
+        ext4_io_raw_filename(ext4_fname);
+        bd = ext4_io_raw_dev_get();
+
+    }
+    else
+#endif
+    {
+        ext4_filedev_filename(ext4_fname);
+        bd = ext4_filedev_get();
+    }
+    return ext4_device_register(bd, 0, dev_name);
+}
+
+int _mount(char *p)
+{
+    char dev_name[32];
+    char mount_point[32];
+    int rc;
+
+    if(sscanf(p, "%s %s", dev_name, mount_point) != 2){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    rc = ext4_mount(dev_name, mount_point);
+    if(cache_wb)
+        ext4_cache_write_back(mount_point, 1);
+    return rc;
+}
+
+int _umount(char *p)
+{
+    char mount_point[32];
+
+    if(sscanf(p, "%s", mount_point) != 1){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(cache_wb)
+        ext4_cache_write_back(mount_point, 0);
+
+    return ext4_umount(mount_point);
+}
+
+int _mount_point_stats(char *p)
+{
+    char mount_point[32];
+    int d;
+    int rc;
+    struct ext4_mount_stats stats;
+
+    if(sscanf(p, "%s %d", mount_point, &d) != 2){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    rc = ext4_mount_point_stats(mount_point, &stats);
+
+    if(rc != EOK)
+        return;
+
+    if(verbose){
+        printf("\tinodes_count = %d\n", stats.inodes_count);
+        printf("\tfree_inodes_count = %d\n", stats.free_inodes_count);
+        printf("\tblocks_count = %llu\n", stats.blocks_count);
+        printf("\tfree_blocks_count = %llu\n", stats.free_blocks_count);
+
+        printf("\tblock_size = %d\n", stats.block_size);
+        printf("\tblock_group_count = %d\n", stats.block_group_count);
+        printf("\tblocks_per_group = %d\n", stats.blocks_per_group);
+        printf("\tinodes_per_group = %d\n", stats.inodes_per_group);
+
+        printf("\tvolume_name = %s\n", stats.volume_name);
+    }
+
+    return rc;
+}
+
+int _cache_write_back(char *p)
+{
+    char mount_point[32];
+    int en;
+
+    if(sscanf(p, "%s %d", mount_point, &en) != 2){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    return ext4_cache_write_back(mount_point, en);
+}
+
+
+int _fremove(char *p)
+{
+    char path[255];
+
+    if(sscanf(p, "%s", path) != 1){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    return ext4_fremove(path);
+}
+
+int _fopen(char *p)
+{
+    int fid = MAX_FILES;
+    char path[256];
+    char flags[8];
+    int rc;
+
+    if(sscanf(p, "%d %s %s", &fid, path, flags) != 3){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(fid < MAX_FILES)){
+        printf("File id too big\n");
+        return -1;
+    }
+
+    rc = ext4_fopen(&file_tab[fid].fd, path, flags);
+
+    if(rc == EOK)
+        strcpy(file_tab[fid].name, path);
+
+    return rc;
+}
+
+int _fclose(char *p)
+{
+    int fid = MAX_FILES;
+    int rc;
+
+    if(sscanf(p, "%d", &fid) != 1){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(fid < MAX_FILES)){
+        printf("File id too big\n");
+        return -1;
+    }
+
+    if(file_tab[fid].name[0] == 0){
+        printf("File id empty\n");
+        return -1;
+    }
+
+    rc = ext4_fclose(&file_tab[fid].fd);
+
+    if(rc == EOK)
+        file_tab[fid].name[0] = 0;
+
+    return rc;
+}
+
+int _fread(char *p)
+{
+    int fid = MAX_FILES;
+    int len;
+    int d;
+    int rc;
+    int rb;
+
+    if(sscanf(p, "%d %d %d %d", &fid, &d, &len, &d) != 4){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(fid < MAX_FILES)){
+        printf("File id too big\n");
+        return -1;
+    }
+
+    if(file_tab[fid].name[0] == 0){
+        printf("File id empty\n");
+        return -1;
+    }
+
+    while(len){
+        d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
+
+        memset(read_buffer, 0, MAX_RW_BUFFER);
+        rc = ext4_fread(&file_tab[fid].fd, read_buffer, d, &rb);
+
+        if(rc != EOK)
+            break;
+
+        if(rb != d){
+            printf("Read count error\n");
+            return -1;
+        }
+
+        if(memcmp(read_buffer, write_buffer, d)){
+            printf("Read compare error\n");
+            return -1;
+        }
+
+        len -= d;
+    }
+
+    return rc;
+}
+
+int _fwrite(char *p)
+{
+    int fid = MAX_FILES;
+    int len;
+    int d;
+    int rc;
+    int wb;
+
+    if(sscanf(p, "%d %d %d %d", &fid, &d, &len, &d) != 4){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(fid < MAX_FILES)){
+        printf("File id too big\n");
+        return -1;
+    }
+
+    if(file_tab[fid].name[0] == 0){
+        printf("File id empty\n");
+        return -1;
+    }
+
+    while(len){
+        d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
+        rc = ext4_fwrite(&file_tab[fid].fd, write_buffer, d, &wb);
+
+        if(rc != EOK)
+            break;
+
+        if(wb != d){
+            printf("Write count error\n");
+            return -1;
+        }
+
+        len -= d;
+    }
+
+    return rc;
+}
+
+int _fseek(char *p)
+{
+    int fid = MAX_FILES;
+    int off;
+    int origin;
+
+    if(sscanf(p, "%d %d %d", &fid, &off, &origin) != 3){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(fid < MAX_FILES)){
+        printf("File id too big\n");
+        return -1;
+    }
+
+    if(file_tab[fid].name[0] == 0){
+        printf("File id empty\n");
+        return -1;
+    }
+
+    return ext4_fseek(&file_tab[fid].fd, off, origin);
+}
+
+int _ftell(char *p)
+{
+    int fid = MAX_FILES;
+    uint32_t exp_pos;
+
+    if(sscanf(p, "%d %u", &fid, &exp_pos) != 2){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(fid < MAX_FILES)){
+        printf("File id too big\n");
+        return -1;
+    }
+
+    if(file_tab[fid].name[0] == 0){
+        printf("File id empty\n");
+        return -1;
+    }
+
+
+    if(exp_pos != ext4_ftell(&file_tab[fid].fd)){
+        printf("Expected filepos error\n");
+        return -1;
+    }
+
+    return EOK;
+}
+
+int _fsize(char *p)
+{
+    int fid = MAX_FILES;
+    uint32_t exp_size;
+
+    if(sscanf(p, "%d %u", &fid, &exp_size) != 2){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(fid < MAX_FILES)){
+        printf("File id too big\n");
+        return -1;
+    }
+
+    if(file_tab[fid].name[0] == 0){
+        printf("File id empty\n");
+        return -1;
+    }
+
+    if(exp_size != ext4_fsize(&file_tab[fid].fd)){
+        printf("Expected filesize error\n");
+        return -1;
+    }
+
+    return EOK;
+}
+
+int _dir_rm(char *p)
+{
+    char path[255];
+
+    if(sscanf(p, "%s", path) != 1){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    return ext4_dir_rm(path);
+}
+
+int _dir_mk(char *p)
+{
+    char path[255];
+
+    if(sscanf(p, "%s", path) != 1){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    return ext4_dir_mk(path);
+}
+
+int _dir_open(char *p)
+{
+    int did = MAX_DIRS;
+    char path[255];
+    int rc;
+
+    if(sscanf(p, "%d %s", &did, path) != 2){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(did < MAX_DIRS)){
+        printf("Dir id too big\n");
+        return -1;
+    }
+
+    rc = ext4_dir_open(&dir_tab[did].fd, path);
+
+    if(rc == EOK)
+        strcpy(dir_tab[did].name, path);
+
+    return rc;
+}
+
+int _dir_close(char *p)
+{
+    int did = MAX_DIRS;
+    int rc;
+
+    if(sscanf(p, "%d", &did) != 1){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(did < MAX_DIRS)){
+        printf("Dir id too big\n");
+        return -1;
+    }
+
+    if(dir_tab[did].name[0] == 0){
+        printf("Dir id empty\n");
+        return -1;
+    }
+
+    rc = ext4_dir_close(&dir_tab[did].fd);
+
+    if(rc == EOK)
+        dir_tab[did].name[0] = 0;
+
+    return rc;
+}
+
+int _dir_entry_get(char *p)
+{
+    int did = MAX_DIRS;
+    int exp;
+    char name[256];
+
+    if(sscanf(p, "%d %d", &did, &exp) != 2){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    if(!(did < MAX_DIRS)){
+        printf("Dir id too big\n");
+        return -1;
+    }
+
+    if(dir_tab[did].name[0] == 0){
+        printf("Dir id empty\n");
+        return -1;
+    }
+
+
+    int idx = 0;
+    ext4_direntry *d;
+
+    while(d = ext4_dir_entry_get(&dir_tab[did].fd, idx++)){
+
+        memcpy(name, d->name, d->name_length);
+        name[d->name_length] = 0;
+        if(verbose){
+            printf("\t%s %s\n", entry_to_str(d->inode_type), name);
+        }
+    }
+
+    idx--;
+
+    if(idx < 2){
+        printf("Minumum dir entry error\n");
+        return -1;
+    }
+
+    if((idx - 2) != exp){
+        printf("Expected dir entry error\n");
+        return -1;
+    }
+
+    return EOK;
+}
+
+int _multi_fcreate(char *p)
+{
+    char path[256];
+    char path1[256];
+    char prefix[32];
+    int cnt;
+    int rc;
+    int i;
+    ext4_file   fd;
+
+    if(sscanf(p, "%s %s %d", path, prefix, &cnt) != 3){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    for (i = 0; i < cnt; ++i) {
+        sprintf(path1, "%s%s%d", path, prefix, i);
+        rc = ext4_fopen(&fd, path1, "wb+");
+
+        if(rc != EOK)
+            break;
+    }
+
+    return rc;
+}
+
+int _multi_fwrite(char *p)
+{
+    char path[256];
+    char path1[256];
+    char prefix[32];
+    int cnt;
+    int len, ll;
+    int rc;
+    int i, d, wb;
+    ext4_file   fd;
+
+    if(sscanf(p, "%s %s %d %d", path, prefix, &cnt, &ll) != 4){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    for (i = 0; i < cnt; ++i) {
+        sprintf(path1, "%s%s%d", path, prefix, i);
+        rc = ext4_fopen(&fd, path1, "rb+");
+
+        if(rc != EOK)
+            break;
+
+        len = ll;
+        while(len){
+            d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
+            rc = ext4_fwrite(&fd, write_buffer, d, &wb);
+
+            if(rc != EOK)
+                break;
+
+            if(wb != d){
+                printf("Write count error\n");
+                return -1;
+            }
+
+            len -= d;
+        }
+    }
+
+    return rc;
+}
+
+int _multi_fread(char *p)
+{
+    char path[256];
+    char path1[256];
+    char prefix[32];
+    int cnt;
+    int len, ll;
+    int rc;
+    int i, d, rb;
+    ext4_file   fd;
+
+    if(sscanf(p, "%s %s %d %d", path, prefix, &cnt, &ll) != 4){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    for (i = 0; i < cnt; ++i) {
+        sprintf(path1, "%s%s%d", path, prefix, i);
+        rc = ext4_fopen(&fd, path1, "rb+");
+
+        if(rc != EOK)
+            break;
+
+        len = ll;
+        while(len){
+            d = len > MAX_RW_BUFFER ? MAX_RW_BUFFER : len;
+
+            memset(read_buffer, 0, MAX_RW_BUFFER);
+            rc = ext4_fread(&fd, read_buffer, d, &rb);
+
+            if(rc != EOK)
+                break;
+
+            if(rb != d){
+                printf("Read count error\n");
+                return -1;
+            }
+
+            if(memcmp(read_buffer, write_buffer, d)){
+                printf("Read compare error\n");
+                return -1;
+            }
+
+            len -= d;
+        }
+    }
+
+    return rc;
+}
+
+int _multi_fremove(char *p)
+{
+    char path[256];
+    char path1[256];
+    char prefix[32];
+    int  cnt, i, rc;
+
+    if(sscanf(p, "%s %s %d", path, prefix, &cnt) != 3){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    for (i = 0; i < cnt; ++i) {
+        sprintf(path1, "%s%s%d", path, prefix, i);
+        rc = ext4_fremove(path1);
+        if(rc != EOK)
+            break;
+    }
+
+    return rc;
+}
+
+int _multi_dcreate(char *p)
+{
+    char path[256];
+    char path1[256];
+    char prefix[32];
+    int  cnt, i, rc;
+
+    if(sscanf(p, "%s %s %d", path, prefix, &cnt) != 3){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    for (i = 0; i < cnt; ++i) {
+        sprintf(path1, "%s%s%d", path, prefix, i);
+        rc = ext4_dir_mk(path1);
+        if(rc != EOK)
+            break;
+    }
+
+    return rc;
+}
+
+int _multi_dremove(char *p)
+{
+    char path[256];
+    char path1[256];
+    char prefix[32];
+    int  cnt, i, rc;
+
+    if(sscanf(p, "%s %s %d", path, prefix, &cnt) != 3){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    for (i = 0; i < cnt; ++i) {
+        sprintf(path1, "%s%s%d", path, prefix, i);
+        rc = ext4_dir_rm(path1);
+        if(rc != EOK)
+            break;
+    }
+
+    return rc;
+}
+
+struct ext4_mount_stats  saved_stats;
+
+int _stats_save(char *p)
+{
+    char path[256];
+
+    if(sscanf(p, "%s", path) != 1){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    return ext4_mount_point_stats(path, &saved_stats);
+}
+
+int _stats_check(char *p)
+{
+    char path[256];
+    int rc;
+
+    struct ext4_mount_stats  actual_stats;
+
+    if(sscanf(p, "%s", path) != 1){
+        printf("Param list error\n");
+        return -1;
+    }
+
+    rc = ext4_mount_point_stats(path, &actual_stats);
+
+    if(rc != EOK)
+        return rc;
+
+    if(memcmp(&saved_stats, &actual_stats, sizeof(struct ext4_mount_stats))){
+        if(verbose){
+            printf("\tMount point stats error:\n");
+            printf("\tsaved_stats:\n");
+            printf("\tinodes_count = %d\n", saved_stats.inodes_count);
+            printf("\tfree_inodes_count = %d\n", saved_stats.free_inodes_count);
+            printf("\tblocks_count = %llu\n", saved_stats.blocks_count);
+            printf("\tfree_blocks_count = %llu\n", saved_stats.free_blocks_count);
+            printf("\tblock_size = %d\n", saved_stats.block_size);
+            printf("\tblock_group_count = %d\n", saved_stats.block_group_count);
+            printf("\tblocks_per_group = %d\n", saved_stats.blocks_per_group);
+            printf("\tinodes_per_group = %d\n", saved_stats.inodes_per_group);
+            printf("\tvolume_name = %s\n", saved_stats.volume_name);
+            printf("\tactual_stats:\n");
+            printf("\tinodes_count = %d\n", actual_stats.inodes_count);
+            printf("\tfree_inodes_count = %d\n", actual_stats.free_inodes_count);
+            printf("\tblocks_count = %llu\n", actual_stats.blocks_count);
+            printf("\tfree_blocks_count = %llu\n", actual_stats.free_blocks_count);
+            printf("\tblock_size = %d\n", actual_stats.block_size);
+            printf("\tblock_group_count = %d\n", actual_stats.block_group_count);
+            printf("\tblocks_per_group = %d\n", actual_stats.blocks_per_group);
+            printf("\tinodes_per_group = %d\n", actual_stats.inodes_per_group);
+            printf("\tvolume_name = %s\n", actual_stats.volume_name);
+        }
+        return -1;
+    }
+
+
+   return rc;
+}
+
+
+static char* entry_to_str(uint8_t type)
+{
+    switch(type){
+    case EXT4_DIRENTRY_UNKNOWN:
+        return "[UNK] ";
+    case EXT4_DIRENTRY_REG_FILE:
+        return "[FIL] ";
+    case EXT4_DIRENTRY_DIR:
+        return "[DIR] ";
+    case EXT4_DIRENTRY_CHRDEV:
+        return "[CHA] ";
+    case EXT4_DIRENTRY_BLKDEV:
+        return "[BLK] ";
+    case EXT4_DIRENTRY_FIFO:
+        return "[FIF] ";
+    case EXT4_DIRENTRY_SOCK:
+        return "[SOC] ";
+    case EXT4_DIRENTRY_SYMLINK:
+        return "[SYM] ";
+    default:
+        break;
+    }
+    return "[???]";
+}
+
+static int winsock_init(void)
+{
+#if WIN32
+    int rc;
+    static WSADATA wsaData;
+    rc = WSAStartup(MAKEWORD(2,2), &wsaData);
+    if (rc != 0) {
+        return -1;
+    }
+#endif
+    return 0;
+}
+
+static void winsock_fini(void)
+{
+#if WIN32
+    WSACleanup();
+#endif
+}
+
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -61,8 +61,11 @@
 /**@brief   Mount point descrpitor.*/
 struct ext4_mountpoint {
 
+    /**@brief   Mount done flag.*/
+    bool    mounted;
+
     /**@brief   Mount point name (@ref ext4_mount)*/
-    const char *name;
+    char name[32];
 
     /**@brief   Os dependent lock/unlock functions.*/
     struct ext4_lock *os_locks;
@@ -78,7 +81,7 @@
 struct _ext4_devices {
 
     /**@brief   Block device name (@ref ext4_device_register)*/
-    const char *name;
+    char name[32];
 
     /**@brief   Block device handle.*/
     struct ext4_blockdev *bd;
@@ -102,12 +105,15 @@
     ext4_assert(bd && dev_name);
 
     for (i = 0; i < CONFIG_EXT4_BLOCKDEVS_COUNT; ++i) {
-        if(!_bdevices[i].name){
-            _bdevices[i].name   = dev_name;
+        if(!_bdevices[i].bd){
+            strcpy(_bdevices[i].name, dev_name);
             _bdevices[i].bd = bd;
             _bdevices[i].bc = bc;
             return EOK;
         }
+
+        if(!strcmp(_bdevices[i].name, dev_name))
+            return EOK;
     }
     return ENOSPC;
 }
@@ -330,11 +336,16 @@
         return ENODEV;
 
     for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {
-        if(!_mp[i].name){
-            _mp[i].name = mount_point;
+        if(!_mp[i].mounted){
+            strcpy(_mp[i].name, mount_point);
+            _mp[i].mounted = 1;
             mp = &_mp[i];
             break;
         }
+
+        if(!strcmp(_mp[i].name, mount_point)){
+            return EOK;
+        }
     }
 
     if(!mp)
@@ -393,9 +404,8 @@
     struct ext4_mountpoint *mp = 0;
 
     for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {
-        if(_mp[i].name){
-            if(!strcmp(_mp[i].name, mount_point))
-                mp = &_mp[i];
+        if(!strcmp(_mp[i].name, mount_point)){
+            mp = &_mp[i];
             break;
         }
     }
@@ -407,7 +417,7 @@
     if(r != EOK)
         return r;
 
-    mp->name = 0;
+    mp->mounted = 0;
 
     if(mp->cache_dynamic){
         ext4_bcache_fini_dynamic(mp->fs.bdev->bc);
@@ -424,11 +434,11 @@
     struct ext4_mountpoint    *mp = 0;
 
     for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {
-        if(_mp[i].name){
-            if(!strcmp(_mp[i].name, mount_point))
-                mp = &_mp[i];
+        if(!strcmp(_mp[i].name, mount_point)){
+            mp = &_mp[i];
             break;
         }
+
     }
     if(!mp)
         return ENOENT;
@@ -456,10 +466,12 @@
 {
     int i;
     for (i = 0; i < CONFIG_EXT4_MOUNTPOINTS_COUNT; ++i) {
-        if(_mp[i].name){
-            if(!strncmp(_mp[i].name, path, strlen(_mp[i].name)))
-                return &_mp[i];
-        }
+
+        if(!_mp[i].mounted)
+            continue;
+
+        if(!strncmp(_mp[i].name, path, strlen(_mp[i].name)))
+            return &_mp[i];
     }
     return 0;
 }
--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -50,37 +50,10 @@
 
     memset(bc, 0, sizeof(struct ext4_bcache));
 
-    bc->refctr = malloc(cnt * sizeof(uint32_t));
-    if(!bc->refctr)
-        goto error;
-
-    bc->lru_id = malloc(cnt * sizeof(uint32_t));
-    if(!bc->lru_id)
-        goto error;
-
-    bc->free_delay = malloc(cnt * sizeof(uint8_t));
-    if(!bc->free_delay)
-        goto error;
-
-    bc->lba = malloc(cnt * sizeof(uint64_t));
-    if(!bc->lba)
-        goto error;
-
-    bc->dirty = malloc(cnt * sizeof(bool));
-    if(!bc->dirty)
-        goto error;
-
-
     bc->data = malloc(cnt * itemsize);
     if(!bc->data)
         goto error;
 
-    memset(bc->refctr, 0, cnt * sizeof(uint32_t));
-    memset(bc->lru_id, 0, cnt * sizeof(uint32_t));
-    memset(bc->free_delay, 0, cnt * sizeof(uint8_t));
-    memset(bc->lba, 0, cnt * sizeof(uint64_t));
-    memset(bc->dirty, 0, cnt * sizeof(bool));
-
     bc->cnt = cnt;
     bc->itemsize = itemsize;
     bc->ref_blocks = 0;
@@ -90,21 +63,6 @@
 
     error:
 
-    if(bc->refctr)
-        free(bc->refctr);
-
-    if(bc->lru_id)
-        free(bc->lru_id);
-
-    if(bc->free_delay)
-        free(bc->free_delay);
-
-    if(bc->lba)
-        free(bc->lba);
-
-    if(bc->dirty)
-       free(bc->dirty);
-
     if(bc->data)
         free(bc->data);
 
@@ -115,21 +73,6 @@
 
 int ext4_bcache_fini_dynamic(struct ext4_bcache *bc)
 {
-    if(bc->refctr)
-        free(bc->refctr);
-
-    if(bc->lru_id)
-        free(bc->lru_id);
-
-    if(bc->free_delay)
-        free(bc->free_delay);
-
-    if(bc->lba)
-        free(bc->lba);
-
-    if(bc->dirty)
-       free(bc->dirty);
-
     if(bc->data)
         free(bc->data);
 
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -71,19 +71,19 @@
     uint32_t lru_ctr;
 
     /**@brief   Reference count table (cnt).*/
-    uint32_t *refctr;
+    uint32_t refctr[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Last recently used ID table (cnt)*/
-    uint32_t *lru_id;
+    uint32_t lru_id[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Writeback free delay mode table (cnt)*/
-    uint8_t *free_delay;
+    uint8_t free_delay[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Logical block table (cnt).*/
-    uint64_t *lba;
+    uint64_t lba[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Dirty mark (cnt).*/
-    bool *dirty;
+    bool dirty[CONFIG_BLOCK_DEV_CACHE_SIZE];
 
     /**@brief   Cache data buffers (cnt * itemsize)*/
     uint8_t *data;
@@ -98,21 +98,11 @@
 
 /**@brief   Static initializer of block cache structure.*/
 #define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize)      \
-        static uint32_t __name##_refctr[(__cnt)];                   \
-        static uint32_t __name##_lru_id[(__cnt)];                   \
-        static uint8_t  __name##_free_delay[(__cnt)];               \
-        static uint64_t __name##_lba[(__cnt)];                      \
-        static bool     __name##_dirty[(__cnt)];                    \
         static uint8_t  __name##_data[(__cnt) * (__itemsize)];      \
         static struct ext4_bcache __name = {                        \
                 .cnt     = __cnt,                                   \
                 .itemsize  = __itemsize,                            \
                 .lru_ctr   = 0,                                     \
-                .refctr    = __name##_refctr,                       \
-                .lru_id    = __name##_lru_id,                       \
-                .lba    = __name##_lba,                             \
-                .dirty    = __name##_dirty,                         \
-                .free_delay= __name##_free_delay,                   \
                 .data    = __name##_data,                           \
         }
 
--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -111,6 +111,10 @@
 
     /*If cache is full we have to flush it anyway :(*/
     if(ext4_bcache_is_full(bdev->bc) && bdev->cache_write_back){
+
+        uint32_t free_candidate = bdev->bc->cnt;
+        uint32_t min_lru = 0xFFFFFFFF;
+
         for (i = 0; i < bdev->bc->cnt; ++i) {
             /*Check if buffer free was delayed.*/
             if(!bdev->bc->free_delay[i])
@@ -120,15 +124,23 @@
             if(bdev->bc->refctr[i])
                 continue;
 
+            if(bdev->bc->lru_id[i] < min_lru){
+                min_lru = bdev->bc->lru_id[i];
+                free_candidate = i;
+                continue;
+            }
+        }
+
+        if(free_candidate < bdev->bc->cnt){
             /*Buffer free was delayed and have no reference. Flush it.*/
             r = ext4_blocks_set_direct(bdev,
-                    bdev->bc->data + bdev->bc->itemsize * i,
-                    bdev->bc->lba[i], 1);
+                    bdev->bc->data + bdev->bc->itemsize * free_candidate,
+                    bdev->bc->lba[free_candidate], 1);
             if(r != EOK)
                 return r;
 
             /*No delayed anymore*/
-            bdev->bc->free_delay[i] = 0;
+            bdev->bc->free_delay[free_candidate] = 0;
 
             /*Reduce refered block count*/
             bdev->bc->ref_blocks--;
@@ -176,7 +188,7 @@
         return EIO;
 
     /*Doesn,t need to write.*/
-    if(b->dirty == false && !bdev->bc->dirty[b->cache_id]){
+    if(!b->dirty && !bdev->bc->dirty[b->cache_id]){
         ext4_bcache_free(bdev->bc, b, 0);
         return EOK;
     }
@@ -188,13 +200,14 @@
         return ext4_bcache_free(bdev->bc, b, bdev->cache_write_back);
     }
 
-    pba = (b->lb_id * bdev->lg_bsize) / bdev->ph_bsize;
-    pb_cnt = bdev->lg_bsize / bdev->ph_bsize;
-
     if(bdev->bc->refctr[b->cache_id] > 1){
         bdev->bc->dirty[b->cache_id] = true;
         return ext4_bcache_free(bdev->bc, b, 0);
     }
+
+
+    pba = (b->lb_id * bdev->lg_bsize) / bdev->ph_bsize;
+    pb_cnt = bdev->lg_bsize / bdev->ph_bsize;
 
     r = bdev->bwrite(bdev, b->data, pba, pb_cnt);
     bdev->bc->dirty[b->cache_id] = false;
--- a/lwext4/ext4_config.h
+++ b/lwext4/ext4_config.h
@@ -56,7 +56,7 @@
 
 /**@brief   Include error codes from ext4_errno or sandard library.*/
 #ifndef CONFIG_HAVE_OWN_ERRNO
-#define CONFIG_HAVE_OWN_ERRNO       1
+#define CONFIG_HAVE_OWN_ERRNO       0
 #endif
 
 
--- a/lwext4/ext4_errno.h
+++ b/lwext4/ext4_errno.h
@@ -38,7 +38,7 @@
 
 #include <ext4_config.h>
 
-#ifndef CONFIG_HAVE_OWN_ERRNO
+#if !CONFIG_HAVE_OWN_ERRNO
 #include <errno.h>
 #else
 #define EPERM        1 /* Operation not permitted */
@@ -76,6 +76,10 @@
 #define EDOM        33 /* Math argument out of domain of func */
 #define ERANGE      34 /* Math result not representable */
 #define ENOTSUP     95  /* Not supported */
+#endif
+
+#ifndef ENOTSUP
+#define ENOTSUP     95
 #endif
 
 #ifndef EOK
--- a/lwext4/ext4_ialloc.c
+++ b/lwext4/ext4_ialloc.c
@@ -158,7 +158,6 @@
     uint32_t bgid = fs->last_inode_bg_id;
     uint32_t bg_count = ext4_block_group_cnt(sb);
     uint32_t sb_free_inodes = ext4_get32(sb, free_inodes_count);
-    uint32_t avg_free_inodes = sb_free_inodes / bg_count;
     bool     rewind = false;
 
     /* Try to find free i-node in all block groups */
--- a/readme.mediawiki
+++ b/readme.mediawiki
@@ -95,6 +95,7 @@
  - ext4.h           - lwext4 client library header
  - CMakeLists.txt   - CMake config file
  - ext_images.7z    - ext2/3/4 100MB images
+ - fs_test.mk       - automatic tests definition
  - Makefile         - helper makefile to call cmake
  - readme.mediawiki - yes, you are here ;)
   
@@ -129,7 +130,7 @@
  cd build_generic
  make
 
-==Generic demo applicarion==
+==Generic demo application==
 
 Features:
  - load ext2/3/4 images
@@ -162,7 +163,23 @@
     --sbstat - superblock stats                                 
     --wpart  - windows partition mode                           
 
+==Client-server automatic test suite==
 
+Build:
+ make
+ cd build_generic
+ make
+ 
+Unpack images:
+ make unpack_images
+ 
+Run server:
+ make server_ext2
+ 
+Run tests:
+ make all_tests
+
+
 ==Cross-Compile==
 
  Toolchain for ARM Cortex-m3/4: https://launchpad.net/gcc-arm-embedded
@@ -170,17 +187,46 @@
 
 Build bf518 library:
  make bf518
-
+ cd build_bf518
+ make lwext4
+ 
 Build cortex-m3 library:
  make cortex-m3
+ cd build_cortex-m3
+ make lwext4
 
 Build cortex-m4 library:
  make cortex-m4
+ cd build_cortex-m4
+ make lwext4
 
 ==Ports==
- *Blackfin BF518 EZKIT SD Card Demo: TBD
- *STM32F4-Discovery SD Card Demo: TBD 
+STM32F429-DISCO USB flash drive Demo 
+ 
+Build STM32F429 Demo:
+ make cortex-m4
+ cd build_cortex-m4
+ make all
 
 ==Footprint==
-                           
-TBD
\ No newline at end of file
+
+ TOOLCHAIN: arm-none-eabi-gcc
+ OPT: Os  
+ OUTPUT:
+   text    data     bss     dec     hex filename
+   5728       0       0    5728    1660 ext4.c.obj (ex liblwext4.a)
+   2264       0       0    2264     8d8 ext4_balloc.c.obj (ex liblwext4.a)
+   1324       0       0    1324     52c ext4_bcache.c.obj (ex liblwext4.a)
+    936       0       0     936     3a8 ext4_bitmap.c.obj (ex liblwext4.a)
+   2016       0       0    2016     7e0 ext4_blockdev.c.obj (ex liblwext4.a)
+    624       0       0     624     270 ext4_block_group.c.obj (ex liblwext4.a)
+     24       0       4      28      1c ext4_debug.c.obj (ex liblwext4.a)
+   2264       0       0    2264     8d8 ext4_dir.c.obj (ex liblwext4.a)
+   3204       0       0    3204     c84 ext4_dir_idx.c.obj (ex liblwext4.a)
+   3104       0       0    3104     c20 ext4_extent.c.obj (ex liblwext4.a)
+   7360       0       0    7360    1cc0 ext4_fs.c.obj (ex liblwext4.a)
+   2496       0       0    2496     9c0 ext4_hash.c.obj (ex liblwext4.a)
+    684       0       0     684     2ac ext4_ialloc.c.obj (ex liblwext4.a)
+    652       0       0     652     28c ext4_inode.c.obj (ex liblwext4.a)
+    352       0       0     352     160 ext4_super.c.obj (ex liblwext4.a)                      
+                           
\ No newline at end of file