From 04001770116ea64607db8bbca192ec0c5e1c6085 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Tue, 30 Apr 2024 14:06:10 +0200 Subject: [PATCH] fix number of chunks constant --- src/file.rs | 5 ++++- src/page.rs | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/file.rs b/src/file.rs index 948f201..f3d9d1e 100644 --- a/src/file.rs +++ b/src/file.rs @@ -10,8 +10,11 @@ pub use crate::page::ReadError; use crate::page::{ChunkHeader, DehydratedPageReader, Header, PageHeader, PageReader, PageWriter}; use crate::types::{OptionPageID, PageID}; + +pub(crate) const CHUNKS_PER_PAGE: usize = (PAGE_SIZE - PageHeader::SIZE - size_of::()).div_ceil(MAX_CHUNK_SIZE + ChunkHeader::SIZE); pub const PAGE_MAX_PAYLOAD_SIZE: usize = - PAGE_SIZE - PageHeader::SIZE - size_of::() - (page::CHUNKS_PER_PAGE * ChunkHeader::SIZE); + PAGE_SIZE - PageHeader::SIZE - (CHUNKS_PER_PAGE * ChunkHeader::SIZE) - size_of::(); + pub type FileID = u8; diff --git a/src/page.rs b/src/page.rs index 5066dcd..89a8df5 100644 --- a/src/page.rs +++ b/src/page.rs @@ -59,7 +59,6 @@ pub(crate) const MAX_CHUNK_SIZE: usize = if config::MAX_CHUNK_SIZE > (PAGE_SIZE } else { config::MAX_CHUNK_SIZE }; -pub(crate) const CHUNKS_PER_PAGE: usize = (PAGE_SIZE - PageHeader::SIZE) / (MAX_CHUNK_SIZE + ChunkHeader::SIZE); async fn write_header(flash: &mut F, page_id: PageID, header: H) -> Result<(), F::Error> { assert!(size_of::() <= MAX_HEADER_SIZE); @@ -649,7 +648,7 @@ mod tests { const HEADER: TestHeader = TestHeader { foo: 123456 }; const MAX_PAYLOAD: usize = - PAGE_SIZE - PageHeader::SIZE - size_of::() - (ChunkHeader::SIZE * CHUNKS_PER_PAGE); + PAGE_SIZE - PageHeader::SIZE - size_of::() - ChunkHeader::SIZE; #[test_log::test] fn test_crc32() {