Closed josesimoes closed 6 months ago
Hi @josesimoes, hmm, I have not seen something like this before.
A couple questions to try to understand the context:
Does this code work without using attributes? That would narrow things down.
Is there anything logged by littlefs's LFS_DEBUG/LFS_WARN statements? Especially related to gstate.
Does this occur after a power-loss? It sounds easily reproducible so I'm guessing no?
// set file attributes
// hardcoded to 128 which is value for FileAttributes_Normal
nanoAttributes = 128;
attr = (struct lfs_attr){
.type = NANO_LITTLEFS_ATTRIBUTE,
.size = NANO_LITTLEFS_ATTRIBUTE_SIZE,
.buffer = &nanoAttributes
};
This is a bit confusing. Maybe I am missing something, how exactly is nanoAttributes declared? Is it a uint8_t array of size 128?
Just for completeness, what is the value of NANO_LITTLEFS_ATTRIBUTE and NANO_LITTLEFS_ATTRIBUTE_SIZE? NANO_LITTLEFS_ATTRIBUTE_SIZE should be the same size as the buffer array.
I'm I missing something after the directory creation that can "force" any sync or similar? Or is the call to lfs_stat() somehow disrrupting the file system cache/integrity?
There is a special "force consistency" step that occurs on the first mutation after lfs_mount
. This occurs lazily so read-only mounts of littlefs are guaranteed not to write to disk.
You can trigger this explicitly with lfs_fs_mkconsistent
.
It would be interesting to know if calling lfs_fs_mkconsistent
before lfs_getattr
prevents the behavior you are seeing, though if there is no power-loss (or version upgrade?) I think this would be unlikely.
Just to close this issue, a quick follow-up: this ended being an issue in the driver. It was using the wrong command to erase the block. Great support from @geky! Definitely recommend it. 💯 👍🏻
This is kind of a follow-up on #973.
Take the following code, following a successful call to
lfs_format()
followed bylfs_mount()
.(please ignore the file system var which is coming from the rest of the test code)
All the above calls return successfully with
LFS_ERR_OK
. Now comes the unexpected situation.Following the above, any of these calls fail with
LFS_ERR_CORRUPT
.Restarting the application (which detects the corruption on the 1st call to
lfs_mount()
which requires subsequent calls tolfs_format()
followed bylfs_mount()
and will execute the initial code again withLFS_ERR_OK
.Interestingly, if instead of calling
lfs_stat()
the following code is executed, everything runs smootly.I'm I missing something after the directory creation that can "force" any sync or similar? Or is the call to
lfs_stat()
somehow disrrupting the file system cache/integrity?