Skip to content

fs/littlefs: add block_size_factor mount option#19126

Open
alexcekay wants to merge 1 commit into
apache:masterfrom
alexcekay:fs_littlefs_block_size_factor_option
Open

fs/littlefs: add block_size_factor mount option#19126
alexcekay wants to merge 1 commit into
apache:masterfrom
alexcekay:fs_littlefs_block_size_factor_option

Conversation

@alexcekay

Copy link
Copy Markdown
Contributor

Summary

When a board switches storage technology but wants to mount a littlefs filesystem onto this storage it is desired to still use the same firmware.

This almost works out of the box in NuttX with the exception of setting the correct block size, which may be different depending on the used storage. An incorrect block size may lead to suboptimal performance or worse.

To avoid writing a firmware variant that only differs by CONFIG_FS_LITTLEFS_BLOCK_SIZE_FACTOR this adds the option to pass the intended block size at the mount call. To still enable the usage of the existing options this adds a parser for comma-separated mount options, allowing multiple options to be passed simultaneously.

Example: "autoformat,block_size_factor=4",
"autoformat,block_size_factor=1"

This is backwards compatible: single options passed without commas continue to work as before.

Impact

This does not have an impact on existing users. The mount options they currently pass still work as before.

Testing

Tested on a v6s flight-controller (STM32H743VIH6) using the following test mount options:

autoformat
forceformat
block_size_factor=1
block_size_factor=4
autoformat,block_size_factor=1
autoformat,block_size_factor=4

Those were passed at the mount call:

if (nx_mount(lfs_dev, "/fs/microsd", "littlefs", 0, <mount_options>) != 0)

Afterwards a breakpoint was set after the parser code and the values of the variables autoformat, forceformat and block_size_factor were checked for correctness. After that it was ensured that the filesystem mounts correctly.

The obvious edge-case is:

block_size_factor=0

This causes a div by zero in the calculation of fs->cfg.block_count. This however was already the case before with CONFIG_FS_LITTLEFS_BLOCK_SIZE_FACTOR, so I did not add an additional verification as this will directly be visible on the first mount try.

Another edge-case is:

autoformat,forceformat

This semantically does not make much sense but does not cause any real problems as the two options can co-exist. In this case forceformat is executed first. If for some reason the mounting would still fail even after that format with EFAULT then autoformat would format again.

@github-actions github-actions Bot added Area: File System File System issues Size: S The size of the change in this PR is small labels Jun 12, 2026
When a board switches storage technology but wants to mount a littlefs
filesystem onto this storage it is desired to still use the same firmware.

This almost works out of the box in NuttX with the exception of setting the
correct block size, which may be different depending on the used storage.
An incorrect block size may lead to suboptimal performance or worse.

To avoid writing a firmware variant that only differs by
CONFIG_FS_LITTLEFS_BLOCK_SIZE_FACTOR this adds the option to pass the
intended block size at the mount call. To still enable the usage of the existing
options this adds a parser for comma-separated mount options, allowing multiple
options to be passed simultaneously.

Example: "autoformat,block_size_factor=4",
         "autoformat,block_size_factor=1"

This is backwards compatible: single options passed without commas continue to
work as before.

Signed-off-by: alexcekay <alexander@auterion.com>
@alexcekay alexcekay force-pushed the fs_littlefs_block_size_factor_option branch from 5232dd5 to 9ae5111 Compare June 12, 2026 09:31
Comment thread fs/littlefs/lfs_vfs.c

bool autoformat = false;
bool forceformat = false;
int block_size_factor = CONFIG_FS_LITTLEFS_BLOCK_SIZE_FACTOR;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the variable definition to the begin of function for c89

Comment thread fs/littlefs/lfs_vfs.c
goto errout_with_fs;
}

while ((tok = strsep(&tmp, ",")) != NULL)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use strchrnul to avoid strdup?

@acassis

acassis commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

@simbit18 @raiden00pl seems like we are out of space inside our docker image:

docker: failed to register layer: write /tools/zap/node_modules/app-builder-bin/linux/arm64/app-builder: no space left on device

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants