Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
27 changes: 27 additions & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
driver,
io::{self, Error, OpenSeekFrom, Result},
path::{Path, PathBuf},
DISK_VERSION,
};

fn error_code_from<T>(result: Result<T>) -> ll::lfs_error {
Expand Down Expand Up @@ -158,6 +159,10 @@ impl<Storage: driver::Storage> Allocation<Storage> {
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 {
Expand Down Expand Up @@ -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();
Expand Down
47 changes: 35 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> for Version {
fn from(version: u32) -> Self {
Self(version)
}
}

impl From<Version> for u32 {
fn from(version: Version) -> u32 {
version.0
}
}

#[cfg(test)]
Expand Down
6 changes: 3 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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]
Expand Down