Skip to content

Commit 9107213

Browse files
committed
[tsdb] Improve exception handling.
1 parent 83f1669 commit 9107213

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/fdb_tsdb.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static fdb_err_t read_tsl(fdb_tsdb_t db, fdb_tsl_t tsl)
112112
/* read TSL index raw data */
113113
_fdb_flash_read((fdb_db_t)db, tsl->addr.index, (uint32_t *) &idx, sizeof(struct log_idx_data));
114114
tsl->status = (fdb_tsl_status_t) _fdb_get_status(idx.status_table, FDB_TSL_STATUS_NUM);
115-
if (tsl->status == FDB_TSL_PRE_WRITE) {
115+
if ((tsl->status == FDB_TSL_PRE_WRITE) || (tsl->status == FDB_TSL_UNUSED)) {
116116
tsl->log_len = db->max_len;
117117
tsl->addr.log = FDB_DATA_UNUSED;
118118
tsl->time = 0;
@@ -510,13 +510,15 @@ void fdb_tsl_iter_by_time(fdb_tsdb_t db, fdb_time_t from, fdb_time_t to, fdb_tsl
510510
/* search all TSL */
511511
do {
512512
read_tsl(db, &tsl);
513-
if (tsl.time >= from && tsl.time <= to) {
514-
/* iterator is interrupted when callback return true */
515-
if (cb(&tsl, cb_arg)) {
513+
if (tsl.status != FDB_TSL_UNUSED) {
514+
if (tsl.time >= from && tsl.time <= to) {
515+
/* iterator is interrupted when callback return true */
516+
if (cb(&tsl, cb_arg)) {
517+
return;
518+
}
519+
} else {
516520
return;
517521
}
518-
} else {
519-
return;
520522
}
521523
} while ((tsl.addr.index = get_next_tsl_addr(&sector, &tsl)) != FAILED_ADDR);
522524
}

src/fdb_utils.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ size_t fdb_blob_read(fdb_db_t db, fdb_blob_t blob)
230230
if (read_len > blob->saved.len) {
231231
read_len = blob->saved.len;
232232
}
233-
_fdb_flash_read(db, blob->saved.addr, blob->buf, read_len);
233+
if (_fdb_flash_read(db, blob->saved.addr, blob->buf, read_len) != FDB_NO_ERR) {
234+
read_len = 0;
235+
}
234236

235237
return read_len;
236238
}
@@ -253,7 +255,9 @@ fdb_err_t _fdb_flash_read(fdb_db_t db, uint32_t addr, void *buf, size_t size)
253255
#endif
254256
} else {
255257
#ifdef FDB_USING_FAL_MODE
256-
fal_partition_read(db->storage.part, addr, (uint8_t *) buf, size);
258+
if (fal_partition_read(db->storage.part, addr, (uint8_t *) buf, size) < 0) {
259+
result = FDB_READ_ERR;
260+
}
257261
#endif
258262
}
259263

0 commit comments

Comments
 (0)