zephyr/subsys/fs/fcb/fcb_walk.c
Andrzej Puzdrowski 94a022c954 fcb: start using errno codes
Switch form using privater FCB error codes to
errno codes. FCB private codes convention were compatible
with <errno.h> codes:
- 0 mean success
- negative values mean errors
- similar error types.
There was no sense to kept private FCB error codes.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-09-08 12:42:53 +02:00

50 lines
1001 B
C

/*
* Copyright (c) 2017 Nordic Semiconductor ASA
* Copyright (c) 2015 Runtime Inc
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <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;
}