alexcekay opened a new pull request, #19126:
URL: https://github.com/apache/nuttx/pull/19126

   ## 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to