SDK 4.0.0-2.alpha
When run garbage collection, sometimes invalid offset on new page is present. Adding next string fix this. m_swap_page.write_offset = FDS_PAGE_TAG_SIZE; // [FIX]
I did correctly?
Full function text:
static ret_code_t gc_swap()
{ uint32_t ret; uint16_t const gc = m_gc.cur_page;
CRITICAL_SECTION_ENTER();
uint16_t const records_open = m_pages[gc].records_open;
CRITICAL_SECTION_EXIT();
if (records_open == 0)
{
/** The page being GC will be the new swap, and the current swap
* will be used as a valid page. */
uint32_t const * const p_addr = m_swap_page.p_addr;
m_swap_page.p_addr = m_pages[gc].p_addr;
m_pages[gc].p_addr = p_addr;
m_pages[gc].write_offset = m_swap_page.write_offset;
// Erase the new swap page.
ret = fs_erase(&fs_config, m_swap_page.p_addr, FDS_PHY_PAGES_IN_VPAGE);
m_swap_page.write_offset = FDS_PAGE_TAG_SIZE; // [FIX]
m_gc.state = GC_TAG_VALID;
}
else
{
/** If there are open records, we can't GC the page anymore.
* Discard the swap and try to GC another page. */
ret = gc_erase_swap();
}
return ret;
}