Browse Source

Merge with test_suite branch.

pull/1/head
gkostka 11 years ago
parent
commit
d812bca336
  1. 75
      CMakeLists.txt
  2. 13
      Makefile
  3. 12
      blockdev/filedev/ext4_filedev.c
  4. 5
      blockdev/filedev/ext4_filedev.h
  5. 10
      blockdev/filedev_win/io_raw.c
  6. 4
      blockdev/filedev_win/io_raw.h
  7. 9
      demos/generic/generic.cmake
  8. 17
      demos/generic/main.c
  9. 5
      demos/stm32f429_disco/main.c
  10. 38
      demos/stm32f429_disco/stm32f429_demo.cmake
  11. 507
      fs_test.mk
  12. 17
      fs_test/fs_test.cmake
  13. 192
      fs_test/lwext4_client.c
  14. 1111
      fs_test/lwext4_server.c
  15. 46
      lwext4/ext4.c
  16. 57
      lwext4/ext4_bcache.c
  17. 20
      lwext4/ext4_bcache.h
  18. 27
      lwext4/ext4_blockdev.c
  19. 2
      lwext4/ext4_config.h
  20. 6
      lwext4/ext4_errno.h
  21. 1
      lwext4/ext4_ialloc.c
  22. 58
      readme.mediawiki

75
CMakeLists.txt

@ -7,71 +7,24 @@ include_directories(. lwext4)
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

13
Makefile

@ -32,11 +32,22 @@ cortex-m4:
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

12
blockdev/filedev/ext4_filedev.c

@ -45,7 +45,7 @@ static const char *fname = "ext2";
/**@brief Image file descriptor.*/
static FILE *dev_file;
#define DROP_LINUXCACHE_BUFFERS 1
#define DROP_LINUXCACHE_BUFFERS 0
/**********************BLOCKDEV INTERFACE**************************************/
@ -68,9 +68,6 @@ EXT4_BLOCKDEV_STATIC_INSTANCE(
filedev_close
);
/******************************************************************************/
EXT4_BCACHE_STATIC_INSTANCE(__cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
/******************************************************************************/
static int filedev_open(struct ext4_blockdev *bdev)
{
@ -137,13 +134,6 @@ static int filedev_close(struct ext4_blockdev *bdev)
return EOK;
}
/******************************************************************************/
struct ext4_bcache* ext4_filecache_get(void)
{
return &__cache;
}
/******************************************************************************/
struct ext4_blockdev* ext4_filedev_get(void)
{

5
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_ */

10
blockdev/io_raw/io_raw.c → blockdev/filedev_win/io_raw.c

@ -70,9 +70,6 @@ EXT4_BLOCKDEV_STATIC_INSTANCE(
io_raw_close
);
/******************************************************************************/
EXT4_BCACHE_STATIC_INSTANCE(__cache, CONFIG_BLOCK_DEV_CACHE_SIZE, 1024);
/******************************************************************************/
static int io_raw_open(struct ext4_blockdev *bdev)
{
@ -179,13 +176,6 @@ static int io_raw_close(struct ext4_blockdev *bdev)
return EOK;
}
/******************************************************************************/
struct ext4_bcache* ext4_io_raw_cache_get(void)
{
return &__cache;
}
/******************************************************************************/
struct ext4_blockdev* ext4_io_raw_dev_get(void)
{

4
blockdev/io_raw/io_raw.h → blockdev/filedev_win/io_raw.h

@ -35,12 +35,10 @@
#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);
/**@brief Set filrname to open.*/
void ext4_io_raw_filename(const char *n);
#endif /* IO_RAW_H_ */

9
demos/generic/generic.cmake

@ -0,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)

17
demos/generic/main.c

@ -79,8 +79,11 @@ static uint8_t *rd_buff;
/**@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 @@ Usage: \n\
--wpart - windows partition mode \n\
\n";
static char* entry_to_str(uint8_t type)
{
switch(type){
@ -370,8 +377,7 @@ static bool open_filedev(void)
{
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 @@ static bool open_winpartition(void)
#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
}

5
demos/stm32f429_disco/main.c

@ -57,7 +57,7 @@ static int rw_szie = READ_WRITE_SZIZE;
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 @@ static bool dir_test(int len)
}
printf("Add files to: /mp/dir1\n");
for (i = 0; i < len; ++i) {
sprintf(path, "/mp/dir1/f%d", i);
@ -431,6 +432,7 @@ int main(void)
if(!mount())
return EXIT_FAILURE;
ext4_cache_write_back("/mp/", 1);
cleanup();
if(sbstat){
@ -464,6 +466,7 @@ int main(void)
block_stats();
}
ext4_cache_write_back("/mp/", 0);
if(!umount())
return EXIT_FAILURE;

38
demos/stm32f429_disco/stm32f429_demo.cmake

@ -0,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)

507
fs_test.mk

@ -0,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

17
fs_test/fs_test.cmake

@ -0,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)

192
fs_test/lwext4_client.c

@ -0,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

1111
fs_test/lwext4_server.c

File diff suppressed because it is too large

46
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_mountpoint {
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 @@ int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc,
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 @@ int ext4_mount(const char * dev_name, char *mount_point)
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 @@ int ext4_umount(char *mount_point)
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 @@ int ext4_umount(char *mount_point)
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 @@ int ext4_mount_point_stats(const char *mount_point,
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 @@ static struct ext4_mountpoint* ext4_get_mount(const char *path)
{
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;
}

57
lwext4/ext4_bcache.c

@ -50,37 +50,10 @@ int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,
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 @@ int ext4_bcache_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,
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_init_dynamic(struct ext4_bcache *bc, uint32_t cnt,
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);

20
lwext4/ext4_bcache.h

@ -71,19 +71,19 @@ struct ext4_bcache {
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 @@ struct ext4_bcache {
/**@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, \
}

27
lwext4/ext4_blockdev.c

@ -111,6 +111,10 @@ int ext4_block_get(struct ext4_blockdev *bdev, struct ext4_block *b,
/*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 @@ int ext4_block_get(struct ext4_blockdev *bdev, struct ext4_block *b,
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 @@ int ext4_block_set(struct ext4_blockdev *bdev, struct ext4_block *b)
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,14 +200,15 @@ int ext4_block_set(struct ext4_blockdev *bdev, struct ext4_block *b)
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;
if(r != EOK){

2
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

6
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 */
@ -78,6 +78,10 @@
#define ENOTSUP 95 /* Not supported */
#endif
#ifndef ENOTSUP
#define ENOTSUP 95
#endif
#ifndef EOK
#define EOK 0
#endif

1
lwext4/ext4_ialloc.c

@ -158,7 +158,6 @@ int ext4_ialloc_alloc_inode(struct ext4_fs *fs, uint32_t *index, bool is_dir)
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 */

58
readme.mediawiki

@ -95,6 +95,7 @@ Some of ideas and features are based on FreeBSD and Linux implementations.
- 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 @@ Tools needed:
cd build_generic
make
==Generic demo applicarion==
==Generic demo application==
Features:
- load ext2/3/4 images
@ -162,6 +163,22 @@ Usage:
--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==
@ -170,17 +187,46 @@ Usage:
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
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)
Loading…
Cancel
Save