zephyr/subsys/fs/fcb/fcb_walk.c
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00

50 lines
1,008 B
C

/*
* Copyright (c) 2017 Nordic Semiconductor ASA
* Copyright (c) 2015 Runtime Inc
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/fs/fcb.h>
#include "fcb_priv.h"
/*
* Call 'cb' for every element in flash circular buffer. If sector is specified,
* only elements with that flash_sector are reported.
*/
int
fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb,
void *cb_arg)
{
struct fcb_entry_ctx entry_ctx;
int rc;
entry_ctx.loc.fe_sector = sector;
entry_ctx.loc.fe_elem_off = 0U;
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
if (rc < 0) {
return -EINVAL;
}
while ((rc = fcb_getnext_nolock(fcb, &entry_ctx.loc)) !=
-ENOTSUP) {
k_mutex_unlock(&fcb->f_mtx);
if (sector && entry_ctx.loc.fe_sector != sector) {
return 0;
}
entry_ctx.fap = fcb->fap;
rc = cb(&entry_ctx, cb_arg);
if (rc) {
return rc;
}
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
if (rc < 0) {
return -EINVAL;
}
}
k_mutex_unlock(&fcb->f_mtx);
return 0;
}