From 714d6159e7e6afb267a3953756abca445c350e61 Mon Sep 17 00:00:00 2001 From: Mason-Zhang-X-C Date: Sun, 6 Oct 2024 13:45:40 +0800 Subject: [PATCH] [tsdb][read_sector_info]: fix flash overwrite when abnormal power loss (#316) --- src/fdb_tsdb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fdb_tsdb.c b/src/fdb_tsdb.c index aa4905d..2d66c92 100644 --- a/src/fdb_tsdb.c +++ b/src/fdb_tsdb.c @@ -238,10 +238,12 @@ static fdb_err_t read_sector_info(fdb_tsdb_t db, uint32_t addr, tsdb_sec_info_t tsl.addr.index = sector->empty_idx; while (read_tsl(db, &tsl) == FDB_NO_ERR) { - if (tsl.status == FDB_TSL_UNUSED || tsl.status == FDB_TSL_PRE_WRITE) { + if (tsl.status == FDB_TSL_UNUSED) { break; } - sector->end_time = tsl.time; + if (tsl.status != FDB_TSL_PRE_WRITE) { + sector->end_time = tsl.time; + } sector->end_idx = tsl.addr.index; sector->empty_idx += LOG_IDX_DATA_SIZE; sector->empty_data -= FDB_WG_ALIGN(tsl.log_len);