Skip to content

Commit fb3f0af

Browse files
Update to littlefs2-sys v0.3.2 and add unstable-littlefs-patched feature
1 parent f31f4dc commit fb3f0af

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ jobs:
5757
if: matrix.target == 'x86_64-unknown-linux-gnu'
5858
run: >
5959
cargo test --workspace &&
60-
cargo test --workspace --release
60+
cargo test --workspace --release &&
61+
cargo test --workspace --features unstable-littlefs-patched
6162
6263
- name: Check documentation
6364
if: matrix.target == 'x86_64-unknown-linux-gnu'
@@ -79,6 +80,7 @@ jobs:
7980

8081
- name: Patch delog
8182
run: |
83+
echo '[patch.crates-io]' >> Cargo.toml
8284
echo 'delog = { version = "0.1.6", git = "https://github.com/LechevSpace/delog.git", rev = "e83f3fd" }' >> Cargo.toml
8385
8486
- name: Build avr

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Fixed offset calculation overflow in `lfs_config_read` and `lfs_config_prog` if the offset is larger than `u32::MAX`.
1313

14+
### Added
15+
16+
- Added support for setting configuration options:
17+
- Added `Config` struct.
18+
- `Allocation`: Added `with_config` function.
19+
- `Filesystem`: Added `format_with_config`, `is_mountable_with_config`, `mount_and_then_with_config` functions.
20+
- Added support for growing filesystems with `Filesystem::grow`.
21+
- 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:
22+
- Added config flag to disable the block count check on mount:
23+
- Added `MountFlags` enum.
24+
- `Config`: Added `mount_flags` field.
25+
- Added support for shrinking filesystems with `Filesystem::shrink`.
26+
27+
### Changed
28+
29+
- Updated to [`littlefs2-sys` v0.3.2](https://github.com/trussed-dev/littlefs2-sys/releases/tag/0.3.2).
30+
1431
## [v0.6.1](https://github.com/trussed-dev/littlefs2/releases/tag/0.6.1) - 2025-03-04
1532

1633
### Added

Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ delog = "0.1.0"
2828
generic-array = "0.14"
2929
heapless = "0.9"
3030
littlefs2-core = { version = "0.1", path = "core" }
31-
littlefs2-sys = { version = "0.3.1", features = ["multiversion"] }
31+
littlefs2-sys = { version = "0.3.2", features = ["multiversion"] }
3232

3333
[dev-dependencies]
3434
ssmarshal = "1"
@@ -53,10 +53,14 @@ log-debug = []
5353
log-warn = []
5454
log-error = []
5555

56+
# unstable features -- enabling one of the following features may break semantic versioning guarantees
57+
58+
# Use a patched version of littlefs, see littlefs2-sys.
59+
# If this feature is enabled, you should pin littlefs2-sys and littlefs2 to compatible versions.
60+
unstable-littlefs-patched = ["littlefs2-sys/unstable-littlefs-patched"]
61+
5662
# TODO: LFS_NAME_MAX (and maybe other sizes) are baked into the
5763
# compiled C library. For instance, the `lfs_info` struct has a
5864
# member `char name[LFS_NAME_MAX+1]`.
5965
# This means that if we change `traits::Storage::FILENAME_MAX_PLUS_ONE`,
6066
# we need to pass this on!
61-
[patch.crates-io]
62-
littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys", rev = "v0.3.1-nitrokey.1" }

src/fs.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ impl<Storage: driver::Storage> Default for Allocation<Storage> {
8585
#[derive(Default, Clone, Debug)]
8686
#[non_exhaustive]
8787
pub struct Config {
88+
#[cfg(feature = "unstable-littlefs-patched")]
8889
pub mount_flags: MountFlags,
8990
}
9091

92+
#[cfg(feature = "unstable-littlefs-patched")]
9193
bitflags::bitflags! {
92-
#[derive(Default, Clone, Copy,Debug)]
94+
#[derive(Default, Clone, Copy, Debug)]
9395
pub struct MountFlags: u32 {
9496
const DISABLE_BLOCK_COUNT_CHECK = ll::lfs_fs_flags_LFS_CFG_DISABLE_BLOCK_COUNT_CHECK as _;
9597
}
@@ -100,6 +102,9 @@ impl<Storage: driver::Storage> Allocation<Storage> {
100102
Self::with_config(Config::default())
101103
}
102104
pub fn with_config(config: Config) -> Allocation<Storage> {
105+
// only used with unstable-littlefs-patched feature
106+
let _ = config;
107+
103108
let read_size: u32 = Storage::READ_SIZE as _;
104109
let write_size: u32 = Storage::WRITE_SIZE as _;
105110
let block_size: u32 = Storage::BLOCK_SIZE as _;
@@ -174,6 +179,7 @@ impl<Storage: driver::Storage> Allocation<Storage> {
174179
metadata_max: 0,
175180
inline_max: 0,
176181
disk_version: DISK_VERSION.into(),
182+
#[cfg(feature = "unstable-littlefs-patched")]
177183
flags: config.mount_flags.bits(),
178184
};
179185

@@ -268,6 +274,7 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
268274
f(&fs)
269275
}
270276

277+
#[cfg(feature = "unstable-littlefs-patched")]
271278
pub fn shrink(&self, block_count: usize) -> Result<()> {
272279
let mut alloc = self.alloc.borrow_mut();
273280
let return_code = unsafe { ll::lfs_fs_shrink(&mut alloc.state, block_count as _) };

src/tests.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
use core::convert::TryInto;
22
use generic_array::typenum::consts;
3-
use littlefs2_core::PathBuf;
43

54
use crate::{
6-
driver::Storage,
7-
fs::{Allocation, Attribute, File, Filesystem, MountFlags},
5+
fs::{Allocation, Attribute, File, Filesystem},
86
io::{Error, OpenSeekFrom, Read, Result, SeekFrom},
97
path, BACKEND_VERSION, DISK_VERSION,
108
};
@@ -37,6 +35,7 @@ ram_storage!(
3735
path_max_plus_one_ty = consts::U256,
3836
);
3937

38+
#[cfg(feature = "unstable-littlefs-patched")]
4039
ram_storage!(
4140
name = LargerRamStorage,
4241
backend = LargerRam,
@@ -562,8 +561,11 @@ fn test_mount_or_else_clobber_alloc() {
562561
// t.pass("tests/ui/*-pass.rs");
563562
// }
564563

564+
#[cfg(feature = "unstable-littlefs-patched")]
565565
#[test]
566566
fn shrinking() {
567+
use crate::{driver::Storage, fs::MountFlags};
568+
567569
let backend = &mut Ram::default();
568570
let storage = &mut RamStorage::new(backend);
569571
let alloc = &mut Allocation::new();
@@ -614,8 +616,12 @@ fn shrinking() {
614616
);
615617
}
616618

619+
#[cfg(feature = "unstable-littlefs-patched")]
617620
#[test]
618621
fn shrinking_full() {
622+
use crate::driver::Storage;
623+
use littlefs2_core::PathBuf;
624+
619625
let larger_backend = &mut LargerRam::default();
620626
let larger_storage = &mut LargerRamStorage::new(larger_backend);
621627
let larger_alloc = &mut Allocation::new();

0 commit comments

Comments
 (0)