std1.0.0-beta-7 SafeC docs

std :: fs::block

Struct std::BlockDevice

#include <std/fs/block.h> source

struct BlockDevice {
    unsigned long sector_count;
    unsigned long sector_size;
    ?fn int(&Erased, unsigned long, []unsigned char) read_fn;
    ?fn int(&Erased, unsigned long, []const unsigned char) write_fn;
    ?&Erased ctx;
}

Fields

§unsigned long sector_countsource

total sectors on device

§unsigned long sector_sizesource

bytes per sector (usually 512)

§?fn int(&Erased, unsigned long, []unsigned char) read_fnsource

The driver's methods and context, stored type-erased (std/erased.h): one VFS can mount devices from different drivers at once, so BlockDevice itself isn't generic. BlockDevice::new<T> is the only writer and always pairs T's thunks with a &T context.

§?fn int(&Erased, unsigned long, []const unsigned char) write_fnsource

the &T

Methods

§generic<T: BlockDriver> static struct BlockDevice new( &T drv, unsigned long sector_count, unsigned long sector_size, )source · definition

A device of sector_count sectors of sector_size bytes whose read()/write() call drv.read(...)/drv.write(...). drv must outlive it.

§int read(unsigned long lba, []unsigned char buf)source · definition

Reads buf.len / sector_size sectors starting at lba into buf. -1 when buf is empty or not a whole number of sectors.

§int write(unsigned long lba, []const unsigned char buf)source · definition

Writes the buf.len / sector_size sectors of buf at lba (same rule).

§int valid() constsource · definition

Is the device valid / initialised?