sectorize

Crates.iosectorize
lib.rssectorize
version0.1.0
sourcesrc
created_at2024-06-30 15:43:32.621308
updated_at2024-06-30 15:43:32.621308
descriptionA small library for writing arbitrarily-aligned data to sectored mediums
homepage
repositoryhttps://gitlab.scd31.com/stephen/sectorize
max_upload_size
id1288058
size6,720
Stephen D (scd31)

documentation

README

sectorize

A basic library for writing data at an arbitrary address/length to a sectorized medium, like flash memory.

Usage

Here's how I'm using it. This is a snippet from a project I'm working on (and the motivation for writing this crate).

fn write_data(&mut self, start_addr: usize, buf: &[u8]) {
    for s in SectorizeIter::new(SECTOR_SIZE, start_addr, buf.len()) {
        let mut existing = self.read_slice(s.sector_index * SECTOR_SIZE);

        // only write if there's a difference
        if existing[s.sector_start..s.sector_end] != buf[s.input_start..s.input_end] {
            existing[s.sector_start..s.sector_end]
                .copy_from_slice(&buf[s.input_start..s.input_end]);
            self.write_sector(s.sector_index * SECTOR_SIZE, &existing);
        }
    }
}
Commit count: 0

cargo fmt