From 492e3ebd96f30f8e8ccedbcb40ea4391fe43ca87 Mon Sep 17 00:00:00 2001 From: Yossi Levy Date: Wed, 16 Jan 2019 15:43:53 +0200 Subject: [PATCH] Fixing a bug in FileSystemStore to get the folder path from kv_config in FILESYSTEM and default configuration --- .../storage/TESTS/kvstore/static_tests/main.cpp | 1 + features/storage/kvstore/conf/kv_config.cpp | 16 ++++++++++++++++ features/storage/kvstore/conf/kv_config.h | 13 +++++++------ .../kvstore/filesystemstore/FileSystemStore.cpp | 15 ++++++++++----- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/features/storage/TESTS/kvstore/static_tests/main.cpp b/features/storage/TESTS/kvstore/static_tests/main.cpp index db6379c8b3..a063d5c4d6 100644 --- a/features/storage/TESTS/kvstore/static_tests/main.cpp +++ b/features/storage/TESTS/kvstore/static_tests/main.cpp @@ -910,6 +910,7 @@ static void iterator_close_right_after_iterator_open() utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { greentea_case_failure_abort_handler(source, reason); + UnityConcludeTest(); return STATUS_CONTINUE; } diff --git a/features/storage/kvstore/conf/kv_config.cpp b/features/storage/kvstore/conf/kv_config.cpp index 3ff9762d5a..852e153f22 100644 --- a/features/storage/kvstore/conf/kv_config.cpp +++ b/features/storage/kvstore/conf/kv_config.cpp @@ -134,6 +134,8 @@ int _storage_config_FILESYSTEM_NO_RBP(); int _storage_config_tdb_external_common(); int _storage_config_filesystem_common(); +static const char *filesystemstore_folder_path = NULL; + using namespace mbed; @@ -881,6 +883,9 @@ int _storage_config_FILESYSTEM() #if !SECURESTORE_ENABLED return MBED_ERROR_UNSUPPORTED; #endif + + filesystemstore_folder_path = STR(MBED_CONF_STORAGE_FILESYSTEM_FOLDER_PATH); + bd_size_t internal_rbp_size = MBED_CONF_STORAGE_FILESYSTEM_RBP_INTERNAL_SIZE; bd_addr_t internal_start_address = MBED_CONF_STORAGE_FILESYSTEM_INTERNAL_BASE_ADDRESS; @@ -962,6 +967,12 @@ int _storage_config_FILESYSTEM() int _storage_config_FILESYSTEM_NO_RBP() { +#if !SECURESTORE_ENABLED + return MBED_ERROR_UNSUPPORTED; +#endif + + filesystemstore_folder_path = STR(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FOLDER_PATH); + bd_size_t size = MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_SIZE; bd_addr_t address = MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_EXTERNAL_BASE_ADDRESS; const char *mount_point = STR(MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_MOUNT_POINT); @@ -1062,6 +1073,11 @@ int _storage_config_default() #endif } +const char *get_filesystemstore_folder_path() +{ + return filesystemstore_folder_path; +} + MBED_WEAK int kv_init_storage_config() { diff --git a/features/storage/kvstore/conf/kv_config.h b/features/storage/kvstore/conf/kv_config.h index 6a78cf3390..660a6bdd88 100644 --- a/features/storage/kvstore/conf/kv_config.h +++ b/features/storage/kvstore/conf/kv_config.h @@ -20,12 +20,6 @@ extern "C" { #endif -#if MBED_CONF_STORAGE_STORAGE_TYPE == FILESYSTEM -#define FSST_FOLDER_PATH MBED_CONF_STORAGE_FILESYSTEM_FOLDER_PATH -#elif MBED_CONF_STORAGE_STORAGE_TYPE == FILESYSTEM_NO_RBP -#define FSST_FOLDER_PATH MBED_CONF_STORAGE_FILESYSTEM_NO_RBP_FOLDER_PATH -#endif - #ifndef MBED_CONF_STORAGE_STORAGE #define MBED_CONF_STORAGE_STORAGE USER_DEFINED #endif @@ -41,6 +35,13 @@ extern "C" { */ int kv_init_storage_config(); +/** + * @brief A getter for filesystemstore folder path configuration + * + * @returns string with the file folder path or NULL if not set + */ +const char *get_filesystemstore_folder_path(); + #ifdef __cplusplus } // closing brace for extern "C" #endif diff --git a/features/storage/kvstore/filesystemstore/FileSystemStore.cpp b/features/storage/kvstore/filesystemstore/FileSystemStore.cpp index 5561d3cd65..ac1aea3cd7 100644 --- a/features/storage/kvstore/filesystemstore/FileSystemStore.cpp +++ b/features/storage/kvstore/filesystemstore/FileSystemStore.cpp @@ -17,6 +17,7 @@ */ #include "FileSystemStore.h" +#include "kv_config.h" #include "Dir.h" #include "File.h" #include "BlockDevice.h" @@ -31,9 +32,7 @@ #define FSST_REVISION 1 #define FSST_MAGIC 0x46535354 // "FSST" hex 'magic' signature -#ifndef FSST_FOLDER_PATH -#define FSST_FOLDER_PATH "kvstore" //default FileSystemStore folder path on fs -#endif +#define FSST_DEFAULT_FOLDER_PATH "kvstore" //default FileSystemStore folder path on fs static const uint32_t supported_flags = mbed::KVStore::WRITE_ONCE_FLAG; @@ -73,9 +72,15 @@ int FileSystemStore::init() int status = MBED_SUCCESS; _mutex.lock(); + const char *temp_path = get_filesystemstore_folder_path(); + if (temp_path == NULL) { + _cfg_fs_path_size = strlen(FSST_DEFAULT_FOLDER_PATH); + _cfg_fs_path = string_ndup(FSST_DEFAULT_FOLDER_PATH, _cfg_fs_path_size); + } else { + _cfg_fs_path_size = strlen(temp_path); + _cfg_fs_path = string_ndup(temp_path, _cfg_fs_path_size); + } - _cfg_fs_path_size = strlen(FSST_FOLDER_PATH); - _cfg_fs_path = string_ndup(FSST_FOLDER_PATH, _cfg_fs_path_size); _full_path_key = new char[_cfg_fs_path_size + KVStore::MAX_KEY_SIZE + 1]; memset(_full_path_key, 0, (_cfg_fs_path_size + KVStore::MAX_KEY_SIZE + 1)); strncpy(_full_path_key, _cfg_fs_path, _cfg_fs_path_size);