Browse Source

fs: fcb: rename variables differently than struct tag

Even just making minor edits to fcb, warnings are triggered
from Coding Guidelines of the form

Violation to rule 5.7 (Tag name should be unique) tag: fcb

Rename pointer variable names to fcbp.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
pull/75780/head
Chris Friedt 1 year ago committed by Alberto Escolar
parent
commit
3b54d2b4b9
  1. 58
      include/zephyr/fs/fcb.h
  2. 148
      subsys/fs/fcb/fcb.c
  3. 42
      subsys/fs/fcb/fcb_priv.h

58
include/zephyr/fs/fcb.h

@ -158,11 +158,11 @@ struct fcb {
* Initialize FCB instance. * Initialize FCB instance.
* *
* @param[in] f_area_id ID of flash area where fcb storage resides. * @param[in] f_area_id ID of flash area where fcb storage resides.
* @param[in,out] fcb FCB instance structure. * @param[in,out] fcbp FCB instance structure.
* *
* @return 0 on success, non-zero on failure. * @return 0 on success, non-zero on failure.
*/ */
int fcb_init(int f_area_id, struct fcb *fcb); int fcb_init(int f_area_id, struct fcb *fcbp);
/** /**
* Appends an entry to circular buffer. * Appends an entry to circular buffer.
@ -172,24 +172,24 @@ int fcb_init(int f_area_id, struct fcb *fcb);
* flash_area_write() to fcb flash_area. * flash_area_write() to fcb flash_area.
* When you're finished, call fcb_append_finish() with loc as argument. * When you're finished, call fcb_append_finish() with loc as argument.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* @param[in] len Length of data which are expected to be written as the entry * @param[in] len Length of data which are expected to be written as the entry
* payload. * payload.
* @param[out] loc entry location information * @param[out] loc entry location information
* *
* @return 0 on success, non-zero on failure. * @return 0 on success, non-zero on failure.
*/ */
int fcb_append(struct fcb *fcb, uint16_t len, struct fcb_entry *loc); int fcb_append(struct fcb *fcbp, uint16_t len, struct fcb_entry *loc);
/** /**
* Finishes entry append operation. * Finishes entry append operation.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* @param[in] append_loc entry location information * @param[in] append_loc entry location information
* *
* @return 0 on success, non-zero on failure. * @return 0 on success, non-zero on failure.
*/ */
int fcb_append_finish(struct fcb *fcb, struct fcb_entry *append_loc); int fcb_append_finish(struct fcb *fcbp, struct fcb_entry *append_loc);
/** /**
* FCB Walk callback function type. * FCB Walk callback function type.
@ -213,7 +213,7 @@ typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg);
* *
* @param[in] sector fcb sector to be walked. If null, traverse entire * @param[in] sector fcb sector to be walked. If null, traverse entire
* storage. * storage.
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* @param[in] cb pointer to the function which gets called for every * @param[in] cb pointer to the function which gets called for every
* entry. If cb wants to stop the walk, it should return * entry. If cb wants to stop the walk, it should return
* non-zero value. * non-zero value.
@ -223,8 +223,7 @@ typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg);
* @return 0 on success, negative on failure (or transferred form callback * @return 0 on success, negative on failure (or transferred form callback
* return-value), positive transferred form callback return-value * return-value), positive transferred form callback return-value
*/ */
int fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb, int fcb_walk(struct fcb *fcbp, struct flash_sector *sector, fcb_walk_cb cb, void *cb_arg);
void *cb_arg);
/** /**
* Get next fcb entry location. * Get next fcb entry location.
@ -237,12 +236,12 @@ int fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb,
* FCB storage. loc->fe_sector is set and loc->fe_elem_off is 0 function fetches * FCB storage. loc->fe_sector is set and loc->fe_elem_off is 0 function fetches
* the first entry location in the fcb sector. * the first entry location in the fcb sector.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* @param[in,out] loc entry location information * @param[in,out] loc entry location information
* *
* @return 0 on success, non-zero on failure. * @return 0 on success, non-zero on failure.
*/ */
int fcb_getnext(struct fcb *fcb, struct fcb_entry *loc); int fcb_getnext(struct fcb *fcbp, struct fcb_entry *loc);
/** /**
* Rotate fcb sectors * Rotate fcb sectors
@ -250,9 +249,9 @@ int fcb_getnext(struct fcb *fcb, struct fcb_entry *loc);
* Function erases the data from oldest sector. Upon that the next sector * Function erases the data from oldest sector. Upon that the next sector
* becomes the oldest. Active sector is also switched if needed. * becomes the oldest. Active sector is also switched if needed.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
*/ */
int fcb_rotate(struct fcb *fcb); int fcb_rotate(struct fcb *fcbp);
/** /**
* Start using the scratch block. * Start using the scratch block.
@ -260,50 +259,49 @@ int fcb_rotate(struct fcb *fcb);
* Take one of the scratch blocks into use. So a scratch sector becomes * Take one of the scratch blocks into use. So a scratch sector becomes
* active sector to which entries can be appended. * active sector to which entries can be appended.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* *
* @return 0 on success, non-zero on failure. * @return 0 on success, non-zero on failure.
*/ */
int fcb_append_to_scratch(struct fcb *fcb); int fcb_append_to_scratch(struct fcb *fcbp);
/** /**
* Get free sector count. * Get free sector count.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* *
* @return Number of free sectors. * @return Number of free sectors.
*/ */
int fcb_free_sector_cnt(struct fcb *fcb); int fcb_free_sector_cnt(struct fcb *fcbp);
/** /**
* Check whether FCB has any data. * Check whether FCB has any data.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* *
* @return Positive value if fcb is empty, otherwise 0. * @return Positive value if fcb is empty, otherwise 0.
*/ */
int fcb_is_empty(struct fcb *fcb); int fcb_is_empty(struct fcb *fcbp);
/** /**
* Finds the fcb entry that gives back up to n entries at the end. * Finds the fcb entry that gives back up to n entries at the end.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* @param[in] entries number of fcb entries the user wants to get * @param[in] entries number of fcb entries the user wants to get
* @param[out] last_n_entry last_n_entry the fcb_entry to be returned * @param[out] last_n_entry last_n_entry the fcb_entry to be returned
* *
* @return 0 on there are any fcbs available; -ENOENT otherwise * @return 0 on there are any fcbs available; -ENOENT otherwise
*/ */
int fcb_offset_last_n(struct fcb *fcb, uint8_t entries, int fcb_offset_last_n(struct fcb *fcbp, uint8_t entries, struct fcb_entry *last_n_entry);
struct fcb_entry *last_n_entry);
/** /**
* Clear fcb instance storage. * Clear fcb instance storage.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* *
* @return 0 on success; non-zero on failure * @return 0 on success; non-zero on failure
*/ */
int fcb_clear(struct fcb *fcb); int fcb_clear(struct fcb *fcbp);
/** /**
* @} * @}
@ -319,7 +317,7 @@ int fcb_clear(struct fcb *fcb);
/** /**
* Read raw data from the fcb flash sector. * Read raw data from the fcb flash sector.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* @param[in] sector FCB sector. * @param[in] sector FCB sector.
* @param[in] off Read offset form sector begin. * @param[in] off Read offset form sector begin.
* @param[out] dst Destination buffer. * @param[out] dst Destination buffer.
@ -327,13 +325,13 @@ int fcb_clear(struct fcb *fcb);
* *
* @return 0 on success, negative errno code on fail. * @return 0 on success, negative errno code on fail.
*/ */
int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector, int fcb_flash_read(const struct fcb *fcbp, const struct flash_sector *sector, off_t off,
off_t off, void *dst, size_t len); void *dst, size_t len);
/** /**
* Write raw data to the fcb flash sector. * Write raw data to the fcb flash sector.
* *
* @param[in] fcb FCB instance structure. * @param[in] fcbp FCB instance structure.
* @param[in] sector FCB sector. * @param[in] sector FCB sector.
* @param[in] off Write offset form sector begin. * @param[in] off Write offset form sector begin.
* @param[in] src Source buffer. * @param[in] src Source buffer.
@ -341,8 +339,8 @@ int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector,
* *
* @return 0 on success, negative errno code on fail. * @return 0 on success, negative errno code on fail.
*/ */
int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector, int fcb_flash_write(const struct fcb *fcbp, const struct flash_sector *sector, off_t off,
off_t off, const void *src, size_t len); const void *src, size_t len);
/** /**
* @} * @}

148
subsys/fs/fcb/fcb.c

@ -5,32 +5,32 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include "fcb_priv.h"
#include <errno.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <zephyr/fs/fcb.h>
#include "fcb_priv.h"
#include "string.h"
#include <errno.h>
#include <zephyr/device.h> #include <zephyr/device.h>
#include <zephyr/drivers/flash.h> #include <zephyr/drivers/flash.h>
#include <zephyr/fs/fcb.h>
uint8_t uint8_t fcb_get_align(const struct fcb *fcbp)
fcb_get_align(const struct fcb *fcb)
{ {
uint8_t align; uint8_t align;
if (fcb->fap == NULL) { if (fcbp->fap == NULL) {
return 0; return 0;
} }
align = flash_area_align(fcb->fap); align = flash_area_align(fcbp->fap);
return align; return align;
} }
int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector, int fcb_flash_read(const struct fcb *fcbp, const struct flash_sector *sector, off_t off,
off_t off, void *dst, size_t len) void *dst, size_t len)
{ {
int rc; int rc;
@ -38,11 +38,11 @@ int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector,
return -EINVAL; return -EINVAL;
} }
if (fcb->fap == NULL) { if (fcbp->fap == NULL) {
return -EIO; return -EIO;
} }
rc = flash_area_read(fcb->fap, sector->fs_off + off, dst, len); rc = flash_area_read(fcbp->fap, sector->fs_off + off, dst, len);
if (rc != 0) { if (rc != 0) {
return -EIO; return -EIO;
@ -51,8 +51,8 @@ int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector,
return 0; return 0;
} }
int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector, int fcb_flash_write(const struct fcb *fcbp, const struct flash_sector *sector, off_t off,
off_t off, const void *src, size_t len) const void *src, size_t len)
{ {
int rc; int rc;
@ -60,11 +60,11 @@ int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector,
return -EINVAL; return -EINVAL;
} }
if (fcb->fap == NULL) { if (fcbp->fap == NULL) {
return -EIO; return -EIO;
} }
rc = flash_area_write(fcb->fap, sector->fs_off + off, src, len); rc = flash_area_write(fcbp->fap, sector->fs_off + off, src, len);
if (rc != 0) { if (rc != 0) {
return -EIO; return -EIO;
@ -73,16 +73,15 @@ int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector,
return 0; return 0;
} }
int int fcb_erase_sector(const struct fcb *fcbp, const struct flash_sector *sector)
fcb_erase_sector(const struct fcb *fcb, const struct flash_sector *sector)
{ {
int rc; int rc;
if (fcb->fap == NULL) { if (fcbp->fap == NULL) {
return -EIO; return -EIO;
} }
rc = flash_area_flatten(fcb->fap, sector->fs_off, sector->fs_size); rc = flash_area_flatten(fcbp->fap, sector->fs_off, sector->fs_size);
if (rc != 0) { if (rc != 0) {
return -EIO; return -EIO;
} }
@ -90,8 +89,7 @@ fcb_erase_sector(const struct fcb *fcb, const struct flash_sector *sector)
return 0; return 0;
} }
int int fcb_init(int f_area_id, struct fcb *fcbp)
fcb_init(int f_area_id, struct fcb *fcb)
{ {
struct flash_sector *sector; struct flash_sector *sector;
int rc; int rc;
@ -102,27 +100,27 @@ fcb_init(int f_area_id, struct fcb *fcb)
struct fcb_disk_area fda; struct fcb_disk_area fda;
const struct flash_parameters *fparam; const struct flash_parameters *fparam;
if (!fcb->f_sectors || fcb->f_sector_cnt - fcb->f_scratch_cnt < 1) { if (!fcbp->f_sectors || fcbp->f_sector_cnt - fcbp->f_scratch_cnt < 1) {
return -EINVAL; return -EINVAL;
} }
rc = flash_area_open(f_area_id, &fcb->fap); rc = flash_area_open(f_area_id, &fcbp->fap);
if (rc != 0) { if (rc != 0) {
return -EINVAL; return -EINVAL;
} }
fparam = flash_get_parameters(fcb->fap->fa_dev); fparam = flash_get_parameters(fcbp->fap->fa_dev);
fcb->f_erase_value = fparam->erase_value; fcbp->f_erase_value = fparam->erase_value;
align = fcb_get_align(fcb); align = fcb_get_align(fcbp);
if (align == 0U) { if (align == 0U) {
return -EINVAL; return -EINVAL;
} }
/* Fill last used, first used */ /* Fill last used, first used */
for (i = 0; i < fcb->f_sector_cnt; i++) { for (i = 0; i < fcbp->f_sector_cnt; i++) {
sector = &fcb->f_sectors[i]; sector = &fcbp->f_sectors[i];
rc = fcb_sector_hdr_read(fcb, sector, &fda); rc = fcb_sector_hdr_read(fcbp, sector, &fda);
if (rc < 0) { if (rc < 0) {
return rc; return rc;
} }
@ -146,21 +144,21 @@ fcb_init(int f_area_id, struct fcb *fcb)
/* /*
* No initialized areas. * No initialized areas.
*/ */
oldest_sector = newest_sector = &fcb->f_sectors[0]; oldest_sector = newest_sector = &fcbp->f_sectors[0];
rc = fcb_sector_hdr_init(fcb, oldest_sector, 0); rc = fcb_sector_hdr_init(fcbp, oldest_sector, 0);
if (rc) { if (rc) {
return rc; return rc;
} }
newest = oldest = 0; newest = oldest = 0;
} }
fcb->f_align = align; fcbp->f_align = align;
fcb->f_oldest = oldest_sector; fcbp->f_oldest = oldest_sector;
fcb->f_active.fe_sector = newest_sector; fcbp->f_active.fe_sector = newest_sector;
fcb->f_active.fe_elem_off = fcb_len_in_flash(fcb, sizeof(struct fcb_disk_area)); fcbp->f_active.fe_elem_off = fcb_len_in_flash(fcbp, sizeof(struct fcb_disk_area));
fcb->f_active_id = newest; fcbp->f_active_id = newest;
while (1) { while (1) {
rc = fcb_getnext_in_sector(fcb, &fcb->f_active); rc = fcb_getnext_in_sector(fcbp, &fcbp->f_active);
if (rc == -ENOTSUP) { if (rc == -ENOTSUP) {
rc = 0; rc = 0;
break; break;
@ -169,31 +167,29 @@ fcb_init(int f_area_id, struct fcb *fcb)
break; break;
} }
} }
k_mutex_init(&fcb->f_mtx); k_mutex_init(&fcbp->f_mtx);
return rc; return rc;
} }
int int fcb_free_sector_cnt(struct fcb *fcbp)
fcb_free_sector_cnt(struct fcb *fcb)
{ {
int i; int i;
struct flash_sector *fa; struct flash_sector *fa;
fa = fcb->f_active.fe_sector; fa = fcbp->f_active.fe_sector;
for (i = 0; i < fcb->f_sector_cnt; i++) { for (i = 0; i < fcbp->f_sector_cnt; i++) {
fa = fcb_getnext_sector(fcb, fa); fa = fcb_getnext_sector(fcbp, fa);
if (fa == fcb->f_oldest) { if (fa == fcbp->f_oldest) {
break; break;
} }
} }
return i; return i;
} }
int int fcb_is_empty(struct fcb *fcbp)
fcb_is_empty(struct fcb *fcb)
{ {
return (fcb->f_active.fe_sector == fcb->f_oldest && return (fcbp->f_active.fe_sector == fcbp->f_oldest &&
fcb->f_active.fe_elem_off == fcb_len_in_flash(fcb, sizeof(struct fcb_disk_area))); fcbp->f_active.fe_elem_off == fcb_len_in_flash(fcbp, sizeof(struct fcb_disk_area)));
} }
/** /**
@ -217,36 +213,33 @@ fcb_is_empty(struct fcb *fcb)
* to correctly use the first bit of byte to figure out how many bytes are there * to correctly use the first bit of byte to figure out how many bytes are there
* and if there is any data at all or both bytes are equal to erase value. * and if there is any data at all or both bytes are equal to erase value.
*/ */
int int fcb_put_len(const struct fcb *fcbp, uint8_t *buf, uint16_t len)
fcb_put_len(const struct fcb *fcb, uint8_t *buf, uint16_t len)
{ {
if (len < 0x80) { if (len < 0x80) {
buf[0] = len ^ ~fcb->f_erase_value; buf[0] = len ^ ~fcbp->f_erase_value;
return 1; return 1;
} else if (len <= FCB_MAX_LEN) { } else if (len <= FCB_MAX_LEN) {
buf[0] = (len | 0x80) ^ ~fcb->f_erase_value; buf[0] = (len | 0x80) ^ ~fcbp->f_erase_value;
buf[1] = (len >> 7) ^ ~fcb->f_erase_value; buf[1] = (len >> 7) ^ ~fcbp->f_erase_value;
return 2; return 2;
} else { } else {
return -EINVAL; return -EINVAL;
} }
} }
int int fcb_get_len(const struct fcb *fcbp, uint8_t *buf, uint16_t *len)
fcb_get_len(const struct fcb *fcb, uint8_t *buf, uint16_t *len)
{ {
int rc; int rc;
uint8_t buf0_xor; uint8_t buf0_xor;
uint8_t buf1_xor; uint8_t buf1_xor;
buf0_xor = buf[0] ^ ~fcb->f_erase_value; buf0_xor = buf[0] ^ ~fcbp->f_erase_value;
if (buf0_xor & 0x80) { if (buf0_xor & 0x80) {
if ((buf[0] == fcb->f_erase_value) && if ((buf[0] == fcbp->f_erase_value) && (buf[1] == fcbp->f_erase_value)) {
(buf[1] == fcb->f_erase_value)) {
return -ENOTSUP; return -ENOTSUP;
} }
buf1_xor = buf[1] ^ ~fcb->f_erase_value; buf1_xor = buf[1] ^ ~fcbp->f_erase_value;
*len = (uint16_t)((buf0_xor & 0x7f) | ((uint16_t)buf1_xor << 7)); *len = (uint16_t)((buf0_xor & 0x7f) | ((uint16_t)buf1_xor << 7));
rc = 2; rc = 2;
} else { } else {
@ -259,18 +252,17 @@ fcb_get_len(const struct fcb *fcb, uint8_t *buf, uint16_t *len)
/** /**
* Initialize erased sector for use. * Initialize erased sector for use.
*/ */
int int fcb_sector_hdr_init(struct fcb *fcbp, struct flash_sector *sector, uint16_t id)
fcb_sector_hdr_init(struct fcb *fcb, struct flash_sector *sector, uint16_t id)
{ {
struct fcb_disk_area fda; struct fcb_disk_area fda;
int rc; int rc;
fda.fd_magic = fcb_flash_magic(fcb); fda.fd_magic = fcb_flash_magic(fcbp);
fda.fd_ver = fcb->f_version; fda.fd_ver = fcbp->f_version;
fda._pad = fcb->f_erase_value; fda._pad = fcbp->f_erase_value;
fda.fd_id = id; fda.fd_id = id;
rc = fcb_flash_write(fcb, sector, 0, &fda, sizeof(fda)); rc = fcb_flash_write(fcbp, sector, 0, &fda, sizeof(fda));
if (rc != 0) { if (rc != 0) {
return -EIO; return -EIO;
} }
@ -283,8 +275,7 @@ fcb_sector_hdr_init(struct fcb *fcb, struct flash_sector *sector, uint16_t id)
* Returns 0 if sector is unused; * Returns 0 if sector is unused;
* Returns 1 if sector has data. * Returns 1 if sector has data.
*/ */
int fcb_sector_hdr_read(struct fcb *fcb, struct flash_sector *sector, int fcb_sector_hdr_read(struct fcb *fcbp, struct flash_sector *sector, struct fcb_disk_area *fdap)
struct fcb_disk_area *fdap)
{ {
struct fcb_disk_area fda; struct fcb_disk_area fda;
int rc; int rc;
@ -292,14 +283,14 @@ int fcb_sector_hdr_read(struct fcb *fcb, struct flash_sector *sector,
if (!fdap) { if (!fdap) {
fdap = &fda; fdap = &fda;
} }
rc = fcb_flash_read(fcb, sector, 0, fdap, sizeof(*fdap)); rc = fcb_flash_read(fcbp, sector, 0, fdap, sizeof(*fdap));
if (rc) { if (rc) {
return -EIO; return -EIO;
} }
if (fdap->fd_magic == MK32(fcb->f_erase_value)) { if (fdap->fd_magic == MK32(fcbp->f_erase_value)) {
return 0; return 0;
} }
if (fdap->fd_magic != fcb_flash_magic(fcb)) { if (fdap->fd_magic != fcb_flash_magic(fcbp)) {
return -ENOMSG; return -ENOMSG;
} }
return 1; return 1;
@ -312,9 +303,7 @@ int fcb_sector_hdr_read(struct fcb *fcb, struct flash_sector *sector,
* @param2 ptr to the fcb_entry to be returned * @param2 ptr to the fcb_entry to be returned
* @return 0 on there are any fcbs aviable; -ENOENT otherwise * @return 0 on there are any fcbs aviable; -ENOENT otherwise
*/ */
int int fcb_offset_last_n(struct fcb *fcbp, uint8_t entries, struct fcb_entry *last_n_entry)
fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
struct fcb_entry *last_n_entry)
{ {
struct fcb_entry loc; struct fcb_entry loc;
int i; int i;
@ -327,14 +316,14 @@ fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
i = 0; i = 0;
(void)memset(&loc, 0, sizeof(loc)); (void)memset(&loc, 0, sizeof(loc));
while (!fcb_getnext(fcb, &loc)) { while (!fcb_getnext(fcbp, &loc)) {
if (i == 0) { if (i == 0) {
/* Start from the beginning of fcb entries */ /* Start from the beginning of fcb entries */
*last_n_entry = loc; *last_n_entry = loc;
} }
/* Update last_n_entry after n entries and keep updating */ /* Update last_n_entry after n entries and keep updating */
else if (i > (entries - 1)) { else if (i > (entries - 1)) {
rc = fcb_getnext(fcb, last_n_entry); rc = fcb_getnext(fcbp, last_n_entry);
if (rc) { if (rc) {
/* A fcb history must have been erased, /* A fcb history must have been erased,
@ -354,14 +343,13 @@ fcb_offset_last_n(struct fcb *fcb, uint8_t entries,
* @param fcb * @param fcb
* @return 0 on success; non-zero on failure * @return 0 on success; non-zero on failure
*/ */
int int fcb_clear(struct fcb *fcbp)
fcb_clear(struct fcb *fcb)
{ {
int rc; int rc;
rc = 0; rc = 0;
while (!fcb_is_empty(fcb)) { while (!fcb_is_empty(fcbp)) {
rc = fcb_rotate(fcb); rc = fcb_rotate(fcbp);
if (rc) { if (rc) {
break; break;
} }

42
subsys/fs/fcb/fcb_priv.h

@ -8,6 +8,10 @@
#ifndef __FCB_PRIV_H_ #ifndef __FCB_PRIV_H_
#define __FCB_PRIV_H_ #define __FCB_PRIV_H_
#include <stdint.h>
#include <zephyr/fs/fcb.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -35,11 +39,11 @@ extern "C" {
* *
* @return uin32_t formatted magic value * @return uin32_t formatted magic value
*/ */
static inline uint32_t fcb_flash_magic(const struct fcb *fcb) static inline uint32_t fcb_flash_magic(const struct fcb *fcbp)
{ {
const uint8_t ev = fcb->f_erase_value; const uint8_t ev = fcbp->f_erase_value;
return (fcb->f_magic ^ ~MK32(ev)); return (fcbp->f_magic ^ ~MK32(ev));
} }
struct fcb_disk_area { struct fcb_disk_area {
@ -49,32 +53,30 @@ struct fcb_disk_area {
uint16_t fd_id; uint16_t fd_id;
}; };
int fcb_put_len(const struct fcb *fcb, uint8_t *buf, uint16_t len); int fcb_put_len(const struct fcb *fcbp, uint8_t *buf, uint16_t len);
int fcb_get_len(const struct fcb *fcb, uint8_t *buf, uint16_t *len); int fcb_get_len(const struct fcb *fcbp, uint8_t *buf, uint16_t *len);
static inline int fcb_len_in_flash(struct fcb *fcb, uint16_t len) static inline int fcb_len_in_flash(struct fcb *fcbp, uint16_t len)
{ {
if (fcb->f_align <= 1U) { if (fcbp->f_align <= 1U) {
return len; return len;
} }
return (len + (fcb->f_align - 1U)) & ~(fcb->f_align - 1U); return (len + (fcbp->f_align - 1U)) & ~(fcbp->f_align - 1U);
} }
const struct flash_area *fcb_open_flash(const struct fcb *fcb); const struct flash_area *fcb_open_flash(const struct fcb *fcbp);
uint8_t fcb_get_align(const struct fcb *fcb); uint8_t fcb_get_align(const struct fcb *fcbp);
int fcb_erase_sector(const struct fcb *fcb, const struct flash_sector *sector); int fcb_erase_sector(const struct fcb *fcbp, const struct flash_sector *sector);
int fcb_getnext_in_sector(struct fcb *fcb, struct fcb_entry *loc); int fcb_getnext_in_sector(struct fcb *fcbp, struct fcb_entry *loc);
struct flash_sector *fcb_getnext_sector(struct fcb *fcb, struct flash_sector *fcb_getnext_sector(struct fcb *fcbp, struct flash_sector *sector);
struct flash_sector *sector); int fcb_getnext_nolock(struct fcb *fcbp, struct fcb_entry *loc);
int fcb_getnext_nolock(struct fcb *fcb, struct fcb_entry *loc);
int fcb_elem_info(struct fcb *fcb, struct fcb_entry *loc); int fcb_elem_info(struct fcb *fcbp, struct fcb_entry *loc);
int fcb_elem_endmarker(struct fcb *fcb, struct fcb_entry *loc, uint8_t *crc8p); int fcb_elem_endmarker(struct fcb *fcbp, struct fcb_entry *loc, uint8_t *crc8p);
int fcb_sector_hdr_init(struct fcb *fcb, struct flash_sector *sector, uint16_t id); int fcb_sector_hdr_init(struct fcb *fcbp, struct flash_sector *sector, uint16_t id);
int fcb_sector_hdr_read(struct fcb *fcb, struct flash_sector *sector, int fcb_sector_hdr_read(struct fcb *fcbp, struct flash_sector *sector, struct fcb_disk_area *fdap);
struct fcb_disk_area *fdap);
#ifdef __cplusplus #ifdef __cplusplus
} }

Loading…
Cancel
Save