Trait littlefs2::driver::Storage[][src]

pub trait Storage {
    type CACHE_SIZE: ArrayLength<u8>;
    type LOOKAHEADWORDS_SIZE: ArrayLength<u32>;

    const READ_SIZE: usize;
    const WRITE_SIZE: usize;
    const BLOCK_SIZE: usize;
    const BLOCK_COUNT: usize;
    const BLOCK_CYCLES: isize;

    fn read(&self, off: usize, buf: &mut [u8]) -> Result<usize>;
fn write(&mut self, off: usize, data: &[u8]) -> Result<usize>;
fn erase(&mut self, off: usize, len: usize) -> Result<usize>; }
Expand description

Users of this library provide a “storage driver” by implementing this trait.

The write method is assumed to be synchronized to storage immediately. littlefs provides more flexibility - if required, this could also be exposed. Do note that due to caches, files still must be synched. And unfortunately, this can’t be automatically done in drop, since it needs mut refs to both filesystem and storage.

The *_SIZE types must be generic_array::typenume::consts such as U256.

Why? Currently, associated constants can not be used (as constants…) to define arrays. This “will be fixed” as part of const generics. Once that’s done, we can get rid of generic-arrays, and replace the *_SIZE types with usizes.

Associated Types

littlefs uses a read cache, a write cache, and one cache per per file. Must be a multiple of READ_SIZE and WRITE_SIZE. Must be a factor of BLOCK_SIZE.

littlefs itself has a LOOKAHEAD_SIZE, which must be a multiple of 8, as it stores data in a bitmap. It also asks for 4-byte aligned buffers. Hence, we further restrict LOOKAHEAD_SIZE to be a multiple of 32. Our LOOKAHEADWORDS_SIZE is this multiple.

Associated Constants

Minimum size of block read in bytes. Not in superblock

Minimum size of block write in bytes. Not in superblock

Size of an erasable block in bytes, as unsigned typenum. Must be a multiple of both READ_SIZE and WRITE_SIZE. At least 128 (https://git.io/JeHp9). Stored in superblock.

Number of erasable blocks. Hence storage capacity is BLOCK_COUNT * BLOCK_SIZE

Suggested values are 100-1000, higher is more performant but less wear-leveled. Default of -1 disables wear-leveling. Value zero is invalid, must be positive or -1.

Required methods

Read data from the storage device. Guaranteed to be called only with bufs of length a multiple of READ_SIZE.

Write data to the storage device. Guaranteed to be called only with bufs of length a multiple of WRITE_SIZE.

Erase data from the storage device. Guaranteed to be called only with bufs of length a multiple of BLOCK_SIZE.

Implementors