This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

fds: pages_init() will not initialize all entries of m_pages[]?

For example, if the first page is erased then it will set this page as swap page and continue looping without increasing the 'page' variable.

  • This means that the last entry of m_pages is left uninitialized.
    • Uninitialized in this case is interpreted as page type FDS_PAGE_DATA, zero bytes used and NULL for page address.
      • write_space_reserve() will use this page.
        • write_execute will send a null pointer to record_header_write_begin which fails with FDS_ERR_BUSY.

I worked around this for the most common case where the erased page is supposed to be a data page and continuing looping for the actual swap page, unless the file system is uninitialized.

The workaround fixes the most common case where the swap page is replaced. This case is quickly encountered by testing with random resets during file system use.

Do you have update code in your repositories that we can try as a proper fix?

/ Ralf

  • I spoke to one of the developers and he said that this should not be an issue since the swap page is held in a separate variable m_swap_page and not in the m_pages array-

  • Which of my four bulleted statements are wrong then?

  • Hi,

    I think the problem is due to a missing initialization of the page in case it is neither a data page, a swap page or an entirely erased page. Because m_pages[] is static, the un-initialized page fields will have default values i.e. zero which is equal to FDS_PAGE_DATA (for page_type) and NULL (for p_page_addr).

    I would try to fix this by adding a 'else' clause after line 672 in fds.c where you set the page type to FDS_PAGE_UNDEFINED. That's basically the situation where the page is neither a data page, a swap page or a fully erased page (the condition tested in the if statement). That way fds will ignore the page in question.

    if (page_is_erased())
    {...}
    else
    {
        m_pages[page++].page_type = FDS_PAGE_UNDEFINED;
    }
    

    The variable page should be incremented in this case. Note that it is correct not to increment the variable page when we first encouter an erased page since m_pages[] does not contain the swap page, which is kept in a separate structure.

    Hope this solves your problem, or at least helps a little :)

    Regards,

    E

    I'm editing the answer to address your comment (can't write long stuff in a comment):

    I see, that's a problem.

    I think that you could keep a local boolean flag that you set to true when a swap 'candidate' is found before the real swap page (if there's any). When you then encouter the real swap page, you can check against that variable to determine wheter or not to initialize a page in m_pages[] to the address of the page which was previously designated as swap.

    I tried to paste some code but I couldn't get the formatting to work -.-

    Regards,

    E

Related