From a7a29bb658aa98758a560884d88aaec3149a2e05 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Mon, 28 Mar 2022 12:27:02 +0200 Subject: [PATCH] driver::storage::Base: Add an isSliceUninitialized() function First, we add an `uinitialized_byte` prop to `BaseProps`, so implementations that don't use `0xff` as default can set it to whatever they use. Do keep in mind that plenty of code still assumes `0xff` is the uninitialized byte, but this way we have a starting point. Then, we add an `isSliceUninitialized()` function, which checks whether a given slice is completely made up from uninitialized bytes or not. Fixes #1145. Signed-off-by: Gergely Nagy --- src/kaleidoscope/driver/storage/Base.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/kaleidoscope/driver/storage/Base.h b/src/kaleidoscope/driver/storage/Base.h index a2dae8d0..00cc481a 100644 --- a/src/kaleidoscope/driver/storage/Base.h +++ b/src/kaleidoscope/driver/storage/Base.h @@ -25,6 +25,7 @@ namespace storage { struct BaseProps { static constexpr uint16_t length = 0; + static constexpr uint8_t uninitialized_byte = 0xff; }; template @@ -48,6 +49,14 @@ class Base { void update(int idx, uint8_t val) {} + bool isSliceUninitialized(uint16_t offset, uint16_t size) { + for (uint16_t o = offset; o < offset + size; o++) { + if (read(o) != _StorageProps::uninitialized_byte) + return false; + } + return true; + } + const uint16_t length() { return _StorageProps::length; }