Browse Source

Client server basic test suite + minor code improvment.

pull/1/head
gkostka 11 years ago
parent
commit
52a1caf803
  1. 59
      CMakeLists.txt
  2. 8
      Makefile
  3. 10
      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. 421
      fs_test.mk
  12. 14
      fs_test/fs_test.cmake
  13. 194
      fs_test/lwext4_client.c
  14. 1071
      fs_test/lwext4_server.c
  15. 38
      lwext4/ext4.c
  16. 2
      lwext4/ext4_ialloc.c

59
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)
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)
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)
else()
#Library size print
add_custom_target(lib_size ALL DEPENDS lwext4 COMMAND size -B liblwext4.a)
#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)
include(demos/generic/generic.cmake)
include(fs_test/fs_test.cmake)
endif()
#DISTRIBUTION

8
Makefile

@ -32,7 +32,6 @@ cortex-m4:
all: generic bf518 cortex-m3 cortex-m4 generic
clean:
rm -R -f build_bf518
rm -R -f build_cortex-m3
@ -40,3 +39,10 @@ clean:
rm -R -f build_generic
include fs_test.mk

10
blockdev/filedev/ext4_filedev.c

@ -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)
}
ext4_cache_write_back("/mp/", 1);
printf("Add files to: /mp/dir1\n");
for (i = 0; i < len; ++i) {
sprintf(path, "/mp/dir1/f%d", i);
@ -224,7 +225,7 @@ static bool dir_test(int len)
return false;
}
}
ext4_cache_write_back("/mp/", 0);
stop = get_ms();
diff = stop - start;
dir_ls("/mp/dir1");

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)

421
fs_test.mk

@ -0,0 +1,421 @@
LWEXT4_CLIENT = @build_generic\\lwext4_client
TEST_DIR = /test
t0:
@echo "T0: Device regoster 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 "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 "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 "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 "dir_rm $(TEST_DIR)"
$(LWEXT4_CLIENT) -c "stats_check /"
$(LWEXT4_CLIENT) -c "umount /"
t20:
@echo "T10: 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 "dir_rm $(TEST_DIR)"
$(LWEXT4_CLIENT) -c "stats_check /"
$(LWEXT4_CLIENT) -c "umount /"
all_tests: t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 t19 t20

14
fs_test/fs_test.cmake

@ -0,0 +1,14 @@
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)
target_link_libraries(lwext4_server ws2_32)
add_executable(lwext4_client fs_test/lwext4_client.c ${BLOCKDEV_SRC})
target_link_libraries(lwext4_client lwext4)
target_link_libraries(lwext4_client ws2_32)

194
fs_test/lwext4_client.c

@ -0,0 +1,194 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdbool.h>
#include <getopt.h>
#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.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 = 8888;
/**@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);
closesocket(sockfd);
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

1071
fs_test/lwext4_server.c

File diff suppressed because it is too large

38
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,8 +404,7 @@ 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))
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))
if(!strcmp(_mp[i].name, mount_point)){
mp = &_mp[i];
break;
}
}
if(!mp)
return ENOENT;
@ -456,11 +466,13 @@ 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(!_mp[i].mounted)
continue;
if(!strncmp(_mp[i].name, path, strlen(_mp[i].name)))
return &_mp[i];
}
}
return 0;
}

2
lwext4/ext4_ialloc.c

@ -186,7 +186,7 @@ int ext4_ialloc_alloc_inode(struct ext4_fs *fs, uint32_t *index, bool is_dir)
uint32_t used_dirs = ext4_bg_get_used_dirs_count(bg, sb);
/* Check if this block group is good candidate for allocation */
if (free_inodes > 0) {
if (free_inodes >= avg_free_inodes) {
/* Load block with bitmap */
uint32_t bitmap_block_addr = ext4_bg_get_inode_bitmap(
bg_ref.block_group, sb);

Loading…
Cancel
Save