diff --git a/kernel/libk/libk-mm/src/lib.rs b/kernel/libk/libk-mm/src/lib.rs index 5de4e74f..7ad405c4 100644 --- a/kernel/libk/libk-mm/src/lib.rs +++ b/kernel/libk/libk-mm/src/lib.rs @@ -230,6 +230,10 @@ impl PageBox> { PageBox { value, page_count } } + + pub fn as_bytes_mut(p: &mut Self) -> &mut PageSlice> { + unsafe { core::mem::transmute(p.as_bytes_mut()) } + } } impl PageBox<[MaybeUninit]> { diff --git a/kernel/libk/src/vfs/block/partition.rs b/kernel/libk/src/vfs/block/partition.rs index 2880740a..db38d081 100644 --- a/kernel/libk/src/vfs/block/partition.rs +++ b/kernel/libk/src/vfs/block/partition.rs @@ -90,14 +90,6 @@ impl<'a, D: NgBlockDevice + 'a> BlockDevice for Partition<'a, D> { || buf.len() % self.device.block_size != 0 { // TODO fallback to unaligned read - log::info!( - "Unaligned read: block_size={}, off={:#x}, pos={:#x}, len={}", - self.device.block_size, - pos, - start, - buf.len() - ); - loop {} todo!() } @@ -154,11 +146,14 @@ impl<'a, D: NgBlockDevice + 'a> BlockDevice for Partition<'a, D> { } } -async unsafe fn read_struct_lba(dev: &'static dyn BlockDevice, lba: u64) -> Result { +async unsafe fn read_struct_lba( + dev: &'static dyn BlockDevice, + lba: u64, +) -> Result, Error> { assert_eq!(size_of::(), 512); - let mut data = MaybeUninit::::uninit(); - let buffer = core::slice::from_raw_parts_mut(data.as_mut_ptr() as *mut u8, 512); - dev.read_exact(lba * 512, buffer).await?; + let mut data = PageBox::new_uninit()?; + dev.read_aligned(lba * 512, PageBox::as_bytes_mut(&mut data)) + .await?; Ok(data.assume_init()) } diff --git a/lib/runtime/build.rs b/lib/runtime/build.rs index 42e5a23c..127d159c 100644 --- a/lib/runtime/build.rs +++ b/lib/runtime/build.rs @@ -73,6 +73,7 @@ fn generate_abi>(abi_path: P) { } fn main() { + println!("cargo:rustc-check-cfg=cfg(rust_analyzer)"); build_libm(); generate_abi("../abi/def"); } diff --git a/lib/runtime/src/net.rs b/lib/runtime/src/net.rs index 7de76a9a..cebd5d08 100644 --- a/lib/runtime/src/net.rs +++ b/lib/runtime/src/net.rs @@ -2,7 +2,7 @@ pub use abi::net::{MacAddress, SocketInterfaceQuery, SocketOption, SocketType}; -#[cfg(feature = "alloc")] +#[cfg(any(feature = "alloc", rust_analyzer))] pub mod dns { //! DNS resolver module for `std` use abi::net::dns::DnsSerialize;