LITTLEFS
LITTLEFS
A little fail-safe filesystem designed for microcontrollers from https://github.com/littlefs-project/littlefs.
In NuttX, littlefs can be interacted with through the virtual file system. This
means that it can be used normally with read(), write(), etc. calls, as
well as file operations (fopen(), fclose(), etc).
Note
Since littlefs is power-fail safe and must commit writes before they are
permanently stored (corruption prevention mechanism), it is required to
periodically call fsync on the file to commit your writes. The exact
semantics of when littlefs files are committed are discussed in this issue.
Note
If your littlefs setup is experiencing crashes when you boot, try
troubleshooting by tweaking the BLOCK_SIZE_FACTOR options in Kconfig. A
factor of 4 works well for SD cards.
Warning
The littlefs support on NuttX only works with mtd drivers, for storage devices such as flash chips, SD cards and eMMC. Performance on SD cards and eMMC devices is worse than flash.
Version and local patches
NuttX downloads littlefs CONFIG_FS_LITTLEFS_VERSION (default v2.11.2)
at build time. For this default version two NuttX patches are applied, which
add lfs_file_path() (used by CONFIG_FS_LITTLEFS_GETPATH) and
lfs_file_getattr()/lfs_file_setattr() (used by
CONFIG_FS_LITTLEFS_ATTR_UPDATE). With any other version the patches are
skipped and both options are unavailable.
fstat() reports the regular-file type even when
CONFIG_FS_LITTLEFS_ATTR_UPDATE is disabled. Reading the stored permission
bits, ownership, and timestamps through fstat() requires this option.
littlefs v2.11.2 writes on-disk version 2.1, while v2.5.1 and earlier wrote
2.0. littlefs 2.1 mounts 2.0 images and upgrades the superblock on the first
write. To keep writing 2.0 images, for example for older bootloaders, enable
CONFIG_FS_LITTLEFS_MULTI_VERSION and set
CONFIG_FS_LITTLEFS_DISK_VERSION to 0x00020000.
User identity and permissions
When both CONFIG_FS_PERMISSION and CONFIG_FS_LITTLEFS_ATTR_UPDATE are
enabled, littlefs stores owner, group, and mode in per-file custom attributes.
This requires User and Group Identity (CONFIG_SCHED_USER_IDENTITY).
Metadata. chmod/chown (via chstat) update the stored mode,
UID, and GID. stat and ls -l read them back.
Creation. New files and directories are created with the effective UID and GID of the creating task.
Open checks. open() enforces POSIX permission bits using the caller’s
effective identity:
- Existing files: each path component must grant search (
X_OK) permission; the final component must grant the access requested byoflags. O_CREATon a non-existent file: the parent directory must grant write and search permission.
Directory reads. opendir() requires read and search permission on the
target directory.
Files created before permission support was enabled, or without stored
attributes, default to mode 0777 until chmod/chown sets explicit
metadata.
Path components above the littlefs mountpoint are enforced by the VFS; see Filesystem Permission Interface.