feat(storage): ext4-only disk via mkfs.ext4 -d; drop FAT16; feature-gated mount (ro on unknown ro_compat); ext4 read spans blocks, delete clears inode, mkdir counts dir; virtio-blk writes; test-qemu e2fsck gate

This commit is contained in:
2026-10-27 17:09:35 +01:00
parent 4030dd4315
commit 0fd568cdad
24 changed files with 390 additions and 809 deletions

View File

@@ -26,6 +26,7 @@ pub struct VirtioBlockDevice {
mmio: UserMmio,
queue: VirtioQueue,
dma: DmaAddrs,
sectors: usize,
}
impl VirtioBlockDevice {
@@ -52,20 +53,23 @@ impl VirtioBlockDevice {
data_pa: PhysicalAddress::from_raw(hdr_pa + 32),
data_va: VirtualAddress::from_raw(REQ_HDR_VA + 32),
};
let capacity = regs.read(block::CONFIG_CAPACITY) as u64
| (regs.read(block::CONFIG_CAPACITY + 4) as u64) << 32;
Some(Self {
mmio: UserMmio,
queue: VirtioQueue::new(QueueAddrs::from_base(VQUEUE_VA)),
dma,
sectors: usize::try_from(capacity).ok()?,
})
}
}
impl BlockDevice for VirtioBlockDevice {
fn sector_size(&self) -> usize { SECTOR_SIZE }
fn sector_count(&self) -> usize { 0xFFFF }
fn sector_count(&self) -> usize { self.sectors }
fn read_sector(&mut self, sector: SectorId, buf: &mut [u8]) -> bool {
if buf.len() < SECTOR_SIZE { return false; }
if buf.len() < SECTOR_SIZE || sector.raw() as usize >= self.sectors { return false; }
let mut sector_buf = [0u8; SECTOR_SIZE];
if !block::read_sector(&self.mmio, &self.queue, &self.dma, sector.raw(), &mut sector_buf) {
return false;
@@ -74,8 +78,8 @@ impl BlockDevice for VirtioBlockDevice {
true
}
fn write_sector(&mut self, _sector: SectorId, _buf: &[u8]) -> bool { false }
/// Writing is not implemented yet.
fn writable(&self) -> bool { false }
fn write_sector(&mut self, sector: SectorId, buf: &[u8]) -> bool {
if sector.raw() as usize >= self.sectors { return false; }
block::write_sector(&self.mmio, &self.queue, &self.dma, sector.raw(), buf)
}
}