Skip to content

Commit

Permalink
[fdb] change some assert to error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
armink committed May 14, 2023
1 parent dbf5a58 commit a035ea3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/fdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <flashdb.h>
#include <fdb_low_lvl.h>
#include <string.h>
#include <inttypes.h>

#define FDB_LOG_TAG ""

Expand Down Expand Up @@ -65,7 +66,10 @@ fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *path, fdb_db_t
db->sec_size = block_size;
} else {
/* must be aligned with block size */
FDB_ASSERT(db->sec_size % block_size == 0);
if (db->sec_size % block_size != 0) {
FDB_INFO("Error: db sector size (%" PRIu32 ") MUST align with block size (%" PRIu32 ").\n", db->sec_size, block_size);
return FDB_INIT_FAILED;
}
}

db->max_size = db->storage.part->len;
Expand All @@ -75,9 +79,15 @@ fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *path, fdb_db_t
/* the block size MUST to be the Nth power of 2 */
FDB_ASSERT((db->sec_size & (db->sec_size - 1)) == 0);
/* must align with sector size */
FDB_ASSERT(db->max_size % db->sec_size == 0);
/* must have more than or equal 2 sector */
FDB_ASSERT(db->max_size / db->sec_size >= 2);
if (db->max_size % db->sec_size != 0) {
FDB_INFO("Error: db total size (%" PRIu32 ") MUST align with sector size (%" PRIu32 ").\n", db->max_size, db->sec_size);
return FDB_INIT_FAILED;
}
/* must has more than or equal 2 sectors */
if (db->max_size / db->sec_size < 2) {
FDB_INFO("Error: db MUST has more than or equal 2 sectors, current has %" PRIu32 " sector(s)\n", db->max_size / db->sec_size);
return FDB_INIT_FAILED;
}

return FDB_NO_ERR;
}
Expand Down

0 comments on commit a035ea3

Please sign in to comment.