Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File system lost files if application restart on a specific point #11

Open
Pablo-Jean opened this issue Aug 7, 2023 · 1 comment
Open

Comments

@Pablo-Jean
Copy link

Description

I'm developing a Digital Lock, and our team is using the JesFs, but, we experiencing some issues that can be a big problem on our products.

Yes, we developing our Digital lock to not restart or crash suddenly, but, it can happen. And, if this event occurs on a file opening operation, between an Erase Sector, the File System lost all the files, more specifically on this code section:

    } else {
/* == After this command == */
        res = sflash_SectorErase(sfun_adr);
        if (res)
            return res;
    }

    fs_memset((uint8_t *)&sflash_info.databuf, 0xFF, HEADER_SIZE_B + FINFO_SIZE_B);
    sflash_info.databuf.u32[0] = SECTOR_MAGIC_HEAD_ACTIVE;
    fs_strcpy((char *)&sflash_info.databuf.u8[HEADER_SIZE_B + 12], pname);
    pdesc->file_ctime = fs_get_secs();
    sflash_info.databuf.u32[HEADER_SIZE_L + 2] = pdesc->file_ctime;
    sflash_info.databuf.u8[HEADER_SIZE_B + 34] = flags;
/* == Before this command == */
    res = sflash_SectorWrite(sfun_adr, (uint8_t *)&sflash_info.databuf, HEADER_SIZE_B + FINFO_SIZE_B);

So, do you guys have a solution to prevent this? Maybe, keeping a file open can be a solution, but, I think, isn't the most efficient, right?

And, I'm making tests to find out another code point that can cause some similar issues.

Thanks.

@joembedded
Copy link
Owner

Hi Pablo, Yes, if power fails during write and the CPU works with lower voltages than the memory, the memory may fail and only reformat is possible. I added a voltage check im the latest release to ensure a minimum time (e.g. a 100uF cap drops 1V if 10mA is drawn for 10msec, and the memory works down to 1.6V, hence a top limit of 2.6V should ensure safe operation)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants