JesFs icon indicating copy to clipboard operation
JesFs copied to clipboard

File system lost files if application restart on a specific point

Open Pablo-Jean opened this issue 1 year ago • 1 comments

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.

Pablo-Jean avatar Aug 07 '23 12:08 Pablo-Jean

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)

joembedded avatar Sep 21 '23 09:09 joembedded