subsys: fs: fcb: rework fcb_walk and its callback
Previously flash_area structure was the parameter for the callback function for transferring sector location info. Now flash_sector is used so relevant flash_area is missing for the callback. This patch introduces structure fcb_entry_ctx which incorporates entries' location and relevant flash area. It is used to pass complete information to the callback. Additional pointer to the flash_area fcb speeds up operations. Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
This commit is contained in:
parent
e3cd915d8f
commit
95a9dbc4b3
4 changed files with 46 additions and 21 deletions
|
@ -43,9 +43,8 @@ fcb_get_align(const struct fcb *fcb)
|
|||
return align;
|
||||
}
|
||||
|
||||
int
|
||||
fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector,
|
||||
off_t off, void *dst, size_t len)
|
||||
int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector,
|
||||
off_t off, void *dst, size_t len)
|
||||
{
|
||||
const struct flash_area *fa;
|
||||
int rc;
|
||||
|
@ -69,9 +68,8 @@ fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector,
|
||||
off_t off, const void *src, 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)
|
||||
{
|
||||
const struct flash_area *fa;
|
||||
int rc;
|
||||
|
@ -131,6 +129,11 @@ fcb_init(struct fcb *fcb)
|
|||
return FCB_ERR_ARGS;
|
||||
}
|
||||
|
||||
fcb->fap = fcb_open_flash(fcb);
|
||||
if (fcb->fap == NULL) {
|
||||
return FCB_ERR_ARGS;
|
||||
}
|
||||
|
||||
align = fcb_get_align(fcb);
|
||||
if (align == 0) {
|
||||
return FCB_ERR_ARGS;
|
||||
|
@ -264,7 +267,7 @@ fcb_sector_hdr_init(struct fcb *fcb, struct flash_sector *sector, u16_t id)
|
|||
fda._pad = 0xff;
|
||||
fda.fd_id = id;
|
||||
|
||||
rc = fcb_flash_write(fcb, sector, 0, &fda, sizeof fda);
|
||||
rc = fcb_flash_write(fcb, sector, 0, &fda, sizeof(fda));
|
||||
if (rc != 0) {
|
||||
return FCB_ERR_FLASH;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ u8_t fcb_get_align(const struct fcb *fcb);
|
|||
int fcb_erase_sector(const struct fcb *fcb, const struct flash_sector *sector);
|
||||
|
||||
int fcb_getnext_in_sector(struct fcb *fcb, struct fcb_entry *loc);
|
||||
struct flash_sector *fcb_getnext_sector(struct fcb *fcb, struct flash_sector *sector);
|
||||
struct flash_sector *fcb_getnext_sector(struct fcb *fcb,
|
||||
struct flash_sector *sector);
|
||||
int fcb_getnext_nolock(struct fcb *fcb, struct fcb_entry *loc);
|
||||
|
||||
int fcb_elem_info(struct fcb *fcb, struct fcb_entry *loc);
|
||||
|
@ -48,7 +49,7 @@ int fcb_elem_crc8(struct fcb *fcb, struct fcb_entry *loc, u8_t *crc8p);
|
|||
|
||||
int fcb_sector_hdr_init(struct fcb *fcb, struct flash_sector *sector, u16_t id);
|
||||
int fcb_sector_hdr_read(struct fcb *fcb, struct flash_sector *sector,
|
||||
struct fcb_disk_area *fdap);
|
||||
struct fcb_disk_area *fdap);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -14,24 +14,28 @@
|
|||
*/
|
||||
int
|
||||
fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb,
|
||||
void *cb_arg)
|
||||
void *cb_arg)
|
||||
{
|
||||
struct fcb_entry loc;
|
||||
struct fcb_entry_ctx entry_ctx;
|
||||
int rc;
|
||||
|
||||
loc.fe_sector = sector;
|
||||
loc.fe_elem_off = 0;
|
||||
entry_ctx.loc.fe_sector = sector;
|
||||
entry_ctx.loc.fe_elem_off = 0;
|
||||
|
||||
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
||||
if (rc) {
|
||||
return FCB_ERR_ARGS;
|
||||
}
|
||||
while ((rc = fcb_getnext_nolock(fcb, &loc)) != FCB_ERR_NOVAR) {
|
||||
while ((rc = fcb_getnext_nolock(fcb, &entry_ctx.loc)) !=
|
||||
FCB_ERR_NOVAR) {
|
||||
k_mutex_unlock(&fcb->f_mtx);
|
||||
if (sector && loc.fe_sector != sector) {
|
||||
if (sector && entry_ctx.loc.fe_sector != sector) {
|
||||
return 0;
|
||||
}
|
||||
rc = cb(&loc, cb_arg);
|
||||
|
||||
entry_ctx.fap = fcb->fap;
|
||||
|
||||
rc = cb(&entry_ctx, cb_arg);
|
||||
if (rc) {
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue