Commit Graph

12 Commits

Author SHA1 Message Date
Sosthène Guédon 9fde6f06fc Run cargo fmt 2023-06-12 10:47:18 +02:00
Robin Krahl aafa02e332 Fix lookahead buffer size reported to littlefs2-sys
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/19
	https://github.com/Nitrokey/littlefs2/pull/1

Fixes: https://github.com/trussed-dev/littlefs2/issues/16
2023-02-07 10:01:42 +01:00
Nicolas Stalder 7b6685771f Add negative test 2023-02-01 01:55:29 +01:00
Nicolas Stalder 2c0dcdc29f Set Path to CStr and add PathBuf
- Same as iqlusion's rewrite, simplify and adjust
to std::fs
2021-01-31 13:39:04 +01:00
Nicolas Stalder cfcbe2bfaa REPLACE old API with new API
- The old API caused UB and was not very ergonomic
- Tests are also updated: `cargo test --release`
2021-01-31 13:39:04 +01:00
Nicolas Stalder 24a245bcac More *With stuff 2019-12-16 22:32:07 +01:00
Nicolas Stalder b5309cea79 Streamline API. Available blocks. More documentation 2019-12-15 12:05:12 +01:00
Nicolas Stalder 7f2d6108c3 MountState is no longer needed. Same for MountError, MountResult 2019-12-14 23:03:23 +01:00
Nicolas Stalder f1883f4e93 BLOCK_SIZE can be a normal usize 2019-12-14 22:42:21 +01:00
Nicolas Stalder fa2cb4fee3 Rename traits.rs -> driver.rs, document Storage more 2019-12-13 22:48:43 +01:00
Nicolas Stalder cd6467822d Demonstrate that RamStorage can be deconstructed. Weird gotcha
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.
2019-12-13 22:00:12 +01:00
Nicolas Stalder 7e99a992af Add some UI tests 2019-12-13 13:53:59 +01:00