From d918c98e1de5023918848d4a2471bc96f653f2a6 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Tue, 25 Jun 2019 12:09:24 -0400 Subject: [PATCH] cleanup: include/: move fcb.h to fs/fcb.h move fcb.h to fs/fcb.h and create a shim for backward-compatibility. No functional changes to the headers. A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES. Related to #16539 Signed-off-by: Anas Nashif --- include/fcb.h | 139 +---------------- include/fs/fcb.h | 146 ++++++++++++++++++ subsys/fs/fcb/fcb.c | 2 +- subsys/fs/fcb/fcb_append.c | 2 +- subsys/fs/fcb/fcb_elem_info.c | 2 +- subsys/fs/fcb/fcb_getnext.c | 2 +- subsys/fs/fcb/fcb_rotate.c | 2 +- subsys/fs/fcb/fcb_walk.c | 2 +- .../settings/include/settings/settings_fcb.h | 2 +- subsys/settings/src/settings_fcb.c | 2 +- subsys/settings/src/settings_init.c | 2 +- tests/subsys/fs/fcb/src/fcb_test.h | 2 +- 12 files changed, 160 insertions(+), 145 deletions(-) create mode 100644 include/fs/fcb.h diff --git a/include/fcb.h b/include/fcb.h index b27611a95ad..52f7dbbcfb8 100644 --- a/include/fcb.h +++ b/include/fcb.h @@ -1,146 +1,15 @@ /* - * Copyright (c) 2017 Nordic Semiconductor ASA - * Copyright (c) 2015 Runtime Inc + * Copyright (c) 2019 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #ifndef ZEPHYR_INCLUDE_FCB_H_ #define ZEPHYR_INCLUDE_FCB_H_ -#ifdef __cplusplus -extern "C" { +#ifndef CONFIG_COMPAT_INCLUDES +#warning "This header file has moved, include instead." #endif -/* - * Flash circular buffer. - */ -#include -#include - -#include - -#include - -#define FCB_MAX_LEN (CHAR_MAX | CHAR_MAX << 7) /* Max length of element */ - -/* - * Entry location is pointer to area (within fcb->f_sectors), and offset - * within that area. - */ -struct fcb_entry { - struct flash_sector *fe_sector; /* ptr to sector */ - /* within fcb->f_sectors */ - u32_t fe_elem_off; /* start of entry */ - u32_t fe_data_off; /* start of data */ - u16_t fe_data_len; /* size of data area */ -}; - -/* - * Helper macro for calculate the data offset related to - * the fcb flash_area start offset. - */ -#define FCB_ENTRY_FA_DATA_OFF(entry) (entry.fe_sector->fs_off +\ - entry.fe_data_off) - -struct fcb_entry_ctx { - struct fcb_entry loc; - const struct flash_area *fap; -}; - -struct fcb { - /* Caller of fcb_init fills this in */ - u32_t f_magic; /* As placed on the disk */ - u8_t f_version; /* Current version number of the data */ - u8_t f_sector_cnt; /* Number of elements in sector array */ - u8_t f_scratch_cnt; /* How many sectors should be kept empty */ - struct flash_sector *f_sectors; /* Array of sectors, */ - /* must be contiguous */ - - /* Flash circular buffer internal state */ - struct k_mutex f_mtx; /* Locking for accessing the FCB data */ - struct flash_sector *f_oldest; - struct fcb_entry f_active; - u16_t f_active_id; - u8_t f_align; /* writes to flash have to aligned to this */ - - const struct flash_area *fap; /* Flash area used by the fcb instance */ - /* This can be transfer to FCB user */ -}; - -/* - * Error codes. - */ -#define FCB_OK 0 -#define FCB_ERR_ARGS -1 -#define FCB_ERR_FLASH -2 -#define FCB_ERR_NOVAR -3 -#define FCB_ERR_NOSPACE -4 -#define FCB_ERR_NOMEM -5 -#define FCB_ERR_CRC -6 -#define FCB_ERR_MAGIC -7 - -int fcb_init(int f_area_id, struct fcb *fcb); - -/* - * fcb_append() appends an entry to circular buffer. When writing the - * contents for the entry, use loc->fl_area and loc->fl_data_off with - * flash_area_write(). When you're finished, call fcb_append_finish() with - * loc as argument. - */ -int fcb_append(struct fcb *fcb, u16_t len, struct fcb_entry *loc); -int fcb_append_finish(struct fcb *fcb, struct fcb_entry *append_loc); - -/* - * Walk over all log entries in FCB, or entries in a given flash_area. - * cb gets called for every entry. If cb wants to stop the walk, it should - * return non-zero value. - * - * Entry data can be read using flash_area_read(), using - * loc->fe_area, loc->fe_data_off, and loc->fe_data_len as arguments. - */ -typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg); -int fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb, - void *cb_arg); -int fcb_getnext(struct fcb *fcb, struct fcb_entry *loc); - -/* - * Erases the data from oldest sector. - */ -int fcb_rotate(struct fcb *fcb); - -/* - * Start using the scratch block. - */ -int fcb_append_to_scratch(struct fcb *fcb); - -/* - * How many sectors are unused. - */ -int fcb_free_sector_cnt(struct fcb *fcb); - -/* - * Whether FCB has any data. - */ -int fcb_is_empty(struct fcb *fcb); - -/* - * Element at offset *entries* from last position (backwards). - */ -int fcb_offset_last_n(struct fcb *fcb, u8_t entries, - struct fcb_entry *last_n_entry); - -/* - * Clears FCB passed to it - */ -int fcb_clear(struct fcb *fcb); - -int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector, - off_t off, void *dst, size_t len); -int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector, - off_t off, const void *src, size_t len); - -#ifdef __cplusplus -} -#endif +#include #endif /* ZEPHYR_INCLUDE_FCB_H_ */ diff --git a/include/fs/fcb.h b/include/fs/fcb.h new file mode 100644 index 00000000000..a897779eb71 --- /dev/null +++ b/include/fs/fcb.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2017 Nordic Semiconductor ASA + * Copyright (c) 2015 Runtime Inc + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_FS_FCB_H_ +#define ZEPHYR_INCLUDE_FS_FCB_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Flash circular buffer. + */ +#include +#include + +#include + +#include + +#define FCB_MAX_LEN (CHAR_MAX | CHAR_MAX << 7) /* Max length of element */ + +/* + * Entry location is pointer to area (within fcb->f_sectors), and offset + * within that area. + */ +struct fcb_entry { + struct flash_sector *fe_sector; /* ptr to sector */ + /* within fcb->f_sectors */ + u32_t fe_elem_off; /* start of entry */ + u32_t fe_data_off; /* start of data */ + u16_t fe_data_len; /* size of data area */ +}; + +/* + * Helper macro for calculate the data offset related to + * the fcb flash_area start offset. + */ +#define FCB_ENTRY_FA_DATA_OFF(entry) (entry.fe_sector->fs_off +\ + entry.fe_data_off) + +struct fcb_entry_ctx { + struct fcb_entry loc; + const struct flash_area *fap; +}; + +struct fcb { + /* Caller of fcb_init fills this in */ + u32_t f_magic; /* As placed on the disk */ + u8_t f_version; /* Current version number of the data */ + u8_t f_sector_cnt; /* Number of elements in sector array */ + u8_t f_scratch_cnt; /* How many sectors should be kept empty */ + struct flash_sector *f_sectors; /* Array of sectors, */ + /* must be contiguous */ + + /* Flash circular buffer internal state */ + struct k_mutex f_mtx; /* Locking for accessing the FCB data */ + struct flash_sector *f_oldest; + struct fcb_entry f_active; + u16_t f_active_id; + u8_t f_align; /* writes to flash have to aligned to this */ + + const struct flash_area *fap; /* Flash area used by the fcb instance */ + /* This can be transfer to FCB user */ +}; + +/* + * Error codes. + */ +#define FCB_OK 0 +#define FCB_ERR_ARGS -1 +#define FCB_ERR_FLASH -2 +#define FCB_ERR_NOVAR -3 +#define FCB_ERR_NOSPACE -4 +#define FCB_ERR_NOMEM -5 +#define FCB_ERR_CRC -6 +#define FCB_ERR_MAGIC -7 + +int fcb_init(int f_area_id, struct fcb *fcb); + +/* + * fcb_append() appends an entry to circular buffer. When writing the + * contents for the entry, use loc->fl_area and loc->fl_data_off with + * flash_area_write(). When you're finished, call fcb_append_finish() with + * loc as argument. + */ +int fcb_append(struct fcb *fcb, u16_t len, struct fcb_entry *loc); +int fcb_append_finish(struct fcb *fcb, struct fcb_entry *append_loc); + +/* + * Walk over all log entries in FCB, or entries in a given flash_area. + * cb gets called for every entry. If cb wants to stop the walk, it should + * return non-zero value. + * + * Entry data can be read using flash_area_read(), using + * loc->fe_area, loc->fe_data_off, and loc->fe_data_len as arguments. + */ +typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg); +int fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb, + void *cb_arg); +int fcb_getnext(struct fcb *fcb, struct fcb_entry *loc); + +/* + * Erases the data from oldest sector. + */ +int fcb_rotate(struct fcb *fcb); + +/* + * Start using the scratch block. + */ +int fcb_append_to_scratch(struct fcb *fcb); + +/* + * How many sectors are unused. + */ +int fcb_free_sector_cnt(struct fcb *fcb); + +/* + * Whether FCB has any data. + */ +int fcb_is_empty(struct fcb *fcb); + +/* + * Element at offset *entries* from last position (backwards). + */ +int fcb_offset_last_n(struct fcb *fcb, u8_t entries, + struct fcb_entry *last_n_entry); + +/* + * Clears FCB passed to it + */ +int fcb_clear(struct fcb *fcb); + +int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector, + off_t off, void *dst, size_t len); +int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector, + off_t off, const void *src, size_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_INCLUDE_FS_FCB_H_ */ diff --git a/subsys/fs/fcb/fcb.c b/subsys/fs/fcb/fcb.c index cbd953bb01c..fa7aa8c2032 100644 --- a/subsys/fs/fcb/fcb.c +++ b/subsys/fs/fcb/fcb.c @@ -8,7 +8,7 @@ #include #include -#include "fcb.h" +#include #include "fcb_priv.h" #include "string.h" diff --git a/subsys/fs/fcb/fcb_append.c b/subsys/fs/fcb/fcb_append.c index 5ccaf255417..454a60a9e1c 100644 --- a/subsys/fs/fcb/fcb_append.c +++ b/subsys/fs/fcb/fcb_append.c @@ -8,7 +8,7 @@ #include #include -#include "fcb.h" +#include #include "fcb_priv.h" static struct flash_sector * diff --git a/subsys/fs/fcb/fcb_elem_info.c b/subsys/fs/fcb/fcb_elem_info.c index 547dbb639b0..a203d893917 100644 --- a/subsys/fs/fcb/fcb_elem_info.c +++ b/subsys/fs/fcb/fcb_elem_info.c @@ -7,7 +7,7 @@ #include -#include "fcb.h" +#include #include "fcb_priv.h" /* diff --git a/subsys/fs/fcb/fcb_getnext.c b/subsys/fs/fcb/fcb_getnext.c index fc9d2fa0974..9989fefdb8f 100644 --- a/subsys/fs/fcb/fcb_getnext.c +++ b/subsys/fs/fcb/fcb_getnext.c @@ -7,7 +7,7 @@ #include -#include "fcb.h" +#include #include "fcb_priv.h" int diff --git a/subsys/fs/fcb/fcb_rotate.c b/subsys/fs/fcb/fcb_rotate.c index 521da2ab682..8304fa9101d 100644 --- a/subsys/fs/fcb/fcb_rotate.c +++ b/subsys/fs/fcb/fcb_rotate.c @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "fcb.h" +#include #include "fcb_priv.h" int diff --git a/subsys/fs/fcb/fcb_walk.c b/subsys/fs/fcb/fcb_walk.c index 1df7e942070..4a4e199158e 100644 --- a/subsys/fs/fcb/fcb_walk.c +++ b/subsys/fs/fcb/fcb_walk.c @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "fcb.h" +#include #include "fcb_priv.h" /* diff --git a/subsys/settings/include/settings/settings_fcb.h b/subsys/settings/include/settings/settings_fcb.h index a1406cd6813..dbb5a54fb1e 100644 --- a/subsys/settings/include/settings/settings_fcb.h +++ b/subsys/settings/include/settings/settings_fcb.h @@ -8,7 +8,7 @@ #ifndef __SETTINGS_FCB_H_ #define __SETTINGS_FCB_H_ -#include +#include #include "settings/settings.h" #ifdef __cplusplus diff --git a/subsys/settings/src/settings_fcb.c b/subsys/settings/src/settings_fcb.c index 5824e30d0b7..fcaf97f8833 100644 --- a/subsys/settings/src/settings_fcb.c +++ b/subsys/settings/src/settings_fcb.c @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include "settings/settings.h" diff --git a/subsys/settings/src/settings_init.c b/subsys/settings/src/settings_init.c index 12b36124a98..601364d2c50 100644 --- a/subsys/settings/src/settings_init.c +++ b/subsys/settings/src/settings_init.c @@ -62,7 +62,7 @@ int settings_backend_init(void) } #elif defined(CONFIG_SETTINGS_FCB) -#include "fcb.h" +#include #include "settings/settings_fcb.h" static struct flash_sector settings_fcb_area[CONFIG_SETTINGS_FCB_NUM_AREAS + 1]; diff --git a/tests/subsys/fs/fcb/src/fcb_test.h b/tests/subsys/fs/fcb/src/fcb_test.h index 127b3ed486b..b577c43acdf 100644 --- a/tests/subsys/fs/fcb/src/fcb_test.h +++ b/tests/subsys/fs/fcb/src/fcb_test.h @@ -12,7 +12,7 @@ #include #include -#include "fcb.h" +#include #include "fcb_priv.h" #ifdef __cplusplus