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>
This commit is contained in:
parent
ce4cc465fc
commit
94a022c954
14 changed files with 56 additions and 66 deletions
|
@ -123,18 +123,6 @@ struct fcb {
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <fs/fcb.h>
|
#include <fs/fcb.h>
|
||||||
#include "fcb_priv.h"
|
#include "fcb_priv.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
u8_t
|
u8_t
|
||||||
fcb_get_align(const struct fcb *fcb)
|
fcb_get_align(const struct fcb *fcb)
|
||||||
|
@ -32,17 +33,17 @@ int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector,
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (off + len > sector->fs_size) {
|
if (off + len > sector->fs_size) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fcb->fap == NULL) {
|
if (fcb->fap == NULL) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = flash_area_read(fcb->fap, sector->fs_off + off, dst, len);
|
rc = flash_area_read(fcb->fap, sector->fs_off + off, dst, len);
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -54,17 +55,17 @@ int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector,
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (off + len > sector->fs_size) {
|
if (off + len > sector->fs_size) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fcb->fap == NULL) {
|
if (fcb->fap == NULL) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = flash_area_write(fcb->fap, sector->fs_off + off, src, len);
|
rc = flash_area_write(fcb->fap, sector->fs_off + off, src, len);
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -76,13 +77,13 @@ fcb_erase_sector(const struct fcb *fcb, const struct flash_sector *sector)
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (fcb->fap == NULL) {
|
if (fcb->fap == NULL) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = flash_area_erase(fcb->fap, sector->fs_off, sector->fs_size);
|
rc = flash_area_erase(fcb->fap, sector->fs_off, sector->fs_size);
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -100,17 +101,17 @@ fcb_init(int f_area_id, struct fcb *fcb)
|
||||||
struct fcb_disk_area fda;
|
struct fcb_disk_area fda;
|
||||||
|
|
||||||
if (!fcb->f_sectors || fcb->f_sector_cnt - fcb->f_scratch_cnt < 1) {
|
if (!fcb->f_sectors || fcb->f_sector_cnt - fcb->f_scratch_cnt < 1) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = flash_area_open(f_area_id, &fcb->fap);
|
rc = flash_area_open(f_area_id, &fcb->fap);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
align = fcb_get_align(fcb);
|
align = fcb_get_align(fcb);
|
||||||
if (align == 0U) {
|
if (align == 0U) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill last used, first used */
|
/* Fill last used, first used */
|
||||||
|
@ -155,8 +156,8 @@ fcb_init(int f_area_id, struct fcb *fcb)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
rc = fcb_getnext_in_sector(fcb, &fcb->f_active);
|
rc = fcb_getnext_in_sector(fcb, &fcb->f_active);
|
||||||
if (rc == FCB_ERR_NOVAR) {
|
if (rc == -ENOTSUP) {
|
||||||
rc = FCB_OK;
|
rc = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
|
@ -205,7 +206,7 @@ fcb_put_len(u8_t *buf, u16_t len)
|
||||||
buf[1] = len >> 7;
|
buf[1] = len >> 7;
|
||||||
return 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +217,7 @@ fcb_get_len(u8_t *buf, u16_t *len)
|
||||||
|
|
||||||
if (buf[0] & 0x80) {
|
if (buf[0] & 0x80) {
|
||||||
if (buf[0] == 0xff && buf[1] == 0xff) {
|
if (buf[0] == 0xff && buf[1] == 0xff) {
|
||||||
return FCB_ERR_NOVAR;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
*len = (buf[0] & 0x7f) | (buf[1] << 7);
|
*len = (buf[0] & 0x7f) | (buf[1] << 7);
|
||||||
rc = 2;
|
rc = 2;
|
||||||
|
@ -243,7 +244,7 @@ fcb_sector_hdr_init(struct fcb *fcb, struct flash_sector *sector, u16_t id)
|
||||||
|
|
||||||
rc = fcb_flash_write(fcb, sector, 0, &fda, sizeof(fda));
|
rc = fcb_flash_write(fcb, sector, 0, &fda, sizeof(fda));
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -265,13 +266,13 @@ int fcb_sector_hdr_read(struct fcb *fcb, struct flash_sector *sector,
|
||||||
}
|
}
|
||||||
rc = fcb_flash_read(fcb, sector, 0, fdap, sizeof(*fdap));
|
rc = fcb_flash_read(fcb, sector, 0, fdap, sizeof(*fdap));
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
if (fdap->fd_magic == 0xffffffff) {
|
if (fdap->fd_magic == 0xffffffff) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (fdap->fd_magic != fcb->f_magic) {
|
if (fdap->fd_magic != fcb->f_magic) {
|
||||||
return FCB_ERR_MAGIC;
|
return -ENOMSG;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ fcb_append_to_scratch(struct fcb *fcb)
|
||||||
|
|
||||||
sector = fcb_new_sector(fcb, 0);
|
sector = fcb_new_sector(fcb, 0);
|
||||||
if (!sector) {
|
if (!sector) {
|
||||||
return FCB_ERR_NOSPACE;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
rc = fcb_sector_hdr_init(fcb, sector, fcb->f_active_id + 1);
|
rc = fcb_sector_hdr_init(fcb, sector, fcb->f_active_id + 1);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
@ -53,7 +53,7 @@ fcb_append_to_scratch(struct fcb *fcb)
|
||||||
fcb->f_active.fe_sector = sector;
|
fcb->f_active.fe_sector = sector;
|
||||||
fcb->f_active.fe_elem_off = sizeof(struct fcb_disk_area);
|
fcb->f_active.fe_elem_off = sizeof(struct fcb_disk_area);
|
||||||
fcb->f_active_id++;
|
fcb->f_active_id++;
|
||||||
return FCB_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -76,14 +76,14 @@ fcb_append(struct fcb *fcb, u16_t len, struct fcb_entry *append_loc)
|
||||||
|
|
||||||
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
active = &fcb->f_active;
|
active = &fcb->f_active;
|
||||||
if (active->fe_elem_off + len + cnt > active->fe_sector->fs_size) {
|
if (active->fe_elem_off + len + cnt > active->fe_sector->fs_size) {
|
||||||
sector = fcb_new_sector(fcb, fcb->f_scratch_cnt);
|
sector = fcb_new_sector(fcb, fcb->f_scratch_cnt);
|
||||||
if (!sector || (sector->fs_size <
|
if (!sector || (sector->fs_size <
|
||||||
sizeof(struct fcb_disk_area) + len + cnt)) {
|
sizeof(struct fcb_disk_area) + len + cnt)) {
|
||||||
rc = FCB_ERR_NOSPACE;
|
rc = -ENOSPC;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
rc = fcb_sector_hdr_init(fcb, sector, fcb->f_active_id + 1);
|
rc = fcb_sector_hdr_init(fcb, sector, fcb->f_active_id + 1);
|
||||||
|
@ -97,7 +97,7 @@ fcb_append(struct fcb *fcb, u16_t len, struct fcb_entry *append_loc)
|
||||||
|
|
||||||
rc = fcb_flash_write(fcb, active->fe_sector, active->fe_elem_off, tmp_str, cnt);
|
rc = fcb_flash_write(fcb, active->fe_sector, active->fe_elem_off, tmp_str, cnt);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
rc = FCB_ERR_FLASH;
|
rc = -EIO;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
append_loc->fe_sector = active->fe_sector;
|
append_loc->fe_sector = active->fe_sector;
|
||||||
|
@ -108,7 +108,7 @@ fcb_append(struct fcb *fcb, u16_t len, struct fcb_entry *append_loc)
|
||||||
|
|
||||||
k_mutex_unlock(&fcb->f_mtx);
|
k_mutex_unlock(&fcb->f_mtx);
|
||||||
|
|
||||||
return FCB_OK;
|
return 0;
|
||||||
err:
|
err:
|
||||||
k_mutex_unlock(&fcb->f_mtx);
|
k_mutex_unlock(&fcb->f_mtx);
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -131,7 +131,7 @@ fcb_append_finish(struct fcb *fcb, struct fcb_entry *loc)
|
||||||
|
|
||||||
rc = fcb_flash_write(fcb, loc->fe_sector, off, crc8, fcb->f_align);
|
rc = fcb_flash_write(fcb, loc->fe_sector, off, crc8, fcb->f_align);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,11 @@ fcb_elem_crc8(struct fcb *fcb, struct fcb_entry *loc, u8_t *c8p)
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (loc->fe_elem_off + 2 > loc->fe_sector->fs_size) {
|
if (loc->fe_elem_off + 2 > loc->fe_sector->fs_size) {
|
||||||
return FCB_ERR_NOVAR;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
rc = fcb_flash_read(fcb, loc->fe_sector, loc->fe_elem_off, tmp_str, 2);
|
rc = fcb_flash_read(fcb, loc->fe_sector, loc->fe_elem_off, tmp_str, 2);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt = fcb_get_len(tmp_str, &len);
|
cnt = fcb_get_len(tmp_str, &len);
|
||||||
|
@ -54,7 +54,7 @@ fcb_elem_crc8(struct fcb *fcb, struct fcb_entry *loc, u8_t *c8p)
|
||||||
|
|
||||||
rc = fcb_flash_read(fcb, loc->fe_sector, off, tmp_str, blk_sz);
|
rc = fcb_flash_read(fcb, loc->fe_sector, off, tmp_str, blk_sz);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
crc8 = crc8_ccitt(crc8, tmp_str, blk_sz);
|
crc8 = crc8_ccitt(crc8, tmp_str, blk_sz);
|
||||||
}
|
}
|
||||||
|
@ -78,11 +78,11 @@ int fcb_elem_info(struct fcb *fcb, struct fcb_entry *loc)
|
||||||
|
|
||||||
rc = fcb_flash_read(fcb, loc->fe_sector, off, &fl_crc8, sizeof(fl_crc8));
|
rc = fcb_flash_read(fcb, loc->fe_sector, off, &fl_crc8, sizeof(fl_crc8));
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return FCB_ERR_FLASH;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fl_crc8 != crc8) {
|
if (fl_crc8 != crc8) {
|
||||||
return FCB_ERR_CRC;
|
return -EBADMSG;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,16 @@ fcb_getnext_in_sector(struct fcb *fcb, struct fcb_entry *loc)
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = fcb_elem_info(fcb, loc);
|
rc = fcb_elem_info(fcb, loc);
|
||||||
if (rc == 0 || rc == FCB_ERR_CRC) {
|
if (rc == 0 || rc == -EBADMSG) {
|
||||||
do {
|
do {
|
||||||
loc->fe_elem_off = loc->fe_data_off +
|
loc->fe_elem_off = loc->fe_data_off +
|
||||||
fcb_len_in_flash(fcb, loc->fe_data_len) +
|
fcb_len_in_flash(fcb, loc->fe_data_len) +
|
||||||
fcb_len_in_flash(fcb, FCB_CRC_SZ);
|
fcb_len_in_flash(fcb, FCB_CRC_SZ);
|
||||||
rc = fcb_elem_info(fcb, loc);
|
rc = fcb_elem_info(fcb, loc);
|
||||||
if (rc != FCB_ERR_CRC) {
|
if (rc != -EBADMSG) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (rc == FCB_ERR_CRC);
|
} while (rc == -EBADMSG);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ fcb_getnext_nolock(struct fcb *fcb, struct fcb_entry *loc)
|
||||||
switch (rc) {
|
switch (rc) {
|
||||||
case 0:
|
case 0:
|
||||||
return 0;
|
return 0;
|
||||||
case FCB_ERR_CRC:
|
case -EBADMSG:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto next_sector;
|
goto next_sector;
|
||||||
|
@ -70,23 +70,23 @@ fcb_getnext_nolock(struct fcb *fcb, struct fcb_entry *loc)
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (rc == FCB_ERR_NOVAR) {
|
if (rc == -ENOTSUP) {
|
||||||
goto next_sector;
|
goto next_sector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (rc == FCB_ERR_CRC) {
|
while (rc == -EBADMSG) {
|
||||||
rc = fcb_getnext_in_sector(fcb, loc);
|
rc = fcb_getnext_in_sector(fcb, loc);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc != FCB_ERR_CRC) {
|
if (rc != -EBADMSG) {
|
||||||
/*
|
/*
|
||||||
* Moving to next sector.
|
* Moving to next sector.
|
||||||
*/
|
*/
|
||||||
next_sector:
|
next_sector:
|
||||||
if (loc->fe_sector == fcb->f_active.fe_sector) {
|
if (loc->fe_sector == fcb->f_active.fe_sector) {
|
||||||
return FCB_ERR_NOVAR;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
loc->fe_sector = fcb_getnext_sector(fcb, loc->fe_sector);
|
loc->fe_sector = fcb_getnext_sector(fcb, loc->fe_sector);
|
||||||
loc->fe_elem_off = sizeof(struct fcb_disk_area);
|
loc->fe_elem_off = sizeof(struct fcb_disk_area);
|
||||||
|
@ -94,7 +94,7 @@ next_sector:
|
||||||
switch (rc) {
|
switch (rc) {
|
||||||
case 0:
|
case 0:
|
||||||
return 0;
|
return 0;
|
||||||
case FCB_ERR_CRC:
|
case -EBADMSG:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto next_sector;
|
goto next_sector;
|
||||||
|
@ -112,7 +112,7 @@ fcb_getnext(struct fcb *fcb, struct fcb_entry *loc)
|
||||||
|
|
||||||
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
rc = fcb_getnext_nolock(fcb, loc);
|
rc = fcb_getnext_nolock(fcb, loc);
|
||||||
k_mutex_unlock(&fcb->f_mtx);
|
k_mutex_unlock(&fcb->f_mtx);
|
||||||
|
|
|
@ -16,12 +16,12 @@ fcb_rotate(struct fcb *fcb)
|
||||||
|
|
||||||
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = fcb_erase_sector(fcb, fcb->f_oldest);
|
rc = fcb_erase_sector(fcb, fcb->f_oldest);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
rc = FCB_ERR_FLASH;
|
rc = -EIO;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (fcb->f_oldest == fcb->f_active.fe_sector) {
|
if (fcb->f_oldest == fcb->f_active.fe_sector) {
|
||||||
|
|
|
@ -24,10 +24,10 @@ fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb,
|
||||||
|
|
||||||
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
while ((rc = fcb_getnext_nolock(fcb, &entry_ctx.loc)) !=
|
while ((rc = fcb_getnext_nolock(fcb, &entry_ctx.loc)) !=
|
||||||
FCB_ERR_NOVAR) {
|
-ENOTSUP) {
|
||||||
k_mutex_unlock(&fcb->f_mtx);
|
k_mutex_unlock(&fcb->f_mtx);
|
||||||
if (sector && entry_ctx.loc.fe_sector != sector) {
|
if (sector && entry_ctx.loc.fe_sector != sector) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -41,7 +41,7 @@ fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb,
|
||||||
}
|
}
|
||||||
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
rc = k_mutex_lock(&fcb->f_mtx, K_FOREVER);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
return FCB_ERR_ARGS;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
k_mutex_unlock(&fcb->f_mtx);
|
k_mutex_unlock(&fcb->f_mtx);
|
||||||
|
|
|
@ -268,7 +268,7 @@ static int settings_fcb_save_priv(struct settings_store *cs, const char *name,
|
||||||
|
|
||||||
for (i = 0; i < cf->cf_fcb.f_sector_cnt - 1; i++) {
|
for (i = 0; i < cf->cf_fcb.f_sector_cnt - 1; i++) {
|
||||||
rc = fcb_append(&cf->cf_fcb, len, &loc.loc);
|
rc = fcb_append(&cf->cf_fcb, len, &loc.loc);
|
||||||
if (rc != FCB_ERR_NOSPACE) {
|
if (rc != -ENOSPC) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
settings_fcb_compress(cf);
|
settings_fcb_compress(cf);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include <fs/fcb.h>
|
#include <fs/fcb.h>
|
||||||
#include "fcb_priv.h"
|
#include "fcb_priv.h"
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#extern "C" {
|
#extern "C" {
|
||||||
|
|
|
@ -32,7 +32,7 @@ void fcb_test_append_fill(void)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
||||||
if (rc == FCB_ERR_NOSPACE) {
|
if (rc == -ENOSPC) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (loc.fe_sector == &test_fcb_sector[0]) {
|
if (loc.fe_sector == &test_fcb_sector[0]) {
|
||||||
|
|
|
@ -16,17 +16,17 @@ void fcb_test_init(void)
|
||||||
(void)memset(fcb, 0, sizeof(*fcb));
|
(void)memset(fcb, 0, sizeof(*fcb));
|
||||||
|
|
||||||
rc = fcb_init(TEST_FCB_FLASH_AREA_ID, fcb);
|
rc = fcb_init(TEST_FCB_FLASH_AREA_ID, fcb);
|
||||||
zassert_true(rc == FCB_ERR_ARGS, "fcb_init call should fail");
|
zassert_true(rc == -EINVAL, "fcb_init call should fail");
|
||||||
|
|
||||||
fcb->f_sectors = test_fcb_sector;
|
fcb->f_sectors = test_fcb_sector;
|
||||||
|
|
||||||
rc = fcb_init(TEST_FCB_FLASH_AREA_ID, fcb);
|
rc = fcb_init(TEST_FCB_FLASH_AREA_ID, fcb);
|
||||||
zassert_true(rc == FCB_ERR_ARGS, "fcb_init call should fail");
|
zassert_true(rc == -EINVAL, "fcb_init call should fail");
|
||||||
|
|
||||||
fcb->f_sector_cnt = 2U;
|
fcb->f_sector_cnt = 2U;
|
||||||
fcb->f_magic = 0x12345678;
|
fcb->f_magic = 0x12345678;
|
||||||
rc = fcb_init(TEST_FCB_FLASH_AREA_ID, fcb);
|
rc = fcb_init(TEST_FCB_FLASH_AREA_ID, fcb);
|
||||||
zassert_true(rc == FCB_ERR_MAGIC, "fcb_init call should fail");
|
zassert_true(rc == -ENOMSG, "fcb_init call should fail");
|
||||||
|
|
||||||
fcb->f_magic = 0U;
|
fcb->f_magic = 0U;
|
||||||
rc = fcb_init(TEST_FCB_FLASH_AREA_ID, fcb);
|
rc = fcb_init(TEST_FCB_FLASH_AREA_ID, fcb);
|
||||||
|
|
|
@ -29,7 +29,7 @@ void fcb_test_last_of_n(void)
|
||||||
*/
|
*/
|
||||||
for (i = 0U; i < ENTRIES; i++) {
|
for (i = 0U; i < ENTRIES; i++) {
|
||||||
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
||||||
if (rc == FCB_ERR_NOSPACE) {
|
if (rc == -ENOSPC) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ void fcb_test_multi_scratch(void)
|
||||||
(void)memset(elem_cnts, 0, sizeof(elem_cnts));
|
(void)memset(elem_cnts, 0, sizeof(elem_cnts));
|
||||||
while (1) {
|
while (1) {
|
||||||
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
||||||
if (rc == FCB_ERR_NOSPACE) {
|
if (rc == -ENOSPC) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
idx = loc.fe_sector - &test_fcb_sector[0];
|
idx = loc.fe_sector - &test_fcb_sector[0];
|
||||||
|
@ -58,7 +58,7 @@ void fcb_test_multi_scratch(void)
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
||||||
if (rc == FCB_ERR_NOSPACE) {
|
if (rc == -ENOSPC) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
idx = loc.fe_sector - &test_fcb_sector[0];
|
idx = loc.fe_sector - &test_fcb_sector[0];
|
||||||
|
|
|
@ -33,7 +33,7 @@ void fcb_test_rotate(void)
|
||||||
*/
|
*/
|
||||||
while (1) {
|
while (1) {
|
||||||
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
rc = fcb_append(fcb, sizeof(test_data), &loc);
|
||||||
if (rc == FCB_ERR_NOSPACE) {
|
if (rc == -ENOSPC) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (loc.fe_sector == &test_fcb_sector[0]) {
|
if (loc.fe_sector == &test_fcb_sector[0]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue