Previously, we reported the lookahead buffer size in bytes but
littlefs2-sys expects the lookahead buffer size as a multiple of 8
bytes. This could lead to a buffer overflow causing filesystem
corruption. This patch fixes the reported lookahead buffer size.
Note that Storage::LOOKAHEAD_WORDS_SIZE allows users to set invalid
values (as it is measured in 4 bytes, not in 8 bytes). Invalid values
that were previously accepted because of the wrong buffer size
calculation can now be rejected by littlefs2-sys.
This is a combination of two previous patches:
https://github.com/trussed-dev/littlefs2/pull/19https://github.com/Nitrokey/littlefs2/pull/1
Fixes: https://github.com/trussed-dev/littlefs2/issues/16
In real usage, `Storage` will be implemented by a class wrapping
a device's flash peripheral. We may very well need access to this
peripheral outside of littlefs (e.g., to change startup bytes or
any other flash read/write operation).
One possible approach is to "release" the flash peripheral, drop
the Storage, and later recreate it again with the same peripheral.
`ram_storage!` now generates a `Ram`, which is not dropped and
plays the role of the flash peripheral and its backing flash.
Instead, `RamStorage` now stores a `&mut Ram`. The tests intend to
demonstrate that we can reconstruct `RamStorage` and continue to
work with a possibly even mounted filesystem.
The "weird gotcha" is that `assert_eq!(metadata.len(), n)` panics
on an `unwrap_err`, while `assert!(metadata.len() == n)` works.