From a4b9bfa50ba14f54d0ea364ffef7367ab42e75ea Mon Sep 17 00:00:00 2001 From: TaeJun Kwon Date: Thu, 11 May 2017 19:53:26 +0900 Subject: [PATCH] Fix journaling issue If buffer size is bigger than remained area + next area, calculating failed --- os/fs/smartfs/smartfs_utils.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/os/fs/smartfs/smartfs_utils.c b/os/fs/smartfs/smartfs_utils.c index 371605f..0ffe000 100644 --- a/os/fs/smartfs/smartfs_utils.c +++ b/os/fs/smartfs/smartfs_utils.c @@ -2924,19 +2924,22 @@ static int get_next_sector_info(struct journal_transaction_manager_s *j_mgr) ret = NO_CHANGE; newsector = j_mgr->sector; + newoffset = j_mgr->offset; entry = (struct smartfs_logging_entry_s *)(j_mgr->buffer); startsector = SMARTFS_LOGGING_SECTOR + j_mgr->jarea * CONFIG_SMARTFS_NLOGGING_SECTORS; if ((j_mgr->offset + sizeof(struct smartfs_logging_entry_s)) > j_mgr->availbytes) { + newsector++; + newoffset = 0; ret = NEXT_SECTOR; } - if (j_mgr->sector >= startsector + CONFIG_SMARTFS_NLOGGING_SECTORS) { + if (newsector >= startsector + CONFIG_SMARTFS_NLOGGING_SECTORS) { return MOVE_AREA; } - newoffset = j_mgr->offset + sizeof(struct smartfs_logging_entry_s) - + (GET_TRANS_TYPE(entry->trans_info) != T_DELETE ? entry->datalen : 0); + + newoffset += sizeof(struct smartfs_logging_entry_s) + (GET_TRANS_TYPE(entry->trans_info) != T_DELETE ? entry->datalen : 0); + if (newoffset > j_mgr->availbytes) { newsector++; - newoffset -= j_mgr->availbytes; } if (newsector >= startsector + CONFIG_SMARTFS_NLOGGING_SECTORS) { ret = MOVE_AREA; -- 2.7.4