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 <algernon@keyboard.io>
pull/1146/head
Gergely Nagy 3 years ago
parent 7a9588e404
commit a7a29bb658
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -25,6 +25,7 @@ namespace storage {
struct BaseProps { struct BaseProps {
static constexpr uint16_t length = 0; static constexpr uint16_t length = 0;
static constexpr uint8_t uninitialized_byte = 0xff;
}; };
template <typename _StorageProps> template <typename _StorageProps>
@ -48,6 +49,14 @@ class Base {
void update(int idx, uint8_t val) {} 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() { const uint16_t length() {
return _StorageProps::length; return _StorageProps::length;
} }

Loading…
Cancel
Save