strat9_kernel/boot/block_device.rs
1//! Block device abstraction for boot partition access.
2//!
3//! Provides a trait for reading blocks from storage devices,
4//! used by the FAT32 module loader to read userspace ELFs.
5
6/// Trait for block-based storage devices.
7pub trait BlockDevice {
8 /// Read blocks from the device into the buffer.
9 ///
10 /// # Arguments
11 /// * `lba` - Logical Block Address to start reading from
12 /// * `buf` - Buffer to read into (must be at least block_size() bytes)
13 ///
14 /// # Returns
15 /// `Ok(())` on success, `Err(())` on failure.
16 fn read_block(&mut self, lba: u64, buf: &mut [u8]) -> Result<(), ()>;
17
18 /// Get the block size in bytes (typically 512 or 4096).
19 fn block_size(&self) -> u64;
20}
21
22/// Initialize a block device from the Device Tree.
23///
24/// # Safety
25///
26/// `dtb_ptr` must point to a valid flattened device tree.
27pub unsafe fn init_block_device_from_dtb(dtb_ptr: u64) -> Option<&'static mut dyn BlockDevice> {
28 // TODO: Parse DTB to find virtio-blk or other block devices
29 // For now, return None until Phase 4 is fully implemented
30 crate::serial_println!("[block] Block device init from DTB not yet implemented");
31 None
32}