Page 1 of 1

littlefs panic when partition is full

Posted: Tue Apr 02, 2024 1:28 am
by owenjames
I am using littlefs to store logs to internal flash and have been testing the behaviour when the littlefs partition is full. I expected a graceful failure of fopen() or fprintf() but I get a DivideByZero exception from lfs_alloc in the bowels of the library from fclose(). It seems that I need to leave 8K of unused space to avoid this. Am I missing some config?

ESP-IDF v5.1.2
litlefs v1.14.2

Re: littlefs panic when partition is full

Posted: Mon Apr 15, 2024 11:27 am
by ESP_adokitkat
Thank you for the report. We will investigate this. However it may be an issue on the LittleFS side. If so we will notify the maintainers.

Re: littlefs panic when partition is full

Posted: Mon Apr 15, 2024 6:53 pm
by bnp117
@owenjames can you post the full log? I believe this is an upstream core littlefs issue (unexpected divide by zero); esp_littlefs should be reporting an appropriate error code. The log can help us raise an appropriate issue in https://github.com/littlefs-project/littlefs

Re: littlefs panic when partition is full

Posted: Tue Apr 16, 2024 1:45 am
by owenjames
Sorry, I don't have the log now but my notes show the exception occurs in lfs.c (when block_count is zero):
  1. static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
  2. ...
  3.         // In order to keep our block allocator from spinning forever when our
  4.         // filesystem is full, we mark points where there are no in-flight
  5.         // allocations with a checkpoint before starting a set of allocations.
  6.         //
  7.         // If we've looked at all blocks since the last checkpoint, we report
  8.         // the filesystem as out of storage.
  9.         //
  10.         if (lfs->lookahead.ckpoint <= 0) {
  11.             LFS_ERROR("No more free space 0x%"PRIx32,
  12.                     (lfs->lookahead.start + lfs->lookahead.next)
  13.                         % lfs->cfg->block_count);
  14.             return LFS_ERR_NOSPC;
  15.         }

Re: littlefs panic when partition is full

Posted: Tue Apr 16, 2024 11:14 pm
by bnp117
In this context,

Code: Select all

block_count
is the number of blocks in the entire filesystem, not free ones remaining. In newer versions of littlefs, the

Code: Select all

lfs_config.block_count
value can be set to 0 to be inferred from an existing filesystem; on mount

Code: Select all

lfs.block_count
is then appropriately populated.

If you can get a fullstack trace, or other info, it would greatly help! Upstream littlefs does have exhaustion tests, and I cannot find a location by inspection where a DivideByZero could occur. Thanks!

Also, I just released esp_littlefs v1.14.3 that updates littlefs v2.9.0 to v2.9.1, incase that fixes anything.

Re: littlefs panic when partition is full

Posted: Wed Apr 17, 2024 3:41 am
by bnp117
Based on huming2207 being able to reproduce it here: https://github.com/joltwallet/esp_littlefs/issues/183

I opened up a PR that may resolve the issue here: https://github.com/littlefs-project/littlefs/pull/966

Will update when it gets merged and and makes its way to esp_littlefs.

Re: littlefs panic when partition is full

Posted: Wed Apr 17, 2024 6:15 pm
by bnp117
fixed in core littlefs v2.9.2, and subsequently in esp_littlefs v1.14.4