diff --git a/.gitignore b/.gitignore index 4fffb2f..d2599e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -/target +target /Cargo.lock diff --git a/.vscode/settings.json b/.vscode/settings.json index 2b0ee9f..65677c4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "rust-analyzer.linkedProjects": [ "Cargo.toml", "fuzz/Cargo.toml", - "example/Cargo.toml" + "example/Cargo.toml", + "host-tool/Cargo.toml" ] } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 43686a0..e8cda29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - *Breaking:* Added `Value` impls for `bool`, `Option`, and `[T: Value; N]`. *This can break existing code because it changes type inference, be mindfull of that!* +- Expose map item iterator, to load all items in one pass +- Add host tool, allow experiment, inspect dump file in the host environment. ## 3.0.1 25-07-24 diff --git a/host-tool/Cargo.lock b/host-tool/Cargo.lock new file mode 100644 index 0000000..54b3dad --- /dev/null +++ b/host-tool/Cargo.lock @@ -0,0 +1,501 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bytes" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "embedded-storage" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21dea9854beb860f3062d10228ce9b976da520a73474aed3171ec276bc0c032" + +[[package]] +name = "embedded-storage-async" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1763775e2323b7d5f0aa6090657f5e21cfa02ede71f5dc40eead06d64dcd15cc" +dependencies = [ + "embedded-storage", +] + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "sequential-storage" +version = "3.0.1" +dependencies = [ + "approx", + "arrayvec", + "embedded-storage-async", + "futures", +] + +[[package]] +name = "sequential-storage-tool" +version = "0.1.0" +dependencies = [ + "embedded-storage-async", + "sequential-storage", + "tokio", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/host-tool/Cargo.toml b/host-tool/Cargo.toml new file mode 100644 index 0000000..2c6a24c --- /dev/null +++ b/host-tool/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "sequential-storage-tool" +version = "0.1.0" +edition = "2021" + +[dependencies] +embedded-storage-async = "0.4.1" +sequential-storage = { version = "3.0.1", path = "..", features = ["_test"] } +tokio = { version = "1.40.0", features = ["full"]} diff --git a/host-tool/rmk.raw b/host-tool/rmk.raw new file mode 100755 index 0000000..ebb2183 Binary files /dev/null and b/host-tool/rmk.raw differ diff --git a/host-tool/src/main.rs b/host-tool/src/main.rs new file mode 100644 index 0000000..93c6ae8 --- /dev/null +++ b/host-tool/src/main.rs @@ -0,0 +1,96 @@ +use std::{ + fs::File, + io::{Read, Seek, SeekFrom}, + ops::Range, +}; + +use embedded_storage_async::nor_flash::{ + ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, +}; +use sequential_storage::{cache::NoCache, Storage}; + +pub struct Partition(File); + +impl Partition { + pub const WORD_SIZE: usize = 4; + pub const SECTOR_SIZE: usize = 4096; + + pub fn new(path: &str) -> Self { + Self(File::open(path).unwrap()) + } +} + +#[derive(Debug)] +pub struct Error(std::io::Error); +impl From for Error { + fn from(value: std::io::Error) -> Self { + Self(value) + } +} + +impl NorFlashError for Error { + fn kind(&self) -> NorFlashErrorKind { + // match self.0.code() { + // => NorFlashErrorKind::NotAligned, + // ESP_ERR_INVALID_SIZE => NorFlashErrorKind::OutOfBounds, + // _ => + NorFlashErrorKind::Other + // } + } +} + +impl ErrorType for Partition { + type Error = Error; +} + +impl ReadNorFlash for Partition { + const READ_SIZE: usize = Self::WORD_SIZE as _; + + async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { + self.0.seek(SeekFrom::Start(offset as u64))?; + self.0.read_exact(bytes).map_err(Error::from) + } + + fn capacity(&self) -> usize { + self.0.metadata().unwrap().len() as usize + } +} + +impl NorFlash for Partition { + const WRITE_SIZE: usize = Self::WORD_SIZE as _; + const ERASE_SIZE: usize = Self::SECTOR_SIZE as _; + + async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { + println!( + "esp partition write at {:#x} size {:#x}", + offset, + bytes.len() + ); + Ok(()) + } + + async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { + println!("esp partition erase from {:#x} size {:#x}", from, to - from); + Ok(()) + } +} + +impl MultiwriteNorFlash for Partition {} + +#[tokio::main] +async fn main() -> Result<(), sequential_storage::Error> { + let mut flash = Partition::new("rmk.raw"); + let flash_range: Range = 0..flash.capacity() as u32; + let mut cache = NoCache::new(); + let mut storage = Storage::new(&mut flash, flash_range, &mut cache); + + let mut pageit = storage.iter().await?; + while let Some(mut itemit) = pageit.next(&mut storage).await? { + println!("Page {:?}", 1); + let mut buffer = [0u8; 1024]; + while let Ok(Some((item, _))) = itemit.next(&mut storage.flash, &mut buffer).await { + println!("\tItem {:02x?}", item.data()); + } + } + Ok(()) +} diff --git a/src/item.rs b/src/item.rs index 6361fb0..564501f 100644 --- a/src/item.rs +++ b/src/item.rs @@ -506,17 +506,19 @@ pub async fn is_page_empty( } } +/// An iterator-like interface to iterate over items in page pub struct ItemIter { header: ItemHeaderIter, } impl ItemIter { - pub fn new(start_address: u32, end_address: u32) -> Self { + pub(crate) fn new(start_address: u32, end_address: u32) -> Self { Self { header: ItemHeaderIter::new(start_address, end_address), } } + /// iterator next pub async fn next<'m, S: NorFlash>( &mut self, flash: &mut S, @@ -543,7 +545,7 @@ impl ItemIter { pub struct ItemHeaderIter { current_address: u32, - end_address: u32, + pub(crate) end_address: u32, } impl ItemHeaderIter { diff --git a/src/lib.rs b/src/lib.rs index 567c4ab..a541b8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,13 +7,15 @@ // - flash erase size is quite big, aka, this is a paged flash // - flash write size is quite small, so it writes words and not full pages -use cache::PrivateCacheImpl; +use cache::{CacheImpl, PrivateCacheImpl}; use core::{ fmt::Debug, ops::{Deref, DerefMut, Range}, }; use embedded_storage_async::nor_flash::NorFlash; +pub use item::ItemIter; use map::SerializationError; +use queue::find_oldest_page; #[cfg(feature = "arrayvec")] mod arrayvec_impl; @@ -32,6 +34,65 @@ pub mod mock_flash; /// Many flashes have 4-byte or 1-byte words. const MAX_WORD_SIZE: usize = 32; +/// Storage configuration +pub struct Storage<'s, S: NorFlash, CI: CacheImpl> { + /// flash + pub flash: &'s mut S, + /// range + pub flash_range: Range, + /// cache + pub cache: &'s mut CI, +} +impl<'s, S: NorFlash, CI: CacheImpl> Storage<'s, S, CI> { + /// constructor + pub fn new(flash: &'s mut S, flash_range: Range, cache: &'s mut CI) -> Self { + Self { + flash, + flash_range, + cache, + } + } + + /// return iterator for used page + pub async fn iter(&mut self) -> Result> { + let index = find_oldest_page(self.flash, self.flash_range.clone(), self.cache).await?; + + Ok(PageIter { index }) + } +} +/// An iterator-like interface to iterate over Closed and PartialOpen pages +/// This goes from oldest to newest. +pub struct PageIter { + index: usize, +} +impl PageIter { + /// return iterator for items in page + pub async fn next<'s, S: NorFlash, CI: CacheImpl>( + &mut self, + storage: &mut Storage<'s, S, CI>, + ) -> Result, Error> { + let r = match get_page_state( + storage.flash, + storage.flash_range.clone(), + storage.cache, + self.index, + ) + .await + { + Ok(PageState::Closed) | Ok(PageState::PartialOpen) => Some(ItemIter::new( + calculate_page_address::(storage.flash_range.clone(), self.index), + calculate_page_end_address::(storage.flash_range.clone(), self.index), + )), + _ => None, + }; + self.index += 1; + if self.index >= storage.flash_range.len() / S::ERASE_SIZE { + self.index = 0; + } + Ok(r) + } +} + /// Resets the flash in the entire given flash range. /// /// This is just a thin helper function as it just calls the flash's erase function. diff --git a/src/queue.rs b/src/queue.rs index a56d965..a85f536 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -710,7 +710,7 @@ async fn find_youngest_page( }) } -async fn find_oldest_page( +pub(crate) async fn find_oldest_page( flash: &mut S, flash_range: Range, cache: &mut impl PrivateCacheImpl,