settings: file: change FS (or file system) wording to File

Currently there is inconsistency in repository file names, APIs, Kconfig
options and documentation around file / file-system backend for settings
storage, as both "file" and "FS (file system)" are used. As an example,
there is `CONFIG_SETTINGS_FS` Kconfig option, but the file that implements
this settings backend is called `settings_file.c`. Another example are
names of static functions that implement settings storage API:
`settings_file_load()`, `settings_file_save()` and
`settings_fs_storage_get()`.

This backend is actually storing all settings in a single file, so it makes
sense to use "File" as the name of backend, instead of a more general
"FS" (which would make sense if several files would be used to store
settings).

Fix inconsistency in used wording in the tree and unify it to "settings
file backend". This naming is more precise to how the implementation looks.
It will also make it easier to grep through the codebase and analyze
existing code.

Deprecate settings_mount_fs_backend() function and all Kconfig options
starting with `CONFIG_SETTINGS_FS`.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
This commit is contained in:
Marcin Niestroj 2022-11-21 15:58:03 +01:00 committed by Carles Cufí
commit daee6cb4a9
36 changed files with 126 additions and 68 deletions

View file

@ -37,7 +37,7 @@ choice SETTINGS_BACKEND
prompt "Storage back-end"
default SETTINGS_NVS if NVS
default SETTINGS_FCB if FCB
default SETTINGS_FS if FILE_SYSTEM
default SETTINGS_FILE if FILE_SYSTEM
default SETTINGS_NONE
depends on SETTINGS
help
@ -49,12 +49,20 @@ config SETTINGS_FCB
help
Use FCB as a settings storage back-end.
config SETTINGS_FS
bool "File System"
config SETTINGS_FILE
bool "File"
depends on FILE_SYSTEM
select SETTINGS_ENCODE_LEN
help
Use a file system as a settings storage back-end.
Use a file (on mounted file system) as a settings storage back-end.
config SETTINGS_FS
bool "FS (DEPRECATED)"
depends on FILE_SYSTEM
select SETTINGS_ENCODE_LEN
select DEPRECATED
help
This is deprecated, please use SETTINGS_FILE instead.
config SETTINGS_NVS
bool "NVS non-volatile storage support"
@ -107,26 +115,47 @@ config SETTINGS_FCB_MAGIC
help
Magic 32-bit word for to identify valid settings area
config SETTINGS_FS_DIR
config SETTINGS_FILE_DIR
string "Serialization directory"
default "/settings"
depends on SETTINGS && SETTINGS_FS
depends on SETTINGS && SETTINGS_FILE
help
Directory where the settings data is stored
config SETTINGS_FS_FILE
config SETTINGS_FILE_PATH
string "Default settings file"
default "/settings/run"
depends on SETTINGS && SETTINGS_FS
depends on SETTINGS && SETTINGS_FILE
help
Full path to the default settings file.
config SETTINGS_FS_MAX_LINES
config SETTINGS_FILE_MAX_LINES
int "Compression threshold"
default 32
depends on SETTINGS && SETTINGS_FILE
help
Limit how many items stored in a file before compressing
config SETTINGS_FS_DIR
string "Serialization directory (DEPRECATED)"
default "/settings"
depends on SETTINGS && SETTINGS_FS
help
This is deprecated. Use SETTINGS_FILE_DIR instead.
config SETTINGS_FS_FILE
string "Default settings file (DEPRECATED)"
default "/settings/run"
depends on SETTINGS && SETTINGS_FS
help
This is deprecated. Use SETTINGS_FILE_PATH instead.
config SETTINGS_FS_MAX_LINES
int "Compression threshold (DEPRECATED)"
default 32
depends on SETTINGS && SETTINGS_FS
help
Limit how many items stored in a file before compressing
This is deprecated. Use SETTINGS_FILE_MAX_LINES instead.
config SETTINGS_NVS_SECTOR_SIZE_MULT
int "Sector size of the NVS settings area"

View file

@ -8,6 +8,7 @@
#ifndef __SETTINGS_FILE_H_
#define __SETTINGS_FILE_H_
#include <zephyr/toolchain.h>
#include <zephyr/settings/settings.h>
#ifdef __cplusplus
@ -29,7 +30,12 @@ int settings_file_src(struct settings_file *cf);
/* settings saves go to a file */
int settings_file_dst(struct settings_file *cf);
void settings_mount_fs_backend(struct settings_file *cf);
void settings_mount_file_backend(struct settings_file *cf);
__deprecated static inline void settings_mount_fs_backend(struct settings_file *cf)
{
settings_mount_file_backend(cf);
}
#ifdef __cplusplus
}

View file

@ -8,6 +8,7 @@ zephyr_sources(
)
zephyr_sources_ifdef(CONFIG_SETTINGS_RUNTIME settings_runtime.c)
zephyr_sources_ifdef(CONFIG_SETTINGS_FILE settings_file.c)
zephyr_sources_ifdef(CONFIG_SETTINGS_FS settings_file.c)
zephyr_sources_ifdef(CONFIG_SETTINGS_FCB settings_fcb.c)
zephyr_sources_ifdef(CONFIG_SETTINGS_NVS settings_nvs.c)

View file

@ -19,19 +19,29 @@
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
int settings_backend_init(void);
void settings_mount_fs_backend(struct settings_file *cf);
void settings_mount_file_backend(struct settings_file *cf);
static int settings_file_load(struct settings_store *cs,
const struct settings_load_arg *arg);
static int settings_file_save(struct settings_store *cs, const char *name,
const char *value, size_t val_len);
static void *settings_fs_storage_get(struct settings_store *cs);
static void *settings_file_storage_get(struct settings_store *cs);
static const struct settings_store_itf settings_file_itf = {
.csi_load = settings_file_load,
.csi_save = settings_file_save,
.csi_storage_get = settings_fs_storage_get
.csi_storage_get = settings_file_storage_get
};
/*
@ -500,7 +510,7 @@ static int write_handler(void *ctx, off_t off, char const *buf, size_t len)
return rc;
}
void settings_mount_fs_backend(struct settings_file *cf)
void settings_mount_file_backend(struct settings_file *cf)
{
settings_line_io_init(read_handler, write_handler, get_len_cb, 1);
}
@ -508,8 +518,8 @@ void settings_mount_fs_backend(struct settings_file *cf)
int settings_backend_init(void)
{
static struct settings_file config_init_settings_file = {
.cf_name = CONFIG_SETTINGS_FS_FILE,
.cf_maxlines = CONFIG_SETTINGS_FS_MAX_LINES
.cf_name = SETTINGS_FILE_PATH,
.cf_maxlines = SETTINGS_FILE_MAX_LINES
};
struct fs_dirent entry;
int rc;
@ -525,20 +535,20 @@ int settings_backend_init(void)
k_panic();
}
settings_mount_fs_backend(&config_init_settings_file);
settings_mount_file_backend(&config_init_settings_file);
/*
* Must be called after root FS has been initialized.
*/
rc = fs_stat(CONFIG_SETTINGS_FS_DIR, &entry);
rc = fs_stat(SETTINGS_FILE_DIR, &entry);
/* If directory doesn't exist, create it */
if (rc == -ENOENT) {
rc = fs_mkdir(CONFIG_SETTINGS_FS_DIR);
rc = fs_mkdir(SETTINGS_FILE_DIR);
}
return rc;
}
static void *settings_fs_storage_get(struct settings_store *cs)
static void *settings_file_storage_get(struct settings_store *cs)
{
struct settings_file *cf = (struct settings_file *)cs;