pub struct Reader<'a> {
flash: &'a dyn Flash,
buffer: &'a mut [u8],
loaded: Option<u64>,
checked: bool,
blocks: GoodBlocks<'a>,
next_index: u64,
current: Option<u32>,
position: u64,
}Expand description
Reader over the good blocks of an MTD device.
Bad blocks are skipped, so the data of good block n starts at byte
n * block_size. Errors are DeviceErrors wrapped in io::Error.
A block with uncorrectable ECC errors fails the read, unless the reader
was created with Reader::unchecked.
The reader loads one whole block at a time into the buffer of the caller
and serves reads from it. io::BufRead gives access to that buffer.
Fields§
§flash: &'a dyn Flash§buffer: &'a mut [u8]Buffer for the data of one block.
loaded: Option<u64>Index of the good block in buffer.
checked: boolWhether loading a block checks for uncorrectable ECC errors.
blocks: GoodBlocks<'a>Good blocks after current.
next_index: u64Index of the good block that blocks yields next.
current: Option<u32>Physical index of good block next_index - 1.
position: u64Implementations§
§impl<'a> Reader<'a>
impl<'a> Reader<'a>
pub fn new(
flash: &'a dyn Flash,
buffer: &'a mut [u8],
) -> Result<Self, DeviceError>
pub fn new( flash: &'a dyn Flash, buffer: &'a mut [u8], ) -> Result<Self, DeviceError>
Creates a reader over all good blocks of flash.
buffer must be exactly one block long.
§Errors
Returns DeviceError::BufferLength if buffer isn’t one block long.
pub fn unchecked(
flash: &'a dyn Flash,
buffer: &'a mut [u8],
) -> Result<Self, DeviceError>
pub fn unchecked( flash: &'a dyn Flash, buffer: &'a mut [u8], ) -> Result<Self, DeviceError>
Creates a reader that skips the ECC check.
Blocks with uncorrectable ECC errors return their data with the bit
errors. Use this if you verify the data yourself, for example with a
checksum. The ECC check reads the ECC statistics twice per block. On
kernels with CONFIG_MTD_LAZYECCSTATS, each of those reads checks the
bad block marker of every block in the partition.
§Errors
Returns DeviceError::BufferLength if buffer isn’t one block long.
fn with_check( flash: &'a dyn Flash, buffer: &'a mut [u8], checked: bool, ) -> Result<Self, DeviceError>
pub fn size(&self) -> Result<u64, DeviceError>
pub fn size(&self) -> Result<u64, DeviceError>
Returns the number of readable bytes: the size of all good blocks.
§Errors
Returns an error if the bad block markers can’t be read.
fn locate(&mut self, index: u64) -> Result<Option<u32>, DeviceError>
fn locate(&mut self, index: u64) -> Result<Option<u32>, DeviceError>
Returns the physical index of good block index, or None if there
are fewer good blocks.
fn restart(&mut self)
Trait Implementations§
§impl BufRead for Reader<'_>
impl BufRead for Reader<'_>
§fn consume(&mut self, amount: usize)
fn consume(&mut self, amount: usize)
amount of additional bytes from the internal buffer as having been read.
Subsequent calls to read only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte or EOF is reached. Read more§impl Read for Reader<'_>
impl Read for Reader<'_>
§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
fn chain<R>(self, next: R) -> Chain<Self, R> ⓘ
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
fn take(self, limit: u64) -> Take<Self> ⓘwhere
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)§impl Seek for Reader<'_>
impl Seek for Reader<'_>
§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len)