littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
5.23k stars 801 forks source link

Corrupted dir pair on disk 2.0 after writing to a file on disk 2.1 #999

Closed MikhailSiomin closed 4 months ago

MikhailSiomin commented 5 months ago

Our bootloaders work on Zephyr RTOS 2.7.6 using LittleFS 2.2.0, applications - on Zephyr RTOS 3.7.0-rc1 using LittleFS 2.8.1 (the bug described below also appears with LittleFS 2.9.3). File system is located on the W25Q128JVSIQ chip.

How I reproduce this bug:

  1. the bootloader mounts empty /com fs.
  2. the bootloader creates /com/log/log.0000 file and writes small logs.
  3. the bootloader run the application which also mounts /com fs.
  4. the application writes to existing /com/logs/log.0000 file some logs.
  5. I'm doing a power reset.
  6. the bootloader tries to mount /com fs, but finds corrupted dir pair (non-root), then mounts empty /com fs.

But if step 4 is interrupted after first lfs_file_sync due to a power reset, then the bootloader finds corrupted dir pair when the file size is around 8000 bytes or larger.

I'm currently searching for the cause of this problem and would appreciate any help.

MikhailSiomin commented 4 months ago

@geky, I found that even opening an existing file in Littlefs 2.9.3 causes Littlefs 2.2.0 to use a previous revision's root block.

MikhailSiomin commented 4 months ago

The problem is solved. To do this, it was necessary to define the LFS_MULTIVERSION macro and, specify the supported disk version in the disk_version field of the struct lfs_config for mounting.