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
total sectors on device
bytes per sector (usually 512)
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.
the &T
Methods
§
generic<T: BlockDriver> static struct BlockDevice new(
&T drv,
unsigned long sector_count,
unsigned long sector_size,
)source · definitionA device of sector_count sectors of sector_size bytes whose
read()/write() call drv.read(...)/drv.write(...). drv must outlive it.
Reads buf.len / sector_size sectors starting at lba into buf.
-1 when buf is empty or not a whole number of sectors.
Writes the buf.len / sector_size sectors of buf at lba (same rule).
Is the device valid / initialised?