dev/block: use read_aligned in partition probing
This commit is contained in:
parent
128b699352
commit
4fc322405c
@ -230,6 +230,10 @@ impl<T> PageBox<MaybeUninit<T>> {
|
|||||||
|
|
||||||
PageBox { value, page_count }
|
PageBox { value, page_count }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_bytes_mut(p: &mut Self) -> &mut PageSlice<MaybeUninit<u8>> {
|
||||||
|
unsafe { core::mem::transmute(p.as_bytes_mut()) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> PageBox<[MaybeUninit<T>]> {
|
impl<T> PageBox<[MaybeUninit<T>]> {
|
||||||
|
@ -90,14 +90,6 @@ impl<'a, D: NgBlockDevice + 'a> BlockDevice for Partition<'a, D> {
|
|||||||
|| buf.len() % self.device.block_size != 0
|
|| buf.len() % self.device.block_size != 0
|
||||||
{
|
{
|
||||||
// TODO fallback to unaligned read
|
// 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!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,11 +146,14 @@ impl<'a, D: NgBlockDevice + 'a> BlockDevice for Partition<'a, D> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async unsafe fn read_struct_lba<T>(dev: &'static dyn BlockDevice, lba: u64) -> Result<T, Error> {
|
async unsafe fn read_struct_lba<T>(
|
||||||
|
dev: &'static dyn BlockDevice,
|
||||||
|
lba: u64,
|
||||||
|
) -> Result<PageBox<T>, Error> {
|
||||||
assert_eq!(size_of::<T>(), 512);
|
assert_eq!(size_of::<T>(), 512);
|
||||||
let mut data = MaybeUninit::<T>::uninit();
|
let mut data = PageBox::new_uninit()?;
|
||||||
let buffer = core::slice::from_raw_parts_mut(data.as_mut_ptr() as *mut u8, 512);
|
dev.read_aligned(lba * 512, PageBox::as_bytes_mut(&mut data))
|
||||||
dev.read_exact(lba * 512, buffer).await?;
|
.await?;
|
||||||
Ok(data.assume_init())
|
Ok(data.assume_init())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ fn generate_abi<P: AsRef<Path>>(abi_path: P) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
println!("cargo:rustc-check-cfg=cfg(rust_analyzer)");
|
||||||
build_libm();
|
build_libm();
|
||||||
generate_abi("../abi/def");
|
generate_abi("../abi/def");
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
pub use abi::net::{MacAddress, SocketInterfaceQuery, SocketOption, SocketType};
|
pub use abi::net::{MacAddress, SocketInterfaceQuery, SocketOption, SocketType};
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(any(feature = "alloc", rust_analyzer))]
|
||||||
pub mod dns {
|
pub mod dns {
|
||||||
//! DNS resolver module for `std`
|
//! DNS resolver module for `std`
|
||||||
use abi::net::dns::DnsSerialize;
|
use abi::net::dns::DnsSerialize;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user