[BUG] Littlefs only syncing with fsync
, but not fflush
#15840
Labels
Arch: arm
Issues related to ARM (32-bit) architecture
Area: File System
File System issues
OS: Linux
Issues related to Linux (building system, etc)
Type: Bug
Something isn't working
Description / Steps to reproduce the issue
This may not be considered a bug, but the behaviour of
fflush
on files in a littlefs filesystem does not match what I would expect to see.My setup is an RP2040 based MCU connected to an SD card over SPI1. The SD card has two partitions, the first one is a FAT filesystem and the second is a littlefs file system. The littlefs file system is mounted at
/pwrfs
When I run the following code with a littlefs file system and interrupt its execution by removing power to my board, none of logs that were written in the main loop are visible in the log file. The file was created, but that's it:
I have also tried limiting the loop to 10 iterations, then closing the file with
fclose
after the loop and then cutting power. The file still remains empty.After some searching through file system debug logs, I saw the
echo
command makes calls tolfs_file_sync
. This appears only to be accessible throughlittlefs_sync
andlittlefs_open
from my grepping in the source code. I decided to try operating on my log file using file descriptors instead of theFILE
API. The following code performs exactly how I would expect:No matter when I pull the power on my board, logs are preserved in the log file and I can access the contents on the next boot, instead of being greeted by an empty file.
I don't know if there would be any other similar/equivalent
FILE
API function tofsync
besidesfflush
, so I would intuitively expect that this function would sync the file system to "disk" underneath the hood. Maybe that's an incorrect/naive assumption. If so, could anyone tell me an alternative option so I can use theFILE
API but still have my log file be synced? I've let the program run for quite a few iterations and I still observe an empty file. Does the file ever get synced when modified through theFILE
API? And when?On which OS does this issue occur?
[OS: Linux]
What is the version of your OS?
Linux 6.13.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 08 Feb 2025 18:54:55 +0000 x86_64 GNU/Linux
NuttX Version
e538855
Issue Architecture
[Arch: arm]
Issue Area
[Area: File System]
Host information
No response
Verification
The text was updated successfully, but these errors were encountered: