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:
Marcin Niestroj 2022-12-07 21:20:32 +01:00 committed by Carles Cufí
parent f386967b06
commit 2d3365200c
10 changed files with 45 additions and 26 deletions

View file

@ -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`

View file

@ -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"

View file

@ -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"

View file

@ -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)"

View file

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

View file

@ -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);

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"