diff --git a/CHANGELOG.md b/CHANGELOG.md index d5b6805e..6f4fe037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased -- +### Changed + +- Updated to [`littlefs2-sys` v0.3.1](https://github.com/trussed-dev/littlefs2-sys/releases/tag/0.3.1) and [`littlefs` v2.9.3](https://github.com/littlefs-project/littlefs/releases/tag/v2.9.3). + - `littlefs2` v2.6 introduced a new on-disk format (lfs2.1). + We use the multiversion feature to keep the old on-disk format (lfs2.0) to not break compatibility with older versions of this crate. +- Replaced the `version` function with the `BACKEND_VERSION` and `DISK_VERSION` constants. + - Changed the `Version` struct to be a wrapper for a littlefs version number. ## [v0.5.0](https://github.com/trussed-dev/littlefs2/releases/tag/0.5.0) - 2024-10-25 diff --git a/Cargo.toml b/Cargo.toml index fcbd1742..888dee9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ delog = "0.1.0" generic-array = "0.14" heapless = "0.7" littlefs2-core = { version = "0.1", path = "core" } -littlefs2-sys = "0.2" +littlefs2-sys = { version = "0.3.1", features = ["multiversion"] } [dev-dependencies] ssmarshal = "1" diff --git a/README.md b/README.md index c32b4d72..bda7dfa4 100644 --- a/README.md +++ b/README.md @@ -37,14 +37,14 @@ The low-level bindings are provided by the [littlefs2-sys][littlefs2-sys] librar The core types that are independent of a specific implementation version are provided by the `littlefs2-core` crate, see the [`core`](./core) directory. These types are re-exported from the `littlefs2` crate too. -Upstream release: [v2.2.1][upstream-release] +Upstream release: [v2.9.3][upstream-release] [geky]: https://github.com/geky [littlefs]: https://github.com/littlefs-project/littlefs [release-notes-2]: https://github.com/littlefs-project/littlefs/releases/tag/v2.0.0 [std-fs]: https://doc.rust-lang.org/std/fs/index.html [littlefs2-sys]: https://lib.rs/littlefs2-sys -[upstream-release]: https://github.com/littlefs-project/littlefs/releases/tag/v2.2.1 +[upstream-release]: https://github.com/littlefs-project/littlefs/releases/tag/v2.9.3 ## `no_std` diff --git a/src/fs.rs b/src/fs.rs index 2de75265..50f06c9b 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -19,6 +19,7 @@ use crate::{ driver, io::{self, Error, OpenSeekFrom, Result}, path::{Path, PathBuf}, + DISK_VERSION, }; fn error_code_from(result: Result) -> ll::lfs_error { @@ -158,6 +159,10 @@ impl Allocation { name_max: filename_max_plus_one.wrapping_sub(1), file_max, attr_max, + compact_thresh: 0, + metadata_max: 0, + inline_max: 0, + disk_version: DISK_VERSION.into(), }; Self { @@ -1224,6 +1229,28 @@ mod tests { use io::Result as LfsResult; const_ram_storage!(TestStorage, 4096); + #[test] + fn disk_version() { + let mut test_storage = TestStorage::new(); + Filesystem::format(&mut test_storage).unwrap(); + Filesystem::mount_and_then(&mut test_storage, |fs| { + let mut fs_info = ll::lfs_fsinfo { + disk_version: 0, + block_size: 0, + block_count: 0, + name_max: 0, + file_max: 0, + attr_max: 0, + }; + let return_code = + unsafe { ll::lfs_fs_stat(&mut fs.alloc.borrow_mut().state, &mut fs_info) }; + result_from((), return_code).unwrap(); + assert_eq!(fs_info.disk_version, DISK_VERSION.into()); + Ok(()) + }) + .unwrap(); + } + #[test] fn todo() { let mut test_storage = TestStorage::new(); diff --git a/src/lib.rs b/src/lib.rs index dc74da1a..02a5c082 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -164,21 +164,44 @@ pub mod driver; pub mod fs; pub mod object_safe; -/// get information about the C backend -pub fn version() -> Version { - Version { - format: (ll::LFS_DISK_VERSION_MAJOR, ll::LFS_DISK_VERSION_MINOR), - backend: (ll::LFS_VERSION_MAJOR, ll::LFS_VERSION_MINOR), +/// The version of the C backend. +pub const BACKEND_VERSION: Version = Version(ll::LFS_VERSION); + +/// The on-disk version used by [`Filesystem`][`fs::Filesystem`]. +/// +/// Note that this is not the same as the littlefs [`LFS_DISK_VERSION`][`ll::LFS_DISK_VERSION`] +/// constant as this crate uses the multiversion feature to select on-disk version 2.0 instead of +/// using the latest on-disk version (currently 2.1). +pub const DISK_VERSION: Version = Version(0x0002_0000); + +/// A littlefs version number. +#[derive(Clone, Copy, Debug)] +pub struct Version(u32); + +impl Version { + /// The major version component (top-nibble). + pub const fn major(&self) -> u16 { + let [high, low, _, _] = self.0.to_be_bytes(); + u16::from_be_bytes([high, low]) + } + + /// The minor version component (bottom-nibble). + pub const fn minor(&self) -> u16 { + let [_, _, high, low] = self.0.to_be_bytes(); + u16::from_be_bytes([high, low]) } } -/// Information about the C backend -#[derive(Clone, Copy, Debug)] -pub struct Version { - /// On-disk format (currently: 2.0) - pub format: (u32, u32), - /// Backend release (currently: 2.1) - pub backend: (u32, u32), +impl From for Version { + fn from(version: u32) -> Self { + Self(version) + } +} + +impl From for u32 { + fn from(version: Version) -> u32 { + version.0 + } } #[cfg(test)] diff --git a/src/tests.rs b/src/tests.rs index cee385e5..f4e1cb81 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -5,7 +5,7 @@ use crate::{ driver, fs::{Attribute, File, Filesystem}, io::{Error, OpenSeekFrom, Read, Result, SeekFrom}, - path, + path, BACKEND_VERSION, DISK_VERSION, }; ram_storage!( @@ -42,8 +42,8 @@ ram_storage!( #[test] fn version() { - assert_eq!(crate::version().format, (2, 0)); - assert_eq!(crate::version().backend, (2, 2)); + assert_eq!((BACKEND_VERSION.major(), BACKEND_VERSION.minor()), (2, 9)); + assert_eq!((DISK_VERSION.major(), DISK_VERSION.minor()), (2, 0)); } #[test]