From 4e5677408256f82d47cd56a6b04605dcee35ed9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=A4=A9=E9=BE=99=20=28Armink=29?= Date: Sun, 28 May 2023 19:03:26 +0800 Subject: [PATCH] [fdb] add db path info for logs --- inc/fdb_low_lvl.h | 1 + src/fdb.c | 22 ++++++++++++++++++++-- src/fdb_kvdb.c | 5 +++-- src/fdb_tsdb.c | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/inc/fdb_low_lvl.h b/inc/fdb_low_lvl.h index 0f16047..a9b78e2 100644 --- a/inc/fdb_low_lvl.h +++ b/inc/fdb_low_lvl.h @@ -57,6 +57,7 @@ uint32_t _fdb_continue_ff_addr(fdb_db_t db, uint32_t start, uint32_t end); fdb_err_t _fdb_init_ex(fdb_db_t db, const char *name, const char *part_name, fdb_db_type type, void *user_data); void _fdb_init_finish(fdb_db_t db, fdb_err_t result); void _fdb_deinit(fdb_db_t db); +const char *_fdb_db_path(fdb_db_t db); fdb_err_t _fdb_write_status(fdb_db_t db, uint32_t addr, uint8_t status_table[], size_t status_num, size_t status_index, bool sync); size_t _fdb_read_status(fdb_db_t db, uint32_t addr, uint8_t status_table[], size_t total_num); fdb_err_t _fdb_flash_read(fdb_db_t db, uint32_t addr, void *buf, size_t size); diff --git a/src/fdb.c b/src/fdb.c index bfd5274..08b47c4 100644 --- a/src/fdb.c +++ b/src/fdb.c @@ -103,8 +103,8 @@ void _fdb_init_finish(fdb_db_t db, fdb_err_t result) log_is_show = true; } } else if (!db->not_formatable) { - FDB_INFO("Error: %s (%s) is initialize fail (%d).\n", db->type == FDB_DB_TYPE_KV ? "KVDB" : "TSDB", - db->name, (int)result); + FDB_INFO("Error: %s (%s@%s) is initialize fail (%d).\n", db->type == FDB_DB_TYPE_KV ? "KVDB" : "TSDB", + db->name, _fdb_db_path(db), (int)result); } } @@ -131,3 +131,21 @@ void _fdb_deinit(fdb_db_t db) db->init_ok = false; } + +const char *_fdb_db_path(fdb_db_t db) +{ + if (db->file_mode) { +#ifdef FDB_USING_FILE_MODE + return db->storage.dir; +#else + return NULL; +#endif + } + else { +#ifdef FDB_USING_FAL_MODE + return db->storage.part->name; +#else + return NULL; +#endif + } +} \ No newline at end of file diff --git a/src/fdb_kvdb.c b/src/fdb_kvdb.c index 88fb162..b2f0f33 100644 --- a/src/fdb_kvdb.c +++ b/src/fdb_kvdb.c @@ -19,7 +19,7 @@ #define FDB_LOG_TAG "[kv]" /* rewrite log prefix */ #undef FDB_LOG_PREFIX2 -#define FDB_LOG_PREFIX2() FDB_PRINT("[%s] ", db_name(db)) +#define FDB_LOG_PREFIX2() FDB_PRINT("[%s][%s] ", db_name(db), _fdb_db_path((fdb_db_t)db)) #if defined(FDB_USING_KVDB) @@ -276,7 +276,8 @@ static uint32_t find_next_kv_addr(fdb_kvdb_t db, uint32_t start, uint32_t end) #endif /* FDB_KV_USING_CACHE */ for (; start < end && start + sizeof(buf) < end; start += (sizeof(buf) - sizeof(uint32_t))) { - _fdb_flash_read((fdb_db_t)db, start, (uint32_t *) buf, sizeof(buf)); + if (_fdb_flash_read((fdb_db_t)db, start, (uint32_t *) buf, sizeof(buf)) != FDB_NO_ERR) + return FAILED_ADDR; for (i = 0; i < sizeof(buf) - sizeof(uint32_t) && start + i < end; i++) { #ifndef FDB_BIG_ENDIAN /* Little Endian Order */ magic = buf[i] + (buf[i + 1] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24); diff --git a/src/fdb_tsdb.c b/src/fdb_tsdb.c index a931fe2..9bd26b1 100644 --- a/src/fdb_tsdb.c +++ b/src/fdb_tsdb.c @@ -21,7 +21,7 @@ #define FDB_LOG_TAG "[tsl]" /* rewrite log prefix */ #undef FDB_LOG_PREFIX2 -#define FDB_LOG_PREFIX2() FDB_PRINT("[%s] ", db_name(db)) +#define FDB_LOG_PREFIX2() FDB_PRINT("[%s][%s] ", db_name(db), _fdb_db_path((fdb_db_t)db)) #if defined(FDB_USING_TSDB)