From a806e41af0360680f9a0dace6cd61f56a23553e3 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Fri, 7 Feb 2025 18:59:00 -0800 Subject: [PATCH] [VFS] Skeleton for moving victoria falls to rust. --- rust/Cargo.lock | 10 ++++++ rust/Cargo.toml | 2 +- .../client/denali_client/src/disk_reader.rs | 31 +++++++++++++++++++ rust/lib/client/denali_client/src/lib.rs | 4 +++ rust/lib/fs/ext2/Cargo.toml | 8 +++++ rust/lib/fs/ext2/src/ext2_driver.rs | 19 ++++++++++++ rust/lib/fs/ext2/src/lib.rs | 8 +++++ rust/lib/fs/ext2/src/types.rs | 30 ++++++++++++++++++ rust/lib/mammoth/src/mem.rs | 6 ++++ rust/sys/victoriafalls/Cargo.toml | 2 ++ .../victoriafalls/src/bin/victoriafalls.rs | 13 ++++++-- 11 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 rust/lib/client/denali_client/src/disk_reader.rs create mode 100644 rust/lib/fs/ext2/Cargo.toml create mode 100644 rust/lib/fs/ext2/src/ext2_driver.rs create mode 100644 rust/lib/fs/ext2/src/lib.rs create mode 100644 rust/lib/fs/ext2/src/types.rs diff --git a/rust/Cargo.lock b/rust/Cargo.lock index c3a5f0e..6083562 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -48,6 +48,14 @@ dependencies = [ "yunqc", ] +[[package]] +name = "ext2" +version = "0.1.0" +dependencies = [ + "denali_client", + "mammoth", +] + [[package]] name = "linked_list_allocator" version = "0.10.5" @@ -163,6 +171,8 @@ checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" name = "victoriafalls" version = "0.1.0" dependencies = [ + "denali_client", + "ext2", "mammoth", "yellowstone-yunq", "yunq", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 0d4b7ca..1e43df4 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,7 +1,7 @@ [workspace] members = [ - "lib/client/denali_client", + "lib/client/denali_client", "lib/fs/ext2", "lib/mammoth", "lib/voyageurs", "lib/yellowstone", diff --git a/rust/lib/client/denali_client/src/disk_reader.rs b/rust/lib/client/denali_client/src/disk_reader.rs new file mode 100644 index 0000000..2d9a6a8 --- /dev/null +++ b/rust/lib/client/denali_client/src/disk_reader.rs @@ -0,0 +1,31 @@ +use mammoth::{cap::Capability, zion::ZError}; + +use crate::{DenaliClient, DiskBlock, ReadRequest}; + +pub struct DiskReader { + client: DenaliClient, + disk_id: u64, + lba_offset: u64, +} + +impl DiskReader { + pub fn new(client: DenaliClient, disk_id: u64, lba_offset: u64) -> Self { + Self { + client, + disk_id, + lba_offset, + } + } + + pub fn read(&mut self, lba: u64, cnt: u64) -> Result { + let read_resp = self.client.read(&ReadRequest { + device_id: self.disk_id, + block: DiskBlock { + lba: self.lba_offset + lba, + size: cnt, + }, + })?; + + Ok(Capability::take(read_resp.memory)) + } +} diff --git a/rust/lib/client/denali_client/src/lib.rs b/rust/lib/client/denali_client/src/lib.rs index 3cec9d6..72dfc10 100644 --- a/rust/lib/client/denali_client/src/lib.rs +++ b/rust/lib/client/denali_client/src/lib.rs @@ -3,3 +3,7 @@ use core::include; include!(concat!(env!("OUT_DIR"), "/yunq.rs")); + +mod disk_reader; + +pub use disk_reader::DiskReader; diff --git a/rust/lib/fs/ext2/Cargo.toml b/rust/lib/fs/ext2/Cargo.toml new file mode 100644 index 0000000..631197a --- /dev/null +++ b/rust/lib/fs/ext2/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "ext2" +version = "0.1.0" +edition = "2024" + +[dependencies] +denali_client = { path = "../../client/denali_client" } +mammoth = { path = "../../mammoth" } diff --git a/rust/lib/fs/ext2/src/ext2_driver.rs b/rust/lib/fs/ext2/src/ext2_driver.rs new file mode 100644 index 0000000..5354dd3 --- /dev/null +++ b/rust/lib/fs/ext2/src/ext2_driver.rs @@ -0,0 +1,19 @@ +use denali_client::DiskReader; +use mammoth::mem::MemoryRegion; + +use crate::types::Superblock; + +pub struct Ext2Driver { + reader: DiskReader, +} + +impl Ext2Driver { + pub fn new(mut reader: DiskReader) -> Self { + let super_block_mem = MemoryRegion::from_cap(reader.read(2, 2).unwrap()).unwrap(); + let super_block: &Superblock = super_block_mem.as_ref(); + let inodes = super_block.inodes_count; + let magic = super_block.magic; + mammoth::debug!("Superblock ({:#x}): inodes: {:#x}", magic, inodes); + Self { reader } + } +} diff --git a/rust/lib/fs/ext2/src/lib.rs b/rust/lib/fs/ext2/src/lib.rs new file mode 100644 index 0000000..40d9458 --- /dev/null +++ b/rust/lib/fs/ext2/src/lib.rs @@ -0,0 +1,8 @@ +#![no_std] + +extern crate alloc; + +mod ext2_driver; +mod types; + +pub use ext2_driver::Ext2Driver; diff --git a/rust/lib/fs/ext2/src/types.rs b/rust/lib/fs/ext2/src/types.rs new file mode 100644 index 0000000..e01b545 --- /dev/null +++ b/rust/lib/fs/ext2/src/types.rs @@ -0,0 +1,30 @@ +#[repr(C, packed)] +pub struct Superblock { + pub inodes_count: u32, + pub blocks_count: u32, + pub reserved_blocks_count: u32, + pub free_blocks_count: u32, + pub free_inodes_count: u32, + pub first_data_blok: u32, + pub log_block_size: u32, + pub log_frag_size: u32, + pub blocks_per_group: u32, + pub frags_per_group: u32, + pub inodes_per_group: u32, + pub mtime: u32, + pub wtime: u32, + pub mnt_count: u16, + pub max_mnt_count: u16, + pub magic: u16, + pub state: u16, + pub errors: u16, + pub minor_rev_level: u16, + pub lastcheck: u32, + pub checkinterval: u32, + pub creator_os: u32, + pub rev_level: u32, + pub def_resuid: u16, + pub def_resgid: u16, + pub first_ino: u32, + pub inode_size: u16, +} diff --git a/rust/lib/mammoth/src/mem.rs b/rust/lib/mammoth/src/mem.rs index ea4a070..0beb262 100644 --- a/rust/lib/mammoth/src/mem.rs +++ b/rust/lib/mammoth/src/mem.rs @@ -103,6 +103,12 @@ impl MemoryRegion { } } +impl AsRef for MemoryRegion { + fn as_ref(&self) -> &T { + unsafe { (self.virt_addr as *const T).as_ref().unwrap() } + } +} + impl Drop for MemoryRegion { fn drop(&mut self) { // FIXME: We shouldn't have to do this manual adjustment. diff --git a/rust/sys/victoriafalls/Cargo.toml b/rust/sys/victoriafalls/Cargo.toml index 3c2b75f..5464a78 100644 --- a/rust/sys/victoriafalls/Cargo.toml +++ b/rust/sys/victoriafalls/Cargo.toml @@ -7,6 +7,8 @@ edition = "2021" mammoth = { path = "../../lib/mammoth" } yellowstone-yunq = { path = "../../lib/yellowstone" } yunq = { path = "../../lib/yunq" } +denali_client = { path = "../../lib/client/denali_client" } +ext2 = { path = "../../lib/fs/ext2" } [build-dependencies] yunqc = { path = "../../../yunq/rust" } diff --git a/rust/sys/victoriafalls/src/bin/victoriafalls.rs b/rust/sys/victoriafalls/src/bin/victoriafalls.rs index 4d19ddd..f8fef0f 100644 --- a/rust/sys/victoriafalls/src/bin/victoriafalls.rs +++ b/rust/sys/victoriafalls/src/bin/victoriafalls.rs @@ -1,7 +1,9 @@ #![no_std] #![no_main] -use mammoth::{define_entry, zion::z_err_t}; +use denali_client::{DenaliClient, DiskReader}; +use ext2::Ext2Driver; +use mammoth::{cap::Capability, define_entry, zion::z_err_t}; define_entry!(); @@ -9,7 +11,14 @@ define_entry!(); extern "C" fn main() -> z_err_t { let yellowstone = yellowstone_yunq::from_init_endpoint(); - let denali = yellowstone.get_denali().unwrap(); + let denali_info = yellowstone.get_denali().unwrap(); + let client = DenaliClient::new(Capability::take(denali_info.denali_endpoint)); + + let driver = Ext2Driver::new(DiskReader::new( + client, + denali_info.device_id, + denali_info.lba_offset, + )); 0 }