From fb3f0af9cc659f20f725dbcddd5da23a6842555d Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 24 Feb 2026 17:37:43 +0100 Subject: [PATCH] Update to littlefs2-sys v0.3.2 and add unstable-littlefs-patched feature --- .github/workflows/ci.yml | 4 +++- CHANGELOG.md | 17 +++++++++++++++++ Cargo.toml | 10 +++++++--- src/fs.rs | 9 ++++++++- src/tests.rs | 12 +++++++++--- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcee2df6..c5117578 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,8 @@ jobs: if: matrix.target == 'x86_64-unknown-linux-gnu' run: > cargo test --workspace && - cargo test --workspace --release + cargo test --workspace --release && + cargo test --workspace --features unstable-littlefs-patched - name: Check documentation if: matrix.target == 'x86_64-unknown-linux-gnu' @@ -79,6 +80,7 @@ jobs: - name: Patch delog run: | + echo '[patch.crates-io]' >> Cargo.toml echo 'delog = { version = "0.1.6", git = "https://github.com/LechevSpace/delog.git", rev = "e83f3fd" }' >> Cargo.toml - name: Build avr diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d95b225..80191974 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed offset calculation overflow in `lfs_config_read` and `lfs_config_prog` if the offset is larger than `u32::MAX`. +### Added + +- Added support for setting configuration options: + - Added `Config` struct. + - `Allocation`: Added `with_config` function. + - `Filesystem`: Added `format_with_config`, `is_mountable_with_config`, `mount_and_then_with_config` functions. +- Added support for growing filesystems with `Filesystem::grow`. +- Added `unstable-littlefs-patched` feature. Enabling this feature may break semantic versioning guarantees. If this feature is enabled, a patched version of littlefs is used (see `littlefs2-sys`) and the following changes are applied: + - Added config flag to disable the block count check on mount: + - Added `MountFlags` enum. + - `Config`: Added `mount_flags` field. + - Added support for shrinking filesystems with `Filesystem::shrink`. + +### Changed + +- Updated to [`littlefs2-sys` v0.3.2](https://github.com/trussed-dev/littlefs2-sys/releases/tag/0.3.2). + ## [v0.6.1](https://github.com/trussed-dev/littlefs2/releases/tag/0.6.1) - 2025-03-04 ### Added diff --git a/Cargo.toml b/Cargo.toml index 3c9490cb..9482626d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ delog = "0.1.0" generic-array = "0.14" heapless = "0.9" littlefs2-core = { version = "0.1", path = "core" } -littlefs2-sys = { version = "0.3.1", features = ["multiversion"] } +littlefs2-sys = { version = "0.3.2", features = ["multiversion"] } [dev-dependencies] ssmarshal = "1" @@ -53,10 +53,14 @@ log-debug = [] log-warn = [] log-error = [] +# unstable features -- enabling one of the following features may break semantic versioning guarantees + +# Use a patched version of littlefs, see littlefs2-sys. +# If this feature is enabled, you should pin littlefs2-sys and littlefs2 to compatible versions. +unstable-littlefs-patched = ["littlefs2-sys/unstable-littlefs-patched"] + # TODO: LFS_NAME_MAX (and maybe other sizes) are baked into the # compiled C library. For instance, the `lfs_info` struct has a # member `char name[LFS_NAME_MAX+1]`. # This means that if we change `traits::Storage::FILENAME_MAX_PLUS_ONE`, # we need to pass this on! -[patch.crates-io] -littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys", rev = "v0.3.1-nitrokey.1" } diff --git a/src/fs.rs b/src/fs.rs index 82ec300e..a71e5952 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -85,11 +85,13 @@ impl Default for Allocation { #[derive(Default, Clone, Debug)] #[non_exhaustive] pub struct Config { + #[cfg(feature = "unstable-littlefs-patched")] pub mount_flags: MountFlags, } +#[cfg(feature = "unstable-littlefs-patched")] bitflags::bitflags! { - #[derive(Default, Clone, Copy,Debug)] + #[derive(Default, Clone, Copy, Debug)] pub struct MountFlags: u32 { const DISABLE_BLOCK_COUNT_CHECK = ll::lfs_fs_flags_LFS_CFG_DISABLE_BLOCK_COUNT_CHECK as _; } @@ -100,6 +102,9 @@ impl Allocation { Self::with_config(Config::default()) } pub fn with_config(config: Config) -> Allocation { + // only used with unstable-littlefs-patched feature + let _ = config; + let read_size: u32 = Storage::READ_SIZE as _; let write_size: u32 = Storage::WRITE_SIZE as _; let block_size: u32 = Storage::BLOCK_SIZE as _; @@ -174,6 +179,7 @@ impl Allocation { metadata_max: 0, inline_max: 0, disk_version: DISK_VERSION.into(), + #[cfg(feature = "unstable-littlefs-patched")] flags: config.mount_flags.bits(), }; @@ -268,6 +274,7 @@ impl Filesystem<'_, Storage> { f(&fs) } + #[cfg(feature = "unstable-littlefs-patched")] pub fn shrink(&self, block_count: usize) -> Result<()> { let mut alloc = self.alloc.borrow_mut(); let return_code = unsafe { ll::lfs_fs_shrink(&mut alloc.state, block_count as _) }; diff --git a/src/tests.rs b/src/tests.rs index 2a0bf9c2..33cc6dbd 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,10 +1,8 @@ use core::convert::TryInto; use generic_array::typenum::consts; -use littlefs2_core::PathBuf; use crate::{ - driver::Storage, - fs::{Allocation, Attribute, File, Filesystem, MountFlags}, + fs::{Allocation, Attribute, File, Filesystem}, io::{Error, OpenSeekFrom, Read, Result, SeekFrom}, path, BACKEND_VERSION, DISK_VERSION, }; @@ -37,6 +35,7 @@ ram_storage!( path_max_plus_one_ty = consts::U256, ); +#[cfg(feature = "unstable-littlefs-patched")] ram_storage!( name = LargerRamStorage, backend = LargerRam, @@ -562,8 +561,11 @@ fn test_mount_or_else_clobber_alloc() { // t.pass("tests/ui/*-pass.rs"); // } +#[cfg(feature = "unstable-littlefs-patched")] #[test] fn shrinking() { + use crate::{driver::Storage, fs::MountFlags}; + let backend = &mut Ram::default(); let storage = &mut RamStorage::new(backend); let alloc = &mut Allocation::new(); @@ -614,8 +616,12 @@ fn shrinking() { ); } +#[cfg(feature = "unstable-littlefs-patched")] #[test] fn shrinking_full() { + use crate::driver::Storage; + use littlefs2_core::PathBuf; + let larger_backend = &mut LargerRam::default(); let larger_storage = &mut LargerRamStorage::new(larger_backend); let larger_alloc = &mut Allocation::new();