settings: file: drop CONFIG_SETTINGS_FILE_DIR
There is already CONFIG_SETTINGS_FILE_PATH, which is set to full file path, while CONFIG_SETTINGS_FILE_DIR is required to be set to its parent directory. This is redundant, as parent directory path can be easily found out either during runtime or optionally during buildtime by CMake. CONFIG_SETTINGS_FILE_DIR was actually introduced recently after Zephyr 3.2 release as a replacement of deprecated CONFIG_SETTINGS_FS_DIR. This means, that there is no need to deprecate it for 3.3 release and dropping it should be fine. Adjust 3.3 release notes accordingly, so that CONFIG_SETTINGS_FILE_PATH will be used directly. This patch stops using deprecated CONFIG_SETTINGS_FS_DIR. There is actually no value in respecting it, as setting anything other than parent directory of CONFIG_SETTINGS_FS_FILE makes no sense. There is actually one use of CONFIG_SETTINGS_FILE_DIR in file backend tests, to derive directory for files containing tested settings. CONFIG_SETTINGS_FILE_PATH is not used there, so it makes little sense to derive directory name from it. Instead, just use hardcoded "/settings" subdirectory, as this was the default value of CONFIG_SETTINGS_FILE_DIR. Deriving parent directory can be done either in runtime or in buildtime (e.g. using some helper CMake function). Doing it in runtime however allows to create directory recursively (which this patch actually implements), e.g. for some more nested FS tree structure. Additionally it will simplify migration of settings configuration from Kconfig to device-tree (yet to be developed feature). Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
parent
f386967b06
commit
2d3365200c
|
@ -122,7 +122,8 @@ Deprecated in this release
|
|||
|
||||
:kconfig:option:`CONFIG_SETTINGS_FS` in favor of :kconfig:option:`CONFIG_SETTINGS_FILE`
|
||||
|
||||
:kconfig:option:`CONFIG_SETTINGS_FS_DIR` in favor of :kconfig:option:`CONFIG_SETTINGS_FILE_DIR`
|
||||
:kconfig:option:`CONFIG_SETTINGS_FS_DIR` in favor of creating all parent
|
||||
directories from :kconfig:option:`CONFIG_SETTINGS_FILE_PATH`
|
||||
|
||||
:kconfig:option:`CONFIG_SETTINGS_FS_FILE` in favor of :kconfig:option:`CONFIG_SETTINGS_FILE_PATH`
|
||||
|
||||
|
|
|
@ -2,5 +2,4 @@
|
|||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
CONFIG_SETTINGS_FILE=y
|
||||
CONFIG_SETTINGS_FILE_DIR="/ff/settings"
|
||||
CONFIG_SETTINGS_FILE_PATH="/ff/settings/run"
|
||||
|
|
|
@ -2,5 +2,4 @@
|
|||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_LITTLEFS=y
|
||||
CONFIG_SETTINGS_FILE=y
|
||||
CONFIG_SETTINGS_FILE_DIR="/ff/settings"
|
||||
CONFIG_SETTINGS_FILE_PATH="/ff/settings/run"
|
||||
|
|
|
@ -111,13 +111,6 @@ config SETTINGS_FCB_MAGIC
|
|||
help
|
||||
Magic 32-bit word for to identify valid settings area
|
||||
|
||||
config SETTINGS_FILE_DIR
|
||||
string "Serialization directory"
|
||||
default "/settings"
|
||||
depends on SETTINGS_FILE
|
||||
help
|
||||
Directory where the settings data is stored
|
||||
|
||||
config SETTINGS_FILE_PATH
|
||||
string "Default settings file"
|
||||
default "/settings/run"
|
||||
|
@ -137,7 +130,7 @@ config SETTINGS_FS_DIR
|
|||
default "/settings"
|
||||
depends on SETTINGS_FS
|
||||
help
|
||||
This is deprecated. Use SETTINGS_FILE_DIR instead.
|
||||
This is deprecated. Use SETTINGS_FILE_PATH instead.
|
||||
|
||||
config SETTINGS_FS_FILE
|
||||
string "Default settings file (DEPRECATED)"
|
||||
|
|
|
@ -21,11 +21,9 @@ LOG_MODULE_DECLARE(settings, CONFIG_SETTINGS_LOG_LEVEL);
|
|||
|
||||
#ifdef CONFIG_SETTINGS_FS
|
||||
#define SETTINGS_FILE_MAX_LINES CONFIG_SETTINGS_FS_MAX_LINES
|
||||
#define SETTINGS_FILE_DIR CONFIG_SETTINGS_FS_DIR
|
||||
#define SETTINGS_FILE_PATH CONFIG_SETTINGS_FS_FILE
|
||||
#else
|
||||
#define SETTINGS_FILE_MAX_LINES CONFIG_SETTINGS_FILE_MAX_LINES
|
||||
#define SETTINGS_FILE_DIR CONFIG_SETTINGS_FILE_DIR
|
||||
#define SETTINGS_FILE_PATH CONFIG_SETTINGS_FILE_PATH
|
||||
#endif
|
||||
|
||||
|
@ -519,16 +517,54 @@ void settings_mount_file_backend(struct settings_file *cf)
|
|||
settings_line_io_init(read_handler, write_handler, get_len_cb, 1);
|
||||
}
|
||||
|
||||
static int mkdir_if_not_exists(const char *path)
|
||||
{
|
||||
struct fs_dirent entry;
|
||||
int err;
|
||||
|
||||
err = fs_stat(path, &entry);
|
||||
if (err == -ENOENT) {
|
||||
return fs_mkdir(path);
|
||||
} else if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (entry.type != FS_DIR_ENTRY_DIR) {
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mkdir_for_file(const char *file_path)
|
||||
{
|
||||
char dir_path[SETTINGS_FILE_NAME_MAX];
|
||||
int err;
|
||||
|
||||
for (size_t i = 0; file_path[i] != '\0'; i++) {
|
||||
if (i > 0 && file_path[i] == '/') {
|
||||
dir_path[i] = '\0';
|
||||
|
||||
err = mkdir_if_not_exists(dir_path);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
dir_path[i] = file_path[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int settings_backend_init(void)
|
||||
{
|
||||
static struct settings_file config_init_settings_file = {
|
||||
.cf_name = SETTINGS_FILE_PATH,
|
||||
.cf_maxlines = SETTINGS_FILE_MAX_LINES
|
||||
};
|
||||
struct fs_dirent entry;
|
||||
int rc;
|
||||
|
||||
|
||||
rc = settings_file_src(&config_init_settings_file);
|
||||
if (rc) {
|
||||
return rc;
|
||||
|
@ -544,12 +580,7 @@ int settings_backend_init(void)
|
|||
/*
|
||||
* Must be called after root FS has been initialized.
|
||||
*/
|
||||
rc = fs_stat(SETTINGS_FILE_DIR, &entry);
|
||||
/* If directory doesn't exist, create it */
|
||||
if (rc == -ENOENT) {
|
||||
rc = fs_mkdir(SETTINGS_FILE_DIR);
|
||||
}
|
||||
return rc;
|
||||
return mkdir_for_file(config_init_settings_file.cf_name);
|
||||
}
|
||||
|
||||
static void *settings_file_storage_get(struct settings_store *cs)
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "settings_test_file.h"
|
||||
|
||||
#define TEST_FS_MPTR "/fs"
|
||||
#define TEST_CONFIG_DIR TEST_FS_MPTR""CONFIG_SETTINGS_FILE_DIR
|
||||
#define TEST_CONFIG_DIR TEST_FS_MPTR"/settings"
|
||||
|
||||
void *config_setup_fs(void);
|
||||
|
||||
|
|
|
@ -14,5 +14,4 @@ CONFIG_SETTINGS=y
|
|||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FILE=y
|
||||
|
||||
CONFIG_SETTINGS_FILE_DIR="/ff/settings"
|
||||
CONFIG_SETTINGS_FILE_PATH="/ff/settings/run"
|
||||
|
|
|
@ -11,5 +11,4 @@ CONFIG_SETTINGS=y
|
|||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FILE=y
|
||||
|
||||
CONFIG_SETTINGS_FILE_DIR="/ff/settings"
|
||||
CONFIG_SETTINGS_FILE_PATH="/ff/settings/run"
|
||||
|
|
|
@ -11,5 +11,4 @@ CONFIG_SETTINGS=y
|
|||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FILE=y
|
||||
|
||||
CONFIG_SETTINGS_FILE_DIR="/ff/settings"
|
||||
CONFIG_SETTINGS_FILE_PATH="/ff/settings/run"
|
||||
|
|
|
@ -12,5 +12,4 @@ CONFIG_SETTINGS=y
|
|||
CONFIG_SETTINGS_RUNTIME=y
|
||||
CONFIG_SETTINGS_FILE=y
|
||||
|
||||
CONFIG_SETTINGS_FILE_DIR="/ff/settings"
|
||||
CONFIG_SETTINGS_FILE_PATH="/ff/settings/run"
|
||||
|
|
Loading…
Reference in a new issue